<?php
 session_start(); 

	if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}
	
	include("connect.php");
	include("connectp.php");
	include("mylibrary.php");
	date_default_timezone_set("Asia/Kolkata");
	$mdate= date('Y-m-d H:i:s');
	$mdate2= date('d-m-Y H:i');
	
	
	
	
	
	$umid=$_SESSION['umid'];
	$pdstatus=checkvalidstring($_POST['pdstatus']);
	$papprovalremark=checkvalidstring($_POST['papprovalremark']);
	$pddid =$_POST['pddid'];
	
	
	 $eve2 = "update res_payments_detail set  papproveaddedon='$mdate',pdstatus='$pdstatus',papproveby='$umid',papprovalremark='$papprovalremark' where pddid=$pddid ";
	
	
	if ($conn->query($eve2) === TRUE)
	{
		if($pdstatus == 'Approved')
		{
			$eve23 = "select * from res_payments_detail where pddid=$pddid";
					$re23 = mysqli_query($conn, $eve23);
							while($rt23 = mysqli_fetch_assoc($re23))
							{
								$paidamount=$rt23['paidamount'];
								$isdid=$rt23['isdid'];
							}
								
			$eve2 = "update res_inquiryservice_detail set isreceviedamt= isreceviedamt+$paidamount,ispendingamount=ispendingamount-$paidamount where isdid=$isdid";
		$re2 = mysqli_query($conn, $eve2);
		
		 header("Location: paymentreciptpdf.php?id=$pddid");
		}else{
			header("Location: paymentlist.php");
		}
		
		
		
		
	}
	else
	{
		$_SESSION['msg1'] = "Error";
		header("Location: paymentlist.php");
	}
	
	
		
	
?>	