
	<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/allinvoices";
    }

	 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(16);
     window.print();

	 if( window.print()) {
         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;


}

#printableArea { font-size: 1.3em;         font-weight: bold;
}

#printreceipt { font-size: 1.3em;         font-weight: bold;
}
    @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);
   $myname=$myuser[0]['firstname'];
    $postedtime = date('Y-m-d');
		$currenttime = date('h:i:sa');
 		$dateposted =  ($postedtime)." ".$currenttime ;	
 $countbranch=$this->usermodel->countbranches($companyid);

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);
 $session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
	 $data['branchid'] = $session_data['branchid'];
	 $branchid = $data['branchid'];
	 
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	

$profile = $this->usermodel->populateallarray('smsconfig','id',$companyid);

$hscode=$profile[0]['hscode'];
									$photo=$profile[0]['logo'];
									$img=$profile[0]['logo'];
											$receiptlogo=$profile[0]['receiptlogo'];


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

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
	 $data['branchid'] = $session_data['branchid'];
	 $branchid = $data['branchid'];
	 
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	

$profile = $this->usermodel->populateallarray('smsconfig','id',$companyid);

$hscode=$profile[0]['hscode'];
									$photo=$profile[0]['logo'];
									$img=$profile[0]['logo'];
											$receiptlogo=$profile[0]['receiptlogo'];


		 
?>
 
 <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="0" width="100%">
					
						<tr>
						<td colspan="1" >
 
		
		
 
								
								

				
					<center>


			<?php
			
$img1='uploads/';
	
			if($receiptlogo=="yes") {
					$url = base_url().$img1.$img;

			}else{
				 $allbranches= $this->usermodel->populateallarray('branch','id',$branchid);
					$branchlogo=$allbranches[0]['logo']; 
											
				
					$url = base_url().$img1.$branchlogo;

			}

	
if($photo!=""){
	
	?>
	
 <div>
<img class="img-circle" src="<?php echo $url ?>" height="80%" width="80%" style="border-radius:4px;margin:0px  ">		 

</div>
<?php
 
 }

 ?>
		
						</center>	
						</td> <td colspan="2">
						
						<?php 
										 if( $countbranch >1){
										 $mybranches= $this->usermodel->populateallarray('branch','id',$branchid);
										$branchdescription=$mybranches[0]['description']; if(isset($branchdescription)) {
											
											
											   echo ($branchdescription); }
											  // echo strtoupper($branchdescription); }


										}else{
 						$description=$configuration[0]['businessname']; if(isset($description)) {  echo $description; }

											 
										 }
										 $user=$this->usermodel->populateallarray('people','id', $userid);
						$donebynames=$user[0]['firstname'];
						
						
										?>
				
							
						
						
						
						</td>
						
						<td colspan="3" valign="top">
					<h1>RECEIPT 	</h1>
					
<br><br>
						 Payment Date:  <?php echo$viewbill[0]['dateposted'];?><BR>
						Receipt  No: <?php echo$viewbill[0]['id'];?><BR>

					

						Ref No:  <?php $invoiceid; if(isset($invoiceid)) {echo   $invoiceid; }?><BR>
						Payment Method:<?php  echo$viewbill[0]['type'];?><BR>
						INVOICE NO:<?php echo$viewbill[0]['invoice'];?><BR>
					 
					
					 DUE DATE :<?php echo$viewbill[0]['due_date'];?><BR>
						<BR>
						Sales Person:  <?php 
						
							$user=$this->usermodel->populateallarray('people','id', $userid);
						echo$names=$user[0]['firstname']. " ".$user[0]['surname'] ;
						
						
						?><BR>

						</td>
						
						</tr>
						
					<TR>
					<td colspan="6">
					<hr style="border-top: 2px solid gray;">

					</td>
					</TR>
						<tr>
						
					
						<td colspan="3">
						<B>Received From:</B><br>
					
							<?php 
