<?php // manav 
$pgMod="pay_fee";
$pgAct="view";
unset($_SESSION["recept"]);
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);

$idd=$_GET[id];
//payNow1
		
if(isset($_POST["payNow1"])){
	
	if($_POST["payNow1"]==""){
		$alert_err[]="Please enter Pay amount";
	}	
	
	elseif($_POST["payNow1"]<=0){
		$alert_err[]="Amount must greater than 0";
		
	}elseif(!is_numeric($_POST["payNow1"])){
		$alert_err[]="Amount must Numeric";
	}elseif($_POST["payNow1"]>$_POST["paytotalMoth"]){
		$alert_err[]="Amount must less than total amount";
	}
	else{
		echo $sibling=$db->getVal("SELECT concat(idno,',',sibling) as sibling from student  WHERE idno='".$_GET["id"]."' and session='".$_SESSION["admin"]["session"]."' ");	
$a= explode(',',$sibling);
$rrid=array(); 
$url=array();
//print_r($a );
$total=$_POST["payNow1"];
		foreach($a as $a1){
			$_GET["id"]=$a1;
			$class_sibling=$db->getVal("SELECT class  from student  WHERE idno='".$_GET["id"]."' and session='".$_SESSION["admin"]["session"]."' ");	
			
		$d= explode(" ",$_POST["select_date"]);
		
		
		if($d[0]=="2018-02-25"){ 
		
		$d= implode(" ",$d);
		
		} else { $_POST["select_date"]= date("Y-m-d H:i:g");}
		
		
		
		 $id= $_GET["id"];
		 
		 $clas= $class_sibling;
		 $m=$_POST["activatedMonth"];
		/* $receptData=array(	
						"idno"=>$_GET["id"],
						"udate"=>date("Y-m-d"),
						"amount"=>$total,
						
						
						"class"=>$_POST["cls"],
						"total"=>$_POST["paytotalMoth"],
						
						"install"=>$_POST["activatedMonth"]
	);*/
	
	$receptData=array(	
						"idno"=>$_GET["id"],
						"udate"=>$_POST["select_date"],
						"amount"=>$total,
						
						
						"class"=>$_POST["cls"],
						"total"=>$_POST["paytotalMoth"],
						
						"install"=>$_POST["activatedMonth"]
	);
	
	// new  start
	$monthary=array();
	/*for($y=1; $y<=$m; $y++){
		$monthary[]=$y;
		
	}
	$monthAll=implode(",",$monthary);
	*/
	//echo $monthAll;
	
	$recData=array(	"page_id"=>"recepitNew",
						"idno"=>$_GET["id"],
						"udate"=>$_POST["select_date"],
						
						"type"=>"fee",
						"paytype"=>"classfee",
						"class"=>$_POST["cls"],
						"total"=>$_POST["paytotalMoth"],
						
						"install"=>$_POST["activatedMonth"]
	);
			
//$url=array();
/*
	foreach($recData as $key=>$val){
		$url[]=$key."=".$val;
	}*/
//$rrid=array(); 
	//print_r($arraData);exit;
	//$sid=$_REQUEST['student_id'];
	 // $compURL="print/?".implode("&",$url);
	
	
	
	// new end 

	
      $tution=$db->getRow("SELECT * from installment  WHERE idno='$id' and session='".$_SESSION["admin"]["session"]."'" );

		for($x=1; $x<=$m; $x++){
		
		// tution fee pay start
if(!empty($tution[i.$x])){
		if(empty($tution[ip.$x])){
			$monthary[]=$x;
			if(!empty($total)){
				$monthary[]=$x;
			if($tution[i.$x]>=$total){
				
				//echo 1;
				
				$rest_data1=$tution[i.($x+1)]+$tution[i.$x]-$total;
				$tution_inp= array(ip.$x=>$total, i.($x+1)=>$rest_data1);
				//$reff_receipt["amount"]=$total;
				$recept="fee-tution";
				$recData[$recept]+=$total;
				$reff_receipt=array(				                   
									"type"=>"fee",
									"inst_id"=>"$x",
									"amount"=>$total,									
									"idno"=>$_GET["id"],
									"session"=>$_SESSION["admin"]["session"]
									);
									
													
					$insAry=array( "ip".($x)=>$total);
					$given=$total;			
				$rest_data='';
				
			$total= $rest_data; 	
			}
			if($tution[i.$x]<$total){
				
				$rest_data=$total-$tution[i.$x];
				$tution_inp= array(ip.$x=>$tution[i.$x]);
				//$reff_receipt["amount"]=$tution[i.$x];
				$recept="fee-tution";
				$recData[$recept]+=$tution[i.$x];
				
					$reff_receipt=array(				                   
									"type"=>"fee",
									"inst_id"=>"$x",
									"amount"=>$tution[i.$x],
									"idno"=>$_GET["id"],
									"session"=>$_SESSION["admin"]["session"]
									);
									
					$insAry=array( "ip".($x)=>$tution[i.$x]);				
									
					$given=$tution[i.$x];			
			 $total= $rest_data;				 
			}
				
				$inup=$db->updateAry("installment",$tution_inp," where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
				
					installment_time($_GET["id"],"ip".$x,$_POST["select_date"]);
						
                     $reff_receipt["school_id"]=$_SESSION["admin"]["school_id"];
					$reff_receipt["added_by"]=$_SESSION["admin"]["uid"];
					$reff_receipt["date"]=$_POST["select_date"];
					
					$rrid[].=$db->insertAry("reff_receipt",$reff_receipt);
					
				
					deposit($given,$_GET["id"],json_encode($insAry),"fee","Student fee Payment in installment type");	
					
	//$e=$total-$rest_data;
		} 
			//if($e=='0') { break; exit(); }
		}
}
		// tution fee pay end
		
		
		// bus fee pay start
  if(!empty($tution[b.$x])){
		   if(empty($tution[bp.$x])){
			
			//echo 3;
			if(!empty($total)){
				$monthary[]=$x;
			if($tution[b.$x]>=$total){
				
				//echo 1;
				$after_bus_rest_data=$tution[b.($x+1)]+$tution[b.$x]-$total;
				$tution_inp= array(bp.$x=>$total, b.($x+1)=>$after_bus_rest_data);
				//$reff_receipt["amount"]=$total;
				
				$recept="fee-bus";
				$recData[$recept]+=$total;
				
				$reff_receipt=array(				                   
									"type"=>"busfee",
									"inst_id"=>"$x",
									"amount"=>$total,									
									"idno"=>$_GET["id"],
									"session"=>$_SESSION["admin"]["session"]
									);
									
													
					$insAry=array( "bp".($x)=>$total);
					$given=$total;			
				$rest_data='';
				
			$total= $rest_data; 					
			}
			if($tution[b.$x]<$total){
				
				$after_bus_rest_data=$total-$tution[b.$x];
				$tution_inp= array(bp.$x=>$tution[b.$x]);
				//$reff_receipt["amount"]=$tution[i.$x];
				$recept="fee-bus";
				$recData[$recept]+=$tution[b.$x];
					$reff_receipt=array(				                   
									"type"=>"busfee",
									"inst_id"=>"$x",
									"amount"=>$tution[b.$x],
									"idno"=>$_GET["id"],
									"session"=>$_SESSION["admin"]["session"]
									);
									
					$insAry=array( "bp".($x)=>$tution[b.$x]);				
									
					$given=$tution[b.$x];	
					
                $total=$after_bus_rest_data;				
				
			}
				
				$inup=$db->updateAry("installment",$tution_inp," where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."'");
				
					installment_time($_GET["id"],"bp".$x,$_POST["select_date"]);
						
                     $reff_receipt["school_id"]=$_SESSION["admin"]["school_id"];
					$reff_receipt["added_by"]=$_SESSION["admin"]["uid"];
					$reff_receipt["date"]=$_POST["select_date"];
					$rrid[].=$db->insertAry("reff_receipt",$reff_receipt);
					
				
					deposit($given,$_GET["id"],json_encode($insAry),"bus","Student bus fee Payment in installment type");	
			$e=	$total-$after_bus_rest_data;	
			}
			
				//if($e=='0') { break; exit(); }
		 }
		}		
		
		// bus fee end
		
		
		
// other fee start..........
				
		$aryForm=$db->getRow("SELECT * FROM student WHERE school_id='".$_SESSION["admin"]["school_id"]."' and idno='$id'");
		
		$other_fee_name=$db->getRows("SELECT  id,name from otherfee_structure  WHERE class='$clas' and month='$x' and (otype='$id' or otype='$aryForm[stype]' or otype='') and session='".$_SESSION["admin"]["session"]."' ");
		
				
		$other_name=$db->getRows(" SELECT @serial := @serial+1 AS serial_number, id,name from otherfee_structure,(SELECT @serial:= 0) AS s  WHERE class='$clas' and (otype='$id' or otype='$aryForm[stype]' or otype='') and session='".$_SESSION["admin"]["session"]."' " );
						
		$n=0;
		$a= array();
		foreach($other_name as $name){
			$n++;
			$a[]=$name[name];
		}		
		foreach($other_fee_name as $other_name){
		foreach($a as $key=>$value){
			
			if($value==$other_name[name]){
				$n= $key+1;
			}
		}							
			
	$total_other=$db->getVal("SELECT COALESCE(sum(fee),0) as result from otherfee_structure  WHERE class='$clas' and name='$other_name[name]'  and (otype='$id'  or otype='$aryForm[stype]' or otype='') and session='".$_SESSION["admin"]["session"]."' ");
	
	
	$total_other_discount=$db->getVal("SELECT COALESCE(sum(discount),0) as result from otherfee_discount  WHERE  idno='$id' and other_id='$other_name[id]'  and month='$x'   and session='".$_SESSION["admin"]["session"]."' ");
	
			
	$total_other_given=$db->getVal("SELECT COALESCE(sum(fine),0) as result from installment_fine  WHERE  idno='$id' and reasion ='$other_name[name]'   and session='".$_SESSION["admin"]["session"]."' ");
				
			  $final= $total_other-$total_other_discount-$total_other_given;
							
					 $num=$n*2;
					
			if(!empty($total)){
			if(!empty($final)){
				
				if(empty($total_other_given)){
					$monthary[]=$x;
					
					// if given is empty then data inserted in both table installment_fine & installment_time
					$udate=$_POST["select_date"];
					
					installment_time($id,"other".$num."_detail",$_POST["select_date"]);
									
				if($final>=$total){
					$recept="fee-".$other_name[name];
				$recData[$recept]+=$total;
					
				$insAry=array(  "ins_name"	=>	$num."-otherfee",
					"fine"		=>	$total,
					"reasion"	=>	$other_name[name],
					'udate'		=>  $_POST["select_date"],
					"status"	=>	"1",
					"idno"		=>	$id
					
				);
				
				$insAry["school_id"]=$_SESSION["admin"]["school_id"];
				$insAry["added_by"]=$_SESSION["admin"]["uid"];
				$insAry["session"]=$_SESSION["admin"]["session"];
				
				$inup=$db->insertAry("installment_fine",$insAry);
				
				// reff receipt start
				
				$reff_receipt=array("amount"=>$total,
										"type"=>$other_name[name],
										"idno"=>$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"];
						$reff_receipt["date"]=$_POST["select_date"];
						$rrid[].=$db->insertAry("reff_receipt",$reff_receipt);
				// reff receipt end 
				
				deposit($total,$id,$inup,"other".$num."_fee","Student Other fee ".$other_name[name]);
				$rest_data='';
				
			$total= $rest_data;
				
				}
				
				if($final<$total){
					
			    $recept="fee-".$other_name[name];
				$recData[$recept]+=$final;
				
					$after_other_rest_data=$total-$final;
				$insAry=array(  "ins_name"	=>	$num."-otherfee",
					"fine"		=>	$final,
					"reasion"	=>	$other_name[name],
					'udate'		=>  $_POST["select_date"],
					"status"	=>	"1",
					"idno"		=>	$id
					
				);
				$insAry["school_id"]=$_SESSION["admin"]["school_id"];
				$insAry["added_by"]=$_SESSION["admin"]["uid"];
				$insAry["session"]=$_SESSION["admin"]["session"];
				
				$inup=$db->insertAry("installment_fine",$insAry);
				
				// reff receipt start
				
				$reff_receipt=array("amount"=>$final,
										"type"=>$other_name[name],
										"idno"=>$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"];
						$reff_receipt["date"]=$_POST["select_date"];
						$rrid[].=$db->insertAry("reff_receipt",$reff_receipt);
				// reff receipt end 
				
				deposit($final,$id,$inup,"other".$num."_fee","Student Other fee ".$other_name[name]);
				
				$total=$after_other_rest_data;
				}
			 }
			 else{
				 	$monthary[]=$x;			
				if($final>=$total){
					
					$recept="fee-".$other_name[name];
				$recData[$recept]+=$total;
				
				$insAry=array(  "ins_name"	=>	$num."-other",
					"fine"		=>	$total,
					"reasion"	=>	$other_name[name],
					'udate'		=>  $_POST["select_date"],
					"status"	=>	"1",
					"idno"		=>	$id
					
				);
				$insAry["school_id"]=$_SESSION["admin"]["school_id"];
				$insAry["added_by"]=$_SESSION["admin"]["uid"];
				$insAry["session"]=$_SESSION["admin"]["session"];
				
				$inup=$db->insertAry("installment_fine",$insAry);
								
				// reff receipt start
				
				$reff_receipt=array("amount"=>$total,
										"type"=>$other_name[name],
										"idno"=>$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"];
						$reff_receipt["date"]=$_POST["select_date"];
						$rrid[].=$db->insertAry("reff_receipt",$reff_receipt);
				// reff receipt end 
				deposit($total,$id,$inup,"other".$num."_fee","Student Other fee ".$other_name[name]);
				
				$rest_data='';				
			$total= $rest_data;				
				}
				
				if($final<$total){
					
				$recept="fee-".$other_name[name];
				$recData[$recept]+=$final;
					
					$after_other_rest_data=$total-$final;
				$insAry=array(  "ins_name"	=>	$num."-other",
					"fine"		=>	$final,
					"reasion"	=>	$other_name[name],
					'udate'		=>  $_POST["select_date"],
					"status"	=>	"1",
					"idno"		=>	$id
					
				);
				$insAry["school_id"]=$_SESSION["admin"]["school_id"];
				$insAry["added_by"]=$_SESSION["admin"]["uid"];
				$insAry["session"]=$_SESSION["admin"]["session"];
				
				$inup=$db->insertAry("installment_fine",$insAry);
								
				// reff receipt start				
				$reff_receipt=array("amount"=>$final,
										"type"=>$other_name[name],
										"idno"=>$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"];
						$reff_receipt["date"]=$_POST["select_date"];
						$rrid[].=$db->insertAry("reff_receipt",$reff_receipt);
				// reff receipt end 
				deposit($final,$id,$inup,"other".$num."_fee","Student Other fee ".$other_name[name]);
				
				
				$total=$after_other_rest_data;
				}
				$e =$total-$after_other_rest_data;
				//if($e=='0') { //break; exit(); }
			 }		 
			}
			}
		}
		
		// other fee end
	 }
	 //if($e=='0') { break; exit(); }
	 
	}
}

$recData['amount']=$_POST["payNow1"];;
$recData['idno']=$idd;

 $rr1= implode(",",  $rrid);
//echo '<br>';
$select_tution= $db->getVal("select  sum(amount) as amount1 from reff_receipt where id in($rr1) and type='fee' GROUP by type order by id  ");
$select_bus= $db->getVal("select  sum(amount) as amount1 from reff_receipt where id in($rr1) and type='busfee' GROUP by type order by id  ");
$recData['fee-tution']=$select_tution;
$recData['fee-bus']=$select_bus;

$select_other= $db->getRows("select type, sum(amount) as amount1 from reff_receipt where id in($rr1) and type!='busfee' and type!='fee' GROUP by type order by id  ");

foreach($select_other as $select_other1){
	
	$d="fee-".$select_other1[type];
	$recData[$d]=$select_other1["amount1"];
	
	
}
//print_r($recData); die;
	foreach($recData as $key=>$val){
		
		$url[]=$key."=".$val;
	}
		
	//print_r($arraData);exit;
	//$sid=$_REQUEST['student_id'];
	   $compURL="print/?".implode("&",$url);
	
	$mo="&month=".implode(",",array_unique($monthary));
	
	$compURL=$compURL.$mo;
	
	$rid="&rrid=rrid-".implode("-",$rrid);
	$_SESSION["url"]=$compURL.$rid;
	redirect();
	//die;
}
	
elseif(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
						);
						$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
						);
						$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;
					
					$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"]."'");
					$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;
					$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
						);
						
						$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='?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='?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: 32%;
	display: inline-block;
	vertical-align: top;
	border-left: 5px 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>
                <div style="float:right; margin-top:5px;">
               		 <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>
            <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">Account No</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>-->
				 <form method="post" action="" id="paybymonth" >
				<!--<input type="text" name="select_date" id="fdate<?php echo $i ?>" class="fdate<?php echo $i ?> datepicker span12" value="<?php echo date("Y-m-d H:i:g"); ?>" />-->
				
				 Payment detail</h3>
                <div style="float:right; margin-top:5px">
               
                	<!--<select name="MyActivatedMonth" style="position:absolute" id="MyActivatedMonth" onchange="getTotalMonthCost()"> -->
			

			
		<select name="activatedMonth" style="position:absolute" id="myMonth"  onchange="mycost(<?php echo $_GET[id] ?> )" >
		
                    	<?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="hidden" value="<?php echo $aryForm["stype"] ?>" name="stu_type" id="stu_type" />
					
                    <input type="hidden" value="<?php echo $aryForm["htype"] ?>" name="h_stu_type" id="h_stu_type" />
                    <input type="hidden" value="<?php echo $aryForm["idno"] ?>" name="stu_id" id="stu_id" />
                    <input type="hidden" value="<?php echo $aryForm["bpl"] ?>" name="bpl" id="bpl" />
					
                    <input type="text"  name="paytotalMoth" id="paytotalMoth" value='0'  /> 
					
				   <!--<input type="text" readonly="readonly" onload="default_month(<?php echo $_GET[id] ?> )" name="paytotalMoth" value="<?php  echo $cmonth ?>" />-->
                   <!-- <input type="text" name="payNow" value="<?php  echo $_POST["payNow"] ?>" /> -->
					 <input type="text" name="payNow1" value="<?php  echo $_POST["payNow1"] ?>" />
                    <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>
                
                </div>
                </form>
				</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"]?>'/>
                                    
                                <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"  type="text" id="fee<?php echo $i.$aryForm["idno"] ?>" 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>'; ?>
								<?php 
								$id4=$aryForm["idno"];
								//if($aryInstall[$iip]>0)
								echo '<a style="float:left" href="javascript:;"  onclick="update_tution(\''.$i.'\',\''.$id4.'\')"><button type="button" class="btn btn-info">Update</button></a>';
							if(!empty($aryInstall[$iip]))
							echo '<a style="float:left" href="javascript:;"  onclick="delete_tution(\''.$i.'\',\''.$id4.'\')"><button type="button" class="btn btn-danger">Delete</button></a>';
							?>
								</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'");?>
                                <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"]?>'/>
                                <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"  type="text" id="busfee<?php echo $i.$aryForm["idno"] ?>" 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>'; ?>
								
								<?php 
								$id4=$aryForm["idno"];
								//if($aryInstall[$iip]>0)
								echo '<a style="float:left" href="javascript:;"  onclick="update_bus(\''.$i.'\',\''.$id4.'\')"><button type="button" class="btn btn-info">Update</button></a>';
							if(!empty($aryInstall[$iip]))
							echo '<a style="float:left" href="javascript:;"  onclick="delete_bus(\''.$i.'\',\''.$id4.'\')"><button type="button" class="btn btn-danger">Delete</button></a>';
							?>
								</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 $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>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 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.$aryForm["idno"]; ?>" <?php if($name!="Back_dues" AND strpos($name, "Latefine_")===false){ ?> 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+$fineAry["fine"]; ?>" 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 //} ?>
                      
					  <?php 
								$id4=$aryForm["idno"];
								//if($aryInstall[$iip]>0)
								echo '<a style="float:left" href="javascript:;" id="saveother'.$i.'" onclick="update_back_dues(\''.$i.'\',\''.$name.'\',\''.$id4.'\')"><button type="button" class="btn btn-info">Update</button></a><a style="float:left" href="javascript:;" id="saveother'.$i.'" onclick="delete_back_dues(\''.$i.'\',\''.$name.'\',\''.$id4.'\')"><button type="button" class="btn btn-danger">Delete</button></a>';
							?>
					  
                        </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 $i; ?>" 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 $i; ?>" 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();
					 }?>
                  	
                  
                 
                 
                 <?php //echo $db->getErMsg().$db->getLastQuery(); ?>
          </div>
            </div>
         </div>
		 
<?php
 $sibling=$db->getVal("SELECT  sibling from student  WHERE idno='".$_REQUEST[id]."' and session='".$_SESSION["admin"]["session"]."' ");

$sibling1= array_filter(explode(',',$sibling));

foreach($sibling1 as $sibling2){ 


$aryForm=$db->getRow("SELECT * FROM student WHERE school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$sibling2."'");
$_GET["id"]=$aryForm['idno'];
?>
	
	<div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Student detail</h3>
                
            </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="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"]?>'/>
                                    
                                <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"  type="text" id="fee<?php echo $i.$aryForm["idno"]; ?>" 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>'; ?>
								<?php 
								$id4=$aryForm["idno"];
								//if($aryInstall[$iip]>0)
								echo '<a style="float:left" href="javascript:;"  onclick="update_tution(\''.$i.'\',\''.$id4.'\')"><button type="button" class="btn btn-info">Update</button></a>';
							if(!empty($aryInstall[$iip]))
							echo '<a style="float:left" href="javascript:;"  onclick="delete_tution(\''.$i.'\',\''.$id4.'\')"><button type="button" class="btn btn-danger">Delete</button></a>';
							?>
								
								</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'");?>
                                <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"]?>'/>
                                <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"  type="text" id="busfee<?php echo $i.$aryForm["idno"] ?>" 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>'; ?>
								<?php 
								$id4=$aryForm["idno"];
								//if($aryInstall[$iip]>0)
								echo '<a style="float:left" href="javascript:;"  onclick="update_bus(\''.$i.'\',\''.$id4.'\')"><button type="button" class="btn btn-info">Update</button></a>';
							
							if(!empty($aryInstall[$iip]))
							echo '<a style="float:left" href="javascript:;"  onclick="delete_bus(\''.$i.'\',\''.$id4.'\')"><button type="button" class="btn btn-danger">Delete</button></a>';
							?>
								
								</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 $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 sum(fine) from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."' and reasion='".$iPro["name"]."' and ins_name like '%otherfee%'");
							$paid_Fee=$db->getVal("select sum(fine) from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."' and reasion='".$iPro["name"]."' ");
							
							
							
							$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.$aryForm["idno"]; ?>" <?php if($name!="Back_dues" AND strpos($name, "Latefine_")===false){ ?> 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+$fineAry["fine"]; ?>" 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 //} ?>

                         <?php 
								$id4=$aryForm["idno"];
								//if($aryInstall[$iip]>0)
								echo '<a style="float:left" href="javascript:;" id="saveother'.$i.'" onclick="update_back_dues(\''.$i.'\',\''.$name.'\',\''.$id4.'\')"><button type="button" class="btn btn-info">Update</button></a><a style="float:left" href="javascript:;" id="saveother'.$i.'" onclick="delete_back_dues(\''.$i.'\',\''.$name.'\',\''.$id4.'\')"><button type="button" class="btn btn-danger">Delete</button></a>';
							?>
								                       
                        </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 $i; ?>" 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 $i; ?>" 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();
					 }?>
                  	
                  
                 
                 
                 <?php //echo $db->getErMsg().$db->getLastQuery(); ?>
          </div>
            </div>
         </div>
	 
<?php }  ?>
		 
    </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("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();
			}
		});
	}
}
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_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(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/calendar11.png",
		  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

// default month code start .........


window.onload = default_month();

function default_month(id){
	
	var id= $("#stu_id").val();
	var bpl= $("#bpl").val();
	 
	 
	 
	
	
	var month=$("#myMonth").val();
	var cls=$("#cls").val();
	var type=$("#stu_type").val();
   //alert(month);
	
	//alert (id);
	//$("#paytotalMoth").val(month);

var html = '<table border="2" id="mytable" style="text-align:center; width:400px" >';
var obj = {
    "1":"Apr",
   
    "2":"May",
    "3":"Jun",
    "4":"July",
    "5":"Aug",
    "6":"Sep",
    "7":"Oct",
    "8":"Nov",
    "9":"Dec",
    "10":"January",
    "11":"Feb",
   "12":"Mar"
};


//var number = 9;
var tbody = $("#mytable tbody");

if (tbody.children().length == 0) {

if(month in obj){
	
	
		for(i=1; i<=month; i++){
   var month1=obj[i];
   
 
               
   html += '<tr  style="width:400px"id='+i+'  ><td border="0" style="width:200px" colspan="2" >' +month1+ '</td></tr><tr  style="width:400px"id=fee'+i+'  ></tr><tr  style="width:400px"id=val'+i+'  ></tr>';
      
   } 
  
  }
}
	 html += '</table>';
 $("#feedetailDiv").append(html);



	
	
	$.post( "ajax.php", { type: "totalcostpermonth" ,month: month,bpl:bpl, id:id,cla:cls,stu_type:type  } , function( data ) {
	  			
     $("#paytotalMoth").val(data);
	 
	 	
				
	});
	
	
}

// default month code end

///'............
function mycost(id){
	//alert(1);
	//document.getElementById("feedetailDiv").innerHTML.reload;
	$("#mytable").empty();
	var udetail=$("#userdetails").html();
	//$("#appendDiv").remove();
	//alert(1);
	//$('#userdetails').appendTo('#feedetailDiv');
	//var htmlDisplay="<div>"+udetail+"</div>";
	var bpl= $("#bpl").val();
	var month=$("#myMonth").val();
	var cls=$("#cls").val();
	var type=$("#stu_type").val();
   //alert(month);
	var id= id;
	//alert (id);
	var html = '<table border="2" id="mytable" style="text-align:center; width:670px" >';
var obj = {
    "1":"Apr",
   
    "2":"May",
    "3":"Jun",
    "4":"July",
    "5":"Aug",
    "6":"Sep",
    "7":"Oct",
    "8":"Nov",
    "9":"Dec",
    "10":"January",
    "11":"Feb",
   "12":"Mar"
};

//var number = 9;
var tbody = $("#mytable tbody");

if (tbody.children().length == 0) {

if(month in obj){
	
	
		for(i=1; i<=month; i++){
   var month1=obj[i];
   
               
   html += '<tr  style="width:400px"id='+i+'  ><td border="0" style="width:200px" colspan="2" >' +month1+ '</td></tr><tr  style="width:400px"id=fee'+i+'  ></tr><tr  style="width:400px"id=val'+i+'  ></tr>';
      
   } 
  
  }
}
	 html += '</table>';
 $("#feedetailDiv").append(html);
  
	
	//$("#feedetailDiv").html(htmlDisplay);
	
	$.post( "ajax.php", { type: "totalcostpermonth" ,month: month,bpl:bpl, id:id,cla:cls,stu_type:type  } , function( data ) {
	  	
		//alert(data);
		
     $("#paytotalMoth").val(data);
	 
	 	// $("#feedetailDiv").append(html);
				
	});
	
}

// default month hostel start
window.onload = default_month_hostel();

function default_month_hostel(){
	var id= $("#stu_id").val();
	var month=$("#myMonth1").val();
	
	var cls=$("#cls").val();
	var type=$("#h_stu_type").val();
   //alert(type);
	//alert(type);
	//alert (id);
	var html = '<table border="2" id="mytable_h" style="text-align:center; width:670px" >';
  var obj = {
    "1":"Apr",
   
    "2":"May",
    "3":"Jun",
    "4":"July",
    "5":"Aug",
    "6":"Sep",
    "7":"Oct",
    "8":"Nov",
    "9":"Dec",
    "10":"January",
    "11":"Feb",
   "12":"Mar"
};

//var number = 9;
var tbody = $("#mytable_h tbody");

if (tbody.children().length == 0) {
//alert(1);
if(month in obj){
	
	
		for(i=1; i<=month; i++){
   var month1=obj[i];
   
 //alert(1);
               
   html += '<tr  style="width:400px"id='+i+'  ><td border="0" style="width:200px" colspan="2" >' +month1+ '</td></tr><tr  style="width:400px"id=fee_h'+i+'  ></tr><tr  style="width:400px"id=val_h'+i+'  ></tr>';
      
   } 
  
  }
}
	 html += '</table>';
 $("#feedetailDiv1").append(html);
	
	$.post( "ajax.php", { type: "totalhostelpermonth" ,month: month, id:id,cla:cls,stu_type:type  } , function( data ) {
	  	
	
		
     $("#paytotalMoth1").val(data);
	 
	 		
	});	
		
}


// hostel on select month
function mycost1(id){
	$("#mytable_h").empty();
	var udetail=$("#userdetails").html();
	
	var month=$("#myMonth1").val();
	var cls=$("#cls").val();
	var type=$("#h_stu_type").val();
   //alert(type);
	var id= id;
	//alert (id);
	var html = '<table border="2" id="mytable_h" style="text-align:center; width:670px" >';
var obj = {
    "1":"Apr",
   
    "2":"May",
    "3":"Jun",
    "4":"July",
    "5":"Aug",
    "6":"Sep",
    "7":"Oct",
    "8":"Nov",
    "9":"Dec",
    "10":"January",
    "11":"Feb",
   "12":"Mar"
};

//var number = 9;
var tbody = $("#mytable_h tbody");

if (tbody.children().length == 0) {

if(month in obj){
	
	
		for(i=1; i<=month; i++){
   var month1=obj[i];
   
 
               
   html += '<tr  style="width:400px"id='+i+'  ><td border="0" style="width:200px" colspan="2" >' +month1+ '</td></tr><tr  style="width:400px"id=fee_h'+i+'  ></tr><tr  style="width:400px"id=val_h'+i+'  ></tr>';
      
   } 
  
  }
}
	 html += '</table>';
 $("#feedetailDiv1").append(html);
	
	$.post( "ajax.php", { type: "totalhostelpermonth" ,month: month, id:id,cla:cls,stu_type:type  } , function( data ) {
	  	
	
		
     $("#paytotalMoth1").val(data);
	 
	 		
	});	
}

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" || 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]);
					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>';
		}
    $("#paybymonth").append("<div id='appendDiv'>"+htmlCode+"</div>")
	//$("#feedetailDiv").html(htmlDisplay+"<hr/>Total : "+total)
	$("#feedetailDiv").html(htmlDisplay)
	//$("#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)
	$("#feedetailDiv1").html(htmlDisplay)
	//$("#paytotalMoth1").val(total);
	//alert(total+"Second");
}

