<?php
$this->load->view("partial/header");
//echo"<pre>";
//print_r($mode);
//echo '</pre>';
?>
<!-------- Receipt----------->




<div id="page_title" style="margin-bottom:8px;"><?php echo $this->lang->line('sales_register'); ?>
    <span id="current_add">
        <?php
        //        if (end($cart)) {
        //            echo end($cart)["item_number"] . "@" . end($cart)["price"] . "&nbsp;BDT";
        //        }
        ?>
    </span>
</div>
<!--<div id="current_add" ><p>shad</p></div>-->
<?php
if (isset($error)) {
	echo "<div class='error_message'>" . $error . "</div>";
}

if (isset($warning)) {
	echo "<div class='warning_mesage'>" . $warning . "</div>";
}

if (isset($success)) {
	echo "<div class='success_message'>" . $success . "</div>";
}
?>
<div id="register_wrapper">
    <?php echo form_open("sales/change_mode", array('id' => 'mode_form')); ?>
    <span><?php echo $this->lang->line('sales_mode') ?></span>
    <?php echo form_dropdown('mode', $modes, $mode, 'onchange="$(\'#mode_form\').submit();"id="change"'); ?>
    <div id="show_suspended_sales_button">
        <?php
        echo anchor("sales/suspended/width:425", "<div class='small_button'><span style='font-size:73%;'>" . $this->lang->line('sales_suspended_sales') . "</span></div>", array('class' => 'thickbox none', 'title' => $this->lang->line('sales_suspended_sales')));
        ?>
    </div>
</form>
<?php echo form_open("sales/add", array('id' => 'add_item_form')); ?>
<label id="item_label" for="item">

    <?php
    if ($mode == 'sale' || $mode == 'global') {
    	echo $this->lang->line('sales_find_or_scan_item');
    } else {
    	echo $this->lang->line('sales_find_or_scan_item_or_receipt');
    }
    ?>
</label>
<?php
if ($mode == 'global') {
	echo form_input(array('name' => 'item', 'id' => 'find', 'size' => '40'));
} else if($mode == 'global_delivery'){
	echo form_input(array('name' => 'recept_id', 'id' => 'recept_id', 'size' => '40'));
}else {
	echo form_input(array('name' => 'item', 'id' => 'item', 'size' => '40'));
}
?>

<?php if ($mode == 'global'){?>
<div id="item_find" >
    <?php echo anchor("sales/globalsearch/-1/width:480", "<div class='small_button' id='find' ><span>" . $this->lang->line('sales_find') . "</span></div>", array('class' => 'thickbox none', 'id' => "button_find", 'title' => $this->lang->line('sales_find'))); ?>
</div>
<?php } else if($mode == 'global_delivery'){?>
<div id="item_find" >
<?php echo anchor("sales/global_delivery/-1/width:480", "<div class='small_button' id='recept_id' ><span>" . $this->lang->line('sales_find') . "</span></div>", array('class' => 'thickbox none', 'id' => "button_find", 'title' => $this->lang->line('sales_find'))); ?>
</div>    
<?php }?>

<?php //if ($mode != 'global') { ?>
    <!--<div id="new_item_button_register" >-->
        <?php
        //echo anchor("items/view/-1/width:360", "<div class='small_button'><span>" . $this->lang->line('sales_new_item') . "</span></div>", array('class' => 'thickbox none', 'title' => $this->lang->line('sales_new_item')));
        ?>
    <!--</div>-->
<?php //} else { ?>

    <!--<div id="item_find" >-->
        <?php
        //echo anchor("sales/globalsearch/-1/width:480", "<div class='small_button' id='find' ><span>" . $this->lang->line('sales_find') . "</span></div>", array('class' => 'thickbox none', 'id' => "button_find", 'title' => $this->lang->line('sales_find')));
        ?>
    <!--</div>-->