$customer=$viewbill[0]['customer'];
							$customername=$viewbill[0]['name'];
														$mysupplier=$this->usermodel->populateallarray('people','id', $customer);

							$mysupplier=$this->usermodel->populateallarray('people','id', $customer);
						$alldetais="";
														
														
					$previousbalance=$mysupplier[0]['balance'];
					
						 
						 if($mysupplier[0]['company']!=""){
							 $alldetais.= $mysupplier[0]['company']."<br>";
						 }else{
						  if($mysupplier[0]['firstname']!=""){
							 $alldetais.= $mysupplier[0]['firstname']." ". $mysupplier[0]['surname']."<br>";
						 }	 
							 
						 }
						
						  if($mysupplier[0]['idno']!=""){
							 $alldetais.= $mysupplier[0]['idno']."<br>";
						 }
						   if($mysupplier[0]['idnumber']!=""){
							 $alldetais.= $mysupplier[0]['idnumber']."<br>";
							 //$alldetais.= "Customer pin:".$mysupplier[0]['idnumber']."<br>";



						}
						  if($mysupplier[0]['phone']!=""){
							 $alldetais.= $mysupplier[0]['phone']."<br>";
						 } if($mysupplier[0]['email']!=""){
							 $alldetais.= $mysupplier[0]['email']."<br>";
						 }
						  if($mysupplier[0]['website']!=""){
							// $alldetais= $mysupplier[0]['website']."<br>";
						 }
						  if($mysupplier[0]['zip']!=""){
							// $alldetais.= $mysupplier[0]['zip']."<br>";
						 }
						   if($mysupplier[0]['code']!=""){
							 $alldetais.= $mysupplier[0]['code']."<br>";
						 }
						 
						  if($mysupplier[0]['city']!=""){
							 $alldetais.= $mysupplier[0]['city']."<br>";
						 }
						
						  if($mysupplier[0]['comments']!=""){
							 $alldetais.= $mysupplier[0]['comments']."<br>";
						 }
						    if($viewbill[0]['description']!=""){
							// $alldetais.= $viewbill[0]['description']."<br>";
						 }
						 
						   if($customername!=""){
							 $alldetais.= $customername;
						 }
						 	
													echo "<br>".$alldetais;

						//echo "<br>".$comments=$mysupplier[0]['comments'];
							?>
						
						
						
						
						
						
						
						
						</td>
						
							<td colspan="3">
							<B>
						
						
						</B>
	
						</td>
						
						
						
							</tr>
																				
																				
																				
																				</table >
											
											
											<table  class="table table-bordered" border="0" width="100%" id="printreceipt">

							<tr>

				<tr>
				<th>	 Paid Amount</th>
				<th>	 Balance</th>
				<!--<th>	 Method</th>-->
    	        <th>	Description</th>
	

                 </tr>
           
							</tr>
					
							<?php
					
 

					
					

 if(!is_array($viewcollection)) 

 {


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

  	foreach ($viewcollection as $c): 

		 

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


  $total=$total+$c->amount;
 $invoice_number=$c->invoice;

?>

	  <td><?php  
	  
	  echo   formatMoney($c->amount, true);
	  
	  ?></td>
	    <td><?php 
		 echo   formatMoney($c->balance, true);
		
		?></td>
	<!--  <td>
			 <?php  $paymentmethodesid= $c->paymentmethodes ;
	 $mypaymentmethodes = $this->usermodel->populateallarray('glaccounts','number',$paymentmethodesid);

    $mypaymentmethodes[0]['accountname'];
			  ?>
			</td>
			-->
	  	  <td><?php echo $c->remarks ; ?></td>
  
	   
											</tr>
										<?php endforeach;} ?>

          
			  
							
							
							
						
							
							
							
							
								<tr>
								
								
								<td colspan="7"> 

								
								
							<H3 class="pull-right">Total payment done:
															<?php  if(isset($total)) {echo   formatMoney($total, true); }?></br></br>
															
															<!--
															Signature:-------------------------
											-->
											
											</H3>

							
							
							</td>
							
							</tr>
							
									
							
							
							
				
								
									
									
					</table>
	
					
					
					
					
				</div>
			</div>
			</div>
		</div>
  
  </div>
 </div>
 </div> 
			
			
		
		
	<script type="text/javascript">


$(window).load(function()
{
	 if( window.print()) {
         window.location.href = "../user/allinvoices";
 }else{
	  //       window.location.href = "../user/allinvoices";
 
 }
});
</script>	


























