<?php session_start(); 
if($_SESSION["username"]=="")
{
 	echo "You are not Logged in Please <a href='signin.php'>Sign in </a> First ";
}
elseif($_SESSION["usertype"]=="Parents")
{
 	echo "You are not Authorized This Page <a href='parents.php'>Back </a> ";
}
else
{


include 'dbc.php';

$userid=$_SESSION["userid"];
$month_name=$_POST["month_name"];
$from_date=$_POST["from_date"];
$to_date=$_POST["to_date"];
 echo "<table border=10 width=100% align=center bgcolor=white>";
echo "<tr>";
echo "<td>";
echo "Debit Side";
$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 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'";
   $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>";
  
    
   
   echo "</table>";
  echo "</td>";
  
  
   
  
echo "<td>";
echo "Credit Side";
$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 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;
  }
   
   echo "</table>";
   
  echo "</td>";
   echo "</tr>";
  echo "</table>";
  echo "<table border=10 width=100% align=center bgcolor=white>";
 $gtotaldr =  $total_net_bal + $total_bal + $totalvalue +  $totalvalue5;
$gtotalcr = $total_net_bal1 + $total_bal1 + $total_sale_multan + $total_sale_pesh;
 echo "<tr>";
echo "<td width=42%>" . "Total Debit Side" .   "</td>";
echo "<td width=10%>" . $gtotaldr .   "</td>";
 echo "<td width=42%>" . "Total Credit Side" .   "</td>";
echo "<td width=10%>" . $gtotalcr .   "</td>";
   echo "</tr>";
   echo "</table>";

}
?>