<?php //} ?>
<!--</form>-->
<?php
//echo '<pre>';
//print_r($cart);
//print_r($lot_details);
?>
<table id="register">
    <thead>
        <tr>
            <th style="width:11%;"><?php echo $this->lang->line('common_delete'); ?></th>
            <th style="width:10%;"><?php echo $this->lang->line('sales_item_number'); ?></th>
            <th style="width:30%;"><?php echo $this->lang->line('sales_item_name'); ?></th>
            <th style="width:11%;"><?php echo $this->lang->line('sales_price'); ?></th>
            <th style="width:11%;"><?php echo $this->lang->line('sales_quantity'); ?></th>
            <th style="width:11%;"><?php echo $this->lang->line('sales_discount'); ?></th>
            <th style="width:15%;"><?php echo $this->lang->line('sales_total'); ?></th>
            <?php if ($mode == 'global') { ?>
                <th style="width:15%;"><?php echo $this->lang->line('location'); ?></th>    
                <?php
            } else {
                ?>
                <th style="width:15%;"><?php echo $this->lang->line('sales_edit'); ?></th>  
                <?php
            }
            ?>
        </tr>
    </thead>
    <tbody id="cart_contents">
        <?php
        if (count($cart) == 0) {
            ?>
            <tr><td colspan='8'>
                    <div class='warning_message' style='padding:7px;'><?php echo $this->lang->line('sales_no_items_in_cart'); ?></div>
            </tr></tr>
            <?php
        } else {
        	 echo form_open("sales/edit_item_shawpon", array('id' => 'edit_item_shawpon_form')); ?>
        <div class='small_button' id='edit_item_shawpon_button' style='margin-top:5px;'>
            <span><?php echo $this->lang->line('sales_cancel_sale'); ?></span>
        </div>
        </form>
        <?php
        foreach (array_reverse($cart, true) as $line => $item) {







        	// $cur_item_info = $this->Item->get_info_shawpon($item['item_id'],$item['lot_no']);
        	echo form_open("sales/edit_item/$line");
                ?>
                <tr>
                    <td><?php echo anchor_delete("sales/delete_item/$line", '[' . $this->lang->line('common_delete') . ']','',$item['item_id'],$item['name'],$item['lot_no']); ?></td>
                    <td><?php echo $item['item_id']."</br>L: ".$item['lot_no']; ?></td>
                    <td style="align:center;"><?php echo $item['name']; ?><br /> <?php echo ($mode != 'global') ? '[' . $cur_item_info->quantity . ' in stock]' : '' ?></td>

                    <?php
                    if ($items_module_allowed) {
                        ?>
                        <td>
                            <?php //echo form_input(array('name' => 'price', 'value' => $item['price'], 'size' => '6')); ?>
                            <?php echo number_format($item['price'], 2, '.', ''); ?>
                            <?php echo form_hidden('price', $item['price']); ?>
                        </td>
                        <?php
                    } else {
                        ?>
                        <td>
                            <?php echo number_format($item['price'], 2, '.', ''); ?>
                            <?php echo form_hidden('price', $item['price']); ?>
                        </td>
                        <?php
                    }
                    ?>

                    <td>
                        <?php
                        //                        if ($item['is_serialized'] == 1) {
                        //                            echo $item['quantity'];
                        //                            echo form_hidden('quantity', $item['quantity']);
                        //                        } else {
                        //                            echo form_input(array('name' => 'quantity', 'value' => $item['quantity'], 'size' => '2'));
                        //                        }
                        if ($mode == 'global') {
                        	echo $item['quantity'];
                        	echo form_hidden('quantity', $item['quantity']);
                        } else {
                        	echo form_input(array('name' => 'quantity', 'value' => $item['quantity'], 'size' => '2'));
                        	// echo $item['quantity'];
                        	//echo form_hidden('quantity', $item['quantity']);
                        }
                        ?>
                    </td>

                    <td><?php echo form_input(array('name' => 'discount', 'value' => $item['discount'], 'size' => '3')); ?></td>
                    <td><?php echo number_format(($item['price'] * $item['quantity']) - (($item['price'] * $item['quantity']) * ($item['discount'] / 100)), 2, '.', ''); ?></td>
                    <?php
                    if ($mode == 'global') {
                    	echo '<td>' . $item['location'] . ' </td>';
                    } else {
                        ?>

                        <td><?php echo form_submit("edit_item", $this->lang->line('sales_edit_item')); ?></td>
                    <?php } ?>

                </tr>
                <?php /*
                        <tr>
                        <td style="color:#2F4F4F";><?php echo $this->lang->line('sales_description_abbrv') . ':'; ?></td>
                        <td colspan=2 style="text-align:left;">

                        <?php
                        if ($item['allow_alt_description'] == 1) {
                        echo form_input(array('name' => 'description', 'value' => $item['description'], 'size' => '20'));
                        } else {
                        if ($item['description'] != '') {
                        echo $item['description'];
                        echo form_hidden('description', $item['description']);
                        } else {
                        echo 'None';
                        echo form_hidden('description', '');
                        }
                        }
                        ?>
                        </td>
                        <td>&nbsp;</td>
                        <td style="color:#2F4F4F";>
                        <?php
                        if ($item['is_serialized'] == 1) {
                        echo $this->lang->line('sales_serial') . ':';
                        }
                        ?>
                        </td>
                        <td colspan=3 style="text-align:left;">
                        <?php
                        if ($item['is_serialized'] == 1) {
                        echo form_input(array('name' => 'serialnumber', 'value' => $item['serialnumber'], 'size' => '20'));
                        } else {
                        echo form_hidden('serialnumber', '');
                        }
                        ?>
                        </td>


                        </tr>
                 */ ?>
                <tr style="height:3px">
                    <td colspan=8 style="background-color:white"> </td>
                </tr>		</form>
                <?php
        }
        }
        ?>
    </tbody>
