
	<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/allinvoices";
		alert(" printing...........");
    }else {

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

		    // document.body.innerHTML = originalContents;

	}
}
	</script>
 <style type="text/css">
  
  
  .invoice-box table tr.heading td {
        background: #eee;
        border-bottom: 1px solid #ddd;
        font-weight: bold;
		height:auto;
		
		
    }
  

    #printable { display: none; }
#print{  	


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

    width:100%; height:50px;



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


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

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

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


}
#myalltitle { font-size: 2em; }
#alltitle{ font-size: 1em; }
	#mytitle { font-size: 1.4em; }

    
    {
		
    	#non-printable { display: none; }
    	#printableArea { display: block; font-size:10; width:100%; }
		  margin:0; 
		#receipt{
	font-style: normal;font-size: 1.5em;
	
	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);
   $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);
															 $countbranch=$this->usermodel->countbranches($companyid);

					
?>
 
 <div class="row">

 

   	<div class="col-md-12">
		 <div class="pull-right" id="non-printable"  >
<form name="print" method="post" action="">
 <input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('printableArea')" value="Print Invoice!" />
                   
 
 </form>
                    <a class="btn btn-info"  href="<?php echo base_url(); ?>viewsales/mysales">NEXT SALE</a>

 <a href="<?php echo base_url(); ?>user/allinvoices">Go Back to all invoices</a>
                   <a href="<?php echo base_url(); ?>user/mysales">Or Cashier Sales</a>

 </div>
  	
			<div class="table-responsive" id="printableArea" style="width:100%" >
						<table border="0" width="100%">
				
						<tr>
						<td colspan="3" style="border-radius:4px;margin:0px ; width:60%">
					
