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

  // getting branch details

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

  if($_REQUEST['from']!=" " && $_REQUEST['from']!=NULL ) {
$from=date("Y-m-d",strtotime($_REQUEST['from']));  

}else {
$from=date("Y-m-01");  
}

if($_REQUEST['to']!=" " && $_REQUEST['to']!=NULL   ) {
$to=date("Y-m-d",strtotime($_REQUEST['to']));
}else {
$to=date("Y-m-t");  
} 

  /*$sql = "SELECT * FROM eduportal_accounts_voucher_detailed_entries where branch_id='$branchID' order by voucher_id_FK asc";

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



$sql = "SELECT * FROM eduportal_chart_of_accounts where all_data='All'";

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




 ?>
<!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">
<title>Print Trial Balance</title>
<link rel="icon" type="image/png" href="img/favicon.png" sizes="32x32" />
<script type="text/javascript">
// window.print();
</script>
<style type="text/css">

tr th {border-top:1px solid gray;border-left:1px solid black;border-bottom:1px solid black;text-align:center;font-size:10px; padding:3px;}
tr td {border-bottom:1px solid gray;border-left:1px solid black;font-size:12px; padding:3px;}
  
.border{border:1px solid black;}
.center{text-align:center;}
.alignment{padding-left:1%;text-align:left;}
.borderTop{
  border-top: none;
}
</style>
</head>
<body style="font-size:12px;">

<br>

<div class="page-header-space">
<div class="page-headers" style="text-align: center">
<div class="row text-center">
<div class="col-sm-12">
<span class="font-weight-bold" style="font-size: 2rem"><?php echo $brid[0]['Branch_Name'];?></span><br>
<span style="font-size:18px;">Trail Balance Sheet</span> <br><br>
<span style="font-size:14px;">For the Period <?php echo date("01-M-Y");?> to <?php echo date("t-M-Y");?></span>
</div>
</div>    
</div>
</div><br>
   
    <table id="listofstudents3" data-page-length='100' class="table table-striped table-bordered table-bordered" style="width:70%; margin-left: auto;margin-right: auto;border-right: 1px solid gray; text-align: center;">
          
          <thead>

        <tr style="">
            <th width="2%" style="background-color:#042954;color:#fff;font-size: 16px;">#</th>
            <th width="4%" style="background-color:#042954;color:#fff;font-size: 16px;">Account Number</th>
            <th width="8%" style="background-color:#042954;color:#fff;font-size: 16px;text-align: left;">Account Name</th>
            <th width="5%" style="background-color:#042954;color:#fff;font-size: 16px;">Debit Balance</th>
            <th width="5%" style="background-color:#042954;color:#fff;font-size: 16px;">Credit Balance</th>
          </tr>          
       
          <tbody>
        <?php 

        $count=1;
        foreach ($trailBalance as $trailBal) {    


          $accountID=$trailBal['coa_id'];
          $sql = "SELECT sum(debit_amount) as debit FROM eduportal_accounts_voucher_detailed_entries  "; 
          $sql .= "where voucher_date BETWEEN '" .$from. "' AND '" .$to. "' ";         
          $sql .= "and branch_id='$branchID' and debit_account_id = '$accountID'";
      
          $BalanceDebit = $m->query($sql);     


          $sql = "SELECT sum(credit_amount) as credit FROM eduportal_accounts_voucher_detailed_entries  "; 
          $sql .= "where voucher_date BETWEEN '" .$from. "' AND '" .$to. "' ";         
          $sql .= "and branch_id='$branchID' and credit_account_id = '$accountID'";
      
          $BalanceCredit = $m->query($sql);

          
          
         ?>
          <tr>
          <td style="font-size:16px;"><?php echo $count++;?></td>

          <td style="font-size:16px;"><?php 
            echo $trailBal['account_code'];
         ?></td>


          <td style="font-size:16px;text-align: left;padding-left: 5px;">
          <?php 
            echo $trailBal['account_title'];
          ?>
        </td>

          <td style="font-size:16px;"><?php if ($BalanceDebit[0]['debit']!=NULL) {
            echo $BalanceDebit[0]['debit'];
            $totalDebit+=$BalanceDebit[0]['debit'];
          } else { echo "--";}?></td>

          <td style="font-size:16px;"><?php if ($BalanceCredit[0]['credit']!=NULL) {
            echo $BalanceCredit[0]['credit'];
           $totalCredit+=$BalanceCredit[0]['credit'];
          } else { echo "--";}?></td>

          </tr>
          
         <?php } ?>   
        
          
        
      </tbody>
      <tfoot>
        <tr>
          <th colspan="3" style="background-color:#042954;color:#fff;font-size: 16px;">Total Balance</th>
          <th style="background-color:#042954;color:#fff;font-size: 16px;"><?php echo $totalDebit;?></th>
          <th style="background-color:#042954;color:#fff;font-size: 16px;"><?php echo $totalCredit;?></th>

        </tr>
      </tfoot>
      
    </table><br>
          

</body>
</html>