</table>
</div>


<div id="overall_sale">
    <?php
    if (isset($customer)) {
    	echo $this->lang->line("sales_customer") . ': <b>' . $customer . '</b><br />';
    	echo anchor("sales/remove_customer", '[' . $this->lang->line('common_remove') . ' ' . $this->lang->line('customers_customer') . ']');
        ?>
        <div style="margin-top:5px;text-align:left;">
            <?php if ($previous_due > 0) { ?>
                <font style="font-weight:bold;">Previous Due: </font><font style="font-weight:bold;color:#FF0000;"><?php echo to_currency($previous_due); ?></font>
            <?php } else if ($previous_due < 0) { ?>
                <font style="font-weight:bold;">Previous Advance: </font><font style="font-weight:bold;color:#078d20;"><?php echo to_currency($previous_due); ?></font>
            <?php } else { ?>
                <font style="font-weight:bold;">Previous Due: </font><font style="font-weight:bold;color:#000000;"><?php echo to_currency($previous_due); ?></font>
            <?php } ?>
        </div>
        <div style="margin-top:5px;text-align:left;">
            User Points: <?php echo!empty($user_points) ? $user_points : 0 ?>
        </div>
        <?php
    } else {
    	echo form_open("sales/select_customer", array('id' => 'select_customer_form'));
        ?>
        <label id="customer_label" for="customer"><?php echo $this->lang->line('sales_select_customer'); ?></label>
        <?php echo form_input(array('name' => 'customer', 'id' => 'customer', 'size' => '30', 'value' => $this->lang->line('sales_start_typing_customer_name'))); ?>
    </form>
    <div style="margin-top:5px;text-align:center;">
    <!--     <h3 style="margin: 5px 0 5px 0"><?php echo $this->lang->line('common_or'); ?></h3> -->
        <?php
        //     echo anchor("customers/view/-1/width:350", "<div class='small_button' style='margin:0 auto;'><span>" . $this->lang->line('sales_new_customer') . "</span></div>", array('class' => 'thickbox none', 'title' => $this->lang->line('sales_new_customer')));
        ?>
    </div>
    <div class="clearfix">&nbsp;</div>
    <?php
    }
?>

