<?php 
session_name('SolarSCM');
session_start();
/*-- Library of Functions to be executed from Ajax call.	App:b2b@solarexplosives.com Company:softwareCREATIONS Author:dashgandhi@yahoo.com Contact:+919819603482	*/
const DBNameTrade		= 'b2b_solar_sc';		// Should keep in sink in b2b.index.php, b2b.class.BusiLogic & b2b.ajax.php 
const DBNameNonTrade	= 'cib2b_solar_sc';
const DBNameExport	= 'exb2b_solar_sc';


$DBName = isset($_POST['DBName']) ? $_POST['DBName'] : DBNameTrade;
$IsTradeSector	= ($DBName == DBNameTrade);

require_once('./../classes/b2b.class.dbConnect.php');
require_once('./../classes/b2b.class.dbQuery.php');
require_once('./../classes/b2b.class.BusiLogic.php');
require_once('./cryptojs-aes.php');


$objDBConnect	= new DBConnect($DBName);
$objDBQuery		= new DBQuery($objDBConnect);
$objSolarCustomer	= new BusiLogic($objDBQuery, $DBName);

$action = (isset($_GET['actionName']) ? $_GET['actionName'] : '');
/*$action = '';
if (isset($_GET['actionName'])) {
	$action = $_GET['actionName'];
}*/