<?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'];	

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

	
		if(!is_array($profile)) 

 {
	 $this->session->set_flashdata('msg', '<div class="alert alert-danger fade in">
						 <a href="#" class="close" data-dismiss="alert">&times;</a><strong>Error!</strong>Upload photo</div>');
							

    }else {

    
          
  	foreach ($profile as $c): 
$photo= $c->logo;
		 	if($photo!=""){
		 
		 

		
	
			
		
		$img=$c->logo;
	
		$img1='uploads/';
	$url = base_url().$img1.$img;

 
 ?>
 <div >
<img class="img-circle" src="<?php echo $url ?>" height="100" width="100" style="border-radius:4px;margin:0px  ">		 

</div>



	 <?php }else{
		 ?>

				<?php
	 }
		 endforeach; ?>

              <?php }?>
					
					
						<?php 
										 if( $countbranch>1){
										 $mybranches= $this->usermodel->populateallarray('branch','id',$branchid);
										$branchdescription=$mybranches[0]['invoice']; if(isset($branchdescription)) {
											
											
											echo   strtoupper($branchdescription); }


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

											 
										 }
										?>
				
				
					
					
						</td>
						
						<td colspan="2" style=" width:40%">
															<h2 style="margin:0px;"> INVOICE 	</h2>
															<b>

				 Date:  <?php 
				 
				 $myypostedtime= $viewreceipt[0]['dateposted']; echo date("d/m/Y H:i:a", strtotime($myypostedtime));
				 ?><BR>
						 	Due Date: <?php

				 $due_date= $viewreceipt[0]['due_date']; echo date("d/m/Y H:i:a", strtotime($due_date));

							?><BR>
				Invoice  No: <?php echo$viewreceipt[0]['id'];?><BR>

				Ref No:  <?php $invoiceid; if(isset($invoiceid)) {echo   $invoiceid; }?>
						<BR>
						
							 <?php  if($viewreceipt[0]['salesperson'] !=""){
						echo "Sales Person:";
							$user=$this->usermodel->populateallarray('people','id', $viewreceipt[0]['salesperson']);
						echo$names=$user[0]['firstname']. " ".$user[0]['surname'] ;
						echo "<BR>";
							}
						
						?>
						
						Prepared By:..  <?php 
						
							$user=$this->usermodel->populateallarray('people','id', $userid);
						echo$names=$user[0]['firstname']. " ".$user[0]['surname'] ;
						
						
						?>..
					</b>
						</td>
						
						</tr>
						
					<TR>
					<td colspan="6">
					<hr style="border-top: 2px solid gray;">

					</td>
					</TR>
						<tr>
						
					
						<td colspan="3" id="mytitle">
						<B>Billing To:</B>
					
						<?php 

						$customer=$viewreceipt[0]['customer'];
							$customername=$viewreceipt[0]['name'];
							$mysupplier=$this->usermodel->populateallarray('people','id', $customer);
						$alldetais="";
														
														
					
					
						 
						 if($mysupplier[0]['company']!=""){
							 $alldetais.= $mysupplier[0]['company']."<br>";
						 }
						  if($mysupplier[0]['firstname']!=""){
							 $alldetais.= $mysupplier[0]['firstname']." ". $mysupplier[0]['surname']."<br>";
						 }
						  if($mysupplier[0]['idno']!=""){
							 $alldetais.= $mysupplier[0]['idno']."<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($customername!=""){
							 //$alldetais.= $customername;
						 }
						 	
													echo "<br>".$alldetais;

						//echo "<br>".$comments=$mysupplier[0]['comments'];
							?>
						
						
						
						
						
						
						
						
						</td>
						
							<td colspan="3"  id="mytitle">
							<B>Delivered  To:<br>
						
						 <?php echo$viewreceipt[0]['description'];?><BR>
						
						</B>
	
						</td>
						
						
						
							</tr>
																				
																				
																				
																				</table >
							
											

										<div class="invoice-box">
													<table border="1" class="height2" height="100%" style="width:100%; " id="maintable">

							
						
							<tr  class="heading">
							
<?php 
if($displaycode==true){
	 ?>
<td style="color:blue" ><b>Code</b></td>
<td><b>Item Name</b></td>
	 	<?php
		}else{?>
	<td colspan="2"><b>Item Name</b></td>
 <?php
 }
 ?>


 <td><b>Qty</b></td>
							<td><b>Disc %</b></td>
								<td align="right"><b> Price Excl </b></td>
																<td align="right"><b>VAT </b></td>


								<td align="right" ><b> Total</b></td>
							</tr>
					
						<?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;
  $totalvatcost2=0;
    $myttvatable=0;
  	foreach ($viewsales as $c): 

		 				  $myttvatable=$myttvatable+$c->taxable ;

   	$totalvatcost2=$totalvatcost2+$c->tax2;

             ?>
				                    <tbody >
									
										 
												
											<tr   valign="top"  id="mytitle">
											
											<?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";  
   }
  
  if($c->description !=""){
	  echo " -".$c->description ;
	  
  }
   if( $c->address !=""){
	 echo "-".$c->address;
	 
 }
   if($c->serial!=""){
		
		echo " S/N-".$c->serial;
	}
  ?></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";  
   }
  
    if($c->description !=""){
	  echo " -".$c->description ;
	  
  }
   if( $c->address !=""){
	 echo "-".$c->address;
	 
 }
   if($c->serial!=""){
		
		echo " S/N-".$c->serial;
	}
  ?></td>
 <?php
 }
 ?>

										<td><?php echo $c->qty ; ?></td>
												

												<td><?php echo $c->discount ; ?></td>
												
											
										 	 <td  align="right"  ><?php 
												 echo   formatMoney($c->taxable, true); 


											 ?></td>
											 
											 
											  	 <td  align="right"  ><?php 
												 echo   formatMoney($c->tax, true); 


											 ?></td>
											 
											 
											 
											 
											  	<?php 
												    formatMoney(($c->taxable *$c->qty), true); 


											 ?>
											 
											 
											 
											 
											 
											 
											 	 <td align="right" ><?php
												 
												 //echo $c->amount ; 
											// $totalcost=$totalcost+$c->amount ;

												  $mytotal= $c->qty*$c->sprice ;
												 
												 echo   formatMoney($mytotal, true); 
												  $totalcost=$totalcost+$mytotal ;
												 
												 $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="6" id="mytitle"> <b> GRAND TOTAL </b></td>

								
								
							<td colspan="1" id="myalltitle"> <b class="pull-right">
							
															<?php 
															$mydiscount=$viewreceipt[0]['maindiscount'];
															
															$total=$viewreceipt[0]['total']; 
															if(isset($total)) {echo   formatMoney($total-$mydiscount, true); }?>
											
									</b>
							</td>
							
							</tr>
			  	<tr>
								
								<td colspan="7"> 

								
					<br><br><br><br>

							
							
							</td>
							
							</tr>
							
			  
								
	
							<?php
						$display1=$configuration[0]['display1']; 
						$display2=$configuration[0]['display2']; 

						if(	$display1=="yes"){
						
						?>
							
								<tr>
								
								<td  colspan="3"><B>TAX RATE </B></td>
									<td ><B>VAT AMT 
							<?php 
						if($display2=="yes"){
							?>
							|| CTL
							<?php 
								}
							?>
									
									</B></td>
								
								
								<td colspan="2"><B>VATABLE AMT </B></td>
								
							<td colspan="2" ><B>EXMPT  AMT</B></td>
							
							</tr>
							
								<tr>
								<td id="mytitle"  colspan="3">
							<?php $tax1rate=$configuration[0]['tax1rate']; if(isset($tax1rate)) {echo round(formatMoney($tax1rate, true),1) ;}?>%
						<?php 
						if($display2=="yes"){
							?>
						||<?php $tax2rate=$configuration[0]['tax2rate']; if(isset($tax2rate)) {echo  round(formatMoney($tax2rate, true),1) ;}?>%

							<?php 
								}
							?>
						

								</td>
							
								
								<td id="mytitle">
								<?php if(isset($totaltax)) {  echo formatMoney($totaltax, true) ;}?>
							
								

															<?php 
						if($display2=="yes"){
							?>
																||<?php if(isset($totalvatcost2)) {  echo formatMoney($totalvatcost2, true) ;}?>

							<?php 
								}
							?>
							
								</td>
								<td colspan="2" id="mytitle">
								
								
								
															<?php 
						if($display2=="yes"){
					if(isset($totalvatcost)) { $vatable=($totalvatcost-$totaltax-$totalvatcost2);echo formatMoney($vatable, true) ; }

								}else{
				echo formatMoney($myttvatable, true) ; 
		
									
						}
							?>
						</td>
								<td colspan="2" id="mytitle">
								<?php if(isset($totalexemptedcost)) {  echo formatMoney($totalexemptedcost, true) ;}?>
								
																<?php if(isset($totaltax)) { // echo",". formatMoney(($totaltax+$vatable), true) ;
																}
																
																?>

								
								
							
								</td>
							</tr>
							
								  <tr>
								<td colspan="4" id="mytitle"> <b> GRAND TOTAL AMOUNT: </b></td>

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

								
								
							<H3 class="pull-left">
									Name:-----------------------------Signature:------------</br>						
									
															
									Received By-----------------------Signature-------------
											</H3>

							
							
							</td>
							
							</tr>
							
							
						
							
							
							
							
							
				
									</tbody>
									
									
					</table>
			<div>
				<div>
<?php $invoicedetails=$configuration[0]['invoicedetails']; if(isset($invoicedetails)) {echo   $invoicedetails; }?><br>

</div>
					
					
					
					
				</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>	

















