<?php 
include("../db.php");
if($_REQUEST["type"]=="tc_data"){
	//echo $_REQUEST['class'];
	$where="";
	if(isset($_REQUEST["class"]))$where=" AND class='".$_REQUEST["class"]."'";
	if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="undefined")$where.=" AND section='".$_REQUEST["section"]."' ";
	$sql_limit="select * from newtc ";
	$aryList=$db->getRows($sql_limit);
	$aryPgAct=array("page_id"=>"print_newtc","action"=>"add");
	if(is_array($aryList) && count($aryList)>0)
	{
		$aryData='{ "aaData": [
		';
	    $i=0;
		foreach($aryList as $iList)
		{
			$aryPgAct["id"]=$iList['tc_number'];
			$i++;
			$aryData.='["'.POST($iList['tc_number']).'",';
			$aryData.='"'.POST($iList['nameofpupil']).'",';
			$aryData.='"'.POST($iList['nameofGuardien']).'",';
			$aryData.='"'.POST($iList['DOB']).'",';
			$aryData.='"'.POST($iList['last_class']).'",';
			$aryData.='"'.POST($iList['year']).'",';
			$aryData.='"';
			if($iList["issue_TC"]==0){ $aryPgAct['action']="tc";
			
			}
			$aryPgAct['action']="print";
			$aryData.='<a href=\''.URL_ROOT.'print/'.getQueryString($aryPgAct).'\' ><button type=\'button\' class=\'btn btn-danger\'>Print TC</button></a>';
			
			$aryData.='<a href=\''.URL_ROOT.'?src=TC&page_id=edit_newtc&id='.$iList['tc_number'].'\' ><button type=\'button\' class=\'btn btn-danger\'>Edit TC</button></a>';
			
			


			$aryData.='"]';
			if($i!=count($aryList))$aryData.=",";
		 }
		 $aryData.="] }";	
		 echo $aryData;	
	}else{
		echo $db->getLastQuery().$db->getErMsg();
	}
}else{
	$where=array();
	$where[]=" i.idno=s.idno and s.idno=it.idno and it.idno='".$_REQUEST["idno"]."' and s.session='".$_SESSION["admin"]["session"]."' and s.status=1 ";
	$table=" installment as i, installment_time as it, student as s";
	$detail=$db->getRow("SELECT i.*,i.bus as busfe,s.class as sclass,s.name,s.mobile,s.medium,it.ins_name,it.date FROM ".$table." where i.school_id='".$_SESSION["admin"]["school_id"]."' and ".implode(" AND ",$where)."");
	
	$overAllTotal=0;$overAllFee=0;$overAllBus=0;$overAllDiscount=0;
	$overTotal=0;$overFee=0;$overBus=0;$iptotal=0;$bptotal=0;$ipremail=0;$bpremail=0;
	if(is_array($detail) && count($detail)>0){
		$overBus=0;$bptotal=0;
		(int)$total=(int)$detail["total"]+(int)$detail["busfe"];
		(int)$overFee=(int)$overFee+(int)$detail["total"];
		(int)$overBus=(int)$overBus+(int)$detail["busfe"];
		$ip=$detail["ip1"]+$detail["ip2"]+$detail["ip3"]+$detail["ip4"]+$detail["ip5"]+$detail["ip6"]+$detail["ip7"]+$detail["ip8"]+$detail["ip9"]+$detail["ip10"]+$detail["ip11"]+$detail["ip12"]+$detail["ip13"]+$detail["ip14"]+$detail["ip15"];
		$iptotal=$ip;
		$bp=$detail["bp1"]+$detail["bp2"]+$detail["bp3"]+$detail["bp4"]+$detail["bp5"]+$detail["bp6"]+$detail["bp7"]+$detail["bp8"]+$detail["bp9"]+$detail["bp10"]+$detail["bp11"]+$detail["bp12"]+$detail["bp13"]+$detail["bp14"]+$detail["bp15"];
		$bptotal=$bp;
		$totalPay=$ip+$bp;
		if($total>$totalPay){
			if($overFee>$ip)
				echo "Class Fee Remaining ".($overFee-$ip).": Total class fee is $overFee and student Pay $ip \n";
			elseif($overBus>$bp)
				echo "Bus Fee Remaining ".($overBus-$bp).": Total class fee is $overBus and student Pay $bp\n";
			else
				echo "Total Fee Remaining ".($total-$totalPay).": Total class fee is $total and student Pay $totalPay";
		}else{
			echo "1";
		}
	}
}
?>