<?php  
require "commonincludefiles.php";
if($_SESSION["cCompany_id"]!="" && isset($_SESSION["cCompany_id"]))
{
	$objVendorMgmt = new VendorMgmt();
	$AccountMasterMgmt = new AccountMasterMgmt();	
	$AccountGroupMgmt =new AccountGroupMgmt();
	
	
	$objVendorMgmt ->vendor_id          = $_REQUEST["vendor_id"] ;
	$objVendorMgmt ->vendor_orgname		= $_REQUEST['vendor_orgname'] ;
	$objVendorMgmt ->vendor_address		= $_REQUEST['vendor_address'] ;
	$objVendorMgmt ->district_id		= $_REQUEST['hiddendist_code'];
	$objVendorMgmt ->vendor_phone1      = $_REQUEST["vendor_phone1"] ;
	
	
	$objVendorMgmt ->vendor_phone2		= $_REQUEST['vendor_phone2'];
	$objVendorMgmt ->vendor_email		= $_REQUEST['vendor_email'];
	$objVendorMgmt ->vendor_website		= $_REQUEST['vendor_website'];
	$objVendorMgmt ->vendor_balance		= $_REQUEST['vendor_balance'];
	$objVendorMgmt ->vendor_baltype		= $_REQUEST['vendor_baltypehidden'];

	$objVendorMgmt ->vendor_cpname1			= $_REQUEST['vendor_cpname1'] ;
	$objVendorMgmt ->vendor_cpdesignation1	= $_REQUEST['hiddenvendor_cpdesignation1'];
	$objVendorMgmt ->vendor_cpmobile1       = $_REQUEST["vendor_cpmobile1"] ;
	$objVendorMgmt ->vendor_cpemail1		= $_REQUEST['vendor_cpemail1'] ;
	
	
	$objVendorMgmt ->vendor_tinno			= $_REQUEST['vendor_tinno'];
	$objVendorMgmt ->vendor_cstno			= $_REQUEST['vendor_cstno'] ;
	$objVendorMgmt ->vendor_servicetaxno	= $_REQUEST['vendor_servicetaxno'];
	$objVendorMgmt ->vendor_panno			= $_REQUEST['vendor_panno'] ;
	$objVendorMgmt ->vendor_remark			= $_REQUEST['vendor_remark'];
	
	$AccountMasterMgmt->account_groupid		= $AccountGroupMgmt->getIdByName('Purchase A/c');
	$AccountMasterMgmt->account_type		= 'Personal & Trading Account';
	$AccountMasterMgmt->account_name		= $_REQUEST['vendor_orgname'];
	$AccountMasterMgmt->account_opbalance	= $_REQUEST['vendor_balance'];
	$AccountMasterMgmt->account_crdr		= $_REQUEST['vendor_baltypehidden'];
	$AccountMasterMgmt->account_baldate   	= date("Y-m-d");
	$AccountMasterMgmt->account_address		= $_REQUEST['vendor_address'] ;
	$AccountMasterMgmt->account_phone		= $_REQUEST["vendor_phone1"] ;
	$AccountMasterMgmt->account_effect		= 'Profit & Loss';
	
	if($objVendorMgmt->vendor_id=="0" || $objVendorMgmt->vendor_id==""){
	
		$objVendorMgmt->add();
		$AccountMasterMgmt->add();	
									
	}
	else{
		
		$objVendorMgmt->edit();
		if($_REQUEST['account_id']!="")
		{
			$AccountMasterMgmt->account_id			=$_REQUEST['account_id'];
			$AccountMasterMgmt->edit();	
		}
		else
		{
			$AccountMasterMgmt->add();	
			
		}
	}						
	echo '{"success":"true","msg":""}';
}
else {
	echo '{"success":"false","msg":"session expiry"}';
}	         
?>
