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

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

		    // 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%; 


}
#alltitle{ font-size: 1em; }
	#mytitle { font-size: 1.5em; }
#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 OPENNING/ CLOSING STOCK REPORT</span>
			
                  
		  <a  id="more"  class="btn btn-info" href="<?php echo base_url();?>user/viewopeningstock">Back </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');

   		
$mydate=date('Y-m-d');
$mytime=date('H:i:s');
 	 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
	  	   $dontshowprofit=$this->usermodel->populatuserpermissionsdataarray('reports','dontshowprofit',$userid);

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

				echo $this->session->flashdata('msg'); 
								?>	
					<div class="row">
						<div class="col-md-12">
							
							<div class="panel-body">
	
									
									
				<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

             <thead>
			  <tr>
								
								<td colspan="15"><center>
								
						
									

										<?php $bussinessname=$configuration[0]['businessname']; if(isset($bussinessname)) {echo   $bussinessname; }
										
									
										
										?>
										<br>
												<span id="mytitle"><b> CLOSING AND OPENING STOCK(<?PHP echo "BETWEEN ".$startdate." AND ".$closedate; ?>)</b>		
								
								<br>Name---------------------------Date--------------------------Signature---------------------</span>

								</center></td>
								
								
							</tr>
         <tr>
       <!--   <th>Code</th>
	   -->
     <th>Item Name</th>
	

	 <th>Open</th>
		   <th>Added</th> 
		   <th>Total</th> 
		<th>Sold</th>




<th>Cl. Stock </th>
<!--
<th id="non-printable">R.Level </th>

<th id="non-printable">Qty.O </th>

-->
<th >B.Price </th>
<th>TT B.Price </th>





<th>S.Price </th>

<th>TT Amount</th>
<th>Profit</th>
<th>Stock Value</th>


<!--
<th >TT Q.Order </th>
<th>TT Cost Q.Order </th>
-->

<th >Branch</th>
<th >Open Date</th>
<th >Staff</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 
  $qtytotal=0;
  $totalsales=0;
     $ttsold=0;
  $ttvalue=0;
  $ttbuyingprice=0;
    $totalamount=0;

  $ttprofits=0;
   $ttstockvalue=0;
  	foreach ($viewproducts as $c): 

		


             ?>



             <tr>
                
            <?php 
$id=$c->id;
$myaty="0";
$myaty=$c->open ;
$totalsales=$totalsales+$c->totalamount;

?>

    <!--          
  <td><?php  $c->code ; ?></td>
  
  -->
    <td><?php 
	 $mycode=$c->code;
	 $myproductlist = $this->usermodel->populatealldataarray('productlist','code', $mycode,'branch',$c->branchid);

	 
	
	  $userid=$c->userid;
   if($mycode!=""){
	  
      $productname = $this->usermodel->geteproductbyid($mycode);
  
     echo$name=$productname[0]['name']."  ". $description=$productname[0]['description'];

	
   }else{
	    echo "No Product";  
   }
  
	?>
	</td>

  <td><?php 
  
  
  $myuser=$this->usermodel->geteuser($userid);
  echo $c->open ; ?></td>
          <td><?php echo $c->added ; ?></td> 
      <td><?php echo $c->total; ?></td>  
  
   <td><?php echo $c->sold; 
			   $ttsold=$ttsold+$c->sold; 
			   
			   ?></td>  
			  <td><?php echo $c->balance; ?></td>  
			  <!--
			  			  <td id="non-printable"><?php echo $myproductlist[0]['reorderevel']; ?></td>  

						  			  <td id="non-printable"><?php echo $qtyorder= $myproductlist[0]['reorderevel']-$c->balance; ?></td> 

-->									  
			  			  <td ><?php echo $myproductlist[0]['buyingprice']; ?></td>  
			  			 

  
 <td><?php 
 echo $bbprice=$myproductlist[0]['buyingprice']*$c->sold;
 $ttbuyingprice = $ttbuyingprice + $bbprice;
  ?>
 
 
 </td> 










			   
  <td><?php echo $c->price; ?></td>  
  <td><?php 
  
  
   echo $ttsprice=$c->price*$c->sold;
 $totalamount = $totalamount + $ttsprice;
  
  
  
  
  
  ?></td>  


  <td><?php if( $dontshowprofit !=true){
	  
	  echo $profit=(($c->price-$myproductlist[0]['buyingprice'])*$c->sold);

   $ttprofits=   $ttprofits+$profit;
   
  }
  ?></td>  
   <td><?php 
echo$currentvalue= $myproductlist[0]['buyingprice']*$c->balance  ;
   $ttstockvalue=   $ttstockvalue+$currentvalue;
  ?></td> 



<!--
						 <td id="non-printable"><?php echo $tt=$myproductlist[0]['reorderevel']*$myproductlist[0]['buyingprice'];
  $qtytotal= $qtytotal+$tt;

						  ?></td>  
	    <td><?php echo $value=($c->open*$myproductlist[0]['buyingprice']) ;
			
			   $ttvalue=$ttvalue+$value; 
			   
			   ?></td> 
			   
			 -->
			   
			   
			   
		
			   
			   
  
												 
			  <td ><?php
								$mybranch = $this->usermodel->populateallarray('branch','id',$c->branchid);
echo$branchname=$mybranch[0]['name'];

		?></td> 									 
				  <td><?php echo $c->startdate; ?></td> 											 
									 
												 
											<td ><?php 
				  $myid="";
				  $updatedby=$c->updatedby;
				  if($updatedby==0){
					    $myid=$userid;
					  
				  }else{
					  $myid=$updatedby;

					  
				  }
				
		 $myuser=$this->usermodel->geteuser($myid);
			echo $myname=$myuser[0]['firstname'];
				  ?></td>    
			
	 
		 
		 	
			</tr>

	<?php endforeach;} ?>

           
			  
		

			  <tr border="1" background="green">
									<td colspan="2"><b  style="background:#999999 ; width:100px" >Total items:<?php if(isset($total)) {echo formatMoney($total, true);  }?></b>    Total amount</td>
									<td colspan="5"></td>
																						<td style="background:#999999 ; width:100px" ><b><?php if(isset($ttbuyingprice)) {echo formatMoney($ttbuyingprice, true);  }?></b></td>

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

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

							
</tr>

        </table>
			 
	</div>

		
	
	

	

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

 
</div>


















