<?php 
require_once("../../includes/functions_internal_user_dryout.inc.php");
$obj = new data();
$connect = $obj->funConnect();

$inv_no = !empty($_REQUEST['inv_no']) ? mysql_real_escape_string($_REQUEST['inv_no']) : '';
$sql = 'select * from freight_invoice_master where MESSAGE="'.$inv_no.'"';
$res = mysql_query($sql);
$num = mysql_num_rows($res);
$rows = mysql_fetch_assoc($res);
if($num > 0)
{

	$array_json = [
		"voucherType" => "Receipt",
		"voucherDt" => date('d-M-Y H:i:s', strtotime($rows['DATE'])),
		"voucherNo" => $rows['MESSAGE'],
		"receivedFromErpID" => $obj->getVendorListNewData($rows['VEDNOR'],"VENDORID"),
		"receivedFromAccount" => $obj->getVendorListNewData($rows['VEDNOR'],"NAME"),
		"receivedFromAlias" => "",
		"receivedFromAliasID" => "",
		"receivedFromGroup" => "Customer",
		"receivedFromDivision" => "",
		"receivedFromAddLine1" => $obj->getVendorListNewData($rows['VEDNOR'],"STREET_1"),
		"receivedFromAddLine2" => null,
		"receivedFromLandmark" => null,
		"receivedFromCity" => $obj->getVendorListNewData($rows['VEDNOR'],"CITY"),
		"receivedFromState" => "",
		"receivedFromCountry" => $obj->getVendorListNewData($rows['VEDNOR'],"COUNTRY"),
		"receivedFromPincode" => $obj->getVendorListNewData($rows['VEDNOR'],"CITY_POSTAL_CODE"),
		"receivedFromGstNo" => $obj->getVendorDataBasedOnID($rows['VEDNOR'],'VAT_NUMBER'),
		"receivedFromPanNo" => $obj->getVendorDataBasedOnID($rows['VEDNOR'],'VAT_NUMBER'),
		"receivedFromCinNo" => "",
		"receivedFromContactName" => $obj->getVendorListNewData($rows['VEDNOR'],"STREET_2"),
		"receivedFromMobile" => $obj->getVendorDataBasedOnID($rows['VEDNOR'],'PHONE'),
		"receivedFromEmail" => $obj->getVendorDataBasedOnID($rows['VEDNOR'],'EMAILID'),
		"receivedByErpID" => $obj->getVendorListNewData($rows['SHIP_OWNER'],"VENDORID"),
		"receivedByAccount" => $obj->getVendorListNewData($rows['SHIP_OWNER'],"NAME"),
		"receivedByAlias" => "",
		"receivedByAliasID" => "",
		"receivedByGroup" => "",
		"receivedByDivision" => "",
		"receivedByAddLine1" => $obj->getVendorListNewData($rows['SHIP_OWNER'],"STREET_1"),
		"receivedByAddLine2" => null,
		"receivedByLandmark" => null,
		"receivedByCity" => $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY"),
		"receivedByState" => $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY"),
		"receivedByCountry" => $obj->getVendorListNewData($rows['SHIP_OWNER'],"COUNTRY"),
		"receivedByPincode" => $obj->getVendorListNewData($rows['SHIP_OWNER'],"CITY_POSTAL_CODE"),
		"receivedByGstNo" => $obj->getVendorListNewData($rows['SHIP_OWNER'],"VAT_NUMBER"),
		"receivedByPanNo" => $obj->getVendorListNewData($rows['SHIP_OWNER'],"VAT_NUMBER"),
		"receivedByCinNo" => null,
		"receivedByContactName" => $obj->getVendorListNewData($rows['SHIP_OWNER'],"STREET_2"),
		"receivedByMobile" => $obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'PHONE'),
		"receivedByEmail" => $obj->getVendorDataBasedOnID($rows['SHIP_OWNER'],'EMAILID'),
		"totalAmt" => $rows['NET_PAYABLE_TAX']
	];
	$sql2 = "select * from banking_details where BD_ID='".$rows['NOB']."'";
	$res2 = mysql_query($sql2);
	$rows2 = mysql_fetch_assoc($res2);

	$particular = [
		"accountErpID" => $rows2['BD_ID'],
		"accountName" => $rows2['NAME'],
		"accountAlias" => "",
		"accountAliasID" => "",
		"accountGroup" => "Bank Accounts",
		"accountDivision" => $rows2['BANK'],
		"accountAddLine1" => $rows2['ADDRESS'],
		"accountAddLine2" => "",
		"accountLandmark" => "",
		"accountCity" => "",
		"accountState" => "",
		"accountCountry" => "",
		"accountPincode" => "",
		"accountGstNo" => "",
		"accountPanNo" => "",
		"accountCinNo" => "",
		"accountContactName" => "",
		"accountMobile" => "91-6000000",
		"accountEmail" => "",
		"totalAmt" => $rows['P_AMT'],
		"billType" => 0
	];

	$data = array('inv_no' => $rows['MESSAGE'], 'jsondata' => array('response' => $array_json, 'objParticulars' => $particular, "hasErrors" => false, "errors" => null, "errorCode" => null));
}else{
	$data = array("result" => "400","status"=>'Bad Request', "message" => "Invoice date does not exist.");
}
	

mysql_close($connect);
header("Content-type: application/json");
echo json_encode($data);

?>
