<?php  
require "commonincludefiles.php";
error_reporting(1);

if($_SESSION["cCompany_id"]!="" && isset($_SESSION["cCompany_id"]))
{
	//print_r($_REQUEST);
	
	$objCustomerMgmt = new CustomerMgmt();
	$AccountMasterMgmt = new AccountMasterMgmt();	
	$AccountGroupMgmt =new AccountGroupMgmt();
	
	$objCustomerMgmt ->customer_id          = $_REQUEST["customer_id"] ;
	$objCustomerMgmt ->customer_orgname		= $_REQUEST['customer_orgname'] ;
	$objCustomerMgmt ->customer_address		= $_REQUEST['customer_address'] ;
	$objCustomerMgmt ->district_id		    = $_REQUEST['hiddendist_code'];
	$objCustomerMgmt ->customer_phone1      = $_REQUEST["customer_phone1"] ;
	
	$objCustomerMgmt ->customer_phone2		= $_REQUEST['customer_phone2'];
	$objCustomerMgmt ->customer_email		= $_REQUEST['customer_email'];
	$objCustomerMgmt ->customer_website		= $_REQUEST['customer_website'];
	$objCustomerMgmt ->customer_balance		= $_REQUEST['customer_balance'];
	$objCustomerMgmt ->customer_baltype		= $_REQUEST['balance_typehidden'];
	
	$objCustomerMgmt ->customer_cpname1			= $_REQUEST['customer_cpname1'] ;
	$objCustomerMgmt ->customer_cpdesignation1	= $_REQUEST['hiddencustomer_cpdesignation1'];
	$objCustomerMgmt ->customer_cpmobile1       = $_REQUEST["customer_cpmobile1"] ;
	$objCustomerMgmt ->customer_cpemail1		= $_REQUEST['customer_cpemail1'] ;
	
	
	$objCustomerMgmt ->customer_tinno			= $_REQUEST['customer_tinno'];
	$objCustomerMgmt ->customer_cstno			= $_REQUEST['customer_cstno'] ;
	$objCustomerMgmt ->customer_servicetaxno	= $_REQUEST['customer_servicetaxno'];
	$objCustomerMgmt ->customer_panno			= $_REQUEST['customer_panno'] ;
	$objCustomerMgmt ->customer_remark			= $_REQUEST['customer_remark'];
	
	
	$AccountMasterMgmt->account_groupid		= $AccountGroupMgmt->getIdByName('Sales A/c');
	$AccountMasterMgmt->account_type		= 'Personal & Trading Account';
	$AccountMasterMgmt->account_name		= $_REQUEST['customer_orgname'];
	$AccountMasterMgmt->account_opbalance	= $_REQUEST['customer_balance'];
	$AccountMasterMgmt->account_crdr		= $_REQUEST['balance_typehidden'];
	$AccountMasterMgmt->account_baldate   	= date("Y-m-d");
	$AccountMasterMgmt->account_address		= $_REQUEST['customer_address'] ;
	$AccountMasterMgmt->account_phone		= $_REQUEST["customer_phone1"] ;
	$AccountMasterMgmt->account_effect		= 'Profit & Loss';
	
	if($objCustomerMgmt->customer_id=="0" || $objCustomerMgmt->customer_id==""){
	
		$objCustomerMgmt->add();
		$AccountMasterMgmt->add();	
									
	}
	else{
		
		if($_REQUEST['account_id']!="0" || $_REQUEST['account_id']!="")
		{			
			$AccountMasterMgmt->account_id	=$_REQUEST['account_id'];
			$AccountMasterMgmt->edit();	
		}
		$objCustomerMgmt->edit();				
	}	
	if($customer_cpname1 == "" && $address == "")
	{
	$newID = "";					
	}
    $newID  = $objCustomerMgmt->customer_id;			
	echo '{"success":"true","msg":"" , "Id":"'.$newID.'"}';
}
else {
	echo '{"success":"false","msg":"session expiry"}';
}	         
?>
