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


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");  
} 


// getting branch details

$branchID=$_SESSION['branch'];

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

$sql = "SELECT * FROM eduportal_chart_of_accounts where parent_id='9'";

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


  $sql = "SELECT * FROM eduportal_chart_of_accounts where parent_id='8'";

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


$sql = "SELECT * FROM eduportal_chart_of_accounts where parent_id='45'";

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


  $sql = "SELECT * FROM eduportal_chart_of_accounts where parent_id='76'";

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

$sql = "SELECT * FROM eduportal_chart_of_accounts where parent_id='27'";

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

  $sql = "SELECT * FROM eduportal_chart_of_accounts where parent_id='73'";

 // print_r($sql);
  $EquityAccounts = $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 Balance Sheet</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;">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>

<div class="container">
<div class="row">
<div class="col-lg-6">

<table id="listofstudents3" class="table table-striped table-bordered table-bordered" style="width:40%; margin-left: 10%; border-right: 1px solid gray; float: left">

<thead>

<tr>
<th style="background-color:#042954;color:#fff;font-size:16px;">Assets</th>
<th style="background-color:#042954;color:#fff;font-size:16px;">RS</th>

</tr>          

<tbody class="">


<?php foreach ($CashAssetAccounts as $CashAssetAccount) { 

/*$m->where("coa_id_fk", $assetAccount['coa_id']); 
$opeingBalance = $m->get("eduportal_branch_account_opening_balances");*/


$accountID=$CashAssetAccount['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'";

$AssetDebitBalance = $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'";

$AssetCreditBalance = $m->query($sql);

$totalAssets+=$AssetDebitBalance[0]['debit']+$AssetCreditBalance[0]['credit'];


    ?>
<tr>
<td style="padding:5px;font-size: 14px"><?php echo $CashAssetAccount['account_title'];?></td>
<td style="text-align:center;font-size: 14px;"><?php echo $AssetDebitBalance[0]['debit']+$AssetCreditBalance[0]['credit'];?></td>
</tr>
<?php } ?>


<?php foreach ($assetAccounts as $assetAccount) { 

/*$m->where("coa_id_fk", $assetAccount['coa_id']); 
$opeingBalance = $m->get("eduportal_branch_account_opening_balances");*/


$accountID=$assetAccount['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'";

$AssetDebitBalance = $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'";

$AssetCreditBalance = $m->query($sql);

$totalAssets+=$AssetDebitBalance[0]['debit']-$AssetCreditBalance[0]['credit'];


	?>
<tr>
<td style="padding:5px;font-size: 14px"><?php echo $assetAccount['account_title'];?></td>
<td style="text-align:center;font-size: 14px;"><?php echo $AssetDebitBalance[0]['debit']-$AssetCreditBalance[0]['credit'];?></td>
</tr>
<?php } ?>






</tbody>
<tfoot style="background-color: #042954; font-weight: bold; color: white">
<tr>

<td class="text-center" style="font-size:16px;">Total Assets</td>

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

</tr>
</tfoot>


</table>


</div>



<!-- 2nd table -->

<div class="col-lg-6">

<table id="listofstudents3" class="table table-striped table-bordered table-bordered" style="width:40%; margin-left:  3%; border-right: 1px solid gray; float: left">

<thead>

<tr>
<th style="background-color:#042954;color:#fff;font-size:16px;">Laibilities</th>
<th style="background-color:#042954;color:#fff;font-size:16px;">RS</th>

</tr>          

<tbody class="">

<?php foreach ($LaibilitiesAccountsPayale as $LaibilitiesAccountsPay) { 


/*$m->where("coa_id_fk", $LaibilitiesAccount['coa_id']); 
$LaiopeingBalance = $m->get("eduportal_branch_account_opening_balances");*/



$accountID=$LaibilitiesAccountsPay['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'";

$LaibilitiDebitBalance = $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'";

$LaibilitiCreditBalance = $m->query($sql);


$totalLaibilities+=$LaibilitiDebitBalance[0]['debit']+$LaibilitiCreditBalance[0]['credit'];


    ?>
<!-- <tr>

<td style="padding:5px;font-size: 14px;"><?php echo $LaibilitiesAccountsPay['account_title'];?></td>
<td style="text-align:center;font-size: 14px;"><?php echo $LaibilitiDebitBalance[0]['debit']+$LaibilitiCreditBalance[0]['credit'];?></td>


</tr> -->
<?php }?>



<?php foreach ($LaibilitiesAccounts as $LaibilitiesAccount) { 


/*$m->where("coa_id_fk", $LaibilitiesAccount['coa_id']); 
$LaiopeingBalance = $m->get("eduportal_branch_account_opening_balances");*/



$accountID=$LaibilitiesAccount['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'";

$LaibilitiDebitBalance = $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'";

$LaibilitiCreditBalance = $m->query($sql);


$totalLaibilities+=$LaibilitiDebitBalance[0]['debit']+$LaibilitiCreditBalance[0]['credit'];


	?>
<!-- <tr>

<td style="padding:5px;font-size: 14px;"><?php echo $LaibilitiesAccount['account_title'];?></td>
<td style="text-align:center;font-size: 14px;"><?php echo $LaibilitiDebitBalance[0]['debit']+$LaibilitiCreditBalance[0]['credit'];?></td>


</tr> -->
<?php }?>

<!-- =====================================accounts payable====================================== -->

<?php foreach ($AccountsPayable as $AccountsPayab) { 


/*$m->where("coa_id_fk", $LaibilitiesAccount['coa_id']); 
$LaiopeingBalance = $m->get("eduportal_branch_account_opening_balances");*/



$accountID=$AccountsPayab['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'";

$AccPayAbleDebitBalance = $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'";

$AccPayAbleCreditBalance = $m->query($sql);


$totalAccountPayable+=$AccPayAbleDebitBalance[0]['debit']+$AccPayAbleCreditBalance[0]['credit'];


    ?>
<!-- <tr>

<td style="padding:5px;font-size: 14px;"><?php echo $AccountsPayab['account_title'];?></td>
<td style="text-align:center;font-size: 14px;"><?php echo $AccPayAbleDebitBalance[0]['debit']+$AccPayAbleCreditBalance[0]['credit'];?></td>


</tr> -->
<?php }?>

<!-- =======================================end accounts payable================================ -->

<tr style="background-color: #042954; font-weight: bold; color: white">

<td class="text-center" style="font-size:16px;">Total Laibilities</td>

<td style="font-size:16px;text-align: center;"><?php //echo $totalLaibilities+$totalAccountPayable;?></td>

</tr>

<tr style="background-color: #042954; font-weight: bold; color: white; text-align: center;">

<td class="text-center" style="font-size:16px;" colspan="2">Equity</td>

</tr>


<?php foreach ($EquityAccounts as $EquityAccount) { 

$m->where("coa_id_fk", $EquityAccount['coa_id']); 
$EqutyopeingBalance = $m->get("eduportal_branch_account_opening_balances");



$accountID=$EquityAccount['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'";

$EquityDebitBalance = $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'";

$EquityCreditBalance = $m->query($sql);


$totalEquity+=$EquityDebitBalance[0]['debit']+$EquityCreditBalance[0]['credit'];

	?>
<tr>

<td style="font-size:14px;"><?php echo $EquityAccount['account_title'];?></td>
<td style="text-align: center;font-size: 14px;"><?php echo $EquityDebitBalance[0]['debit']+$EquityCreditBalance[0]['credit'];?></td>


</tr>
<?php }?>

<tr style="background-color: #042954; font-weight: bold; color: white">

<td style="font-size:16px;" class="text-center">Total Equity</td>

<td style="text-align:center;font-size: 16px;"><?php echo $totalEquity;?></td>

</tr>


<tr>
<td style="font-size: 14px;">Retained Earnings</td>
<td style="text-align:center;font-size: 14px;"><?php echo $totalLaibilities+$totalAccountPayable;?></td>
</tr>



</tbody>
<tfoot style="background-color: #042954; font-weight: bold; color: white">
<tr>

<td style="font-size:16px;" class="text-center">Total Laibilities & Equity</td>

<td style="text-align:center;font-size:16px;"><?php echo $totalLaibilities+$totalEquity;?> </td>

</tr>
</tfoot>


</table><br>


</div>


<!-- 2nd table -->

</div>
</div>




</body>
</html>
