<?php
$peri=$pe.'-'.$yr;
///////////////CBC
//Tution Fee
 $query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(TuFee) from feestatement where Month='May' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as mayfee,
 (SELECT SUM(TuFee) from feestatement where Month='June' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as junfee , 
 (SELECT SUM(TuFee) from feestatement where Month='July' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as julyfee,
 (SELECT SUM(TuFee) from feestatement where Month='August' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as augfee,
 (SELECT SUM(TuFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as apfee,
 (SELECT SUM(Amount) from BudgetAmount where ID='sfee' AND Period='$peri') as sfee FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
 $mayfee=$row['mayfee'];
 $junfee=$row['junfee'];
 $julyfee=$row['julyfee'];
 $augfee=$row['augfee'];
 $apfee=$row['apfee'];
 $sfee=$row['sfee'];
 $totmayfee=$mayfee+$junfee+$julyfee+$augfee+$apfee;
 $mayfee=$mayfee+$apfee;
}

//Motivation Fee
 $query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(MoFee) from feestatement where Month='May' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as maymoti,
 (SELECT SUM(MoFee) from feestatement where Month='June' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as junmoti,
 (SELECT SUM(MoFee) from feestatement where Month='July' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as julymoti,
 (SELECT SUM(MoFee) from feestatement where Month='August' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as augmoti,
 (SELECT SUM(MoFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as apmoti,
 (SELECT SUM(Amount) from BudgetAmount where ID='moti' AND Period='$peri' AND Term='Term Two') as moti FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
 $maymoti=$row['maymoti'];
 $junmoti=$row['junmoti'];
 $julymoti=$row['julymoti'];
 $augmoti=$row['augmoti'];
 $moti=$row['moti'];
 $aprmoti=$row['apmoti'];
 
 $maymoti=$maymoti+$aprmoti;
 $totmaymoti=$maymoti+$junmoti+$julymoti+$augmoti;
}

//Admission Fee
 $query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(AdFee) from feestatement where Month='May' AND Year='$yr' AND Cate='Upper') as mayadfe,
 (SELECT SUM(AdFee) from feestatement where Month='June' AND Year='$yr' AND Cate='Upper') as junadfe,
 (SELECT SUM(AdFee) from feestatement where Month='July' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as julyadfe,
 (SELECT SUM(AdFee) from feestatement where Month='August' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as augadfe,
 (SELECT SUM(AdFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as apradfe,
 (SELECT SUM(Amount) from BudgetAmount where ID='adfee' AND Period='$peri') as adfee FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
 $mayadfe=$row['mayadfe'];
 $junadfe=$row['junadfe'];
 $julyadfe=$row['julyadfe'];
 $augadfe=$row['augadfe'];
 $adfee=$row['adfee'];
 $apradfe=$row['apradfe'];
 $mayadfe=$mayadfe+$apradfe;
 
 $totmayadfee=$mayadfe+$junadfe+$julyadfe+$augadfe;
}

//Transport Fee
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(TrFee) from feestatement where Month='May' AND Year='$yr' AND Cate='Upper') as maytra,
(SELECT SUM(TrFee) from feestatement where Month='June' AND Year='$yr' AND Cate='Upper') as juntra,
(SELECT SUM(TrFee) from feestatement where Month='July' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as julytra,
(SELECT SUM(TrFee) from feestatement where Month='August' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as augtra,
(SELECT SUM(TrFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as aprtra,
(SELECT SUM(Amount) from BudgetAmount where ID='trafee' AND Period='$peri') as trafee FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$maytra=$row['maytra'];
$juntra=$row['juntra'];
$julytra=$row['julytra'];
$augtra=$row['augtra'];
$trafee=$row['trafee'];
$aprtra=$row['aprtra'];

$maytra=$maytra+$aprtra;

$totmaytra=$maytra+$juntra+$julytra+$augtra;
}

//Uniform Fee
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(UnFee) from feestatement where Month='May' AND Year='$yr' AND Cate='Upper') as mayuni,
(SELECT SUM(UnFee) from feestatement where Month='June' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as jununi,
(SELECT SUM(UnFee) from feestatement where Month='July' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as julyuni,
(SELECT SUM(UnFee) from feestatement where Month='August' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as auguni,
(SELECT SUM(UnFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as apruni,
(SELECT SUM(Amount) from BudgetAmount where ID='unifee' AND Period='$peri') as unifee FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$mayuni=$row['mayuni'];
$jununi=$row['jununi'];
$julyuni=$row['julyuni'];
$auguni=$row['auguni'];
$unifee=$row['unifee'];
$apruni=$row['apruni'];
$mayuni=$mayuni+$apruni;
$totmayuni=$mayuni+$jununi+$julyuni+$auguni;
}

//Diaries
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(DiFee) from feestatement where Month='May' AND Year='$yr' AND Cate='Upper') as maydia,
(SELECT SUM(DiFee) from feestatement where Month='June' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as jundia,
(SELECT SUM(DiFee) from feestatement where Month='July' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as julydia,
(SELECT SUM(DiFee) from feestatement where Month='August' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as augdia,
(SELECT SUM(DiFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as aprdia,
(SELECT SUM(Amount) from BudgetAmount where ID='diafee' AND Period='$peri') as diafee FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$maydia=$row['maydia'];
$jundia=$row['jundia'];
$julydia=$row['julydia'];
$augdia=$row['augdia'];
$aprdia=$row['aprdia'];
$diafee=$row['diafee'];
$maydia=$maydia+$aprdia;
$totmaydia=$maydia+$jundia+$julydia+$augdia;
}

//Books
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(BookFee) from feestatement where Month='May' AND Year='$yr' AND Cate='Upper') as maybkf,
(SELECT SUM(BookFee) from feestatement where Month='June' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as junbkf,
(SELECT SUM(BookFee) from feestatement where Month='July' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as julybkf,
(SELECT SUM(BookFee) from feestatement where Month='August' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as augbkf,
(SELECT SUM(BookFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as aprbkf,
(SELECT SUM(Amount) from BudgetAmount where ID='bks' AND Period='$peri') as bks FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$maybkf=$row['maybkf'];
$junbkf=$row['junbkf'];
$julybkf=$row['julybkf'];
$augbkf=$row['augbkf'];
$aprbkf=$row['aprbkf'];
$bks=$row['bks'];
$maybkf=$maybkf+$aprbkf;
$totmaybkf=$maybkf+$junbkf+$julybkf+$augbkf;
}

//Developemnt
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(Dev) from feestatement where Month='May' AND Year='$yr' AND Cate='Upper') as maydev,
(SELECT SUM(Dev) from feestatement where Month='June' AND Year='$yr' AND Cate='Upper') as jundev,
(SELECT SUM(Dev) from feestatement where Month='July' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as julydev,
(SELECT SUM(Dev) from feestatement where Month='August' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as augdev,
(SELECT SUM(Dev) from feestatement where Month='April' AND Year='$yr' AND Cate='Upper' AND Term='Term Two') as aprdev,
(SELECT SUM(Amount) from BudgetAmount where ID='dev' AND Period='$peri') as devfee FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$maydev=$row['maydev'];
$jundev=$row['jundev'];
$julydev=$row['julydev'];
$augdev=$row['augdev'];
$devfee=$row['devfee'];

$aprdev=$row['aprdev'];
$maydev=$maydev+$aprdev;
$totmaydev=$maydev+$jundev+$julydev+$augdev;
}

/////////////////////Sub Total CBC
$subtncbc=$totmayfee+$totmaymoti+$totmayadfee+$totmaytra+$totmayuni+$totmaydia+$totmaybkf+$totmaydev+$totmaytab;


///////////////Nursery
//Tution Fee N
 $query=mysqli_query($con,"select feestatement.pid, 
 (SELECT SUM(TuFee+MoFee+PeFee+Tablet) from feestatement where Month='May' AND Year='$yr' AND Cate='Lower') as mayfeen,
 (SELECT SUM(TuFee+MoFee+PeFee+Tablet) from feestatement where Month='June' AND Year='$yr' AND Cate='Lower') as junfeen, 
 (SELECT SUM(TuFee+MoFee+PeFee+Tablet) from feestatement where Month='July' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as julyfeen,
 (SELECT SUM(TuFee+MoFee+PeFee+Tablet) from feestatement where Month='August' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as augfeen,
  (SELECT SUM(TuFee+MoFee+PeFee+Tablet) from feestatement where Month='April' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as aprfeen,
 (SELECT SUM(Amount) from BudgetAmount where ID='tufeen' AND Period='$peri') as tufeen FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
 $mayfeen=$row['mayfeen'];
 $junfeen=$row['junfeen'];
 $julyfeen=$row['julyfeen'];
 $augfeen=$row['augfeen'];
 $aprfeen=$row['aprfeen'];
 $tufeen=$row['tufeen'];
 
 $mayfeen=$mayfeen+$aprfeen;
 $totmayfeen=$mayfeen+$junfeen+$julyfeen+$augfeen;
}

//Admission Fee N
 $query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(AdFee) from feestatement where Month='May' AND Year='$yr' AND Cate='Lower') as mayadfel,
 (SELECT SUM(AdFee) from feestatement where Month='June' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as junadfel,
 (SELECT SUM(AdFee) from feestatement where Month='July' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as julyadfel,
 (SELECT SUM(AdFee) from feestatement where Month='August' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as augadfel,
 (SELECT SUM(AdFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as apradfel,
 (SELECT SUM(Amount) from BudgetAmount where ID='adfee2' AND Period='$peri') as adfee2 FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
 $mayadfel=$row['mayadfel'];
 $junadfel=$row['junadfel'];
 $julyadfel=$row['julyadfel'];
 $augadfel=$row['augadfel'];
 $apradfel=$row['apradfel'];
 $adfee2=$row['adfee2'];
 
 $mayadfel=$mayadfel+$apradfel;
 $totmayadfeel=$mayadfel+$junadfel+$julyadfel+$augadfel;
}

//Transport Fee N
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(TrFee) from feestatement where Month='May' AND Year='$yr' AND Cate='Lower') as maytran,
(SELECT SUM(TrFee) from feestatement where Month='June' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as juntran,
(SELECT SUM(TrFee) from feestatement where Month='July' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as julytran,
(SELECT SUM(TrFee) from feestatement where Month='August' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as augtran,
(SELECT SUM(TrFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as aprtran,
 (SELECT SUM(Amount) from BudgetAmount where ID='trafeen' AND Period='$peri') as trafeen FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$maytran=$row['maytran'];
$juntran=$row['juntran'];
$julytran=$row['julytran'];
$augtran=$row['augtran'];
$trafeen=$row['trafeen'];
$aprtran=$row['aprtran'];

$maytran=$maytran+$aprtran;
$totmaytran=$maytran+$juntran+$julytran+$augtran;
}


//Uniform FeeN
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(UnFee) from feestatement where Month='May' AND Year='$yr' AND Cate='Lower') as mayunin,
(SELECT SUM(UnFee) from feestatement where Month='June' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as jununin,
(SELECT SUM(UnFee) from feestatement where Month='July' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as julyunin,
(SELECT SUM(UnFee) from feestatement where Month='August' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as augunin,
(SELECT SUM(UnFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as aprunin,
(SELECT SUM(Amount) from BudgetAmount where ID='unifeen' AND Period='$peri') as unifeen FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$mayunin=$row['mayunin'];
$jununin=$row['jununin'];
$julyunin=$row['julyunin'];
$augunin=$row['augunin'];
$aprunin=$row['aprunin'];
$unifeen=$row['unifeen'];

$mayunin=$mayunin+$aprunin;
$totmayunin=$mayunin+$jununin+$julyunin+$augunin;
}

//Diaries N
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(DiFee) from feestatement where Month='May' AND Year='$yr' AND Cate='Lower') as maydian,
(SELECT SUM(DiFee) from feestatement where Month='June' AND Year='$yr' AND Cate='Lower') as jundian,
(SELECT SUM(DiFee) from feestatement where Month='July' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as julydian,
(SELECT SUM(DiFee) from feestatement where Month='August' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as augdian,
(SELECT SUM(DiFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as aprdian,
(SELECT SUM(Amount) from BudgetAmount where ID='diafeen' AND Period='$peri') as diafeen FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$maydian=$row['maydian'];
$jundian=$row['jundian'];
$julydian=$row['julydian'];
$augdian=$row['augdian'];
$diafeen=$row['diafeen'];
$aprdian=$row['aprdian'];

$maydian=$maydian+$aprdian;
$totmaydian=$maydian+$jundian+$julydian+$augdian;
}

//Books N
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(BookFee) from feestatement where Month='May' AND Year='$yr' AND Cate='Lower') as maybkfn,
(SELECT SUM(BookFee) from feestatement where Month='June' AND Year='$yr' AND Cate='Lower') as junbkfn,
(SELECT SUM(BookFee) from feestatement where Month='July' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as julybkfn,
(SELECT SUM(BookFee) from feestatement where Month='August' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as augbkfn,
(SELECT SUM(BookFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as aprbkfn,
(SELECT SUM(Amount) from BudgetAmount where ID='boon' AND Period='$peri') as boon FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$maybkfn=$row['maybkfn'];
$junbkfn=$row['junbkfn'];
$julybkfn=$row['julybkfn'];
$augbkfn=$row['augbkfn'];
$boon=$row['boon'];
$aprbkfn=$row['aprbkfn'];

$maybkfn=$maybkfn+$aprbkfn;
$totmaybkfn=$maybkfn+$junbkfn+$julybkfn+$augbkfn;
}

//Developemnt N
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(Dev) from feestatement where Month='May' AND Year='$yr' AND Cate='Lower') as maydevn,
(SELECT SUM(Dev) from feestatement where Month='June' AND Year='$yr' AND Cate='Lower') as jundevn,
(SELECT SUM(Dev) from feestatement where Month='July' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as julydevn,
(SELECT SUM(Dev) from feestatement where Month='August' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as augdevn,
(SELECT SUM(Dev) from feestatement where Month='April' AND Year='$yr' AND Cate='Lower' AND Term='Term Two') as aprdevn,
(SELECT SUM(Amount) from BudgetAmount where ID='devn' AND Period='$peri') as devn FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$maydevn=$row['maydevn'];
$jundevn=$row['jundevn'];
$julydevn=$row['julydevn'];
$augdevn=$row['augdevn'];
$devn=$row['devn'];
$aprdevn=$row['aprdevn'];
$maydevn=$maydevn+$aprdevn;

$totmaydevn=$maydevn+$jundevn+$julydevn+$augdevn;
}

//Graduation PP2
 $query=mysqli_query($con,"select Gradpayment.pid, (SELECT SUM(Amount) from Gradpayment where Month='May' AND Year='$yr') as gradmay,
 (SELECT SUM(Amount) from Gradpayment where Month='June' AND Year='$yr') as gradjun,
 (SELECT SUM(Amount) from Gradpayment where Month='July' AND Year='$yr') as gradjul,
 (SELECT SUM(Amount) from Gradpayment where Month='August' AND Year='$yr') as gradaug,
 (SELECT SUM(Amount) from BudgetAmount where ID='grad' AND Period='$peri') as grad FROM Gradpayment where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
 $gmay=$row['gradmay'];
 $gjun=$row['gradjun'];
 $gjul=$row['gradjul'];
 $gaug=$row['gradaug'];
 $gradd=$row['grad'];
 $totgradmay=$gmay+$gjun+$gjul+$gaug;
}
/////////////////////Sub Total nursery
$subtn=$totmayfeen+$totmayadfeel+$totmaytran+$totmayunin+$totmaydian+$totmaybkfn+$totmaydevn+$totgradmay;

//Tourpayment
 $query=mysqli_query($con,"select TourPayment.pid, (SELECT SUM(Amount) from TourPayment where Month='May' AND Year='$yr') as maytour,
 (SELECT SUM(Amount) from TourPayment where Month='June' AND Year='$yr') as juntour,
 (SELECT SUM(Amount) from TourPayment where Month='July' AND Year='$yr') as julytour,
 (SELECT SUM(Amount) from TourPayment where Month='August' AND Year='$yr') as augtour,
 (SELECT SUM(Amount) from BudgetAmount where ID='tuwa' AND Period='$peri') as tuwa FROM TourPayment where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
 $maytour=$row['maytour'];
 $juntour=$row['juntour'];
 $julytour=$row['julytour'];
 $augtour=$row['augtour'];
 $tuwa=$row['tuwa'];
 $totmaytour=$maytour+$juntour+$julytour+$augtour;
}

//Bus Hire
 $query=mysqli_query($con,"select busincome.busid, (SELECT SUM(cost) from busincome where Month='May' AND Year='$yr') as maybh,
 (SELECT SUM(cost) from busincome where Month='June' AND Year='$yr') as junbh,
 (SELECT SUM(cost) from busincome where Month='July' AND Year='$yr') as julybh,
 (SELECT SUM(cost) from busincome where Month='August' AND Year='$yr') as augbh,
 (SELECT SUM(Amount) from BudgetAmount where ID='bus' AND Period='$peri') as bus FROM busincome where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
 $maybh=$row['maybh'];
 $junbh=$row['junbh'];
 $julybh=$row['julybh'];
 $augbh=$row['augbh'];
 $bus=$row['bus'];
 $totmaybh=$maybh+$junbh+$julybh+$augbh;
}

//Farm Income
 $query=mysqli_query($con,"select farminput.item, (SELECT SUM(Amount) from farminput where Month='May' AND Year='$yr') as mayfam,
 (SELECT SUM(Amount) from farminput where Month='June' AND Year='$yr') as junfam,
 (SELECT SUM(Amount) from farminput where Month='July' AND Year='$yr') as julyfam,
 (SELECT SUM(Amount) from farminput where Month='August' AND Year='$yr') as augfam FROM farminput where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
 $mayfam=$row['mayfam'];
 $junfam=$row['junfam'];
 $julyfam=$row['julyfam'];
 $augfam=$row['augfam'];
 $totmayfam=$mayfam+$junfam+$julyfam+$augfam;
}

$totincomemayaug=$subtncbc+$totmaytour+$totmaybh+$totmayfam+$subtn;


//EXPENSES ------------------------------------------------------------------------------------------------------------------
//Project Bank
$query=mysqli_query($con,"select Item, (SELECT SUM(Amount) from prodata where Month='May' AND Year='$yr') as mpro, 
(SELECT SUM(Amount) from prodata where Month='June' AND Year='$yr') as jupro,
(SELECT SUM(Amount) from prodata where Month='July' AND Year='$yr') as julpro,
(SELECT SUM(Amount) from prodata where Month='August' AND Year='$yr') as aupro FROM prodata where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
 $mpro=$row['mpro'];
 $jupro=$row['jupro'];
 $julpro=$row['julpro'];
 $aupro=$row['aupro'];
 $totmayproject=$mpro+$jupro+$julpro+$aupro;
}

//Salaries
$query=mysqli_query($con,"select Staff_id, (SELECT SUM(Gross) from payment where Month='May' AND Year='$yr' AND Approved='Yes') as masala, 
(SELECT SUM(Gross) from payment where Month='June' AND Year='$yr' AND Approved='Yes') as jusala,
(SELECT SUM(Gross) from payment where Month='July' AND Year='$yr' AND Approved='Yes') as julsala,
(SELECT SUM(Gross) from payment where Month='August' AND Year='$yr' AND Approved='Yes') as ausala FROM payment where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
 $msala=$row['masala'];
 $jusala=$row['jusala'];
 $julsala=$row['julsala'];
 $ausala=$row['ausala'];
 $totmaysala=$msala+$jusala+$julsala+$ausala;
}


//Category Expenses
$query=mysqli_query($con,"select expenses.*,(SELECT SUM(Amount) FROM Expenses where Month='May' AND Year='$yr') as mayyexpe,
(SELECT SUM(Amount) FROM Imprest2 where Month='May' AND Year='$yr') as mayyexpe2,
(SELECT SUM(Amount) FROM Expenses where Month='June' AND Year='$yr') as juneexpe,
(SELECT SUM(Amount) FROM Imprest2 where Month='June' AND Year='$yr') as juneexpe2,

(SELECT SUM(Amount) FROM Expenses where Month='July' AND Year='$yr') as julyexpe,
(SELECT SUM(Amount) FROM Imprest2 where Month='July' AND Year='$yr') as julyexpe2,

(SELECT SUM(Amount) FROM Expenses where Month='August' AND Year='$yr') as augaexpe,
(SELECT SUM(Amount) FROM Imprest2 where Month='August' AND Year='$yr') as augaexpe2 from expenses ORDER BY Item DESC");
while($row=mysqli_fetch_array($query))
{
$totmaye=$row['mayyexpe']+$row['mayyexpe2'];
$totjunee=$row['juneexpe']+$row['juneexpe2'];
$totjulye=$row['julyexpe']+$row['julyexpe2'];
$totaugae=$row['augaexpe']+$row['augaexpe2'];
}

$totexpe=$totmaye+$totjunee+$totjulye+$totaugae;
$totalexpens=$totmayproject+$totmaysala+$totexpe;

?>