<div id='sale_details'>
    <div class="float_left" style="width:55%;"><?php echo $this->lang->line('sales_sub_total'); ?>:</div>
    <div class="float_left" style="width:45%;font-weight:bold;text-align:right;"><?php echo to_currency($subtotal); ?></div>
    <?php if ($this->session->userdata['customer'] != -1) { ?>
        <?php if ($previous_due >= 0) { ?>
            <div class="float_left" style="width:55%;"><?php echo "Previous Due"; ?>:</div>
        <?php } else { ?>
            <div class="float_left" style="width:55%;"><?php echo "Previous Advance"; ?>:</div>
        <?php } ?>

        <div class="float_left" style="width:45%;font-weight:bold;text-align:right;"><?php echo to_currency($previous_due); ?></div>

        <?php
    }
    $total_tax = 0.00;
    ?>
    <?php foreach ($taxes as $name => $value) { ?>
        <div class="float_left" style='width:55%;'><?php echo $name; ?>:</div>
        <div class="float_left" style="width:45%;font-weight:bold;text-align:right;"><?php echo to_currency($value); ?></div>
        <?php
        $total_tax = $total_tax + $value;
    };
    ?>

    <?php if ($this->session->userdata['customer'] != -1) { ?>
        <div class="float_left" style='width:70%;'>User Points(-): (<?php echo $cart_point . ' * ' . to_currency($cart_point_value) ?>)</div>
        <div class="float_left" style="width:30%;font-weight:bold;text-align:right;"><?php echo "-" . to_currency($cart_point_cost); ?></div>
    <?php } ?>

    <?php
    $adjectment = number_format(ceil($total) - ($subtotal + $total_tax + $cart_point_cost+$previous_due),2);
    ?>
    <div class="float_left" style='width:55%;'>Adjustment(+/-):</div>
    <div class="float_left" style="width:45%;font-weight:bold;text-align:right;"><?php echo $adjectment > 0 ? "+" . to_currency($adjectment) : to_currency($adjectment); ?></div>
    <div class="float_left" style='width:55%;'><?php echo $this->lang->line('sales_total'); ?>:</div>
    <div class="float_left" style="width:45%;font-weight:bold;text-align:right;"><?php echo to_currency(ceil($total + $previous_due )); ?></div>
</div>




