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

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

		    // document.body.innerHTML = originalContents;

	}
}
	</script>
	<script type="text/javascript">


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

  <style type="text/css">
  
  	
  .invoice-box table tr.heading td {
        background: #eee;
        border-bottom: 1px solid #ddd;
        font-weight: bold;
		
		
    }
  
  #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'];
//



$data['branchid'] = $session_data['branchid'];
$branchid = $session_data['branchid'];






   $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 LPO!" />
                   
 
 </form>
 <a href="<?php echo base_url(); ?>user/allpurchaseorder">Go Back to all purchases</a>

 </div>
  
        	
			
			<div class="table-responsive" id="printableArea" style="width:100%" >
						<table border="0" width="100%">
					
						<tr>
						<td colspan="2" valign="top">
<?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'];	

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

									$photo=$profile[0]['logo'];
									$img=$profile[0]['logo'];
					 $countbranch=$this->usermodel->countbranches($companyid);
				$receiptlogo=$profile[0]['receiptlogo'];


	$img1='uploads/';

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;


			}











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

</div>



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


										}else{
									$bussinessname=$configuration[0]['businessname']; if(isset($bussinessname)) {echo   $bussinessname; }
 
											 
										 }
										?>
							
						
						
						
						</td>
						
						<td colspan="4" valign="top">
					<h2>
					 <?php 
						 if($type =="oversees"){
							 
							 ?>
										OVERSEES PURCHASE ORDER	

					 <?php 
						 }else{
							?> 
											LOCAL PURCHASE ORDER	
	 
							 
							 <?php  
						 }
					?>
					
					
					
					</h2>
					
<br><br>
						 Date:  <?php echo$viewreceipt[0]['orderdate'];?><BR>
						Purchase Order No: <?php echo$viewreceipt[0]['id'];?><BR>
						Ref No: <?php echo$viewreceipt[0]['ordernumber'];?><BR>
						Status:  <?php echo$viewreceipt[0]['approvalstatus'];?><BR></H3>

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

					</td>
					</TR>
						<tr>
						
					
						<td colspan="3" valign="top">
						<B>Supplier Name:</B><br>
						
						<?PHP
						
						 $alldetais="";
						//
						
						 if($viewreceipt[0]['supplier']!=""){
							$mysupplier=$this->usermodel->populateallarray('people','id', $viewreceipt[0]['supplier']);

							 $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($viewreceipt[0]['description']!=""){
							// $alldetais.= $viewreceipt[0]['description']."<br>";
						 }
						 
						
													echo "<br>".$alldetais;

						
						
						
							 
						 
							?>
						
						
						
						
						
						
						</td>
						
							<td colspan="3">
						<B></B><br>
	 <?php $viewreceipt[0]['shippingto'];?>
						</td>
						
						
						
							</tr>
																				
																				
																				
																				</table >
<br><br>
										<div class="invoice-box">
													<table border="1" class="height2" height="100%" style="width:100%;">

								<tr class="heading">
							

							<td><b>From Date</b></td>
								<td><b>Expiry Date</b></td>
								<td><b>Ordered By</b></td>
								<td><b>Shipped Via</b></td>
								<td><b>F.O.B</b></td>
									<td><b>Terms</b></td>

							</tr>
							
							<tr>
							

							<td><?php echo$viewreceipt[0]['orderdate'];?></td>
							<td><?php echo$viewreceipt[0]['canceldate'];?></td>
							<td><?php 
								$mysupplierorderedby=$this->usermodel->populateallarray('people','id', $viewreceipt[0]['orderedby']);
										if($mysupplierorderedby==false){
											
											echo$viewreceipt[0]['orderedby'];
										}else{
											echo$mysupplierorderedby[0]['firstname'];
											
										}
							
							
							
							
							;?></td>
							<td><?php echo$viewreceipt[0]['deliverymethod'];?></td>
							<td><?php echo$viewreceipt[0]['fob'];?></td>
							<td><?php echo$viewreceipt[0]['terms'];?>
							
							</td>

							</tr>
						<tr>
							<td colspan="6"><br>	</td>
						</tr>
							<tr  class="heading">
							
<?php 
if($displaycode==true){
	 ?>
<td><b>Code</b></td>
<td><b>Item Name</b></td>
	 	<?php
		}else{?>
	<td colspan="2"><b>Item Name</b></td>
 <?php
 }
 ?>
 <td><b>Qty</td>
								<td><b>Disc %</b></td>
								<td><b>Price</b></td>
								<td><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;
  	foreach ($viewsales as $c): 

		 

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

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

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

	
   }else{
	    echo "No Product";  
   }
     echo $c->name;

  	  if($c->description !=""){
	
echo "</BR> ".$c->description ."";
	
}
  ?></td>
 <?php
 }
 ?>
										<td><?php echo $c->qty ; ?></td>
													<td><?php echo $c->discount ; ?></td>
										 	 <td ><?php

echo formatMoney($c->buyingprice , true);
											 ?></td>
											 	 <td><?php 
												 
												   echo formatMoney($c->amount , true);
												 $totalcost=$totalcost+$c->amount ;
												 $totaltax=$totaltax+$c->vat ;
												 $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" rowspan="7"></td>
								
							

								
								
							
									</tr>
									
									<tr>
							
									<td><b>Sub Total:</b></td><td>	<b><?php $total=$viewreceipt[0]['amount']; if(isset($totalcost)) {echo   formatMoney($totalcost, true); }?></b></td>
									</tr>
									<?php 
						$display1=$configuration[0]['display1']; 
						if(	$display1=="yes"){
						
						?>
						
							

							

							
									<tr><td>TAX RATE:</td><td>	<?php $tax1rate=$configuration[0]['tax1rate']; if(isset($tax1rate)) {echo  formatMoney($tax1rate, true) ;}?>%</td>	</tr>

								<tr><td>VAT AMT:	</td><td><?php if(isset($totaltax)) {  echo formatMoney($totaltax, true) ;}?></td>	</tr>

								<tr><td>VATABLE AMT:</td><td><?php if(isset($totalvatcost)) { echo formatMoney($viewreceipt[0]['taxable'], true) ; }?></td>	</tr>

								<tr><td>EXEMPT  AMT:</td><td>	<?php if(isset($totalexemptedcost)) {  echo formatMoney($viewreceipt[0]['EXEMPTED'], true) ;}?></td>

								</tr>
								
								<?php
									}
									?>
								
							
							
							
						<tr>
								
								
								<td colspan="6"> 

								
								
							<SPAN class="pull-left">
													<b>		
												
															</b>
											</SPAN>

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

<br>
						
<table>
							<tr>
<td colspan="3"	>

<?PHP
$mysupplier=$this->usermodel->populateallarray('people','id', $viewreceipt[0]['userid']);
?>
Prepared by (Name):----<b><?PHP echo $mysupplier[0]['firstname'];  ?></b>------(Signature):----------------------</br>
</br>Checked by (Name):-----------------------------------------------------------Signature:-------------------------
</br>Confirmed by (Name):-----------------------------------------------------------Signature:-------------------------

</br>Approved by (Name):-----------------------------------------------------------Signature:-------------------------

						</td>
									
							</tr>
					
					</table>
					








</div>
					
					
					
					
				</div>
			</div>
		
		
  


			
			
		
		

















