
<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">
  
  	
  .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>


	
   	<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>
				View item based purchase report
								                        <a  id="more" target="blank" class="btn btn-primary" href="<?php echo base_url();?>user/viewpurchases">back  </a>

			


				</div>
            </div>
			<div class="panel-body">
 <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 Purchases!" />
                   
 
 </form>

 </div>
			
										
					<div class="row">
						<div class="col-md-12">
							
							<div class="panel-body">
										<div class="table-responsive" id="printableArea" style="width:100%" >

<table id="register" class="table table-bordered " width="100%" >
						<thead>	
						 <tr>
									<td id="non-printable"></td>
								<td colspan="4" ><center  >
								
						
									

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


$data['surname'] = $session_data['surname'];
$data['id'] = $session_data['id'];

$surname=$data['surname'];
   $userid=$data['id'];

										$bussinessname=$configuration[0]['businessname']; if(isset($bussinessname)) {echo   $bussinessname; }
							$mysupplier=$this->usermodel->populateallarray('people','id', $userid);
								$customername=$mysupplier[0]['firstname'];
										?>
												<span id="mytitle"><b> PURCHASE REPORT Between <?PHP echo $fromdate ?> and <?PHP echo $todate ?></b>		
								
								<br><b>Served by: <?php echo $customername;  ?>----Signature--------</b></span>

								</center></td>
																	<td id="non-printable"></td>

								
							</tr>
						
						<tr>
								<th id="non-printable">Code</th>
								<th>Item Name</th>
								
								<th>Qty</th>
								<th>B Price </th>
								<th>Total</th>
								
								
								
								<th>EXP Date </th>
								<th>Batch No</th>
								
								
								
								
								<th id="non-printable">To?</th>
									<th id="non-printable">Status?</th>
								<th>Supplier</th>

							</tr>
						</thead>
						<?php
					
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;
					}
 if(!is_array($viewreceivings)) {
	  echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='5'>";
    echo"There is no record found";
    echo "</td>";
   echo "</tr>";

			 }else{
  $ttbprice=0;

 $ttqty=0;
  $finaltotal=0;
  	foreach ($viewreceivings as $c){
		 $ttqty=$ttqty+$c->total;
  $ttbprice=$ttbprice+$c->buyingprice ;

		
				 		$recaiving= $this->usermodel->populateallarray('products', 'code',$c->item_id);
				 		$branch= $this->usermodel->populateallarray('branch', 'id',$c->type);

		?>
			<tr>
								<td id="non-printable"><?php echo $c->item_id."</br> RF: ". $c->invoice_number ; ?></td>
								<td><?php echo$recaiving[0]["name"] ; ?></td>
								
				<td><?php

echo formatMoney($c->mytotal, true);  


								echo " ".$recaiving[0]["uom"]; ?></td>
								<td><?php   echo formatMoney($c->buyingprice, true); ?> </td>
								 <td><?php 
												 $totalqty=1;
												 if($c->total !=""){
													 
													 $totalqty=$c->total;
												 }
												 $totalcost=(($totalqty)*($c->buyingprice)) ;
												echo formatMoney($totalcost, true);
												 $finaltotal=$finaltotal+$totalcost;
												 ?></td>
								
								
								
									<td><?php   echo $c->enddate; ?> </td>
								<td><?php   echo $c->batchno; ?> </td>
								<td id="non-printable"><?php echo$branch[0]["name"] ;  ?></td>
 <td>
  
  		   <a  id="non-printable" class=" btn-default" target="_blank"  href="<?php echo base_url();?>user/searchallmysalesorder?searchterm=<?php   if(isset($c->invoice )) {echo $c->invoice ; } ?>&view=userdata/allinvoices"> 		

  <?php echo $c->itemstatus ; ?>
   </a>

 </td>
 

	<td><?php 
	
	
	  		$recaiving= $this->usermodel->populateallarray('purchaseorder', 'invoice',$c->invoice_number);
			
			//$recaiving[0]["supplier"] ; 
			

$myuser=$this->usermodel->getpeople($recaiving[0]["supplier"]);
    $myname=$myuser[0]['company'];
     $firstname=$myuser[0]['firstname'];
   if($myname!=""){
	   echo $myname;
	   
   }else{
	   
	   echo $firstname; 
	   
   }
	
	
	?>
	
	</td>
 
 
 
 


							</tr>
		
		
	<?php	
	}
	
			 }
	?>
				<tr>		
								

								
								<th id="non-printable"></th>
									<th></th>
								<th>
								<?php if(isset($ttqty)) {echo formatMoney($ttqty, true);  }?>
								</th>
								<th>
								</th>
								<th>
								<?php if(isset($finaltotal)) {echo formatMoney($finaltotal, true);  }?>
								</th>
						
							</tr>	
									
			</table>	
									
					</div>				
							</div>			
									
									
									
							</div>
						</div>
				

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

 
</div>


















