<?php

 
 include('db_con.php');
 
 $jv_id = $_GET['id'];
 $tot_debit = 0;
 $tot_credit= 0;
           
   $statement = $connect->prepare("select * from titles where  id= :title_id
    
  ");
 $statement->execute(
  array(  
   ':title_id'       =>  1
  )
 );
 $result = $statement->fetchAll();
 
  foreach($result as $row)
 {
  $heading1 = $row['heading1'];
  $heading2 = $row['heading2'];
  $heading3 = $row['heading3'];
 }
        
 
 
  $statement = $connect->prepare("
  select m.jv_id,m.dated,m.jv_no, m.source,m.description
  
  from jv m where 
  m.jv_id=:jv_id LIMIT 1");
 $statement->execute(
  array(
   ':jv_id'       =>  $jv_id
  
  )
 );
 $result = $statement->fetchAll();
 ?>
 <!DOCTYPE html>
  <html>
  <head>
    <meta charset="utf-8">
    <title>Journal Voucher</title>
     <style>
    * {
      font-family: Calibri;
      font-size: 14px;
      padding: 2px;
      font-weight: bold;

    }
    

   .rightside {
    text-align: right;
   } 
   
   table.datatable td {
    border-bottom: 1px solid gray;
   }
   table.datatable thead td {
    border-bottom: 2px solid black;
        border-top: 2px solid black;
   }
   .total {
    border-top: 1px solid black;
   }
   h2 {
    font-size: 18px;
    font-weight: bold;
   }
   .title {
    font-size: 16px;
   }
   .hline {
    border-top: 1px solid black;
   }
   table.titletable {
    border-bottom: 1px solid;
   }
  </style>

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

<tr>
  <td width="60%" class="title">'.$heading1.'</td><td width="20%"></td><td width="20%"> </td></tr>
  <tr><td class="title_small">'.$heading2.' </td></tr>
  <tr><td class="title_small">'.$heading3.'</td></tr>
  
  </table>
  
  
  <table width="100%">
  <tr>
  <td width="25%">Jv No :</td><td width="25%">'.$row["jv_no"].'</td><td width="25%" class="rightside">Date :</td><td width="25%" class="rightside">'.$row["dated"].'</td>
  </tr>
  
  <tr>
  <td width="90%" colspan="3">'.$row["description"].'</td><td width="10%" class="rightside"></td>
  </tr>
  </table>
  
  <table width="100%" class="datatable">
  <thead>
  <tr>
  <td width="20%">Acc_No</td>
  <td width="40%">Account Name</td>
  
  <td width="20%" class="rightside">Debit</td>
  <td width="20%" class="rightside">Credit</td>
  </tr>
  </thead>
  <tbody>
';
}
$sql = "select a.acc_no,a.acc_name,d.debit,d.credit from jv_detail d , accounts a where d.acc_no=a.acc_no and d.jv_id = '".$jv_id."'";
$statement = $connect->query($sql);
$result = $statement->fetchAll();
foreach ($result as $row) {
 
  $debit = $row["debit"];
  $credit = $row["credit"];
  $tot_debit = $tot_debit + $debit;
  $tot_credit = $tot_credit + $credit;


  
echo '
<tr>
  <td width="15%" class="dataline">'.$row["acc_no"].'</td>
<td width="35%" class="dataline">'.$row["acc_name"].'</td>

<td width="15%" class="rightside dataline">'.number_format($debit, 2).'</td>
   <td width="15%" class="rightside dataline">'.number_format($credit, 2).'</td>
  
   
    
   </tr>';
}
echo '

<tr>
<td colspan="2" class="rightside">Total:</td>
<td width="15%" class="rightside total">'.number_format($tot_debit, 2).'</td>
<td width="15%" class="rightside total">'.number_format($tot_credit, 2).'</td>
</tr>
</table>
<br />
<br />
<table width="100%">
<tr>
<td width="33%">Prepared By: __________</td><td>Checked By:__________</td><td>Approved By:__________</td>
</tr>

        ';

?>
</body>
</html>