<?php 
/*-- Library of Functions to be executed from Ajax call.	App:scm@solarexplosives.com Company:softwareCREATIONS Author:dashgandhi@yahoo.com Contact:+919819603482	*/
define('DBName', 'scm_solar_sc');	// keep in sink with index.php

require_once('./../classes/scm.class.dbConnect.php');
require_once('./../classes/scm.class.dbQuery.php');
require_once('./../classes/scm.class.BusiLogic.php');

$objDBConnect	= new DBConnect(DBName);
$objDBQuery		= new DBQuery($objDBConnect);
$objBusiLogic	= new BusiLogic($objDBQuery, DBName);

$action = '';
if (isset($_GET['actionName'])) {
	$action = $_GET['actionName'];
}

switch ($action)
{
	case 'getVanIdBarcode':
	getVanIdBarcode($objBusiLogic);
	break;
	
	case 'fillGateTranVanDriverMDisp':
	fillGateTranVanDriverMDisp($objBusiLogic);
	break;
	
	case 'getGateTranVanReportingNo':
	getGateTranVanReportingNo($objBusiLogic);
	break;

	case 'checkGetTranVanActive':
	checkGetTranVanActive($objBusiLogic);
	break;
	
	case 'getGateTranVanStatusApp':
	getGateTranVanStatusApp($objBusiLogic);
	break;

	case 'getGateTranSubCustomerNewB2B':
	getGateTranSubCustomerNewB2B($objBusiLogic);
	break;

	case 'getGateTranSubCustomerNewPre':
	getGateTranSubCustomerNewPre($objBusiLogic);
	break;

	case 'getGateTranSubCustomerEdit':
	getGateTranSubCustomerEdit($objBusiLogic);
	break;

	case 'getGateTranSubCheckNew':
	getGateTranSubCheckNew($objBusiLogic);
	break;

	case 'getGateTranSubCheckEdit':
	getGateTranSubCheckEdit($objBusiLogic);
	break;
	
	case 'getVansNVanCapacity':
	getVansNVanCapacity($objBusiLogic);
	break;
	
	case 'getCityMForState':
	getCityMForState($objBusiLogic);
	break;
	
	case 'getVanMTransporterMDisp':
	getVanMTransporterMDisp($objBusiLogic);
	break;
	
	case 'getVanMSubTransporterEdit':
	getVanMSubTransporterEdit($objBusiLogic);
	break;
	
	case 'getVanDriverMTransporterMDisp':
	getVanDriverMTransporterMDisp($objBusiLogic);
	break;
	
	case 'getVanDriverMSubTransporterEdit':
	getVanDriverMSubTransporterEdit($objBusiLogic);
	break;

	case 'reportOnlineVanStatus':
	reportOnlineVanStatus($objBusiLogic);
	break;

	case 'reportCustomerVanStatus':
	reportCustomerVanStatus($objBusiLogic);
	break;

	case 'reportDownload':
	reportDownload($objBusiLogic);
	break;

	case 'utilSetFORCompVan':
	utilSetFORCompVan($objBusiLogic);
	break;

	case 'utilSetAllVan':
	utilSetAllVan($objBusiLogic);
	break;
	
	case 'removeDriverPDF':
	removeDriverPDF($objBusiLogic);
	break;

	default:
} 


function getVanIdBarcode($objBusiLogic) {
	$resultArr	= $objBusiLogic->getVanIdBarcode($_POST['IdVan']);
	echo json_encode($resultArr);
}

function fillGateTranVanDriverMDisp($objBusiLogic) {
	$resultArr	= $objBusiLogic->fillGateTranVanDriverMDisp($_POST['IdVan'], $_POST['DriverLicNo']);
	echo json_encode($resultArr);
}

function getGateTranVanReportingNo($objBusiLogic) {
//	$str = $_POST['IdVan'];
//$from = "@";
//$to = "@";
//$IdVan=  $objBusiLogic->getStringBetween($str,$from,$to);


	$resultArr	= $objBusiLogic->getGateTranVanReportingNo($_POST['GateCd'], $_POST['IdVan'], $_POST['DriverLicNo']
			, $_POST['IsGateIn']);
// 1st Recordset is always discarded. Though possibility of >3 recordsets, we are sending max 2 (ie 2nd & 3rd) Recordset to js/jQuery
	if (sizeof($resultArr)>2) {
		echo json_encode(array($resultArr[1], $resultArr[2]));
	} else {
		echo json_encode($resultArr[1]);
	}
}

