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

	 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">
      #myprint { display: none; }
  
  .invoice-box table tr.heading td {
        background: #eee;
        border-bottom: 1px solid #ddd;
        font-weight: bold;
		height:auto;
		
		
    }
  #rcorners {

    border-collapse:separate;
    border:solid black 1px;
    border-radius:6px;
    -moz-border-radius:6px;
	   border-left:solid black 1px;


  }
  

    #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:0px dashed #494949; padding:5px;}


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['branchid'] = $session_data['branchid'];
	 $branchid = $data['branchid'];
$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);
	$profile = $this->usermodel->populateallarray('smsconfig','id',$companyid);

									$photo=$profile[0]['logo'];
									$img=$profile[0]['logo'];
									$hscode=$profile[0]['hscode'];
																				$receiptlogo=$profile[0]['receiptlogo'];
 $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 Delivery!" />
                   
 
 </form>
 <a href="<?php echo base_url(); ?>user/viewsales" class="btn btn-info">Go Back new to Sales</a>
                   <a  class="btn btn-success"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="6">
				
				<?php
$img1='uploads/';
	$url = base_url().$img1.$img;
	
if($photo!=""){
	
	?>
	
 <div>
<img class="img-circle" src="<?php echo $url ?>" height="150" width="100%" style="border-radius:4px;margin:0px  ">		 

</div>
<?php
 
 }
 ?>
				
				</td>
				
				</tr>
				-->
						<tr>
								<td  style="border-radius:4px;margin:0px ; width:20%" valign="bottom" valign="left">
					
<?php
$img1='uploads/';
	//$url = base_url().$img1.$img;
	
	if($receiptlogo=="yesbranch") {
					 $allbranches= $this->usermodel->populateallarray('branch','id',$branchid);
					$branchlogo=$allbranches[0]['logo']; 
											
				
					$url = base_url().$img1.$branchlogo;

			}else{
									$url = base_url().$img1.$img;


			}

	
if($photo!=""){

	
	
	
	
	
	
	
	
	
	
	
	?>
	
 <div>

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

</div>
<?php
 
 }
 ?>

 
 </td>		
										<td colspan="2" style="margin:2px ; width:20%">
<?php 
										 if( $countbranch >1){
										 $mybranches= $this->usermodel->populateallarray('branch','id',$branchid);
										$branchdescription=$mybranches[0]['invoice']; 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="2" style=" width:30%" valign="top">
															<h2 style="margin:2px;">  
															<?php   if($viewreceipt[0]['type']=="Creditnote"){
															echo"CREDIT NOTE";
															}else{
																echo"DELIVERY NOTE";
																
															}?>
															</h2>
															
														<table border="1" width="100%" id="rcorners" style="padding:0px; cellpadding:0px;margin:0px; cellpadding:0; cellspacing:0;">
															
															<tr><td>  NUMBER </td><td> <?php 
															
															if($viewreceipt[0]['receiptno'] !=""){
																echo$viewreceipt[0]['receiptno'];
															}else{
																echo$viewreceipt[0]['id'];
																
															}
															
															?></td>	</tr>
															<tr><td>DATE </td><td>  <?php $myypostedtime= $viewreceipt[0]['dateposted']; echo date("d/m/Y", strtotime($myypostedtime));?></td>	</tr>
															
 	<?php $mypin= $configuration[0]['address']; 
if(	$mypin!=""){
?>
<tr><td>PIN </td><td> <?php echo$mypin;?></td>	</tr>

 <?php
};			 
?>
															
															
															
															
															
															
															<tr><td>REF NO</td><td> <?php $invoiceid; if(isset($invoiceid)) {echo   $invoiceid; }?></td>	</tr>
														<?php	if($viewreceipt[0]['mytable'] !=""){
															?>
																<!--
																	<tr><td>LPO NO: </td><td><?php echo$viewreceipt[0]['mytable'];?> </td>	</tr>
																-->
																
																<?php	
														}
														?>
															<tr><td>SALES PERSON </td>
															
															
															
															
															<td> 
															
																												 	<?php $mypin= $configuration[0]['address']; 
if($viewreceipt[0]['userid'] !=0){
		$alluser=$this->usermodel->populateallarray('people','id', $viewreceipt[0]['userid']);
						echo $allnames=$alluser[0]['firstname'];
						
						
}
?>
															
															</td>	
															
															
															</tr>
<?php $mypin= $configuration[0]['address']; 
if($viewreceipt[0]['salesperson'] !=0){
		$user=$this->usermodel->populateallarray('people','id', $viewreceipt[0]['salesperson']);
						$MYnames=$user[0]['firstname'];
?>
															<tr><td>SALES REP </td><td> <?php echo$MYnames;?></td>	</tr>

 
<?php
};			 
				 

							?>
							
							
							
							
							
							
							
							
							
							
							
							
							
							
							
							
															</table>
															
					<TR >
					<td colspan="6">
					<hr style="border-top: 2px solid gray;margin:0px;padding:0px">

					</td>
					</TR>
						<tr >
						
					
						<td colspan="4" id="mytitle" style="valign:top">
						<B>Billing To:</B>
					
						<?php 

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

						//echo "<br>".$comments=$mysupplier[0]['comments'];
							?>
						
						
						
						
						
						
						
						
						</td>
						
							<td colspan="2"  id="mytitle" valign="top" >
							<B> Shipping to 	</B><br>
						
						 <?php echo$viewreceipt[0]['description'];?><BR>
						
	
						</td>
						
						
						
							</tr>
												
							
												</table >
<br><br>
										<div class="invoice-box">
													<table border="1" class="height2" height="100%" style="width:100%; ">

							
						
							<tr  class="heading">
								 <td><b>Code</td>	
								 <td colspan="2"><b>Item Name/Description</b></td>
			 <td><b>Qty </td>				
	 <td><b>S/N</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 {
 $count=0;
 $ttqts=0;
  	foreach ($viewsales as $c): 

		  $count=++$count;

             ?>
				                    <tbody >
									
										 
												
											<tr   valign="top">
											
											<?php 

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


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

			<td><?php echo $c->qty ; 
			 $ttqts= $ttqts+$c->qty;
			
			?></td>
									
				<td><?php echo $c->serial ; ?></td>										
									
											</tr>
										<?php endforeach;} ?>
										
											  <tr>
											  	<td></td>	
			    <td colspan="2">
			  
			  </td>
				<td><b><?php echo $ttqts ; ?></b></td>	
			  
			  </tr>

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


}?><br>

	</div>						

				<p>
									</pre>	</pre>	</br></br>			
									Prepared By:------																												 	<?php 
if($viewreceipt[0]['userid'] !=0){
		$alluser=$this->usermodel->populateallarray('people','id', $viewreceipt[0]['userid']);
						echo $allnames=$alluser[0]['firstname'];
						
						
}
?>-----------------------------------------------Sign:-----------------------------------Date---------------------------		</pre>	</pre></br>	</br>	</br>				
									
							
									Delivered By:------------------------------------------------------------------Sign:-----------------------------------Date---------------------------</pre>	</pre></br></br>	</br>
									Received By:------------------------------------------------------------------Sign:-----------------------------------Date---------------------------
<?php $invoicedetails=$configuration[0]['invoicedetails']; if(isset($invoicedetails)) {
	//echo   $invoicedetails; 

}?>
</p>
<br>

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

















