<link href="<?php echo base_url(); ?>assets/autocomplete/jquery-ui.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/autocomplete/ui.theme.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/autocomplete/autocomplete.css" rel="stylesheet">


<script>

function getfirstone(){
 //alert(3333);
 
					    	 var firstone = document.getElementById('firstone').value;
							 var secondone = document.getElementById('secondone').value;
							 var tt = document.getElementById('ttqty').value;

							 
						var correctqty = parseFloat(tt);
var myfirst = parseFloat(firstone);
var mysecond = parseFloat(secondone);
 if (myfirst !== "") {

var nextretailprice = (correctqty-myfirst);


		   $("#secondone").val(nextretailprice); 
		   
 }else{
	 
	 
	 		   $("#secondone").val(0.00); 

	 
 }
}







function getsecondone(){
 //alert(3333);
 
					    	 var firstone = document.getElementById('firstone').value;
							 var secondone = document.getElementById('secondone').value;
							 var tt = document.getElementById('ttqty').value;

							 
						var correctqty = parseFloat(tt);
var myfirst = parseFloat(firstone);
var mysecond = parseFloat(secondone);
 if (mysecond !== "") {

var nextretailprice = (correctqty-mysecond);


		   $("#firstone").val(nextretailprice); 
		   
 }else{
	 
	 
	 		   $("#firstone").val(0.00); 

	 
 }
}









    function selectAllCheckBoxes(obj){
        $('input:checkbox:not(:disabled).checkBoxInLoop').prop('checked', jQuery(obj).prop('checked'));
    }

    function unselectCheckBoxUnik(){

        /*first you verify if the quantity of checkboxes equals number of checkboxes*/
        a = $('input:checkbox:not(:disabled).checkBoxInLoop:checked').size();
        b = $('input:checkbox:not(:disabled).checkBoxInLoop').size();

        /*if equals, mark a checkBoxUnik*/
        ((a == b)? $('#checkBoxUnik').prop("checked", true) : $('#checkBoxUnik').prop("checked", false));
    }

		
		
		
	function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

    // document.body.innerHTML = printContents.fontsize(12);
     window.print();

	 if( window.print()) {
         window.location.href = "../user/startsales";
		alert(" printing...........");
    }else {

	
		      return      window.location.href = "../user/startsales";

		    // document.body.innerHTML = originalContents;

	}
}



	$(document).on("click", "#invocebtn", function()
        {
          var phone = $(this).data('phone');
		  $("#phone1").val(phone); 
		   
		   		   
   var message = $(this).data('message');
		   $("#message1").val(message);
 
	
		  
		  
		   
        });
		


	$(document).on("click", "#receiptbtn", function()
        {
          var phone = $(this).data('phone');
		  $("#phone2").val(phone); 
		   
		   		   
   var message = $(this).data('message');
		   $("#message2").val(message);
 
	
		  
		  
		   
        });
		








	</script>

<style>
#big{
	font-style: normal;font-size: 1.8em;
	
}
#cash{
	font-style: normal;font-size: 1em;
	 line-height: 50%;
	padding:5px;
	
}
#discountedtotal{
	font-style: normal;font-size: 1em;
	 line-height: 50%;
	padding:5px;
	
}

