<?php
include("../db.php");
$ch=$_REQUEST["type"];$status="";
if($ch=="enquiry_data"){
	$where="";
	if(isset($_REQUEST["class"]))$where.=" AND class='".$_REQUEST["class"]."' ";
	if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="undefined")$where.=" AND section='".$_REQUEST["section"]."' ";
	$sql_limit="select * from enquiry where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $where and status=1 $where order by name";
	$aryList=$db->getRows($sql_limit);
	
	$aryPgAct=array("page_id"=>"pay_fees","action"=>"add");
	if(is_array($aryList) && count($aryList)>0)
	{
		$aryData='{ "aaData": [
		';
	    $i=0;
		foreach($aryList as $iList)
		{
			 $aryPgAct["id"]=$iList['idno'];
			$i++;
			//$aryData.='["'.$i.'",';
			$aryData.='["'.$i.'",';
			$aryData.='"'.POST($iList['name']).'",';
			$aryData.='"'.POST($iList['class']).'",';
			$aryData.='"'.POST($iList['fname']).'",';
			$aryData.='"'.POST($iList['mobile']).'",';
			$aryData.='"'.POST($iList['discount_mode']).'",';
			$aryData.='"';
			$aryPgAct['action']="add";
			$aryPgAct['page_id']="pay_fees";
			$aryData.='<a href=\''.URL_ADMIN_HOME.getQueryString($aryPgAct).'\'><button type=\'button\' class=\'btn btn-info\'>Pay Amount</button></a>';
			$aryPgAct['action']="edit";
			$aryPgAct['page_id']="enquiry";
			$aryData.='<a href=\''.URL_ADMIN_HOME.getQueryString($aryPgAct).'\'><button type=\'button\' class=\'btn btn-info\'>Edit</button></a>';
			$aryPgAct['action']="delete";
			$aryData.='<a href=\'javascript:;\' onclick=\'del(\"'.URL_ADMIN_HOME.getQueryString($aryPgAct).'\")\' class=\'confirmation\'><button type=\'button\' class=\'btn btn-danger\'>Delete</button></a>';
			
			$aryData.='"]';
			if($i!=count($aryList))$aryData.=",";
		 }
		 $aryData.="] }";	
		 echo $aryData;	
	}else{
		echo $db->getLastQuery().$db->getErMsg();
	}
}
elseif($ch=="enquiry_data1"){
	$where="";
	if(isset($_REQUEST["class"]))$where.=" AND class='".$_REQUEST["class"]."' ";
	if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="undefined")$where.=" AND section='".$_REQUEST["section"]."' ";
	$sql_limit="select * from enquiry where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $where and status=1 $where order by name";
	$aryList=$db->getRows($sql_limit);
	
	$aryPgAct=array("page_id"=>"pay_fees","action"=>"add");
	if(is_array($aryList) && count($aryList)>0)
	{
		$aryData='{ "aaData": [
		';
	    $i=0;
		foreach($aryList as $iList)
		{
			 $aryPgAct["id"]=$iList['idno'];
			$i++;
			//$aryData.='["'.$i.'",';
			$aryData.='["'.$i.'",';
			$aryData.='"'.POST($iList['name']).'",';
			$aryData.='"'.POST($iList['class']).'",';
			$aryData.='"'.POST($iList['fname']).'",';
			$aryData.='"'.POST($iList['mobile']).'",';
			$aryData.='"'.POST($iList['discount_mode']).'",';
			$aryData.='"';
			$aryPgAct['action']="add";
			$aryPgAct['page_id']="pay_fees";
			$aryData.='<a href=\''.URL_ADMIN_HOME.getQueryString($aryPgAct).'\'><button type=\'button\' class=\'btn btn-info\'>Pay Amount</button></a>';
			$aryPgAct['action']="edit";
			$aryPgAct['page_id']="enquiry";
			$aryData.='<a href=\''.URL_ADMIN_HOME.getQueryString($aryPgAct).'\'><button type=\'button\' class=\'btn btn-info\'>Edit</button></a>';
			//$aryPgAct['action']="delete";
			//$aryData.='<a href=\'javascript:;\' onclick=\'del(\"'.URL_ADMIN_HOME.getQueryString($aryPgAct).'\")\' class=\'confirmation\'><button type=\'button\' class=\'btn btn-danger\'>Delete</button></a>';
			
			$aryData.='"]';
			if($i!=count($aryList))$aryData.=",";
		 }
		 $aryData.="] }";	
		 echo $aryData;	
	}else{
		echo $db->getLastQuery().$db->getErMsg();
	}
}
elseif($ch=="checkreceptNo_enquiry"){
	$data=$db->getVal("select id from enquiry_receipt where id=".$_REQUEST["id"]." and type='".$_REQUEST["paytype"]."'");  
	if($data!="")
	echo "data already exit";
}
elseif($ch=="feeother"){
	if($_REQUEST["fee"]==""){
		echo "please enter other fee";
	}elseif($_REQUEST["given"]==""){
		echo "please enter fee";
	}elseif(!is_numeric($_REQUEST["given"])){
		echo "fee must in numeric format";
	}elseif($_REQUEST["given"]==0){
		echo "fee must greater than 0";
	}else{
		   $trn=$db->getVal("Select amount from transaction where detail like 'Enquiryfee%' and rid=".$_REQUEST["student_id"]." and session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and tid='".$_REQUEST["reasion"]."'");
		   $mobile=$db->getVal("Select mobile from enquiry where idno = '".$_REQUEST["student_id"]."'");
			if(!$trn) { 
			deposit($_REQUEST["given"],$_REQUEST["student_id"],$_REQUEST["reasion"],"cash","Enquiryfee ".$_REQUEST["fee"]);
			sms(mydetail("$mobile",$_REQUEST["student_id"],"student"),"Dear Parent, Amount of Rs.".$_REQUEST["given"]." is successfully deposited for ".$_REQUEST["reasion"]." in ".$LinksDetails["site_name"],"fee_submit");
			}
			else echo " You Can not pay with same name..! Please try again";
			
	}
}
elseif($ch=="DeleteInstallment"){
	$flg=0;$ftype="";$r="";$where="";
	$trn=$db->getVal("Select id from transaction where detail like 'Enquiryfee%' and rid=".$_REQUEST["idno"]." and session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and tid='".$_REQUEST["detail"]."'");
	$r=$db->getVal("Select id from enquiry_receipt where rrid=".$trn." and session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_REQUEST["idno"]."'");
	$ftype=$_REQUEST["paytype"];
	//echo $_REQUEST["udate"].$_REQUEST["detail"].$_REQUEST['amount'];exit;
	if($_REQUEST['amount']!="") {
			//print_r($ref);exit;
			$arr=array("idno"    =>$_REQUEST["idno"],
				   "class"   =>$_REQUEST["class"],
				   "paytype" =>$_REQUEST["paytype"],
				   "amount"  =>$_REQUEST["amount"],
				   "install" =>$_REQUEST["install"],
				    'status'  =>1,
				   "receipt_id"=>$r,
				   "detail"  =>$_REQUEST["detail"],
				  "school_id"=>$_SESSION["admin"]["school_id"],
				  "session"  =>$_SESSION["admin"]["session"],
				  "added_by" =>$_SESSION["admin"]["uid"]
				  
		 );
		 //print_r($arr);exit;
		 $flgIn=$db->insertAry("delete_report",$arr);
		 if(!is_null($flgIn))
			{$flg=1;}
	}//echo $db->getLastQuery();
  if($flg==1){
    if($_REQUEST["paytype"]=="enquiry"){
		$detail=$_REQUEST["install"]."-otherfee";
		$where="where detail like 'Enquiryfee%' and rid=".$_REQUEST["idno"]." and session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and amount='".$_REQUEST["amount"]."' and tid='".$_REQUEST["detail"]."'";
		//echo $where;exit;
		echo $res=$db->delete("transaction","$where");
	}
  }
}
?>