<?php
session_start();

	if(!isset($_SESSION['linkarisecrm']))
	{
		header('Location: index.php');
		return;
	}
		$brmid=$_SESSION['linkariseumid'];

	include("connect.php");
	
	date_default_timezone_set("Asia/Kolkata");
	$mdate1= date('Y-m-d H:i:s');
	$mdate2= date('d-m-Y');
	
	$lacrmusername = $_SESSION['linkariseufullname'];
	$cmpmid=$_SESSION['linkarisecmpmid'];
	$brmid=$_SESSION['linkarisebranchid'];
	$umid = $_SESSION['linkariseumid'];
	
	
	$ipaddress = "";

	if (getenv('HTTP_CLIENT_IP'))
		$ipaddress = getenv('HTTP_CLIENT_IP');
	else if(getenv('HTTP_X_FORWARDED_FOR'))
		$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
	else if(getenv('HTTP_X_FORWARDED'))
		$ipaddress = getenv('HTTP_X_FORWARDED');
	else if(getenv('HTTP_FORWARDED_FOR'))
		$ipaddress = getenv('HTTP_FORWARDED_FOR');
	else if(getenv('HTTP_FORWARDED'))
		$ipaddress = getenv('HTTP_FORWARDED');
	else if(getenv('REMOTE_ADDR'))
		$ipaddress = getenv('REMOTE_ADDR');
	else
		$ipaddress = 'UNKNOWN';
	
	$userserver=$_SERVER['HTTP_USER_AGENT'];
	$eve1 = "insert into res_user_log (lid,mobile,lastupdatedtime,pagename,taskname,ipaddress,useragentdetail) values(NULL,'$lacrmusername','$mdate1','Payment Out','Delete Payment Out','$ipaddress','$userserver')";
	$re1 = mysqli_query($conn, $eve1);

	
	$payoutno=(int)mysqli_real_escape_string($conn,$_GET['id']);
	

	$paymentoutmid=0;
	
	$eve1 = "select * from res_paymentout_master where payoutno ='$payoutno' and cmpmid=$cmpmid";

	$re1 = mysqli_query($conn, $eve1);
																
	if(mysqli_num_rows($re1) > 0)

	{											
																	
		while($rt1 = mysqli_fetch_assoc($re1))
		{
		$paymentoutmid=$rt1['paymentoutmid'];
			
		}
																	 
	}

	$query="delete from res_paymentout_master where payoutno=$payoutno and cmpmid=$cmpmid";
	$result= mysqli_query($conn, $query) ;
		
	
	$query2="delete from res_paymenttransaction_detail where Paymentrefid=$paymentoutmid and paymenttype='Payment Out'";
	$result2= mysqli_query($conn, $query2) ;
		
	$_SESSION['msg'] = "Record deleted successfully";
	header('Location: paymentout.php');
	
?>