switch ($action)
{
//============diffAmount ===============	
	case 'exportDiffAmt':
	exportDiffAmt($objSolarCustomer);
	break;

//================ Diff Amount===============
	
	case 'updatepasswordValidation':
	updatepasswordValidation($objSolarCustomer);
	break;
	
	case 'updateCustomerBankData':
	updateCustomerBankData($objSolarCustomer);
	break;
	
	case 'getSubdealerDealerItemRest':
	getSubdealerDealerItemRest($objSolarCustomer);
	break;

	case 'filterCustomerOnSector':
	filterCustomerOnSector($objSolarCustomer);
	break;
	
	case 'filterCustomerOnState':
	filterCustomerOnState($objSolarCustomer);
	break;

	case 'filterSubdealerSector':
	filterSubdealerSector($objSolarCustomer);
	break;

	case 'getSectorUserMDisp':
	getSectorUserMDisp($objSolarCustomer);
	break;

	case 'getPODateValidUpto':
	getPODateValidUpto($objSolarCustomer);
	break;
	
	case 'getExpDetMagazine':
	getExpDetMagazine($objSolarCustomer);
	break;
	
	case 'getCustomerItem':
	getCustomerItem($objSolarCustomer);
	break;	
	
	case 'getPOPromoQuantityHeader':
	getPOPromoQuantityHeader($objSolarCustomer);
	break;
	
	case 'getFlagRE11PDF':
	getFlagRE11PDF($objSolarCustomer);
	break;

	case 'getPromotionItemQuantity':
	getPromotionItemQuantity($objSolarCustomer, $IsTradeSector);
	break;
	//=======================Multi PO promo Qty==============================
	
	case 'getCustomerMultiPoResrtictionHeader':
	getCustomerMultiPoResrtictionHeader($objSolarCustomer);
	break;
	
	case 'getMultiPOPromotionItemQuantity':
	getMultiPOPromotionItemQuantity($objSolarCustomer, $IsTradeSector);
	break;
	
	
	//========================End of Multi PO promo Qty =================
	case 'getExpDetSubItemNew':
	getExpDetSubItemNew($objSolarCustomer, $IsTradeSector);
	break;

	case 'getExpDetSubItemEdit':
	getExpDetSubItemEdit($objSolarCustomer, $IsTradeSector);
	break;

	case 'removeExpDetRE11PDF':
	removeExpDetRE11PDF($objSolarCustomer);
	break;
	
	case 'removeExpDetvanloadingPDF':
	removeExpDetvanloadingPDF($objSolarCustomer);
	break;
	
	case 'removeExpDetDriverAuthPDF':
	removeExpDetDriverAuthPDF($objSolarCustomer);
	break;
	
	case 'removeExpDet403FormPDF':
	removeExpDet403FormPDF($objSolarCustomer);
	break;
	
	case 'removeExpDetRE11PDFTrade':
	removeExpDetRE11PDFTrade($objSolarCustomer);
	break;
	
	case 'getStateMDisp':
	getStateMDisp($objSolarCustomer);
	break;
	
	case 'getDistrictMDisp':
	getDistrictMDisp($objSolarCustomer);
	break;
	
	case 'getDistrictselect':
	getDistrictselect($objSolarCustomer);
	break;

	case 'getRouteMaster':
	getRouteMaster($objSolarCustomer);
	break;
	
	case 'getRouteChangeReuest':
	getRouteChangeReuest($objSolarCustomer);
	break;
	
	case 'getAdvanceintimationRoute':
	getAdvanceintimationRoute($objSolarCustomer);
	break;

	case 'filterMagazineOnCustomer':
	filterMagazineOnCustomer($objSolarCustomer);
	break;

	case 'fillContractCustomerItemRateMDisp':
	fillContractCustomerItemRateMDisp($objSolarCustomer);
	break;
	
	case 'fillPOPendingContract':
	fillPOPendingContract($objSolarCustomer);
	break;
	
	case 'fillPOVehicleMDisp':
	fillPOVehicleMDisp($objSolarCustomer);
	break;
	
	case 'isExistPOPromoRestriction':
	isExistPOPromoRestriction($objSolarCustomer);
	break;
	
	case 'IsExistMultiPOPromo':
	IsExistMultiPOPromo($objSolarCustomer);
	break;
	
	case 'getcustomerstate':
	getcustomerstate($objSolarCustomer);
	break;
	
	case 'getVehicleCapacity':
	getVehicleCapacity($objSolarCustomer);
	break;
	case 'getVehiclePOCapacity':
	getVehiclePOCapacity($objSolarCustomer);
	break;
	
	case 'getPORestrictionQty':
	getPORestrictionQty($objSolarCustomer);
	break;
	
	case 'updateVehicleReachedDate':
	updateVehicleReachedDate($objSolarCustomer);
	break;
	
	

//============= Dealer Sub Dealer AED Allotment==========

	case 'getDealerSubdealerDetails':
	getDealerSubdealerDetails($objSolarCustomer);
	break;

	case 'getDealerSubdealerReserveStock':
	getDealerSubdealerReserveStock($objSolarCustomer);
	break;

	case 'getDealerSubDealerAEDAllocationHeader':
	getDealerSubDealerAEDAllocationHeader($objSolarCustomer);
	break;

	case 'getCustomerPO':
	getCustomerPO($objSolarCustomer);
	break;

	case 'getTransporterMDisp':
	getTransporterMDisp($objSolarCustomer);
	break;
	
	case 'getVanIdFromPO':
	getVanIdFromPO($objSolarCustomer);
	break;

	
//================== End of Dealer Subdealer AED Allottment
//==============================Subdealer Bank Detials


	case 'approveBankDetails':
	approveBankDetails($objSolarCustomer);
	break;
	

//============================================
	case 'uploadLetter':
	uploadLetter($objSolarCustomer);
	break;
	
	case 'UpdateFileName':
	UpdateFileName($objSolarCustomer);
	break;
	
	
	case 'fillAccessoryCtg':
	fillAccessoryCtg($objSolarCustomer);
	break;
	
	case 'fillPOCustomerItemRateMDisp':
	fillPOCustomerItemRateMDisp($objSolarCustomer);
	break;
	
	case 'getAccessoryCustDetail':
	getAccessoryCustDetail($objSolarCustomer);
	break;
	
	case 'getAccessoryDirectSub':
	getAccessoryDirectSub($objSolarCustomer);
	break;
	
	case 'getAccessoryIndirectSub':
	getAccessoryIndirectSub($objSolarCustomer);
	break;
	
	case 'removeAccessoryRE11PDF':
	removeAccessoryRE11PDF($objSolarCustomer);
	break;
	
	case 'getDailyStockSubdealerM':
	getDailyStockSubdealerM($objSolarCustomer);
	break;
	
	case 'getDailyStockItem':
	getDailyStockItem($objSolarCustomer);
	break;
	
	case 'getDespPlanItem':
	getDespPlanItem($objSolarCustomer);
	break;
	
	case 'getDailySaleItem':
	getDailySaleItem($objSolarCustomer);
	break;
	
	case 'fillTargetYearB2bCustomerItemMDisp':
	fillTargetYearB2bCustomerItemMDisp($objSolarCustomer);
	break;

	case 'fillTradeTargetYearB2bCustomerItemMDisp':
	fillTradeTargetYearB2bCustomerItemMDisp($objSolarCustomer);
	break;

	case 'fillTargetYearCib2bCustomerItemMDisp':
	fillTargetYearCib2bCustomerItemMDisp($objSolarCustomer);
	break;

	case 'fillTargetMonthB2bCustomerItemMDispTrade':
	fillTargetMonthB2bCustomerItemMDispTrade($objSolarCustomer);
	break;
	
	case 'fillTargetMonthB2bCustomerItemMDisp':
	fillTargetMonthB2bCustomerItemMDisp($objSolarCustomer);
	break;
	
	case 'fillTargetMonthB2bCompanyItemMDisp':
	fillTargetMonthB2bCompanyItemMDisp($objSolarCustomer);
	break;

	case 'fillTargetMonthCib2bCustomerItemMDisp':
	fillTargetMonthCib2bCustomerItemMDisp($objSolarCustomer);
	break;
	
	case 'SaleReport':
	SaleReport($objSolarCustomer);
	break;
	
	case 'reportExpDetOrderStatus':
	reportExpDetOrderStatus($objSolarCustomer);
	break;
	
	case 'getDispatch':
	getDispatch($objSolarCustomer);
	break;

	case 'reportAccessoryStatus':
	reportAccessoryStatus($objSolarCustomer);
	break;

	case 'reportStdVsActualVanTrip':
	reportStdVsActualVanTrip($objSolarCustomer);
	break;

	case 'reportStdVsActualDespatch':
	reportStdVsActualDespatch($objSolarCustomer);
	break;

	case 'reportDailyStock':
	reportDailyStock($objSolarCustomer);
	break;

	case 'reportDailySaleDealerSubdealer':
	reportDailySaleDealerSubdealer($objSolarCustomer);
	break;

	case 'reportDownload':
	reportDownload($objSolarCustomer);
	break;

	case 'IsYearlyTargetExist':
	IsYearlyTargetExist($objSolarCustomer);
	break;
	
	
	case 'utilSetFORCompVan':
	utilSetFORCompVan($objSolarCustomer);
	break;

	case 'isDocKeyExist':
	isDocKeyExist($objSolarCustomer);
	break;
	
	//===========Customer indent alert 
	case 'getCustomer':
	getCustomer($objSolarCustomer);
	break;
	
	case 'getCompetitorDealer':
	getCompetitorDealer($objSolarCustomer);
	break;
	
	case 'getSubdealerCd':
	getSubdealerCd($objSolarCustomer);
	break;

	case 'getOwnCompany':
	getOwnCompany($objSolarCustomer);
	break;

	case 'getOtherCompany':
	getOtherCompany($objSolarCustomer);
	break;
	
	case 'isRE11Exist':
	isRE11Exist($objSolarCustomer);
	break;
	
	//====================================  Stock Batch Date No Wise Popup
	case 'insertStockBatchDatewiseCustomer':
	insertStockBatchDatewiseCustomer($objSolarCustomer);
	break;	
	
	case 'removeStockBatchItem':
	removeStockBatchItem($objSolarCustomer);
	break;	
	//==========================================
	//********************* AED allocation  ******************************/
	
	case 'getCustomerDetails':
	getCustomerDetails($objSolarCustomer);
	break;
	
//********************* End AED allocation *******************************/
	
	case 'approveDealerTargetConfirmation':
	approveDealerTargetConfirmation($objSolarCustomer);
	break;
	//=================================
	case 'downloadSubDealerPercantageList':
	downloadSubDealerPercantageList($objSolarCustomer);
	break;
		
	case 'approveSubdealerPercentageByAdmin':
	approveSubdealerPercentageByAdmin($objSolarCustomer);
	break;
	
	//============================Postal Address
	
	case 'insertAddressDetails':
	insertAddressDetails($objSolarCustomer);
	break;
	
	case 'editAddressDetails':
	editAddressDetails($objSolarCustomer);
	break;
	
	case 'downloadCustomerBankPayment':
	downloadCustomerBankPayment($objSolarCustomer);
	break;
	
	case 'getRE11nPODetails':
	getRE11nPODetails($objSolarCustomer);
	break;
	
	
	case 'checkMainClubedPOExist':
	checkMainClubedPOExist($objSolarCustomer);
	break;
	
	
	case 'getClubedVanCustomer':
	getClubedVanCustomer($objSolarCustomer);
	break;
	
	case 'acceptClubedVanPOByOwner':
	acceptClubedVanPOByOwner($objSolarCustomer);
	break;
	
	
	case 'checkMainCustomerVehicle':
	checkMainCustomerVehicle($objSolarCustomer);
	break;
	case 'clubedVanFinalAprove':
	clubedVanFinalAprove($objSolarCustomer);
	break;
	//===================Sen=miactive Reason
	
	case 'getSemiActiveReason':
	getSemiActiveReason($objSolarCustomer);
	break;
	
	case 'editSemiActiveReason':
	editSemiActiveReason($objSolarCustomer);
	break;
	
	case 'deleteSemiActiveReason':
	deleteSemiActiveReason($objSolarCustomer);
	break;
	
	//========================Customer UTR No======================//
	
	case 'UpdatePOUTR':
	UpdatePOUTR($objSolarCustomer);
	break;
	
	case 'checkUTRCondition':
	checkUTRCondition($objSolarCustomer);
	break;
	
	case 'getUTRFromExpDet':
	getUTRFromExpDet($objSolarCustomer);
	break;
	
	//=============================End of Customer UTR No========================//

// scm Report
	case 'reportCustomerVanStatus':
	reportCustomerVanStatus($objSolarCustomer);
	break;
	
//=============User Authentivation Control============
	case 'UpdateAccessControll':
	UpdateAccessControll($objSolarCustomer);
	break;
	
	
	default:
} 

