<?php
//require_once 'pdf.php';
 
 include('db_con.php');
 $html = '';
 $fdate = $_GET['fdate'];
 $v_id = $_GET['v_id'];
 $tdate = $_GET['tdate'];
 $pay_status = $_GET['pay_status'];
 $sorted = $_GET['sorted'];
 $tot_amount = 0;
 if($v_id == 'ALL')
 {
   header('location:rpt_pay_voucher_all?print=1&v_id='.$v_id.'&fdate='.$fdate.'&tdate='.$tdate.'&pay_status='.$pay_status.'&sorted='.$sorted.'');
 }
           $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
           $acc_name = $statement->fetchColumn();
         
              
                $statement = $connect->prepare("
        select pay_id,chq_no,chq_date,description,pay_status,amount from pay_voucher where
        v_id = :v_id and dated between :fdate and :tdate and pay_status = :pay_status 
        order by chq_date");
       $statement->execute(
        array(
         ':v_id'       =>  $v_id,         
         ':fdate'       =>  $fdate,
         ':tdate'       =>  $tdate,
         ':pay_status'       =>  $pay_status
        )
       );
        if($pay_status =='ALL')
               {
                $statement = $connect->prepare("
        select pay_id,chq_no,chq_date,CONCAT(description,' - ',pay_status) as description,amount from pay_voucher where
        v_id = :v_id and dated between :fdate and :tdate order by chq_date");
       $statement->execute(
        array(
         ':v_id'       =>  $v_id,
         ':fdate'       =>  $fdate,
         ':tdate'       =>  $tdate
        )
       );
               }
              
              
  
 $result = $statement->fetchAll();
echo '
  
  <h3>Cheques '.$pay_status.'</h3>
  <table width="100%">
  <tr>
  <td width="50%"><b>ID : </b>'.$v_id.'</td><td width="50%" class="rightside">From : '.$fdate.'</td>
  </tr>
  <tr>
  <td width="50%">Name : '.$acc_name.'</td><td width="50%" class="rightside">To : '.$tdate.'</td>
  </tr>
  
  </table>
  ';
  ?>
  <!DOCTYPE html>
  <html>
  <head>
      <meta charset="utf-8">
      <title>Cheque Detail Report</title>
      <style>
      * {
        font-family: arial;
        padding: 4px;
        font-size: 14px;
    }
          .rightside {text-align: right;}

          thead td {
            border-bottom: 2px solid black;
            border-top: 2px solid black;
            font-weight: bold;
          }

          tbody td {border-bottom: 1px solid black;}
      
      </style>
  </head>
  <body>
  
  
  <table width="100%" id="data_table">
    <thead>
        
  <tr>
  <td width="7%">pay_id</td>
  <td width="10%">chq_no</td>
  <td width="10%">chq_date</td>
  <td width="61%">Description</td>
  
  <td width="10%" class="rightside">Amount</td>
 
  </tr>
    </thead>

<tbody>
    <?php 
foreach($result as $row)
 {
 
  $amount = $row["amount"];

  
  
echo '
<tr>
<td>'.$row["pay_id"].'</td>
 
<td>'.$row["chq_no"].'</td>
<td>'.$row["chq_date"].'</td>
<td>'.$row["description"].'</td>
   <td class="rightside">'.number_format($amount, 2).'</td>
  
   
    
   </tr>
   
  ';
  $tot_amount = $tot_amount + $amount;
}

echo '
  <tr>
  <td colspan="4" class="rightside"> Total : </td><td class="rightside">'.number_format($tot_amount, 2).'</td>
  </tr>
';
?>
</tbody>
</table>
</body>
</html>