<?php include('parent/callMe.php');?>
<?php include('Sessioncheck.php');?>

<?php   

 $branchID=$_SESSION['branch'];


$sql = "SELECT * FROM eduportal_accounts_voucher_details where branch_id='$branchID' and voucher_id=".$_REQUEST['voucher_id'];


 // print_r($sql);
  $vocherDetails = $m->query($sql); 


// getting branch details

$m->where("branch_id", $_SESSION['branch']);
$branch=$m->get("edu_branch_config");

$m->where("user_id", $vocherDetails[0]['user_id']);
$userName=$m->get("edu_user_config");

?>
 <!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Favicons-->
<link rel="icon" type="image/png" href="img/favicon.png" sizes="32x32" />
<title>Print Account Voucher</title>
<!-- Favicons-->
<link rel="icon" type="image/png" href="img/favicon.png" sizes="32x32" />

<script type="text/javascript">
 //window.print();
</script>
<style> 
.section{width:80%; height:auto;margin-left: auto;margin-right: auto;}
     
tr th {background-color:gray; text-align:center;font-size:14px;border:1px solid black;padding:.8%;}
tr td {border-bottom:1px solid black;border-left:1px solid black;padding:.8%;}

@media print {
    #Header, #Footer { display: none !important; }
}
@media screen
   {
      p.bodyText {font-family:verdana, arial, sans-serif;}
   }

   @media print
   {
      p.bodyText {font-family:georgia, times, serif;}
   }
   @media screen, print
   {
      p.bodyText {font-size:10pt}
   }
   @media print {
  a[href]:after {
    content: none !important;
  }
}
</style>
</head>
<body>


 <!-- Vouchere Fist -->
<div class="section">



   <div style="text-align:center;margin-top: 20px;">

         <span style="font-size:20px; font-weight:bold;">  <?php echo $branch[0]['Branch_Name'];?> </span>

         <br>


         <span style="font-size:14px; text-align:center;">  <?php echo $branch[0]['Branch_Location'];?> </span>
         <br>
         <strong> <u> Journal Voucher </u>  </strong>

   </div>


  
<div style="font-size:20px;margin-top:3%;">  
  
   <div>
      <div style="width:14%; float:left;">Voucher Number:</div>
      <div style="width:16%; float:left;text-align: center;border-bottom: 1px solid black;"><?php echo $vocherDetails[0]['voucher_code'];?></div>
      <div style="width:5%; float:left;">Date :</div>
      <div style="width:16%; float:left;text-align: center; border-bottom: 1px solid black;"><?php echo date("d-M-Y",strtotime($vocherDetails[0]['voucher_date_entry']));?></div>
      <div style="width:9%; float:left;">Posted On :</div>
      <div style="width:16%; float:left;text-align: center; border-bottom: 1px solid black;"><?php  if($vocherDetails[0]['posted_date']!=NULL){ echo date("d-M-Y",strtotime($vocherDetails[0]['posted_date']));}else {echo "--";};?></div>
      <div style="width:7%; float:left;">Inserter :</div>
      <div style="width:16%; float:left;text-align: center; border-bottom: 1px solid black;"><?php echo $userName[0]['user_fname']; ?></div>


   </div>
   <br>
   <br>
   <div>
      <div style="width:15%;float: left;text-align: left;" >Narration</div>
      <div style="width:84%;float: left;border-bottom: 1px solid black;text-align: center;"><?php echo $vocherDetails[0]['voucher_narration'];?></div>
   </div>

   <br> 
   <br>      
   <br> 
   

  <div>

   <table width="100%" style="font-size:16px;" cellspacing="0" border="1">     
   
         <tr>  
            
            <th> Sr. </th>  
            <th style="text-align: left;"> Account Code </th>
            <th style="text-align: left;"> Account </th>
            <th style="text-align: left;"> Narration </th>
            <th style="text-align: left;"> Debit Amount </th>
            <th style="text-align: left;"> Credit Amount </th>

                                
         </tr>
<?php 
$vID=$_REQUEST['voucher_id'];
$sql1 = "SELECT * FROM eduportal_accounts_voucher_detailed_entries where branch_id='$branchID' and voucher_id_FK='$vID' order by voucher_entries asc";
  //print_r($sql1);
  $vocherDetailEntries = $m->query($sql1);
$count=1;
$code;
$account_name;
$Narration;
  foreach ($vocherDetailEntries as $vocherDetailEntry) {

/*if ($count==1) {*/
  
   $m->where("coa_id", $vocherDetailEntry['debit_account_id']); 
   $debitAccountName = $m->get("eduportal_chart_of_accounts");

  // $code=$debitAccountName[0]['account_code'];
   //$account_name=$debitAccountName[0]['account_title'];
   //$Narration=$vocherDetailEntry['debit_narration'];
/*}*/

/*if ($count==2) {*/

   $m->where("coa_id", $vocherDetailEntry['credit_account_id']); 
   $creditAccountName = $m->get("eduportal_chart_of_accounts");

  // $code=$creditAccountName[0]['account_code'];
   //$account_name=$creditAccountName[0]['account_title'];
   //$Narration=$vocherDetailEntry['credit_narration'];
/*}*/




if ($debitAccountName[0]['account_code']!=NULL) {
   $code=$debitAccountName[0]['account_code'];
} else {
   $code=$creditAccountName[0]['account_code'];
}



if ($debitAccountName[0]['account_title']!=NULL) {
   $account_name=$debitAccountName[0]['account_title'];
} else {   
   $account_name=$creditAccountName[0]['account_title'];
}




if ($vocherDetailEntry['debit_narration']!=NULL) {
   $Narration=$vocherDetailEntry['debit_narration'];
} else {   
   $Narration=$vocherDetailEntry['credit_narration'];
}





    $totalDebit+=$vocherDetailEntry['debit_amount'];
    $totalCredit+=$vocherDetailEntry['credit_amount'];

   ?>    
  
        
         <tr>

            <td> <?php echo $count; $count++;?> </td>
            <td> <?php  echo $code; ?> </td>
            <td> <?php echo $account_name;?> </td>
            <td> <?php echo $Narration;?> </td>
            <td> <?php echo $vocherDetailEntry['debit_amount'];?> </td>
            <td> <?php echo $vocherDetailEntry['credit_amount'];?> </td>

         </tr>

   <?php  } ?>

   <tr>

      <th colspan="4" style="text-align:center;"> Total </th>
      <th> <?php  echo number_format($totalDebit,2); ?> </th>
      <th> <?php echo number_format($totalCredit,2);?> </th>

   </tr>     
       
   </table>



      
    </div>



</div>

<br>
<br>
<br>
<br>
<br>
<div>
      <div style="width:25%; float:left;">(Prepared/Posted By)</div>
      
      <div style="width:25%; float:left;text-align: center;">(Checked By)</div>
      
      <div style="width:25%; float:left; text-align: center;">(Approved By)</div>
     
      <div style="width:25%; float:left;text-align: right;">(Received By)</div>
      
</div>


</div>




</body>
</html>
