	<?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'];	
	
													  $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()) {
		 if(printing=true){
			 
			  window.location.href = "../user/logout";

		 }else{
			         window.location.href = "../user/viewsales";
					  $("#next-btn").focus();
 		alert(" printing...........");

		 }
    }else {

	
		      return      window.location.href = "../user/viewsales";
			   $("#next-btn").focus();

		    // document.body.innerHTML = originalContents;

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


}

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

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


}
    @media print
    {
    	#non-printable { display: none; }
    	#printableArea { display: block; font-size:18; width:100%; }
    }
    </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('discount','sales',$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%" >
<table   border="1"  width="100%" >
						<thead>
							<tr>
								
								<td colspan="6"><center><b>
										<?php $bussinessname=$configuration[0]['businessname']; if(isset($bussinessname)) {echo   $bussinessname; }?>

								</b></center></td>
								
								
							</tr>
							<tr>
								
								<td ><b>RECEIPT NO:(<?php  echo$viewreceipt[0]['type'];?>)<b></td>
								
								<td colspan="5"><b>
																	<?php $invoiceid; if(isset($invoiceid)) {echo   $invoiceid; }?>
	
								
								<b></td>
								
							</tr>
							<tr>
								
								<td><b>DATE:<b></td>
								
								<td colspan="5"><b><?php echo$dateposted ;?><b></td>
								
							</tr>
						
							
							
							<?php $customer=$viewreceipt[0]['customer'];
							$customername=$viewreceipt[0]['name'];
						 if(($customer!=0)&&($customer!="")){
							 ?><tr><td>CUSTOMER:</td><td colspan="5">
							<?php
							$mysupplier=$this->usermodel->populateallarray('people','id', $customer);
						echo$myname=$mysupplier[0]['company'].''.$mysupplier[0]['firstname'];
						?>
						</td></tr><?php
						 }else  if(($customername!=0)||($customername!="")){
							 	 ?><tr><td>CUSTOMER:</td><td colspan="5">
							<?php
						
						
						echo$customername;
						?>
						</td></tr><?php
							 
						 }
							?>
							<tr><td colspan="6"><?php $tillno=$configuration[0]['tillno']; if(isset($tillno)) {echo   $tillno; }?></td></tr>
								
									
									<tr><td>SERVED BY:</td>	<td colspan="5"><?php echo $firstname;?></td></tr>
								
							
							
							
							
							
							
							
							
							<tr>
							
<?php 
if($displaycode==true){
	 ?>
<td>Code</td>
<td>Item Name</td>
	 	<?php
		}else{?>
	<td colspan="2">Item Name</td>
 <?php
 }
 ?>
 <td>Qty</td>
 <?php 
if($displaydiscount==true){
	 ?>
								<td>Disc %</td>
 <?php
 }
 ?>					
								<td>Price</td>
								<td>Total</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;
  $totalvatcost=0;
  $totalexemptedcost=0;
   $totaltax=0;
  	foreach ($viewsales as $c): 

		 

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

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

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

	
   }else{
	    echo "No Product";  
   }
  
  
  ?></td>
 <?php
 }
 ?>
										<td><?php echo $c->qty ; ?></td>
										
										 <?php 
if($displaydiscount==true){
	 ?>
	<td><?php echo $c->discount ; ?></td>
 <?php
 }
 ?>	
										
										
										 	 <td><?php echo $c->sprice ; ?></td>
											 	 <td><?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"><b> TOTAL AMOUNT</b></td>
								
								<td colspan="2"><b>
								<?php $total=$viewreceipt[0]['total']; if(isset($total)) {echo   formatMoney($total, true); }
								 $finalmaindiscount=$viewreceipt[0]['maindiscount'];
								?> </b>
								
								
								
								</td>
							
							</tr>
							<?php
							 if($finalmaindiscount>0){
								 
							 
							?>
								<tr>
								
								<td colspan="4"><b>GRAND DISCOUNT</b></td>
								
								<td colspan="2">
								<?php $maindiscount=$viewreceipt[0]['maindiscount']; if(isset($maindiscount)) {echo   formatMoney($maindiscount, true); }?>
								
								
								
								</td>
							
							</tr>
							
							<tr>
								
								<td colspan="4"><b>GRAND TOTAL</b></td>
								
								<td colspan="2">
								<?php $discountedtotal=$viewreceipt[0]['discountedtotal']; if(isset($discountedtotal)) {echo   formatMoney($discountedtotal, true); }?>
								
								
								
								</td>
							
							</tr>
							
							
							
							
								<?php
							
								 
							 }
							?>
							
							
								<tr>
								
								<td colspan="4"><b>CASH</b></td>
								
								<td colspan="2">
								<?php $cash=$viewreceipt[0]['cash']; if(isset($cash)) {echo formatMoney($cash, true);}?>
								</td>
							
							</tr>
							
								<?php
								if($cash>0){
							
							
								?>
							
							
								<tr>
								
								<td colspan="4"><b>CHANGE</b></td>
								
								<td colspan="2">
								<?php
								if($finalmaindiscount>0){
									 $chage=$cash-$discountedtotal; 
									if(isset($chage)) {echo formatMoney($chage, true) ;}
								}else{
									 $chage=$cash-$total; 
								if(isset($chage)) {echo formatMoney($chage, true) ;}	
								}
								
								?>
								</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>
							<?php $tax1rate=$configuration[0]['tax1rate']; if(isset($tax1rate)) {echo  formatMoney($tax1rate, true) ;}?>%
								
								</td>
							
								
								<td>
								<?php if(isset($totaltax)) {  echo formatMoney($totaltax, true) ;}?>
								
								</td>
								<td colspan="2">
							<?php if(isset($totalvatcost)) { $vatable=($totalvatcost-$totaltax);echo formatMoney($vatable, true) ; }?>
								
								</td>
								<td colspan="2">
								<?php if(isset($totalexemptedcost)) {  echo formatMoney($totalexemptedcost, true) ;}?>
								
								</td>
							</tr>
							
								<tr>
								<td colspan="2"> <H2>EXPECTED TOTAL AMOUNT</H2></td>

								
								
							<td colspan="4"><H1 class="pull-right">
															<?php $total=$viewreceipt[0]['total']; if(isset($total)) {echo   formatMoney($total, true); }?>
											</H1>

							</td>
							
							</tr>
							
							
							
							
							
							
							
							
									<?php
									}
									?>
							
							
							
				
									</tbody>
									
									
					</table>
			<div style="text-align: center; margin-top: 8px; text-size:12px ">
<?php $returnpolicy=$configuration[0]['returnpolicy']; if(isset($returnpolicy)) {echo   $returnpolicy; }?><br>
Developed by Robiseach LTD (0780655987)<br>
.............*******...............
</div>
					
					
					
					
				</div>
			</div>
			</div>
		</div>
  
  </div>
 </div>
 </div> 
			
			
		
		

