//=================diff AMount=============

function exportDiffAmt($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->exportDiffAmt($_POST['IdExpDet']);
	//echo  $resultArr;
	echo json_encode($resultArr);
}


//==========================End of Diff Amount=-=-===============
function updatepasswordValidation($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->updatepasswordValidation($_POST['NewPassword'],$_POST['UserName']);
	//echo json_encode (array($resultArr));
	echo json_encode($resultArr);
}


function updateCustomerBankData($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->updateCustomerBankData($_POST['BankName'], $_POST['BankBranch'], $_POST['BankAccountNo'], $_POST['IFSCCode'], $_POST['oldCustomerCd']);
	echo json_encode($resultArr);
}

function downloadCustomerBankPayment($objBusiLogic) {
	$resultArr	= $objBusiLogic->getCustomerBankPaymentData($_POST['date'],$Id='',$_POST['downloadfile'],null,$_POST['PaymentReturnId'],$_POST['CompanyCd']);
	echo json_encode($resultArr);
}

function getRE11nPODetails($objBusiLogic) {
	$resultArr	= $objBusiLogic->getRe11Data($_POST['IdExpDet'],$_POST['MagazineCd']);
	echo json_encode($resultArr);
}




function checkMainClubedPOExist($objBusiLogic) {
	$resultArr	= $objBusiLogic->checkMainClubedPOExist($_POST['value']);
	echo json_encode($resultArr);
}

