<?php







 include('function.php');



 



 include('db_con.php');



 //stock_update($connect);



item_stock_instore($connect);



 $html = '';



 



 $count = 0;



 $gtot_qty = 0;





$dated= date('Y-m-d');









  $statement = $connect->prepare("select DISTINCT item_no from stock_instore



    ");



 $statement->execute();





$result = $statement->fetchAll();









 ?>







<!DOCTYPE html>



<html>



<head>



  <title>



  



  </title>



  <style>



  .rightside {text-align: right;}



  @media print {



  @page { margin: 0; }



  body { margin: 1.6cm; }



}



  table td{



    



    border-bottom: 1px solid gray;







  }



  .head_row {



    font-weight: bold;



  }



  thead td {



    font-weight: bold;



     border-bottom: 1px solid gray;



      border-top: 1px solid gray;



       background-color: :  gray;







  }



  </style>



</head>



<body>







 







  



  <table id="main" width="100%">



  



  <thead>



<tr>



  <td width="5%" class="font-bold">Sr</td>



  



  <td width="45%" class="font-bold">Item Name</td>

  <td width="35%" class="font-bold">Store Name</td>



  <td width="10%" class="font-bold">UOM</td>



  



  



  <td width="15%" class="rightside font-bold">Stock</td>



 















  </tr>



  </thead>



  







<tbody>







  



<?php







foreach($result as $row)



 {











$item_no = $row["item_no"];









          $item_statement = $connect->prepare("select CONCAT(i.item_name,' ', t.type_name ,' ',l.color_name,' ',b.brand_name) as item_name,u.uom_name from  items i,item_brand b,item_type t,item_color l, item_uom u where i.brand_id=b.brand_id and i.color_id=l.color_id and t.type_id=i.type_id and i.uom=u.uom_id and i.status = 'Active' and i.item_id



     = '".$item_no."'");



         $item_statement->execute(



                   );



         $item_result = $item_statement->fetchAll();







foreach($item_result as $item_row)



 {





   $count = $count+1;







          $detail_statement = $connect->prepare("select s.store_name,sum(d.purchase) - sum(d.sale) - sum(d.pr) + sum(d.sr) + sum(d.qty_in) - sum(d.qty_out)



  -sum(d.qty_from)+sum(d.qty_to) stock from stock_instore d,store s where s.store_id=d.store_id and d.item_no   



     = '".$item_no."' group by store_name");



         $detail_statement->execute(



                   );



         $detail_result = $detail_statement->fetchAll();











  



  echo '



  



<tr class="head_row">



<b>



<td width="5%">'.$count.'</td>



<td  width="70%" colspan="2">'.$item_row["item_name"].' </td>

<td  width="10%">'.$item_row["uom_name"].' </td>

<td width="15%"></td>



  























</b>



</tr>











   ';



   



 











   $sr = 0;



   $tot_qty = 0;



  

   //$tot_amount = 0;



   //$tot_qty = 0;



   //$tot_dis_amount = 0;



                foreach($detail_result as $detail_row)



                  {







                  //  $gst_pr = $detail_row["gst_pr"];







  $qty = $detail_row["stock"];





  $tot_qty = $tot_qty + $qty;







                      $sr = $sr+1;



                    



                     



                     



                      //$tot_amount = $tot_amount + $amount;



                     // $tot_qty = $tot_qty + $qty;



                     // $tot_dis_amount = $tot_dis_amount + $dis_amount;







                echo '



                      <tr>



                       



                    <td width="5%" class="small-font">'.$sr.'</td>  



                   

                    <td width="35%" class="small-font"></td>

                    <td width="35%" class="small-font">'.$detail_row["store_name"].'</td>









<td width="10%" class="rightside small-font"></td>

<td width="15%" class="rightside small-font">'.number_format($qty, 2).'</td>





  



   



    



   </tr>';



   }





   echo '



     <tr>



                       



<td colspan="4" width="85%" class="rightside small-font">Total :</td>        

<td width="15%" class="rightside small-font">'.number_format($tot_qty, 2).'</td>



 



   </tr>



   ';



}



 }







?>







</tbody>



  



  



</tfoot>



 



 </table><!--end main table-->







    



  



 </body>



 </html>