<?php 
/*-- 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';


$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('spl.class.Special.php');


$objDBConnect	= new DBConnect($DBName);
$objDBQuery		= new DBQuery($objDBConnect);
$objSolarCustomer	= new BusiLogic($objDBQuery, $DBName);
$objSpecialClass	= new SpecialClass($objDBQuery, $DBName, $objSolarCustomer);

$action = (isset($_GET['actionName']) ? $_GET['actionName'] : '');
/*$action = '';
if (isset($_GET['actionName'])) {
	$action = $_GET['actionName'];
}*/

switch ($action)
{	
	
	case 'shortreportDailyStock':
		shortreportDailyStock($objSolarCustomer, $objSpecialClass);
	break;
	default:
	case 'getSubdealerM':
		getSubdealerM($objSolarCustomer, $objSpecialClass);
	break;
	
	case 'approvePhoneCall':
		approvePhoneCall($objSolarCustomer, $objSpecialClass);
	break;
	
	case 'getSubdealerDetails':
		getSubdealerDetails($objSolarCustomer, $objSpecialClass);
	break;
	case 'CheckRE11':
		CheckRE11($objDBQuery,$objSolarCustomer, $objSpecialClass);
	break;
	case 'getItemM':
		getItemM($objSolarCustomer,$objSpecialClass);
	break;

	case 'getItemMExp':
		getItemMExp($objSolarCustomer,$objSpecialClass);
	break;
	case 'getCustomerLicDoc':
		getCustomerLicDoc($objSolarCustomer,$objSpecialClass);
	break;
	case 'reportCustomerM':
		reportCustomerM($objSolarCustomer, $objSpecialClass);
	break;
	
	case 'reportStateWiseCustomerM':
		reportStateWiseCustomerM($objSolarCustomer, $objSpecialClass);
	break;
	case 'reportSubdealerM':
		reportSubdealerM($objSolarCustomer, $objSpecialClass);
	break;
	case 'reportstateWiseSubdealerM':
		reportstateWiseSubdealerM($objSolarCustomer, $objSpecialClass);
	break;
	
	case 'getDealerSubdealerPercentage':
		getDealerSubdealerPercentage($objSolarCustomer, $objSpecialClass);
	break;
	
	case 'statusToggleByAdmin':
		statusToggleByAdmin($objSolarCustomer, $objSpecialClass);
	break;

	default:
} 


function shortreportDailyStock($objSolarCustomer, $objSpecialClass) {
	
	$resultArr = $objSpecialClass->shortreportDailyStock($_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());
	}
}

//Phone call Report functionality

function getSubdealerM($objSolarCustomer, $objSpecialClass) {
	
	$resultArr = $objSolarCustomer->getSubdealerMDisp($_POST['CustomerCd']);	// Returns Subdealers Details
	$firm_array = $objSolarCustomer->fillMasterDropDown('IdSubdealer', $resultArr,'','');
	if ($firm_array !='') {
		echo $firm_array;
	} else {
		echo json_encode(array());
	}
}

function approvePhoneCall($objSolarCustomer, $objSpecialClass) {
	$resultArr = $objSpecialClass->approvePhoneCall($_POST['Id'],$_POST['CustomerCd'],$_POST['Date']);	
	echo json_encode(array());
}

	

function getSubdealerDetails($objSolarCustomer, $objSpecialClass) {

	$SubdealerCd = $_POST['SubdealerCd'];
	$CustomerCd = $_POST['CustomerCd'];

	$resultArr = $objSpecialClass->SubdealerDetails($SubdealerCd,$CustomerCd);	// Returns Subdealers Details

	
	if (sizeof($resultArr)> 0) {
		echo json_encode($resultArr);
	} else {
		echo json_encode(array());
	}
}


function CheckRE11($objDBConnect,$objSolarCustomer, $objSpecialClass) {

	$RE11NO = $_POST['INDETNo'];
	$RE11Date = $_POST['INDETDate'];
	
	$resultArr = $objSpecialClass->getRE11Details($RE11NO, $RE11Date);	// Returns RE11 Details
	
	if (sizeof($resultArr)> 0) {
		echo json_encode($resultArr);
	} else {
		echo json_encode(array());
	}
}