<?php
// Only show this part if there are Items already in the sale.
if (count($cart) > 0) {
    ?>

    <div id="Cancel_sale">
        <?php echo form_open("sales/cancel_sale", array('id' => 'cancel_sale_form')); ?>
        <div class='small_button' id='cancel_sale_button' style='margin-top:5px;'>
            <span><?php echo $this->lang->line('sales_cancel_sale'); ?></span>
        </div>
        </form>
    </div>
    <div class="clearfix" style="margin-bottom:1px;">&nbsp;</div>
    <?php
    // Only show this part if there is at least one payment entered.
    if (count($payments) > 0) {
    	if ($mode == 'global') {
    		$posLocations = [0 => $this->lang->line('select_locations'), LOCATION_CODE => LOCATION_NAME];
    		if ($this->session->userdata('global_receive_location_code') != LOCATION_CODE) {
    			$posLocations[$this->session->userdata('global_receive_location_code')] = $this->session->userdata('global_receive_location');
    		}
    	}
        ?>
        <div id="finish_sale">
            <?php echo form_open("sales/complete", array('id' => 'finish_sale_form')); ?>
            <?php if ($mode == 'global') { ?>
                <label id="comment_label" for="comment"><?php echo $this->lang->line('common_locations'); ?>:</label>
                <?php echo form_dropdown('receive_location', $posLocations, '', 'id="receive_location"'); ?><br/><br/>
            <?php } ?>
            <label id="comment_label" for="comment"><?php echo $this->lang->line('common_comments'); ?>:</label>
            <?php echo form_textarea(array('name' => 'comment', 'id' => 'comment', 'value' => $comment, 'rows' => '4', 'cols' => '23')); ?>
            <br /><br />

            <?php
            if (!empty($customer_email)) {
            	echo $this->lang->line('sales_email_receipt') . ': ' . form_checkbox(array(
            	'name' => 'email_receipt',
            	'id' => 'email_receipt',
            	'value' => '1',
            	'checked' => (boolean) $email_receipt,
            	)) . '<br />(' . $customer_email . ')<br />';
            }

            if ($payments_cover_total) {
            	echo "<div class='small_button' id='finish_sale_button' style='float:left;margin-top:5px;'><span>" . $this->lang->line('sales_complete_sale') . "</span></div>";
            }
            echo "<div class='small_button' id='suspend_sale_button' style='float:right;margin-top:5px;'><span>" . $this->lang->line('sales_suspend_sale') . "</span></div>";
            ?>
        </div>
        </form>
        <?php
    }
    ?>



    <table width="100%">
        <tr>
            <td style="width:55%; "><div class="float_left"><?php echo 'Payments Total:' ?></div></td>
            <td style="width:45%; text-align:right;"><div class="float_left" style="text-align:right;font-weight:bold;"><?php echo to_currency($payments_total); ?></div></td>
        </tr>
        <?php if (!empty($cart_point)) { ?>
            <tr>
                <td style="width:55%; "><div class="float_left"><?php echo 'Use Points:' ?></div></td>
                <td style="width:45%; text-align:right;"><div class="float_left" style="text-align:right;font-weight:bold;"><?php echo $cart_point; ?></div></td>
            </tr>
        <?php } ?>
        <tr>

            <td style="width:55%; "><div class="float_left" ><?php echo 'Trans. Amount Due:' ?></div></td>
            <?php if ($amount_due < 0) { ?>
                <td style="width:45%; text-align:right; "><div class="float_left" style="text-align:right;font-weight:bold;color:#008000;font-size: 150%; "><?php echo to_currency($amount_due + $previous_due + $adjectment); ?></div></td>

            <?php } else { ?>
                <td style="width:45%; text-align:right; "><div class="float_left" style="text-align:right;font-weight:bold;color:#FF3A3A;font-size: 150%; "><?php echo to_currency($amount_due + $previous_due + $adjectment); ?></div></td>
            <?php } ?>
        </tr>
    </table>

    <div id="Payment_Types" >

        <div style="height:auto;">

            <?php echo form_open("sales/add_payment", array('id' => 'add_payment_form')); ?>
            <table width="100%">
                <tr>
                    <td>
                        <?php echo $this->lang->line('sales_payment') . ':   '; ?>
                    </td>
                    <td>
                        <?php echo form_dropdown('payment_type', $payment_options, array(), 'id="payment_types"'); ?>
                    </td>
                </tr>
                <tr id="hide-row">
                    <td>
                        <?php echo $this->lang->line('sales_amount_tendered') . ': '; ?></span>
                    </td>
                    <td>
                        <?php echo form_input(array('name' => 'amount_tendered', 'id' => 'amount_tendered', 'value' => to_currency_no_money($amount_due + $previous_due), 'size' => '10')); ?>
                    </td>
                </tr>
            </table>
            <?php
            // add div which depend(Change or Hide) on dropdown value
            //-------------------------------------start----------------------
            ?>


            <div id="check" style="display: none">
                <table width="100%">

                    <tr>
                        <td><?php echo $this->lang->line('check_no') . ': '; ?></td>

                        <td><?php echo form_input(array('name' => 'check_name', 'id' => 'check_name', 'value' => '', 'size' => '20')); ?></td>
                    </tr>
                    <tr>
                        <td> <?php echo '<label>' . $this->lang->line('ac_no') . ': ' . '</label>'; ?></td>

                        <td> <?php echo form_input(array('name' => 'ac_no_check', 'id' => 'ac_no', 'value' => '', 'size' => '20')); ?></td>
                    </tr>
                    <tr>
                        <td>  <?php echo $this->lang->line('holder_name') . ': '; ?></td>

                        <td>  <?php echo form_input(array('name' => 'holder_name_check', 'id' => 'holder_name', 'value' => '', 'size' => '20')); ?></td>
                    </tr>
                    <tr>
                        <td><?php echo $this->lang->line('bank_name') . ':'; ?></td>
                        <td> <?php echo form_dropdown('bank_name_check', $bank_id, array(), 'id="bank_name"'); ?></td>
                    </tr>
                    <tr>
                        <td> <?php echo $this->lang->line('branch_name') . ': '; ?></td>
                        <td>                <?php echo form_input(array('name' => 'branch_name_check', 'id' => 'branch_name', 'value' => '', 'size' => '20')); ?>
                        </td>
                    </tr>
                    <tr>
                        <td><?php echo $this->lang->line('check_date') . ': '; ?> </td>
                        <td><?php echo form_input(array('name' => 'check_date', 'id' => 'check_date', 'value' => '', 'size' => '20')); ?>
                        </td>
                    </tr>
                </table>

            </div>

            <div id="debit" style="display: none">
                <table>
                    <tr>
                        <td><?php echo $this->lang->line('bank_name') . ':'; ?></td>
                        <td><?php echo form_dropdown('bank_name_debit', $bank_id, array(), 'id="bank_name"'); ?></td>
                    </tr>
                    <tr>
                        <td><?php echo $this->lang->line('card_no') . ': '; ?></td>
                        <td><?php echo form_input(array('name' => 'card_no_debit', 'id' => 'card_no', 'value' => '', 'size' => '10')); ?></td>
                    </tr>
                    <tr>
                        <td><?php echo $this->lang->line('holder_name') . ': '; ?></td>
                        <td><?php echo form_input(array('name' => 'holder_name_debit', 'id' => 'holder_name', 'value' => '', 'size' => '10')); ?></td>
                    </tr>
                </table>

            </div>



            <div id="credit" style="display: none">
                <table>
                    <tr>
                        <td><?php echo $this->lang->line('bank_name') . ':'; ?></td>
                        <td><?php echo form_dropdown('bank_name_credit', $bank_id, array(), 'id="bank_name"'); ?></td>
                    </tr>
                    <tr>
                        <td><?php echo $this->lang->line('card_no') . ': '; ?></td>
                        <td><?php echo form_input(array('name' => 'card_no_credit', 'id' => 'card_no', 'value' => '', 'size' => '10')); ?></td>
                    </tr>
                    <tr>
                        <td><?php echo $this->lang->line('holder_name') . ': '; ?></td>
                        <td><?php echo form_input(array('name' => 'holder_name_credit', 'id' => 'holder_name', 'value' => '', 'size' => '10')); ?></td>
                    </tr>

                    <tr>
                        <td><?php echo $this->lang->line('card_expire_month') . ':'; ?></td>
                        <td><?php echo form_dropdown('card_expire_month', $month, array(), 'id="card_expire_month"'); ?></td>
                    </tr>
                    <tr>
                        <td><?php echo $this->lang->line('card_expire_year') . ':'; ?></td>
                        <td><?php echo form_dropdown('card_expire_year', $year, array(), 'id="card_expire_year"'); ?> </td>
                    </tr>

                </table>

            </div>

            <div id="points" style="display: none">
                <table>
                    <tr>
                        <td>
                            <?php echo $this->lang->line('use_point') . ': '; ?></span>
                        </td>
                        <td>
                            <?php echo form_input(array('name' => 'user_point', 'id' => 'user_point', 'value' => '', 'size' => '10')); ?>
                        </td>
                    </tr>
                </table>
            </div>

            <?php
            if(($amount_due + $previous_due)>0){

            ?>
            <div class='small_button' id='add_payment_button' style='float:left;margin-top:5px;'>
                <span><?php echo $this->lang->line('sales_add_payment'); ?></span>
            </div>
<?php }?>
        </div>
        </form>
    </div>
    <?php
    // Only show this part if there is at least one payment entered.
    if (count($payments) > 0 || !empty($cart_point)) {
        ?>
        <table id="register">
            <thead>
                <tr>
                    <th style="width:11%;"><?php echo $this->lang->line('common_delete'); ?></th>
                    <th style="width:60%;"><?php echo 'Type'; ?></th>
                    <th style="width:18%;"><?php echo 'Amount'; ?></th>


                </tr>
            </thead>
            <tbody id="payment_contents">
                <?php
                foreach ($payments as $payment_id => $payment) {
                	if ($payment['payment_type'] != 'User Point') {
                		echo form_open("sales/edit_payment/$payment_id", array('id' => 'edit_payment_form' . $payment_id));
                        ?>
                        <tr>
                            <td><?php echo anchor("sales/delete_payment/$payment_id", '[' . $this->lang->line('common_delete') . ']'); ?></td>
                            <td><?php echo $payment['payment_type']; ?></td>
                            <td style="text-align:right;"><?php echo to_currency($payment['payment_amount']); ?></td>
                        </tr>
                        </form>
                        <?php
                	}
                }
                ?>
                <?php
                if (!empty($cart_point)) {
                    ?>
                    <tr>
                        <td><?php echo anchor("sales/delete_point", '[' . $this->lang->line('common_delete') . ']'); ?></td>
                        <td>Point (<?php echo $cart_point ?>)</td>
                        <td style="text-align:right;"><?php echo '-' . to_currency($cart_point_cost); ?></td>
                    </tr>
                <?php } ?>
            </tbody>
        </table>
        <br />
        <?php
    }
}
?>
</div>
<div class="clearfix" style="margin-bottom:30px;">&nbsp;</div>


