<?php
 session_start(); 

	if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}
	date_default_timezone_set("Asia/Kolkata");
	$mdate= date('Y-m-d H:i:s');
	
	include("connect.php");
	$umid = $_SESSION['umid'];
	
	$imid=$_POST['imid'];
	$stiqmid=$_POST['stiqmid'];
	
	$ptype=$_POST['ptype'];
	if($ptype == 'Branch' || $ptype == 'Country')
	{
	$packagemid=$_POST['packagemid'];
	$clgappmid =0;
	}else{
		$clgappmid = $_POST['clgappmid'];
		$packagemid =0;
	}
	$isremark=$_POST['isremark'];
	$pcurrencyrate=$_POST['pcurrencyrate'];
	$serviceoffer=$_POST['serviceoffer'];
	$servicefinalrate=$_POST['servicefinalrate'];
	$spaymenttype=$_POST['spaymenttype'];
	$servicepayamount=$_POST['servicepayamount'];
	$paycurrency=$_POST['paycurrency'];
	$paycurrencyvalue=$_POST['paycurrencyvalue'];
	
					
									
	
	$codaddedby=$_SESSION['umid'];
	$codaddedtype=$_SESSION['utype'];
	
	  $eve2 = "insert into res_inquiryservice_detail (imid,isaddedby,isaddedon,isupdatedby,isupdatedon,stiqmid,ispendingamount,isremark,packagemid,packagefees,serviceoffer,servicefinalrate,spaymenttype,servicepayamount,linkmid,ptype) values ($imid,$codaddedby,'$mdate',$codaddedby,'$mdate','$stiqmid','$servicefinalrate','$isremark','$packagemid','$pcurrencyrate','$serviceoffer','$servicefinalrate','$spaymenttype','$paycurrencyvalue','$clgappmid','$ptype')";

	if ($conn->query($eve2) === TRUE)
	{
		$isdid = $conn->insert_id;
		$eve1 = "INSERT INTO res_payments_detail (imid,isdid, paidamount,pdaddedon,pdaddedby,pdupdatedon,pdupdatedby,paycurrency,paycurrencyvalue) VALUES('$imid','$isdid','$paycurrencyvalue','$mdate','$codaddedby','$mdate','$codaddedby','$paycurrency','$paycurrencyvalue')";
		$re1 = mysqli_query($conn, $eve1);
		
		$eve3 = "select siprefferservice from res_studentinquiry_detail where stiqmid=$stiqmid and siprefferservice='Coaching'";
			$re3 = mysqli_query($conn, $eve3);
	
    if(mysqli_num_rows($re3) > 0)
	{
		$eve4 = "select booksetmid from res_packagewisebookset_detail where packagemid=$packagemid ";
		$re4 = mysqli_query($conn, $eve4);
	
    if(mysqli_num_rows($re4) > 0)
	{
		while($rt4 = mysqli_fetch_assoc($re4))
		{ 
			$booksetmid = $rt4['booksetmid'];
			$eve5 = "INSERT INTO res_booksettostudent_detail (imid,stiqmid,booksetmid,bssaddedon,bssaddedby) VALUES('$imid','$stiqmid','$booksetmid','$mdate','$umid')";
			
			$re5 = mysqli_query($conn, $eve5);
		}
	}
		
	}
		
		if($spaymenttype == 'Part Payment')
		{
			$prdate=date("d-m-Y",strtotime($_POST['prdate']));
			$prremark=$_POST['prremark'];
			 $eve2 = "INSERT INTO res_paymentreminder_master (imid,isdid, prdate,prremark,praddedon,praddedby,prupdatedon,prupdatedby) VALUES('$imid','$isdid','$prdate','$prremark','$mdate','$codaddedby','$mdate','$codaddedby')";
			
			$re2 = mysqli_query($conn, $eve2);
		}
		
	}
	
	
		
	
	$_SESSION['msg'] = "Inquiry Status Changed";
	header("Location: inquirydetail.php?id=$imid&tab=student_payment");

?>	