<?php
session_start(); 

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

	
	include("connect.php");
	
	date_default_timezone_set("Asia/Kolkata");
	$mdate1= date('Y-m-d H:i:s');
	$mdate2= date('d-m-Y');
	$mdate3= date('Y-m-d H:i:s');
	
	$lacrmusername = $_SESSION['lacrmusername'];
	$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','Edit Payment Out','$ipaddress','$userserver')";
	$re1 = mysqli_query($conn, $eve1);


	$paymentoutmid=$_POST['paymentoutmid'];
	$partymid=$_POST['partymid'];
	$outrefrenceid=$_POST['outrefrenceid'];
	$outamount=$_POST['outamount'];
	$outmode=$_POST['outmode'];
	$outdetail=$_POST['outdetail'];
	
	
		
	if($outamount!=0)
	{
		 $query = "update res_paymentout_master set partymid='$partymid', outrefrenceid='$outrefrenceid', outdate='$mdate3', outamount='$outamount', cmpmid= '$cmpmid', outmode='$outmode', outdetail='$outdetail',updatedby='$lacrmumid',updatedon='$mdate1' where paymentoutmid=$paymentoutmid";
		if ($conn->query($query) === TRUE)
		{
		 $eve41 ="update res_paymenttransaction_detail set partymid='$partymid',cmpmid='$cmpmid',paymenttype='Payment Out',paymentdate='$mdate3',paymentoutamount='$outamount',paymentmode='$outmode',paymentdetail='$outdetail',updatedby='$lacrmumid',updatedon='$mdate1' where Paymentrefid=$paymentoutmid";
			$re41 = mysqli_query($conn, $eve41); 
			
		}
			
		$_SESSION['msg'] = "Record has been updated successfully";	
	}
	else
	{
		$_SESSION['msg1'] = "Error";
	}
	header('Location: paymentout.php');
?>