<?php $this->load->view("partial/footer"); ?>

<script type="text/javascript" language="javascript">
$(document).ready(function ()
{
	$(this).attr('value', "<?php echo $this->lang->line('sales_start_typing_item_name'); ?>");
	$("#find").blur(function () {
		var find_val = $(this).val();

		$("#button_find").attr('href', '<?php echo base_url(); ?>index.php/sales/globalsearch/' + find_val + '/width:480');
		$(this).attr('value', "<?php echo $this->lang->line('sales_start_typing_item_name'); ?>");
	});

	$("#recept_id").blur(function () {
		var find_val = $(this).val();

		$("#button_find").attr('href', '<?php echo base_url(); ?>index.php/sales/global_delivery/' + find_val + '/width:480');
		$(this).attr('placeholder', "<?php echo $this->lang->line('sales_start_typing_item_name'); ?>");
	});

	$("#item").autocomplete('<?php echo site_url("sales/item_search"); ?>',
	{
		minChars: 0,
		max: 100,
		selectFirst: false,
		delay: 10,
		formatItem: function (row) {
			//return row[1];
			return (row.length > 1 && row[1]) || row[0];
		}
	});


	$("#item").result(function (event, data, formatted)
	{
		$("#add_item_form").submit();
	});
	//
	//        var modechange = $("#change").val();
	//     $("#mode_form").change(function() {
	//
	//            var mode = $("#change").val();
	//
	//              alert(modechange);
	//                    $.ajax({
	//                            type: "POST",
	//                            url: '<?php echo site_url("sales/change_mode"); ?>',
	//                            data: { change: modechange },
	//                            success:function(data){
	//                                alert(data);
	//                            }
	//
	//                            });
	//
	//
	//                });
	//





	$('#item').focus();
	$('#find').focus();
	$('#recept_id').focus();

	$('#item').blur(function ()
	{
		$(this).attr('value', "<?php echo $this->lang->line('sales_start_typing_item_name'); ?>");
	});

	$("#find").autocomplete('<?php echo site_url("sales/item_search"); ?>',
	{
		minChars: 0,
		max: 100,
		selectFirst: false,
		delay: 10,
		formatItem: function (row) {
			return row[1];
		}
	});

	$('#check_date').datePicker();


	$('#item,#customer,#find,#recept_id').click(function ()
	{
		$(this).attr('value', '');

	});

	$("#customer").autocomplete('<?php echo site_url("sales/customer_search"); ?>',
	{
		minChars: 0,
		delay: 10,
		max: 100,
		formatItem: function (row) {
			return row[1];
		}
	});

	$("#customer").result(function (event, data, formatted)
	{
		$("#select_customer_form").submit();
	});

	$('#customer').blur(function ()
	{
		$(this).attr('value', "<?php echo $this->lang->line('sales_start_typing_customer_name'); ?>");
	});

	$('#comment').change(function ()
	{
		$.post('<?php echo site_url("sales/set_comment"); ?>', {comment: $('#comment').val()});
	});

	$('#receive_location').change(function ()
	{
		$.post('<?php echo site_url("sales/set_receive_location"); ?>', {receive_location: $('#receive_location').val()});
	});

	$('#email_receipt').change(function ()
	{
		$.post('<?php echo site_url("sales/set_email_receipt"); ?>', {email_receipt: $('#email_receipt').is(':checked') ? '1' : '0'});
	});


	$("#finish_sale_button").click(function ()
	{
		if (confirm('<?php echo $this->lang->line("sales_confirm_finish_sale"); ?>'))
		{
			$('#finish_sale_form').submit();
		}
	});

	$("#suspend_sale_button").click(function ()
	{
		if (confirm('<?php echo $this->lang->line("sales_confirm_suspend_sale"); ?>'))
		{
			$('#finish_sale_form').attr('action', '<?php echo site_url("sales/suspend"); ?>');
			$('#finish_sale_form').submit();
		}
	});

	$("#cancel_sale_button").click(function ()
	{
		if (confirm('<?php echo $this->lang->line("sales_confirm_cancel_sale"); ?>'))
		{
			$('#cancel_sale_form').submit();
		}
	});

	$("#edit_item_shawpon_button").click(function ()
	{
		$('#edit_item_shawpon_form').submit();
	});

	$("#add_payment_button").click(function ()
	{
		$('#add_payment_form').submit();
	});



	$("#payment_types").change(checkPaymentTypeGiftcard).ready(checkPaymentTypeGiftcard)
});

