<?php
$peri=$pe.'-'.$yr;
///////////////CBC
//Tution Fee
 $query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(TuFee) from feestatement where Month='January' AND Year='$yr' AND Cate='Upper') as Januaryfee,
 (SELECT SUM(TuFee) from feestatement where Month='February' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as junfee , 
 (SELECT SUM(TuFee) from feestatement where Month='March' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as Marchfee,
 (SELECT SUM(TuFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as augfee,
 (SELECT SUM(Amount) from BudgetAmount where ID='sfee' AND Period='$peri') as sfee FROM feestatement where Year='$yr'");
 
while($row=mysqli_fetch_array($query))
{
 $Januaryfee=$row['Januaryfee'];
 $junfee=$row['junfee'];
 $Marchfee=$row['Marchfee'];
 $augfee=$row['augfee'];
 $sfee=$row['sfee'];
 $totJanuaryfee=$Januaryfee+$junfee+$Marchfee+$augfee;
  $janjanjan=$Januaryfee+$junfee+$Marchfee+$augfee;
}

//Motivation Fee
 $query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(MoFee) from feestatement where Month='January' AND Year='$yr' AND Cate='Upper') as Januarymoti,
 (SELECT SUM(MoFee) from feestatement where Month='February' AND Year='$yr' AND Cate='Upper') as junmoti,
 (SELECT SUM(MoFee) from feestatement where Month='March' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as Marchmoti,
 (SELECT SUM(MoFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as augmoti,
 (SELECT SUM(Amount) from BudgetAmount where ID='moti' AND Period='$peri') as moti FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
 $Januarymoti=$row['Januarymoti'];
 $junmoti=$row['junmoti'];
 $Marchmoti=$row['Marchmoti'];
 $augmoti=$row['augmoti'];
 $moti=$row['moti'];
 $totJanuarymoti=$Januarymoti+$junmoti+$Marchmoti+$augmoti;
}

//Admission Fee
 $query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(AdFee) from feestatement where Month='January' AND Year='$yr' AND Cate='Upper') as Januaryadfe,
 (SELECT SUM(AdFee) from feestatement where Month='February' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as junadfe,
 (SELECT SUM(AdFee) from feestatement where Month='March' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as Marchadfe,
 (SELECT SUM(AdFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as augadfe,
 (SELECT SUM(Amount) from BudgetAmount where ID='adfee' AND Period='$peri') as adfee FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
 $Januaryadfe=$row['Januaryadfe'];
 $junadfe=$row['junadfe'];
 $Marchadfe=$row['Marchadfe'];
 $augadfe=$row['augadfe'];
 $adfee=$row['adfee'];
 $totJanuaryadfee=$Januaryadfe+$junadfe+$Marchadfe+$augadfe;
}


//Transport Fee
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(TrFee) from feestatement where Month='January' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as Januarytra,
(SELECT SUM(TrFee) from feestatement where Month='February' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as juntra,
(SELECT SUM(TrFee) from feestatement where Month='March' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as Marchtra,
(SELECT SUM(TrFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as augtra,
(SELECT SUM(Amount) from BudgetAmount where ID='trafee' AND Period='$peri') as trafee FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$Januarytra=$row['Januarytra'];
$juntra=$row['juntra'];
$Marchtra=$row['Marchtra'];
$augtra=$row['augtra'];
$trafee=$row['trafee'];
$totJanuarytra=$Januarytra+$juntra+$Marchtra+$augtra;
}

//Uniform Fee
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(UnFee) from feestatement where Month='January' AND Year='$yr' AND Cate='Upper') as Januaryuni,
(SELECT SUM(UnFee) from feestatement where Month='February' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as jununi,
(SELECT SUM(UnFee) from feestatement where Month='March' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as Marchuni,
(SELECT SUM(UnFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as auguni,
(SELECT SUM(Amount) from BudgetAmount where ID='unifee' AND Period='$peri') as unifee FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$Januaryuni=$row['Januaryuni'];
$jununi=$row['jununi'];
$Marchuni=$row['Marchuni'];
$auguni=$row['auguni'];
$unifee=$row['unifee'];
$totJanuaryuni=$Januaryuni+$jununi+$Marchuni+$auguni;
}

//Diaries
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(DiFee) from feestatement where Month='January' AND Year='$yr' AND Cate='Upper') as Januarydia,
(SELECT SUM(DiFee) from feestatement where Month='February' AND Year='$yr' AND Cate='Upper') as jundia,
(SELECT SUM(DiFee) from feestatement where Month='March' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as Marchdia,
(SELECT SUM(DiFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as augdia,
(SELECT SUM(Amount) from BudgetAmount where ID='diafee' AND Period='$peri') as diafee FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$Januarydia=$row['Januarydia'];
$jundia=$row['jundia'];
$Marchdia=$row['Marchdia'];
$augdia=$row['augdia'];
$diafee=$row['diafee'];
$totJanuarydia=$Januarydia+$jundia+$Marchdia+$augdia;
}

//Books
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(BookFee) from feestatement where Month='January' AND Year='$yr' AND Cate='Upper') as Januarybkf,
(SELECT SUM(BookFee) from feestatement where Month='February' AND Year='$yr' AND Cate='Upper') as junbkf,
(SELECT SUM(BookFee) from feestatement where Month='March' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as Marchbkf,
(SELECT SUM(BookFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as augbkf,
(SELECT SUM(Amount) from BudgetAmount where ID='bks' AND Period='$peri') as bks FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$Januarybkf=$row['Januarybkf'];
$junbkf=$row['junbkf'];
$Marchbkf=$row['Marchbkf'];
$augbkf=$row['augbkf'];
$bks=$row['bks'];
$totJanuarybkf=$Januarybkf+$junbkf+$Marchbkf+$augbkf; 
}

//Developemnt
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(Dev) from feestatement where Month='January' AND Year='$yr' AND Cate='Upper') as Januarydev,
(SELECT SUM(Dev) from feestatement where Month='February' AND Year='$yr' AND Cate='Upper') as jundev,
(SELECT SUM(Dev) from feestatement where Month='March' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as Marchdev,
(SELECT SUM(Dev) from feestatement where Month='April' AND Year='$yr' AND Cate='Upper' AND Term='Term One') as augdev,
(SELECT SUM(Amount) from BudgetAmount where ID='dev' AND Period='$peri') as devfee FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$Januarydev=$row['Januarydev'];
$jundev=$row['jundev'];
$Marchdev=$row['Marchdev'];
$augdev=$row['augdev'];
$devfee=$row['devfee'];
$totJanuarydev=$Januarydev+$jundev+$Marchdev+$augdev;
}

/////////////////////Sub Total CBC
$subtncbc=$totJanuaryfee+$totJanuarymoti+$totJanuaryadfee+$totJanuarytra+$totJanuaryuni+$totJanuarydia+$totJanuarybkf+$totJanuarypef+$totJanuarydev;


///////////////Nursery
//Tution Fee N
 $query=mysqli_query($con,"select feestatement.pid, 
 (SELECT SUM(TuFee+MoFee+PeFee+Tablet) from feestatement where Month='January' AND Year='$yr' AND Cate='Lower') as Januaryfeen,
 (SELECT SUM(TuFee+MoFee+PeFee+Tablet) from feestatement where Month='February' AND Year='$yr' AND Cate='Lower') as junfeen, 
 (SELECT SUM(TuFee+MoFee+PeFee+Tablet) from feestatement where Month='March' AND Year='$yr' AND Cate='Lower' AND Term='Term One') as Marchfeen,
 (SELECT SUM(TuFee+MoFee+PeFee+Tablet) from feestatement where Month='April' AND Year='$yr' AND Cate='Lower' AND Term='Term One') as augfeen,
 (SELECT SUM(Amount) from BudgetAmount where ID='tufeen' AND Period='$peri') as tufeen FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
 $Januaryfeen=$row['Januaryfeen'];
 $junfeen=$row['junfeen'];
 $Marchfeen=$row['Marchfeen'];
 $augfeen=$row['augfeen'];
 $tufeen=$row['tufeen'];
 $totJanuaryfeen=$Januaryfeen+$junfeen+$Marchfeen+$augfeen;
}

//Admission Fee N
 $query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(AdFee) from feestatement where Month='January' AND Year='$yr' AND Cate='Lower') as Januaryadfel,
 (SELECT SUM(AdFee) from feestatement where Month='February' AND Year='$yr' AND Cate='Lower') as junadfel,
 (SELECT SUM(AdFee) from feestatement where Month='March' AND Year='$yr' AND Cate='Lower' AND Term='Term One') as Marchadfel,
 (SELECT SUM(AdFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Lower' AND Term='Term One') as augadfel,
 (SELECT SUM(Amount) from BudgetAmount where ID='adfee2' AND Period='$peri') as adfee2 FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
 $Januaryadfel=$row['Januaryadfel'];
 $junadfel=$row['junadfel'];
 $Marchadfel=$row['Marchadfel'];
 $augadfel=$row['augadfel'];
 $adfee2=$row['adfee2'];
 $totJanuaryadfeel=$Januaryadfel+$junadfel+$Marchadfel+$augadfel;
}

//Transport Fee N
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(TrFee) from feestatement where Month='January' AND Year='$yr' AND Cate='Lower') as Januarytran,
(SELECT SUM(TrFee) from feestatement where Month='February' AND Year='$yr' AND Cate='Lower' AND Term='Term One') as juntran,
(SELECT SUM(TrFee) from feestatement where Month='March' AND Year='$yr' AND Cate='Lower' AND Term='Term One') as Marchtran,
(SELECT SUM(TrFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Lower' AND Term='Term One') as augtran,
 (SELECT SUM(Amount) from BudgetAmount where ID='trafeen' AND Period='$peri') as trafeen FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$Januarytran=$row['Januarytran'];
$juntran=$row['juntran'];
$Marchtran=$row['Marchtran'];
$augtran=$row['augtran'];
$trafeen=$row['trafeen'];
$totJanuarytran=$Januarytran+$juntran+$Marchtran+$augtran;
}


//Uniform FeeN
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(UnFee) from feestatement where Month='January' AND Year='$yr' AND Cate='Lower') as Januaryunin,
(SELECT SUM(UnFee) from feestatement where Month='February' AND Year='$yr' AND Cate='Lower') as jununin,
(SELECT SUM(UnFee) from feestatement where Month='March' AND Year='$yr' AND Cate='Lower' AND Term='Term One') as Marchunin,
(SELECT SUM(UnFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Lower' AND Term='Term One') as augunin,
(SELECT SUM(Amount) from BudgetAmount where ID='unifeen' AND Period='$peri') as unifeen FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$Januaryunin=$row['Januaryunin'];
$jununin=$row['jununin'];
$Marchunin=$row['Marchunin'];
$augunin=$row['augunin'];
$unifeen=$row['unifeen'];
$totJanuaryunin=$Januaryunin+$jununin+$Marchunin+$augunin;
}

//Diaries N
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(DiFee) from feestatement where Month='January' AND Year='$yr' AND Cate='Lower') as Januarydian,
(SELECT SUM(DiFee) from feestatement where Month='February' AND Year='$yr' AND Cate='Lower') as jundian,
(SELECT SUM(DiFee) from feestatement where Month='March' AND Year='$yr' AND Cate='Lower' AND Term='Term One') as Marchdian,
(SELECT SUM(DiFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Lower' AND Term='Term One') as augdian,
(SELECT SUM(Amount) from BudgetAmount where ID='diafeen' AND Period='$peri') as diafeen FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$Januarydian=$row['Januarydian'];
$jundian=$row['jundian'];
$Marchdian=$row['Marchdian'];
$augdian=$row['augdian'];
$diafeen=$row['diafeen'];
$totJanuarydian=$Januarydian+$jundian+$Marchdian+$augdian;
}

//Books N
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(BookFee) from feestatement where Month='January' AND Year='$yr' AND Cate='Lower') as Januarybkfn,
(SELECT SUM(BookFee) from feestatement where Month='February' AND Year='$yr' AND Cate='Lower' AND Term='Term One') as junbkfn,
(SELECT SUM(BookFee) from feestatement where Month='March' AND Year='$yr' AND Cate='Lower' AND Term='Term One') as Marchbkfn,
(SELECT SUM(BookFee) from feestatement where Month='April' AND Year='$yr' AND Cate='Lower' AND Term='Term One') as augbkfn,
(SELECT SUM(Amount) from BudgetAmount where ID='boon' AND Period='$peri') as boon FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$Januarybkfn=$row['Januarybkfn'];
$junbkfn=$row['junbkfn'];
$Marchbkfn=$row['Marchbkfn'];
$augbkfn=$row['augbkfn'];
$boon=$row['boon'];
$totJanuarybkfn=$Januarybkfn+$junbkfn+$Marchbkfn+$augbkfn;
}


//Developemnt N
$query=mysqli_query($con,"select feestatement.pid, (SELECT SUM(Dev) from feestatement where Month='January' AND Year='$yr' AND Cate='Lower') as Januarydevn,
(SELECT SUM(Dev) from feestatement where Month='February' AND Year='$yr' AND Cate='Lower') as jundevn,
(SELECT SUM(Dev) from feestatement where Month='March' AND Year='$yr' AND Cate='Lower' AND Term='Term One') as Marchdevn,
(SELECT SUM(Dev) from feestatement where Month='April' AND Year='$yr' AND Cate='Lower' AND Term='Term One') as augdevn,
(SELECT SUM(Amount) from BudgetAmount where ID='devn' AND Period='$peri') as devn FROM feestatement where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
$Januarydevn=$row['Januarydevn'];
$jundevn=$row['jundevn'];
$Marchdevn=$row['Marchdevn'];
$augdevn=$row['augdevn'];
$devn=$row['devn'];
$totJanuarydevn=$Januarydevn+$jundevn+$Marchdevn+$augdevn;
}

//Graduation PP2
 $query=mysqli_query($con,"select Gradpayment.pid, (SELECT SUM(Amount) from Gradpayment where Month='January' AND Year='$yr') as gradJanuary,
 (SELECT SUM(Amount) from Gradpayment where Month='February' AND Year='$yr') as gradjun,
 (SELECT SUM(Amount) from Gradpayment where Month='March' AND Year='$yr') as gradjul,
 (SELECT SUM(Amount) from Gradpayment where Month='April' 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))
{
 $gJanuary=$row['gradJanuary'];
 $gjun=$row['gradjun'];
 $gjul=$row['gradjul'];
 $gaug=$row['gradaug'];
 $gradd=$row['grad'];
 $totgradJanuary=$gJanuary+$gjun+$gjul+$gaug;
}
/////////////////////Sub Total nursery
$subtn=$totJanuaryfeen+$totJanuaryadfeel+$totJanuarytran+$totJanuaryunin+$totJanuarydian+$totJanuarybkfn+$totJanuarydevn+$totgradJanuary;


//Tourpayment
 $query=mysqli_query($con,"select TourPayment.pid, (SELECT SUM(Amount) from TourPayment where Month='January' AND Year='$yr') as Januarytour,
 (SELECT SUM(Amount) from TourPayment where Month='February' AND Year='$yr') as juntour,
 (SELECT SUM(Amount) from TourPayment where Month='March' AND Year='$yr') as Marchtour,
 (SELECT SUM(Amount) from TourPayment where Month='April' 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))
{
 $Januarytour=$row['Januarytour'];
 $juntour=$row['juntour'];
 $Marchtour=$row['Marchtour'];
 $augtour=$row['augtour'];
 $tuwa=$row['tuwa'];
 $totJanuarytour=$Januarytour+$juntour+$Marchtour+$augtour;
}

//Bus Hire
 $query=mysqli_query($con,"select busincome.busid, (SELECT SUM(cost) from busincome where Month='January' AND Year='$yr') as Januarybh,
 (SELECT SUM(cost) from busincome where Month='February' AND Year='$yr') as junbh,
 (SELECT SUM(cost) from busincome where Month='March' AND Year='$yr') as Marchbh,
 (SELECT SUM(cost) from busincome where Month='April' 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))
{
 $Januarybh=$row['Januarybh'];
 $junbh=$row['junbh'];
 $Marchbh=$row['Marchbh'];
 $augbh=$row['augbh'];
 $bus=$row['bus'];
 $totJanuarybh=$Januarybh+$junbh+$Marchbh+$augbh;
}

//Farm Income
 $query=mysqli_query($con,"select farminput.item, (SELECT SUM(Amount) from farminput where Month='January' AND Year='$yr') as Januaryfam,
 (SELECT SUM(Amount) from farminput where Month='February' AND Year='$yr') as junfam,
 (SELECT SUM(Amount) from farminput where Month='March' AND Year='$yr') as Marchfam,
 (SELECT SUM(Amount) from farminput where Month='April' AND Year='$yr') as augfam FROM farminput where Year='$yr'");
while($row=mysqli_fetch_array($query))
{
 $Januaryfam=$row['Januaryfam'];
 $junfam=$row['junfam'];
 $Marchfam=$row['Marchfam'];
 $augfam=$row['augfam'];
 $totJanuaryfam=$Januaryfam+$junfam+$Marchfam+$augfam;
}

$totincomeJanuaryaug=$subtncbc+$totJanuarytour+$totJanuarybh+$totJanuaryfam+$subtn;


//EXPENSES ------------------------------------------------------------------------------------------------------------------
//Project Bank
$query=mysqli_query($con,"select Item, (SELECT SUM(Amount) from prodata where Month='January' AND Year='$yr') as mpro, 
(SELECT SUM(Amount) from prodata where Month='February' AND Year='$yr') as jupro,
(SELECT SUM(Amount) from prodata where Month='March' AND Year='$yr') as julpro,
(SELECT SUM(Amount) from prodata where Month='April' 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'];
 $totJanuaryproject=$mpro+$jupro+$julpro+$aupro;
}

//Salaries
$query=mysqli_query($con,"select Staff_id, (SELECT SUM(Gross) from payment where Month='January' AND Year='$yr' AND Approved='Yes') as masala, 
(SELECT SUM(Gross) from payment where Month='February' AND Year='$yr' AND Approved='Yes') as jusala,
(SELECT SUM(Gross) from payment where Month='March' AND Year='$yr' AND Approved='Yes') as julsala,
(SELECT SUM(Gross) from payment where Month='April' 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'];
 $totJanuarysala=$msala+$jusala+$julsala+$ausala;
}


//Category Expenses
$query=mysqli_query($con,"select expenses.*,(SELECT SUM(Amount) FROM Expenses where Month='January' AND Year='$yr') as Januaryyexpe,
(SELECT SUM(Amount) FROM Imprest2 where Month='January' AND Year='$yr') as Januaryyexpe2,
(SELECT SUM(Amount) FROM Expenses where Month='February' AND Year='$yr') as Februaryexpe,
(SELECT SUM(Amount) FROM Imprest2 where Month='February' AND Year='$yr') as Februaryexpe2,

(SELECT SUM(Amount) FROM Expenses where Month='March' AND Year='$yr') as Marchexpe,
(SELECT SUM(Amount) FROM Imprest2 where Month='March' AND Year='$yr') as Marchexpe2,

(SELECT SUM(Amount) FROM Expenses where Month='April' AND Year='$yr') as augaexpe,
(SELECT SUM(Amount) FROM Imprest2 where Month='April' AND Year='$yr') as augaexpe2 from expenses ORDER BY Item DESC");
while($row=mysqli_fetch_array($query))
{
$totJanuarye=$row['Januaryyexpe']+$row['Januaryyexpe2'];
$totFebruarye=$row['Februaryexpe']+$row['Februaryexpe2'];
$totMarche=$row['Marchexpe']+$row['Marchexpe2'];
$totaugae=$row['augaexpe']+$row['augaexpe2'];
}

$totexpe=$totJanuarye+$totFebruarye+$totMarche+$totaugae;
$totalexpens=$totJanuaryproject+$totJanuarysala+$totexpe;

?>




