<?php 
//set_time_limit(60);

	require "commonincludefiles.php";
	require "data/sendingsms_studentpresant.php";
	
	if($_SESSION["VedantnrCollegeId"]!="" && isset($_SESSION["VedantnrCollegeId"]))
	{
		
		
		$qry_nam = "SELECT * FROM `cms_feesreceivemaster`
		WHERE `semester_id` ='".$_REQUEST['semester_hidden']."' 
		and `branch_id` = '".$_REQUEST['branch_hidden']."' 
		and `college_id` = '".$_SESSION["VedantnrCollegeId"]."' 
		and `year_id` = '".$_SESSION["VedantnrYearId"]."' 
		and `student_id` = '".$_REQUEST['student_hidden']."' 
		and `receive_amt` = '".$_REQUEST['receive_amt']."'
		and createdon = '".date('Y-m-d h:i:s')."' ;";
		
				
		$qry_res=dbQuery($qry_nam);
		$norec = dbRows($qry_res);
		
		
		$headids=json_decode(stripslashes($_REQUEST['headids']));
		//$recivedamt=json_decode(stripslashes($_REQUEST['recivedamt']));
		$recivedamt=$_REQUEST['receive_amt'];
		 
		$objStudentFeesRecMgmt  = new StudentFeesRecMgmt();
		$objStudentFeesRecMgmtdetail = new StudentFeesRecDetailMgmt();
		
		$objStudentFeesRecMgmt->cheque_id	= $_REQUEST["cheque_id"] ; 	
		$objStudentFeesRecMgmt->semester_id		= $_REQUEST['semester_hidden'];  
		$objStudentFeesRecMgmt->branch_id		= $_REQUEST['branch_hidden'];  
		$objStudentFeesRecMgmt->student_name		= $_REQUEST['student_name']; 
		
		
     	$objStudentFeesRecMgmt->fee_typehidden		= substr($_REQUEST['fee_typehidden'],0,1); 
    
	   	$objStudentFeesRecMgmt->receipt_no=$_REQUEST['receipt_no']; 
		
		$_SESSION["receiptno1"]= $objStudentFeesRecMgmt->receipt_no;
	  
		$_SESSION["student_id"]= $objStudentFeesRecMgmt->student_id;
	  
		$objStudentFeesRecMgmt->receipt_date  = $_REQUEST['receipt_date'];				
		$objStudentFeesRecMgmt->receive_amt	 	= $_REQUEST['receive_amt'];				
		$objStudentFeesRecMgmt->cheque_no  		= $_REQUEST['cheque_no'];				
		$objStudentFeesRecMgmt->bank_name 		= $_REQUEST['bank_name'];				
		$objStudentFeesRecMgmt->ifsc_code 		= $_REQUEST['ifsc_code'];		
		$objStudentFeesRecMgmt->student_rollno 		= $_REQUEST['student_gturegno'];			
		$objStudentFeesRecMgmt->latefee 		= $_REQUEST['latefee'];		
		if($norec == 0 && $_REQUEST["cheque_id"] == 0 && isset($_REQUEST["cheque_id"]) ){		
			
			sleep(rand(0, 10));
			
			if($_REQUEST['fee_typehidden'] != 'Transport')
			
			{
		//	$objStudentFeesRecMgmt->receipt_no= $objStudentFeesRecMgmt->getreciptNO();
			$_SESSION["receiptno1"]= $objStudentFeesRecMgmt->receipt_no;
		}
		else
		{
		//	$objStudentFeesRecMgmt->receipt_no= $objStudentFeesRecMgmt->getreciptNO1();
			$_SESSION["receiptno1"]= $objStudentFeesRecMgmt->receipt_no;
		}
		
			if($norec == 0)
			{
				
				$objStudentFeesRecMgmt->addcheque();
			}
			else
			{
				exit;
			}
			
			
		}
		else{ 
		  	$objStudentFeesRecMgmt -> edit();
		    $objStudentFeesRecMgmtdetail -> cheque_id = $_REQUEST["cheque_id"] ; 
			$objStudentFeesRecMgmtdetail -> delete();
		}

		//to Send SMS

				echo '{"success":"true","msg":"Data saved Successfully"}';exit;
			}
			else
			{
				echo '{"success":"false","msg":"session expiry"}';exit;
			}
			exit;
?>