//window.onload = showDetail();
function showDetail(id,idno){
	
		var month=$("#myMonth").val();
		var bpl= $("#bpl").val();
		//alert(month);
		
        var month_h=$("#myMonth1").val();
		var id1 = $("#stu_id").val();

		var c=$("#cls").val();
		
//alert(id1);
	
	    var type1=$("#stu_type").val();
	    var type_h=$("#h_stu_type").val();
		
	// withou hostel start
	
	
	var html = '<table border="2" id="mytable" style="text-align:center; width:670px" >';
var obj = {
    "1":"Apr",
   
    "2":"May",
    "3":"Jun",
    "4":"July",
    "5":"Aug",
    "6":"Sep",
    "7":"Oct",
    "8":"Nov",
    "9":"Dec",
    "10":"January",
    "11":"Feb",
   "12":"Mar"
};

//var number = 9;
var tbody = $("#mytable tbody");

if (tbody.children().length == 0) {

if(month in obj){
	
	
		for(i=1; i<=month; i++){
   var month1=obj[i];
   
               
   html += '<tr  style="width:400px"id='+i+'  ><td border="0" style="width:200px" colspan="2" >' +month1+ '</td></tr><tr  style="width:400px"id=fee'+i+'  ></tr><tr  style="width:400px"id=val'+i+'  ></tr>';
      
   } 
  
  }
}
	 html += '</table>';
 $("#feedetailDiv").append(html);
	
	// without hostel end
		
		
		
	 //$( "#feedetailDiv" ).load();
	$.post( "ajax.php", { type: "mydata" ,month2: month,bpl:bpl, id2:id1, cl2:c, type2:type1 } , function( data ) {
	  	
		//alert(data);
		 
		 $("#feedetailDiv").append(data);
		
					
	});
	
		// for hostel start
		
		
		var html = '<table border="2" id="mytable_h" style="text-align:center; width:670px" >';
  var obj = {
    "1":"Apr",
   
    "2":"May",
    "3":"Jun",
    "4":"July",
    "5":"Aug",
    "6":"Sep",
    "7":"Oct",
    "8":"Nov",
    "9":"Dec",
    "10":"January",
    "11":"Feb",
   "12":"Mar"
};

//var number = 9;
var tbody = $("#mytable_h tbody");

if (tbody.children().length == 0) {
//alert(1);
if(month in obj){
	
	
		for(i=1; i<=month; i++){
   var month1=obj[i];
   
 //alert(1);
               
   html += '<tr  style="width:400px"id='+i+'  ><td border="0" style="width:200px" colspan="2" >' +month1+ '</td></tr><tr  style="width:400px"id=fee_h'+i+'  ></tr><tr  style="width:400px"id=val_h'+i+'  ></tr>';
      
   } 
  
  }
}
	 html += '</table>';
 $("#feedetailDiv1").append(html);
		
		
		// for hostel end
	
	$.post( "ajax.php", { type: "mydata_hostal" ,month2: month_h, id2:id1, cl2:c, type2:type_h } , function( data ) {
	  	
		 
		 $("#feedetailDiv1").append(data);
						
	});
		
	//
			
	$( "#"+id ).dialog({
      resizable: false,
      modal: true,
	  height:400,
	  width:700,
      buttons: {
	   "Print": function() {
          printDiv('feedetailDiv')
		   //$( "#feedetailDiv" ).empty();
		   
        },
       Cancel: function() {
          $( this ).dialog( "close" );
		  
		  location.reload();
		  
		  
		  //$( "#feedetailDiv" ).empty();
		  //$( "#total" ).remove();
        }
      }
    });
}