#maindiscount{
	font-style: normal;font-size: 1em;
	 line-height: 50%;
	padding:5px;
	
}
#change{
		font-style: normal;font-size: 1em;
	 line-height: 50%;
	padding:5px;
	
}
</style>
	

 
            
        <script type="text/javascript">  
        $(this).ready( function() {  
            $("#id").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/LookupReturnsales",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        default:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });  
		
		
			   $(this).ready( function() {  
            $("#user3").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/customerlookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        default:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
			
		 $(document).on("click", "#managebtndelete", function()
        {
          var splitid = $(this).data('id');
		  $("#splitid").val(splitid); 
   var myinvoice = $(this).data('myinvoice');
		  $("#invoiceid").val(myinvoice); 
		   
		      var mytype = $(this).data('mytype');
		  $("#mytype").val(mytype); 
		      var ttqty = $(this).data('ttqty');
		  $("#ttqty").val(ttqty); 
		   
        });
			$(document).on("click", "#edittablebtn", function()
        {
          var myinvoice = $(this).data('myinvoice');
		  $("#myinvoice").val(myinvoice); 
		   alert("ouko");
		   		   

		    var mytable = $(this).data('mytable');
		   $("#mytable").val(mytable); 
		   
		   
		  
		  
		   
        });
		
		
		
        </script>  
		 
 <div class="row">
   	<div class="col-md-12">
	
  
		<div class="panel panel-default" data-collapsed="0">
        	<div class="panel-heading">
            	<div class="panel-title" id="redcolor" >
            		<i class="entypo-plus-circled"></i>

				
            	</div>
            </div>
			<div class="panel-body">

				<div class="widget-content nopadding table_holder table-responsive"  >		
	
		
						<?php
						
											function formatMoney($number, $fractional=false) {
						if ($fractional) {
							$number = sprintf('%.2f', $number);
						}
						while (true) {
							$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
							if ($replaced != $number) {
								$number = $replaced;
							} else {
								break;
							}
						}
						return $number;
					}
											 $session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
	    $clear=$this->usermodel->populatuserpermissionsdataarray('viewreturnsales','clear',$userid);
			    $moresales=$this->usermodel->populatuserpermissionsdataarray('sales','moresales',$userid);
			    $return=$this->usermodel->populatuserpermissionsdataarray('viewreturnsales','return',$userid);
							    $cashierreprint=$this->usermodel->populatuserpermissionsdataarray('sales','reprint',$userid);
							    $clearpayments=$this->usermodel->populatuserpermissionsdataarray('sales','clearpayments',$userid);
			    $cashiersales=$this->usermodel->populatuserpermissionsdataarray('cashiersales','all',$userid);

						$printbill=$this->usermodel->populatuserpermissionsdataarray('sales','printbill',$userid);
						$closebill=$this->usermodel->populatuserpermissionsdataarray('sales','closebill',$userid);
						$updatepaymentmode=$this->usermodel->populatuserpermissionsdataarray('sales','updatepaymentmode',$userid);
						
												$splitbills=$this->usermodel->populatuserpermissionsdataarray('sales','splitbill',$userid);

						
						 $salesdetails = $this->usermodel->populateallarray('sales','invoice',$salesid);
		 	  $mycustomer=$salesdetails[0]['customer'];	
			  
			     $duedate = date("d/m/Y", strtotime($salesdetails[0]['due_date']));

  $Receiptno=$salesdetails[0]['id'];	
							$people=$this->usermodel->populateallarray('people','id', $mycustomer);
							  $phone=$people[0]['phone'];	
							  
							  $mytotal = formatMoney($salesdetails[0]['total'], true); 
							  						$invoicelink= base_url()."printinvoice?refnumber=".$salesid;

						$receiptlink= base_url()."pintreceipt?refnumber=".$salesid;
						$invoicemessae="Hello, this is to inform you that your invoice worth Ksh ".$mytotal." with Invoice No ".$Receiptno."   and  REF No ".$salesid." due on ".$duedate."  has been generated. Thank you for shopping with us. Click this link to print your Digital invoice: ".$invoicelink."";
												$receiptemessage="Hello, this is to inform you that your Receipt worth Ksh ".$mytotal." with Receipt No ".$Receiptno."   and  REF No ".$salesid." has been generated.Thank you for shopping with us. Click this link to print your Digital Receipt: ".$receiptlink."";


					  $mydate=date("Y-m-d H:i:s");
					  $fromdate=date("Y-m-d 00:00:00");
?>
					
					
				
					<div class="table-responsive">
						<table id="register" class="table table-bordered " width="100%" >
						<thead>
							<tr>
								<th colspan="5" width="70%">Receipt Number
								
								
						
												
												

	 <a class="btn btn-warning invocebtn" id="invocebtn" data-phone='<?php echo  $phone;?>'   data-message='<?php echo  $invoicemessae;?>'  data-id='<?php echo  $salesid;?>' data-toggle='modal' data-target='#addinvoicesmsModal'> 	 

                                                <i class="glyphicon glyphicon-pencil"></i>
																Send invoice sms
                                                </a>
                                              										                              <a  id="more" class="btn btn-success" href="https://api.whatsapp.com/send?phone=<?php echo  $phone;?>&text=<?php echo  $invoicemessae;?>&source=&data=&app_absent="> Whatsapp Invoice </a>
       
												
												
												
												
												
									 <a class="btn btn-warning receiptbtn" id="receiptbtn" data-phone='<?php echo  $phone;?>'   data-message='<?php echo  $receiptemessage;?>'  data-id='<?php echo  $salesid;?>' data-toggle='modal' data-target='#addreceiptsmsModal'> 	 

													


                                                <i class="glyphicon glyphicon-pencil"></i>
																Send Receipt sms
                                                </a>
								
								
								

																		                              <a  id="more" class="btn btn-success" href="https://api.whatsapp.com/send?phone=<?php echo  $phone;?>&text=<?php echo  $receiptemessage;?>&source=&data=&app_absent="> Whatsapp Receipt </a>

								</th>
							
								<th colspan="5" width="30%">Add</th>
								
								
							</tr>
								<tr>
								<th  colspan="5" width="70%">
					<?php
	 echo $this->session->flashdata('msg'); 

                 echo form_open('user/searchinvoice' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>


			  		<input type="hidden" name="type" value="<?php echo set_value('type','cashcash'); ?>" class="form-control" required placeholder="Enter type">
			  		<input type="hidden" name="salestype" value="retail" class="form-control" required placeholder="Enter sales type">
								<input type="hidden" name="view" value="user/searchinvoice?code=<?php $salesid ;?>" id="view" class="form-control" required placeholder="Enter view">

		  		<input type="text" name="code" id="id" autofocus value="<?php echo set_value('code'); ?>" class="form-control" required placeholder="Search Sales by Receipt by number">
		 
								</th>
								
							
								<th colspan="4" width="30%">
								<button type="submit"  value="sale" name="btn_addsale" class="btn btn-default"> Search the invoice by number   </button>
		                              <a  id="more" class="btn btn-default" href="<?php echo base_url();?>user/viewreturnsales"> Refresh/Next </a>

 
  					<?php echo form_close();?>
								
								</th>
								<th 	 colspan="1">
																	<a data-toggle='modal' data-target='#customergroupModal' class="btn btn-default">Search by Customer  </a>

								</th>
				
								
							</tr>
							
												<?php
								 	$myinvoice = $userid.time();

		
                 echo form_open('user/splitsale' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>		

<input type="hidden" name="myinvoice" value="<?php echo $myinvoice; ?>"  class="form-control" required placeholder="Enter view">
		<input type="hidden" name="view" value="user/splitbill" id="view" class="form-control" required placeholder="Enter view">
<input type="hidden" name="myview" value="user/searchinvoice?code=<?php if(isset($salesid)) {echo $salesid;  }?>" id="view" class="form-control" required placeholder="Enter view">
							
								<tr>
								
									       
    	 <th> 
		 <input type="checkbox" onclick="selectAllCheckBoxes(this)" id="checkBoxUnik"/>All
		</th>
								
								<th>Code</th>
								<th width="40%">Item Name</th>

								<th>Qty</th>
																	<th>S/N</th>

								<th>Disc/date</th>
								<th>S Price</th>
								<th>Total</th>
								<th>Vat</th>
								<th colspan="3">
								
									<?php
	

		 if($splitbills==true){
	 ?>
		     
			         <button type="submit"  value="split" name="splitbill" class="btn btn-default"> Split Bill  </button>
<?php

		 }
?>
								
								</th>
									
							</tr>
						</thead>
						<?php
						
					  $view="";
					  if(is_array($viewreceipt)) 

 {
	

if ($salestype=="wholesale"){
		
	  $view="user/viewwholesales";
}else if ($salestype=="retail"){

	 $view="user/viewsales";

}else{
	 $view="user/viewsales";
	
}
$mybalance=0;
$mycash=0;
$myamount=0;
   $correctime=$viewreceipt['0']['updatedat'];
   	    $myamount=$viewreceipt['0']['paymentstatus'];
   	    $updatedby=$viewreceipt['0']['updatedby'];

	    $mycash=$viewreceipt['0']['cash'];
		 $mybalance=$viewreceipt['0']['balance'];
	    $type=$viewreceipt['0']['type'];
			    $branchid=$viewreceipt['0']['branch'];

		   $salestype=$viewreceipt['0']['type'];
		    $mytable=$viewreceipt['0']['mytable'];
		    $description=$viewreceipt['0']['description'];
    $discountedtotal=$viewreceipt['0']['discountedtotal'];
       $mytotal=$viewreceipt['0']['total'];

    }
 if(!is_array($viewreturnsales)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='8'>";
	       //echo '<div class="alert alert-default text-center">The receipt is availabel with no products sold/found..</div>';

    echo "</td>";
   echo "</tr>";
    }else {
 $totalcost=0;
   $totaltaxt=0;
  	foreach ($viewreturnsales as $c): 
      ?>
				                    <tbody >
									
										 
											
											<tr>
											 <td>
			<input class="btn btn-default" name="selector[]" type="checkbox" onclick="unselectCheckBoxUnik()" class="checkBoxInLoop" value="<?php echo $c->id ; ?>">
				</td>
											
																							    <td><?php ; 
													
   $customer=$c->code;
   if($customer!=""){
	  
      $productname = $this->usermodel->geteproductbyid($customer);
  
?>
 <a class="btn default editbtn" id="editbtn"data-tax_included='<?php echo  $productname[0]['tax_included'];?>' data-expdate='<?php echo  $productname[0]['expdate'];?>'data-store='<?php echo  $productname[0]['store'];?>' 	 data-orderamount='<?php echo  $productname[0]['orderamount'];?>' data-supplier='<?php echo  $productname[0]['supplier'];?>'  data-category='<?php echo  $productname[0]['category'];?>'  data-buyingprice='<?php echo  $productname[0]['buyingprice'];?>' data-sellingprice='<?php echo  $productname[0]['sellingprice'];?>'data-promoprice='<?php echo  $productname[0]['promoprice'];?>'  data-wholesaleprice='<?php echo  $productname[0]['wholesaleprice'];?>' data-code='<?php echo  $productname[0]['code'];?>' data-qty='<?php echo  $productname[0]['qty'];?>'	data-description='<?php echo  $productname[0]['description'];?>' data-name='<?php echo  $productname[0]['name'];?>'	data-reorderevel='<?php echo  $productname[0]['reorderevel'];?>'  data-id='<?php echo  $productname[0]['id'];?>' data-toggle='modal' data-target='#editProductModel'> <?php echo $productname[0]['code'] ; ?> </a>	 

<?php
	
   }else{
	    echo "No Product";  
   }

  
  ?></td>
  
											
													    <td><?php ; 
														
   $customer=$c->code;
   if($customer!=""){
	  
      $productname = $this->usermodel->geteproductbyid($customer);
  
     echo "<b>".$name=$productname[0]['name']."</b>"; 

	
   }else{
	    echo "No Product";  
   }

  
  ?></td>
												
													<td>
<input type="hidden" name="originalinvoice" value="<?php if(isset($salesid)) {echo $salesid;  }?>"  class="form-control" required placeholder="Enter originalinvoice">

											<input type="hidden" name="myid" id="myid" value="<?php echo set_value('myid',$c->id); ?>" class="form-control" required placeholder="myid" >
															  		<input type="hidden" name="price[]" readonly id="price" value="<?php echo set_value('price',$c->sprice); ?>" class="form-control" required placeholder="price" >

															  		<input type="text" name="myqty[]" readonly id="myqty" value="<?php echo set_value('myqty',$c->qty); ?>" class="form-control" required placeholder="Qty" >
</td>
													
																										<td><?php echo $c->serial ; ?></td>

													<td><?php 

if($c->discount =="0"){
	echo $c->dateposted ;
}else{
	echo $c->discount."<br>". $c->dateposted ;
}

													?></td>

										 	 <td><?php echo $c->sprice ; ?></td>
											 	 <td><?php echo $c->amount ; 
												 $totalcost=$totalcost+($c->sprice*$c->qty) ;
												 ?></td>
												 <td><?php
   $totaltaxt=$totaltaxt+$c->tax ;


												 echo $c->tax ; ?></td>
												 
												 	<td  style='color:green'> 
		<?php
		$myid=  $c->id ;
				$serial=  $c->serial ;

		 if($return==true){
	 ?>
		                              <a  id="more" class="btn btn-danger" href="<?php echo base_url();?>user/deletereturnedeproducts?randomitemidentifier=<?php   {echo  $salesid;}  ?>&transactionid=<?php   {echo  $myid;}  ?>&serial=<?php   {echo  $serial;}  ?> &type=<?php   {echo  $serial;}  ?>&salestype=<?php  $salestype;  ?>"> <span class="glyphicon glyphicon-pencil">Return</span> </a>
		                          <?php
								  if($c->qty>1){
									?>
								  <a  id="more" class="btn btn-warning" href="<?php echo base_url();?>user/splitproducts?randomitemidentifier=<?php   {echo  $salesid;}  ?>&transactionid=<?php   {echo  $myid;}  ?>&serial=<?php   {echo  $serial;}  ?> &type=<?php   {echo  $serial;}  ?>"> <span class="glyphicon glyphicon-pencil">Split</span> </a>


								 <?php
								  }
			  
								  if($c->qty>1){
									?>
	 <a class="btn btn-warning managebtn" id="managebtndelete" data-ttqty='<?php echo  $c->qty;?>' 	data-mytype='<?php echo  $salestype;?>' 	data-myinvoice='<?php echo  $salesid;?>'  data-id='<?php echo  $myid;?>'    data-toggle='modal' data-target='#myDelete<?php  $myid; ?>'>		  <span class="glyphicon glyphicon-pencil">Dbl. SplitSplit</span> </a>
 


                             

								 <?php
								  }
			

 }else{
	
 
  
 }
  ?>
		                              
									  
									  
									  
									  
									  
									  
									  
									  
									  </td> 
																	

				</tr>
										<?php endforeach;
										?>
												 	<?php echo form_close();

										
										
										} ?>

           
			 
								<tr>
							
								<th  colspan="3">Receipt No :         <?php if(isset($salesid)) {
									
									
							
	 $invoiceno = $this->usermodel->populateallarray('sales','invoice',$salesid);

   echo $invoiceno[0]['id']; 
    echo "  and  Ref No:"; 
		echo $salesid; echo"</br>"; 							
									
											if($type=="Invoice"){
												
												
												 if( $cashierreprint==true){
															?>
																		<a  id="more" class="btn btn-default" href="<?php echo base_url();?>user/printinvoice?invoice=<?php   if(isset($salesid)) {echo $salesid; } ?>&view=<?php   {echo  $view;}  ?>">  Print Invoice   </a>

								<?php 
													 
												 }else{
													 
												 }
										
								}else{
									 if( $cashierreprint==true){
									?>
<a  id="more" class="btn btn-default" href="<?php echo base_url();?>user/printpending?invoice=<?php   if(isset($salesid)) {echo $salesid; } ?>&view=<?php   {echo  $view;}  ?>&receipt=receipt">  Print Receipt   </a>
																		<a  id="more" class="btn btn-default" href="<?php echo base_url();?>user/printa4receipt?invoice=<?php   if(isset($salesid)) {echo $salesid; } ?>&view=<?php   {echo  $view;}  ?>">  Print A4   </a>

<a  id="more" class="btn btn-default" href="<?php echo base_url();?>user/printpending?invoice=<?php   if(isset($salesid)) {echo $salesid; } ?>&view=<?php   {echo  $view;}  ?>&receipt=both">  Receipt & Bill   </a>

								<?php
									 }else{
										 
									 }
								}
	 if($printbill==true){
		 //
		 
		 	 if($myamount !="Cleared")  {
		 
	 ?>

			<a  id="more" class="btn btn-default" href="<?php echo base_url();?>user/printbill?invoice=<?php   if(isset($salesid)) {echo $salesid; } ?>&view=<?php   {echo  $view;}  ?>">  Print Bill   </a>

	 	<?php
	 
		 
	 }
							

 }else{
	
 }
 										


?> 										


									

							
							
												<?php

	
 if($clear==true){
	 ?>
																	<a  id="more" class="btn btn-default" href="<?php echo base_url();?>user/clearbalance?invoice=<?php   if(isset($salesid)) {echo $salesid; } ?>"> Clear Balance  </a>

	 
	 	<?php	

 }else{
	
 }
 	?>
<br><br>
<?php	

	
 if($moresales==true){
	 
	 	
		 
	 if($myamount=="Cleared")  {
		 
	 ?>


	 	<?php
	 
		 
	 } else if(($myamount=="Cleared")  && ($usertype=!"admin"))  {

		 
	 
	 
		 
	 } else if(($myamount !="Cleared") )  {
		 
	 

	 ?>
																	<a  id="more" class="btn btn-default" href="<?php echo base_url();?>user/viewmysales?invoice=<?php   if(isset($salesid)) {echo $salesid; } ?>&myview=<?php   if(isset($view)) {echo $view; } ?>"> Add Order/ Close Bill </a>


	 	<?php	
}
 }else{
	
 }
  
 }

  
 										
?>
	<a  id="more" class="btn btn-default" href="<?php echo base_url();?>user/viewmyreturnedsales?invoice=<?php   if(isset($salesid)) {echo $salesid; } ?>&myview=<?php   if(isset($view)) {echo $view; } ?>"> Post Credit Note </a>

<?php	
								
	 if($updatepaymentmode==true){
								?>
						<a  id="more" class="btn btn-info" href="<?php echo base_url();?>user/changepayment?invoice=<?php   if(isset($salesid)) {echo $salesid; } ?>"> Change Payment  </a>

									 	<?php	

 }else{
	
 }
 										
?>
					
				 
				 				<?php
		
		 if($cashiersales==true){
			?>
				 <a href="<?php echo base_url();?>user/mysales" class="btn btn-default"> Cashier sales </a>	
<?php


 }else{

 
  
 }
  ?>

				 
				 
				 
				 
				 
				 
	<?php
 if($clearpayments==true){
								?>
													<a  id="more" class="btn btn-info" href="<?php echo base_url();?>user/viewbalance?invoice=<?php   if(isset($salesid)) {echo $salesid; } ?>"> Receive Payment  </a>
				
									 	<?php	

 }else{
	
 }
?>



<a  id="more" class="btn btn-info" href="<?php echo base_url();?>user/printcreditnote?invoice=<?php   if(isset($salesid)) {echo $salesid; } ?>&view=<?php   {echo  $view;}  ?>&receipt=both">  Credit Note   </a>
												<?php

	 if($usertype=="admin"){  
?>
		<!---
	
	<a  id="more" class="btn btn-danger" target="_blank"  href="<?php echo base_url();?>user/Reconcilesale?searchterm=<?php   {echo  $salesid;}  ?>&type=<?php   {echo  $type;}  ?>&branch=<?php   {echo  $branchid;}  ?>">
						
															Reconcile GL Transactions(To be Clicked ONLY after Returning items)
                                                </a>
												-->
												
											<?php

	 }
?>											
								
								</th>
							
								<th  colspan="2"><h3>Grand Total</h3></th>

								
								<th ><H1><?php if(isset($totalcost)) {echo $totalcost; }?></H1>
								<th colspan="2" ><H3>

								Cash Paid :<?php if(isset($mycash)) {echo $mycash; }?><br>
								Balance : <?php if(isset($mybalance)) {echo $mybalance; }?><br>
								Status :<?php if(isset($myamount)) {echo $myamount; }
	if(isset($updatedby)) {

	if(($updatedby !="") && ($myamount!="No")){
									$myuser=$this->usermodel->geteuser($updatedby);
   echo " By " .$myname=$myuser[0]['firstname']." at ".$correctime;
		}
			 }					?><br>
								
								
								Table No :<?php if(isset($mytable)) {echo $mytable; }?><br>

								
	 <a class="btn btn-default edittablebtn" id="edittablebtn" data-mytable='<?php if(isset($mytable)) {echo $mytable; }?>' data-myinvoice=' <?php if(isset($salesid)) {echo $salesid; }?> ' data-toggle='modal' data-target='#editProductModel'> 	 

                                                <i class="glyphicon glyphicon-pencil"></i>
																Transfer Table
                                                </a>
								</H3>
								
								</th>
								<th>
								
								<?php if(isset($totaltaxt)) {echo $totaltaxt; }?>
							
								
								</th>
						<th colspan="3" >
									Delivery Details:<br>
									<?php if(isset($description)) {echo $description; }?><br>
											<?php 
											if($discountedtotal !=$mytotal){
												echo "<b style='color:red'> Original Amount: ". $discountedtotal ."<b>";
											}
											
											
										?>

						</th>
						
						
							</tr>
				
									</tbody>
									
									
					</table>
					
					
					
				

<?php if(isset($salesid)) {
  $salesreport = $this->usermodel->populateall('splitbillmaster','originalinvoice', $salesid);



 if(!is_array($salesreport)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='5'>";
    
    echo "</td>";
   echo "</tr>";
    }else {
?>

	<h3>Splited Bills</h3>
					
					<table border="1"  width="100%" id="sortable_table">			

             <thead>
			 		 
        
			 
         <tr>
		 
		       
<th> RCT No</th>
									<th> Ref No</th>
											 	<th> Date</th>

                                        <th>  	Total</th>
										   
                                        <th>  	Bill</th>

												
										
										

                 </tr>
             </thead>
    
             <?php 
  $total=0; 
  

  	foreach ($salesreport as $c): 

 $myinvoice=$c->invoice ; 
             ?>



             <tr>
			  
            <?php 
$id=$c->id;

$salesid=$c->invoice;
       ?>       
  
  <td><?php echo $c->id ; ?></td>
  <td><?php echo $c->invoice ; ?></td>
  <td><?php echo $c->dateposted ; ?></td>
  <td><?php 
  $getamount = $this->usermodel->populateall('sales_order','user', $c->invoice);
$ttamount=0;
if(is_array($getamount)) {

   foreach($getamount as $row)
   {
   $amount=trim($row->amount);
    $ttamount=$ttamount+ $amount;
   }
}
echo  $ttamount;
$view="user/mergebill";

  ?></td>

 
 <td>
 
 			<a  id="more" class="btn btn-default" href="<?php echo base_url();?>user/printsplitedbill?invoice=<?php   if(isset($salesid)) {echo $salesid; } ?>&view=<?php   {echo  $view;}  ?>">  Print Bill   </a>

 </td>
 
 
	 

	 
         
             </tr>

	<?php endforeach;
	?>


	
	
	
              <?php }
}?>

        </table>
					
					
					
					
					
				</div>	
			</div>
					
					
					
					
					
					
		
		</div>
  
  </div>
			
			
			
			
			
			<div id="myDelete" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">BULK SPLIT</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to Split  this item Into two? 
		
		NOTE: TOTAL QTY SHOULD BE EQUAL TO ORIGAN QTY e.g 5=(3 firt one + 2 second one);
		</h3>
      </div>
      <div class="modal-footer">
	  	

     
		<?PHP
				$session_data = $this->session->userdata('logged_in');
 echo $this->session->flashdata('deletemsg'); 

		
                 echo form_open('user/splitproductsbulk' , array('class' => 'form-horizontal ', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>
 <input type="hidden" id="table"name="table" class="table" placeholder="view" value="products">

<input type="hidden" name="type" value="product"id="mytype" class="form-control" required placeholder="Enter type">
	<input type="text" readonly name="ttqty" value=""id="ttqty" class="form-control" required placeholder="Enter type">


<input type="hidden" name="view" value="user/searchinvoice?code=<?php echo $salesid ;?>" id="view" class="form-control" required placeholder="Enter view">
 <input type="hidden" id="invoiceid"  name="invoice" class="itemid" placeholder="invoice" value=""><br>
<div class="form-group">
    <label for="inputfirstone" class="col-sm-2 control-label">	 First QTY</label>
    <div class="col-sm-10">
		
				<input type="text" name="firstone"   onblur="getfirstone()"  id="firstone" value="<?php echo set_value('firstone') ;?>"  class="form-control" required placeholder="Enter  First qty e.g 3 out of 5">

		<span class="text-danger"> <?php echo form_error('firstone'); ?>
		
		</span>
	</div>
  </div>
  <div class="form-group">
    <label for="inputsecondone" class="col-sm-2 control-label">	 Second QTY</label>
    <div class="col-sm-10">
		
				<input type="text" name="secondone"  onblur="getsecondone()"  id="secondone" value="<?php echo set_value('secondone') ;?>"  class="form-control" required placeholder="Enter  Second qty e.g 2 out of 5">

		<span class="text-danger"> <?php echo form_error('secondone'); ?>
		
		</span>
	</div>
	

  </div>
 <input type="hidden" id="splitid"  name="itemid" class="itemid" placeholder="itemid" value=""><br>
 <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
 		  	         <button type="submit" name="btn_delete" value="deletebyid" class="btn btn-danger"> Yes  </button>

	<?php echo form_close();?>
      </div>
    </div>

  </div>

  </div>
			
			
			
			
			
			
			
			
			<div id="editProductModel" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Transfer Table</h4>
      </div>
      <div class="modal-body">
      
	  	

				<?PHP
//$session_data = $this->session->userdata('logged_in');



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/updatetabletransfer' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>
	<input type="hidden" name="invoice" value="<?php if(isset($salesid)) {echo $salesid; }?>" id="myinvoice" class="form-control" required placeholder="Enter myinvoice">
											<input type="hidden" name="view" value="user/searchinvoice?code=<?php echo $salesid ;?>" id="view" class="form-control" required placeholder="Enter view">
  		
	<div class="form-group">
    <label for="inputmytable" class="col-sm-2 control-label">Orignal Table No </label>
    <div class="col-sm-10">
	
		  		<input type="text" readonly name="mytable" value="<?php if(isset($mytable)) {echo $mytable; }?>" id="mytable" class="form-control" required placeholder="Enter mytable">
		 
				
		<span class="text-danger"> <?php echo form_error('mytable'); ?>
		
		</span>
	</div>
  </div>
 
  
  
  
  
  

	<div class="form-group">
    <label for="inputnewtable" class="col-sm-2 control-label">New Table No(</label>
    <div class="col-sm-10">
		  		<input type="text" name="newtable" value="<?php echo set_value('newtable'); ?>" id="description" class="form-control" required placeholder="Enter new table No">

			
		<span class="text-danger"> Transfer to table no?<?php echo form_error('newtable'); ?>
		
		</span>
	</div>
  </div>
		

	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="transfer" name="btn_updatetransfer" class="btn btn-default"> Transfer Table   </button>

    </div>
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </div>
    </div>
					
					
					
					

						<div id="addreceiptsmsModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Add new Sms</h4>
      </div>
      <div class="modal-body">
      
	  	

				<?PHP
//$session_data = $this->session->userdata('logged_in');

//

				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/addsalessms' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>
				  		
	<div class="form-group">
    <label for="inputcontact" class="col-sm-2 control-label">	Contact </label>
    <div class="col-sm-10">

									<input type="hidden" name="view" value="user/searchinvoice?code=<?php echo $salesid ;?>" id="view" class="form-control" required placeholder="Enter view">

	<textarea name="contact" value="<?php echo set_value('contact'); ?>" id="phone2" class="form-control"  placeholder="Enter phone e.g  254712345678,254712345678"></textarea>

		
				
		<span class="text-danger"> <?php echo form_error('contact'); ?>
		
		</span>
	</div>
  </div>
  
  

	

	<div class="form-group">
    <label for="inputmessage" class="col-sm-2 control-label">	Message</label>
    <div class="col-sm-10">
		
<textarea   maxlength="800" required name="message" value="" id="message2" class="form-control" rows="3" cols="60" onFocus="countChars('textbox','char_count',0)" onKeyDown="countChars('textbox','char_count',0)" onKeyUp="countChars('textbox','char_count',0)"></textarea> <br />Characters:<span id="char_count"></span>

			
		
			
		<span class="char_count"> <?php echo form_error("message"); ?>
		
		</span>
	</div>
  </div>
		

	
	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="sms" name="btn_addsms" class="btn btn-primary"> Send SMS   </button>

    </div>
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </div>
    </div>

					
			

						<div id="addinvoicesmsModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Add new Sms</h4>
      </div>
      <div class="modal-body">
      
	  	

				<?PHP
//$session_data = $this->session->userdata('logged_in');



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/addsalessms' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>
				  		
	<div class="form-group">
    <label for="inputcontact" class="col-sm-2 control-label">	Contact </label>
    <div class="col-sm-10">
								<input type="hidden" name="view" value="user/searchinvoice?code=<?php echo $salesid ;?>" id="view" class="form-control" required placeholder="Enter view">

	
	<textarea name="contact" value="<?php echo set_value('contact'); ?>" id="phone1" class="form-control"  placeholder="Enter phone e.g  254712345678,254712345678"></textarea>

		
				
		<span class="text-danger"> <?php echo form_error('contact'); ?>
		
		</span>
	</div>
  </div>
  
  

	

	<div class="form-group">
    <label for="inputmessage" class="col-sm-2 control-label">	Message</label>
    <div class="col-sm-10">
		
<textarea   maxlength="800" required name="message" id="message1" value="pos.robisearch.com/printinvoice?refnumber=11597205277" class="form-control" rows="3" cols="60" onFocus="countChars('textbox','char_count',0)" onKeyDown="countChars('textbox','char_count',0)" onKeyUp="countChars('textbox','char_count',0)"></textarea> <br />Characters:<span id="char_count"></span>

			
		
			
		<span class="char_count"> <?php echo form_error("message"); ?>
		
		</span>
	</div>
  </div>
		

	
	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="sms" name="btn_addsms" class="btn btn-primary"> Send SMS   </button>

    </div>
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </div>
    </div>

				
			
			<div id="customergroupModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Group Sales per customer
      </div>
      <div class="modal-body">
      
	  	

				<?PHP
//$session_data = $this->session->userdata('logged_in');



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/viewproductgroupsalesreportbycustomer' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>

	 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="user/viewreturnsales">

  <div class="form-group">
    <label for="inputbranchname" class="col-sm-2 control-label">Counter</label>
    <div class="col-sm-10">
	<select class="form-control" name="branchname"  id="branchname" required>
	
	
	<option value=""  >---Select Branch/Counter Name--</option>
<?php
									 if( $viewallaction==true){
										 ?>
					<option value="all"  >All branches/Counters</option>
									<?php
									 }
							
	?>
	
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

   //echo $courserow->coursename;
    ?>
					<option selected="selected" value="<?=  $maincategoryrow->id;   ?>"><?=  $maincategoryrow->name; ?></option>



	<?php

}} else {
    echo 'No main counter available.';
}
	
?>
</select>
		

	</div>	
	</div>
		
	  <div class="form-group">
    <label for="inputuser" class="col-sm-2 control-label">Customer name</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="user" id="user3" autofocus value="<?php echo set_value('user'); ?>" class="form-control" required placeholder="Enter Customer name">
		 
				
		<span class="text-danger"> <?php echo form_error('user'); ?>
		
		</span>
	</div>
  </div>
  
	
	
	
	
	
  <div class="form-group">
    <label for="inputfromdate" class="col-sm-2 control-label">From Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="fromdate" value="<?php echo set_value('fromdate',$fromdate); ?>" class="form-control" required placeholder="Enter start date">
		 
				
		<span class="text-danger"> <?php echo form_error('fromdate'); ?>
		
		</span>
	</div>
  </div>
  
  	<div class="form-group">
    <label for="inputtodate" class="col-sm-2 control-label">	To Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="todate" value="<?php echo set_value('todate',$mydate); ?>" class="form-control" required placeholder="Enter End date">
		 
				
		<span class="text-danger"> <?php echo form_error('todate'); ?>
		
		</span>
	</div>
  </div>
  
    
     <div class="form-group">
    <label for="inputtype" class="col-sm-2 control-label">Sales type?</label>
    <div class="col-sm-10">
	<select class="form-control" name="type" required>
	<option selected="selected" value="all"  >---All/Any type--</option>
	<option value="Cash" >Cash</option>
<option value="Credit">Credit</option>
<option value="Invoice">Invoice</option>
<option value="Mpesa">Mpesa</option>
<option value="Bank">Bank</option>
	
</select>
		
						<span class="text-danger"><?php echo form_error('type'); ?>

	</div>
  </div>
   

	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="event" name="btn_addevent" class="btn btn-default"> View Sales  </button>

    </div>
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </div>
    </div>
		
  

 
</div>
	
	
			
			
				
			