<?php



//require_once 'pdf.php';

 

 include('db_con.php');

 $html = '';

 $fdate = $_GET['fdate'];

 

  $v_id = $_GET['v_id'];

 $tdate = $_GET['tdate'];

  $item_type = $_GET['item_type'];

  $item_brand = $_GET['item_brand'];

  $item_made = $_GET['item_made'];

  $item_size = $_GET['item_size'];

  $item_year = $_GET['item_year'];

  $item_no = $_GET['item_no'];





  $tot_amount = 0;

  $tot_qty = 0;

$count = 0;

 

 

 

 

 



 $sql = "SELECT name FROM vendors WHERE v_id='".$v_id."'";

           $statement = $connect->prepare($sql);

           $statement->execute(); // no need to add `$sql` here, you can take that out

           $v_name = $statement->fetchColumn();

           

  $statement = $connect->prepare("select m.p_id,m.dated,i.item_name,i.item_size,

    i.item_type,i.item_made,i.item_brand,i.item_year,d.item_no,d.qty, d.rate,d.qty*d.rate as amount

    from items i,purchase m, purchase_detail d where m.p_id=d.p_id and d.item_no=i.item_no

    and  m.v_id = :v_id and m.dated between :fdate and :tdate and i.item_no LIKE '%".$item_no."%' and 

   i.item_type LIKE '%".$item_type."%' and i.item_brand LIKE '%".$item_brand."%'

   and i.item_made LIKE '%".$item_made."%' and i.item_size LIKE '%".$item_size."%'

   and i.item_year LIKE '%".$item_year."%'  order by dated desc

  ");





  

 $statement->execute(

  array(

   ':v_id'       =>  $v_id,

   ':fdate'       =>  $fdate,

   ':tdate'       =>  $tdate

  )

 );

 $result = $statement->fetchAll(); 



 ?>





 <html>

 <head>

 <style>

    @page { margin:160px 20px; }

    @page {margin-bottom: 40px;}

    #header { position: fixed; left: 0px; top: -160px; right: 0px; height: 160px; text-align: center; }

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

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

    .rightside{text-align:right;font-size:13px;}

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

    .tot {border-top:1px solid gray;}

    

    #table_header th {

    border-top:1px solid black;

    border-bottom:1px solid black;

  }

  .smallfont{font-size:12px;text-align:right;}

  </style>



  <body>



  <div id="header">



  <h3>Purchase Report</h3>

  <table width="100%">

  <tr>

  <td width="20%">ID :</td><td width="20%"><?php echo''.$v_id.'';?></td><td width="55%" class="rightside">From :</td><td width="20%" class="rightside"><?php echo''.$fdate.'';?></td>

  </tr>

  <tr>

  <td width="15%">Name : </td><td width="70%" style="font-size:15px"><?php echo''.$v_name.'';?></td><td width="20%" class="rightside">To :</td><td width="20%" class="rightside"><?php echo''.$tdate.'';?></td>

  </tr>

  <tr>

  <td width="10%"></td><td width="20%"></td><td width="70%" class="rightside"></td><td width="20%" class="rightside"></td>

  </tr>

  </table>

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

 



  </table>



  </div>

   <div id="content">

  

  <table width="100%">

  <tr>

  <th width="3%">#</th>

  <th width="4%">P_ID</th>

<th width="7%">Date</th>

  <th width="5%">No.</th>

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

  <th width="6%">Type</th> 

  <th width="8%">Size</th> 

  <th width="8%">Brand</th> 

  <th width="8%">Made</th> 

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

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

   

  

  

  <th width="6%" class="rightside">Rate</th>

   <th width="6%" class="rightside">Amount</th>



  </tr>



  



  <?php 

foreach($result as $row)

 {

  $qty = $row["qty"];

  $rate = $row["rate"];





 $amount = $qty * $rate;



 $tot_amount = $tot_amount + $amount;



 $tot_qty = $tot_qty + $qty;



 $count = $count + 1;

   

 

  

    

  

  



echo '

 







<tr>

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

<td width="4%">'.$row["p_id"].'</td>

<td width="7%">'.$row["dated"].'</td>

  <td width="5%">'.$row["item_no"].'</td>

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

<td width="6%">'.$row["item_type"].'</td>

<td width="8%">'.$row["item_size"].'</td>

<td width="8%">'.$row["item_brand"].'</td>

<td width="8%">'.$row["item_made"].'</td>

<td width="5%">'.$row["item_year"].'</td>

    

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

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

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

  

   

    

   </tr>

   

  



        ';



}



?>



</table>





  </div>



<table width = "100%">

<tr>

<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>

<td width = "6%" class="rightside tot">Total :</td>

  <td width="6%" class="rightside tot"><?php echo''.number_format($tot_qty, 2).'';?></td>

    <td width="6%" class="tot"></td>

    <td width="6%" class="rightside tot" ><?php echo''.number_format($tot_amount, 2).'';?></td>

    </tr>

  </table>

</body>

</html>  