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

				 		 	<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'];	
				  $viewbprice=$this->usermodel->populatuserpermissionsdataarray('products','viewbprice',$userid);

	 $countbranch=$this->usermodel->countbranches($companyid);

	 				echo $this->session->flashdata('deletemsg'); 

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

             <thead>
			 
			 	  <tr>
			  	 <td colspan="11" valign="top"> 
					
<?php
$img1='uploads/';
						$profile = $this->usermodel->populateallarray('smsconfig','id',$companyid);

									$photo=$profile[0]['logo'];
									$img=$profile[0]['logo'];
										$receiptlogo=$profile[0]['receiptlogo'];

	
	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
 
 }
 ?>

 


			<CENTER>
			 
			 	

			 <?php
			 if(isset($configuration[0]['businessname'])) {echo   $configuration[0]['businessname']; }
			 
			 	$mybranches= $this->usermodel->populateallarray('branch','id',$branchid);
echo",". $mybranches[0]['name'];
			   $TIMEOFREPORT=date("d/m/Y H:i:s a");
			 ?>

			 <B></br>STOCK VALUE REPORT.</BR> 
			 Report was run on <?php echo  date("d/m/Y H:i:s");?>
									<br>Name----------------------Date--------------------Signature----------------</span>
</CENTER>
			</td>
	
	
			 </tr>
			 	
       	<TR >
					<td colspan="12">
					<hr style="border-top: 2px solid gray;margin:0px;padding:0px">

					</td>
					</TR>
			 
			 
			 
			 
			 
			 
			 
			 
			 
			  <tr>
	 
	 </tr>
         <tr>
     <th>Code</th>
     <th>Product Name</th>
	
	     <th id="non-printable">Category</th>

	 <th>Qty</th>
		   <th>B.price</th> 
		   <?php 
	     if($display=="Exclusive"){
			 ?> 
			 
			 
			
		   	   <th>Vat</th> 
		<?php 
	     }
		 ?> 
			 
			 
		   <th>S.price</th> 
		<th>WH.price</th>


<th id="non-printable">Branch</th>

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


			  </tr>
             </thead>
