<?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>

</head>

<body>


    <!-- Left Panel -->

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

    <!-- Left Panel -->

    <!-- Right Panel -->

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

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

        

       
						<center> <img src="logo1.jpg" align="middle" /></center></strong>
                        <h2><center><? echo "" . $_SESSION["userid"]; ?></center></h2>
                   
                                <strong class="card-title"><center>Income Statement Report</center> </strong>
                          
							<?php

include 'dbc.php';


$userid=$_SESSION["userid"];
$from_date=$_POST["from_date"];
$to_date=$_POST["to_date"];

$sql1 = "SELECT * FROM addclass where user_id = '$userid'";
$result1=$conn->query($sql1);
$row1 = $result1->fetch_assoc();
$feedisc1=$row1['feedisc1'] ;
$feedisc2=$row1['feedisc2'] ;
$feedisc3=$row1['feedisc3'] ;
$feedisc4=$row1['feedisc4'] ;
$feedisc5=$row1['feedisc5'] ;
$feedisc6=$row1['feedisc6'] ;
?>
                               
								<h4><center><? echo "For the Period of From:" . $from_date . "To:" . $to_date; ?></center></h4>
                                  
									<?php
include 'dbc.php';


$userid=$_SESSION["userid"];

    $sqlinactive = "SELECT * FROM invoice_details where date between '$from_date' and '$to_date' and  user_id='$userid'";
$resultinactive=$conn->query($sqlinactive);
while($rowinactive = $resultinactive->fetch_assoc())
 
  {
  $item_name = $rowinactive['item_name'];
   $qty = $rowinactive['qty'];
  $sql10 = "SELECT * FROM items where user_id = '$userid'";
$result10=$conn->query($sql10);
$row10 = $result10->fetch_assoc();
$crate=$row10['cost_price'] ;
$costamount = $crate * $qty;
  $tfeeinactive=$tfeeinactive + $rowinactive['amount'];
 $tcostamount = $tcostamount + $costamount;
  }
  $netitemprofit = $tfeeinactive - $tcostamount;
  $amounts1=0;
  $amounts2=0;
  $amounts3=0;
  $amounts4=0;
  $amounts5=0;
  $amounts6=0;
  $amounts7=0;
  $amounts8=0;
  $sql1 = "select * from rec_fee where date between '$from_date' and '$to_date' and user_id='$userid'";
$result1=$conn->query($sql1);
                                       while($ppp = $result1->fetch_assoc())
{
  $amounts1=$amounts1 + $ppp["feerec"];
  $amounts2=$amounts2 + $ppp["fee1rec"];
  $amounts3=$amounts3 + $ppp["fee2rec"];
  $amounts4=$amounts4 + $ppp["fee3rec"];
  $amounts5=$amounts5 + $ppp["fee4rec"];
  $amounts6=$amounts6 + $ppp["fee5rec"];
  $amounts7=$amounts7 + $ppp["fee6rec"];
  $amounts8=$amounts8 + $ppp["fine"];
 
 }
 $netfine= $amounts8;
$netincome=$amounts1 + $amounts2 + $amounts3 + $amounts4 + $amounts5 + $amounts6 + $amounts7 + $amounts8 +$$netitemprofit;
  echo "<table border=10 width=100% align=center bgcolor=white>";

 echo "<tr height=50>";
echo "<th width=80%  bgcolor=#0099FF>  Item & Fee Discription Details   </th>";
echo "<th width=20%  bgcolor=#0099FF>  Amount   </th>";
 
   echo "</tr>";
    echo "<tr>";
echo "<td width=80%>" . "Cost of Items Sold" .   "</td>";
echo "<td width=20%>" . $tfeeinactive .   "</td>";
   echo "</tr>";
    echo "<tr>";
echo "<td width=80%>" . "Cost of Items" .   "</td>";
echo "<td width=20%>" . $tcostamount .   "</td>";
   echo "</tr>";
    echo "<tr height=50>";
echo "<th width=80%>Items Profit</th>";
echo "<th width=20%>  $netitemprofit </th>";
   echo "</tr>";

 echo "<tr>";
echo "<td width=80%>" . "Tution Fee" .   "</td>";
echo "<td width=20%>" . $amounts1 .   "</td>";
   echo "</tr>";
   echo "<tr>";
echo "<td width=80%>" . $feedisc1 .   "</td>";
echo "<td width=20%>" . $amounts2 .   "</td>";
   echo "</tr>";
   echo "<tr>";
echo "<td width=80%>" . $feedisc2 .   "</td>";
echo "<td width=20%>" . $amounts3 .   "</td>";
   echo "</tr>";
   echo "<tr>";