function checkGetTranVanActive($objBusiLogic) {		// defunct
	$resultArr	= $objBusiLogic->checkGetTranVanActive($_POST['VanNo']);
	echo json_encode($resultArr);
}

function getGateTranVanStatusApp($objBusiLogic) {
	$resultArr	= $objBusiLogic->getGateTranVanStatusApp($_POST['VanStatusCd'], $_POST['GateNo'], $_POST['IsGateIn'], $_POST['LoadUnloadCd'], $_POST['TransporterTypeCd']);
	echo json_encode($resultArr);
}

function getGateTranSubCustomerNewB2B($objBusiLogic) {
	$resultArr	= $objBusiLogic->getGateTranSubCustomerNewB2B($_POST['IdVan']);
	echo json_encode($resultArr);
}

function getGateTranSubCustomerNewPre($objBusiLogic) {
	$resultArr	= $objBusiLogic->getGateTranSubCustomerNewPre((int)$_POST['GateCd'], (int)$_POST['IsGateIn']
				, (int)$_POST['GateTranNo']);
	echo json_encode($resultArr);
}

function getGateTranSubCustomerEdit($objBusiLogic) {
	$resultArr	= $objBusiLogic->getGateTranSubCustomerEdit((int)$_POST['GateCd'], (int)$_POST['IsGateIn'], (int)$_POST['GateTranNo']);
	echo json_encode($resultArr);
}

function getGateTranSubCheckEdit($objBusiLogic) {
	$resultArr	= $objBusiLogic->getGateTranSubCheckEdit((int)$_POST['GateCd'], (int)$_POST['IsGateIn'], (int)$_POST['GateTranNo']);
	echo json_encode($resultArr);
}

function getGateTranSubCheckNew($objBusiLogic) {
	$resultArr	= $objBusiLogic->getGateTranSubCheckNew((int)$_POST['LoadUnloadCd'], (int)$_POST['GateNo'], (int)$_POST['IsGateIn']
		, $_POST['SectorCd'], $_POST['IdVan'], $_POST['DriverLicNo'], (int)$_POST['GateCdLast'], (int)$_POST['IsGateInLast'], (int)$_POST['GateTranNoLast']);
	echo json_encode($resultArr);
}

function getVansNVanCapacity($objBusiLogic) {
	$resultArr	= $objBusiLogic->getVansNVanCapacity((int)$_POST['PlantCd'], $_POST['SectorCd']);
	echo json_encode($resultArr);
}

function getCityMForState($objBusiLogic) {
	$resultArr	= $objBusiLogic->getCityMForState($_POST['StateCd']);
	echo json_encode($resultArr);
}

function getVanMTransporterMDisp($objBusiLogic) {
	$resultArr	= $objBusiLogic->getPartyMDisp($_POST['TransporterTypeCd'], 'TransporterCd');
	echo json_encode($resultArr);
}

function getVanMSubTransporterEdit($objBusiLogic) {
	$resultArr	= $objBusiLogic->getVanMSubTransporterEdit($_POST['IdVan']);
	echo json_encode($resultArr);
}

function getVanDriverMTransporterMDisp($objBusiLogic) {
	$resultArr	= $objBusiLogic->getPartyMDisp($_POST['TransporterTypeCd'], 'TransporterCd');
	echo json_encode($resultArr);
}

function getVanDriverMSubTransporterEdit($objBusiLogic) {
	$resultArr	= $objBusiLogic->getVanDriverMSubTransporterEdit($_POST['DriverLicNo']);
	echo json_encode($resultArr);
}

function reportOnlineVanStatus($objBusiLogic) {
	
	$resultArr = $objBusiLogic->reportOnlineVanStatus((int)$_POST['PlantCd'], $_POST['SectorCdStr'], $_POST['StateCd'], $_POST['ItemCdStr']);
	echo json_encode($resultArr);
}

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 utilSetFORCompVan($objBusiLogic) {
	$resultArr = $objBusiLogic->utilSetFORCompVan($_POST['SectorCd'],$_POST['CompanyCd'],(int)$_POST['IsAssignVan']);
	if (sizeof($resultArr)>1) {
		echo json_encode($resultArr[1]);
	} else {
		echo json_encode(array());
	}
}

function utilSetAllVan($objBusiLogic) {
	$resultArr = $objBusiLogic->utilSetAllVan($_POST['SectorCd'],$_POST['CompanyCd'],(int)$_POST['IsAssignVan']);
	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 removeDriverPDF($objBusiLogic){
	$resultArr = $objBusiLogic->removeDriverPDF($_POST['DriverLicenceNo'], $_POST['removefield'], $_POST['filename'] );
	echo $resultArr;
}

?>