<?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' and acc_type='Cash'";
//$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>";
   
  }
  
  $sqlbank = "select * from chartofaccounts where acc_symb='Dr' and acc_type='Bank'";
//$sql = "select * from chartofaccounts";
   $std_ledger1bank=mysql_query($sqlbank) or die("Error : " . mysql_error());
while($rowbank = mysql_fetch_array($std_ledger1bank))

  {
 $acc_namebank= $rowbank["acc_name"];
 $net_balbank=0;
 $total_dr_amountbank =0;
  $total_cr_amountbank=0;
   $sql1bank = "select * from acc_ledger  where acc_name='$acc_namebank' and user_id='$userid'";
  $std_ledger11bank=mysql_query($sql1bank) or die("Error : " . mysql_error());
  
   echo "<table border=1 width=100% align=center bgcolor=white>";
while($row1bank = mysql_fetch_array($std_ledger11bank))
 {
$total_dr_amountbank=$total_dr_amountbank + $row1bank["dr_amount"];
$total_cr_amountbank=$total_cr_amountbank + $row1bank["cr_amount"];
  }
  $net_balbank=$total_dr_amountbank - $total_cr_amountbank;
  
echo "<tr>";
echo "<td width=80%>" . $acc_namebank .   "</td>";
echo "<td width=20%>" . $net_balbank .   "</td>";
 
   echo "</tr>";
   
  }

  
  $sqlassets = "select * from chartofaccounts where acc_symb='Dr' and acc_type='Assets'";
//$sql = "select * from chartofaccounts";
   $std_ledger1assets=mysql_query($sqlassets) or die("Error : " . mysql_error());
while($rowassets = mysql_fetch_array($std_ledger1assets))

  {
 $acc_nameassets= $rowassets["acc_name"];
 $net_balassets=0;
 $total_dr_amountassets =0;
  $total_cr_amountassets=0;
   $sql1assets = "select * from acc_ledger  where acc_name='$acc_nameassets' and user_id='$userid'";
  $std_ledger11assets=mysql_query($sql1assets) or die("Error : " . mysql_error());
  
   echo "<table border=1 width=100% align=center bgcolor=white>";
while($row1assets = mysql_fetch_array($std_ledger11assets))
 {
$total_dr_amountassets=$total_dr_amountassets + $row1assets["dr_amount"];
$total_cr_amountassets=$total_cr_amountassets + $row1assets["cr_amount"];
  }
  $net_balassets=$total_dr_amountassets - $total_cr_amountassets;
  
echo "<tr>";
echo "<td width=80%>" . $acc_nameassets .   "</td>";
echo "<td width=20%>" . $net_balassets .   "</td>";
 
   echo "</tr>";
   
  }

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



$sql = "select * from acc_ledger where  acc_type='Expense' and user_id='$userid'";
   $std_ledger1=mysql_query($sql) or die("Error : " . mysql_error());
while($row = mysql_fetch_array($std_ledger1))
  {
 $exp_amounts=$exp_amounts + $row["dr_amount"];
  }
  //sale multan
  
  
  $total_sale=$sale_multan_amounts + $sale_peshawar_amounts;
  $total_cost= $cost_multan_amounts + $cost_peshawar_amounts;
  $gross_profit= $total_sale -  $total_cost;
  $net_profit= $gross_profit - $exp_amounts;

  echo "<tr>";
echo "<td width=80%>" . "Net Profit" .   "</td>";
echo "<td width=20%>" . $net_profit .   "</td>";
 
   echo "</tr>";


   echo "</table>";
   
  echo "</td>";
   echo "</tr>";
  echo "</table>";


}
?>