<?php
 	session_start();

	if(!isset($_SESSION['linkarisecrm']))
	{
		header('Location: index.php');
		return;
	}
		$brmid=$_SESSION['linkarisebranchid'];
	$umid = $_SESSION['linakriseumid'];
$cmpmid=$_SESSION['linkarisecmpmid'];
	include("connect.php");
	include("removespecial.php");

	date_default_timezone_set("Asia/Kolkata");
	 $mdate1= date('Y-m-d');
	 $mdatetime= date('Y-m-d H:i:s');
	 $cdatetime= date('Y-m-d H:i:s');


	
	
	$lacrmumid=$_SESSION['linkariseumid'];
	if(isset($_POST['umid']))
	{
		$umid=$_POST['umid'];
	}
		
		$cmpname=$_POST['cmpname'];
		$address=removespecialchar($_POST['paddress']);
		
		$partyinqno=0;
		$last_id_partymid = '0';
		$partyno=0;
		$ccity="";
		$cstatecode="";
		$cpincode="";
		
		$partyno=0;
		$evemaxpartyno = "SELECT max(partyno) AS maxpartyinqno FROM res_party_master where partytype='Expense' and cmpmid=$cmpmid";
		$remaxpartyno = mysqli_query($conn, $evemaxpartyno);
		if(mysqli_num_rows($remaxpartyno) > 0)
		{
			while($rtmaxpartyno = mysqli_fetch_assoc($remaxpartyno))
			{
				$partyno=$rtmaxpartyno['maxpartyinqno'];
			}
		}
		$partyno=$partyno+1;		
		 $eve1 = "INSERT INTO res_party_master ( cmpmid,umid,partyno,partyname,partyaddress,partytype,partyaddedby,partyaddedon,partyupdatedby,partyupdatedon) VALUES
			('$cmpmid','$umid','$partyno','$cmpname', '$address','Expense','$lacrmumid','$cdatetime','$lacrmumid','$cdatetime')";	
		
		if ($conn->query($eve1) === TRUE)
		{
			$partymid = $conn->insert_id;
			
			$_SESSION['msg'] = "Record saved successfully";
		}
		else{
			$_SESSION['msg1'] = "Error";
		}
	
		header('Location: expense.php');
		

?>
