	<?PHP

 $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'];	
	  $data['branchid'] = $session_data['branchid'];
	 $branchid = $data['branchid'];
									
	
													  $logoutaction=$this->usermodel->populatuserpermissionsdataarray('sales','Logout',$userid);

								?>	
					  		<input type="hidden" name="printing" id="printing"  value="<?php echo set_value('printing',$logoutaction); ?>" class="form-control"  placeholder="Enter printing">


<script type="text/javascript">
$(window).load(function()
{
	  var printing = document.getElementById('printing');

	   if( window.print()) {
		 		 //window.location.href = "../user/printreceipt?invoice=<?php echo $invoiceid ?>";
//return window.location.replace("../user/viewsales");
//return window.location.replace("../user/viewsales");
$(location).attr('href','../user/viewsales');
	       window.setTimeout('window.open("../user/viewsales/","newsite")',4500);
    }else {

	 	//	return  window.location.href = "../user/printreceipT?invoice=<?php echo $invoiceid ?>";
//return window.location.replace("../user/printreceiptcopy?invoice=<?php echo $invoiceid ?>");
//return window.location.replace("../user/viewsales");

    window.setTimeout('window.open("../user/printorder?invoice=<?php echo $invoiceid ?>","newsite")',1000);	
		    // return      window.location.href = "../login";
			//   $("#next-btn").focus();

		    // document.body.innerHTML = originalContents;

	}

	
	
	
	
	 function Redirect() {
               return window.location.replace("../user/viewsales");
            }
            
           // document.write("You will be redirected to main page in 10 sec.");
      
	
	
	
});
</script>
	<script>
	var util = { };

document.addEventListener('keydown', function(e){

    var key = util.key[e.which];
    if( key ){
        e.preventDefault();
    }

   if( key === 'F5' ){        
  return  printDiv('printableArea');
    }
  if( key === 'F6' ){        
  window.location.href = "../user/viewsales";
    }

	 if( key === 'enter' ){        
return true;
    }
	
   
	
	
})


  
util.key = { 
  9: "tab",
  //13: "enter",
  16: "shift",
  12: "alt",
  27: "esc",
  33: "rePag",
  34: "avPag",
  35: "end",
  36: "home",
  37: "left",
  38: "up",
  39: "right",
  40: "down",
  112: "F1",
  113: "F2",
  114: "F3",
  115: "F4",
  116: "F5",
  117: "F6",
  112: "F7",
  119: "F8",
  120: "F9",
  121: "F10",
  122: "F11",
  123: "F12"
}
 

	</script>
<script>
	function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;
  var printing = document.getElementById('printing');

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

	 if( window.print()) {
		 if(printing=true){
			 
			  window.location.href = "../user/logout";

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

		 }
    }else {

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

		    // document.body.innerHTML = originalContents;

	}
}
	</script>
  <style type="text/css">
  


    #printable { display: none; }
#print{  	


    background-repeat: no-repeat;
	font-size;20px;

    width:100%; height:50px;



}
.doted{
    border: dotted 3px #000000;
}
table { border-collapse: collapse; }
td { padding: 5px; }
tr { border-bottom:1px dashed #494949; }


table{
    border-collapse:collapse;/*This property collapses borders together*/
}

#sale{  	
background-image:url(images/add.png) ;

    background-repeat: no-repeat;
  
    width:100px; height:50px;


}
#alltitle{ font-size: 1em; }
	#mytitle { font-size: 1.5em; }

    @media print
    {
		
    	#non-printable { display: none; }
    	#printableArea { display: block; font-size:18; width:100%; }
		  margin:0; 
		#receipt{
	font-style: normal;font-size: 2em;
	
	padding:0px;
	
}
    }
    </style>
<?PHP

 echo $this->session->flashdata('imagemsg1'); 
		 
		    
$session_data = $this->session->userdata('logged_in');


$data['surname'] = $session_data['surname'];
$data['id'] = $session_data['id'];

$surname=$data['surname'];
   $userid=$data['id'];

   $myuser=$this->usermodel->geteuser($userid);
   $firstname=$myuser[0]['firstname'];
    $postedtime = date('Y-m-d');
		$currenttime = date('h:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;	

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;
					}	

 $displaycode=$this->usermodel->populatuserpermissionsdataarray('config','productcode',$userid);
  $displaydiscount=$this->usermodel->populatuserpermissionsdataarray('sales','discount',$userid);

					
?>
 
 <div class="row">

 

   	<div class="col-md-12">
	
  
		<div class="panel panel-default" data-collapsed="0">
        	<div class="panel-heading" id="non-printable">
            	<div class="panel-title" id="redcolor" >
            		<i class="entypo-plus-circled"></i>
						 <span class="pull-right"> View Sales</span>
						 
							<div class="print-hide"  >
