<?php



if(isset($_POST["submit600"])){
$selectyear=$_POST['schoolyear'];
$ya = "and schoolyear=$selectyear";
$tid= $_POST['term'];
}
else
{
$selectyear=date('y');
$ya = "and schoolyear=$selectyear";
$cm = date("m");

if ($cm>='1' and $cm<='4'){$tid="1";}
elseif ($cm>='5' and $cm<='8'){$tid="2";}
elseif ($cm>='9' and $cm<='12'){$tid="3";}
}
//Unpaid fees and requirements primary 
$resultexpected1 = $dbh->query("select sum(uniform) from t".$tid." where schoolclass<20 $ya");
$rowexpected1 = $resultexpected1->fetch();

$resultexpected2 = $dbh->query("select sum(contribution) from t".$tid." where schoolclass<20 $ya");
$rowexpected2 = $resultexpected2->fetch();

$resultexpected3 = $dbh->query("select sum(registration) from t".$tid." where schoolclass<20 $ya");
$rowexpected3 = $resultexpected3->fetch();

$resultexpected4 = $dbh->query("select sum(holiday) from t".$tid." where schoolclass<20 $ya");
$rowexpected4 = $resultexpected4->fetch();

$resultexpected5 = $dbh->query("select sum(admission) from t".$tid." where schoolclass<20 $ya");
$rowexpected5 = $resultexpected5->fetch();

$resultexpected6 = $dbh->query("select sum(transport) from t".$tid." where schoolclass<20 $ya");
$rowexpected6 = $resultexpected6->fetch();

$resultexpected7 = $dbh->query("select sum(mockfa) from t".$tid." where schoolclass<20 $ya");
$rowexpected7 = $resultexpected7->fetch();

$resultexpected8 = $dbh->query("select sum(other1) from t".$tid." where schoolclass<20 $ya");
$rowexpected8 = $resultexpected8->fetch();

$resultexpected9 = $dbh->query("select sum(other2) from t".$tid." where schoolclass<20 $ya");
$rowexpected9 = $resultexpected9->fetch();

$resultexpected911 = $dbh->query("select sum(other3) from t".$tid." where schoolclass<20 $ya");
$rowexpected911 = $resultexpected911->fetch();

$resultexpected912 = $dbh->query("select sum(ownfee) from t".$tid." where schoolclass<20 $ya");
$rowexpected912 = $resultexpected912->fetch();
/*above: Unpaid fees and requirements primary */

/*below: Unpaid fees and requirements secondary */
$resultexpected21 = $dbh->query("select sum(uniform) from t".$tid." where schoolclass>20 $ya");
$rowexpected21 = $resultexpected21->fetch();

$resultexpected22 = $dbh->query("select sum(contribution) from t".$tid." where schoolclass>20 $ya");
$rowexpected22 = $resultexpected22->fetch();

$resultexpected23 = $dbh->query("select sum(registration) from t".$tid." where schoolclass>20 $ya");
$rowexpected23 = $resultexpected23->fetch();

$resultexpected24 = $dbh->query("select sum(holiday) from t".$tid." where schoolclass>20 $ya");
$rowexpected24 = $resultexpected24->fetch();

$resultexpected25 = $dbh->query("select sum(admission) from t".$tid." where schoolclass>20 $ya");
$rowexpected25 = $resultexpected25->fetch();

$resultexpected26 = $dbh->query("select sum(transport) from t".$tid." where schoolclass>20 $ya");
$rowexpected26 = $resultexpected26->fetch();

$resultexpected27 = $dbh->query("select sum(mockfa) from t".$tid." where schoolclass>20 $ya");
$rowexpected27 = $resultexpected27->fetch();

$resultexpected28 = $dbh->query("select sum(other1) from t".$tid." where schoolclass>20 $ya");
$rowexpected28 = $resultexpected28->fetch();

$resultexpected29 = $dbh->query("select sum(other2) from t".$tid." where schoolclass>20 $ya");
$rowexpected29 = $resultexpected29->fetch();

$resultexpected291 = $dbh->query("select sum(other3) from t".$tid." where schoolclass>20 $ya");
$rowexpected291 = $resultexpected291->fetch();

$resultexpected292 = $dbh->query("select sum(ownfee) from t".$tid." where schoolclass>20 $ya");
$rowexpected292 = $resultexpected292->fetch();

$pri_expected = $dbh->query
("select sum(ownfee)+sum(uniform)+sum(contribution)+sum(registration)+sum(holiday)+sum(admission)+sum(transport)+sum(mockfa)+sum(other1)+sum(other2)+sum(other3) AS pri_totalexpected from t".$tid." where schoolclass<20 $ya");
$row_expected1 = $pri_expected->fetchObject(); 

$sec_expected = $dbh->query
("select sum(ownfee)+sum(uniform)+sum(contribution)+sum(registration)+sum(holiday)+sum(admission)+sum(transport)+sum(mockfa)+sum(other1)+sum(other2)+sum(other3) AS sec_totalexpected from t".$tid." where schoolclass>20 $ya");
$row_expected2 = $sec_expected->fetchObject();

$pri_income = $dbh->query
("select sum(p_fees)+sum(p_uniform)+sum(p_contribution)+sum(p_registration)+sum(p_holiday)+sum(p_admission)+sum(p_transport)+sum(p_mockfa)+sum(p_other1)+sum(p_other2)+sum(p_other3
	) AS pri_totalincome from received where schoolclass<20 and term=".$tid." $ya");