function getClubedVanCustomer($objBusiLogic) {
	$resultArr	= $objBusiLogic->getClubedVanCustomer($_POST['PONo']);
	echo json_encode($resultArr);
	
}function acceptClubedVanPOByOwner($objBusiLogic) {
	$resultArr	= $objBusiLogic->acceptClubedVanPOByOwner($_POST['IdExpDet'],$_POST['AcceptValue']);
	echo json_encode($resultArr);
}


function checkMainCustomerVehicle($objBusiLogic) {
	$resultArr	= $objBusiLogic->checkMainCustomerVehicle($_POST['VehicleInput'], $_POST['IdExpDet']);
	echo json_encode($resultArr);
}
function clubedVanFinalAprove($objBusiLogic) {
	$resultArr	= $objBusiLogic->clubedVanFinalAprove($_POST['Id']);
	echo json_encode($resultArr);
}



function getSubdealerDealerItemRest($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getSubdealerDealerItemRest($_POST['IdSubdealer'], $_POST['CustomerCd'], $_POST['ItemCd']);
	echo json_encode($resultArr);
}

function filterCustomerOnSector($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getCustomerOfSector($_POST['SectorCd']);
	echo json_encode($resultArr);
}

function filterCustomerOnState($objSolarCustomer) {
	$state=$_POST['state'];
	$resultArr	= $objSolarCustomer->getCustomerMDisp(0, '', "StateCd='$state'");
	echo json_encode($resultArr);
}

function filterSubdealerSector($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getSubdealerMDisp();
	echo json_encode($resultArr);
}

function getSectorUserMDisp($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getSectorUserMDisp($_POST['SectorCd']);
	echo json_encode($resultArr);
}

function getPODateValidUpto($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getPODateValidUpto($_POST['SectorCd']);
	echo json_encode($resultArr);
}

function getExpDetMagazine($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getExpDetMagazine($_POST['IdExpDet']);
	echo json_encode($resultArr);
	//echo $resultArr;
}

function getCustomerItem($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getCustomerItem($_POST['CustomerCd']);
	echo json_encode($resultArr);
	//echo $resultArr;
}

function getPOPromoQuantityHeader($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getPOPromoQuantityHeader($_POST['CustomerCd'],$_POST['VehicleCapacity']);
	echo json_encode($resultArr);
}


function getPromotionItemQuantity($objSolarCustomer) {
$resultArr	= $objSolarCustomer->getPromotionItemQuantity($_POST['CustomerCd'], $_POST['VehicleCapacity'], $_POST['ItemCd']);
	echo json_encode($resultArr);
	//echo $resultArr;
}

// ============================= Multi PO Promo ============================

function getMultiPOPromotionItemQuantity($objSolarCustomer) {
$resultArr	= $objSolarCustomer->getMultiPOPromotionItemQuantity($_POST['CustomerCd'], $_POST['VehicleCapacity'], $_POST['ItemCd']);
	echo json_encode($resultArr);
	//echo $resultArr;
}

function getCustomerMultiPoResrtictionHeader($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getCustomerMultiPoResrtictionHeader($_POST['CustomerCd'],$_POST['vehCap']);
	echo json_encode($resultArr);
}

//======================== End multi Po promo =====================

function getFlagRE11PDF($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getFlagRE11PDF($_POST['CustomerCd']);
	echo json_encode($resultArr);
}

function getExpDetSubItemNew($objSolarCustomer, $IsTradeSector) {
	$resultArr	= $objSolarCustomer->getExpDetSubItemNew($IsTradeSector, $_POST['CustomerCd'], $_POST['MagazineCd'], $_POST['CompanyCd'], $_POST['DespatchMode'], $_POST['IsCustomer']);
	echo json_encode($resultArr);
	//echo $resultArr;
}

function getExpDetSubItemEdit($objSolarCustomer, $IsTradeSector) {
	$resultArr	= $objSolarCustomer->getExpDetSubItemEdit($IsTradeSector, $_POST['IdExpDet'], $_POST['UniqueIdMagazine'], $_POST['StatusCd'], $_POST['IsCustomer']);
	echo json_encode($resultArr);
	//echo $resultArr;
}
function getStateMDisp($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getStateMDisp();
	echo json_encode($resultArr);
}

function getDistrictMDisp($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getDistrictMDisp();
	echo json_encode($resultArr);
}

function getDistrictselect($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getDistrictselect($_POST['District']);
	echo json_encode($resultArr);
}

function getRouteMaster($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getroutemaster($_POST['CustomerCd'], $_POST['MagazineCd'], '');
	echo json_encode($resultArr);
}
function getRouteChangeReuest($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getrouterequest($_POST['CustomerCd'], $_POST['RequestId']);
	echo json_encode($resultArr);
}

function getAdvanceintimationRoute($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getIntimationroute($_POST['CustomerCd'],  $_POST['IdExpDet'], $_POST['MagazineCd'],$_POST['IntimationNo'], '');
	echo json_encode($resultArr);
}

function filterMagazineOnCustomer($objSolarCustomer) {
	$postData	= $_POST;
	$resultArr	= $objSolarCustomer->getMagazineOfCustomer($postData);
	echo json_encode($resultArr);
}

