<?php

 date_default_timezone_set('Asia/Karachi');
 include('db_con.php');
 
 
 $id = $_GET['id'];
 
 

  $statement = $connect->prepare("select m.rec_id,m.cust_id,date_format(m.dated,'%d-%m-%Y') dated,a.acc_name,m.description,m.paid_by,m.amount from rec_voucher m, accounts a where m.cust_id=a.acc_no and m.rec_id = '".$id."'");

  $statement->execute();
  $result = $statement->fetchAll();
 
  ?>
  <!DOCTYPE html>
  <html>
  <head>
    <meta charset="utf-8">
    <title>Receipt Voucher</title>
     <style>
    * {
      font-family: arial;
      font-size: 10px;
      padding: 2px;
      font-weight: normal;

    }
    
    thead td {
      font-weight: bold;
      padding: 0;
      margin: 0;
       border-top: 2px solid black;
       border-bottom: 2px solid black;
    }
    tbody td {
      font-weight: bold;
      border-bottom: 1px solid black;
      padding: 3px;
     
    }
    .font-bold {
      font-weight: bold;
      font-size: 10px;
      

    }
    .rightside {
      text-align: right;
    }
    table.table_head td{
      border: none;
    }
    .smallfont {
      font-size: 10px;
      font-weight: bold;
    }
    .endline {
      border-top: 1px solid black;

    }

    h2 {
      font-size: 10px;
      font-weight: bold;
      border-bottom: 1px solid black;
      border-top: 1px solid black;
      padding: 5px;
      text-align: center;

    }


    .bottom-text {
      font-size: 12px;
      font-weight: bold;

    }

    .bottom_line {
      border-top: 1px solid black;
      right: 0;
    }
    .no-border {
      border: none;
    }
    table.sign_table td {
      border-top: 1px solid black;
    }

    @media print {
  @page { margin: 0.5cm; }
  body { margin: 0.2cm;}
}
  </style>

  </head>
  <body onload="window.print();">
    <h2>Receipt Voucher</h2>
   
 <table width="100%" class="table_head">
  <?php 
  foreach($result as $row)
 {

  $acc_no = $row['cust_id'];
  $amount = $row['amount'];

  $sql = "select sum(d.debit-d.credit) from jv_detail d , jv m where m.jv_id=d.jv_id and d.acc_no = '".$acc_no."' and m.status = 'Active'";
$statement = $connect->query($sql);
$balance = $statement->fetchColumn();
$pre_balance = $balance + $amount;
  
 echo '
 <table width="100%">
 <tr>
 <td width="25%" class="no-border"><b>Voucher #:</b></td><td class="no-border" width="30%">'.$row["rec_id"].'</td><td width="20%" class="no-border rightside"><b>Date: </b></td><td width="30%" class="rightside no-border">'.$row["dated"].'</td>
 </tr>

 <tr class="drawline">
 <td width="25%"></td><td width="30%"></td><td width="20%" ></td><td width="25%"></td>
 </tr>

 <tr class="drawline">
 <td width="25%">From : </td><td colspan="3" width="75%">'.$row["acc_name"].'</td>
 </tr>

 <tr class="drawline">
 <td width="25%" style="font-size:10px">Desc:</td><td colspan="3" width="75%">'.$row["description"].'</td>
 </tr>
 </table>
 <table width="100%">
<tr class="drawline">
 <td width="50%" style="font-size:10px">Pre-Balance:</td><td  width="50%" style="font-size:12px; text-align:right">'.number_format($pre_balance,0).'</td>
 </tr>

<tr class="drawline">
 <td width="50%" style="font-size:10px">Received Amount:</td><td  width="50%" style="font-size:12px; text-align:right">'.number_format($amount,0).'</td>
 </tr>



<tr class="drawline">
 <td width="50%" style="font-size:10px">Cur-Balance:</td><td  width="50%" style="font-size:12px; text-align:right">'.number_format($balance,0).'</td>
 </tr>

 </table>
<br />
<br />
 <table no-border" width="100%">
<tr>
<td width="50%" class="no-border">Received By:______________</td>
</tr>
 </table>

  ';
}
  ?> 

</body>
</html>