function post_item_form_submit(response)
{
	if (response.success)
	{
		$("#item").attr("value", response.item_id);
		$("#add_item_form").submit();
	}
}

function post_person_form_submit(response)
{
	if (response.success)
	{
		$("#customer").attr("value", response.person_id);
		$("#select_customer_form").submit();
	}
}

function checkPaymentTypeGiftcard()
{
	if ($("#payment_types").val() == "<?php echo $this->lang->line('sales_giftcard'); ?>")
	{
		$("#amount_tendered_label").html("<?php echo $this->lang->line('sales_giftcard_number'); ?>");
		$("#amount_tendered").val('');
		$("#amount_tendered").focus();
		$("#cash").hide();
		$("#check").hide();
		$("#debit").hide();
		$("#credit").hide();
		$("#points").hide();
		$('#hide-row').show();
		$('#amount_tendered').show();
	} else if ($("#payment_types").val() == "<?php echo $this->lang->line('sales_cash'); ?>")
	{
		$("#amount_tendered_label").html("<?php echo $this->lang->line('sales_amount_tendered'); ?>");
		$("#amount_tendered").val('<?php echo to_currency_no_money($amount_due + $previous_due + $adjectment); ?>');
		$("#cash").show();
		$("#check").hide();
		$("#debit").hide();
		$("#credit").hide();
		$("#gift").hide();
		$("#points").hide();
		$('#hide-row').show();
		$('#amount_tendered').show();
	} else if ($("#payment_types").val() == "<?php echo $this->lang->line('sales_check'); ?>")
	{

		$("#amount_tendered_label").html("<?php echo $this->lang->line('sales_amount_tendered'); ?>");
		$("#amount_tendered").val('<?php echo to_currency_no_money($amount_due + $previous_due + $adjectment); ?>');
		$("#check").show();
		$("#cash").hide();
		$("#debit").hide();
		$("#credit").hide();
		$("#gift").hide();
		$("#points").hide();
		$('#hide-row').show();
		$('#amount_tendered').show();
	} else if ($("#payment_types").val() == "<?php echo $this->lang->line('sales_debit'); ?>")
	{
		$("#amount_tendered_label").html("<?php echo $this->lang->line('sales_amount_tendered'); ?>");
		$("#amount_tendered").val('<?php echo to_currency_no_money($amount_due + $previous_due + $adjectment); ?>');
		$("#credit").hide();
		$("#gift").hide();
		$("#check").hide();
		$("#cash").hide();
		$("#debit").show();
		$("#points").hide();
		$('#hide-row').show();
		$('#amount_tendered').show();
	} else if ($("#payment_types").val() == "<?php echo $this->lang->line('sales_credit'); ?>")
	{
		$("#amount_tendered_label").html("<?php echo $this->lang->line('sales_amount_tendered'); ?>");
		$("#amount_tendered").val('<?php echo to_currency_no_money($amount_due + $previous_due + $adjectment); ?>');
		$("#check").hide();
		$("#cash").hide();
		$("#debit").hide();
		$("#gift").hide();
		$("#credit").show();
		$("#points").hide();
		$('#hide-row').show();
		$('#amount_tendered').show();
	} else if ($("#payment_types").val() == "User Point") {
		$('#hide-row').hide();
		$("#amount_tendered").val('');
		$("#amount_tendered").hide();
		$("#check").hide();
		$("#cash").hide();
		$("#debit").hide();
		$("#gift").hide();
		$("#credit").hide();
		$("#points").show();
	} else
	{
		$("#amount_tendered_label").html("<?php echo $this->lang->line('sales_amount_tendered'); ?>");
	}
}




//$("#add_payment_button").click(function(){
//
//       $.ajax({
//                    type: 'POST',
//                    data: $('#add_payment_form').serialize(),
//                    url: 'index.php/sales/add_payment',
//                    success: function (resp) {
//                        if (resp) {
//                           alert('hi');
//                        }
//
//                    }
//                });
//
//
//    });
//







</script>