function fillContractCustomerItemRateMDisp($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getContractCustomerItemRate($_POST['CustomerCd'], $_POST['CompanyCd'], $_POST['excludeDefCustomer'], $_POST['IdContract'], $_POST['StatusCd'], $_POST['DespatchModeFOR']);
	$jsonString	= json_encode($resultArr);
	echo $jsonString;
}

function fillPOPendingContract($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getPOPendingContract($_POST['CustomerCd']);
	echo json_encode($resultArr);
}

function fillPOVehicleMDisp($objSolarCustomer) {	// <-- also frmSoAccessory
	$resultArr	= $objSolarCustomer->getPOVehicleMDisp($_POST['CustomerCd'], $_POST['Date'], $_POST['DespatchModeFOR'], $_POST['IsAccessory']);
	echo json_encode($resultArr);
}

function isExistPOPromoRestriction($objSolarCustomer) {	// <-- also frmSoAccessory
	$resultArr	= $objSolarCustomer->isExistPOPromoRestriction($_POST['CustomerCd']);
	echo json_encode($resultArr);
}

function IsExistMultiPOPromo($objSolarCustomer) {	// <-- also frmSoAccessory
	$resultArr	= $objSolarCustomer->IsExistMultiPOPromo($_POST['CustomerCd']);
	echo json_encode($resultArr);
}

function getcustomerstate($objSolarCustomer) {	// <-- also frmSoexpdet
	$resultArrData	= $objSolarCustomer->getCustomer($_POST['CustomerCd']);
	$resultArr = array(array('StateCd'=>$resultArrData[0]['StateCd']));
	echo json_encode(($resultArr));
}
function getVehicleCapacity($objSolarCustomer) {	// <-- also frmSoexpdet
	$resultArr	= $objSolarCustomer->VehicleEditData($_POST['VehicleInput']);
	echo json_encode($resultArr);
}

function getVehiclePOCapacity($objSolarCustomer) {	// <-- also frmSoexpdet
	$resultArr	= $objSolarCustomer->getVehiclePOCapacity($_POST['VehicleInput'], $_POST['IdExpDet'] );
	echo json_encode($resultArr);
}

function getPORestrictionQty($objSolarCustomer) {	// <-- also frmSoexpdet
	$resultArr	= $objSolarCustomer->getPORestrictionQty($_POST['StartDate'], $_POST['EndDate'], $_POST['ItemCd'], $_POST['CustomerCd'], $_POST['IdExpDet']);
	echo json_encode($resultArr);
}

function updateVehicleReachedDate($objSolarCustomer) {	// <-- also frmSoexpdet
	$resultArr	= $objSolarCustomer->updateVehicleReachedDate($_POST['IdExpdet']);
	echo json_encode($resultArr);
}

//========================= Dealer Subdealer AED Allottment==============

function getDealerSubdealerDetails($objSolarCustomer){
	$resultArr	= $objSolarCustomer->getDealerSubdealerDetails($_POST['CustomerCd']);
	echo json_encode($resultArr);
}

function getDealerSubdealerReserveStock($objSolarCustomer){
	$resultArr	= $objSolarCustomer->getDealerSubdealerReserveStock($_POST['CustomerCd']);
	echo json_encode($resultArr);
}

function getDealerSubDealerAEDAllocationHeader($objSolarCustomer){
	$resultArr	= $objSolarCustomer->getDealerSubDealerAEDAllocationHeader($_POST['CustomerCd'],$_POST['Month'],$_POST['Year'], $_POST['AEDAllotment_Id']);
	echo json_encode($resultArr);
}

function getCustomerPO($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getCustomerPOList($_POST['CustomerCd']);
	//echo  $resultArr;
	echo json_encode($resultArr);
}

function getTransporterMDisp($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getVanTransporterMDisp($_POST['IdVan']);
	echo json_encode($resultArr);
}


function getVanIdFromPO($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getVanIdFromPO($_POST['IdExpDet']);
	echo json_encode($resultArr);
}

//=============================End Dealer Subdealer AED Allottment==============  
//========================Subdealer Bank Detials=============================

function approveBankDetails($objBusiLogic){
	$resultArr = $objBusiLogic->approveBankDetails($_POST['Subdealer']);
	echo $resultArr;
}

//======================================================================
function uploadLetter($objBusiLogic){
if($_FILES)
{  
	if($_POST['name'] == 'VanLoadingLetter'){
		
		$form = $_POST['fileName'];
	
		$size = $_FILES['VanLoadingLetter']['size'];
		$tmp_name = $_FILES['VanLoadingLetter']['tmp_name'];
		$uploaddir = '../upload/VanLoadingLetter/';
	}
	if($_POST['name'] == 'DriverAuthPDF'){
		$form = $_FILES['DriverAuthPDF']['name'];
		$size = $_FILES['DriverAuthPDF']['size'];
		$tmp_name = $_FILES['DriverAuthPDF']['tmp_name'];
		$uploaddir = '../upload/DriverAuthPDF/';
	}
		$data = array();
		$files = array();
		$valid_formats = array("pdf");	
			list($txt, $ext) = explode(".", $form);
			//$final_image = rand(1000,1000000).$name;
			$final_image = $form;
			if(in_array($ext,$valid_formats)){
				if($size<(1024*800)){
					if(move_uploaded_file($tmp_name, $uploaddir .basename($final_image))){
						$files = $form;
						$data = array('success' => 'file uploaded', 'formData' => array('files' => $form));
					}
					else{
						$data = array('error' => 'There was an error uploading your files');
					}   
				}else{
					$data = array('error' => 'Select file size max 800 KB');
				}
			}
			else{
					$data = array('error' => 'Invalid file format');
			}
	}else{
		$data = array('error' => 'Internal error, please contact administrator');
	}
			echo json_encode($data);
}