<?php
 
 




 if(!is_array($viewproducts)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='11'>";
    
       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;
	    $finalvatamount=0;
    $finaltotalsellingstock=0;
  $totalqty=0; 
   $totalprofit=0; 
      $totalwhprofit=0; 
$totalbuyingstock1=0;
      $totalwh=0; 

  	foreach ($viewproducts as $c): 

		


             ?>



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

 $totalqty= $totalqty+$myaty;
 
 	  //$finaltotalbuyingstock=$finaltotalbuyingstock+$totalbuyingstock;
    $finaltotalsellingstock=$finaltotalsellingstock+(double)$totalsellingstock;


?>

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

    <td id="non-printable"><?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'];
?>
</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

	
 if( $viewbprice==true){
	 ?>
	 
	 	<?php	

 }else{
	 
	  if($display=="Exclusive"){
	
	   if(($c->vattype=="VATABLE") &&($c->taxtype=="Inclusive")) {
		
			  	$mytax=1+($c->tax_included/100); 
				$pricenovat= (double)$c->buyingprice / (double)$mytax;
				 $finatax=(double)$c->buyingprice-(double)$pricenovat;
				$myvat= $myaty * $finatax;
				  echo formatMoney($pricenovat, true);   
				  $totalbuyingstock1=(double)$myaty*(double)$pricenovat;
				  $finalvatamount=(double)$finalvatamount+(double)$myvat;
		  }else{
	 	echo $c->buyingprice ; 
					  $finalvatamount=$finalvatamount+0;  
		  }
	  }else{
		 	echo $c->buyingprice ; 
	  
		  
	  }
		  

 }
  ?>
  
  
  </td>
  
      <?php 
	     if($display=="Exclusive"){
			 ?> <td>
			   <?php 
	   if(($c->vattype=="VATABLE") &&($c->taxtype=="Inclusive")) {
			  
				  echo formatMoney($finatax, true);   
		  }else{
			  echo "0";
			  
		  }
		  ?>
		  
		  </td> 
		   <?php  
		 }
		  
		  
		  ?>
    <td><?php echo $c->sellingprice ; ?></td> 
     
      <td><?php echo $c->wholesaleprice ; ?></td>  
  

	 <td id="non-printable">
												 
	<?php 
					// $branch="";
					
					if($branchname=="all"){
						echo "All Branches";
					}else{
					 $branch=$c->branch;

					 $branch= $this->usermodel->populateall('branch','id',$branch);



if(is_array($branch)) {

   foreach($branch as $branchrow){

   echo $branchrow->name;
 
 
}} else {
    echo 'General.';
}
					}
?>
												 	 
											      <td>
	<?php

	
 if( $viewbprice==true){
	 ?>
	 
	 	<?php	

 }else{
	 
	   if($display=="Exclusive"){
	
	   if(($c->vattype=="VATABLE") &&($c->taxtype=="Inclusive")) {
		   		  	  echo formatMoney($totalbuyingstock1, true);   
				 $finaltotalbuyingstock=$finaltotalbuyingstock+(double)$totalbuyingstock1;

	   }else{
		  	  echo formatMoney($totalbuyingstock, true);   
 				 $finaltotalbuyingstock=$finaltotalbuyingstock+(double)$totalbuyingstock;

	   }
	   }else{
		    				 $finaltotalbuyingstock=$finaltotalbuyingstock+(double)$totalbuyingstock;

	  echo formatMoney($totalbuyingstock, true);   
	   }

 }
  ?>
  
												  
												  
												  
												  
												  </td>  
				 
												 											      <td><?php echo   formatMoney($totalsellingstock, true);  ?></td>  
											 
												 
												   <td><?php echo   formatMoney($ttwh, true);  ?></td>  
												 
									 

			
			
	 
		 
		 	
			</tr>

	<?php endforeach;
		$totalwhprofit=$totalwh- $finaltotalbuyingstock;
 if($display=="Exclusive"){
		$totalprofit=(double)$finaltotalsellingstock- (double)$finaltotalbuyingstock;

 }else{
		$totalprofit=(double)$finaltotalsellingstock- (double)$finaltotalbuyingstock;
 
 }
	
	} 
	
		
	
	
	?>

         
			  
			  <tr border="1" background="green">
									<td colspan="2"><b>Total qty</b></td>
										     <td id="non-printable"></td>

		<td  colspan="2" style="background:#999999 ; width:100px" ><b><?php if(isset($totalqty)) {echo   formatMoney($totalqty, true);   }?></b></td>

 <td colspan="2"></td>
    <?php 
	     if($display=="Exclusive"){
			 ?> 
			 
			 
			
	<td></td>		<?php 
	     }
		 ?> 
<td id="non-printable">TT Buying price</td>
		<td  style="background:#999999 ; width:100px" ><b>
			<?php

	
 if( $viewbprice==true){
	 ?>
	 
	 	<?php	

 }else{
	if(isset($finaltotalbuyingstock)) {echo  formatMoney($finaltotalbuyingstock, true);   }

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

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

</tr>

			  <tr border="1" background="green">
									<td colspan="2"><b>Total expected profit</b></td>
								


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

	    <?php 
	     if($display=="Exclusive"){
			 ?> 
			 
			 
			
	<td colspan="2"></td>		<?php 
	     }
		 ?> 
			
								<td colspan="4"></td>
		<td  colspan="2" style="background:#999999 ; width:100px" ><b>
				<?php
if( $viewbprice==true){
	 ?>
	 <?php	

}else{
		 		 if(isset($totalprofit)) {echo   formatMoney($totalprofit, true);  }

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

}else{
	 			 if(isset($totalwhprofit)) {echo  formatMoney($totalwhprofit, true);  }

}
  ?>
	
		
		
		
		
		
		</b></td>

							
</tr>

        </table>
		
	</div>

		
	
	
	
	

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

 
</div>


















