<?php
session_start(); 

	if(!isset($_SESSION['linkarisecrm']))
	{
		header('Location: index.php');
		return;
	}
	
	include("connect.php");
	include("removespecial.php");
	
	date_default_timezone_set("Asia/Singapore");
	 $cdate= date('Y-m-d');
	 $mdate= date('Y-m-d H:i:s');
	 $cdatetime= date('Y-m-d H:i:s');
	 
	 
	$brmid=$_SESSION['linkarisebranchid'];
	$lacrmumid=$_SESSION['linkariseumid'];
	$cmpmid=$_SESSION['linkarisecmpmid'];
	$lacrmusername = $_SESSION['linkariseufullname'];

	
	$partymid=$_POST['partymid'];
	$bookingmid=$_POST['receiptrefrenceid'];
	$receiptamount=$_POST['receiptamount'];
	$pendingamount=$_POST['pendingamount'];
	//$cmpmid=$_POST['cmpmid'];
	$receiptmode=$_POST['receiptmode'];
	$receiptdetail=removespecialchar($_POST['receiptdetail']);
$bookingtotalamount=0;
		$eve = "select * from res_booking_master where bookingmid=$bookingmid";
	    $re = mysqli_query($conn, $eve);
		while($rt = mysqli_fetch_assoc($re))
		{
				$bookingtotalamount=$rt['bookingtotalamount'];
		}
$pendingamount1=$pendingamount-$receiptamount;
	
			
	  $eve1 = "update res_booking_master set bookingadvanceamount = '$receiptamount',pendingamount='$pendingamount1' where bookingmid='$bookingmid' ";	
	
	if ($conn->query($eve1) === TRUE)
	{
		$last_id = $conn->insert_id;
		  $eve11 = "insert into res_bookingpayment_detail (bookingmid,bookingtotalamount,bookingreceivedamount,paymentmode,paymentremark,bookingpendingamount,cmpmid,paymentdate) VALUES($bookingmid,'$bookingtotalamount','$receiptamount','$receiptmode','$receiptdetail','$pendingamount1','$cmpmid','$cdate')";		
		$re11 = mysqli_query($conn, $eve11);
		$_SESSION['msg'] = "Record has been added successfully";
	}
	else
	{
		$_SESSION['msg1'] = "Error";
	}
	
	
	header('Location: paymentreceipt.php');
?>