<form name="print" method="post" action="">
 
 <div class="row">

 

   	<div class="col-md-6">

	
  			  <a class="btn btn-primary" id="next-btn" href="<?php echo base_url(); ?>user/viewsales">Add New Sales </a>
</div>
   	<div class="col-md-6">
<input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('printableArea')" value="print receipt!" />
</form></div></div>
							</div> 
						 
						 

				
            	</div>
            </div>
				<div class="table-responsive">
			<div id="printableArea" style="width:100%;margin:0" >
<table    width="100%" >
						<thead>
							<tr>
								
								<td colspan="6"><center>
								
								<span id="mytitle"><b> COPY</b>	</span>	
								
								
										<?php $bussinessname=$configuration[0]['businessname']; if(isset($bussinessname)) {echo   $bussinessname; }?>

								</center></td>
								
								
							</tr>
								<tr>
								
								<td ><b> RECEIPT NO</td>
								
								<td colspan="5" id="mytitle">	<h4 style="padding:0; margin:0"><b>
																<?php 
																
															 $refno = $this->usermodel->populateallarray('sales','invoice',$invoiceid);

														echo $refno[0]['id']; 
																
																
																?><b></h4>
																	
																	 
															

								
								</td>
								
								
								
							</tr>
							<tr>
								
								<td ><b> REF NO:(<?php  echo$viewreceipt[0]['type'];?>)<b></td>
								
								<td colspan="5" id="mytitle">	<h4 style="padding:0; margin:0"><b>
																<?php $invoiceid; if(isset($invoiceid)) {  echo $invoiceid; }?><b></h4>
																	
																	 
															

								
								</td>
								
								
								
							</tr>
							<tr>
								
									<td colspan="6" id="mytitle"><h4 style="padding:0; margin:0"><b> DATE: <?php echo$postedtime.";                      TIME:" ;?> <?php echo$currenttime ;?><b> <span class="pull-right"> 
													 <?php $mytable=$viewreceipt[0]['mytable']; if(($mytable!="")) {echo "Table No:".$mytable; }?>
													 </span> </h4></td>
								
							</tr>
						
							
							
							<?php $customer=$viewreceipt[0]['customer'];
							$customername=$viewreceipt[0]['name'];
						 if(($customer!=0)&&($customer!="")){
							 	 ?><tr><td colspan="6"  id="mytitle"> WAITER/CUSTOMER:
							<?php
							$mysupplier=$this->usermodel->populateallarray('people','id', $customer);
						$myname=$mysupplier[0]['company'].''.$mysupplier[0]['firstname'];
						echo strtoupper($myname);
						?>
						</td></tr><?php
						 }else  if(($customername!=0)||($customername!="")){
							 	 ?><tr><td colspan="6"  id="mytitle"> WAITER/CUSTOMER:
							<?php
						
						
						echo strtoupper($customername);
						?>
						</td></tr><?php
							 
						 }
							?>
								
									
							
								
														<tr><td colspan="6" id="mytitle" ><?php $tillno=$configuration[0]['tillno']; if(isset($tillno)) {echo   $tillno; }?></td></tr>

							
							
							
						
							
							
							<tr>
							
<?php 
if($displaycode==true){
	 ?>
<td id="mytitle"><b>Code</b></td>
<td id="mytitle"><b>Item Name</b></td>
	 	<?php
		}else{?>
	<td colspan="2" id="mytitle"><b>Item Name</b></td>
 <?php
 }
 ?>
 <td id="mytitle"><b>Qty</b></td>
 <?php 
