<?php
session_start();
if($_SESSION["username"]=="")
{
 	echo "You are not Logged in Please <a href='index.html'>Sign in </a> First ";
}
else
{


?>
<!doctype html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang=""> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8" lang=""> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9" lang=""> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js" lang="en">
<!--<![endif]-->

<head>
   <?php include("includes/header.php") ?>
</head>

<body>


    <!-- Left Panel -->

   <!-- /#left-panel -->

    <!-- Left Panel -->

    <!-- Right Panel -->

    <div id="right-panel" class="right-panel">

        <!-- Header-->
        
        <!-- Header-->

        

        <div class="content mt-3">
            <div class="animated fadeIn">
                <div class="row">

                    <div class="col-md-14">
                        <div class="card">
						<div class="page-title">
                        <h2><center><? echo "" . $_SESSION["userid"]; ?></center></h2>
                    </div>
                            <div class="card-header">
							
                                <strong class="card-title"><center>Accouts Ledger Report</center> </strong>
                            </div>
                            <div class="card-body">
								<?php

include 'dbc.php';

$userid=$_SESSION["userid"];
$month_name=$_POST["month_name"];
$from_date=$_POST["from_date"];
$to_date=$_POST["to_date"];
	echo "<h1 align=center colspan=4>$userid </h1>";
	echo "<h3 align=center colspan=4>Trial Balance </h3>";

 echo "<table border=10 width=100% align=center bgcolor=white>";
echo "<tr>";
echo "<th> Debit Side </th>";
$sql = "select * from chartofaccounts where acc_symb='Dr'";
//$sql = "select * from chartofaccounts";
   $std_ledger1=mysql_query($sql) or die("Error : " . mysql_error());
while($row = mysql_fetch_array($std_ledger1))

  {
 $acc_name= $row["acc_name"];
 $net_bal=0;
 $total_dr_amount =0;
  $total_cr_amount=0;
   $sql1 = "select * from acc_ledger  where date between '$from_date' and '$to_date' and acc_name='$acc_name' and user_id='$userid'";
  $std_ledger11=mysql_query($sql1) or die("Error : " . mysql_error());
  
   echo "<table border=1 width=100% align=center bgcolor=white>";
while($row1 = mysql_fetch_array($std_ledger11))
 {
$total_dr_amount=$total_dr_amount + $row1["dr_amount"];
$total_cr_amount=$total_cr_amount + $row1["cr_amount"];
  }
  $net_bal=$total_dr_amount - $total_cr_amount;
  
echo "<tr>";
echo "<td width=80%>" . $acc_name .   "</td>";
echo "<td width=20%>" . $net_bal .   "</td>";
 
   echo "</tr>";
   $total_net_bal=$total_net_bal + $net_bal;
  }
  
   $sql2 = "select * from admission where user_id='$userid' and bal > 0";
   $std_ledger12=mysql_query($sql2) or die("Error : " . mysql_error());
while($row2 = mysql_fetch_array($std_ledger12))
  {
 $total_bal=$total_bal + $row2["bal"];
  
  }
  echo "<tr>";
echo "<td width=80%>" . "Debtors" .   "</td>";
echo "<td width=20%>" . $total_bal .   "</td>";
 
   echo "</tr>";
   
    $gtotaldr =  $total_net_bal + $total_bal;
	echo "<tr>";
echo "<th width=80%> Total Debit Side</td>";
echo "<th width=20%> $gtotaldr </td>";
 
   echo "</tr>";
    echo "</table>";
    
   
 
 echo "<table border=10 width=100% align=center bgcolor=white>";
echo "<tr>";
echo "<th> Credit Side </th>";
$sql1 = "select * from chartofaccounts where acc_symb='Cr'";
//$sql1 = "select * from chartofaccounts";
   $std_ledger11=mysql_query($sql1) or die("Error : " . mysql_error());
while($row1 = mysql_fetch_array($std_ledger11))

  {
 $acc_name1= $row1["acc_name"];
 $net_bal1=0;
 $total_dr_amount1 =0;
  $total_cr_amount1=0;
   $sql11 = "select * from acc_ledger  where date between '$from_date' and '$to_date' and acc_name='$acc_name1' and user_id='$userid'";
  $std_ledger111=mysql_query($sql11) or die("Error : " . mysql_error());
  
   echo "<table border=1 width=100% align=center bgcolor=white>";
while($row11 = mysql_fetch_array($std_ledger111))
 {
$total_dr_amount1=$total_dr_amount1 + $row11["dr_amount"];
$total_cr_amount1=$total_cr_amount1 + $row11["cr_amount"];
  }
  $net_bal1=$total_cr_amount1 - $total_dr_amount1;
  
echo "<tr>";
echo "<td width=80%>" . $acc_name1 .   "</td>";
echo "<td width=20%>" . $net_bal1 .   "</td>";
 
   echo "</tr>";
    // $total_net_bal1=$total_net_bal1 + $net_bal1;
  }
   
  $sql1 = "select * from rec_fee where date between '$from_date' and '$to_date' and user_id='$userid'";
$rec_fee=mysql_query($sql1) or die("Error : " . mysql_error());

while($ppp=mysql_fetch_array($rec_fee))
{
  $amounts1=$amounts1 + $ppp["paid_fee"];
  $amounts2=$amounts2 + $ppp["stdfine"];
  $amounts3=$amounts3 + $ppp["prefine"];
  $amounts4=$amounts4 + $ppp["anbal"];
  $amounts5=$amounts5 + $ppp["admbal"];
  $amounts6=$amounts6 + $ppp["regbal"];
  $amounts7=$amounts7 + $ppp["acbal"];
  $amounts8=$amounts8 + $ppp["securitybal"];
  $amounts9=$amounts9 + $ppp["othersbal"];
 }
 $netfine= $amounts2 + $amounts3;
 $netincome= $amounts1 + $amounts2 + $amounts3 + $amounts4 + $amounts5 + $amounts6 + $amounts7 + $amounts8 + $amounts9;
   $gtotalcr = $total_net_bal1 + $total_bal1+ $netincome;
   $capital=$gtotaldr - $gtotalcr;
   $gtotalcr1=$gtotalcr + $capital;
 echo "<tr>";
echo "<td width=80%>" . "Capital" .   "</td>";
echo "<td width=20%>" . $capital .   "</td>";
 
   echo "</tr>";
    echo "<tr>";
echo "<td width=80%>" . "Net Income" .   "</td>";
echo "<td width=20%>" . $netincome .   "</td>";
 
   echo "</tr>";



 echo "<tr>";
echo "<th width=80%> Total Credit Side</td>";
echo "<th width=20%> $gtotalcr1 </td>";
 
   echo "</tr>";
    echo "</table>";

 </div>
                        </div>
                    </div>


                </div>
            </div><!-- .animated -->
        </div> <!-- .content -->
    </div><!-- /#right-panel -->

    <!-- Right Panel -->

   <?php include("includes/footermenu.php") ?>

</body>

</html>
<?php
}
?>