<?php
 	session_start();

	if(!isset($_SESSION['linkarisecrm']))
	{
		header('Location: index.php');
		return;
	}
		$brmid=$_SESSION['linkarisebranchid'];
		$umid = $_SESSION['linkariseumid'];
		$cmpmid=$_SESSION['linkarisecmpmid'];
	include("connect.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');


	
	$idate=date("Y-m-d", strtotime($_POST['idate']));
	$istatus="Pending";
	$idetails=$_POST['idetails'];
	$isname=$_POST['isname'];
	
	$lacrmumid=$_SESSION['lacrmumid'];
	if(isset($_POST['umid']))
	{
		$umid=$_POST['umid'];
	}
		$cpname=$_POST['cpname'];
		$cmpname=$_POST['cmpname'];
		$cmobile=$_POST['pmobile'];
		$cemail=$_POST['pemail'];
		$address=$_POST['paddress'];
		$cstate=$_POST['state'];
		$partygstno=$_POST['gstno'];
		
		
	
		
		$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='Supplier' 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,partycity,partystate,partystatecode,partypincode,partygstno,partycpname,partymobile,partyemail,partytype,pyear,partyaddedby,partyaddedon,partyupdatedby,partyupdatedon) VALUES
			('$cmpmid','$umid','$partyno','$cmpname', '$address','$ccity','$cstate','$cstatecode','$cpincode', '$partygstno','$cpname','$cmobile','$cemail','Supplier','$byear','$lacrmumid','$cdatetime','$lacrmumid','$cdatetime')";		
		if ($conn->query($eve1) === TRUE)
		{
			$partymid = $conn->insert_id;
			
			$_SESSION['msg'] = "Record saved successfully";
		}
		else{
			$_SESSION['msg1'] = "Error";
		}
	
		header('Location: supplier.php');

?>