if($displaydiscount==true){
	 ?>
								<td id="mytitle"><b>Dsc</b></td>
 <?php
 }
 ?>					
								<td id="mytitle"><b>Price</b></td>
								<td id="mytitle"><b>Total</b></td>
							</tr>
						</thead>
						<?php
					
 if(!is_array($viewsales)) {
	 

			 }else{
 if(!is_array($viewsales)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='5'>";
    
    echo "</td>";
   echo "</tr>";
    }else {
 $totalcost=0;
 $total=0;
  $totalvatcost=0;
  $totalexemptedcost=0;
   $totaltax=0;
  	foreach ($viewsales as $c): 
 $total=$c->qty *$c->sprice;
		$totalcost= $totalcost+$total;

		 

             ?>
				                    <tbody>
									
										 
												
											<tr>
											
											<?php 
if($displaycode==true){
	 ?>
									<td id="mytitle"><?php echo $c->code ; ?></td>

													    <td id="mytitle"><?php ; 
	 $receiptdescription=$configuration[0]['receiptdescription'];
   $customer=$c->code;
   if($customer!=""){
	  
      $productname = $this->usermodel->geteproductbyid($customer);
  
     echo$name=strtoupper($productname[0]['name']); if($receiptdescription=="yes"){ echo"-".$description=strtoupper($productname[0]['description']);}

	
   }else{
	    echo "No Product";  
   }
  
  
  ?></td>
	 	<?php
		}else{?>
	
	
													    <td  colspan="2" id="mytitle"><?php ; 
	 $receiptdescription=$configuration[0]['receiptdescription'];
   $customer=$c->code;
   if($customer!=""){
	  
      $productname = $this->usermodel->geteproductbyid($customer);
  
     echo$name=strtoupper($productname[0]['name']); if($receiptdescription=="yes"){ echo"-".$description=strtoupper($productname[0]['description']);}

	
   }else{
	    echo "No Product";  
   }
  
  
  ?></td>
 <?php
 }
 ?>
										<td id="mytitle"><?php echo $c->qty ; ?></td>
										
										 <?php 
if($displaydiscount==true){
	 ?>
	<td id="mytitle"><?php echo $c->discount ; ?></td>
 <?php
 }
 ?>	
										
										
										 	 <td id="mytitle"><?php echo $c->sprice ; ?></td>
											 	 <td id="mytitle"><b><?php echo $c->amount ; 
												 //$totalcost=$totalcost+$c->amount ;
												 $totaltax=$totaltax+$c->tax ;
												 $mytaxrate=$c->tax ;
												 
												 if(($mytaxrate!=0)||($mytaxrate!="")){
													 
													 $totalvatcost=$totalvatcost+$c->amount;
												 }
												  if(($mytaxrate==0)||($mytaxrate=="")){
													 
													 $totalexemptedcost=$totalexemptedcost+$c->amount;
												 }

												 ?></td>
											</tr>
										<?php endforeach;} ?>

              <?php }?>	
			  
								
								<tr>
								
								<td colspan="4" id="mytitle"><b>TOTAL AMOUNT<b></td>
								
								<td colspan="2" id="mytitle" ><b>
								<?php //$total=$viewreceipt[0]['total']; 
								if(isset($totalcost)) {echo   formatMoney($totalcost, true); }
								 $finalmaindiscount=$viewreceipt[0]['maindiscount'];
								 
								?>
								
								<b>
								
								</td>
							
							</tr>
							
							
							
							
							
							
							
							
							
							<?php
							 if($finalmaindiscount>0){
								 
							 
							?>
								<tr>
								
								<td colspan="6" id="mytitle"><b>GRAND DISCOUNT</b>
								
								<?php $maindiscount=$viewreceipt[0]['maindiscount']; if(isset($maindiscount)) {echo   formatMoney($maindiscount, true); }?>
								
								
								
								</td>
							
							</tr>
							
							<tr>
								
								<td colspan="6" id="mytitle"><b>GRAND TOTAL</b>
								
								
								<?php $discountedtotal=$viewreceipt[0]['discountedtotal']; if(isset($discountedtotal)) {echo   formatMoney($discountedtotal, true); }?>
								
								
								
								</td>
							
							</tr>
							
							
							
							
								<?php
							
								 
							 }
							  $mybalance=$viewreceipt[0]['balance']; 
							 $cash=$viewreceipt[0]['cash']; 
							 $mpesa=$viewreceipt[0]['mpesa']; 
							  $card=$viewreceipt[0]['card']; 
								$voucher=$viewreceipt[0]['voucher']; 
							 $credit=$viewreceipt[0]['credit']; 
							  $cheque=$viewreceipt[0]['cheque']; 
							  $points=$viewreceipt[0]['points']; 

							$totalcash=$cash+ $mpesa+$card+$voucher+$credit+$cheque+$points;


							?>
							
							<?php if ($cash>0)
							{
								
							?>
								<tr>
								
								<td colspan="4" id="mytitle" ><b>CASH</b></td>
								
								<td colspan="2" id="mytitle"><b>
								<?php
								if($mybalance > 0){
									 echo$cash+$mybalance;
								}else{
									 echo$cash;
								}
								
								
								?>
								</td></b>
							
							</tr>
							
							<?php 
							}
								
							?>
							
								<?php if ($card>0)
							{
								
							?>
								<tr>
								
								<td colspan="4" id="mytitle"><b>CARD</b></td>
								
								<td colspan="2" id="mytitle"><b>
								<?php echo$card?></b>
								</td>
							
							</tr>
							
							<?php 
							}
								
							?>
								<?php if ($cheque>0)
							{
								
							?>
								<tr>
								
								<td colspan="4" id="mytitle"><b>CHEQUE</b></td>
								
								<td colspan="2" id="mytitle"><b>
								<?php echo$cheque?></b>
								</td>
							
							</tr>
							
							<?php 
							}
								
							?>	<?php if ($mpesa>0)
							{
								
							?>
								<tr>
								
								<td colspan="4" id="mytitle"><b>MPESA</b></td>
								
								<td colspan="2" id="mytitle"><b>
								<?php echo$mpesa?></b>
								</td>
							
							</tr>
							
							<?php 
							}
								
							?>	<?php if ($credit>0)
							{
								
							?>
								<tr>
								
								<td colspan="4" id="mytitle"><b>CREDIT</b></td>
								
								<td colspan="2" id="mytitle"><b>
								<?php echo$credit?></b>
								</td>
							
							</tr>
							
							<?php 
							}
								
							?>	<?php if ($voucher>0)
							{
								
							?>
								<tr>
								
								<td colspan="4" id="mytitle"><b>VOUCHER</b></td>
								
								<td colspan="2" id="mytitle"><b>
								<?php echo$voucher?></b>
								</td>
							
							</tr>
							
							<?php 
							}
								
							?>	<?php if ($points>0)
							{
								
							?>
								<tr>
								
								<td colspan="4" id="mytitle"><b>L POINTS</b></td>
								
								<td colspan="2" id="mytitle"><b>
								<?php echo$points?></b>
								</td>
							
							</tr>
							
							<?php 
							}
								
							?>
							
							
								<tr>
								
								<td colspan="4"><b>CHANGE</b></td>
								
								<td colspan="2" id="mytitle"><b>
								<?php
								
									 if(isset($mybalance)) {echo formatMoney($mybalance, true) ;}	
								?>
								</b></td>
							
							</tr>
								
							<?php
						$display1=$configuration[0]['display1']; 
						if(	$display1=="yes"){
						
						?>
							
								<tr>
								
								<td ><B>TAX RATE </B></td>
									<td ><B>VAT AMT</B>
								
								</td>
								<td colspan="2"><B>VATABLE AMT </B></td>
								
							<td colspan="2" ><B>EXEMPT  AMT</B></td>
							
							</tr>
							
								<tr>
								<td id="mytitle"><b>
							<?php $tax1rate=$configuration[0]['tax1rate']; if(isset($tax1rate)) {echo  formatMoney($tax1rate, true) ;}?>%
								
								</b></td>
							
								
								<td id="mytitle"><b>
								<?php if(isset($totaltax)) {  echo formatMoney($totaltax, true) ;}?>
								</b>
								</td>
								<td colspan="2" id="mytitle"><b>
							<?php if(isset($totalvatcost)) { $vatable=($totalvatcost-$totaltax);echo formatMoney($vatable, true) ; }?>
								
								</b></td>
								<td colspan="2" id="mytitle"><b>
								<?php if(isset($totalexemptedcost)) {  echo formatMoney($totalexemptedcost, true) ;}?>
								</b>
								</td>
							</tr>
							<tr>
								<td colspan="2" id="mytitle"> <b> TOTAL AMOUNT</b></td>

								
								
							<td colspan="4" id="mytitle"> <b>
															<?php //$total=$viewreceipt[0]['total'];
															if(isset($totalcost)) {echo   formatMoney($totalcost, true); }?>
											
									</b>
							</td>
							
							</tr>
							
							
							
							
							
									<?php
									}
									?>
							
							<tr>	<td colspan="6"><H3>SERVED BY:
																	<?php $myuserid=$viewreceipt[0]['userid']; $myuser=$this->usermodel->populateallarray('people','id', $myuserid);
								$myfirstname=$myuser[0]['firstname'];
							echo strtoupper($myfirstname);?>
																	<?php 
															 $countbranch=$this->usermodel->countbranches($companyid);
															 if( $countbranch>1){
																 
																 
															


																		// $mytype=$c->type;

													 $branches= $this->usermodel->populateall('branch','id',$branchid);



								if(is_array($branches)) {

								   foreach($branches as $branches){

								   echo "<b>(".strtoupper($branches->name).")</b>";
								 
								 
								}
								
								} else {
									
							echo '<b>( No  Branch )</b>';

								}
			 }
								
																										
											
																?></H3> </td></tr>
							
				
									</tbody>
									
									
					</table>
			<div style="text-align: center; margin-top: 8px; text-size:12px ">
			<p>
					 <?php
					 
						$barcode=$configuration[0]['barcode']; 
						
						
					
																	 if(isset($invoiceid) && ($barcode=="yes")) {  
																	 ?>
								<img src="<?php echo base_url().'Systemusers/barcode/'.$invoiceid; ?>" alt="">

																	 <?php
																	}

																	
																	?>
																	</p>
<?php $returnpolicy=$configuration[0]['returnpolicy']; if(isset($returnpolicy)) {echo   $returnpolicy; }?><br>
Developed by Robisearch LTD (0780655987)<br>
.............*******...............
</div>
					
					
					
					
				</div>
			</div>
			</div>
		</div>
  
  </div>
 </div>
 </div> 
			
			
		
		

