function UpdateFileName($objBusiLogic){
	$resultArr = $objBusiLogic->UpdateFileName($_POST['FileName'],$_POST['Fieldname'], $_POST['Cond'],$_POST['Tablename']);
	echo $resultArr;
}




function fillAccessoryCtg($objSolarCustomer) {	// <-- also frmSoAccessory
	$resultArr	= $objSolarCustomer->getAccessoryCtgMDisp($_POST['PlantCd']);
	echo json_encode($resultArr);
}

function fillPOCustomerItemRateMDisp($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getPOCustomerItemRate($_POST['ContractNo'], $_POST['IdPO'], $_POST['StatusCd']);
	$jsonString	= json_encode($resultArr);
	echo $jsonString;
}

function getAccessoryCustDetail($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getAccessoryCustDetail($_POST['CustomerCd'], $_POST['AccessoryCtgCd']);
	echo json_encode($resultArr);
}

function getAccessoryDirectSub($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getAccessoryDirectSub((int)$_POST['IdAccessory'], $_POST['StatusCd'], $_POST['AccessoryCtgCd']);
	echo json_encode($resultArr);
}

function getAccessoryIndirectSub($objSolarCustomer) {

	$resultArr	= $objSolarCustomer->getAccessoryIndirectSub((int)$_POST['IdAccessory'], (int)$_POST['AccessoryCtgCd'], $_POST['PropertyName1'], $_POST['PropertyName2']);
	echo json_encode($resultArr);
}

function getDailyStockSubdealerM($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getDailyStockSubdealerM($_POST['CustomerCd']);
	echo json_encode($resultArr);
}

function getDailyStockItem($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getDailyStockItem($_POST['CustomerCd'], $_POST['Date'], $_POST['StatusCd']);
	echo json_encode($resultArr);
}

function getDespPlanItem($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getDespPlanItem($_POST['CustomerCd'], $_POST['Date'], $_POST['StatusCd']);
	echo json_encode($resultArr);
}

function getDailySaleItem($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getDailySaleItem($_POST['CustomerCd'], $_POST['Date'], $_POST['IsHeaderOwn']);
	echo json_encode($resultArr);
}

function fillTargetYearB2bCustomerItemMDisp($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getTargetYearB2bCustomerItem($_POST['CustomerCd'], $_POST['excludeDefCustomer'], $_POST['Year'], $_POST['StatusCd']);
	echo json_encode($resultArr);
}

function fillTradeTargetYearB2bCustomerItemMDisp($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getTradeTargetYearB2bCustomerItem($_POST['CustomerCd'], $_POST['excludeDefCustomer'], $_POST['Year'], $_POST['StatusCd']);
	echo json_encode($resultArr);
}

function fillTargetYearCib2bCustomerItemMDisp($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getTargetYearCib2bCustomerItem($_POST['CustomerCd'], $_POST['excludeDefCustomer'], $_POST['Year'], $_POST['StatusCd']);
	echo json_encode($resultArr);
}

function fillTargetMonthB2bCompanyItemMDisp($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getTargetMonthB2bCompanyItem($_POST['CompanyCd']);
	echo json_encode($resultArr);
}

function fillTargetMonthB2bCustomerItemMDispTrade($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getTradeTargetMonthB2bCustomerItem($_POST['CustomerCd'], $_POST['excludeDefCustomer'], $_POST['Year'], $_POST['Month'], $_POST['StatusCd']);
	echo json_encode($resultArr);
}

function fillTargetMonthB2bCustomerItemMDisp($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getTargetMonthB2bCustomerItem($_POST['CustomerCd'], $_POST['excludeDefCustomer'], $_POST['Year'], $_POST['Month'], $_POST['StatusCd']);
	echo json_encode($resultArr);
}

function fillTargetMonthCib2bCustomerItemMDisp($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getTargetMonthCib2bCustomerItem($_POST['CustomerCd'], $_POST['excludeDefCustomer'], $_POST['Year'], $_POST['Month'], $_POST['StatusCd']);
	echo json_encode($resultArr);
}

function SaleReport($objBusiLogic) {
	$RecCount	= 0;
	$resultArr = $objBusiLogic->SaleReport((int)$_POST['CompanyCd'], $_POST['SectorCd'], $_POST['CustomerCd'], $_POST['StateCd'], $_POST['DTSDays'], $_POST['DTE'], $_POST['StatusCdStr'], $_POST['OnlyApproved'], $RecCount);
	echo json_encode(array($RecCount, $resultArr));
	
}

function reportExpDetOrderStatus($objBusiLogic) {
	$RecCount	= 0;
	$resultArr = $objBusiLogic->reportExpDetOrderStatus((int)$_POST['CompanyCd'], $_POST['SectorCd'], $_POST['CustomerCd'], $_POST['DTSDays'], $_POST['DTE'], $_POST['StatusCdStr'], $_POST['OnlyApproved'], $RecCount);
	echo json_encode(array($RecCount, $resultArr));
}