function getCustomerLicDoc($objSolarCustomer,$objSpecialClass){

	$resultArr = $objSpecialClass->getLicDocKeyOfCustomer($_POST);	// Returns LicDocKey Of Customer
	
	if (sizeof($resultArr)> 0) {
		echo json_encode($resultArr);
	} else {
		echo json_encode(array());
	}

}


function getItemM($objSolarCustomer,$objSpecialClass){

	$CompanyCd = '';
	if(isset($_POST['CompanyCd']) && $_POST['CompanyCd'] !=''){
		$CompanyCd = $_POST['CompanyCd'];
		
		$resultArr = $objSpecialClass->getItem($CompanyCd);	// Returns RE11 Details
		
		if (sizeof($resultArr)> 0) {
			echo json_encode($resultArr);
		} else {
			echo json_encode(array());
		}
	}
}
function getItemMExp($objSolarCustomer,$objSpecialClass){

	$CompanyCd = '';
	if(isset($_POST['CompanyCd']) && $_POST['CompanyCd'] !=''){
		$CompanyCd = $_POST['CompanyCd'];
		
		$resultArr = $objSpecialClass->getItemExp($CompanyCd);	// Returns RE11 Details
		
		if (sizeof($resultArr)> 0) {
			echo json_encode($resultArr);
		} else {
			echo json_encode(array());
		}
	}
}

function reportCustomerM($objSolarCustomer,$objSpecialClass){
	$_SESSION['SectorCd'] = $_POST['SectorCd'];
	$dataArr = $objSpecialClass->getCustomerDetails();
	$fileName = $_POST['ReportFileName'];
	$repTitle = 'Customer Details';
	$objSolarCustomer->makeTabReport($dataArr, 1, $fileName, -1, $repTitle, FALSE);
	echo json_encode(array());	
}

function reportStateWiseCustomerM($objSolarCustomer,$objSpecialClass){
	$_SESSION['SectorCd'] = $_POST['SectorCd'];
	$searchVal = $_POST['searchVal'];
	$dataArr = $objSpecialClass->getStatewiseCustList($searchVal);
	$fileName = $_POST['ReportFileName'];
	$repTitle = 'State wise Customer Details';
	$objSolarCustomer->makeTabReport($dataArr, 1, $fileName, -1, $repTitle, FALSE);
	echo json_encode(array());	
	
}

function reportSubdealerM($objSolarCustomer,$objSpecialClass){
	$dataArr = $objSpecialClass->getSubdealerDetails();
	$fileName = $_POST['ReportFileName'];
	$repTitle = 'Subdealer Details';

	$objSolarCustomer->makeTabReport($dataArr, 1, $fileName, -1, $repTitle, FALSE);
	echo json_encode(array());	
}

function reportstateWiseSubdealerM($objSolarCustomer,$objSpecialClass){
	$searchVal = $_POST['searchVal'];
	$dataArr = $objSpecialClass->getStatewiseSubdealerList($searchVal);
	$fileName = $_POST['ReportFileName'];
	$repTitle = 'Subdealer Details';

	$objSolarCustomer->makeTabReport($dataArr, 1, $fileName, -1, $repTitle, FALSE);
	echo json_encode(array());	
	
}

function getDealerSubdealerPercentage($objSolarCustomer,$objSpecialClass){
	$dataArr = $objSpecialClass->getDealerSubdealerPercentage($_POST['SubdealerCd']);
	echo json_encode($dataArr);	
}

function statusToggleByAdmin($objSolarCustomer,$objSpecialClass){
		$dataArr = $objSpecialClass->statusToggleByAdmin($_POST['SubdealerCd'],$_POST['CustomerCd'],$_POST['Month'],$_POST['Status'],$_POST['Year']);
		echo json_encode($dataArr);	
	}
 
?>