echo "<td width=80%>" . $feedisc3 .   "</td>";
echo "<td width=20%>" . $amounts4 .   "</td>";
   echo "</tr>";
   echo "<tr>";
echo "<td width=80%>" . $feedisc4 .   "</td>";
echo "<td width=20%>" . $amounts5 .   "</td>";
   echo "</tr>";
   echo "<tr>";
echo "<td width=80%>" . $feedisc5 .   "</td>";
echo "<td width=20%>" . $amounts6 .   "</td>";
   echo "</tr>";
   echo "<tr>";
echo "<td width=80%>" . $feedisc6 .   "</td>";
echo "<td width=20%>" . $amounts7 .   "</td>";
   echo "</tr>";
   
    echo "<tr>";
echo "<td width=80%>" . "Fine" .   "</td>";
echo "<td width=20%>" . $netfine .   "</td>";
   echo "</tr>";
       echo "<tr height=50>";
echo "<th width=80%> Total Items + Fees Income   </th>";
echo "<th width=20%>  $netincome   </th>";
 
   echo "</tr>";
echo "</table>";
    echo "<table border=10 width=100% align=center bgcolor=white>";

echo "<tr height=50>";
echo "<th width=80%  bgcolor=#0099FF>  Others Income Details   </th>";
echo "<th width=20%  bgcolor=#0099FF>  Amount   </th>";
 
   echo "</tr>";
   $sqlcoa1 = "select * from chartofaccounts where acc_type='Income' and user_id='$userid'";
//$sql = "select * from chartofaccounts";
  $resultcoa1=$conn->query($sqlcoa1);
                                       while($rowcoa1 = $resultcoa1->fetch_assoc())

  {
 $acc_name1= $rowcoa1["acc_name"];
 $net_bal1=0;
 $amounts1 =0;
  $total_cr_amount1=0;

$sql1 = "select * from expense_voucher where date between '$from_date' and '$to_date' and acc_name_cr='$acc_name1' and mtype='Income' and user_id='$userid'";
   $result1=$conn->query($sql1);
                                       while($row1 = $result1->fetch_assoc())
 
  {
 $amounts1=$amounts1 + $row1["amount"];
  }
  echo "<tr>";
echo "<td width=80%>" . $acc_name1 .   "</td>";
echo "<td width=20%>" . $amounts1 .   "</td>";
 
   echo "</tr>";
  
   $netexp1=$netexp1 + $amounts1;
  }
  $grossprofit=$netexp1 + $netincome;
  echo "<tr height=50>";
echo "<th width=80%>  Total Other Income   </th>";
echo "<th width=20%> $netexp1  </th>";
 
   echo "</tr>";
    echo "<tr height=50>";
echo "<th width=80%><right> Gross Profit </right>  </th>";
echo "<th width=20%> $grossprofit  </th>";
 
   echo "</tr>";
   echo "</table>";

   
   
   
 
 echo "<table border=10 width=100% align=center bgcolor=white>";

echo "<tr height=50>";
echo "<th width=80%  bgcolor=#0099FF> Operating Expense Details   </th>";
echo "<th width=20%  bgcolor=#0099FF>  Amount   </th>";
 
   echo "</tr>";
$sqlcoa = "select * from chartofaccounts where acc_type='Expense' and user_id='$userid'";
//$sql = "select * from chartofaccounts";
  $resultcoa=$conn->query($sqlcoa);
                                       while($rowcoa = $resultcoa->fetch_assoc())

  {
 $acc_name= $rowcoa["acc_name"];
 $net_bal=0;
 $amounts =0;
  $total_cr_amount=0;

$sql = "select * from expense_voucher where date between '$from_date' and '$to_date' and acc_name_dr='$acc_name' and mtype='Expense' and user_id='$userid'";
   $result=$conn->query($sql);
                                       while($row = $result->fetch_assoc())
 
  {
 $amounts=$amounts + $row["amount"];
  }
  echo "<tr>";
echo "<td width=80%>" . $acc_name .   "</td>";
echo "<td width=20%>" . $amounts .   "</td>";
 
   echo "</tr>";
  
   $netexp=$netexp + $amounts;
  }
  echo "<tr height=50>";
echo "<th width=80%>  Net Total Expeses   </th>";
echo "<th width=20%> $netexp  </th>";
 
   echo "</tr>";
   echo "</table>";

$profit=$grossprofit - $netexp;


echo "<table border=10 width=100% align=center >";
  echo "<tr height=60>";
echo "<th width=80%  bgcolor=#0099FF> <right> Net Income   </right></th>";
echo "<th width=20%  bgcolor=#0099FF> $profit  </th>";
 
   echo "</tr>";
echo "</table>";
?> 
                                       
                                 
                          
</body>

</html>
<?php
}
?>