<style>
    #suspended_sales_table th {
        background: #555;
        padding: 5px;
        color: #fff;
    }
    #suspended_sales_table tr td, #suspended_sales_table tr th{
        border: solid #CCC 1px;
    }
    input[type='submit']:hover{
        cursor: pointer;
    }
    .custom-td{
        padding: 0 !important;
    }
    #product-lot{
        padding: 0 !important;
        margin: 0 !important;
        table-layout: fixed;
    }
    #product-lot td{
        padding: 0 !important;
        margin: 0 !important;
    }
</style>

<?php 
if(trim($sale_items[0]->receipt_no)){
?>
  <?php echo form_open("sales/complete", array('id' => 'finish_sale_form')); ?>
  
<strong><?php echo "Invoice No"; ?></strong> : <?php echo $sale_items[0]->receipt_no; ?><br>
<strong><?php echo "Invoice Date"; ?></strong> : <?php echo date("d/m/Y h:i:s A",strtotime($sale_items[0]->sale_time)); ?><br>
<?php if(intval($sale_items[0]->customer_id)){?>
<strong><?php echo "Customer Name"; ?></strong> : <?php echo $sale_items[0]->customer_name; ?><br>
<strong><?php echo "Customer Phone No"; ?></strong> : <?php echo $sale_items[0]->phone_number; ?><br>
<?php
if($sale_items[0]->previous_due>=0){
?>
<strong><?php echo "Customer Previous Due"; ?></strong> : <?php echo $sale_items[0]->previous_due; ?><br>
<?php	
}else{
?>
<strong><?php echo "Customer Advance"; ?></strong> : <?php echo abs($sale_items[0]->previous_due); ?><br>
<?php
}
}
?>
 <?php
  echo "<div class='small_button' id='finish_sale_button' style='float:left;margin-top:5px;'><span>" . "Delivery" . "</span></div>";
  ?>
  </br>
  
  <table style="border: 1px solid #000; width:100%">
	            <tr>
		            <th colspan="3" style="text-align:center; background-color: #00ff00;border: 1px solid #000; width:100%">
		            BAG
		            </th> 
	            </tr>
             	<tr>
		            <th style="text-align:center; background-color: #00ff00;border: 1px solid #000; width:33%">
		            Big
		            </th>
		           <th style="text-align:center; background-color: #00ff00;border: 1px solid #000; width:33%">
		            Medium
		            </th>  
		            <th style="text-align:center; background-color: #00ff00;border: 1px solid #000; width:33%">
		            Small
		            </th> 
	            </tr>
            	<tr>
		            <th style="text-align:center; background-color: #008148;border: 1px solid #000; width:33%">
		            <?php echo form_input(array('name' => 'bag_big', 'value' => $bag_big, 'size' => '2'));?>
		            </th>
		           <th style="text-align:center; background-color: #008148;border: 1px solid #000; width:33%">
		            <?php echo form_input(array('name' => 'bag_medium', 'value' => $bag_medium, 'size' => '2'));?>
		            </th>  
		            <th style="text-align:center; background-color: #008148;border: 1px solid #000; width:33%">
		             <?php echo form_input(array('name' => 'bag_small', 'value' => $bag_small, 'size' => '2'));?>
		            </th> 
	            </tr>
            
            </table>
  
        </br>     
            
<table id="suspended_sales_table" width="100%" border="1" style="border: 1px solid #000000;border-collapse: collapse;">
   <tr>
                        <th style="width:10%;text-align:center;border: 1px solid #000000;"><?php echo $this->lang->line('sales_item_number'); ?></th>
                        <th style="width:17%;border: 1px solid #000000;"><?php echo $this->lang->line('common_price'); ?></th>
                        <th style="width:16%;border: 1px solid #000000;text-align:center;"><?php echo $this->lang->line('sales_quantity'); ?></th>
                        <th style="width:16%;border: 1px solid #000000;text-align:center;"><?php echo $this->lang->line('sales_discount'); ?></th>
                        <th style="width:17%;border: 1px solid #000000;text-align:right;"><?php echo $this->lang->line('sales_total'); ?></th>
                    </tr>
                    
                    
        <?php
        
        $color_code[0]="#B6ABAB";
        $color_code[1]="#DDD";
        
        $start=0;
        
        $total_qty=0;
        foreach ($sale_items as $key => $value) {
        	$total_qty+=$value->quantity_purchased;
        	$total_amount+=$value->total_sale_amount;
        	
        	$color_count=$start%2;
        	
        	?>
        	 <tr style="background-color:<?php echo $color_code[$color_count];?>;">
        		 <td style="border: 1px solid #000000;text-align:center">
        			 <?php echo $value->stock_id;?>
        		 </td>
        	  	 <td style="border: 1px solid #000000; text-align:right;">
        			 <?php echo number_format($value->item_cost_price, 2, '.', ',');?>
        		 </td>
        	 
        	  <td style="border: 1px solid #000000; text-align:center;">
        			 <?php echo $value->quantity_purchased;?>
        		 </td>
        	  <td style="border: 1px solid #000000; text-align:center;">
        			 <?php echo $value->discount_percent;?>
        		 </td> 
        		<td style="border: 1px solid #000000; text-align:right;">
        			 <?php echo number_format($value->total_sale_amount, 2, '.', ',');?>
        		 </td>
        	 </tr>
        	 
        	 <tr style="background-color:<?php echo $color_code[$color_count];?>;">
        	  <td colspan="5" style="border: 1px solid #000000;text-align:left;">
        			 <?php 
        			 if(trim($value->item_size)){
        			 	 echo $value->category_description." - ". $value->item_description." - ".$value->item_size." <font style='font-weight:bold;'>LOT NO : </font>".$value->lot_no; 
        			 }else{
        			 	 echo $value->category_description." - ". $value->item_description." <font style='font-weight:bold;'>LOT NO : </font>".$value->lot_no; 
        			 }
        			 ?>
        		 </td>
        	 </tr>
        	 
        	 
       <?php 	
       $start++;
        }
        
        
        
        ?>      
        
         
            <tr>
        		 <th  colspan="2" style="border: 1px solid #000000;text-align:right;background-color:#555;">
        			 Total
        		 </th>
        	 
        	  <td style="border: 1px solid #000000; text-align:center;">
        			 <?php echo $total_qty;?>
        		 </td>
        	  <td style="border: 1px solid #000000; text-align:center;">
        			 <?php echo "";?>
        		 </td> 
        		<td style="border: 1px solid #000000; text-align:right;">
        			 <?php echo number_format($total_amount, 2, '.', ',');?>
        		 </td>
        	 </tr>         
        	 
  </table>   
<?php echo form_hidden('global_delivery_shawpon', 1); ?>
<?php echo form_hidden('global_delivery_receipt_no', $sale_items[0]->receipt_no); ?>
  </form>
  
 <?php
}else{
 ?>

<strong style="width:100%;font-size:20px; color:#FF0000;text-align:center;font-weight:bold;">INVALID INFORMATION/ALREADY DELIVERED </strong>
 <?php
}
 ?>
 


<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').bind('keyup', function() {

		var itemLength = $("#item").val().length;
		if(itemLength==14){
			if($("#item").val().match(/^\d+$/)) {
				$('#add_item_form').submit();
			}
		}
	});

	$("#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_delivery_global_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();
	}
}
</script>