function payother(id){
	var vl= $("#latefeeid"+id).val();
	var d=id;

	$.post("ajax.php",{
		type:"latefeeupdat",
	value:vl, id:d}, function(data){
alert(data);	
location.reload();	
	});
}

function update_tution(month,idno){
		var c= $("#fee"+month+idno).val();
		//alert(c); return false;
	$.post( "ajax.php", { 	type: "tution_update" ,	
								update: c,
								
								student_id:idno,
								month:month } , function( data ) {
									//alert(data);
																		
					if(data==0)
			{
				window.location='<?php echo curPageURL(); ?>';
			}
			else
			{
				alert(data);
				$("#saveother"+id).show();
			}
			
		});
	
}
function delete_tution(month,idno){
		var c= $("#fee"+month+idno).val();
		//alert(c); return false;
	$.post( "ajax.php", { 	type: "tution_delete" ,	
								update: c,
								
								student_id:idno,
								month:month } , function( data ) {
									//alert(data);
																		
					if(data==0)
			{
				window.location='<?php echo curPageURL(); ?>';
			}
			else
			{
				alert(data);
				$("#saveother"+id).show();
			}
			
		});
	
}

function update_bus(month,idno){
		var c= $("#busfee"+month+idno).val();
		//alert(c); return false;
	$.post( "ajax.php", { 	type: "bus_update" ,	
								update: c,
								
								student_id:idno,
								month:month } , function( data ) {
									//alert(data);
																		
					if(data==0)
			{
				window.location='<?php echo curPageURL(); ?>';
			}
			else
			{
				alert(data);
				$("#saveother"+id).show();
			}
			
		});
	
}

function delete_bus(month,idno){
		var c= $("#busfee"+month+idno).val();
		//alert(c); return false;
	$.post( "ajax.php", { 	type: "bus_delete" ,	
								update: c,
								
								student_id:idno,
								month:month }, function( data ) {
									//alert(data);
																		
					if(data==0)
			{
				window.location='<?php echo curPageURL(); ?>';
			}
			else
			{
				alert(data);
				$("#saveother"+id).show();
			}
			
		});
	
}


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

function delete_back_dues(id,name,idno){
	
	var c= $("#feeother"+id+idno).val();
	var name=name;
	
	$.post( "ajax.php", { 	type: "del_back_dues" ,	
								update: c,
								name:name,
								student_id:idno,
								id: id } , function( data ) {
									//alert(data);
																		
					if(data==0)
			{
				window.location='<?php echo curPageURL(); ?>';
			}
			else
			{
				alert(data);
				$("#saveother"+id).show();
			}
			
		});
		
}

</script>
<style>
.top-bar, .accordion .accordion-toggle{
	overflow:inherit !important;
	width: 96%;
	display:inline-block !important;
}
</style>