$row_income1 = $pri_income->fetchObject(); 
// if using variable $rowto, make sure this line is equal to just fetch and then print $rowto[0]. else if using variable mytotal, rowto should equal fetchObject() and print should be $rowto->mytotal


$sec_income = $dbh->query
("select sum(p_fees)+sum(p_uniform)+sum(p_contribution)+sum(p_registration)+sum(p_holiday)+sum(p_admission)+sum(p_transport)+sum(p_mockfa)+sum(p_other1)+sum(p_other2)+sum(p_other3
	) AS sec_totalincome from received where schoolclass>20 and term=".$tid." $ya");
$row_income2 = $sec_income->fetchObject();

/*above: Unpaid fees and requirements secondary */

/*

$resultunpaidp1 = $dbh->query("select sum(p_uniform) from received where schoolclass<20 $ya and schoolyear='$ya' and term='2'");
$rowunpaidp1 = $resultunpaidp1->fetch();

$resultunpaidp2 = $dbh->query("select sum(p_contribution) from received where schoolclass<20 $ya and schoolyear='$ya' and term='2'");
$rowunpaidp2 = $resultunpaidp2->fetch();

$resultunpaidp3 = $dbh->query("select sum(p_registration) from received where schoolclass<20 $ya and schoolyear='$ya' and term='2'");
$rowunpaidp3 = $resultunpaidp3->fetch();

$resultunpaidp4 = $dbh->query("select sum(p_uniform) from received where schoolclass<20 $ya and schoolyear='$ya' and term='2'");
$rowunpaidp4 = $resultunpaidp4->fetch();

$resultunpaidp5 = $dbh->query("select sum(p_admission) from received where schoolclass<20 $ya and schoolyear='$ya' and term='2'");
$rowunpaidp5 = $resultunpaidp5->fetch();

$resultunpaidp6 = $dbh->query("select sum(p_transport) from received where schoolclass<20 $ya and schoolyear='$ya' and term='2'");
$rowunpaidp6 = $resultunpaidp6->fetch();

$resultunpaidp7 = $dbh->query("select sum(p_mockfa) from received where schoolclass<20 $ya and schoolyear='$ya' and term='2'");
$rowunpaidp7 = $resultunpaidp7->fetch();

$resultunpaidp8 = $dbh->query("select sum(p_other1) from received where schoolclass<20 $ya and schoolyear='$ya' and term='2'");
$rowunpaidp8 = $resultunpaidp8->fetch();

$resultunpaidp9 = $dbh->query("select sum(p_other2) from received where schoolclass<20 $ya and schoolyear='$ya' and term='2'");
$rowunpaidp9 = $resultunpaidp9->fetch();

$resultunpaidp10 = $dbh->query("select sum(p_other3) from received where schoolclass<20 $ya and schoolyear='$ya' and term='2'");
$rowunpaidp10 = $resultunpaidp10->fetch();

$resultunpaidp11 = $dbh->query("select sum(p_fees) from received where schoolclass<20 $ya and schoolyear='$ya' and term='2'");
$rowunpaidp11 = $resultunpaidp11->fetch();

/*Unpaid fees and requirements primary received */

/*Unpaid fees and requirements secondary received *//*
$ya = date("y");

$resultunpaidpz11 = $dbh->query("select sum(p_uniform) from received where cid>='50000' and schoolyear='$ya' and term='2'");
$rowunpaidpz11 = $resultunpaidpz11->fetch();

$resultunpaidp22 = $dbh->query("select sum(p_contribution) from received where cid>='50000' and schoolyear='$ya' and term='2'");
$rowunpaidp22 = $resultunpaidp22->fetch();

$resultunpaidp33 = $dbh->query("select sum(p_registration) from received where cid>='50000' and schoolyear='$ya' and term='2'");
$rowunpaidp33 = $resultunpaidp33->fetch();

$resultunpaidp44 = $dbh->query("select sum(p_holiday) from received where cid>='50000' and schoolyear='$ya' and term='2'");
$rowunpaidp44 = $resultunpaidp44->fetch();

$resultunpaidp55 = $dbh->query("select sum(p_admission) from received where cid>='50000' and schoolyear='$ya' and term='2'");
$rowunpaidp55 = $resultunpaidp55->fetch();

$resultunpaidp66 = $dbh->query("select sum(p_transport) from received where cid>='50000' and schoolyear='$ya' and term='2'");
$rowunpaidp66 = $resultunpaidp66->fetch();

$resultunpaidp77 = $dbh->query("select sum(p_mockfa) from received where cid>='50000' and schoolyear='$ya' and term='2'");
$rowunpaidp77 = $resultunpaidp77->fetch();

$resultunpaidp88 = $dbh->query("select sum(p_other1) from received where cid>='50000' and schoolyear='$ya' and term='2'");
$rowunpaidp88 = $resultunpaidp88->fetch();

$resultunpaidp99 = $dbh->query("select sum(p_other2) from received where cid>='50000' and schoolyear='$ya' and term='2'");
$rowunpaidp99 = $resultunpaidp99->fetch();

$resultunpaidp110 = $dbh->query("select sum(p_other3) from received where cid>='50000' and schoolyear='$ya' and term='2'");
$rowunpaidp110 = $resultunpaidp110->fetch();

$resultunpaidp111 = $dbh->query("select sum(p_fees) from received where cid>='50000' and schoolyear='$ya' and term='2'");
$rowunpaidp111 = $resultunpaidp111->fetch();

/*Unpaid fees and requirements scondary received */

?>