
<script>
	function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

    // document.body.innerHTML = printContents.fontsize(12);
     window.print();

	 if( window.print()) {
         window.location.href = "../user/viewproductlist";
		alert(" printing...........");
    }else {

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

		    // document.body.innerHTML = originalContents;

	}
}
	</script>

         <script type="text/javascript">
  
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
		
		
		
    </script>   
  <style type="text/css">
  
  

    #printable { display: none; }
#print{  	


    background-repeat: no-repeat;
	font-size;20px;
  
    width:100%; 


}

#sale{  	


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


}
    @media print
    {
    	#non-printable { display: none; }
    	#printableArea { display: block; font-size:16; width:100%; }
    }
    </style>
 
 <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 STOCK REPORT</span>
						
						     <a  id="more"  class="btn btn-primary" href="<?php echo base_url();?>user/viewproductlist">Back to Stocklist  </a>
													                        <a  id="more"  class="btn btn-info" href="<?php echo base_url();?>user/viewproductcategory">Back to category </a>
							  <a href="<?php echo base_url();?>user/downloadproductcategory?category=<?php if(isset($itemid)) {echo $itemid;   }?>&type=sub&branch=<?php if(isset($branch)) {echo $branch;   }?>" class="btn btn-success"> Download products</a>	 

				 		 	<div class="pull-right"  >
<form name="print" method="post" action="">
 <input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('sortable_table')" value="print receipt!" />
</form></div>
            	</div>
            </div>
			<div class="panel-body">

			
	<div class="widget-content nopadding table_holder table-responsive" >				
				<?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;
					}
 $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'];	
	
	
	 				echo $this->session->flashdata('deletemsg'); 

				echo $this->session->flashdata('msg'); 
								?>	
					<div class="row">
						<div class="col-md-12">
							
							<div class="panel-body" id="sortable_table">
	
									
									
				<table border="1" width="100%">			

             <thead>
         <tr>
     <th>Code</th>
     <th>Product Name</th>
	
	     <th>Category</th>

	 <th>Qty</th>
		   <th>B.price</th> 
		   <th>S.price</th> 



<th>TT B price </th>
<th>TT S price </th>


			  </tr>
             </thead>
<?php
 
 




 if(!is_array($viewproducts)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='1'>";
    
       echo '<div class="alert alert-warning text-center">There no records found..</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
  
  $totalbuyingstock=0;
    $totalsellingstock=0;
	  $finaltotalbuyingstock=0;
    $finaltotalsellingstock=0;
  $totalqty=0; 
   $totalprofit=0; 
      $totalwhprofit=0; 

      $totalwh=0; 

  	foreach ($viewproducts as $c): 

		


             ?>



             <tr>
                
            <?php 
$id=$c->id;
$myaty="0";
$myaty=$c->qty ;
$totalbuyingstock=$myaty*$c->buyingprice;
$totalsellingstock=$myaty*$c->sellingprice;
$ttwh=$myaty*$c->wholesaleprice;
$totalwh=$totalwh+$ttwh;

 $totalqty= $totalqty+$myaty;
 
 	  $finaltotalbuyingstock=$finaltotalbuyingstock+$totalbuyingstock;
    $finaltotalsellingstock=$finaltotalsellingstock+$totalsellingstock;
	
	$totalprofit=$finaltotalsellingstock- $finaltotalbuyingstock;
		$totalwhprofit=$totalqty- $finaltotalbuyingstock;

?>

              
  <td><?php echo $c->code ; ?></td>
    <td><?php echo $c->name."-".$c->description ; ?></td>

    <td><?php 
	$category=$c->category;
	
	$mycategory = $this->usermodel->populatecategorybyowner($category);
	


if(is_array($mycategory)) {

   foreach($mycategory as $mycategoryrow){
		echo $mycategoryrow->name;


}} else {
    echo 'No Category .';
}
	$qty1=$c->qty ;
	$reorder=$c->reorderevel; 
	  $userids= $c->supplier ;

$myuser=$this->usermodel->geteuser($userids);
   //echo $myname=$myuser[0]['firstname'];
$c->expdate ;
?>
</td>
	<td><b>
			<?php 
			
			if($qty1>$reorder){
			
			?>
			<div style="background-color:green">
			<?php  echo $c->qty ; 	?>
			</div>
			<?php
			}else if($qty1<=$reorder){
		?>
			<div style="background-color:orange">
			<?php  echo $c->qty ; 	?>
			</div>
			<?php
			
			}else if($qty1==0){
			?>
			<div style="background-color:red">
			<?php  echo $c->qty ; 	?>
			</div>
			<?php
			}
			
		
			?>
			
		</b></td>
  <td><?php echo $c->buyingprice ; ?></td>
          <td><?php echo $c->sellingprice ; ?></td> 
  

											 
												 
												 
												 
									 
												 
											      <td><?php echo $totalbuyingstock ; ?></td>  
				 
												 											      <td><?php echo $totalsellingstock ; ?></td>  


			
			
	 
		 
		 	
			</tr>

	<?php endforeach;} ?>

         
			  
			  <tr border="1" background="green">
									<td colspan="2"><b>Total qty</b></td>
		<td  colspan="2" style="background:#999999 ; width:100px" ><b><?php if(isset($totalqty)) {echo $totalqty;   }?></b></td>
<td></td><td></td>

		<td  style="background:#999999 ; width:100px" ><b><?php if(isset($finaltotalbuyingstock)) {echo $finaltotalbuyingstock;   }?></b></td>
		<td  style="background:#999999 ; width:100px" ><b><?php if(isset($finaltotalsellingstock)) {echo $finaltotalsellingstock;   }?></b></td>


</tr>

			  <tr border="1" background="green">
									<td colspan="2"><b>Total expected profit</b></td>
									<td colspan="4"></td>
		<td  colspan="2" style="background:#999999 ; width:100px" ><b><?php if(isset($totalprofit)) {echo $totalprofit;   }?></b></td>

							
</tr>

        </table>
		
	</div>

		
	
	
	
	

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

 
</div>


