function getDispatch($objBusiLogic) {
	$SectorCd = 'T';
	if($SectorCd != ''){
		$resultArr = $objBusiLogic->getDispatchStock((int)$_POST['CompanyCd'], $SectorCd);

		echo json_encode($resultArr);
	}else{
		echo 0;
	}
	
}

function reportAccessoryStatus($objBusiLogic) {
	$RecCount	= 0;
	$resultArr = $objBusiLogic->reportAccessoryStatus((int)$_POST['CompanyCd'], $_POST['SectorCd'], $_POST['CustomerCd'], $_POST['DTSDays'], $_POST['DTE'], $_POST['StatusCdStr'], $_POST['OnlyApproved'], $RecCount);
	echo json_encode(array($RecCount, $resultArr));
}

function reportStdVsActualVanTrip($objBusiLogic) {
	$resultArr = $objBusiLogic->reportStdVsActualVanTrip($_POST['SectorCd'], $_POST['MagazineCd'], $_POST['Transporter'], $_POST['VehicleNo'], $_POST['DTS'], $_POST['DTE']);
	echo json_encode($resultArr);
}

function reportStdVsActualDespatch($objBusiLogic) {
	$resultArr = $objBusiLogic->reportStdVsActualDespatch($_POST['SectorCd'], $_POST['CustomerCd'], $_POST['MagazineCd'], $_POST['DTS'], $_POST['DTE']);
	echo json_encode($resultArr);
}

function reportDailyStock($objBusiLogic) {
	$resultArr = $objBusiLogic->reportDailyStock($_POST['SectorCd'], $_POST['DTSDays'], $_POST['DTE'], $_POST['IsAED']);	// Returns 4 Recordsets 0:@ColumnStru,... (to ignore) 1:DailyStockDetails 2:GrandTotal 3:NoDailyStockCustomerList
	if (sizeof($resultArr)>1) {
		echo json_encode(array($resultArr[1], $resultArr[2], $resultArr[3]));
	} else {
		echo json_encode(array());
	}
}

function reportDailySaleDealerSubdealer($objBusiLogic) {
	$resultArr = $objBusiLogic->reportDailySaleDealerSubdealer($_POST['DTS'], $_POST['DTE'], $_POST['CustomerCd'], $_POST['IdSubdealer'], $_POST['ReportType'], $_POST['StateCd']);
	if (sizeof($resultArr)>1) {
		echo json_encode($resultArr[1]);
	} else {
		echo json_encode(array());
	}	
}

function reportDownload($objBusiLogic) {
	$dataArr	= json_decode($_POST['dataArrJSON']);
	$objBusiLogic->reportDownload($dataArr, $_POST['ReportFileName']);
	echo json_encode(array());
}

function isDocKeyExist($objBusiLogic){
	$resultArr = $objBusiLogic->isDocKeyExist($_POST['dockey']);
	echo $resultArr;
}

//=================================CUSTOMER INDENT AlERT ======================

function getCustomer($objBusiLogic){
	$state=$_POST['StateCd'];
	$resultArr = $objBusiLogic->getCustomerMDisp(0, '', "StateCd='$state'");
	echo json_encode($resultArr);;
}

function getCompetitorDealer($objBusiLogic){
	$resultArr = $objBusiLogic->getCompetitorDealerMDisp();
	echo json_encode($resultArr);;
}

function getSubdealerCd($objBusiLogic){
	$state=$_POST['StateCd'];
	$resultArr = $objBusiLogic->getSubdealerMDisp(NULL, "StateCd ='$state'");
	echo json_encode($resultArr);
}

function getOwnCompany($objBusiLogic){
	$resultArr = $objBusiLogic->getCompanyMDisp();
	echo json_encode($resultArr);;
}

function getOtherCompany($objBusiLogic){
	$resultArr = $objBusiLogic->getOtherCompanyMDisp();
	echo json_encode($resultArr);;
}

function isRE11Exist($objBusiLogic){
	$resultArr = $objBusiLogic->isRE11Exist($_POST['RE11No']);
	echo $resultArr;
}



//======================== Stock Batch Date No Wise Popup======================================
function insertStockBatchDatewiseCustomer($objSolarCustomer){
	$postData	= $_POST;
	$resultArr	= $objSolarCustomer->insertStockBatchDatewiseCustomer($postData);
	echo json_encode($resultArr);
}


function removeStockBatchItem($objSolarCustomer){
	$resultArr	= $objSolarCustomer->removeStockBatchItem($_POST['StateCd'],$_POST['Id'],$_POST['ItemCd']);
	echo json_encode($resultArr);
}
//=========================================

//===========================AED Allocation ========================
/*function getCustomerDetails($objBusiLogic){
	$resultArr = $objBusiLogic->getCustomerDetails($_POST['CustomerCd'],$_POST['CompanyCd']);
	echo json_encode($resultArr);;
}
*/
function getCustomerDetails($objBusiLogic){
	$resultArr = $objBusiLogic->getCustomerDetails(CustomDecrypt($_POST['CustomerCd']),CustomDecrypt($_POST['CompanyCd']));
	echo CustomEncrypt(json_encode($resultArr));
}

