<script type="text/javascript">
$(window).load(function()
{
	window.print();
	  window.location.href = "../login";
    $("#next-btn").focus();
});
</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 = "../login";
    }

	 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;

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

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

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

		    // 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:16; 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);
   $myname=$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);
					
?>
 
 <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/viewwholesales">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 class="panel-body" id="printableArea" style="width:100%" >

			
			
						<table id="printableArea1" class="table table-bordered"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:<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>
							<tr>
								
								<td><b>CONTACT:<b></td>
								
								<td colspan="5"><b>	

								<?php $contact=$configuration[0]['contact']; if(isset($contact)) {echo   $contact; }?>,

								<?php $contact2=$configuration[0]['contact2']; if(isset($contact2)) {echo   $contact2; }?>
								<?php $email=$configuration[0]['email']; if(isset($email)) {echo   $email; }?>

									<?php $address=$configuration[0]['address']; if(isset($address)) {echo   $address; }?>,

								
								<b></td>
								
							</tr>
							
							<tr><td colspan="6"><CENTER><b><H1><?php $tillno=$configuration[0]['tillno']; if(isset($tillno)) {echo   $tillno; }?></H1><b></CENTER>
								
								</td>
							</tr>
																
<?php 
if($displaycode==true){
	 ?>
<td>Code</td>
<td>Item Name</td>
	 	<?php
		}else{?>
	<td colspan="2">Item Name</td>
 <?php
 }
 ?>
								
								<td>Qty</td>
								<td>Disc %</td>
								<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;
  
  	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>
													<td><?php echo $c->discount ; ?></td>
										 	 <td><?php echo $c->sprice ; ?></td>
											 	 <td><?php echo $c->amount ; 
												 $totalcost=$totalcost+$c->amount ;
												 ?></td>
											</tr>
										<?php endforeach;} ?>

              <?php }?>	
			  
								<tr>
								
								<td colspan="4"><b>Expected Total</b></td>
								
								<td colspan="2">
								<?php $total=$viewreceipt[0]['total']; if(isset($total)) {echo   formatMoney($total, true); }
								 $finalmaindiscount=$viewreceipt[0]['maindiscount'];
								?>
								
								
								
								</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>
								<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>TAX RATE</td>
									<td colspan="3">VAT AMT
								
								</td>
								<td colspan="3">VATABLE AMT</td>
								
							
							
							</tr>
							
								<tr>
								<td>
							<?php $tax1rate=$configuration[0]['tax1rate']; if(isset($tax1rate)) {echo  formatMoney($tax1rate, true) ;}?>%
								
								</td>
							
								
								<td colspan="3">
								<?php if(isset($total)) { $vat=($total* 0.16);  echo formatMoney($vat, true) ;}?>
								
								</td>
								<td colspan="3">
							<?php if(isset($total)) { $vatable=($total* 0.84);echo formatMoney($vatable, true) ; }?>
								
								</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>

Thank you for your continued support<br>
You have been served by : <?php echo $myname;?><br>
Developed by Robiseach LTD (0716413386)<br>
.............*******...............
</div>
					
					
					
					</div>
				</div>
			
			</div>
		</div>
  
  </div>
 </div>
 </div> 
			
			
		
		

















