<?php 
$pgMod="pay_fee";
$pgAct="view";
unset($_SESSION["recept"]);
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);
		
if(isset($_POST["payNow"])){
	if($_POST["payNow"]==""){
		$alert_err[]="Please enter Pay amount";
	}elseif($_POST["payNow"]<=0){
		$alert_err[]="Amount must greater than 0";
	}elseif(!is_numeric($_POST["payNow"])){
		$alert_err[]="Amount must Numeric";
	}elseif($_POST["payNow"]>$_POST["paytotalMoth"]){
		$alert_err[]="Amount must less than total amount";
	}else{
	//echo "<pre>";print_r($_POST);exit;
	//echo "<pre>";print_r($_POST["pay-type"]);exit;
	$total=$_POST["payNow"];$totalPay=0;$next=0;$arraData=array();
	$monthary=array_unique($_POST["pay-month"]);
	 $monthAll=implode(",",$monthary);
	$receptData=array(	"page_id"=>"recepitNew",
						"idno"=>$_GET["id"],
						"udate"=>date("Y-m-d"),
						"amount"=>$total,
						"type"=>"fee",
						"paytype"=>"classfee",
						"class"=>$_POST["cls"],
						"total"=>$_POST["paytotalMoth"],
						"month"=>$monthAll,
						"install"=>$_POST["MyActivatedMonth"]
	);
	
	for($i=0; $i<count($_POST["pay-type"]);$i++){
		//echo $total.">".$_POST["pay-value"][$i]."<br />";
		
		if($total>=$_POST["pay-value"][$i]){
			
			$arraData[]=array("month"=>$_POST["pay-month"][$i],
							"total"=>$_POST["pay-value"][$i],
							"given"=>$_POST["pay-value"][$i],
							"type"=>$_POST["pay-type"][$i],
							"name"=>$_POST["pay-name"][$i],
							"left"=>$_POST["pay-left"][$i],
							"idd"=>$_POST["pay-idd"][$i]
			);
			
			$ptype=$db->getVal("select type from extrafee_type where id='".$_POST["pay-type"][$i]."'");
			if($_POST["pay-type"][$i]=="other"){
				$recept="fee-".$_POST["pay-name"][$i];
				//$recept="fee-".str_replace(" ","_",$_POST["pay-name"][$i]);
				if(array_key_exists($recept,$receptData))
				$receptData[$recept]+=$_POST["pay-value"][$i];
				else
				$receptData[$recept]=$_POST["pay-value"][$i];
			}else{
			$recept="fee-".$_POST["pay-type"][$i];
			
			if($ptype!="")$recept="fee-".str_replace(" ","_",$ptype);
			if(array_key_exists($recept,$receptData))
			$receptData[$recept]+=$_POST["pay-value"][$i];
			else
			$receptData[$recept]=$_POST["pay-value"][$i];
		   }
		}elseif($total>0){
			
			$arraData[]=array("month"=>$_POST["pay-month"][$i],
							"total"=>$_POST["pay-value"][$i],
							"given"=>$total,
							"type"=>$_POST["pay-type"][$i],
							"name"=>$_POST["pay-name"][$i],
							"left"=>$_POST["pay-left"][$i],
							"idd"=>$_POST["pay-idd"][$i]
			);
						
			$ptype=$db->getVal("select type from extrafee_type where id='".$_POST["pay-type"][$i]."'");
			if($_POST["pay-type"][$i]=="other"){
				$recept="fee-".$_POST["pay-name"][$i];
				//$recept="fee-".str_replace(" ","_",$_POST["pay-name"][$i]);
				if(array_key_exists($recept,$receptData))
				$receptData[$recept]+=$total;
				else
				$receptData[$recept]=$total;
			}else{
			$recept="fee-".$_POST["pay-type"][$i];
			
			if($ptype!="")$recept="fee-".$ptype;
			if(array_key_exists($recept,$receptData))
			$receptData[$recept]+=$total;
			else
			$receptData[$recept]=$total;
		    }
		}
		
	//	if($_POST["pay-name"][$i]=="tuition_fine" || $_POST["pay-name"][$i]=="bus_fine"){$total=$total+$_POST["pay-value"][$i];}
		//	else{
		$total=$total-$_POST["pay-value"][$i];
		/*$totalPay=$totalPay+$_POST["pay-value"][$i];
		//echo $next.">".$total.">".$totalPay."<br />";
		if($total>$totalPay){
			$arraData[]=array("month"=>$_POST["pay-month"][$i],
							"total"=>$_POST["pay-value"][$i],
							"given"=>$_POST["pay-value"][$i],
							"type"=>$_POST["pay-type"][$i]
			);
		}elseif($next>0){
			$arraData[]=array("month"=>$_POST["pay-month"][$i],
							"total"=>$_POST["pay-value"][$i],
							"given"=>$next,
							"type"=>$_POST["pay-type"][$i]
			);
		}
		$next=$total-$totalPay;*/
	}//print_r($receptData);exit;
	$url=array();
	foreach($receptData as $key=>$val){
		$url[]=$key."=".$val;
	}
	$rrid=array();
	//print_r($arraData);exit;
	//$sid=$_REQUEST['student_id'];
	$compURL="print/?".implode("&",$url);
	if(is_array($arraData) && count($arraData)>0){
		foreach($arraData as $iData){
			if($iData["type"]=="tution"){
				$aryInstall=$db->getRow("select * from installment where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
				$requestid=$iData["month"];
				$given=$iData["given"];
				$total=0;$givenTotal=0;$k=0;
				$reff_receipt=array("amount"=>$iData["given"],
									"type"=>"fee",
									"idno"=>$_GET["id"],
									"session"=>$_SESSION["admin"]["session"]
									);
				$inst_id=array();
				
				if($aryInstall["i".$requestid]!=""){
					$k++;
					$total=$total+$aryInstall["i".$requestid];
					$nexttotal=$total+$aryInstall["i".($requestid+1)];$currentTotal=0;$balanceTotal=0;
					//echo $total." ".$nexttotal." ".$i."\n";
					if($given<$total){
						
						$newInstallment=$total-$iData["given"];//." ".$aryInstall["i".($requestid+$j)]." ";
						$newNextInstallment=$newInstallment+$aryInstall["i".($requestid+1)];
						$insAry=array( "ip".($requestid)=>$given,
							"i".($requestid+1)=>$newNextInstallment
						);
						
						if($requestid=='12'){
						$inup=$db->query("update installment set ip12=COALESCE(ip12,0)+'".$given."' where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");}else {
						
						$inup=$db->updateAry("installment",$insAry," where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
						}
						deposit($given,$_GET["id"],json_encode($insAry),"fee","Student fee Payment in installment type");
						installment_time($_GET["id"],"ip".$requestid);
						//sms(mydetail("mobile",$_GET["id"],"student"),"Dear Parent, Amount of ".$given." successfully submitted as Tution fee in ".$LinksDetails["site_name"],"fee_submit");
						$inst_id[]=$requestid;
					
					}elseif($given==$total){
						
						$insAry=array( "ip".($requestid)	=>	$aryInstall["i".($requestid)]);
						$inup=$db->updateAry("installment",$insAry," where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
						
						deposit($aryInstall["i".($requestid)],$_GET["id"],json_encode($insAry),"fee","Student fee Payment in installment type");
						
						installment_time($_GET["id"],"ip".($requestid));
						$inst_id[]=$requestid;
						
						//sms(mydetail("mobile",$_GET["id"],"student"),"Dear Parent, Amount of ".$given." successfully submitted as Tution fee in ".$LinksDetails["site_name"],"fee_submit");
					
					}
				}
				if(is_array($inst_id) && count($inst_id)>0){
					$reff_receipt["inst_id"]=implode(",",$inst_id);
					$reff_receipt["school_id"]=$_SESSION["admin"]["school_id"];
					$reff_receipt["added_by"]=$_SESSION["admin"]["uid"];
					$rrid[]=$db->insertAry("reff_receipt",$reff_receipt);
				}
				//echo $given."/".$Payment."/".$total;
			}
			elseif($iData["type"]=="bus"){
				$aryInstall=$db->getRow("select * from installment where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
			
				$nextin="b".($iData["month"]+1);
				$requestid=$iData["month"];
				$given=$iData["given"];//busgiven
				$total=0;$givenTotal=0;$k=0;
				$reff_receipt=array("amount"=>$given,
									"type"=>"busfee",
									"idno"=>$_GET["id"],
									"session"=>$_SESSION["admin"]["session"]
									);
				$inst_id=array();
				if($aryInstall["b".($requestid)]!=""){
					$total=$total+$aryInstall["b".($requestid)];
					$nexttotal=$total+$aryInstall["b".($requestid+1)];$currentTotal=0;$balanceTotal=0;
					//echo "$total && $given<$nexttotal";exit;
					if($given<$total){
						$newInstallment=$total-$given;
						$newNextInstallment=$newInstallment+$aryInstall["b".($requestid+1)];
						$insAry=array( "bp".($requestid)	=>	$given,
									"b".($requestid+1)	=>	$newNextInstallment
						);
						
						if($requestid=='12'){
						$inup=$db->query("update installment set bp12=COALESCE(bp12,0)+'".$given."' where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");}else {
							
						$inup=$db->updateAry("installment",$insAry," where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
						
						}
						

						//$inup=$db->updateAry("installment",$insAry," where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
						deposit($given,$_GET["id"],json_encode($insAry),"bus","Student bus fee Payment in installment type");
						$inst_id[]=$requestid;
						installment_time($_GET["id"],"bp".$requestid);
						//sms(mydetail("mobile",$_GET["id"],"student"),"Dear Parent, Amount of ".$given." successfully submitted as Bus fee in ".$LinksDetails["site_name"],"fee_submit");
					}
					elseif($given==$total){	
						$insAry=array( "bp".($requestid)=>	$aryInstall["b".($requestid)]);
						$inup=$db->updateAry("installment",$insAry," where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
						
						deposit($aryInstall["b".($requestid)],$_GET["id"],json_encode($insAry),"bus","Student bus fee Payment in installment type");
						installment_time($_GET["id"],"bp".($requestid));
						//sms(mydetail("mobile",$_GET["id"],"student"),"Dear Parent, Amount of ".$given." successfully submitted as Bus fee in ".$LinksDetails["site_name"],"fee_submit");
						$inst_id[]=$requestid+$j;
					}
					
				}
				if(is_array($inst_id) && count($inst_id)>0){
					$reff_receipt["inst_id"]=implode(",",$inst_id);
					$reff_receipt["school_id"]=$_SESSION["admin"]["school_id"];
					$reff_receipt["added_by"]=$_SESSION["admin"]["uid"];
					$rrid[]=$db->insertAry("reff_receipt",$reff_receipt);//echo $db->getErMsg();exit;
				}
			}
			elseif($iData["type"]=="hostel"){
				//echo $_REQUEST["udate"];exit;
				$aryInstall=$db->getRow("select * from hostelinstallment where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
				$nextin="i".($iData["month"]+1);
				$requestid=$iData["month"];
				$given=$iData["given"];//busgiven
				$total=0;$givenTotal=0;$k=0;
				$reff_receipt=array("amount"=>$given,
									"type"=>"hostelfee",
									"idno"=>$_GET["id"],
									"session"=>$_SESSION["admin"]["session"]
									);
				$inst_id=array();
				
				if($aryInstall["i".($requestid)]!=""){
					$k++;
					$total=$total+$aryInstall["i".($requestid)];
					$nexttotal=$total+$aryInstall["i".($requestid+1)];$currentTotal=0;$balanceTotal=0;
					//echo "$total && $given<$nexttotal";exit;
					if($given<$total){
						$newInstallment=$total-$given;
						$newNextInstallment=$newInstallment+$aryInstall["i".($requestid+1)];
						$insAry=array( "ip".($requestid)	=>	$given,
									"i".($requestid+1)	=>	$newNextInstallment
						);
						
						$inup=$db->updateAry("hostelinstallment",$insAry," where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
						deposit($given,$_GET["id"],json_encode($insAry),"hostel","Student hostel fee Payment in installment type");
						$inst_id[]=$requestid;
						installment_time($_GET["id"],"hp".$requestid);
						//sms(mydetail("mobile",$_GET["id"],"student"),"Dear Parent, Amount of ".$given." successfully submitted as hostel fee in ".$LinksDetails["site_name"],"fee_submit");
					}
					elseif($given==$total){
						$insAry=array( "ip".($requestid)	=>	$aryInstall["i".($requestid)]);
						$inup=$db->updateAry("hostelinstallment",$insAry," where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
						deposit($aryInstall["i".($requestid)],$_GET["id"],json_encode($insAry),"hostel","Student hostel fee Payment in installment type");
						installment_time($_GET["id"],"hp".($requestid));
						//sms(mydetail("mobile",$_GET["id"],"student"),"Dear Parent, Amount of ".$given." successfully submitted as hostel fee in ".$LinksDetails["site_name"],"fee_submit");
						$inst_id[]=$requestid+$j;
						
					}					
				}
				if(is_array($inst_id) && count($inst_id)>0){
					$reff_receipt["inst_id"]=implode(",",$inst_id);
					$reff_receipt["school_id"]=$_SESSION["admin"]["school_id"];
					$reff_receipt["added_by"]=$_SESSION["admin"]["uid"];
					$rrid[]=$db->insertAry("reff_receipt",$reff_receipt);//echo $db->getErMsg();exit;
				}
			}
			elseif($iData['type']=="other"){
				$other=$db->getRow("select * from otherfee_structure where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and name='".$iData['name']."' and class='".$_POST['cls']."' and month='".$iData['month']."'");
				//echo $db->getLastQuery();exit;
				$udate=date("Y-m-d H:i:g");
				//echo print_r($arraData)."left=>".$iData["left"];exit;
				if($iData["left"]==1){
					$insAry=array(  "ins_name"	=>	$iData["idd"]."-other",
					"fine"		=>	$iData["given"],
					"reasion"	=>	$iData["name"],
					'udate'		=>  date("Y-m-d H:i:g"),
					"status"	=>	"1",
					"idno"		=>	$_GET['id']
					
				);
				$insAry["school_id"]=$_SESSION["admin"]["school_id"];
				$insAry["added_by"]=$_SESSION["admin"]["uid"];
				$insAry["session"]=$_SESSION["admin"]["session"];
				//print_r($insAry);exit;
				$inup=$db->insertAry("installment_fine",$insAry);
					if($inup>0){
						//installment_time($_GET['id'],"other".$iData["idd"]."_detail",$udate);
						//if($iData["given"]>0)
						deposit($iData["given"],$_GET['id'],$inup,"fine",$iData['name']);
						
						$reff_receipt=array("amount"=>$iData["given"],
										"type"=>$iData["name"],
										"idno"=>$_GET['id'],
										"date"=>$udate,
										"session"=>$_SESSION["admin"]["session"]
										);
						$reff_receipt["inst_id"]=$inup;
						$reff_receipt["school_id"]=$_SESSION["admin"]["school_id"];
						$reff_receipt["added_by"]=$_SESSION["admin"]["uid"];
						$rrid[]=$db->insertAry("reff_receipt",$reff_receipt);
					 }
				}
				else{
				$insAry=array(  "ins_name"	=>	$iData["idd"]."-otherfee",
					"fine"		=>	$iData["given"],
					"reasion"	=>	$iData["name"],
					'udate'		=>  date("Y-m-d H:i:g"),
					"status"	=>	"1",
					"idno"		=>	$_GET['id']
					
				);
				$insAry["school_id"]=$_SESSION["admin"]["school_id"];
				$insAry["added_by"]=$_SESSION["admin"]["uid"];
				$insAry["session"]=$_SESSION["admin"]["session"];
				//print_r($insAry);exit;
				$inup=$db->insertAry("installment_fine",$insAry);
				if($inup>0){
					installment_time($_GET['id'],"other".$iData["idd"]."_detail",$udate);
					deposit($iData["given"],$_GET['id'],$inup,"other".$iData["idd"]."_fee","Student Other fee ".$iData['name']);
					
					$reff_receipt=array("amount"=>$iData["given"],
									"type"=>$iData["name"],
									"idno"=>$_GET['id'],
									"date"=>$udate,
									"session"=>$_SESSION["admin"]["session"]
									);
					$reff_receipt["inst_id"]=$inup;
					$reff_receipt["school_id"]=$_SESSION["admin"]["school_id"];
					$reff_receipt["added_by"]=$_SESSION["admin"]["uid"];
					$rrid[]=$db->insertAry("reff_receipt",$reff_receipt);
				}
			}}
			else{
				//echo $_REQUEST["udate"];exit;
				$aryInstall=$db->getRow("select * from extrafee where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."' and pid='p".$iData["month"]."' and type='".$iData["type"]."'");
			
				$requestid=$iData["month"];
				$given=$iData["given"];//busgiven
				$total=$aryInstall["fee"];
				$reff_receipt=array("amount"=>$iData["given"],
									"type"=>"extrafee".$iData["type"],
									"idno"=>$_GET["id"],
									"session"=>$_SESSION["admin"]["session"]
									);
				$inst_id=array();
				$detailDt=$iData["type"];
				if($given<$total){
					$nextin="p".($requestid+1);
					$newInstallment=$total-$given;
					$oldNewTotFee=$db->getVal("select fee from extrafee where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."' and pid='".$nextin."' and type='".$iData["type"]."'");
					$newNextInstallment=$newInstallment+$oldNewTotFee;
					$insAryJ=array( "pay".$requestid	=>	$given);
					if($requestid=='12'){
						
					
					$oldFee=$db->getVal("select pay from extrafee where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."' and pid='p12' and type='".$iData["type"]."'");
					$g=$given+$oldFee;
					$insAry=array( "pay"	=>	$g);
					$inup=$db->updateAry("extrafee",$insAry," where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."' and pid='p".$requestid."' and type='".$iData["type"]."'");
					
					//$inup=$db->query("update installment set bp12=bp12+'".$given."' where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
							
					}else{
						
				
					$in=$db->updateAry("extrafee",array( "fee"	=>	$newNextInstallment)," where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."' and pid='".$nextin."' and type='".$iData["type"]."'");
					
					$insAry=array( "pay"	=>	$given);
					$inup=$db->updateAry("extrafee",$insAry," where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."' and pid='p".$requestid."' and type='".$iData["type"]."'");
					}
					$feetype=$db->getVal("select type from extrafee_type where id='".$iData["type"]."'");
					deposit($given,$_GET["id"],json_encode($insAryJ),$feetype,"Student ".$feetype." fee Payment in installment type");
					$inst_id[]=$requestid;
					$detailDtatamu="ext-".$detailDt."-".$requestid;
					installment_time($_GET["id"],$detailDtatamu);
					//sms(mydetail("mobile",$_GET["id"],"student"),"Dear Parent, Amount of ".$given." successfully submitted as ".$feetype." fee in ".$LinksDetails["site_name"],"fee_submit");
				}
				elseif($total==$given){			
					$insAryJ=array( "pay".$requestid	=>	$given);
					$insAry=array( "pay"	=>	$given);
					$inup=$db->updateAry("extrafee",$insAry," where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."' and pid='p".$requestid."' and type='".$iData["type"]."'");
					$feetype=$db->getVal("select type from extrafee_type where id='".$iData["type"]."'");
					deposit($given,$_GET["id"],json_encode($insAryJ),$feetype,"Student ".$feetype." fee Payment in installment type");
					$inst_id[]=$requestid;
					installment_time($_GET["id"],"ext-".$detailDt."-".$requestid);
					//sms(mydetail("mobile",$_GET["id"],"student"),"Dear Parent, Amount of ".$given." successfully submitted as ".$feetype." fee in ".$LinksDetails["site_name"],"fee_submit");
				}else{
					echo "You can not make installment morethen ".$total;
				}
				if(is_array($inst_id) && count($inst_id)>0){
					$reff_receipt["inst_id"]=implode(",",$inst_id);
					$reff_receipt["school_id"]=$_SESSION["admin"]["school_id"];
					$reff_receipt["added_by"]=$_SESSION["admin"]["uid"];
					$rrid[]=$db->insertAry("reff_receipt",$reff_receipt);//echo $db->getErMsg();exit;
				}
			
			}
		}
		$ipi=$_POST["MyActivatedMonth"];$months=="";
		if($ipi<=9){
			$newDate=date("Y")."-".($ipi+3)."-1";
			$months= date("F",strtotime($newDate));//."(".($ij+3).")";
		}
		else{
			$newDate=date("Y")."-".($ipi-9)."-1";
			$months= date("F",strtotime($newDate));//."(".($ij-9).")";
		}
		sms(mydetail("mobile",$_GET["id"],"student"),"Dear Parents, The Amount of Rs. ".$_POST["payNow"]."  for the month of ".$months." has been successfully submitted. Remaining Amount is Left Rs. ".($_POST["paytotalMoth"]-$_POST["payNow"])." ","fee_submit");
		
		
		
	}
	$rid="&rrid=rrid-".implode("-",$rrid);
	$_SESSION["url"]=$compURL.$rid;
	redirect();
	}
	?><script>$("#paybym").show()</script><?php
}
elseif(isset($_POST["payNow_hostel"])){
	if($_POST["payNow_hostel"]==""){
		$alert_err[]="Please enter Pay amount";
	}elseif($_POST["payNow_hostel"]<=0){
		$alert_err[]="Amount must greater than 0";
	}elseif(!is_numeric($_POST["payNow_hostel"])){
		$alert_err[]="Amount must Numeric";
	}elseif($_POST["payNow_hostel"]>$_POST["paytotalMoth1"]){
		$alert_err[]="Amount must less than total amount";
	}else{
	//echo "<pre>";print_r($_POST);
	$total=$_POST["payNow_hostel"];$totalPay=0;$next=0;$arraData=array();
	$monthary=array_unique($_POST["pay-month"]);
	 $min=$_POST["MyActivatedMonth1"];
	 foreach($monthary as $key => $value){
		 if($value > $min)
		   unset($monthary[$key]); }
	 $monthAll=implode(",",$monthary);	   
	$receptData=array(	"page_id"=>"recepitNew_hostel",
						"idno"=>$_GET["id"],
						"udate"=>date("Y-m-d"),
						"amount"=>$total,
						"type"=>"fee",
						"paytype"=>"classfee",
						"class"=>$_POST["cls"],
						"total"=>$_POST["paytotalMoth1"],
						"month"=>$monthAll,
						"install"=>$_POST["MyActivatedMonth1"]
	);
	//echo "<pre>";print_r($receptData);exit;
	for($i=0; $i<count($_POST["pay-type"]);$i++){
		//echo $total.">".$_POST["pay-value"][$i]."<br />";exit;
		
		if($total>=$_POST["pay-value"][$i]){
			
			$arraData[]=array("month"=>$_POST["pay-month"][$i],
							"total"=>$_POST["pay-value"][$i],
							"given"=>$_POST["pay-value"][$i],
							"type"=>$_POST["pay-type"][$i],
							"name"=>$_POST["pay-name"][$i],
							"left"=>$_POST["pay-left"][$i],
							"idd"=>$_POST["pay-idd"][$i]
			);
			
			//$ptype=$db->getVal("select type from extrafee_type where id='".$_POST["pay-type"][$i]."'");
			if($_POST["pay-type"][$i]=="hostelother"){
				$recept="fee-".$_POST["pay-name"][$i];
				//$recept="fee-".str_replace(" ","_",$_POST["pay-name"][$i]);
				if(array_key_exists($recept,$receptData))
				$receptData[$recept]+=$_POST["pay-value"][$i];
				else
				$receptData[$recept]=$_POST["pay-value"][$i];
			}else{
			$recept="fee-".$_POST["pay-type"][$i];
			
			if($ptype!="")$recept="fee-".str_replace(" ","_",$ptype);
			if(array_key_exists($recept,$receptData))
			$receptData[$recept]+=$_POST["pay-value"][$i];
			else
			$receptData[$recept]=$_POST["pay-value"][$i];
		   }
		}elseif($total>0){
			
			$arraData[]=array("month"=>$_POST["pay-month"][$i],
							"total"=>$_POST["pay-value"][$i],
							"given"=>$total,
							"type"=>$_POST["pay-type"][$i],
							"name"=>$_POST["pay-name"][$i],
							"left"=>$_POST["pay-left"][$i],
							"idd"=>$_POST["pay-idd"][$i]
			);
						
			$ptype=$db->getVal("select type from extrafee_type where id='".$_POST["pay-type"][$i]."'");
			if($_POST["pay-type"][$i]=="hostelother"){
				$recept="fee-".$_POST["pay-name"][$i];
				if(array_key_exists($recept,$receptData))
				$receptData[$recept]+=$total;
				else
				$receptData[$recept]=$total;
			}else{
			$recept="fee-".$_POST["pay-type"][$i];
			
			if($ptype!="")$recept="fee-".$ptype;
			if(array_key_exists($recept,$receptData))
			$receptData[$recept]+=$total;
			else
			$receptData[$recept]=$total;
		    }
		}
		$total=$total-$_POST["pay-value"][$i];
		
	}//echo "<pre>";print_r($arraData)."<br/>".print_r($receptData);exit;
	$url1=array();
	foreach($receptData as $key=>$val){
		$url1[]=$key."=".$val;
	}
	$rrid=array();
	//print_r($arraData);exit;
	//$sid=$_REQUEST['student_id'];
	$compURL="print/?".implode("&",$url1);
	if(is_array($arraData) && count($arraData)>0){
		foreach($arraData as $iData){
			if($iData["type"]=="hostel"){
				//echo $_REQUEST["udate"];exit;
				$aryInstall=$db->getRow("select * from hostelinstallment where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
				$nextin="i".($iData["month"]+1);
				$requestid=$iData["month"];
				$given=$iData["given"];//busgiven
				$total=0;$givenTotal=0;$k=0;
				$reff_receipt=array("amount"=>$given,
									"type"=>"hostelfee",
									"idno"=>$_GET["id"],
									"session"=>$_SESSION["admin"]["session"]
									);
				$inst_id=array();
				
				if($aryInstall["i".($requestid)]!=""){
					$k++;
					$total=$total+$aryInstall["i".($requestid)];
					$nexttotal=$total+$aryInstall["i".($requestid+1)];$currentTotal=0;$balanceTotal=0;
					//echo "$total && $given<$nexttotal";exit;
					if($given<$total){
						$newInstallment=$total-$given;
						$newNextInstallment=$newInstallment+$aryInstall["i".($requestid+1)];
						$insAry=array( "ip".($requestid)	=>	$given,
									"i".($requestid+1)	=>	$newNextInstallment
						);
						
						if($requestid=='12'){
						$inup=$db->query("update hostelinstallment set ip12=COALESCE(ip12,0)+'".$given."' where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");}else {
							
						$inup=$db->updateAry("hostelinstallment",$insAry," where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
						
						}
												
						//$inup=$db->updateAry("hostelinstallment",$insAry," where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
						deposit($given,$_GET["id"],json_encode($insAry),"hostel","Student hostel fee Payment in installment type");
						$inst_id[]=$requestid;
						installment_time($_GET["id"],"hp".$requestid);
						//sms(mydetail("mobile",$_GET["id"],"student"),"Dear Parent, Amount of ".$given." successfully submitted as hostel fee in ".$LinksDetails["site_name"],"fee_submit");
					}
					elseif($given==$total){
						$insAry=array( "ip".($requestid)	=>	$aryInstall["i".($requestid)]);
						$inup=$db->updateAry("hostelinstallment",$insAry," where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
						deposit($aryInstall["i".($requestid)],$_GET["id"],json_encode($insAry),"hostel","Student hostel fee Payment in installment type");
						installment_time($_GET["id"],"hp".($requestid));
						//sms(mydetail("mobile",$_GET["id"],"student"),"Dear Parent, Amount of ".$given." successfully submitted as hostel fee in ".$LinksDetails["site_name"],"fee_submit");
						$inst_id[]=$requestid+$j;
						
					}					
				}
				if(is_array($inst_id) && count($inst_id)>0){
					$reff_receipt["inst_id"]=implode(",",$inst_id);
					$reff_receipt["school_id"]=$_SESSION["admin"]["school_id"];
					$reff_receipt["added_by"]=$_SESSION["admin"]["uid"];
					$rrid[]=$db->insertAry("reff_receipt",$reff_receipt);//echo $db->getErMsg();exit;
				}
			}
			elseif($iData['type']=="hostelother"){
				$other=$db->getRow("select * from hostel_otherfee_structure where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and name='".$iData['name']."' and class='".$_POST['cls']."' and month='".$iData['month']."'");
				//echo $db->getLastQuery();exit;
				$udate=date("Y-m-d H:i:g");
				//echo print_r($arraData)."left=>".$iData["left"];exit;
				if($iData["left"]==1){
					$insAry=array(  "ins_name"	=>	$iData["idd"]."-otherhostel",
					"fine"		=>	$iData["given"],
					"reasion"	=>	$iData["name"],
					'udate'		=>  date("Y-m-d H:i:g"),
					"status"	=>	"1",
					"idno"		=>	$_GET['id']
					
				);
				$insAry["school_id"]=$_SESSION["admin"]["school_id"];
				$insAry["added_by"]=$_SESSION["admin"]["uid"];
				$insAry["session"]=$_SESSION["admin"]["session"];
				//print_r($insAry);exit;
				$inup=$db->insertAry("installment_fine",$insAry);
					if($inup>0){
						//installment_time($_GET['id'],"other".$iData["idd"]."_detail",$udate);
						deposit($iData["given"],$_GET['id'],$inup,"fine",$iData['name']);
						
						$reff_receipt=array("amount"=>$iData["given"],
										"type"=>$iData["name"],
										"idno"=>$_GET['id'],
										"date"=>$udate,
										"session"=>$_SESSION["admin"]["session"]
										);
						$reff_receipt["inst_id"]=$inup;
						$reff_receipt["school_id"]=$_SESSION["admin"]["school_id"];
						$reff_receipt["added_by"]=$_SESSION["admin"]["uid"];
						$rrid[]=$db->insertAry("reff_receipt",$reff_receipt);
					 }
				}
				else{
				$insAry=array(  "ins_name"	=>	$iData["idd"]."-otherfeehostel",
					"fine"		=>	$iData["given"],
					"reasion"	=>	$iData["name"],
					'udate'		=>  date("Y-m-d H:i:g"),
					"status"	=>	"1",
					"idno"		=>	$_GET['id']
					
				);
				$insAry["school_id"]=$_SESSION["admin"]["school_id"];
				$insAry["added_by"]=$_SESSION["admin"]["uid"];
				$insAry["session"]=$_SESSION["admin"]["session"];
				//print_r($insAry);exit;
				$inup=$db->insertAry("installment_fine",$insAry);
				if($inup>0){
					installment_time($_GET['id'],"hostelother".$iData["idd"]."_detail",$udate);
					deposit($iData["given"],$_GET['id'],$inup,"other".$iData["idd"]."_fee","Student Other fee ".$iData['name']);
					
					$reff_receipt=array("amount"=>$iData["given"],
									"type"=>$iData["name"],
									"idno"=>$_GET['id'],
									"date"=>$udate,
									"session"=>$_SESSION["admin"]["session"]
									);
					$reff_receipt["inst_id"]=$inup;
					$reff_receipt["school_id"]=$_SESSION["admin"]["school_id"];
					$reff_receipt["added_by"]=$_SESSION["admin"]["uid"];
					$rrid[]=$db->insertAry("reff_receipt",$reff_receipt);
				}
			}}
			
		}
		$ipi=$_POST["MyActivatedMonth1"];$months=="";
		if($ipi<=9){
			$newDate=date("Y")."-".($ipi+3)."-1";
			$months= date("F",strtotime($newDate));//."(".($ij+3).")";
		}
		else{
			$newDate=date("Y")."-".($ipi-9)."-1";
			$months= date("F",strtotime($newDate));//."(".($ij-9).")";
		}
		sms(mydetail("mobile",$_GET["id"],"student"),"Dear Parents, The Amount of Rs. ".$_POST["payNow_hostel"]."  for the month of ".$months." has been successfully submitted.  Remaining Amount is Left Rs.  ".($_POST["paytotalMoth1"]-$_POST["payNow_hostel"])." ","fee_submit");
	}
	$rid="&rrid=rrid-".implode("-",$rrid);
	$_SESSION["url1"]=$compURL.$rid;
	redirect();
	}
	?><script>$("#paybym").show()</script><?php
}
if(isset($_GET["id"]) && $_GET["id"]!=""){
	$insTall=$db->getRow("select * from installment where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
	if(is_array($insTall) && count($insTall)>0){
	
	}else{
		if(!isset($_GET["dis"]) || $_GET["dis"]=="" || $_GET["dis"]=="NULL"){
		?>
		<script>
			var dis=prompt("Please Enter Tusion Fee Discount",0);
			var queryStr='&dis='+dis;
        <?php
		$installDetail=$db->getRow("select * from bus where school_id='".$_SESSION["admin"]["school_id"]."' and id=(select bus from student where idno=(SELECT is_root FROM `session_idno` where idno='".$_GET["id"]."' limit 0,1))");
		if(count($installDetail)>0){
			?>
				var busdis=prompt("Please Enter Bus Fee Discount",0);
				queryStr=queryStr+'&bus='+busdis;
			<?php
		}
		//echo $db->getLastQuery();		exit;
		?>
		window.location='?src=Promote&page_id=pay_fee&action=add&id=<?php echo $_GET["id"] ?>'+queryStr;</script>
        <?php
		exit;	
		}
		$insAry=array(	"idno"=>$_GET["id"],
						"session"=>$_SESSION["admin"]["session"],
						"discount"=>$_GET["dis"],
						"busdiscount"=>$_GET["bus"]
		);
		$total=0;
		$installDetail=$db->getRow("select * from class where school_id='".$_SESSION["admin"]["school_id"]."' and class=(select class from student where idno='".$_GET["id"]."')");
		if(is_array($installDetail) && count($installDetail)>0)
		{
			$devidedFee=(int)($installDetail["fee"]-$_GET["dis"])/(int)$installDetail["installment"];
			for($i=1; $i<=$installDetail["installment"]; $i++){
				$total=$total+$devidedFee;
				$insAry["i".$i]=$devidedFee;
			}
			$insAry["total"]=$total;
		}else{
			echo "Class May Be delete or remove From database, Please re allocate class to this student<br />
			<br />
			Click <a href='?src=Promote&page_id=pay_fee'>here</a> to ho back<br />
			".$db->getLastQuery().$db->getErMsg();
			exit;
		}
		$total=0;
		$installDetail=$db->getRow("select * from bus where school_id='".$_SESSION["admin"]["school_id"]."' and id=(select bus from student where idno=(SELECT is_root FROM `session_idno` where idno='".$_GET["id"]."' limit 0,1))");
		if(is_array($installDetail) && count($installDetail)>0)
		{
			$devidedFee=(int)($installDetail["fee"]-$_GET["bus"])/(int)$installDetail["installment"];
			for($i=1; $i<=$installDetail["installment"]; $i++){
				$insAry["b".$i]=$devidedFee;
				$total=$total+$devidedFee;
			}
			$insAry["bus"]=$total;
			//$db->insertAry("installment",$insAry);
		}
		$insAry["school_id"]=$_SESSION["admin"]["school_id"];
$insAry["added_by"]=$_SESSION["admin"]["uid"];
		$db->insertAry("installment",$insAry);//echo $db->getErMsg();
		//echo "<pre>";print_r($insAry);echo "</pre>";
	}
}
	
if(isset($_SESSION['msg']) && $_SESSION['msg']!="")
{
	?>
	<div class="alert alert-success">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-thumbs-up-alt"></i> <b>Notice</b><?php echo $_SESSION['msg'] ?></i>
	</div>
	<?php
	unset($_SESSION["msg"]);
}
if(is_array($alert_err) && count($alert_err)>0)
{
	?>
	<div class="alert alert-error">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}
if($pgAct=="add" && isset($_GET['id']) && trim($_GET['id']) !='')
{ 
	if(isset($_SESSION['form']))
	{
		$aryForm=$_SESSION['form'];
		unset($_SESSION['form']);
	}
	$aryForm=$db->getRow("SELECT * FROM student WHERE school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
?>
<style>
.st {
	width: 55px;
	display: inline-block;
	color: #021EF0;
}
.recepit {
	width: 717px !important;
	height: 344px !important;
}
.outer, .inner{ 
  max-height: 800px;
  min-height: 460px;
 }
 .outer .undefined{
  background-color: #DADADA !important;
  border: 5px inset #181616 !important;
  min-height: 440px;
  min-width:675px;
}
.half {
	width: 49%;
	display: inline-block;
	vertical-align: top;
	border-left: 4px solid #f00;
border-right: 5px solid #f00;
}
.half .input-block-level {
	width: 80px;
}
.half .table td {
	padding: 3px 5px;
}
.half center {
	font-weight: bold;
	border-top: 1px solid #f00;
	padding: 5px;
	background-color: #A7A1A1;
	color: #000;
}
</style>
<!-- Forms --> 
<div id="printDiv">		
     <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
             <!--   <h3><i class="icon-cog"></i> Student detail</h3><span>&nbsp;&nbsp;&nbsp;</span>  !-->
				      
				
				<div style="float:left; margin-top:5px;"></div>
           
				
				<div style="float:right; margin-top:5px;">
				<a href="print/?page_id=notes&id=<?php echo $_GET["id"] ?>" class="btn btn-danger fancybox">Add Notes</a>
                     <a href="print/?page_id=reciept_detail&id=<?php echo $_GET["id"] ?>" class="btn btn-danger fancybox">Recepit Detail</a>								
                <a href="print/?page_id=cheque_detail&id=<?php echo $_GET["id"] ?>" class="btn btn-danger fancybox">Cheque Detail</a>				
               		<!--<a href="print/?page_id=addamount&id=<?php echo $_GET["id"] ?>" class="btn btn-danger fancybox">Add Amount</a> -->
                	<a href="print/?page_id=addcheque&id=<?php echo $_GET["id"] ?>" class="btn btn-danger fancybox">Add Cheque</a>
                    <a href="javascript:;" onclick="checkRecept('<?php echo $aryForm["class"]; ?>')" class="btn btn-danger">Recepit</a>
                    <a href="javascript:;" onclick="checkRecept_hostel('<?php echo $aryForm["class"]; ?>')" class="btn btn-danger">Hostel-Recepit</a>
                </div>
		  <div class="control-group" style="width: 380px; margin-left:-400px;margin-top:7px;">
							<label class="control-label" for="sibling"></label>
							<div class="controls" >
							<select class="span12" onchange="location = this.value;" >
                                	<option value="">Search </option>
									<?php 
										$student=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status='1'");
										
										if($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id'])!='')
										{
                                      $stu_sib=$db->getval("select sibling from student where idno='".$_GET['id']."'");
									// print_r($stu_sib);
									$csvString= "$stu_sib";
									
$options = explode(",", $csvString);
//print_r($options);
foreach($options as $val) {
	//echo $val;
    ${"opt".$val} = "selected=\"selected\"";
	
	$sib_name=$db->getval("select name from student where idno='".$val."'");
	?>
	
	<option value="<?php echo $val; ?>" <?php echo $opt.$val ?> selected ><?php echo $sib_name=$db->getval("select name from student where idno='".$val."'"); ?>&nbsp;<?php echo $sib_name=$db->getval("select class from student where idno='".$val."'"); ?></option>
	<?php
}
?> 
 <?php
						 
						 									}
										
										foreach($student as $st){
											
											
											?>
											<option <?php if($st["idno"]==$aryForm["sibling"])echo 'selected';?>style="background-color: DarkGreen;color: #FFFFFF;" value="?src=Promote&page_id=pay_fee&action=add&id=<?php echo $st["idno"] ?>">
											 <?php echo $st["name"] ?>&nbsp;&nbsp;  <?php echo $st["fname"] ?>&nbsp;&nbsp;<?php echo $st["class"] ?> <?php echo $st["section"] ?>&nbsp;&nbsp;( <?php echo $st["admissionno"] ?>)
                                            </option>
											<?php
										}
									?>
								</select>
							</div>
						</div>   		
				
            </div>
            <div class="well" id="userdetails" style="padding: 0;margin: 0;">
            	<table class="table">
                	<tr style="border-right: 5px solid #f00;border-left: 5px solid #f00;">
                    	<td><strong class="st">Name</strong></td><td style="border-right:5px solid #f00"><?php echo $aryForm["name"] ?></td>
                        <td><strong class="st">Class</strong></td><td style="border-right:5px solid #f00"><?php echo $aryForm["class"] ?></td>
                        <td><strong class="st">Section</strong></td><td style="border-right:5px solid #f00"><?php echo $aryForm["section"] ?></td>
                        <td><strong class="st">Adm.No</strong></td><td style="border-right:5px solid #f00"><?php echo $aryForm["admissionno"] ?></td>
                        <td rowspan="2"><?php if($aryForm["photo"]!=""){
                        ?><img src="media/photo/<?php echo $aryForm["photo"]; ?>" style="height:70px" /><?php
                    }else{
                        echo "No photo uploaded";
                    }?></td>
                    </tr>
                    <tr style="border-right: 5px solid #f00;border-left: 5px solid #f00;">
                    	<td><strong class="st">DOB</strong></td><td style="border-right:5px solid #f00"><?php echo $aryForm["dob"] ?></td>
                        <td><strong class="st">Father</strong></td><td style="border-right:5px solid #f00"><?php echo $aryForm["fname"] ?></td>
                        <td><strong class="st">DOA</strong></td><td style="border-right:5px solid #f00"><?php echo $aryForm["doa"] ?></td>
                        <td><strong class="st">Contact</strong></td><td style="border-right:5px solid #f00"><?php echo $aryForm["mobile"] ?></li></td>
                    </tr>
                </table>
            </div>
        </div>
     </div> 
     <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Payment detail</h3>
                <div style="float:right; margin-top:5px">
                <form method="post" action="" id="paybymonth">
                	<select name="MyActivatedMonth" style="position:absolute" id="MyActivatedMonth" onchange="getTotalMonthCost()">
                    	<?php
						for($icheck=1;$icheck<=12;$icheck++){
						  $cheched="";
						  $cmonth=(date("n")+9);
						  if($cmonth>12){$cmonth=date("n")-3;}
						  if($icheck<=9){
								if($cmonth==$icheck )
								$cheched="selected='selected'";
								echo "<option value='".$icheck."' $cheched>";
								$newDate=date("Y")."-".($icheck+3)."-1";
								echo date("F",strtotime($newDate));//."(".($ij+3).")";
						  }
						  else{
							  	if($cmonth==$icheck )
							  	$cheched="selected='selected'";
							  	echo "<option value='".$icheck."' $cheched>";
								$newDate=date("Y")."-".($icheck-9)."-1";
								echo date("F",strtotime($newDate));//."(".($ij-9).")";
						  }
						  echo "</option>";
						}
						?>
                    </select>
                    <input type="hidden" value="<?php echo $aryForm["class"] ?>" name="cls" id="cls" />
                    <input type="text" readonly="readonly" name="paytotalMoth" id="paytotalMoth" />
                    <input type="text" name="payNow" value="<?php echo $_POST["payNow"] ?>" />
                    <button type="submit" class="btn btn-primary" id="paybym" onclick="$(this).hide()">Pay fee</button>
                    <button type="button" class="btn btn-primary" onclick="showDetail('feedetailDiv')">View Detail</button>
                   <?php

                       //echo $_SESSION["url"];				   
				    if(isset($_SESSION["url"])){
						?>
						<a data-class="recepit" href="<?php echo $_SESSION["url"] ?>" class="btn btn-primary fancybox">Print recepit</a>
						<?php
						unset($_SESSION["url"]);
					}
					?>
                    
                    <div id="appendDiv" style="display:none"></div>
                    <div id="feedetailDiv" style="display:none" title="View Payment detail"></div>
                </form>
                </div>
                
            </div><div class="top-bar" style="margin-top:-25px;">
             <h3><i class="icon-cog"></i> Hostel detail</h3>
                <div style="float:right; margin-top:10px">
                <form method="Post" action="" id="paybymonth1">
                	<select name="MyActivatedMonth1" style="position:absolute" id="MyActivatedMonth1" onchange="getHostelTotalMonthCost()">
                    	<?php
						for($icheck=1;$icheck<=12;$icheck++){
						  $cheched="";
						  $cmonth=(date("n")+9);
						  if($cmonth>12){$cmonth=date("n")-3;}
						  if($icheck<=9){
								if($cmonth==$icheck )
								$cheched="selected='selected'";
								echo "<option value='".$icheck."' $cheched>";
								$newDate=date("Y")."-".($icheck+3)."-1";
								echo date("F",strtotime($newDate));//."(".($ij+3).")";
						  }
						  else{
							  	if($cmonth==$icheck )
							  	$cheched="selected='selected'";
							  	echo "<option value='".$icheck."' $cheched>";
								$newDate=date("Y")."-".($icheck-9)."-1";
								echo date("F",strtotime($newDate));//."(".($ij-9).")";
						  }
						  echo "</option>";
						}
						?>
                    </select>
                    <input type="hidden" value="<?php echo $aryForm["class"] ?>" name="cls" id="cls" />
                    <input type="text" readonly="readonly" name="paytotalMoth1" id="paytotalMoth1" />
                    <input type="text" name="payNow_hostel" value="<?php echo $_POST["payNow_hostel"] ?>" />
                    <button type="submit" class="btn btn-primary" id="paybym" onclick="$(this).hide()">Pay fee</button>
                    <button type="button" class="btn btn-primary" onclick="showDetail('feedetailDiv1')">View Detailll</button>
                   <?php 
				    if(isset($_SESSION["url1"])){
						?>
						<a data-class="recepit" href="<?php echo $_SESSION["url1"] ?>" class="btn btn-primary fancybox">Print recepit</a>
						<?php
						unset($_SESSION["url1"]);
					}
					?>
                    <div id="appendDiv1" style="display:none"></div>
                    <div id="feedetailDiv1" style="display:none" title="View Payment detail"></div>
                </form>
                </div>
                </div>
            <div class="well no-padding">
                 
             	<div class="half"><center>Tuition fee</center>
            	<table class="table">
                	
                    <thead>
                        
                        <tr>
                            <th style="color:#FFF">Quater</th>
                            <th>Amount</th>
                            <th>Amount Given</th>
                            <th width="50px">Late Fee</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th><span class="action">Action</span></th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php 
						$aryInstall=$db->getRow("select * from installment where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and session='".$_SESSION["admin"]["session"]."'");
						$feeCount=array();$totalclasspayfee=0;$totalbuspayfee=0;$busFine=0;$schoolFine=0;
						for($i=1;$i<=12;$i++){
							$iis="i".$i;
							$iip="ip".$i;
							if($aryInstall[$iis]!="" && $aryInstall[$iis]!=0){
								$totalclasspayfee=$totalclasspayfee+$aryInstall[$iip];
								$is_rr=false;
							?>
                            <tr>
                            	
                                <td><?php $ij=$i;
						  if($ij<=9){
							$newDate=date("Y")."-".($ij+3)."-1";
							echo $month1= date("F",strtotime($newDate));//."(".($ij+3).")";
						  }
						  else{
							$newDate=date("Y")."-".($ij-9)."-1";
							echo $month1=date("F",strtotime($newDate));//."(".($ij-9).")";
						  } ?></td>
              				<!--	<td>School Fee inst. <?php echo $i;?></td>-->
                            <?php 
								$fineAry=$db->getRow("select id,fine,reasion from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$i."-class'"); ?>
								
								
                            	   <!-- <input type='hidden' data-month="month<?php echo $ij;?>" data-value="<?php echo $fineAry["fine"]; ?>-<?php echo $aryInstall[$iip]; ?>" data-name="tuition_fine" data-type="tuition_fine" value='<?php echo $fineAry["fine"]?>'/> -->
								   
								  <?php  
								   // CODE FOR MARCH 
								   if($ij=='12' AND $aryInstall[$iip]!=''){?>
			<input type='hidden' data-month="month12" data-value="<?php echo $aryInstall[$iis]-$aryInstall[$iip]; ?>-"  data-type="tution"  data-name="tution"   value="<?php echo $aryInstall[$iis]-$aryInstall[$iip]; ?>" >
								   <?php } else{  ?>
								 
								   <input type='hidden' data-month="month<?php echo $ij;?>" data-value="<?php echo $fineAry["fine"]; ?>-<?php echo $aryInstall[$iip]; ?>" data-name="tuition_fine" data-type="tuition_fine" value='<?php echo $fineAry["fine"]?>'/>
								   <?php } ?>
                                <td><input data-month="month<?php echo $ij; ?>" data-value="<?php echo $aryInstall[$iis]; ?>-<?php echo $aryInstall[$iip]; ?>" data-type="tution" data-name="tution" data-t="tutionfee" readonly="readonly" type="text" id="fee<?php echo $i ?>" class="input-block-level findFeeNow" value="<?php echo $aryInstall[$iis]; ?>"  name="fee[]"></td>
                                <td><input type="text" id="given<?php echo $i ?>" class="input-block-level" value="<?php echo $aryInstall[$iip]; ?>" 
								<?php if($aryInstall[$iip]>0){ echo 'readonly="readonly"'; $isr=0; }?> name="given[]"></td>
                                
                                <td><?php 
								/*$fineAry=$db->getRow("select fine,reasion from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$i."-class'");*/ ?>
								<input  readonly="readonly" class='span12' type='text' title='<?php  echo $fineAry["reasion"];?>' rel='tooltip' value='<?php echo $fine=$fineAry["fine"]?>'/><?php $schoolFine+=$fine; ?></td>
                                <td><input type="text" id="fdate<?php echo $i ?>" class="fdate<?php echo $i ?> datepicker span12" value="<?php echo date("Y-m-d H:i:g"); ?>" /></td>
                                <td><?php if($aryInstall[$iip]>0)echo '<font color="#009900">Paid</font>';else echo '<font color="#FF0000">Due</font>'; ?></td>
                                <td class="classtd">
								<input type="hidden" value="<?php echo $aryInstall[$iis]; ?>" class="instalment" />
                                <input type="hidden" value="<?php echo $i ?>" class="instalment_no" />
								<?php
								$recpChkData=checkRecepit($_GET["id"],$iip,"fee"); 
								if($recpChkData){
									//echo $db->getLastQuery();print_r($recpChkData);
									if($recpChkData["i"]==1){
										echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$recpChkData["amount"].'&type=fee&paytype=classfee&detail=School fee&install='.$i.'&class='.$aryForm["class"].'&ip='.$i.'" class="btn btn-danger fancybox">Recepit</a>';
										$is_rr=true;
									}
									if($fine=="" || $fine==0){
											
									}else{
										echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&paytype=classfinefee&detail='.$fineAry["reasion"].'&install='.$fineAry["id"].'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fine Rec</a>';
									}
								}else{
									if($aryInstall[$iip]>0){
										echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$aryInstall[$iip].'&type=fee&paytype=classfee&detail=School fee&install='.$i.'&class='.$aryForm["class"].'&ip='.$i.'" class="btn btn-danger fancybox">Recepit</a>';						
										if($fine=="" || $fine==0){
											
										}else{
											echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&paytype=classfinefee&detail='.$fineAry["reasion"].'&install='.$fineAry["id"].'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fine Rec</a>';
										}
									}else{ 
										echo '<a style="float:left" id="save'.$i.'" onclick="paynow(\''.$i.'\')" href="javascript:;"><button type="button" class="btn btn-info">Pay Fees</button></a>'; 
										if($fine=="" || $fine==0){
											echo '<a href="add_fine.php?idno='.$aryForm["idno"].'&no='.$i.'&type=class" data-class="pradesh" class="fancybox"><button type="button" class="btn btn-primary">Add Fine</button></a>';
										}else{
											echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&detail='.$fineAry["reasion"].'&paytype=classfinefee&install='.$fineAry["id"].'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fine Rec</button>';
										}
									}
								}
								//echo $db->getErMsg();
								?></td>
                                <td>
                                <?php  $m=$recpChkData['inst_id']; ?>
                                <?php if($is_rr==true){ ?>
                                <input data-month="<?php echo $i; ?>" data-extramonth="<?php echo $m; ?>" data-tot="<?php echo $recpChkData['tot']; ?>" type="checkbox" class="cla" name="newRec[]" data-rr="<?php echo $recpChkData["rrid"] ?>" value="<?php echo $recpChkData["amount"]; ?>" /><?php //print_r($recpChkData); ?>
                                <?php }?>
                                
                                <?php if(is_array($fineAry) && count($fineAry)>0){?>
                                <input data-month="<?php echo $i; ?>" data-extramonth="<?php echo $m; ?>" type="checkbox" class="cla_fine" name="newRec[]" data-rr="<?php echo $recpChkData["rrid"] ?>" value="<?php echo $fineAry["fine"]; ?>" /><?php //print_r($recpChkData); ?>
                                <?php }?>
                                </td>
                            </tr>
							<?php
							}
						}
					?>
					</tbody>
                </table>
                </div>
                <?php if($aryForm["bus"]!=""){ ?>
                <div  class="half">
                <center>Transport fee</center>
                <table class="table">
                    <thead>
                        <tr>
                        	
                            <th>Quater</th>
                            <th>Amount</th>
                            <th>Amount Given</th>
                            <th width="50px">Late Fee</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th><span class="action">Action</span></th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
					<?php
						$ji=0;
						for($i=1;$i<=12;$i++){
							$iis="b".$i;
							$iip="bp".$i;$is_rr=false;
							if($aryInstall[$iis]!="" && $aryInstall[$iis]!=0){
								$totalbuspayfee=$totalbuspayfee+$aryInstall[$iip];$ji++;
							$is_rr=false;
							?>
                            <tr <?php if($ji==1)echo 'class="first" style="border-top:2px solid #F00"'; ?>>
                            	<td><?php $ij1=$i;
									  if($ij1<=9){
										$newDate=date("Y")."-".($ij1+3)."-1";
										echo date("F",strtotime($newDate));//."(".($ij+3).")";
									  }
									  else{
										$newDate=date("Y")."-".($ij1-9)."-1";
										echo date("F",strtotime($newDate));//."(".($ij-9).")";
									  } ?></td>
                                <!--<td>Bus Fee inst. <?php echo $i ?></td>-->
                                <?php 
								$fineAry=$db->getRow("select fine,reasion from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$i."-bus'");?>
								
								<?php  
								   // CODE FOR MARCH 
								   if($ij1=='12' AND $aryInstall[$iip]!=''){?>
			<input type='hidden' data-month="month12" data-value="<?php echo $aryInstall[$iis]-$aryInstall[$iip]; ?>-"  data-type="bus"  data-name="bus"   value="<?php echo $aryInstall[$iis]-$aryInstall[$iip]; ?>" >
								   <?php } else{  ?>
								 
								    <input type="hidden" data-month="month<?php echo $ij1;?>" data-value="<?php echo $fineAry["fine"]; ?>-<?php echo $aryInstall[$iip]; ?>" data-name="bus_fine" data-type="bus_fine"  value='<?php echo $fineAry["fine"]?>'/>
								   <?php } ?>
										
                               <td><input data-month="month<?php echo $ij1; ?>" data-value="<?php echo $aryInstall[$iis]; ?>-<?php echo $aryInstall[$iip]; ?>" data-type="bus" data-name="bus" data-t="busfee" readonly="readonly" type="text" id="busfee<?php echo $i ?>" class="input-block-level findFeeNow" value="<?php echo $aryInstall[$iis]; ?>"  name="busfee[]"></td>
                                <td><input type="text" id="busgiven<?php echo $i ?>" class="input-block-level" value="<?php echo $aryInstall[$iip]; ?>" <?php if($aryInstall[$iip]>0)echo 'readonly="readonly"'; ?> name="busgiven[]"></td>
                                <td><?php 
								/*$fineAry=$db->getRow("select fine,reasion from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$i."-bus'");*/?>
								<input readonly="readonly" class='span12' type='text' title='<?php  echo $fineAry["reasion"];?>' rel='tooltip' value='<?php echo $fine=$fineAry["fine"]?>'/>
						<?php		//echo "<a href='#' title='".$fineAry["reasion"]."' rel='tooltip'>".$fine=$fineAry["fine"]."</a>";
								//echo "<input  readonly='readonly' data-month='".$ij1."' class='span12' type='text' title='".$fineAry["reasion"]."' rel='tooltip' value='".$fine=$fineAry["fine"]."'/>";
								$busFine+=$fine;
								 ?></td>
                                <td><input type="text" id="bdate<?php echo $i ?>" class="bdate<?php echo $i ?> datepicker span12" value="<?php echo date("Y-m-d H:i:g"); ?>" /></td>
                                <td><?php 
								if($aryInstall[$iip]>0)echo '<font color="#009900">Paid</font>';
								else echo '<font color="#FF0000">Due</font>'; ?></td>
                                <td class="bustd"><input type="hidden" value="<?php echo $aryInstall[$iis]; ?>" class="instalmentbus" />
                                <input type="hidden" value="<?php echo $i ?>" class="instalmentbus_no" /><?php 
								$recpChkData=checkRecepit($_GET["id"],$iip,"busfee"); 
								if($recpChkData){
									if($recpChkData["i"]==1){
										echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$recpChkData["amount"].'&type=fee&paytype=busfee&detail=Bus fee&install='.$i.'&class='.$aryForm["class"].'&ip='.$i.'" class="btn btn-danger fancybox">Recepit</a>';
									$is_rr=true;
									}
									if($fine=="" || $fine==0){
											
									}else{
										echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&paytype=busfinefee&detail='.$fineAry["reasion"].'&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fine Rec</a>';
									}
								}else{
									if($aryInstall[$iip]>0){
										echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$aryInstall[$iip].'&type=fee&paytype=busfee&detail=Bus fee&install='.$i.'&class='.$aryForm["class"].'&ip='.$i.'" class="btn btn-danger fancybox">Recepit</a>';
										
										if($fine=="" || $fine==0){
											
										}else{
											echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&paytype=busfinefee&detail='.$fineAry["reasion"].'&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fine Rec</a>';
										}
										
									}
									else {echo '<a style="float:left" id="savebus'.$i.'" onclick="paybusnow(\''.$i.'\')" href="javascript:;"><button type="button" class="btn btn-info">Pay Fees</button></a>'; 
										if($fine=="" || $fine==0){
											echo '<a href="add_fine.php?idno='.$aryForm["idno"].'&no='.$i.'&type=bus" data-class="pradesh" class="fancybox"><button type="button" class="btn btn-primary">Add Fine</button></a>';
											
										}else{
											echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&paytype=busfinefee&detail='.$fineAry["reasion"].'&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fine Rec</button>';
										}
									}
								}
								?></td>
                                <td>
                                 <?php  $m=$recpChkData['inst_id']; ?>
								<?php if($is_rr==true){ ?>
                                <input data-month="<?php echo $i; ?>" data-extramonth="<?php echo $m; ?>" data-tot="<?php echo $recpChkData['tot']; ?>" type="checkbox" class="bus" name="newRec[]" data-rr="<?php echo $recpChkData["rrid"] ?>" value="<?php echo $recpChkData["amount"]; ?>" /><?php //print_r($recpChkData); ?>
                                <?php }?>
                                <?php if(is_array($fineAry) && count($fineAry)>0){?>
                                <input data-month="<?php echo $i; ?>" data-extramonth="<?php echo $m; ?>" type="checkbox" class="bus_fine" name="newRec[]" data-rr="<?php echo $recpChkData["rrid"] ?>" value="<?php echo $fineAry["fine"]; ?>" /><?php //print_r($recpChkData); ?>
                                <?php }?>
                                </td>
                            </tr>
							<?php
							}
						}
					?>
                    </tbody>
                </table>
                </div>
                <?php } ?>
                <?php 
					$checkhostelFee=$db->getVal("select id from hostelinstallment where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");	
					if($checkhostelFee){
						?>
                        <div  class="half">
                        <center>Hostel fee</center>
                        <table class="table">
                	
                    <thead>
                        
                        <tr>
                            <th style="color:#FFF">Quater</th>
                            <th>Amount</th>
                            <th>Amount Given</th>
                            <th width="50px">Late Fee</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th><span class="action">Action</span></th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php 
						$aryHostelInstall=$db->getRow("select * from hostelinstallment where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and session='".$_SESSION["admin"]["session"]."'");
						$hostelfeeCount=array();$totalhostelpayfee=0;$hostelFine=0;
						for($i=1;$i<=12;$i++){
							$iis="i".$i;
							$iip="ip".$i;$is_rr=false;$fine="";
							if($aryHostelInstall[$iis]!="" && $aryHostelInstall[$iis]!=0){
								$totalhostelpayfee=$totalhostelpayfee+$aryHostelInstall[$iip];$ji++;
								$is_rr=false;
							?>
                            <tr <?php if($ji==1)echo 'class="first" style="border-top:2px solid #F00"'; ?>>
                            	<td><?php $ij1=$i;
									  if($ij1<=9){
										$newDate=date("Y")."-".($ij1+3)."-1";
										echo date("F",strtotime($newDate));//."(".($ij+3).")";
									  }
									  else{
										$newDate=date("Y")."-".($ij1-9)."-1";
										echo date("F",strtotime($newDate));//."(".($ij-9).")";
									  } ?></td>
                                <!--<td>hostel Fee inst. <?php echo $i ?></td>-->
                                
                                <?php $fineAry=$db->getRow("select fine,reasion from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$i."-hostel'"); ?>
								
								<?php  
								   // CODE FOR MARCH 
								   
								   if($ij1=='12' AND $aryHostelInstall[$iip]!=''){?>
			<input type='hidden' data-month="month12" data-value="<?php echo $aryHostelInstall[$iis]-$aryHostelInstall[$iip]; ?>-"  data-type="hostel"  data-name="hostel"   value="<?php echo $aryHostelInstall[$iis]-$aryHostelInstall[$iip]; ?>" >
								   <?php } /*else{  ?>
								 
								    <input type='hidden' data-month="month<?php echo $ij1;?>" data-value="<?php echo $fineAry["fine"]; ?>-<?php echo $aryHostelInstall[$iip]; ?>" data-name="hostel_fine" data-type="hostel_fine" value='<?php echo $fineAry["fine"]?>'/>
								   <?php }*/ ?>								
                  									
								<td>	
                                <input data-month="month<?php echo $ij1; ?>" data-value="<?php echo $aryHostelInstall[$iis]; ?>-<?php echo $aryHostelInstall[$iip]; ?>" data-type="hostel" data-name="hostel" data-t="hostelfee" readonly="readonly" type="text" id="hostelfee<?php echo $i ?>" class="input-block-level findFeeNow" value="<?php echo $aryHostelInstall[$iis]; ?>"  name="hostelfee[]"></td>
                                <td><input type="text" id="hostelgiven<?php echo $i ?>" class="input-block-level" value="<?php echo $aryHostelInstall[$iip]; ?>" <?php if($aryHostelInstall[$iip]>0)echo 'readonly="readonly"'; ?> name="hostelgiven[]"></td>
                                <td><?php 
								$fineAry=$db->getRow("select fine,reasion from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$i."-hostel'");
								//echo "<a href='#' title='".$fineAry["reasion"]."' rel='tooltip'>".$fine=$fineAry["fine"]."</a>";
								if(is_array($fineAry) && count($fineAry)>0)
								echo "<input  readonly='readonly' class='span12' type='text' title='".$fineAry["reasion"]."' rel='tooltip' value='".$fine=$fineAry["fine"]."'/>";
								else
								echo "<input  readonly='readonly' class='span12' type='text' title='' rel='tooltip' value=''/>";
								$hostelFine+=$fine;
								 ?></td>
                                <td><input type="text" id="hosdate<?php echo $i ?>" class="bdate<?php echo $i ?> datepicker span12" value="<?php echo date("Y-m-d H:i:g"); ?>" /></td>
                                <td><?php 
								if($aryHostelInstall[$iip]>0)echo '<font color="#009900">Paid</font>';
								else echo '<font color="#FF0000">Due</font>'; ?></td>
                                <td class="hosteltd"><input type="hidden" value="<?php echo $aryHostelInstall[$iis]; ?>" class="instalmenthostel" />
                                <input type="hidden" value="<?php echo $i ?>" class="instalmenthostel_no" /><?php 
								$recpChkData=checkRecepit($_GET["id"],$iip,"hostelfee"); 
								if($recpChkData){
									if($recpChkData["i"]==1){
										echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$recpChkData["amount"].'&type=fee&paytype=hostelfee&detail=hostel fee&install='.$i.'&class='.$aryForm["class"].'&ip='.$i.'" class="btn btn-danger fancybox">Recepit</a>';
										$is_rr=true;
									}
									if($fine=="" || $fine==0){
											
									}else{
										echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&paytype=hostelfinefee&detail='.$fineAry["reasion"].'&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fine Rec</a>';
									}
								}else{
									if($aryHostelInstall[$iip]>0){
										echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$aryHostelInstall[$iip].'&type=fee&paytype=hostelfee&detail=hostel fee&install='.$i.'&class='.$aryForm["class"].'&ip='.$i.'" class="btn btn-danger fancybox">Recepit</a>';
										
										if($fine=="" || $fine==0){
											
										}else{
											echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&paytype=hostelfinefee&detail='.$fineAry["reasion"].'&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fine Rec</a>';
										}
										
									}
									else {echo '<a style="float:left" id="savehostel'.$i.'" onclick="payhostelnow(\''.$i.'\')" href="javascript:;"><button type="button" class="btn btn-info">Pay Fees</button></a>'; 
										if($fine=="" || $fine==0){
											echo '<a href="add_fine.php?idno='.$aryForm["idno"].'&no='.$i.'&type=hostel" data-class="pradesh" class="fancybox"><button type="button" class="btn btn-primary">Add Fine</button></a>';
											
										}else{
											echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&paytype=hostelfinefee&detail='.$fineAry["reasion"].'&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fine Rec</button>';
										}
									}
								}
								?></td>
                                <td><?php if($is_rr==true){ ?>
                                <input type="checkbox" data-month="<?php echo $i; ?>" data-tot="<?php echo $recpChkData['tot']; ?>" class="hostel" name="newRec[]" data-rr="<?php echo $recpChkData["rrid"] ?>" value="<?php echo $recpChkData["amount"]; ?>" /><?php //print_r($recpChkData); ?>
                                <?php }?>
                                <?php if(is_array($fineAry) && count($fineAry)>0){ ?>
                                <input type="checkbox" data-month="<?php echo $i; ?>" class="hostel_fine" name="newRec[]" data-rr="<?php echo $recpChkData["rrid"] ?>" value="<?php echo $fineAry["fine"]; ?>" /><?php //print_r($recpChkData); ?>
                                <?php }?>
                                </td>
                            </tr>
							<?php
							}
						}
					?>
					</tbody>
                </table>
                        </div>
                		<?php
					}
				?>
                <?php $extrafeeFine=0;
					$checkextFee=$db->getRows("select * from extrafee_type where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'");	
					if(is_array($checkextFee) && count($checkextFee)>0){
						foreach($checkextFee as $chkExtFee){
							$mycheckInstall=$db->getRows("select * from extrafee where idno='".$_GET["id"]."' and type='".$chkExtFee["id"]."'");
							if(is_array($mycheckInstall) && count($mycheckInstall)>0){
						?>
                        <div  class="half">
                        <center><?php echo $chkExtFee["type"];?></center>
                        <table class="table">
                	
                    <thead>
                        
                        <tr>
                            <th style="color:#FFF">Quater</th>
                            <th>Amount</th>
                            <th>Amount Given</th>
                            <th width="50px">Late Fee</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th><span class="action">Action</span></th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php 
						foreach($mycheckInstall as $myinstall){
							$fine="";
							?>
							<tr><td><?php $ipi=ltrim ($myinstall["pid"], 'p');
							if($ipi<=9){
										$newDate=date("Y")."-".($ipi+3)."-1";
										echo date("F",strtotime($newDate));//."(".($ij+3).")";
									  }
									  else{
										$newDate=date("Y")."-".($ipi-9)."-1";
										echo date("F",strtotime($newDate));//."(".($ij-9).")";
									  }
							 ?></td>
                           <td>
						   
						   <?php if($ipi=='12' AND $aryInstall[$iip]!=''){?>
						   <input data-month="month<?php echo $ipi; ?>" data-value="<?php echo $myinstall["fee"]-$myinstall["pay"]; ?>-" data-type="<?php echo $chkExtFee["id"] ?>" data-name="<?php echo $chkExtFee["type"] ?>" data-t="extrafee" readonly="readonly" type="text" id="extra<?php echo $myinstall["type"] ?>fee<?php echo $ipi ?>" class="input-block-level findFeeNow" value="<?php echo $myinstall["fee"]; ?>"  name="extra<?php echo $myinstall["type"] ?>fee[]">
						   <?php } else{ ?>
						   <input data-month="month<?php echo $ipi; ?>" data-value="<?php echo $myinstall["fee"]; ?>-<?php echo $myinstall["pay"]; ?>" data-type="<?php echo $chkExtFee["id"] ?>" data-name="<?php echo $chkExtFee["type"] ?>" data-t="extrafee" readonly="readonly" type="text" id="extra<?php echo $myinstall["type"] ?>fee<?php echo $ipi ?>" class="input-block-level findFeeNow" value="<?php echo $myinstall["fee"]; ?>"  name="extra<?php echo $myinstall["type"] ?>fee[]">
						   
						   <?php } ?>
						   
						   </td>
                                <td><input type="text" id="extragiven<?php echo $myinstall["type"] ?>fee<?php echo $ipi ?>" class="input-block-level" value="<?php if($myinstall["pay"]>0)echo $myinstall["pay"]; ?>" <?php if($myinstall["pay"]>0)echo 'readonly="readonly"'; ?> name="extra<?php echo $myinstall["type"] ?>feegiven[]"></td>
                            <td>
							
							<?php 
								
								$fineAry=$db->getRow("select fine,reasion from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$ipi."-extra".$myinstall["type"]."'");
								//echo $db->getLastQuery();
								//echo "<a href='#' title='".$fineAry["reasion"]."' rel='tooltip'>".$fine=$fineAry["fine"]."</a>";
								//print_r($fineAry);
								if(is_array($fineAry) && count($fineAry)>0){
								echo "<input  readonly='readonly' class='span12' type='text' title='".$fineAry["reasion"]."' rel='tooltip' value='".$fine=$fineAry["fine"]."'/>";
									$extrafeeFine=$extrafeeFine+$fineAry["fine"];
								}
								else{
								echo "<input  readonly='readonly' class='span12' type='text' title='' rel='tooltip' value=''/>";
								}
								 ?></td>
                                <td><input type="text" id="ex<?php echo $myinstall["type"] ?>date<?php echo $ipi ?>" class="bdate<?php echo $ipi ?> datepicker span12" value="<?php echo date("Y-m-d H:i:g"); ?>" /></td>
                                <td><?php 
								if($myinstall["pay"]>0)echo '<font color="#009900">Paid</font>';
								else echo '<font color="#FF0000">Due</font>'; ?></td>

                            	<td class="extra<?php echo $myinstall["type"] ?>td"><input type="hidden" value="<?php echo $myinstall["fee"]; ?>" class="instalmentextra<?php echo $myinstall["type"] ?>" />
                                <input type="hidden" value="<?php echo $ipi ?>" class="instalmentbus_no" /><?php 
								 $recpChkData=checkRecepit($_GET["id"],$ipi,"extrafee".$myinstall["type"]);
//echo $myinstall["type"];
//echo 	$_GET["id"];							 
								//echo $myinstall["type"];
								//echo '<br>';
								//echo $ipi;
								//echo '<br>';
						//print_r($recpChkData);
					
								$is_rr=false;
								if($recpChkData){
									if($recpChkData["i"]==1){
										echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$recpChkData["amount"].'&type=fee&paytype=extrafee'.$myinstall["type"].'&detail='.$chkExtFee["type"].' &install='.$ipi.'&class='.$aryForm["class"].'&ip='.$ipi.'" class="btn btn-danger fancybox">Recepit</a>';
										$is_rr=true;
									}
									if($fine=="" || $fine==0){
											
									}else{
										echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&paytype=extrafinefee&refid='.$myinstall["type"].'&detail='.$fineAry["reasion"].'&install='.$ipi.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fine Rec</a>';
									}
								}else{
									if($myinstall["pay"]>0){
										echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$myinstall["pay"].'&type=fee&paytype=extrafee'.$myinstall["type"].'&detail='.$chkExtFee["type"].'&install='.$ipi.'&class='.$aryForm["class"].'&ip='.$ipi.'" class="btn btn-danger fancybox">Recepit</a>';
										
										if($fine=="" || $fine==0){
											
										}else{
											echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&paytype=extrafinefee&refid='.$myinstall["type"].'&detail='.$fineAry["reasion"].'&install='.$ipi.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fine Rec</a>';
										}
										
									}
									else {echo '<a style="float:left" id="saveextra'.$myinstall["type"].$ipi.'" onclick="payextranow(\''.$ipi.'\',\''.$myinstall["type"].'\')" href="javascript:;"><button type="button" class="btn btn-info">Pay Fees</button></a>'; 
										if($fine=="" || $fine==0){
											echo '<a href="add_fine.php?idno='.$aryForm["idno"].'&no='.$ipi.'&type=extra'.$myinstall["type"].'" data-class="pradesh" class="fancybox"><button type="button" class="btn btn-primary">Add Fine</button></a>';
										}else{
											echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&paytype=extrafinefee&refid='.$myinstall["type"].'&detail='.$fineAry["reasion"].'&install='.$ipi.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fine Rec</button>';
										}
									}
								}
								?></td>
                                <td><?php if($is_rr==true){ ?>
                                <input type="checkbox" data-month="<?php echo $ipi; ?>" data-tot="<?php echo $recpChkData["tot"]; ?>" class="extrafee" data-name="<?php echo str_replace(" ", "+", $chkExtFee["type"]);?>" name="newRec[]" data-rr="<?php echo $recpChkData["rrid"] ?>" value="<?php echo $recpChkData["amount"]; ?>" /><?php //print_r($recpChkData); ?>
                                <?php }?>
                                <?php if(is_array($fineAry) && count($fineAry)>0){?>
                                <input type="checkbox" data-month="<?php echo $ipi; ?>" class="extrafee_fine" data-name="<?php echo str_replace(" ", "+", $chkExtFee["type"]);?>" name="newRec[]" data-rr="<?php echo $recpChkData["rrid"] ?>" value="<?php echo $fineAry["fine"]; ?>" /><?php //print_r($recpChkData); ?>
                                <?php }?>
                                </td>
                            </td>
							<?php
						}
					?>
					</tbody>
                </table>
                        </div>
                		<?php
							}
						}
					}
				?>
                <?php $i=1;$totalOtherhostel=0;$payOtherhostel=0;$fineTotalhostel=0;$allReasion=array();$OtherSiteTotalhostel=0;
					 if($_GET["id"]!=''){ 
					 $utype=mydetail("htype",$_GET["id"],"student");
					 if($utype!=""){
					 $all_other=$db->getRows("select * from hostel_otherfee_structure where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."' and (otype='' OR otype='".$utype."' OR otype='".$_GET["id"]."')");
					 //echo"<pre>";print_r($all_other);echo"</pre>";exit;
					  if(is_array($all_other) && count($all_other))
                      {
						?><div class="half">
                        <center>Hostel Extra fee</center>
                <table class="table">
                    <thead>
                        <tr>
                            <th>Quater</th>
                            <th>Amount</th>
                            <th>Amount Given</th>
                            <th width="50px">Late Fee</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th width="13%"><span class="action">Action</span></th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody id="tbody" style="border-top:2px solid #F00"><?php  
						  
                        foreach($all_other as $iPro)
                        {
							$i++;$ijk=trim($iPro['month']," ");$amt=0;
							$paid_Fee=$db->getVal("select fine from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."' and reasion='".$iPro["name"]."' and ins_name like '%otherfeehostel%'");
							$fineAry=$db->getRow("select sum(fine),reasion from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$i."-otherhostel'");
							//print_r($fineAry);echo $db->getLastQuery();
							$other_Fee=$db->getVal("select sum(discount) from hostelotherfee_discount where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and other_id='".$iPro["id"]."'");		
							$OtherSiteTotalhostel+=(int)$other_Fee;
							$name=$iPro['name'];
							$name=trim($name," ");
							$amt=$iPro["fee"];
							$amt=($iPro["fee"]-(int)$other_Fee);
							$fineAry["fine"]=$fineAry["sum(fine)"];
					 ?>
                     <tr>
                      
                      	<td><?php echo $name; ?></td>
                        <td>
                        <input type="hidden" name="idno[]" value="<?php echo $_GET["id"]; ?>" />
                        <input type="hidden" name="month" value="<?php echo $ijk; ?>" />
                        <input type="hidden" name="reasion[]" id="reasion1<?php echo $i; ?>" value="<?php echo $iPro["name"]; ?>" />
                        <input data-month="month<?php echo $ijk; ?>" data-value="<?php if($amt==$paid_Fee){echo $amt."-".$paid_Fee;}elseif($amt==$fineAry["fine"]+$paid_Fee){echo $amt."-".$paid_Fee;}else {echo $amt-($paid_Fee+$fineAry["fine"])."-";} ?>" data-t="hostelotherfee" data-left="<?php if($amt!=$fineAry["fine"]+$paid_Fee && $paid_Fee!="")echo 1 ?>" data-name="<?php echo $name; ?>" data-type="hostelother" data-idd="<?php echo $i; ?>" rel='tooltip' type="text" id="feeother<?php echo $i; ?>" readonly="readonly" class="input-block-level" value="<?php echo ($iPro["fee"]-(int)$other_Fee); ?>"  data-fee="<?php echo $other_Fee["detail"]; ?>" title="<?php echo $other_Fee["detail"]; ?>" name="fee[]"><?php $totalOtherhostel+=(int)$iPro["fee"]-(int)$other_Fee; ?></td>
                        <td><input type="text" id="givenother1<?php echo $i; ?>" class="input-block-level" value="<?php echo $paid_Fee; ?>" name="othergiven[]" ><?php $payOtherhostel+=(int)$paid_Fee; ?></td>
                        <td>
                        <input  readonly='readonly' class='span12' type='text' title='<?php echo $fineAry["reasion"];?>' rel='tooltip' value='<?php echo $fine=$fineAry["fine"];?>'/>
                        <?php $fineTotalhostel+=(int)$fine; ?>
                        </td>
                        <td><input type="text" id="hodte<?php echo $i ?>" class="odate<?php echo $i ?> datepicker span12" value="<?php echo date("Y-m-d H:i:g"); ?>" /></td>
                        <td>
						<?php 
						if($paid_Fee=="" || $paid_Fee=="0"){  ?><font color="#FF0000">Due</font><?php }else{ ?><font color="#99CC00">Paid</font><?php } ?>
                        
                        </td>
                        <td>
                        <?php
                        if($paid_Fee=="" || $paid_Fee=="0"){ 
							 
                        	echo '<a style="float:left" href="javascript:;" id="saveother'.$i.'" onclick="payhostelother(\''.$i.'\')"><button type="button" class="btn btn-info">Pay Other</button></a>';
                         }else{ 
							echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$paid_Fee.'&type=fee&paytype=hostelotherfee&detail='.$iPro["name"].'&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Recepit</button>';
						} 
					if($fine=="" || $fine==0){
						if($paid_Fee!=$iPro["fee"])
								echo '<a href="add_fine.php?idno='.$aryForm["idno"].'&no='.$i.'&amount='.((int)$iPro["fee"]).'&given='.((int)$paid_Fee).'&type=otherhostel&name='.$iPro["name"].'" data-class="pradesh" class="fancybox"><button type="button" class="btn btn-primary">Left Amount</button></a>';
							}else{
								echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&paytype=hostelotherfinefee&detail='.$fineAry["reasion"].'&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Left  Recepit</button>';
							}	
						?>
                        </td>
                        <td>
                        <?php 
						
						$LastQ=$db->getVal("select max(id) from reff_receipt where idno='".$_GET["id"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and type='".$iPro["name"]."'");
						$LastQ1=$db->getVal("select max(id) from reff_receipt where idno='".$_GET["id"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and type='".$iPro["name"]."' and id!='".$LastQ."'");
						if($paid_Fee>0){ ?>
                                <input data-month="<?php echo $i; ?>" data-tot="<?php echo (($iPro["fee"]-(int)$other_Fee)-(int)$fineAry["fine"]); ?>" data-class="<?php echo $iPro["name"]; ?>" type="checkbox" class="hostelother" name="newRec[]" data-rr="<?php echo $LastQ ?>" value="<?php echo $paid_Fee; ?>" /><?php //print_r($recpChkData); ?>
                            <?php }?>
                        <?php 
						if(is_array($fineAry) && count($fineAry)>0){?>
                                <input data-month="<?php echo $i; ?>" data-class="<?php echo $iPro["name"]; ?>" type="checkbox" class="hostelother_fine" name="newRec[]" data-rr="<?php echo $LastQ ?>" value="<?php echo $fineAry["fine"]; ?>" /><?php //print_r($recpChkData); ?>
                            <?php }
                            
						?>
                        </td>
                      </tr>
                     <?php $i++;} 
					 
					 ?></tbody>
                  </table>
                  </div><?php
					  }
					 
					 echo $db->getErMsg();
					 }
					 }?>
                     
                    <?php $i=1;$totalOther=0;$payOther=0;$fineTotal=0;$allReasion=array();$OtherSiteTotal=0;
					 if($_GET["id"]!=''){ 
					 $utype=mydetail("stype",$_GET["id"],"student");
					 $all_other=$db->getRows("select * from otherfee_structure where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."' and (otype='' OR otype='".$utype."' OR otype='".$_GET["id"]."')");
					 //echo"<pre>";print_r($all_other);echo"</pre>";exit;
					  if(is_array($all_other) && count($all_other))
                      {
						?><div class="half">
                        <center>Extra fee</center>
                <table class="table">
                    <thead>
                        <tr>
                            <th>Quater12</th>
                            <th>Amount</th>
                            <th>Amount Given</th>
                            <th width="50px">Late Fee</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th><span class="action">Action</span></th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody id="tbody" style="border-top:2px solid #F00"><?php  
						  
                        foreach($all_other as $iPro)
                        {
							$i++;$ijk=trim($iPro['month']," ");
							$paid_Fee=$db->getVal("select fine from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."' and reasion='".$iPro["name"]."' and ins_name like '%otherfee%'");
							$fineAry=$db->getRow("select sum(fine),reasion from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$i."-other'");
							//print_r($fineAry);echo $db->getLastQuery();
							$fineAry["fine"]=$fineAry["sum(fine)"];
							$other_Fee=$db->getVal("select sum(discount) from otherfee_discount where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and other_id='".$iPro["id"]."'");		
							$OtherSiteTotal+=(int)$other_Fee;
							$name=$iPro['name'];
							$name=trim($name," ");
							$amt=($iPro["fee"]-(int)$other_Fee);
					 ?>
                     <tr>
                      
                      	<td><?php echo $name; ?></td>
                        <td>
                        <input type="hidden" name="idno[]" value="<?php echo $_GET["id"]; ?>" />
                        <input type="hidden" name="month" value="<?php echo $ijk; ?>" />
                        <input type="hidden" name="reasion[]" id="reasion<?php echo $i; ?>" value="<?php echo $iPro["name"]; ?>" />
                        <input data-month="month<?php echo $ijk; ?>" data-value="<?php if($amt==$paid_Fee){echo $amt."-".$paid_Fee;}elseif($amt==$fineAry["fine"]+$paid_Fee){echo $amt."-".$paid_Fee;}else {echo $amt-($paid_Fee+$fineAry["fine"])."-";} ?>" data-t="otherfee" data-left="<?php if($amt!=$fineAry["fine"]+$paid_Fee && $paid_Fee!="")echo 1 ?>" data-name="<?php echo $name; ?>" data-type="other" 
  data-idd="<?php echo $i; ?>" rel='tooltip' type="text" id="feeother<?php echo $i; ?>" <?php if($name!="Back_dues" AND strpos($name, "Latefine_")===false ){if($name!="Back_Dues"){ ?> readonly="readonly"<?php }} ?> class="input-block-level" value="<?php echo ($iPro["fee"]-(int)$other_Fee); ?>"  data-fee="<?php echo $other_Fee["detail"]; ?>" title="<?php echo $other_Fee["detail"]; ?>" name="fee[]"><?php $totalOther+=(int)$iPro["fee"]-(int)$other_Fee; ?></td>
  
                        <td><input type="text" id="givenother<?php echo $i; ?>" class="input-block-level" value="<?php echo $paid_Fee; ?>" name="othergiven[]" ><?php $payOther+=(int)$paid_Fee; ?></td>
						
                        <td>
                        <input  readonly='readonly' class='span12' type='text' title='<?php echo $fineAry["reasion"];?>' rel='tooltip' value='<?php echo $fine=$fineAry["fine"];?>'/>
                        <?php $fineTotal+=(int)$fine; ?>
                        </td>
                        <td><input type="text" id="odte<?php echo $i ?>" class="odate<?php echo $i ?> datepicker span12" value="<?php echo date("Y-m-d H:i:g"); ?>" /></td>
                        <td>
						<?php 
						if($paid_Fee=="" || $paid_Fee=="0"){  ?><font color="#FF0000">Due</font><?php }else{ ?><font color="#99CC00">Paid</font><?php } ?>
                        
                        </td>
                        <td>
                        <?php
                        if($paid_Fee=="" || $paid_Fee=="0"){ 
							 
                        	echo '<a style="float:left" href="javascript:;" id="saveother'.$i.'" onclick="payother(\''.$i.'\')"><button type="button" class="btn btn-info">Pay Other</button></a>
							
							<a style="float:left" href="javascript:;" id="saveother'.$i.'" onclick="update_back_dues(\''.$i.'\',\''.$name.'\')"><button type="button" class="btn btn-info">Update</button></a> ';
                         }else{ 
							echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$paid_Fee.'&type=fee&paytype=otherfee&detail='.$iPro["name"].'&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Recepit</button>';
						} 
					if($fine=="" || $fine==0){
						if($paid_Fee!=$iPro["fee"])
								echo '<a href="add_fine.php?idno='.$aryForm["idno"].'&no='.$i.'&amount='.((int)$iPro["fee"]).'&given='.((int)$paid_Fee).'&type=other&name='.$iPro["name"].'" data-class="pradesh" class="fancybox"><button type="button" class="btn btn-primary">Left Amount</button></a>';
							}else{
								echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&paytype=otherfinefee&detail='.$fineAry["reasion"].'&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Left  Recepit</button>';
							}
						?>
                        </td>
                        <td>
                        <?php 
						
						$LastQ=$db->getVal("select max(id) from reff_receipt where idno='".$_GET["id"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and type='".$iPro["name"]."'");
						$LastQ1=$db->getVal("select max(id) from reff_receipt where idno='".$_GET["id"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and type='".$iPro["name"]."' and id!='".$LastQ."'");
						if($paid_Fee>0){ ?>
                                <input data-month="<?php echo $ijk; ?>" data-tot="<?php echo (($iPro["fee"]-(int)$other_Fee)-(int)$fineAry["fine"]); ?>" data-class="<?php echo $iPro["name"]; ?>" type="checkbox" class="myother" name="newRec[]" data-rr="<?php echo $LastQ ?>" value="<?php echo $paid_Fee; ?>" /><?php //print_r($recpChkData); ?>
                            <?php }?>
                        <?php 
						if($fine!="" || $fine!=0){?>
                                <input data-month="<?php echo $ijk; ?>" data-class="<?php echo $iPro["name"]; ?>" type="checkbox" class="myother_fine" name="newRec[]" data-rr="<?php echo $LastQ ?>" value="<?php echo $fineAry["fine"]; ?>" /><?php //print_r($recpChkData); ?>
                            <?php }
						?>
                        </td>
                      </tr>
                     <?php $i++;}
					 
					 ?></tbody>
                  </table>
                  </div><?php
					  }
					 
					 echo $db->getErMsg();
					 }?>
                  	
                  <div class="half">
                  <center>Miscellaneous fee</center>
                  <table class="table">
                    <thead>
                        <tr>
                        	<th>Quater</th>
                            <th>Detail</th>
                            <th>Amount Given</th>
                            <th style="display:none" width="50px">Late Fee</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th><span class="action">Action</span></th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody id="tbody" style="border-top:2px solid #F00">
                    	<?php 
					if($_GET["id"]!=''){ 
					 $all_product=$db->getRows("select * from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."' and ins_name like '%otherfee' and reasion not in (select name from otherfee_structure where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and class='".$aryForm["class"]."')");
					 //echo $db->getErMsg();
					
					// echo"<pre>";print_r($all_product);echo"</pre>";
					  if(is_array($all_product) && count($all_product))
                      {
                        foreach($all_product as $iPro)
                        {
							
							?>
                      <tr>
                      
                      	<td>Other <?php echo $i; ?></td>
                        <td><input type="hidden" name="idno" value="<?php echo $_GET["id"]; ?>" />
                        <input style="width:150px" type="text" placeholder="enter detail" id="reasion<?php echo $i; ?>" readonly="readonly" class="input-block-level" value="<?php echo $iPro["reasion"]; ?>" name="reasion[]"></td>
                        <td><input type="text" w id="givenother<?php echo $i; ?>" class="input-block-level" value="<?php echo $iPro["fine"]; ?>" name="othergiven[]" readonly="readonly">
                        <input type="hidden" id="feeother<?php echo $i; ?>" class="input-block-level" value="<?php echo $iPro["fine"]; ?>" name="fee[]" readonly="readonly"></td>
                        <td style="display:none"></td>
                        <td><input type="text" id="odte<?php echo $i ?>" class="odate<?php echo $i ?> datepicker span12" value="<?php echo date("Y-m-d H:i:g"); ?>" /></td>
                        <td><font color="#99CC00">Paid</font></td>
                        <td><?php
                        echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$iPro["fine"].'&type=fee&paytype=extraotherfinefee&detail='.$iPro["reasion"].'&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Recepit</button>';
						$totalOther+=(int)$iPro["fine"];
						$payOther+=(int)$iPro["fine"]; 
						?></td>
                        <td>
                        <?php 
						
						$LastQ=$db->getVal("select max(id) from reff_receipt where idno='".$_GET["id"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and type='".$iPro["reasion"]."'");
						if($iPro["fine"]>0){ ?>
                                <input type="checkbox" class="other" name="newRec[]" data-month="<?php echo $i; ?>" data-rr="<?php echo $LastQ ?>" value="<?php echo $iPro["fine"]; ?>" data-class="<?php echo $iPro["reasion"]; ?>" /><?php //print_r($recpChkData); ?>
                            <?php }?>
                            </td>
                      </tr>
                     <?php $i++;} 
					 ?>
                      <tr>
                      
                      	<td>Other <?php echo $i; ?></td>
                        <td > <input type="hidden" name="idno" value="<?php echo $_GET["id"]; ?>" />
                        <input style="width:150px" type="text" placeholder="enter detail" id="reasion<?php echo $i; ?>" class="input-block-level"  name="reasion[]"></td>
                        <td><input type="text" onkeyup="$('#feeother<?php echo $i; ?>').val(this.value)" id="givenother<?php echo $i; ?>" class="input-block-level" value="" name="othergiven[]" >
                        <input type="hidden" id="feeother<?php echo $i; ?>" class="input-block-level" value="" name="fee[]" ></td>
                        <td style="display:none"></td>
                        <td><input type="text" id="odte<?php echo $i ?>" class="odate<?php echo $i ?> datepicker span12" value="<?php echo date("Y-m-d H:i:g"); ?>" /></td>
                        <td>---</td>
                        <td><a style="float:left" href="javascript:;" id="saveother<?php echo $i ?>" onclick="payother('<?php echo $i; ?>')"><button type="button" class="btn btn-info">Pay Fees</button></a>
                        <a style="display:none" id="add" href="javascript:;"><button type="button" class="btn btn-info">Add Other</button></a>
                        </td>
                        <td></td>
                      </tr>
					 <?php	
					 }else{
					 ?>
                      <tr>
                      
                      	<td>Other <?php echo $i; ?></td>
                        <td > <input type="hidden" name="idno" value="<?php echo $_GET["id"]; ?>" />
                        <input  style="width:150px" type="text" placeholder="enter detail" id="reasion<?php echo $i; ?>" class="input-block-level"  name="reasion[]"></td>
                        <td><input type="text" onkeyup="$('#feeother<?php echo $i; ?>').val($(this).val())" id="givenother<?php echo $i; ?>" class="input-block-level" value="" name="othergiven[]">
                        <input type="hidden" id="feeother<?php echo $i; ?>" class="input-block-level" value="" name="fee[]" ></td>
                        <td></td>
                        <td><input type="text" id="odte<?php echo $i ?>" class="odate<?php echo $i ?> datepicker span12" value="<?php echo date("Y-m-d H:i:g"); ?>" /></td>
                        <td>---</td>
                        <td><a style="float:left" href="javascript:;" id="saveother<?php echo $i ?>" onclick="payother('<?php echo $i; ?>')"><button type="button" class="btn btn-info">Pay Fees</button></a>
                        <a style="display:none" id="add" href="javascript:;"><button type="button" class="btn btn-info">Add Other</button></a>
                        </td>
                        <td style="display:none"></td>
                      </tr>
					 <?php					 
					 }
					 } ?>
                  	</tbody>
                 </table>
                 </div>
                 <?php $overAllTotal=0;$overAllPay=0;$overAllRemaining=0;$overAllDiscount=0; ?>
                 <table class="table">
                 	<thead>
                    	<tr>
                        	<th>School Fee Description</th>
                            <th>Total Fee</th>
                            <th>Total Paid</th>
                            <th>Total Left</th>
                            <th>Discount</th>
                        </tr>
                    </thead>
                    <tbody>
					
					<tr class="first"  style="border-top:2px solid #F00">
                            <th>Total Class Fee</th>
                            <th><?php echo (int)$aryInstall["total"];$overAllTotal+=$aryInstall["total"]; ?></th>
                            <th><?php echo (int)$totalclasspayfee;$overAllPay+=$totalclasspayfee; ?></th>
                            <th><?php echo $rem=(int)($aryInstall["total"]-$totalclasspayfee);$overAllRemaining+=$rem; ?></th>
                           <td><?php echo (int)$aryInstall["discount"];$overAllDiscount+=$aryInstall["discount"]; ?></td>
                       </tr>
                        <tr>
                            <th>Total Transport Fee</th>
                            <th><?php echo (int)$aryInstall["bus"];$overAllTotal+=$aryInstall["bus"]; ?></th>
                            <th><?php echo (int)$totalbuspayfee;$overAllPay+=$totalbuspayfee; ?></th>
                            <th><?php echo $rem=(int)($aryInstall["bus"]-$totalbuspayfee);$overAllRemaining+=$rem; ?></th>
                            <td><?php echo (int)$aryInstall["busdiscount"];$overAllDiscount+=$aryInstall["busdiscount"]; ?></td>
                       </tr>
                       <tr>
                            <th>Total Hostel Fee</th>
                            <th><?php echo (int)$aryHostelInstall["total"];$overAllTotal+=$aryHostelInstall["total"]; ?></th>
                            <th><?php echo (int)$totalhostelpayfee;$overAllPay+=$totalhostelpayfee; ?></th>
                            <th><?php echo $rem=(int)($aryHostelInstall["total"]-$totalhostelpayfee);$overAllRemaining+=$rem; ?></th>
                            <td><?php echo (int)$aryHostelInstall["discount"];$overAllDiscount+=$aryHostelInstall["discount"]; ?></td>
                       </tr>
                       <?php
						$checkextFee=$db->getRows("select * from extrafee_type where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'");	
						if(is_array($checkextFee) && count($checkextFee)>0){
							foreach($checkextFee as $chkExtFee){
								$mycheckInstall=$db->getRow("select SUM(fee) as feetotal,SUM(pay) as payfee  from extrafee where idno='".$_GET["id"]."' and type='".$chkExtFee["id"]."'");
								
							
                   // for extra fee
					$fetch_extra_fee=$db->getRow("select sum(discount) as discount  from extrafee where idno='".$_GET["id"]."' and type='".$chkExtFee["id"]."'");
					
				    // for discount
					$discount_extra_fee=$db->getRow("select sum(discount) as total_discount  from extrafee where idno='".$_GET["id"]."'");
					
								//echo $db->getLastQuery();
								if($mycheckInstall[0]>0){
									?>
									<tr>
                                        <th>Total <?php echo $chkExtFee["type"]; ?></th>
                                        <th><?php echo $chkExtFee["total"]-$fetch_extra_fee[discount];$overAllTotal+=$chkExtFee["total"]-$fetch_extra_fee[discount]; ?></th>
                                        <th><?php echo $mycheckInstall[1]; $overAllPay+=$mycheckInstall[1]; ?></th>
                                        <th><?php echo $rem=(int)($chkExtFee["total"]-$fetch_extra_fee[discount]-$mycheckInstall[1]); $overAllRemaining+=$rem; ?></th>
                                        <td><?php echo $fetch_extra_fee[discount];$overAllDiscount+=$fetch_extra_fee[discount]; ?></td>
                                   </tr>
									<?php
								}
							}
						}
					   ?>
                       <tr>
                            <th>Total Other Fee</th>
                            <th><?php echo (int)$totalOther;$overAllTotal+=$totalOther; ?></th>
                            <th><?php echo $payOther."+".$fineTotal;$overAllPay+=($payOther+$fineTotal); ?></th>
                            <th><?php echo $rem= (int)($totalOther-($payOther+$fineTotal)); $overAllRemaining+=$rem;?></th>
                            <td><?php echo (int)$OtherSiteTotal; $overAllDiscount+=$OtherSiteTotal-$other_Fee;?></td>
                       </tr>
					   
                        <tr>
                            <th>Total Hostel Other Fee</th>
                            <th><?php echo (int)$totalOtherhostel;$overAllTotal+=$totalOtherhostel; ?></th>
                            <th><?php echo $payOtherhostel."+".$fineTotalhostel;$overAllPay+=($payOtherhostel+$fineTotalhostel); ?></th>
                            <th><?php echo $rem= (int)($totalOtherhostel-($payOtherhostel+$fineTotalhostel)); $overAllRemaining+=$rem;?></th>
                            <td><?php echo (int)$OtherSiteTotalhostel; $overAllDiscount+=$OtherSiteTotalhostel;?></td>
                       </tr>
                        <tr>
                            <th>Total Fine</th>
                            <th><?php echo (int)$schoolFine+$busFine+$hostelFine+$extrafeeFine;$overAllPay+=($schoolFine+$busFine+$hostelFine+$extrafeeFine); ?></th>
                            <th><?php echo (int)$schoolFine+$busFine+$hostelFine+$extrafeeFine;$overAllTotal+=($schoolFine+$busFine+$hostelFine+$extrafeeFine); ?></th>
                            <th><?php echo 0;?></th>
                            <td><?php echo 0; ?></td>
                       </tr>
                       <tr style="border-bottom:2px solid #F00; border-top:2px solid #F00;">
                            <th>OverAll Detail</th>
                            <th><?php echo (int)$overAllTotal; ?></th>
                            <th><?php echo (int)$overAllPay; ?></th>
                            <th><?php echo (int)($overAllTotal-$overAllPay); ?></th>
                            <td><?php echo (int)$overAllDiscount+$OtherSiteTotal; ?></td>
                       </tr>
					 <?php 
                     $session=$db->getRows("select session from session where school_id='".$_SESSION["admin"]["school_id"]."' and session!='".$_SESSION["admin"]["session"]."'");
					 //echo $db->getErMsg().$db->getLastQuery(); 
                     $my_root=$db->getVal("select is_root from session_idno	where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and idno='".$_GET["id"]."'");
					 //echo $db->getErMsg().$db->getLastQuery(); 
                     if(is_array($session) && count($session)>0){
                         foreach($session as $s){
                            $installs=$db->getRow("select * from installment where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$s["session"]."' and idno=(select idno from session_idno where session='".$s["session"]."' and is_root=".$my_root." limit 0,1)");
							//echo $db->getErMsg();//$db->getLastQuery(); 
                            $classFee=0;$busFee=0;$classFeePay=0;$busFeePay=0;
                            for($i=1;$i<=15;$i++){
                                $classFee=$classFee+$installs["i".$i];
                                $busFee=$busFee+$installs["b".$i];
                                $classFeePay=$classFeePay+$installs["ip".$i];
                                $busFeePay=$busFeePay+$installs["bp".$i];
                            }
							if(($classFee+$busFee)>($classFeePay+$busFeePay) ){
                            ?>
							<tr style="border-top:2px solid #090">
                                <th>Remainin Class Fee for <?php echo $s["session"]; ?></th>
                                <th><?php echo (int)$installs["total"]; ?></th>
                                <th><?php echo (int)$classFeePay; ?></th>
                                <th><?php echo (int)($installs["total"]-$classFeePay); ?></th>
                                <td>Login with <?php echo $s["session"]; ?> session to pay fee</td>
                           </tr>
                           <tr>
                                <th>Remainin Bus Fee for <?php echo $s["session"]; ?></th>
                               <th><?php echo (int)$installs["bus"]; ?></th>
                                <th><?php echo (int)$busFeePay; ?></th>
                                <th><?php echo (int)($installs["bus"]-$busFeePay); ?></th>
                                <td>Login with <?php echo $s["session"]; ?> session to pay fee</td>
                           </tr>
							<?php
							}
                         }
                     }
                     ?>
                 	</tbody>
              </table>
                 <?php //echo $db->getErMsg().$db->getLastQuery(); ?>
          </div>
         </div>
    </div>
</div>        
<!-- / Forms -->
<?php
}
else{
	?>
	<div class="row-fluid"><div class="span12"><div class="top-bar">
    <h3><i class="icon-eye-open"></i> <?php echo ucwords($pgAct." ".$pgMod); ?></h3>
    </div>
    <div class="well no-padding">
	<?php
	$aryPgAct=array("src"=>"Promote", "page_id"=>$pgMod,"action"=>"add");
	$aryList=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and (status=1 or status=2) order by name");
	//echo $db->getErMsg()." <hr>".$db->getLastQuery();
	if(is_array($aryList) && count($aryList)>0)
	{
		?><div style="position: absolute;width:300px;z-index: 99999;margin: 30px;">
        <select onchange="fetchByClass()" class="span6" name="class" id="class" required <?php if($checkPay!="0" && $pgAct=="edit")echo 'disabled="disabled"'; ?> >
									<option value="">Class</option>
                                    <?php 
										$class=$db->getRows("select * from class");
										foreach($class as $cla){
											?>
											<option <?php if($cla["class"]==$aryForm["class"])echo 'selected';?> value="<?php echo $cla["class"] ?>">
												<?php echo $cla["class"] ?>
                                            </option>
											<?php
										}
									?>
								</select>
                                <select onchange="fetchByClass()" class="span6" name="section" id="section" >
                <option value="">Section</option>
                <?php 
                    $class=$db->getRows("select * from section where school_id='".$_SESSION["admin"]["school_id"]."'");
                    foreach($class as $cla){
                        ?>
                        <option value="<?php echo $cla["name"] ?>">
                            <?php echo $cla["name"] ?>
                        </option>
                        <?php
            
                    }
                ?>
            </select>
                                </div>
        <input type="hidden" id="tabletype" value="payfee_data" />
        <table class="table" id="ajaxtable">
            <thead>
                <tr>
                   <!-- <th width=8%>Serial No</th>-->
                     <th width=10%>Admission no</th>
                    <th>Name</th>
                    <th>Class</th>
                   
                    <th>Cast</th>
                    <th>Father</th>
                    <!--<th>Roll NO</th>-->
                    <th>Action</th>
                </tr>
            </thead>
            <tfoot>
            </tfoot>
            <tbody>
           
            </tbody>
        </table>
       
        <!--<table class="table" id="example">
            <thead>
                <tr>
                    <th>Id No</th>
                    <th>Name</th>
                    <th>Class</th>
                    <th>Father</th>
                    <th>Mobile</th>
                    <th><span class="action">Action</span></th>
                </tr>
            </thead>
            <tbody>
            <?php foreach($aryList as $clist){ $i++; 
            $aryPgAct["id"]=$clist['idno'];
            ?>
                <tr class="grade<?php if($i%2==0)echo "C";else "U";?>">
                    <td><?php echo $clist["idno"] ?></td>
                    <td><?php echo $clist["name"] ?></td>
                    <td><?php echo $clist["class"] ?></td>
                    <td><?php echo $clist["fname"] ?></td>
                    <td><?php echo $clist["mobile"] ?></td>
                    <td>
                         <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-info">Pay Fees</button></a>
                    </td>
                </tr>
            <?php } ?>
            </tbody>
            <tfoot>
                <tr>
                	<th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th colspan="2"></th>
                </tr>
            </tfoot>
        </table>-->
		<?php
	}
	else{
		?>
        <div class="alert alert-info">
          <a class="close" data-dismiss="alert">×</a>
          <i class="icon icon-warning-sign"></i> <b>Notice</b> Record not found </i>
        </div>
        <?php
	}
	?>
	</div></div></div>
	<?php
}

?>
<!-- / Forms -->
<script type="text/javascript">
$(document).ready(function(e) {
    var oTable = $('#ajaxtable').dataTable( {
		"bProcessing": true,
		'sPaginationType': 'full_numbers',
		"sAjaxSource": 'ajax.php?type='+$('#tabletype').val(),
		'iDisplayLength': 5,
		"oLanguage": {
			"sSearch": "Search by any columns:"
		}
	});
});
function fetchByClass(){
	var name=$("#class").val();
	var section=$("#section").val();
	if(name!=""){
		var url='ajax.php?class='+name+'&type='+$('#tabletype').val();
		if(section!=""){
			url+='&section='+section
		}
		 oTable = $('#ajaxtable').dataTable( {
			"bProcessing": true,
			'sPaginationType': 'full_numbers',
			"bServerSide": false,
			"bDestroy":true,
			"sAjaxSource": url,
			'iDisplayLength': 5,
			"oLanguage": {
				"sSearch": "Search by any columns:"
			}
		});
	}else{
		var oTable = $('#ajaxtable').dataTable( {
			"bProcessing": true,
			'sPaginationType': 'full_numbers',
			"bServerSide": false,
			"bDestroy":true,
			"sAjaxSource": 'ajax.php?type='+$('#tabletype').val(),
			'iDisplayLength': 5,
			"oLanguage": {
				"sSearch": "Search by any columns:"
			}
		});
	}
}
function changeIns(){
	var cla=$("#class").val();
	var id=$("#noInstallment").val();
	var bus=$("#bus").val();
	$.post( "ajax.php", { type: "installment" ,class: cla, bus: bus , nos: id } , function( data ) {
	  	$("#ins").html(data);
		getTotal();
	});
	
}
function getTotal(){
	var sum=0;var classfee=0;var busfee=0;
	var cost = document.getElementsByName('fee[]');
	classfee=$('#classfee').val();
	for(var i=0;i<cost.length;i++)
	{
		sum = parseInt(sum) + parseInt(cost[i].value);
	}
	$('#feetotal').val(sum);
	$('#discount').val(parseInt(classfee)-parseInt(sum));
}
function paynow(id){
	$("#save"+id).hide();
	var given=$("#given"+id).val();
	var udate=$("#fdate"+id).val();
	var fee=$("#fee"+id).val();
	if(given==""){
		alert("Amount cannot blank");
		$("#save"+id).show();
	}else{
		$.post( "ajax.php", { 	type: "feepayment" ,	
								fee: fee, 
								given: given, 
								udate: udate,
								student_id:'<?php echo $_GET["id"] ?>',
								id: id } , function( data ) {
			if(data==0)
			{
				window.location='<?php echo curPageURL(); ?>';
			}
			else
			{
				$("#save"+id).show();
				alert(data);
			}
		});
	}
}
function paybusnow(id){
	$("#savebus"+id).hide();
	var busgiven=$("#busgiven"+id).val();
	var udate=$("#bdate"+id).val();
	//alert(udate);return false;exit;
	var busfee=$("#busfee"+id).val();
	if(busgiven==""){
		alert("Amount cannot blank");
		$("#savebus"+id).show();
	}else{
		$.post( "ajax.php", { 	type: "busfeepayment" ,	
								busfee: busfee, 
								udate: udate, 
								busgiven: busgiven, 
								student_id:'<?php echo $_GET["id"] ?>',
								id: id } , function( data ) {
			if(data==0)
			{
				window.location='<?php echo curPageURL(); ?>';
			}
			else
			{
				$("#savebus"+id).show();
				alert(data);
			}
		});
	}
}
function payhostelnow(id){
	$("#savehostel"+id).hide();
	var hostelgiven=$("#hostelgiven"+id).val();
	var udate=$("#hosdate"+id).val();
	var hostelfee=$("#hostelfee"+id).val();
	//alert(hostelgiven+"\n"+hostelfee);
	if(hostelgiven==""){
		alert("Amount cannot blank");
		$("#hostelbus"+id).show();
	}else{
		$.post( "ajax.php", { 	type: "hostelfeepayment" ,	
								hostelfee: hostelfee, 
								udate: udate, 
								hostelgiven: hostelgiven, 
								student_id:'<?php echo $_GET["id"] ?>',
								id: id } , function( data ) {
			if(data==0)
			{
				window.location='<?php echo curPageURL(); ?>';
			}
			else
			{
				$("#hostelbus"+id).show();
				alert(data);
			}
		});
	}
}
function payother(id){
	$("#saveother"+id).hide();
	var given=parseInt($("#givenother"+id).val());
	var fee=$("#reasion"+id).val();
	//alert(fee);
	 if(given==""){
		alert("Amount cannot blank");
		$("#saveother"+id).show();
	}else if(fee < given){
		alert("Amount("+given+") cannot greater then total Amount("+fee+")");
		$("#saveother"+id).show();
	}else{
		//alert(given+"="+fee);exit;
		var reasion=$("#reasion"+id).val();
		var udate=$("#odte"+id).val();//alert(udate);return true;
		$.post( "ajax.php", { 	type: "feeother" ,	
								fee: fee, 
								given: given,
								udate: udate, 
								reasion: reasion, 
								student_id:'<?php echo $_GET["id"] ?>',
								id: id } , function( data ) {
			if(data==0)
			{
				window.location='<?php echo curPageURL(); ?>';
			}
			else
			{
				alert(data);
				$("#saveother"+id).show();
			}
		});
	}
}


// update_back_dues start--------
function update_back_dues(id,name){
	
	
	var c= $("#feeother"+id).val();
	//var name=name;
	
	//alert(name);
	//return false;
	$.post( "ajax.php", { 	type: "back_dues" ,	
								update: c,
								name:name,
								student_id:'<?php echo $_GET["id"] ?>',
								id: id } , function( data ) {
									//alert(data);
																		
					if(data==0)
			{
				window.location='<?php echo curPageURL(); ?>';
			}
			else
			{
				alert(data);
				$("#saveother"+id).show();
			}
			
		});
	
	
	
}

// update_back_dues end
function payhostelother(id){
	$("#saveother"+id).hide();
	var given=parseInt($("#givenother1"+id).val());
	var fee=$("#reasion1"+id).val();
	//alert(fee);
	 if(given==""){
		alert("Amount cannot blank");
		$("#saveother"+id).show();
	}else if(fee < given){
		alert("Amount("+given+") cannot greater then total Amount("+fee+")");
		$("#saveother"+id).show();
	}else{
		//alert(given+"="+fee);exit;
		var reasion=$("#reasion1"+id).val();
		var udate=$("#hodte"+id).val();//alert(udate);return true;
		$.post( "ajax.php", { 	type: "feehostelother" ,	
								fee: fee, 
								given: given,
								udate: udate, 
								reasion: reasion, 
								student_id:'<?php echo $_GET["id"] ?>',
								id: id } , function( data ) {
			if(data==0)
			{
				window.location='<?php echo curPageURL(); ?>';
			}
			else
			{
				alert(data);
				$("#saveother"+id).show();
			}
		});
	}
}

function payextranow(id,typeid){
	$("#saveextra"+typeid+id).hide();
	var given=$("#extragiven"+typeid+"fee"+id).val();
	var udate=$("#ex"+typeid+"date"+id).val();
	//alert(udate);return false;exit;
	var fee=$("#extra"+typeid+"fee"+id).val();
	if(given==""){
		alert("Amount cannot blank");
		$("#saveextra"+typeid+id).show();
	}else{
		$.post( "ajax.php", { 	type: "extrapayment" ,
								typeid : typeid	,
								fee: fee, 
								udate: udate, 
								given: given, 
								student_id:'<?php echo $_GET["id"] ?>',
								id: id } , function( data ) {
			if(data==0)
			{
				window.location='<?php echo curPageURL(); ?>';
			}
			else
			{
				$("#saveextra"+typeid+id).show();
				alert(data);
			}
		});
	}
}
<?php if($aryInstall["status"]==1){?>
$(document).ready(function(){
	var givenCost = document.getElementsByName('given[]');
	var j=0;
	for(var i=0;i<givenCost.length;i++)
	{
		if(givenCost[i].value=="")j++;
	}
	if(j==1){
		var lasttd=$(".classtd:last").html();
		var add_ins='<a style="float:left" onclick="addinstallment()" href="javascript:;"><button type="button" class="btn btn-info">add install</button></a>';
		$(".classtd:last").html(lasttd+' '+add_ins);
	}
	var givenCost = document.getElementsByName('busgiven[]');
	var j=0;
	for(var i=0;i<givenCost.length;i++)
	{
		if(givenCost[i].value=="")j++;
	}
	if(j==1){
		var lastbustd=$(".bustd:last").html();
		var add_bus_ins='<a style="float:left" onclick="addbusinstallment()" href="javascript:;"><button type="button" class="btn btn-info">add install</button></a>';
		$(".bustd:last").html(lastbustd+' '+add_bus_ins);
	}
	var givenCost = document.getElementsByName('hostelgiven[]');
	var j=0;
	for(var i=0;i<givenCost.length;i++)
	{
		if(givenCost[i].value=="")j++;
	}
	if(j==1){
		var lasthosteltd=$(".hosteltd:last").html();
		var add_hostel_ins='<a style="float:left" onclick="addhostelinstallment()" href="javascript:;"><button type="button" class="btn btn-info">add install</button></a>';
		$(".hosteltd:last").html(lasthosteltd+' '+add_hostel_ins);
	}
});
<?php } ?>
function addinstallment(){
	var ins = prompt ('How musch installment you want','2');
	var instalment_no=$(".classtd:last .instalment_no").val();
	var rested_instalment=12-instalment_no;
	if(ins>rested_instalment){
		alert("You maximun no of installment");
	}else
	if(ins!="" && ins!=0){
		make_installment(ins,instalment_no);
	}
}
function make_installment(id,instalment_no){
	var fee=$(".classtd:last .instalment").val();
	update_installment(id,fee,instalment_no,"update_fee_installment");
}
function addbusinstallment(){
	var ins = prompt ('How musch installment you want','2');
	var instalment_no=$(".bustd:last .instalmentbus_no").val();
	var rested_instalment=12-instalment_no;
	if(ins>rested_instalment){
		alert("You  reched  maximum no of installment");
	}else
	if(ins!="" && ins!=0){
		make_bus_installment(ins,instalment_no);
	}
}
function make_bus_installment(id,instalment_no){
	var fee=$(".bustd:last .instalmentbus").val();
	update_installment(id,fee,instalment_no,"update_bus_installment");
}
function addhostelinstallment(){
	var ins = prompt ('How musch installment you want','2');
	var instalment_no=$(".hosteltd:last .instalmenthostel_no").val();
	var rested_instalment=12-instalment_no;
	if(ins>rested_instalment){
		alert("You  reched  maximum no of installment");
	}else
	if(ins!="" && ins!=0){
		make_hostel_installment(ins,instalment_no);
	}
}
function make_hostel_installment(id,instalment_no){
	var fee=$(".hosteltd:last .instalmenthostel").val();
	update_installment(id,fee,instalment_no,"update_hostel_installment");
}
function update_installment(id,fee,instalment_no,type){
	$.post( "ajax.php", { 	type: type ,	
							id: id, 
							fee: fee,
							instalment_no:instalment_no, 
							student_id:'<?php echo $_GET["id"] ?>'
						} , function( data ) {
	  	
		if(data==0)
		{
			window.location='<?php echo curPageURL(); ?>';
		}
		else
		{
			alert(data);
		}
	});
}
function competeFee(){
	if(confirm('Are you sure want to pay?')){
		$.post( "ajax.php", { 	type: "competeFee" ,
								student_id:'<?php echo $_GET["id"] ?>'
							} , function( data ) {
			if(data==0)
			{
				window.location='<?php echo curPageURL(); ?>';
			}
			else
			{
				alert(data);
			}
		});
	}
}

$(document).ready(function(){
	$("#add").click(function(){
		var rowCount = ($('#tbody tr').length)+1;
		var add_tr='<tr><td>other '+rowCount+'</td><td><input type="hidden" name="idno" value="<?php echo $_GET["id"]; ?>" /><input class="input-block-level" type="text" placeholder="enter detail" name="fee[]" id="feeother'+rowCount+'"></td><td><input class="input-block-level" id="givenother'+rowCount+'" type="text" name="othergiven[]"></td><td></td><td></td><td><a href="javascript:;" id="saveother'+rowCount+'" onclick="payother(\''+rowCount+'\')"><button type="button" class="btn btn-info">Pay Fees</button></a><a class="delete" href="javascript:;"><button type="button" class="btn btn-info">Remove Other</button></a></td></tr>';
		$("#tbody").append($(add_tr));
		$('#tbody td a.delete').click(function(){
				$(this).parent().parent().remove(); 
		});	
	});
});

function checkRecept(STcls){
	var totalSum=0;var tot=0;
	var name=0;	var bus=0; var hostel=0; var otherlMonth="";	var extraFee="";	var other=0; var otherfee=""; var ext="";	var msg="";	var rrid="rrid";
	var nameFine=0;	var busFine=0; var hostelFine=0; var otherlMonthFine="";	var extraFeeFine="";	var otherFine=0; var otherFinefee=""; var extFine="";
	var busMonth="";	var hotelMonth="";	var tutionMonth="";	var otherMonth="";	var myotherMonth="";	var extraMonth=""; var m=""; var extrafee=0;
	var busFineMonth="";	var hotelFineMonth="";	var tutionFineMonth="";	var otherFineMonth="";	var myotherMonth="";	var extraFineMonth=""; var m=""; var extraFinefee=0;  var extraFineFee ="";
	$("input:checkbox[type=checkbox]:checked").each(function(){
		var amt=parseInt($(this).val());
		rrid=rrid+"-"+$(this).attr('data-rr');
		if($(this).attr("class")=="bus"){msg+=" bus";bus+=amt;if(busMonth=="")busMonth+=$(this).attr("data-month");else busMonth+=","+$(this).attr("data-month"); m+=","+$(this).attr("data-extramonth");tot+=parseInt($(this).attr("data-tot"));}
		else if($(this).attr("class")=="bus_fine"){msg+=" bus fine ";busFine+=amt;if(busFineMonth=="")busFineMonth+=$(this).attr("data-month");else busFineMonth+=","+$(this).attr("data-month"); m+=","+$(this).attr("data-extramonth");tot+=amt;}
		else if($(this).attr("class")=="hostel"){msg+=" hostel";hostel+=amt;if(hotelMonth=="")hotelMonth+=$(this).attr("data-month");else hotelMonth+=","+$(this).attr("data-month");tot+=parseInt($(this).attr("data-tot"));}
		else if($(this).attr("class")=="hostel_fine"){msg+=" hostel Fine";hostelFine+=amt;if(hotelFineMonth=="")hotelFineMonth+=$(this).attr("data-month");else hotelFineMonth+=","+$(this).attr("data-month");tot+=amt;}
		
		
		else if($(this).attr("class")=="other"){msg+= $(this).attr("data-class");otherfee+="&fee-"+$(this).attr("data-class")+"="+amt; if(otherlMonth=="")otherlMonth+=$(this).attr("data-month"); else otherlMonth+=","+$(this).attr("data-month");tot+=amt;}
		
		/*else if($(this).attr("class")=="myother"){msg+= $(this).attr("data-class"); ext+="&fee-"+$(this).attr("data-class")+"="+amt;tot+=parseInt($(this).attr("data-tot"));}*/
		
		else if($(this).attr("class")=="myother"){msg+= $(this).attr("data-class"); if(myotherMonth=="")myotherMonth+=$(this).attr("data-month");else myotherMonth+=","+$(this).attr("data-month"); ext+="&fee-"+$(this).attr("data-class")+"="+amt;tot+=parseInt($(this).attr("data-tot"));}
		
		/*else if($(this).attr("class")=="myother_fine"){msg+= $(this).attr("data-class"); extFine+="&fee-"+$(this).attr("data-class")+"%20Remaining"+"="+amt;tot+=amt;}*/
		
		else if($(this).attr("class")=="myother_fine"){msg+= $(this).attr("data-class");if(myotherMonth=="")myotherMonth+=$(this).attr("data-month");else myotherMonth+=","+$(this).attr("data-month"); extFine+="&fee-"+$(this).attr("data-class")+"%20Remaining"+"="+amt;tot+=amt;}
		
		
		
		
		
		
		
		else if($(this).attr("class")=="cla"){msg+=" class";name+=amt;if(tutionMonth=="")tutionMonth+=$(this).attr("data-month");else tutionMonth+=","+$(this).attr("data-month"); m+=","+$(this).attr("data-extramonth");tot+=parseInt($(this).attr("data-tot")); }
		else if($(this).attr("class")=="cla_fine"){msg+=" class Fine";nameFine+=amt;if(tutionFineMonth=="")tutionFineMonth+=$(this).attr("data-month");else tutionFineMonth+=","+$(this).attr("data-month"); m+=","+$(this).attr("data-extramonth");tot+=amt;}
		
		
		else if($(this).attr("class")=="extrafee"){extraFee+="&extrafee-"+$(this).attr("data-name")+"`"+$(this).attr("data-month")+"="+amt;
if(extraMonth=="")extraMonth+=$(this).attr("data-month");else extraMonth+=","+$(this).attr("data-month");tot+=parseInt($(this).attr("data-tot"));}
		else if($(this).attr("class")=="extrafee_fine"){
			extraFineFee+="&extrafee-fine%20"+$(this).attr("data-name")+"`"+$(this).attr("data-month")+"="+amt;tot+=amt;
			 if(extraFineMonth=="")extraFineMonth+=$(this).attr("data-month");else extraFineMonth+=","+$(this).attr("data-month"); }
		//alert(amt+"-"+tot);
		totalSum+=amt;
	}); //alert(otherfee);
	//var month="&busMonth="+busMonth+"&hotelMonth="+hotelMonth+"&tutionMonth="+tutionMonth+"&otherMonth="+otherMonth+"&myotherMonth="+myotherMonth+"&extraMonth="+extraMonth;
	//alert(tot);
	var month="&Months="+busMonth+","+hotelMonth+","+tutionMonth+","+m+","+otherMonth+","+myotherMonth+","+extraMonth;
	//var tution_month="&tution_month="+tutionMonth;
	//var bus_month="&bus_month="+busMonth;
	getPopup("<?php echo URL_ROOT ?>print/?page_id=recepitNew&idno=<?php echo $_GET["id"]."&udate=".date("d-m-Y")."&amount="; ?>"+totalSum+"&type=fee&fee-Tution%20Fees="+name+"&fee-Bus%20Fees="+bus+"&fee-Hostel%20Fees="+hostel+"&fee-Hostel%20Fine="+hostelFine+"&fee-Bus%20Fine="+busFine+"&fee-Tution%20Fine="+nameFine+"&rrid="+rrid+otherfee+"&paytype=classfee&detail=pay fee for "+msg+"&class="+STcls+"&install=1"+
	extraFee+extraFineFee+ext+extFine+month+"&total="+tot,"1","recepit");
	$(".close").click(function() {
		$(this).parent().remove();
	});
	$(".outer").click(function() {
		$(this).remove();
	});
}
function checkRecept_hostel(STcls){
	var totalSum=0;var tot=0;
	var name=0;	var bus=0; var hostel=0; var otherlMonth="";	var extraFee="";	var other=0; var otherfee=""; var ext="";	var msg="";	var rrid="rrid";
	var nameFine=0;	var busFine=0; var hostelFine=0; var otherlMonthFine="";	var extraFeeFine="";	var otherFine=0; var otherFinefee=""; var extFine="";
	var busMonth="";	var hotelMonth="";	var tutionMonth="";	var otherMonth="";	var myotherMonth="";	var extraMonth=""; var m=""; var extrafee=0;
	var busFineMonth="";	var hotelFineMonth="";	var tutionFineMonth="";	var otherFineMonth="";	var myotherMonth="";	var extraFineMonth=""; var m=""; var extraFinefee=0;  var extraFineFee ="";
	$("input:checkbox[type=checkbox]:checked").each(function(){
		var amt=parseInt($(this).val());
		rrid=rrid+"-"+$(this).attr('data-rr');
		if($(this).attr("class")=="bus"){msg+=" bus";bus+=amt;if(busMonth=="")busMonth+=$(this).attr("data-month");else busMonth+=","+$(this).attr("data-month"); m+=","+$(this).attr("data-extramonth");tot+=parseInt($(this).attr("data-tot"));}
		else if($(this).attr("class")=="bus_fine"){msg+=" bus fine ";busFine+=amt;if(busFineMonth=="")busFineMonth+=$(this).attr("data-month");else busFineMonth+=","+$(this).attr("data-month"); m+=","+$(this).attr("data-extramonth");tot+=amt;}
		else if($(this).attr("class")=="hostel"){msg+=" hostel";hostel+=amt;if(hotelMonth=="")hotelMonth+=$(this).attr("data-month");else hotelMonth+=","+$(this).attr("data-month");tot+=parseInt($(this).attr("data-tot"));}
		else if($(this).attr("class")=="hostel_fine"){msg+=" hostel Fine";hostelFine+=amt;if(hotelFineMonth=="")hotelFineMonth+=$(this).attr("data-month");else hotelFineMonth+=","+$(this).attr("data-month");tot+=amt;}
		
		
		else if($(this).attr("class")=="other"){msg+= $(this).attr("data-class");otherfee+="&fee-"+$(this).attr("data-class")+"="+amt; if(otherlMonth=="")otherlMonth+=$(this).attr("data-month"); else otherlMonth+=","+$(this).attr("data-month");tot+=amt;}
		
		else if($(this).attr("class")=="myother"){msg+= $(this).attr("data-class"); ext+="&fee-"+$(this).attr("data-class")+"="+amt;tot+=parseInt($(this).attr("data-tot"));}
		else if($(this).attr("class")=="hostelother"){msg+= $(this).attr("data-class"); ext+="&fee-"+$(this).attr("data-class")+"="+amt;tot+=parseInt($(this).attr("data-tot"));}
		else if($(this).attr("class")=="hostelother_fine"){msg+= $(this).attr("data-class"); extFine+="&fee-"+$(this).attr("data-class")+"%20Remaining"+"="+amt;tot+=amt;}

		
		else if($(this).attr("class")=="cla"){msg+=" class";name+=amt;if(tutionMonth=="")tutionMonth+=$(this).attr("data-month");else tutionMonth+=","+$(this).attr("data-month"); m+=","+$(this).attr("data-extramonth");tot+=parseInt($(this).attr("data-tot")); }
		else if($(this).attr("class")=="cla_fine"){msg+=" class Fine";nameFine+=amt;if(tutionFineMonth=="")tutionFineMonth+=$(this).attr("data-month");else tutionFineMonth+=","+$(this).attr("data-month"); m+=","+$(this).attr("data-extramonth");tot+=amt;}
		
		
		else if($(this).attr("class")=="extrafee"){extraFee+="&extrafee-"+$(this).attr("data-name")+"`"+$(this).attr("data-month")+"="+amt;
if(extraMonth=="")extraMonth+=$(this).attr("data-month");else extraMonth+=","+$(this).attr("data-month");tot+=parseInt($(this).attr("data-tot"));}
		else if($(this).attr("class")=="extrafee_fine"){
			extraFineFee+="&extrafee-fine%20"+$(this).attr("data-name")+"`"+$(this).attr("data-month")+"="+amt;tot+=amt;
			 if(extraFineMonth=="")extraFineMonth+=$(this).attr("data-month");else extraFineMonth+=","+$(this).attr("data-month"); }
		//alert(amt+"-"+tot);
		totalSum+=amt;
	}); //alert(tot);
	//var month="&busMonth="+busMonth+"&hotelMonth="+hotelMonth+"&tutionMonth="+tutionMonth+"&otherMonth="+otherMonth+"&myotherMonth="+myotherMonth+"&extraMonth="+extraMonth;
	//alert(tot);
	var month="&Months="+busMonth+","+hotelMonth+","+tutionMonth+","+m+","+otherMonth+","+myotherMonth+","+extraMonth;
	//var tution_month="&tution_month="+tutionMonth;
	//var bus_month="&bus_month="+busMonth;
	getPopup("<?php echo URL_ROOT ?>print/?page_id=recepitNew_hostel&idno=<?php echo $_GET["id"]."&udate=".date("d-m-Y")."&amount="; ?>"+totalSum+"&type=fee&fee-Tution%20Fees="+name+"&fee-Bus%20Fees="+bus+"&fee-Hostel%20Fees="+hostel+"&fee-Hostel%20Fine="+hostelFine+"&fee-Bus%20Fine="+busFine+"&fee-Tution%20Fine="+nameFine+"&rrid="+rrid+otherfee+"&paytype=classfee&detail=pay fee for "+msg+"&class="+STcls+"&install=1"+
	extraFee+extraFineFee+ext+extFine+month+"&total="+tot,"1","recepit");
	$(".close").click(function() {
		$(this).parent().remove();
	});
	$(".outer").click(function() {
		$(this).remove();
	});
}
$(function() {
	$(".datepicker").each(function(index, element) {
        var d = new Date(); // for now
		datetext=d.getHours()+": "+d.getMinutes()+": "+d.getSeconds();
		$( this ).datepicker({
		  changeMonth: true,
		  changeYear: true,
		  showOn: "button",
		  buttonImage: "js/images/calendar.gif",
		  buttonImageOnly: true,
		  buttonText: "Select date",
		  dateFormat: 'yy-mm-dd ',
		  onSelect: function(datetext){
			var d = new Date(); // for now
			datetext=datetext+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
			$(this).val(datetext);
		  }
		});
    });
	getTotalMonthCost();
	getHostelTotalMonthCost();
	$(".datepicker").hide();
});


// previous code start
/*function getTotalMonthCost(){
	var month=$("#MyActivatedMonth").val();
	var udetail=$("#userdetails").html();
	var total=0;htmlCode="";$("#appendDiv").remove();var htmlDisplay="<div>"+udetail+"</div>";
	var monthNames = [ "January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December" ];
	//$("input[data-month=month"+month+"]").each(function(index, element) {
//		var dataP=$(this).attr('data-value');
//		var typeP=$(this).attr('data-type');
//		var dataValP=(dataP).split("-");
//		total=total+parseFloat(dataValP[0]);
//	});
		var t="0",oldrem="0";	
		for(var i=1;i<=month;i++){
			var m=0;
			if(i<=9){
				m=i+3;
			}
			else{
				m=i-9;
			}
			m=m-1; 
			var jj=0;var c=0;
			var cnts=$("input[data-month=month"+i+"]").size();
			var str="";
			$("input[data-month=month"+i+"]").each(function(index, element) {c++;	
				
				var dataP=$(this).attr('data-value');
				var typeP=$(this).attr('data-type');
				var dataValP=(dataP).split("-");
				var dataN=$(this).attr('data-name');
				var dataT=$(this).attr('data-t');
				var idd=0;var left=0;
				if(typeP=="other"){
					idd=$(this).attr('data-idd');
					left=$(this).attr('data-left');
				}
				if(typeP=="tuition_fine" && dataValP[0]=="")
				      dataValP[1]=1;
				if(typeP=="bus_fine" && dataValP[0]=="")
					  dataValP[1]=1;
					  
					//alert(left);  
				//alert(typeP+"-"+dataP);
				if(dataValP[1]=="" || dataValP[1]=="0"){//alert(typeP+"-"+dataValP[0]+" of  month"+i+" "+dataValP[1]);
					if(typeP=="tution" || typeP=="bus" || typeP=="other" || dataT=="extrafee")
							str=typeP;
					if(typeP=="hostel" || typeP=="hostelother" || typeP=="hostel_fine")
					 	 str="";		
					if(str!="" || c==1){
								total=total+parseFloat(dataValP[0]);
					jj=jj+1;
					if(jj==1){
						htmlDisplay+='<table class="table"><thead><tr><td colspan="'+cnts+'" style="text-align:center">'+monthNames[m]+'</td></tr><thead><tbody><tr>'; 
					}
					}
					if(total==0 || str==""){}
					else{
						if(typeP!="hostel" && typeP!="hostelother"){
							htmlCode+='<input type="hidden" name="pay-type[]" value="'+typeP+'">';
							htmlCode+='<input type="hidden" name="pay-value[]" value="'+dataValP[0]+'">';
							htmlCode+='<input type="hidden" name="pay-month[]" value="'+i+'">';
							htmlCode+='<input type="hidden" name="pay-name[]" value="'+dataN+'">';
							htmlCode+='<input type="hidden" name="pay-idd[]" value="'+idd+'">';
							htmlCode+='<input type="hidden" name="pay-left[]" value="'+left+'">';
						
							htmlDisplay+='<td>'+dataN+' ';
							htmlDisplay+='<br/>'+dataValP[0]+'</td>';
						}	
					}
				}			
			});
			htmlDisplay+='</tr></tbody></table>';
		}
    $("#paybymonth").append("<div id='appendDiv'>"+htmlCode+"</div>")
	$("#feedetailDiv").html(htmlDisplay+"<hr/>Total : "+total)
	$("#paytotalMoth").val(total);
	//alert(total+"first");
}*/
// previous code end

// my new code start

function getTotalMonthCost(){
	var month=$("#MyActivatedMonth").val();
	
	var udetail=$("#userdetails").html();
	var total=0;
	htmlCode="";
	$("#appendDiv").remove();
	var htmlDisplay="<div>"+udetail+"</div>";
	var monthNames = [ "January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December" ];
	//$("input[data-month=month"+month+"]").each(function(index, element) {
//		var dataP=$(this).attr('data-value');
//		var typeP=$(this).attr('data-type');
//		var dataValP=(dataP).split("-");
//		total=total+parseFloat(dataValP[0]);
//	});
		var t="0",oldrem="0";	hf=0;
		for(var i=1;i<=month;i++){
			var m=0;
			if(i<=9){
				m=i+3;
			}
			else{
				m=i-9;
			}
			m=m-1; 
			var jj=0;var c=0;
			var cnts=$("input[data-month=month"+i+"]").size();
			var str="";
			$("input[data-month=month"+i+"]").each(function(index, element) {c++;	
				
				var dataP=$(this).attr('data-value');
				
				//alert(dataP);
				var typeP=$(this).attr('data-type');
				var dataValP=(dataP).split("-");
				var dataN=$(this).attr('data-name');
				var dataT=$(this).attr('data-t');
				var idd=0;var left=0;
				if(typeP=="other"){
					idd=$(this).attr('data-idd');
					left=$(this).attr('data-left');
				}
				if(typeP=="tuition_fine" && dataValP[0]=="")
				      dataValP[1]=1;
				if(typeP=="bus_fine" && dataValP[0]=="")
					  dataValP[1]=1;
					//alert(left);  
				//alert(typeP+"-"+dataP);
				if(dataValP[1]=="" || dataValP[1]=="0"){//alert(typeP+"-"+dataValP[0]+" of  month"+i+" "+dataValP[1]);
					//if(typeP=="tution" || typeP=="bus" || typeP=="other" || typeP=="hostel" || dataT=="extrafee")
							//str=typeP;
						
						if(typeP=="tution" || typeP=="bus" || typeP=="other" || dataT=="extrafee")
							str=typeP;
					if(typeP=="hostel" || typeP=="hostelother" || typeP=="hostel_fine")
					 	 str="";
						
						
					if(str!="" || c==1){
								total=total+parseFloat(dataValP[0]);
								//alert(total)
					jj=jj+1;
					if(jj==1){
						htmlDisplay+='<table class="table"><thead><tr><td colspan="'+cnts+'" style="text-align:center">'+monthNames[m]+'</td></tr><thead><tbody><tr>'; 
					}
					}
					if(total==0){}
					else{
						if(typeP!="hostel" && typeP!="hostelother"){
						htmlCode+='<input type="hidden" name="pay-type[]" value="'+typeP+'">';
						htmlCode+='<input type="hidden" name="pay-value[]" value="'+dataValP[0]+'">';
						htmlCode+='<input type="hidden" name="pay-month[]" value="'+i+'">';
						htmlCode+='<input type="hidden" name="pay-name[]" value="'+dataN+'">';
						htmlCode+='<input type="hidden" name="pay-idd[]" value="'+idd+'">';
						htmlCode+='<input type="hidden" name="pay-left[]" value="'+left+'">';
						htmlDisplay+='<td>'+dataN+' ';
						htmlDisplay+='<br/>'+dataValP[0]+'</td>';
						}
					}
				}
				/*if(dataValP[1]=="" || dataValP[1]=="0"){//alert(typeP+"-"+dataValP[0]+" of  month"+i+" "+dataValP[1]);
					if(t==typeP){
						total=total+parseFloat(dataValP[0])-oldrem;
						t="0";
						oldrem="";
					}else{
						total=total+parseFloat(dataValP[0]);
					}
				}else if(dataValP[0]>dataValP[1]){
					var rem=dataValP[0]-dataValP[1];
					total=total+rem;
					t=typeP;oldrem=rem;
				}//alert(dataP+" - "+t+" - "+total)*/
				
			});
			htmlDisplay+='</tr></tbody></table>';
			
			/*
			if ($("#fee"+i+"").length)
				
			{
  alert('this record already exists');
} else {
  alert(1);
}
*/
			
			//var t_fee= $("#fee"+i+"").length();
			//alert(t_fee);
			//var b_fee= $("#busfee"+i+"").length();
			//var hostel_f = $("#hostelfee"+i+"").val();
			//alert(parseInt(hostel_f));
           //hf += +parseInt(hostel_f);	
            //hf +=parseInt(hostel_f);
			/*
			if($("#fee"+i+"").length==0){
			if($("#busfee"+i+"").length==0){
				
				//alert(1);
				var hostel_f = $("#hostelfee"+i+"").val();
			//alert(parseInt(hostel_f));
           //hf += +parseInt(hostel_f);	
            hf +=parseInt(hostel_f);
				
				
			   }	
		 
			}	 
			total= total-hf;
			*/
		}
		// alert(hf);
		  
		
    $("#paybymonth").append("<div id='appendDiv'>"+htmlCode+"</div>")
	$("#feedetailDiv").html(htmlDisplay+"<hr/>Total : "+total)
	$("#paytotalMoth").val(total);
	//feedetailDiv
}
// my new code end

function getHostelTotalMonthCost(){
	var month=$("#MyActivatedMonth1").val();
	var udetail=$("#userdetails").html();
	var total=0;htmlCode="";$("#appendDiv1").remove();var htmlDisplay="<div>"+udetail+"</div>";
	var monthNames = [ "January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December" ];
		var t="0",oldrem="0";
		//alert(month);	
		var i=1;
		for(;i<=month;i++){
			var m=0;
			if(i<=9){
				m=i+3;
			}
			else{
				m=i-9;
			}
			m=m-1; 
			var jj=0;var c=0;
			var cnts=$("input[data-month=month"+i+"]").size();
			var str="";
			$("input[data-month=month"+i+"]").each(function(index, element) {c++;	
				var dataP=$(this).attr('data-value');
				var typeP=$(this).attr('data-type');
				var dataValP=(dataP).split("-");
				var dataN=$(this).attr('data-name');
				var dataT=$(this).attr('data-t');
				var idd=0;var left=0;
				if(typeP=="hostel_fine" && dataValP[0]=="")
				     dataValP[1]=1;
				if(typeP=="hostelother"){
					idd=$(this).attr('data-idd');
					left=$(this).attr('data-left');
				}
				//alert(typeP+"-"+dataP+"-"+i);
				if(dataValP[1]=="" || dataValP[1]=="0"){//alert(typeP+"-"+dataValP[0]+" of  month"+i+" "+dataValP[1]);
					if(typeP=="hostel" || typeP=="hostelother" || typeP=="hostel_fine" ){
							str=typeP;
					if(str!="" || c==1){
								total=total+parseFloat(dataValP[0]);
					jj=jj+1;
					if(jj==1){
						htmlDisplay+='<table class="table"><thead><tr><td colspan="'+cnts+'" style="text-align:center">'+monthNames[m]+'</td></tr><thead><tbody><tr>'; 
					}
					}
					if(total==0){}
					else{
						htmlCode+='<input type="hidden" name="pay-type[]" value="'+typeP+'">';
						htmlCode+='<input type="hidden" name="pay-value[]" value="'+dataValP[0]+'">';
						htmlCode+='<input type="hidden" name="pay-month[]" value="'+i+'">';
						htmlCode+='<input type="hidden" name="pay-name[]" value="'+dataN+'">';
						htmlCode+='<input type="hidden" name="pay-idd[]" value="'+idd+'">';
						htmlCode+='<input type="hidden" name="pay-left[]" value="'+left+'">';
						htmlDisplay+='<td>'+dataN+' ';
						htmlDisplay+='<br/>'+dataValP[0]+'</td>';
						//alert(typeP+"="+dataValP[0]+"-"+dataN);
					}
					}
				}
				});
			htmlDisplay+='</tr></tbody></table>';
		}//alert(i+"--"+c);
    $("#paybymonth1").append("<div id='appendDiv1'>"+htmlCode+"</div>")
	$("#feedetailDiv1").html(htmlDisplay+"<hr/>Total : "+total)
	$("#paytotalMoth1").val(total);
	//alert(total+"Second");
}
function showDetail(id){
	$( "#"+id ).dialog({
      resizable: false,
      modal: true,
	  height:400,
	  width:700,
      buttons: {
	   "Print": function() {
          printDiv('feedetailDiv')
        },
       Cancel: function() {
          $( this ).dialog( "close" );
        }
      }
    });
}
</script>
<style>
.top-bar, .accordion .accordion-toggle{
	overflow:inherit !important;
	width: 96%;
	display:inline-block !important;
}
</style>