//==============================================

// scm Report
function reportCustomerVanStatus($objBusiLogic) {
	$resultArr = $objBusiLogic->reportCustomerVanStatus((int)$_POST['CustomerCd']);
	if (sizeof($resultArr)>1) {
		echo json_encode(array($resultArr[1], $resultArr[2]));
	} else {
		echo json_encode(array());
	}
}

function IsYearlyTargetExist($objBusiLogic){

	$resultArr = $objBusiLogic->isExistTargetYear($_POST['CustomerCd'],$_POST['Year']);

	if ($resultArr == 1) {
		echo 1;
	} else {
		echo 0;
	}
}

function utilSetFORCompVan($objBusiLogic) {
	$resultArr = $objBusiLogic->utilSetFORCompVan($_POST['SectorCd'],$_POST['CompanyCd'],(int)$_POST['IsAssignVan']);
	//echo $resultArr;
	if (sizeof($resultArr)>1) {
		echo json_encode($resultArr[1]);
	} else {
		echo json_encode(array());
	}
}


function removeAccessoryRE11PDF($objBusiLogic){
	$resultArr = $objBusiLogic->removeAccessoryRE11PDF($_POST['IdAccessory'],$_POST['re11PDF']);
	echo $resultArr;
}

function removeExpDetRE11PDF($objBusiLogic){
	$resultArr = $objBusiLogic->removeExpDetRE11PDF($_POST['IdExpDet'],$_POST['re11PDF']);
	echo $resultArr;
}

function removeExpDetvanloadingPDF($objBusiLogic){
	$resultArr = $objBusiLogic->removeExpDetvanloadingPDF($_POST['IdExpDet'],$_POST['VanLoadingLetter']);
	echo $resultArr;
}

function removeExpDetDriverAuthPDF($objBusiLogic){
	$resultArr = $objBusiLogic->removeExpDetDriverAuthPDF($_POST['IdExpDet'],$_POST['DriverAuthPDF']);
	echo $resultArr;
}

function removeExpDet403FormPDF($objBusiLogic){
	$resultArr = $objBusiLogic->removeExpDet403FormPDF($_POST['IdExpDet'],$_POST['Form403PDF']);
	echo $resultArr;
}

function removeExpDetRE11PDFTrade($objBusiLogic){
	$resultArr = $objBusiLogic->removeExpDetRE11PDFTrade($_POST['IdExpDet'], $_POST['MagazineCd'], $_POST['re11PDF']);
	echo $resultArr;
}


function approveDealerTargetConfirmation($objBusiLogic){
	$resultArr = $objBusiLogic->approveDealerTargetConfirmation($_POST['CustomerCd']);
	echo json_encode($resultArr);
}

function downloadSubDealerPercantageList($objBusiLogic) {
	$resultArr	= $objBusiLogic->SubDealerPercantageList(Null,$_POST['downloadfile']);
	echo json_encode($resultArr);
}

function approveSubdealerPercentageByAdmin($objBusiLogic){
	$resultArr = $objBusiLogic->approveSubdealerPercentageByAdmin($_POST['SubdealerCd']);
	echo json_encode($resultArr);
}

function insertAddressDetails($objBusiLogic){
	parse_str($_POST['data'], $postData);
	$resultArr = $objBusiLogic->insertAddressDetails($postData);
	echo json_encode($resultArr);
}

function editAddressDetails($objBusiLogic){
	parse_str($_POST['data'], $postData);
	$resultArr = $objBusiLogic->editAddressDetails($postData);
	echo json_encode($resultArr);
}


//==================== semi active reason ====================================	

function getSemiActiveReason($objBusiLogic) {
	$resultArr	= $objBusiLogic->getSemiActiveReasonData($_POST['Id']);
	echo json_encode($resultArr);
}

function deleteSemiActiveReason($objBusiLogic) {
	$resultArr	= $objBusiLogic->deleteSemiActiveReason($_POST['Id']);
	echo json_encode($resultArr);
}
function editSemiActiveReason($objBusiLogic) {
	parse_str($_POST['data'], $postData);
	$resultArr	= $objBusiLogic->editSemiActiveReason($postData);
	echo json_encode($resultArr);
}
//==================== end semi active reason ====================================	
//==========================Customer UTR No=====================\
function UpdatePOUTR($objBusiLogic) {
	$resultArr	= $objBusiLogic->UpdatePOUTR($_POST['IdExpDet'],$_POST['List']);
	echo json_encode($resultArr);
}


function checkUTRCondition($objBusiLogic) {
	$resultArr	= $objBusiLogic->checkUTRCondition($_POST['UTRvalue'],$_POST['IdExpDet']);
	echo json_encode($resultArr);
}

function 	getUTRFromExpDet($objSolarCustomer) {
	$resultArr	= $objSolarCustomer->getUTRFromExpDet($_POST['IdExpDet']);
	echo json_encode($resultArr);
}

//======================End of Customer UTR No===============================


//================= User Authorization Control=============


function UpdateAccessControll($objSolarCustomer) {
		$resultArr	= $objSolarCustomer->UpdateAccessControll($_POST['Descript'], $_POST['Id'], $_POST['value'],$_POST['stat']);
		echo json_encode($resultArr);
}	







?>