<?php









require_once 'pdf.php';




 




 include('db_con.php');




 if (isset($_SESSION['user_id'])) {




    $user_type = $_SESSION['user_type'];




    $user_id = $_SESSION['user_id'];




    $user_name = $_SESSION['user_name'];




    $branch_id = $_SESSION['branch_id'];




    $branch_name = $_SESSION['branch_name'];




    $store_id = $_SESSION['store_id'];




    $store_name = $_SESSION['store_name'];




}else{




  header('Location: login');




  die();




}




 $html = '';




 




 $do_id = $_GET['id'];









$tot_qty= 0;









     
























  $statement = $connect->prepare("




    select m.do_id,m.dated,m.description,b.branch_name,s.store_name,




    i.item_name,t.store_name as store_detail,d.qty,d.item_status from do m,do_detail d,items i, store s, branch b, store t




    where m.do_id=d.do_id and d.item_no=i.item_id and m.store_id=s.store_id and t.store_id=d.store_id and b.branch_id=m.branch_id and d.store_id = '".$store_id."' and m.do_id = :do_id




  ");




 $statement->execute(




  array(  




   ':do_id'       =>  $do_id




  )




 );




 $result = $statement->fetchAll();









 




  foreach($result as $row)




 {














 









 $html .=' <style>




    @page { margin:140px 20px; }




    #header { position: fixed; left: 0px; top: -140px; right: 0px; height: 140px; text-align: center; background-color: #fff;}




    #footer { position: fixed; left: 0px; bottom: -160px; right: 0px; height: 100px; background-color: #fff; }




    #content {margin:0; font-size:13px;}




    .rightside{text-align:right;}




    #footer .page:after { content: "page " counter(page) " of " counter(pages);}




    




    #table_header th {




    border-top:1px solid black;




    border-bottom:1px solid black;




  }




  </style>









  <div id="header">









  <h3>Deliver Order</h3>




  <table width="100%">




  <tr>




  <td width="15%">ID:</td><td width = "30%">'.$row["do_id"].'</td><td width="15%">Date :</td><td width="20%" class="rightside">'.$row["dated"].'</td><td width="15%" class="rightside"></td><td width="15%"class="rightside"></td>




  </tr>









  <tr>




  <td width="15%">From :</td><td width = "80%"  style="font-size:13px;">'.$row["branch_name"].' Store : '.$row["store_name"].'</td><td width="1%"></td><td width="1%" class="rightside"></td><td width="1%" class="rightside"></td><td width="1%"class="rightside"></td>




  </tr>




  




  




  </table>




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









  <tr>




  <th width="5%">Sr</th>




  <th width="40%">Item Name</th>




  <th width="22%">Store</th>




  <th width="10%" class="rightside">Qty</th>




  <th width="23%"class="rightside">Status</th>




  




 



















  </tr>









  </table>









  </div>









  




';









}




$count = 0;




foreach($result as $row)




 {




  $qty = $row["qty"];









  $tot_qty = $tot_qty + $qty;









   $count = $count +1;




  









$html .= '




  <div id="content">




  




  <table width="100%">




<tr>




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




<td width="40%">'.$row["item_name"].'</td>




<td width="22%">'.$row["store_detail"].'</td>









<td width="10%" class="rightside">'.number_format($qty, 2).'</td>









<td width="23%" class="rightside">'.$row["item_status"].'</td>




  




   




    




   </tr>




   




  </table>









  














  </div>














  <div id="footer">




  <hr />




  <table width="100%">




  <tr>




  <td width="70%" class="rightside"> </td><td width="30%" class="rightside"></td>




  </tr>




  </table>




    <span class="page"></span>




  </div>














 




        ';









}



















$html .='<hr style= "height:1px; " />



















<table width="100%">




<tr>




<td class="rightside" width="67%">Total :</td><td class ="rightside" width="10%"></td>




<td width="10%" class="rightside">'.number_format($tot_qty, 2).'</td><td width="23%" class="rightside"></td>









</tr>









</table>









';









 $html .='<br />




<br />




<table width="100%">




<tr>




<td width="50%">Received By: __________</td><td width="50%">Approved By:__________</td>




</tr>




</table> ';




 $pdf = new Pdf();









 $file_name = 'Delivery Order.pdf';




 $pdf->setPaper('A4', 'portrait');









 $pdf->loadHtml($html);




 $pdf->render();




 $pdf->stream($file_name, array("Attachment" => false));









?>