0% found this document useful (0 votes)
20 views65 pages

New Changes

The document describes a class named CLEWayBillHelper, which is responsible for generating E-Way bills related to invoices and transfer orders. It includes methods for generating E-Way bills, adding headers for API requests, and handling exceptions during the process. The class utilizes various data structures to manage tax information, invoice details, and transport details necessary for E-Way bill generation.

Uploaded by

abhishek.thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views65 pages

New Changes

The document describes a class named CLEWayBillHelper, which is responsible for generating E-Way bills related to invoices and transfer orders. It includes methods for generating E-Way bills, adding headers for API requests, and handling exceptions during the process. The class utilizes various data structures to manage tax information, invoice details, and transport details necessary for E-Way bill generation.

Uploaded by

abhishek.thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 65

/// <summary>

/// This is a main class to execute the logic for E-Invoice - EWB related
activities
/// </summary>
class CLEWayBillHelper
{
System.Net.WebHeaderCollection httpHeader;
System.Net.HttpWebRequest request;
Notes reqBodyStr, resBodyStr;
Newtonsoft.Json.Linq.JTokenWriter writer;
TaxAmount totTaxAmtCGST,totTaxAmtSGST,totTaxAmtIGST,
totTaxAmtCESS;
Amount totAssValue, totInvDisc, totInvAdj;
MarkupAmount totOthCharges;
CLEInvAPIInfo apiInfo;
CLEInvParameters invParameters;
CustInvoiceJour custInvoiceJour;
CustTable custTable;
CompanyInfo companyInfo;
LogisticsPostalAddress sellerPostalAddress;
LogisticsPostalAddress buyerPostalAddress;
LogisticsPostalAddress deliveryPostalAddress;
boolean isMuliValuedParentNode;
CLEInvCancelReason irnCancelReason;
Description irnCancelRemarks;
TaxRegistrationNumber_IN sellerPrimaryGSTIN, buyerGSTIN;
CLEWBNumber ewbNumber;
boolean validResponse;
//Transfer Order cases
InventTransferJour inventTransferJour;
Amount totalInvAmt;
AmountMST totalInvAmtMST;
TaxAmount taxAmt;
//Project invoices
ProjInvoiceJour projInvoiceJour;
//Purchase returns
VendInvoiceJour vendInvoiceJour;
VendTable vendTable;
//EWB
CLEInvEWBCancelReason ewbCancelReason;
Description ewbCancelRemarks;
CLEInvIRNData irnData;
RefTableId parentTableId;
RefRecId parentRecId;
Voucher voucher;
CLEInvSupType supType;
str typ, no, dt, transMode;
Name sellerName, sellerTrdName, buyerName,
buyerTrdName;
LogisticsElectronicAddressLocator sellerPhone, sellerEmail, buyerPhone,
buyerEmail;
str city, zipcode, stateCode;
MarkupTrans markupTrans;
CurrencyCode currencyCode;
Amount tcsRate, tcsAmt, preTcsAmt;
Amount othChrgs;
//Tax
TaxAmount taxAmtCGST,taxAmtSGST,taxAmtIGST,
totalGSTAmt, taxAmtCESS, totalCESSAmt;
TaxValue taxPerCGST,taxPerSGST,taxPerIGST,
totalGSTPr, taxPerCESS, totalCESSPr;
CLEWBTransportDetails transportDetails;
CLEWBUpdateAction updateAction;
CLEWBConsolidateAction consolidationAction;
Notes ewbNumbersConsolidation;
CLEWBTransportDetailsPartB transportDetailsPartB;
CLEWBTransportDetailsExtValidity transportDetailsEwtValidity;
CLEWBTransportDetailsTranspId transportDetailsTransporterId;
CLEWBTransportDetailsMultiVehicle transportDetailsMultiVehicle;
TaxInformation_IN fromTaxInformation, toTaxInformation;
NoYes isInclTax;
Amount itemAssessableVal;
container storedHeaderDetails;

/// <summary>
/// TISEInvoiceHelper
/// </summary>
/// <returns>TISEInvoiceHelper</returns>
public static CLEWayBillHelper Construct()
{
CLEWayBillHelper ewbHelper = new CLEWayBillHelper();

return ewbHelper;
}

/// <summary>
/// Generated E-Way bill (No IRN)
/// </summary>
/// <param name = "_custInvoiceJour">CustInvoiceJour</param>
/// <returns>Boolean</returns>
public boolean generateEWayBill(CustInvoiceJour _custInvoiceJour)
{
System.Net.HttpWebResponse response;
CLRObject clrObj;
System.Exception ex;

System.IO.Stream requestStream;
System.IO.StreamWriter streamWriter;
System.IO.StreamReader streamRead;

try
{
custInvoiceJour = _custInvoiceJour;
parentTableId = custInvoiceJour.TableId;
parentRecId = custInvoiceJour.RecId;

irnData = CLEInvIRNData::findIRN(custInvoiceJour.RecId,
custInvoiceJour.TableId);
sellerPrimaryGSTIN = irnData.GSTIN;
ewbNumber = irnData.EwayBillNo;
if (ewbNumber)
{
throw warning("@TIS:EWBExists");
}
apiInfo =
CLEInvAPIInfo::findByAPIType(CLEInvAPIType::GenEwayBillNoIRN);
select firstonly invParameters;
/* if(_custInvoiceJour.InvoiceAmountMST < 50000)
{
warning("@TIS:EInvInvalidAmtEWB");
return false;
}*/

new InteropPermission(InteropKind::ClrInterop).assert();
clrObj =
System.Net.WebRequest::Create(invParameters.HostUrl+apiInfo.RequestAPI);
request = clrObj;

// adding headers
if(!this.addHeader())
{
return false;

//Req Stream
}

//Req Stream
requestStream = request.GetRequestStream();
streamWriter = new System.IO.StreamWriter(requestStream);

//Prepare Json body


this.createJSONStrBody(apiInfo.ApiId, apiInfo.APIType);

// writing JSON
streamWriter.WriteAsync(reqBodyStr);
streamWriter.Flush();
streamWriter.Close();

//Response
response = request.GetResponse();
streamRead = new System.IO.StreamReader(response.GetResponseStream());
resBodyStr = streamRead.ReadToEnd();

this.insertReqLogs(apiInfo.APIId, custInvoiceJour.InvoiceId,
apiInfo.RequestAPI
, reqBodyStr, resBodyStr, custInvoiceJour.TableId,
custInvoiceJour.RecId, CLEWBStatus::Completed);

this.getGenEWBResponseKeyValues();

if (validResponse)
{
info(strFmt("@TIS:EInvEWBGenerated", custInvoiceJour.InvoiceId));
}
else
{
warning ("@TIS:EInvEWBcantGenerated");
}
}
catch
{
//exception
ex = CLRInterop::getLastException().GetBaseException();

this.insertReqLogs(apiInfo.APIId, custInvoiceJour.InvoiceId,
apiInfo.RequestAPI
, reqBodyStr, ex.get_Message(), custInvoiceJour.TableId,
custInvoiceJour.RecId, CLEWBStatus::Error);

error(ex.get_Message());
}

return true;
}

/// <summary>
/// Generate E-Way Bill - TO (No IRN)
/// </summary>
/// <param name = "_inventTransferJour">InventTransferJour</param>
/// <returns>boolean</returns>
public boolean generateEWayBillTrans(InventTransferJour _inventTransferJour)
{
System.Net.HttpWebResponse response;
CLRObject clrObj;
System.Exception ex;

System.IO.Stream requestStream;
System.IO.StreamWriter streamWriter;
System.IO.StreamReader streamRead;

try
{
inventTransferJour = _inventTransferJour;
parentTableId = inventTransferJour.TableId;
parentRecId = inventTransferJour.RecId;

irnData = CLEInvIRNData::findIRN(inventTransferJour.RecId,
inventTransferJour.TableId);
ewbNumber = irnData.EwayBillNo;
if (ewbNumber)
{
throw warning("@TIS:EWBExists");
}
apiInfo =
CLEInvAPIInfo::findByAPIType(CLEInvAPIType::GenEwayBillNoIRN);
select firstonly invParameters;

new InteropPermission(InteropKind::ClrInterop).assert();
clrObj =
System.Net.WebRequest::Create(invParameters.HostUrl+apiInfo.RequestAPI);
request = clrObj;

// adding headers
if(!this.addHeader())
{
return false;
}

//Req Stream
requestStream = request.GetRequestStream();
streamWriter = new System.IO.StreamWriter(requestStream);

//Prepare Json body


this.createJSONStrBody(apiInfo.ApiId, apiInfo.APIType);
// writing JSON
streamWriter.WriteAsync(reqBodyStr);
streamWriter.Flush();
streamWriter.Close();

//Response
response = request.GetResponse();
streamRead = new System.IO.StreamReader(response.GetResponseStream());
resBodyStr = streamRead.ReadToEnd();

this.getGenEWBResponseKeyValues();

if ( validResponse)
{
this.insertReqLogs(apiInfo.APIId, inventTransferJour.TransferId,
apiInfo.RequestAPI
, reqBodyStr, resBodyStr, inventTransferJour.TableId,
inventTransferJour.RecId, CLEWBStatus::Completed);
info(strFmt("@TIS:EInvEWBGeneratedTO",
inventTransferJour.TransferId));
}
else
{
this.insertReqLogs(apiInfo.APIId, inventTransferJour.TransferId,
apiInfo.RequestAPI
, reqBodyStr, resBodyStr, inventTransferJour.TableId,
inventTransferJour.RecId, CLEWBStatus::Error);
warning ("@TIS:EInvEWBNotGeneratedTO");
}
}
catch
{
//exception
ex = CLRInterop::getLastException().GetBaseException();

this.insertReqLogs(apiInfo.APIId, inventTransferJour.TransferId,
apiInfo.RequestAPI
, reqBodyStr, ex.get_Message(), inventTransferJour.TableId,
inventTransferJour.RecId, CLEWBStatus::Error);

error(ex.get_Message());
}

return true;
}

/// <summary>
/// To add header
/// </summary>
/// <returns>Boolean</returns>
private boolean addHeader()
{
CLEinvAPIHeader apiHeaders;

if (!this.setVariables())
{
return false;
}

httpHeader = new System.Net.WebHeaderCollection();

while select apiHeaders


where apiHeaders.APIId == apiInfo.APIId
&& apiHeaders.HeaderType != CLEInvAPIHeaderType::ContentType
{
if (apiHeaders.HeaderType == CLEInvAPIHeaderType::GSTIN)
{
if (invParameters.StagingMode == NoYes::No)
{
httpHeader.Add(apiHeaders.Header, sellerPrimaryGSTIN);
storedHeaderDetails =
conIns(storedHeaderDetails,apiHeaders.SequenceNum,'['+sellerPrimaryGSTIN +']');
}
else
{
httpHeader.Add(apiHeaders.Header,
CLEInvGSTINUnitList::findDemoGSTIN(sellerPrimaryGSTIN).DemoRegistrationNumber);
storedHeaderDetails =
conIns(storedHeaderDetails,apiHeaders.SequenceNum,'['+CLEInvGSTINUnitList::findDemo
GSTIN(sellerPrimaryGSTIN).DemoRegistrationNumber+']');
}
}
else if (apiHeaders.HeaderType == CLEInvAPIHeaderType::OwnerId)
{
if (invParameters.StagingMode == NoYes::No)
{
httpHeader.Add(apiHeaders.Header,
CLEInvGSTINUnitList::findGSTIN(sellerPrimaryGSTIN).OwnerId);
storedHeaderDetails =
conIns(storedHeaderDetails,apiHeaders.SequenceNum,'['+CLEInvGSTINUnitList::findGSTI
N(sellerPrimaryGSTIN).OwnerId+']');
}
else
{
httpHeader.Add(apiHeaders.Header,
CLEInvGSTINUnitList::findDemoGSTIN(sellerPrimaryGSTIN).DemoOwnerId);
storedHeaderDetails =
conIns(storedHeaderDetails,apiHeaders.SequenceNum,'['+CLEInvGSTINUnitList::findDemo
GSTIN(sellerPrimaryGSTIN).DemoOwnerId+']');
}
}
else if (apiHeaders.HeaderType == CLEInvAPIHeaderType::Product)
{
httpHeader.Add(apiHeaders.Header, apiHeaders.DefaultValue);
storedHeaderDetails =
conIns(storedHeaderDetails,apiHeaders.SequenceNum,'['+apiHeaders.DefaultValue+']');
}
else if (apiHeaders.HeaderType == CLEInvAPIHeaderType::UserAuthToken)
{
httpHeader.Add(apiHeaders.Header, invParameters.AuthToken);
storedHeaderDetails =
conIns(storedHeaderDetails,apiHeaders.SequenceNum,'['+invParameters.AuthToken+']');
}
}
request.set_Headers(httpHeader);
request.set_Method(enum2str(apiInfo.ReqType));

select firstonly apiHeaders


where apiHeaders.APIId == apiInfo.APIId
&& apiHeaders.HeaderType == CLEInvAPIHeaderType::ContentType;
if (apiHeaders)
{
request.set_ContentType(apiHeaders.DefaultValue);
}

return true;
}

private boolean setVariables()


{
boolean ret = true;

if ((apiInfo.APIType == CLEInvAPIType::GenEwayBillByIRN
|| apiInfo.APIType == CLEInvAPIType::EWBUpdate
|| apiInfo.APIType == CLEInvAPIType::GenConsolidatedEWB
|| apiInfo.APIType == CLEInvAPIType::MultiVehicleEWB)
&& !this.getTransportDetails())
{
return false;
}

if (apiInfo.APIType == CLEInvAPIType::GenEwayBillNoIRN)
{
if (custInvoiceJour)
{
return this.setVariablesCustInvoice();
}
else if (inventTransferJour)
{
return this.setVariablesStockTransfer();
}
else if (vendInvoiceJour)
{
return this.setVariablesPurchReturn();
}
//else if (projInvoiceJour)
//{
// return this.setVariablesProjInvoice();
//}
}
return ret;
}

private boolean setVariablesCustInvoice()


{
CustInvoiceTrans custInvoiceTrans;
//CustInvoiceLineTaxExtensionIN lineTaxExtension;
TaxInformation_IN taxInformation, custTaxInformation;
TaxRegistrationNumbers_IN taxRegNumbers, custTaxRegNumbers;
CLEInvGSTINUnitList orgUnitList;
TaxWithholdTrans_IN taxWithholdTransLoc;
CustInvoiceLine custInvoiceLine;
TransTaxInformationRelationView taxInformationRelationView;
TransTaxInformation transTaxInfo;

transportDetails = CLEWBTransportDetails::find(parentRecId, parentTableId);


if (!transportDetails)
{
warning("@TIS:EWBTranspDetNA");
return false;
}
totalInvAmt = custInvoiceJour.InvoiceAmount;
totalInvAmtMST = custInvoiceJour.InvoiceAmountMST;

typ = enum2Value(transportDetails.DocumentType);

no = custInvoiceJour.InvoiceId;
Dt = date2str(custInvoiceJour.InvoiceDate, 123, 2, DateSeparator::Slash, 2,
DateSeparator::Slash, DateSeparator::Slash, 4);

select sum(TaxWithholdAmount),
sum(TaxWithholdAmountOrigin),TaxWithholdValue from taxWithholdTransLoc
where taxWithholdTransLoc.Voucher ==
custInvoiceJour.LedgerVoucher
&& taxWithholdTransLoc.TransDate ==
custInvoiceJour.InvoiceDate;

tcsRate = taxWithholdTransLoc.TaxWithholdValue;
tcsAmt = taxWithholdTransLoc.TaxWithholdAmount;
preTcsAmt = taxWithholdTransLoc.TaxWithholdAmountOrigin *
(custInvoiceJour.ExchRate/100);

voucher = custInvoiceJour.ledgerVoucher;

select sum(value) from markupTrans


where markupTrans.TransTableId == custInvoiceJour.TableId
&& markupTrans.TransRecId == custInvoiceJour.RecId;

othChrgs = markupTrans.Value;

//
companyInfo = CompanyInfo::find();
custTable = CustTable::find(custInvoiceJour.InvoiceAccount);

//supType = CustGroup::find(CustTable.CustGroup).CLEInvSupType;
//if (!custInvoiceJour.SumTax
// && (supType != CLEInvSupType::EXPWP && supType !=
CLEInvSupType::EXPWOP))
//{
// warning("@TIS:EInvBillOfSupply");
// return false;
//}

if (custInvoiceJour.RefNum == RefNum::SalesOrder)
{
select firstonly custInvoiceTrans
where custInvoiceTrans.SalesId == custInvoiceJour.SalesId
&& custInvoiceTrans.InvoiceId == custInvoiceJour.InvoiceId
&& custInvoiceTrans.InvoiceDate == custInvoiceJour.InvoiceDate
&& custInvoiceTrans.numberSequenceGroup ==
custInvoiceJour.numberSequenceGroup;
//taxInformation = TaxInformation_IN::find(salesIn.TaxInformation);
//custTaxInformation =
TaxInformation_IN::find(salesIn.CustomerTaxInformation);

select firstonly transTaxInfo


join taxInformationRelationView
where taxInformationRelationView.TransTaxInformationRefRecId ==
transTaxInfo.RecId
&& taxInformationRelationView.TransactionRefTableId ==
custInvoiceTrans.TableId
&& taxInformationRelationView.TransactionRefRecId ==
custInvoiceTrans.RecId;

taxInformation = TaxInformation_IN::find(transTaxInfo.TaxInformation);
custTaxInformation =
TaxInformation_IN::find(transTaxInfo.CustomerTaxInformation);
}
else if (custInvoiceJour.RefNum == RefNum::Cust)
{
custInvoiceLine =
CustInvoiceLine::findByParentRecId(custInvoiceJour.custInvoiceTable().RecId);

select firstonly transTaxInfo


join taxInformationRelationView
where taxInformationRelationView.TransTaxInformationRefRecId ==
transTaxInfo.RecId
&& taxInformationRelationView.TransactionRefTableId ==
custInvoiceLine.TableId
&& taxInformationRelationView.TransactionRefRecId ==
custInvoiceLine.RecId;

taxInformation = TaxInformation_IN::find(transTaxInfo.TaxInformation);
custTaxInformation =
TaxInformation_IN::find(transTaxInfo.CustomerTaxInformation);
}

taxRegNumbers = TaxRegistrationNumbers_IN::find(taxInformation.GSTIN);
sellerPostalAddress =
LogisticsPostalAddress::findByLocation(taxInformation.RegistrationLocation);

//buyerGSTIN = custTable.GST_IN();
custTaxRegNumbers =
TaxRegistrationNumbers_IN::find(custTaxInformation.GSTIN);
buyerGSTIN = custTaxRegNumbers.RegistrationNumber;
if (buyerGSTIN)
{
supType = CLEInvSupType::B2B;
}
//if(!buyerGSTIN
// && (supType != CLEInvSupType::EXPWP && supType !=
CLEInvSupType::EXPWOP))
//{

// warning("@TIS:EInvUnregisteredGSTINCust");
// return false;

//}
if(!custTaxInformation)
{
buyerPostalAddress =
LogisticsPostalAddress::findByLocation(LogisticsPostalAddress::findRecId(custInvoic
eJour.InvoicePostalAddress).Location);
}
else
{

//buyerPostalAddress =
LogisticsPostalAddress::findByLocation(LogisticsPostalAddress::findRecId(custInvoic
eJour.InvoicePostalAddress).Location);
buyerPostalAddress =
LogisticsPostalAddress::findByLocation(custTaxInformation.RegistrationLocation);
}
deliveryPostalAddress =
LogisticsPostalAddress::findByLocation(LogisticsPostalAddress::findRecId(custInvoic
eJour.DeliveryPostalAddress).Location);
sellerPrimaryGSTIN = taxRegNumbers.RegistrationNumber;

//for demo only


if (invParameters.StagingMode)
{
select firstOnly orgUnitList
where orgUnitList.StateId ==
LogisticsAddressState::find(sellerPostalAddress.CountryRegionId,
sellerPostalAddress.State).StateCode_IN;

//sellerPrimaryGSTIN =
TaxRegistrationNumbers_IN::find( orgUnitList.GSTRegistrationNumber).RegistrationNu
mber;
sellerPrimaryGSTIN =orgUnitList.DemoRegistrationNumber;
}
//for demo only - finish

sellerPhone = subStr(strKeep(companyInfo.phone(),
CLEInvConstant::phone),1,12);
sellerEmail = companyInfo.email();
sellerName = companyInfo.Name();
sellerTrdName = companyInfo.NameAlias;

buyerPhone = strKeep(custTable.phone(),CLEInvConstant::phone);
buyerEmail = custTable.email();
buyerName = custTable.Name();
buyerTrdName = custTable.nameAlias();
zipcode = strRemoveCr(buyerPostalAddress.zipCode);
city = buyerPostalAddress.City;
stateCode =
LogisticsAddressState::find(buyerPostalAddress.CountryRegionId,
buyerPostalAddress.State).StateCode_IN;

return true;
}

private boolean setVariablesStockTransfer()


{
InventTransferJourLine inventTransferJourLine;
//InventTransferLine inventTransferLine;
//inventTransferLine_IN inventTransferLineIn;
//TaxInformation_IN fromTaxInformation, toTaxInformation;
TaxRegistrationNumbers_IN fromTaxRegNumbers, toTaxRegNumbers;
InventLocation inventLocationFrom, inventLocationTo;
CLEInvGSTINUnitList orgUnitList;
TransTaxInformationRelationView taxInformationRelationView;
TransTaxInformation transTaxInfo;
//TaxWithholdTrans_IN taxWithholdTransLoc;

transportDetails = CLEWBTransportDetails::find(parentRecId, parentTableId);


if (!transportDetails)
{
warning("@TIS:EWBTranspDetNA");
return false;
}
totalInvAmt = this.invTotalAmtRecve_IN();
totalInvAmtMST = totalInvAmt;

typ = enum2Value(transportDetails.DocumentType);

if
(InventTransferTable::find(inventTransferJour.TransferId).TransferType_IN ==
TransferType_IN::TransferOrder)
{
return this.setVariablesTransferOrder();
}

parentTableId = inventTransferJour.TableId;
parentRecId = inventTransferJour.RecId;

no = inventTransferJour.VoucherId;
Dt = date2str(inventTransferJour.TransDate,123, 2, DateSeparator::Slash, 2,
DateSeparator::Slash, DateSeparator::Slash, 4);

voucher = inventTransferJour.VoucherId;

select sum(value) from markupTrans


where markupTrans.TransTableId == inventTransferJour.TableId
&& markupTrans.TransRecId == inventTransferJour.RecId;

othChrgs = markupTrans.Value;

//
supType = CLEInvSupType::B2B;
companyInfo = CompanyInfo::find();

InventTransferLine transferLine;

select firstOnly transferLine


where transferLine.TransferId == inventTransferJour.TransferId;

select firstOnly inventTransferJourLine


where inventTransferJourLine.TransferId ==
inventTransferJour.TransferId
&& inventTransferJourLine.VoucherId ==
inventTransferJour.VoucherId;
/*
while select transTaxInfo
exists join taxInformationRelationView
where taxInformationRelationView.TransTaxInformationRefRecId ==
transTaxInfo.RecId
&& taxInformationRelationView.TransactionRefTableId ==
inventTransferJourLine.TableId
&& taxInformationRelationView.TransactionRefRecId ==
inventTransferJourLine.RecId
{
if (transTaxInfo.Type ==
TransTaxInformationType_IN::InventTransferFrom)
{
fromTaxInformation =
TaxInformation_IN::find(transTaxInfo.TaxInformation);
}
else if (transTaxInfo.Type ==
TransTaxInformationType_IN::InventTransferTo)
{
toTaxInformation =
TaxInformation_IN::find(transTaxInfo.TaxInformation);
}
}
*/

while select transTaxInfo


join taxInformationRelationView
where transTaxInfo.RecId ==
taxInformationRelationView.TransTaxInformationRefRecId
&& taxInformationRelationView.TransactionRefTableId ==
transferLine.TableId
&& taxInformationRelationView.TransactionRefRecId ==
transferLine.RecId
{
if (transTaxInfo.Type ==
TransTaxInformationType_IN::InventTransferFrom)
{
fromTaxInformation =
TaxInformation_IN::find(transTaxInfo.TaxInformation);
}
else if (transTaxInfo.Type ==
TransTaxInformationType_IN::InventTransferTo)
{
toTaxInformation =
TaxInformation_IN::find(transTaxInfo.TaxInformation);
}
}

//if (!fromTaxInformation)
//{
// warning("@TIS:EInvUnavailableFromTaxInfo");
// return false;
//}
//if (!toTaxInformation)
//{
// warning("@TIS:EInvUnavailableToTaxInfo");
// return false;
//}

//fromTaxInformation =
TaxInformation_IN::find(inventTransferLineIn.FromTaxInformation);
fromTaxRegNumbers =
TaxRegistrationNumbers_IN::find(fromTaxInformation.GSTIN);
sellerPostalAddress =
LogisticsPostalAddress::findByLocation(fromtaxInformation.RegistrationLocation);
inventLocationFrom =
InventLocation::find(inventTransferJour.InventLocationIdFrom);
sellerPrimaryGSTIN = fromtaxRegNumbers.RegistrationNumber;

//toTaxInformation =
TaxInformation_IN::find(inventTransferLineIn.ToTaxInformation);
toTaxRegNumbers =
TaxRegistrationNumbers_IN::find(totaxInformation.GSTIN);
buyerPostalAddress =
LogisticsPostalAddress::findByLocation(totaxInformation.RegistrationLocation);
inventLocationTo =
InventLocation::find(inventTransferJour.InventLocationIdTo);
buyerGSTIN = totaxRegNumbers.RegistrationNumber;
deliveryPostalAddress = buyerPostalAddress;

if(!sellerPrimaryGSTIN)
{
warning("@TIS:EInvUnGSTINforFrom");
return false;
}
//if(!buyerGSTIN)
//{
// warning("@TIS:EInvUnGSTINforTO");
// return false;
//}

if(!totaxInformation)
{
buyerPostalAddress =
LogisticsPostalAddress::findByLocation(InventLocation::find(inventTransferJour.Inve
ntLocationIdTo).logisticsPostalAddress().Location);
}
else
{

//buyerPostalAddress =
LogisticsPostalAddress::findByLocation(LogisticsPostalAddress::findRecId(custInvoic
eJour.InvoicePostalAddress).Location);
buyerPostalAddress =
LogisticsPostalAddress::findByLocation(totaxInformation.RegistrationLocation);
}

//for demo only


if (invParameters.StagingMode)
{
select firstOnly orgUnitList
where orgUnitList.StateId ==
LogisticsAddressState::find(sellerPostalAddress.CountryRegionId,
sellerPostalAddress.State).StateCode_IN;

//sellerPrimaryGSTIN
=TaxRegistrationNumbers_IN::find( orgUnitList.GSTRegistrationNumber).RegistrationN
umber;
sellerPrimaryGSTIN =orgUnitList.DemoRegistrationNumber;
}
//for demo only - finish

sellerPhone = subStr(strKeep(companyInfo.phone(), '1234567890'),1,12);


sellerEmail = companyInfo.email();
sellerName = inventLocationFrom.Name;
sellerTrdName = inventLocationFrom.Name;

buyerPhone = strKeep(sellerPhone,'1234567890');
buyerEmail = sellerEmail;
buyerName = inventLocationTo.Name;
buyerTrdName = inventLocationTo.Name;
zipcode = strRemoveCr(buyerPostalAddress.ZipCode);
city = buyerPostalAddress.City;
stateCode =
LogisticsAddressState::find(buyerPostalAddress.CountryRegionId,
buyerPostalAddress.State).StateCode_IN;

return true;
}

private boolean setVariablesTransferOrder()


{
//InventTransferJourLine inventTransferJourLine;
//InventTransferLine inventTransferLine;
//inventTransferLine_IN inventTransferLineIn;
//TaxInformation_IN fromTaxInformation, toTaxInformation;
TaxRegistrationNumbers_IN fromTaxRegNumbers, toTaxRegNumbers;
InventLocation inventLocationFrom, inventLocationTo;
CLEInvGSTINUnitList orgUnitList;
//TaxWithholdTrans_IN taxWithholdTransLoc;

parentTableId = inventTransferJour.TableId;
parentRecId = inventTransferJour.RecId;

totalInvAmt = this.invTotalAmtRecve_IN();
totalInvAmtMST = totalInvAmt;
if (totalInvAmt >= 0)
{
typ = CLEInvConstant::INV;
}
else
{
typ = CLEInvConstant::CRN;
}

no = inventTransferJour.VoucherId;
Dt = date2str(inventTransferJour.TransDate,123, 2, DateSeparator::Slash, 2,
DateSeparator::Slash, DateSeparator::Slash, 4);

voucher = inventTransferJour.VoucherId;

//

//if (!taxAmt)
//{
// warning("@TIS:EInvBillOfSupply");
// return false;
//}
select sum(value) from markupTrans
where markupTrans.TransTableId == inventTransferJour.TableId
&& markupTrans.TransRecId == inventTransferJour.RecId;

othChrgs = markupTrans.Value;

//
supType = CLEInvSupType::B2B;
companyInfo = CompanyInfo::find();

inventLocationFrom =
InventLocation::find(inventTransferJour.InventLocationIdFrom);
sellerPostalAddress =
LogisticsPostalAddress::findRecId(inventTransferJour.FromPostalAddress);
fromTaxInformation =
TaxInformation_IN::findDefaultbyLocation(sellerPostalAddress.Location);
fromTaxRegNumbers =
TaxRegistrationNumbers_IN::find(fromTaxInformation.GSTIN);
sellerPrimaryGSTIN = fromtaxRegNumbers.RegistrationNumber;

inventLocationTo =
InventLocation::find(inventTransferJour.InventLocationIdTo);
// 21-02-2023
// if(inventTransferJour.InventLocationIdTo == 'YCH' ||
//inventTransferJour.InventLocationIdTo == 'DEL')
// 21-02-2023
if(inventTransferJour.InventLocationIdTo)
{
buyerPostalAddress =
LogisticsPostalAddress::findRecId(inventTransferJour.ToPostalAddress);
}
else
{
buyerPostalAddress = LogisticsPostalAddress::findByLocation(
DirPartyLocation::findPrimaryPartyLocation(

CustTable::find(inventTransferJour.InventLocationIdTo).Party).Location);
}
// 21-02-2023
//buyerPostalAddress =
LogisticsPostalAddress::findRecId(inventTransferJour.ToPostalAddress);
// 21-02-2023
toTaxInformation =
TaxInformation_IN::findDefaultbyLocation(buyerPostalAddress.Location);
toTaxRegNumbers =
TaxRegistrationNumbers_IN::find(toTaxInformation.GSTIN);
buyerGSTIN = toTaxRegNumbers.RegistrationNumber;

if (!fromTaxInformation)
{
warning("@TIS:EInvUnavailableFromTaxInfo");
return false;
}
if (!toTaxInformation)
{
warning("@TIS:EInvUnavailableToTaxInfo");
return false;
}
if(!sellerPrimaryGSTIN)
{
warning("@TIS:EInvUnGSTINforFrom");
return false;
}
if(!buyerGSTIN)
{
warning("@TIS:EInvUnGSTINforTO");
return false;
}

//if(!totaxInformation)
//{
// buyerPostalAddress =
LogisticsPostalAddress::findByLocation(InventLocation::find(inventTransferJour.Inve
ntLocationIdTo).logisticsPostalAddress().Location);
//}
//else
//{

// //buyerPostalAddress =
LogisticsPostalAddress::findByLocation(LogisticsPostalAddress::findRecId(custInvoic
eJour.InvoicePostalAddress).Location);
// buyerPostalAddress =
LogisticsPostalAddress::findByLocation(totaxInformation.RegistrationLocation);
//}

//for demo only


if (invParameters.StagingMode)
{
select firstOnly orgUnitList
where orgUnitList.StateId ==
LogisticsAddressState::find(sellerPostalAddress.CountryRegionId,
sellerPostalAddress.State).StateCode_IN;

//sellerPrimaryGSTIN =
TaxRegistrationNumbers_IN::find( orgUnitList.GSTRegistrationNumber).RegistrationNu
mber;
sellerPrimaryGSTIN =orgUnitList.DemoRegistrationNumber;
}
//for demo only - finish

sellerPhone = subStr(strKeep(companyInfo.phone(), '1234567890'),1,12);


sellerEmail = companyInfo.email();
sellerName = inventLocationFrom.Name;
sellerTrdName = inventLocationFrom.Name;

buyerPhone = strKeep(sellerPhone,'1234567890');
buyerEmail = sellerEmail;
buyerName = inventLocationTo.Name;
buyerTrdName = inventLocationTo.Name;
zipcode = strRemoveCr(buyerPostalAddress.ZipCode);
city = buyerPostalAddress.City;
stateCode =
LogisticsAddressState::find(buyerPostalAddress.CountryRegionId,
buyerPostalAddress.State).StateCode_IN;

return true;
}

/// <summary>
/// Create Request Body - JSON
/// </summary>
/// <param name = "_apiId">Int</param>
/// <param name = "_apiType">CLEInvAPIType</param>
protected void createJSONStrBody(Int _apiId, CLEInvAPIType _apiType =
CLEInvAPIType::GenEwayBillNoIRN)
{
CLEInvAPIRequestBody eInvReqBody;
CLRObject clrObj;
Newtonsoft.Json.Linq.JObject jObject;
boolean transactionNode;
;
writer = new Newtonsoft.Json.Linq.JTokenWriter();

//Main loop for request paramaters


while select eInvReqBody order by KeyId asc
where eInvReqBody.APIId == _apiId
&& eInvReqBody.IsEnabled == NoYes::Yes
&& eInvReqBody.IsRequestParameter == NoYes::Yes
{
if (_apiType == CLEInvAPIType::GenEwayBillNoIRN
&& eInvReqBody.KeyFieldName == CLEInvConstant::ExpShipDtls)
{
//export
if (custInvoiceJour &&
LogisticsPostalAddress::findRecId(custInvoiceJour.DeliveryPostalAddress).CountryReg
ionId != CLEInvConstant::IND)
{
this.prepareJsonNode(eInvReqBody.ValueScope,
eInvReqBody.KeyFieldName, eInvReqBody.MultiValue);
}
else
{
continue;
}
}
else
{
this.prepareJsonNode(eInvReqBody.ValueScope,
eInvReqBody.KeyFieldName, eInvReqBody.MultiValue);
}

//Actual param settings


if (einvReqBody.KeyFieldName == CLEInvConstant::transaction)
{
//transaction start
transactionNode = true;
}

if (_apiType == CLEInvAPIType::GenEwayBillNoIRN)//To Generate EWB


{
this.parmsGenerateEWB(eInvReqBody);
}
else if (_apiType == CLEInvAPIType::CancelEwayBill) //To Cancel E-Way
bill
{
this.parmsCancelEWB(eInvReqBody);
}
else if (_apiType == CLEInvAPIType::EWBUpdate)//update E-Way Bill
{
this.parmsUpdateEWB(eInvReqBody);
}
else if (_apiType == CLEInvAPIType::GenConsolidatedEWB)//Consolidate E-
Way Bill
{
this.parmsGenerateConsolidatedEWB(eInvReqBody);
}
else if (_apiType == CLEInvAPIType::MultiVehicleEWB)//Multi vehicle E-
Way Bill
{
this.parmsMultiVehEWB(eInvReqBody);
}
}
//Req body loop endss

if (transactionNode)
{
writer.WriteEndObject();
}
writer.WriteEndObject();

if (isMuliValuedParentNode)
{
writer.WriteEndArray();
}

clrObj = writer.get_Token();
jObject = clrObj;

reqBodyStr = jObject.ToString();
}

/// <summary>
/// Populate EWB(No IRN) generation parameters
/// </summary>
/// <param name = "_einvReqBody">CLEInvAPIRequestBody</param>
private void parmsGenerateEWB(CLEInvAPIRequestBody _einvReqBody)
{
if (_einvReqBody.KeyFieldName == CLEInvConstant::DocumentNumber)
{
this.writeStrValue(no);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::DocumentType)
{
this.writeStrValue(typ);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::DocumentDate)
{
this.writeStrValue(dt);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::SupplyType)
{
this.writeStrValue(enum2Value(transportDetails.SupplyType));
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::SubSupplyType)
{
this.writeStrValue(enum2Value(transportDetails.SubSupplyType));
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::SubSupplyTypeDesc)
{
this.writeStrValue('NA');
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TransactionType)
{
this.writeStrValue(enum2str(transportDetails.TransactionType));
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::BuyerDtls)
{
//Buyer details
this.getBuyerDtls(_einvReqBody.KeyId);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::SellerDtls)
{
//Seller details
this.getSellerDtls(_einvReqBody.KeyId);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::ExpShipDtls)
{
this.getEwbExpDtls(_einvReqBody.KeyId);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::DispDtls)
{
//Dispatch from details
this.getDispDtls(_einvReqBody.KeyId);
}
//else if (_einvReqBody.KeyFieldName == CLEInvConstant::ShipDtls)
//{
// //Ship To details object
// this.getShipDtls(_einvReqBody.KeyId);
//}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::ItemList)
{
//List of one or more Item objects
if (custInvoiceJour)
{
this.getItemList(_einvReqBody.KeyId);
}
else if (inventTransferJour)
{
this.getItemListTransfer(_einvReqBody.KeyId);
}
else if (vendInvoiceJour)
{
this.getItemListPurchReturn(_einvReqBody.KeyId);
}
//else if (projInvoiceJour)
//{
// //this.getItemListProj(_einvReqBody.KeyId);
//}
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TotalInvoiceAmount)
{
writer.WriteValue(abs(totalInvAmtMST));
//writer.WriteValue(abs(totAssValue));
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TotalCgstAmount)
{
writer.WriteValue(totTaxAmtCGST);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TotalSgstAmount)
{
writer.WriteValue(totTaxAmtSGST);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TotalIgstAmount)
{
writer.WriteValue(totTaxAmtIGST);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TotalCessAmount)
{
writer.WriteValue(totTaxAmtCESS);
}
else if (_einvReqBody.KeyFieldName ==
CLEInvConstant::TotalCessNonAdvolAmount)
{
writer.WriteValue(0);
}
else if (_einvReqBody.KeyFieldName ==
CLEInvConstant::TotalAssessableAmount)
{
writer.WriteValue(totAssValue);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::OtherAmount)
{
writer.WriteValue(othChrgs);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::OtherTcsAmount)
{
writer.WriteValue(tcsAmt);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TransId)
{
this.writeStrValue(transportDetails.TransportId);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TransName)
{
this.writeStrValue(transportDetails.TransporterName);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TransMode)
{
if (transportDetails.EWBType == CLEWayBillStatus::PartA)
{
this.writeStrValue('');
}
else
{
this.writeStrValue(enum2Str(transportDetails.TransportMode));
}
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::Distance)
{
this.writeIntValue(transportDetails.Distance);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TransDocNo)
{
if (transportDetails.EWBType == CLEWayBillStatus::PartA)
{
this.writeStrValue('');
}
else
{
this.writeStrValue(transportDetails.TransportDocumentNumber);
}
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TransDocDt)
{
this.writeStrValue(date2str(transportDetails.TransportDocDate, 123, 2,
DateSeparator::Slash, 2, DateSeparator::Slash, DateSeparator::Slash, 4));
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::VehNo)
{
if (transportDetails.EWBType == CLEWayBillStatus::PartA)
{
this.writeStrValue('');
}
else
{
this.writeStrValue(transportDetails.VehicleNumber);
}
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::VehType)
{
if (transportDetails.EWBType == CLEWayBillStatus::PartA)
{
this.writeStrValue('');
}
else
{
this.writeStrValue(enum2Value(transportDetails.VehicleType));
}
}
}

/// <summary>
///
/// </summary>
private void getGenEWBResponseKeyValues()
{
Map map, map1;
MapEnumerator mapEnumeratorMain, mapEnumeratorGovtResp;
boolean inValid;
container dtValue;
container successValue;
container govtResp;
CLEWBUpdateHistory updateHistory;
CLEInvGSTINUnitList demogst;

map = RetailCommonWebAPI::getMapFromJsonString(resBodyStr);
mapEnumeratorMain = map.getEnumerator();
irnData = CLEInvIRNData::findIRN(parentRecId, parentTableId);
if (irnData)
{
irnData.selectForUpdate(true);
}

while (mapEnumeratorMain.moveNext() && !inValid)


{

switch (mapEnumeratorMain.currentKey())
{
case CLEInvConstant::ewb_status:

if (mapEnumeratorMain.currentValue() !=
CLEInvConstant::GENERATED || mapEnumeratorMain.currentValue() Like 'PARTA*')
{
inValid = false;
}
else
{
inValid = true;
}
break;

case CLEInvConstant::govt_response:

govtResp = mapEnumeratorMain.currentValue();
map1 = Map::create(govtResp);

mapEnumeratorGovtResp = map1.getEnumerator();
while (mapEnumeratorGovtResp.moveNext() && !inValid)
{
switch (mapEnumeratorGovtResp.currentKey())
{
case CLEInvConstant::Success:
successValue =
mapEnumeratorGovtResp.currentValue();
if (con2Str(successValue) != 'Y')
{
inValid = true;
}
break;

case CLEInvConstant::ewbNo:
irnData.EwayBillNo =
mapEnumeratorGovtResp.currentValue();
break;

case CLEInvConstant::EwbDt:
dtValue = mapEnumeratorGovtResp.currentValue();
irnData.EWayDateTime =
str2datetime(con2str(dtValue), 321);
dtValue = conNull();
break;

case CLEInvConstant::EwbValidTill:
dtValue = mapEnumeratorGovtResp.currentValue();
irnData.EWayValidDateTime =
str2datetime(con2str(dtValue), 321);
dtValue = conNull();
break;
case CLEInvConstant::errors:
case CLEInvConstant::errorDetails:
inValid = true;
break;

case CLEInvConstant::Remarks:
//irnData.EWBRemarks =
mapEnumeratorMain.currentValue();
break;
}
}
break;

if (!inValid)
{
ttsBegin;
irnData.IsEWBCancelled = NoYes::No;
if (irnData)
{
irnData.update();
}
else
{
irnData.ParentTableId = parentTableId;
irnData.ParentRecId = parentRecId;
irnData.InvoiceId = custInvoiceJour.InvoiceId;
if(!invParameters.StagingMode)
{
irnData.GSTIN = sellerPrimaryGSTIN;
}
else
{
irnData.GSTIN = sellerPrimaryGSTIN;
}
irnData.insert();
}
ttsCommit;

updateHistory.IRNDataRefRecId = irnData.RecId;
updateHistory.EwayBillNo = irnData.EwayBillNo;
updateHistory.UpdateDateTime = irnData.EWayDateTime;
updateHistory.EWayValidDateTime = irnData.EWayValidDateTime;
updateHistory.UpdateAction = updateAction;
irnData.CLEWBStatus = CLEWBStatus::Completed;
updateHistory.insert();

validResponse = true;
}
else
{
validResponse = false;
}
}
/// <summary>
/// Cancel E-Way Bill
/// </summary>
/// <param name = "_refTableId">RefTableId</param>
/// <param name = "_refrecId">RefRecId</param>
/// <param name = "_documentId">Description</param>
/// <param name = "_cancelReason">CLEInvEWBCancelReason</param>
/// <param name = "_cancelRemarks">Description</param>
public void cancelEWB(RefTableId _refTableId, RefRecId _refrecId, Description
_documentId
, CLEInvEWBCancelReason _cancelReason, Description _cancelRemarks)
{
System.Net.HttpWebResponse response;
CLRObject clrObj;
System.Exception ex;

System.IO.Stream requestStream;
System.IO.StreamWriter streamWriter;
System.IO.StreamReader streamRead;

try
{
parentTableId = _refTableId;
parentRecId = _refrecId;

apiInfo =
CLEInvAPIInfo::findByAPIType(CLEInvAPIType::CancelEwayBill);
irnData = CLEInvIRNData::findValidEWB(parentRecId,
parentTableId);
sellerPrimaryGSTIN = irnData.GSTIN;
ewbNumber = irnData.EwayBillNo;
if (!ewbNumber)
{
throw error("@TIS:EWayBillInvalidForCancel");
}

select firstonly invParameters;


new InteropPermission(InteropKind::ClrInterop).assert();
clrObj =
System.Net.WebRequest::Create('https://api-sandbox.clear.in/einv/v2/eInvoice/
ewaybill/cancel'); // invParameters.HostUrl+apiInfo.RequestAPI
request = clrObj;

// adding headers
this.addHeader();

//Req Stream
requestStream = request.GetRequestStream();
streamWriter = new System.IO.StreamWriter(requestStream);

//Prepare Json body


ewbCancelReason = _cancelReason;
ewbCancelRemarks= _cancelRemarks;
this.createJSONStrBody(apiInfo.ApiId, apiInfo.APIType);

// writing JSON
streamWriter.WriteAsync(reqBodyStr);
streamWriter.Flush();
streamWriter.Close();
//Response
response = request.GetResponse();
streamRead = new System.IO.StreamReader(response.GetResponseStream());

resBodyStr = streamRead.ReadToEnd();

this.insertReqLogs(apiInfo.APIId, _documentId, apiInfo.RequestAPI


, reqBodyStr, resBodyStr, _refTableId, _refRecId,
CLEWBStatus::Completed);

this.getCancelEWBResponseKeyValues();

if (validResponse)
{
if (_refTableId == tableNum(CustInvoiceJour))
{
info(strFmt("@TIS:EInvEWBCancelled", _documentId));
}
else if (_refTableId == tableNum(InventTransferJour))
{
info(strFmt("@TIS:EInvEWBCancelledforTO", _documentId));
}
else if (_refTableId == tableNum(ProjInvoiceJour))
{
info(strFmt("@TIS:EWayBillCancelledForPro", _documentId));
}
}
else
{
warning ("@TIS:EInvEWBCantCancelled");
}
}
catch
{
//exception
ex = CLRInterop::getLastException().GetBaseException();
this.insertReqLogs(apiInfo.APIId, _documentId, apiInfo.RequestAPI,
con2Str(storedHeaderDetails)+' '+ reqBodyStr, ex.get_Message(), _refTableId,
_refRecId,CLEWBStatus::Error);
error(ex.get_Message());
}
}

/// <summary>
/// Populate E-way bill cancellation parameters
/// </summary>
/// <param name = "_einvReqBody">CLEInvAPIRequestBody</param>
private void parmsCancelEWB(CLEInvAPIRequestBody _einvReqBody)
{
if (_einvReqBody.KeyFieldName == CLEInvConstant::ewbNo)
{
//IRN to be cancelled
this.writeStrValue(ewbNumber);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::cancelRsnCode)
{
//cancel reason
if (ewbCancelReason == CLEInvEWBCancelReason::Duplicate)
{
this.writeStrValue('DUPLICATE');
}
else if (ewbCancelReason == CLEInvEWBCancelReason::DataEntryMistake)
{
this.writeStrValue('DATA_ENTRY_MISTAKE');
}
else if (ewbCancelReason == CLEInvEWBCancelReason::OrderCancelled)
{
this.writeStrValue('ORDER_CANCELLED');
}
else if (ewbCancelReason == CLEInvEWBCancelReason::Others)
{
this.writeStrValue('OTHERS');
}
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::cancelRmrk)
{
//Cancellation remarks
this.writeStrValue(ewbCancelRemarks);
}
}

private void getCancelEWBResponseKeyValues()


{
Map map;
MapEnumerator mapEnumeratorMain;
boolean Valid;
CLEWBUpdateHistory updateHistory;
container cancelValue;

map = RetailCommonWebAPI::getMapFromJsonString(resBodyStr);

mapEnumeratorMain = map.getEnumerator();

if (!irnData)
{
return;
}
irnData.selectForUpdate(true);

while ( mapEnumeratorMain.moveNext() && !Valid)


{
switch (mapEnumeratorMain.currentKey())
{
case CLEInvConstant::ewbStatus:
cancelValue = mapEnumeratorMain.currentValue();

if (con2Str(cancelValue) == CLEInvConstant::CANCELLED)
{
Info( strFmt(' CurrVal %1 ',con2Str(cancelValue) ) );
Valid = true;
}
break;
}
}

if (Valid)
{
ttsBegin;
updateHistory.IRNDataRefRecId = irnData.RecId;
updateHistory.EwayBillNo = irnData.EwayBillNo;
updateHistory.UpdateDateTime = irnData.EWayDateTime;
updateHistory.EWayValidDateTime = irnData.EWayValidDateTime;
updateHistory.UpdateAction = CLEWBUpdateAction::CANCELLED;
updateHistory.EWBCancelReason = ewbCancelReason;
updateHistory.EWBCancelRemarks = ewbCancelRemarks;
updateHistory.insert();

irnData.IsEWBCancelled = NoYes::Yes;
irnData.EwayBillNo = '';
irnData.EWBCancelReason = ewbCancelReason;
irnData.EWBCancelRemarks = ewbCancelRemarks;
irnData.update();

ttsCommit;

validResponse = true;
}
else
{
validResponse = false;
}
}

private void getBuyerDtls(Integer _keyId)


{
CLEInvAPIRequestBody eInvReqBodyTranDtls;

while select eInvReqBodyTranDtls


where eInvReqBodyTranDtls.APIId == apiInfo.APIId
&& eInvReqBodyTranDtls.ParentKeyId == _keyId
&& eInvReqBodyTranDtls.IsEnabled == NoYes::Yes
{
this.prepareJsonNode(eInvReqBodyTranDtls.ValueScope,
eInvReqBodyTranDtls.KeyFieldName, eInvReqBodyTranDtls.MultiValue);

if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Gstin)
{
if (buyerPostalAddress.CountryRegionId == CLEInvConstant::IND)
{
if (buyerGSTIN)
{
this.writeStrValue(buyerGSTIN);
}
else
{

this.writeStrValue(strfmt("@SYS82282",eInvReqBodyTranDtls.DefaultValue));
}
}
else
{

this.writeStrValue(strfmt("@SYS82282",eInvReqBodyTranDtls.DefaultValue));
}
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::LglNm)
{
this.writeStrValue(buyerName);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::TrdNm)
{
this.writeStrValue(buyerTrdName);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Pos)
{
if (deliveryPostalAddress.CountryRegionId == CLEInvConstant::IND)
{
this.writeStrValue(strfmt("@SYS82282",
LogisticsAddressState::find(deliveryPostalAddress.CountryRegionId,
deliveryPostalAddress.State).StateCode_IN));
}
else
{

this.writeStrValue(strfmt("@SYS82282",eInvReqBodyTranDtls.DefaultValue));
}
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Addr1)
{
this.writeStrValue(subStr(strfmt("@SYS82282",
strRemoveCr(buyerPostalAddress.Street)), 1, 100));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Addr2)
{
writer.WriteNull();
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Loc)
{
this.writeStrValue(strfmt("@SYS82282", city));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Pin)
{
if (buyerPostalAddress.CountryRegionId == CLEInvConstant::IND)
{
this.writeStrValue(strfmt("@SYS82282", zipcode));
}
else
{

this.writeStrValue(strfmt("@SYS82282",eInvReqBodyTranDtls.DefaultValue));
}
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Stcd)
{
if (buyerPostalAddress.CountryRegionId == CLEInvConstant::IND)
{
this.writeStrValue(strfmt("@SYS82282", stateCode));
}
else
{

this.writeStrValue(strfmt("@SYS82282",eInvReqBodyTranDtls.DefaultValue));
}
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Ph)
{
this.writeStrValue(buyerPhone);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Em)
{
this.writeStrValue(buyerEmail);
}

//close object node


writer.WriteEndObject();
}

private void getDispDtls(Integer _keyId)


{
CLEInvAPIRequestBody eInvReqBodyTranDtls;

//if no separate dispatch address


if (sellerPostalAddress.Address ==
CLEInvConstant::SeparateDispatchAddresse)
{
writer.WriteEndObject();
return;
}

while select eInvReqBodyTranDtls


where eInvReqBodyTranDtls.APIId == apiInfo.APIId
&& eInvReqBodyTranDtls.ParentKeyId == _keyId
&& eInvReqBodyTranDtls.IsEnabled == NoYes::Yes
{
this.prepareJsonNode(eInvReqBodyTranDtls.ValueScope,
eInvReqBodyTranDtls.KeyFieldName, eInvReqBodyTranDtls.MultiValue);
if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Nm)
{
this.writeStrValue(eInvReqBodyTranDtls.DefaultValue);//for test
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Addr1)
{
this.writeStrValue(strfmt("@SYS82282",
sellerPostalAddress.Street));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Addr2)
{
writer.WriteNull();
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Loc)
{
this.writeStrValue(strfmt("@SYS82282", sellerPostalAddress.City));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Pin)
{
this.writeStrValue(strfmt("@SYS82282",
sellerPostalAddress.zipCode));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Stcd)
{
this.writeStrValue(strfmt("@SYS82282",
LogisticsAddressState::find(sellerPostalAddress.CountryRegionId,
sellerPostalAddress.State).StateCode_IN));
}
}

//close object node


writer.WriteEndObject();
}

private void getEwbDtls(Integer _keyId)


{
CLEInvAPIRequestBody eInvReqBodyTranDtls;

while select eInvReqBodyTranDtls


where eInvReqBodyTranDtls.APIId == apiInfo.APIId
&& eInvReqBodyTranDtls.ParentKeyId == _keyId
&& eInvReqBodyTranDtls.IsEnabled == NoYes::Yes
{
this.prepareJsonNode(eInvReqBodyTranDtls.ValueScope,
eInvReqBodyTranDtls.KeyFieldName, eInvReqBodyTranDtls.MultiValue);
}

//close object node


writer.WriteEndObject();
}

private void getEwbExpDtls(Integer _keyId)


{
CLEInvAPIRequestBody eInvReqBodyTranDtls;
//Port address from where item has been shipped

while select eInvReqBodyTranDtls


where eInvReqBodyTranDtls.APIId == apiInfo.APIId
&& eInvReqBodyTranDtls.ParentKeyId == _keyId
&& eInvReqBodyTranDtls.IsEnabled == NoYes::Yes
{
this.prepareJsonNode(eInvReqBodyTranDtls.ValueScope,
eInvReqBodyTranDtls.KeyFieldName, eInvReqBodyTranDtls.MultiValue);

if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Addr1)
{
this.writeStrValue(strfmt("@SYS82282",
transportDetails.PortStreet));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Addr2)
{
writer.WriteNull();
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Loc)
{
this.writeStrValue(strfmt("@SYS82282", transportDetails.PortCity));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Pin)
{
this.writeStrValue(strfmt("@SYS82282",
transportDetails.PortZipCode));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Stcd)
{
this.writeStrValue(strfmt("@SYS82282",
LogisticsAddressState::find(CLEInvConstant::IND,
transportDetails.PortState).StateCode_IN));
}
}

//close object node


writer.WriteEndObject();
}

private void getExpDtls(Integer _keyId)


{
CLEInvAPIRequestBody eInvReqBodyTranDtls;

while select eInvReqBodyTranDtls


where eInvReqBodyTranDtls.APIId == apiInfo.APIId
&& eInvReqBodyTranDtls.ParentKeyId == _keyId
&& eInvReqBodyTranDtls.IsEnabled == NoYes::Yes
{
this.prepareJsonNode(eInvReqBodyTranDtls.ValueScope,
eInvReqBodyTranDtls.KeyFieldName, eInvReqBodyTranDtls.MultiValue);
}

//close object node


writer.WriteEndObject();
}

private void getItemList(Integer _keyId)


{
CustInvoiceTrans custInvoiceTrans;
//SalesLine_IN salesLine;
HSNCodeTable_IN hsnCodeTable;
ServiceAccountingCodeTable_IN serviceCodetable;
TransTaxInformation transTaxInfo;
TransTaxInformationRelationView taxInformationRelationView;

Counter lineNum;
ExchRate exchRate;
str isserv = CLEInvConstant::N, hsnServCode;

//CustInvoiceLine custInvLine;
//CustInvoiceTable custInvTable;

exchRate = custInvoiceJour.ExchRate/100;

while select custInvoiceTrans


where custInvoiceTrans.SalesId == custInvoiceJour.SalesId
&& custInvoiceTrans.InvoiceId == custInvoiceJour.InvoiceId
&& custInvoiceTrans.InvoiceDate == custInvoiceJour.InvoiceDate
&& custInvoiceTrans.numberSequenceGroup ==
custInvoiceJour.numberSequenceGroup
join taxInformationRelationView
where taxInformationRelationView.TransactionRefTableId ==
custInvoiceTrans.TableId
&& taxInformationRelationView.TransactionRefRecId ==
custInvoiceTrans.RecId
join transTaxInfo
where transTaxInfo.RecId ==
taxInformationRelationView.TransTaxInformationRefRecId
{
if (transTaxInfo.HSNCodeTable)
{
hsnCodeTable= HSNCodeTable_IN::find(transTaxInfo.HSNCodeTable);
hsnServCode = hsnCodeTable.Code;
}
else if(transTaxInfo.ServiceAccountingCodeTable)
{
serviceCodetable =
ServiceAccountingCodeTable_IN::find(transTaxInfo.ServiceAccountingCodeTable);
isserv = CLEInvConstant::Y;
hsnServCode = serviceCodetable.SAC;
}

totalGSTAmt = 0;
totalGSTPr = 0;
totalCESSAmt = 0;
totalCESSPr = 0;
taxAmtCGST = 0;
taxAmtSGST = 0;
taxAmtIGST = 0;
taxAmtCESS = 0;
taxPerCGST = 0;
taxPerSGST = 0;
taxPerIGST = 0;
taxPerCESS = 0;

lineNum++;

this.calculateItemTaxes(custInvoiceTrans.InvoiceDate,
custInvoiceTrans.TableId, custInvoiceTrans.RecId, exchRate);

this.setItemValues(_keyId, lineNum, custInvoiceTrans.TableId,


custInvoiceTrans.RecId, exchRate
, custInvoiceTrans.ItemId, custInvoiceTrans.itemName()?
custInvoiceTrans.itemName():custInvoiceTrans.Name, isserv, hsnServCode,
custInvoiceTrans.Qty?custInvoiceTrans.Qty:1, custInvoiceTrans.SalesUnit?
custInvoiceTrans.SalesUnit:'NOS', custInvoiceTrans.SalesPrice?
custInvoiceTrans.SalesPrice:custInvoiceTrans.LineAmountMST
, custInvoiceTrans.amountDiscAmount());//,
custInvoiceTrans.amountDiscPercentInclTax());
}

//End itemlist Array


writer.WriteEndArray();
}

private void getItemListTransfer(Integer _keyId)


{
if
(InventTransferTable::find(inventTransferJour.TransferId).TransferType_IN ==
TransferType_IN::TransferOrder)
{
this.getItemListTransferOrder(_keyId);
return;
}
InventTransferJourLine inventTransferJourLine;
HSNCodeTable_IN hsnCodeTable;
ServiceAccountingCodeTable_IN serviceCodetable;
TransTaxInformation transTaxInfo;
TransTaxInformationRelationView taxInformationRelationView;

Counter lineNum;
str isserv = CLEInvConstant::N, hsnServCode;

//while select inventTransferJourLine


// where inventTransferJourLine.TransferId ==
inventTransferJour.TransferId
// && inventTransferJourLine.VoucherId == inventTransferJour.VoucherId
//join taxInformationRelationView
// where taxInformationRelationView.TransactionRefTableId ==
inventTransferJourLine.TableId
// && taxInformationRelationView.TransactionRefRecId ==
inventTransferJourLine.RecId
//join transTaxInfo
// where transTaxInfo.RecId ==
taxInformationRelationView.TransTaxInformationRefRecId
// && transTaxInfo.Type ==
TransTaxInformationType_IN::InventTransferTo

while select inventTransferJourLine


where inventTransferJourLine.TransferId ==
inventTransferJour.TransferId
&& inventTransferJourLine.VoucherId == inventTransferJour.VoucherId
{

InventTransferLine transferLine =
inventTransferJourLine.inventTransferLine();
InventTransferLine_IN transferLine_IN =
InventTransferLine_IN::findByinventTransferLine(transferLine.RecId);

select taxInformationRelationView
where taxInformationRelationView.TransactionRefTableId ==
transferLine.TableId
&& taxInformationRelationView.TransactionRefRecId ==
transferLine.RecId
join transTaxInfo
where transTaxInfo.RecId ==
taxInformationRelationView.TransTaxInformationRefRecId
&& transTaxInfo.Type ==
TransTaxInformationType_IN::InventTransferTo;

if (transTaxInfo.HSNCodeTable)
{
hsnCodeTable= HSNCodeTable_IN::find(transTaxInfo.HSNCodeTable);
hsnServCode = hsnCodeTable.Code;
}
else if(transTaxInfo.ServiceAccountingCodeTable)
{
serviceCodetable =
ServiceAccountingCodeTable_IN::find(transTaxInfo.ServiceAccountingCodeTable);
isserv = CLEInvConstant::Y;
hsnServCode = serviceCodetable.SAC;
}

totalGSTAmt = 0;
totalGSTPr = 0;
totalCESSAmt = 0;
totalCESSPr = 0;
taxAmtCGST = 0;
taxAmtSGST = 0;
taxAmtIGST = 0;
taxAmtCESS = 0;
taxPerCGST = 0;
taxPerSGST = 0;
taxPerIGST = 0;
taxPerCESS = 0;

lineNum++;

this.calculateItemTaxes(inventTransferJourLine.TransDate,
inventTransferJourLine.TableId, inventTransferJourLine.RecId, 1,
inventTransferJourLine.VoucherId);

this.setItemValues(_keyId, lineNum, inventTransferJourLine.TableId,


inventTransferJourLine.RecId, 1
, inventTransferJourLine.ItemId, inventTransferJourLine.itemName(),
isserv, hsnServCode, inventTransferJourLine.QtyShipped,
inventTransferJourLine.UnitId, inventTransferJourLine.UnitPrice_IN);
}

//End itemlist Array


writer.WriteEndArray();
}

private void getItemListTransferOrder(Integer _keyId)


{
InventTransferJourLine inventTransferJourLine, inventTransferJourLine1;
InventTrans inventTrans;
InventTransOrigin inventTransOrigin;
TransTaxInformation fromTransTaxInformation;
HSNCodeTable_IN hsnCodeTable;
ServiceAccountingCodeTable_IN serviceCodetable;
InventTable inventTableLoc;
//ItemId oldItemId;

Counter lineNum;
str isserv = CLEInvConstant::N, hsnServCode;

while select inventTrans order by Itemid


where inventTrans.StatusIssue == StatusIssue::Sold
exists join inventTransOrigin
where inventTransOrigin.RecId == inventTrans.InventTransOrigin
&& inventTransOrigin.ReferenceCategory ==
InventTransType::TransferOrderShip
exists join inventTransferJourLine1
where inventTransferJourLine1.InventTransId ==
inventTransOrigin.InventTransId
&& inventTransferJourLine1.TransferId ==
inventTransferJour.TransferId
{
select firstonly inventTransferJourLine
where inventTransferJourLine.InventTransId ==
inventTrans.inventTransOrigin().InventTransId
&& inventTransferJourLine.TransferId ==
inventTransferJour.TransferId;

select firstonly fromTransTaxInformation


where fromTransTaxInformation.TaxInformation ==
fromTaxInformation.RecId;

if (fromTransTaxInformation.HSNCodeTable)
{
hsnCodeTable=
HSNCodeTable_IN::find(fromTransTaxInformation.HSNCodeTable);
hsnServCode = hsnCodeTable.Code;
}
else
{
serviceCodetable =
ServiceAccountingCodeTable_IN::find(fromTransTaxInformation.ServiceAccountingCodeTa
ble);
if (serviceCodetable)
{
isserv = CLEInvConstant::Y;
hsnServCode = serviceCodetable.SAC;
}
else
{
inventTableLoc =
InventTable::find(inventTransferJourLine.ItemId);

if (inventTableLoc.HSNCodeTable_IN)
{
hsnCodeTable=
HSNCodeTable_IN::find(inventTableLoc.HSNCodeTable_IN);
hsnServCode = hsnCodeTable.Code;
}
else if (inventTableLoc.ServiceAccountingCodeTable_IN)
{
serviceCodetable =
ServiceAccountingCodeTable_IN::find(inventTableLoc.ServiceAccountingCodeTable_IN);
isserv = CLEInvConstant::Y;
hsnServCode = serviceCodetable.SAC;
}
}
}

totalGSTAmt = 0;
totalGSTPr = 0;
totalCESSAmt = 0;
totalCESSPr = 0;
taxAmtCGST = 0;
taxAmtSGST = 0;
taxAmtIGST = 0;
taxAmtCESS = 0;
taxPerCGST = 0;
taxPerSGST = 0;
taxPerIGST = 0;
taxPerCESS = 0;
lineNum++;

this.calculateItemTaxes(inventTransferJourLine.TransDate,
inventTransferJourLine.TableId, inventTransferJourLine.RecId, 1,
inventTransferJourLine.VoucherId);

EcoResProductName ecoResProductName =
EcoResProductTranslation::getNameOrDefaultName(InventTable::find(inventTransferJour
Line.ItemId).Product, CompanyInfo::find().LanguageId);

PriceDiscTable priceDiscTable;
UnitPrice unitPrice;
InventUnitId unit = inventTransferJourLine.inventUnit();
if (match('<CC41', inventTransferJour.InventLocationIdTo))
{
select firstonly priceDiscTable
where priceDiscTable.ItemRelation == inventTrans.ItemId
&& priceDiscTable.AccountRelation ==
inventTransferJour.InventLocationIdTo
&& priceDiscTable.relation == PriceType::PriceSales
&& priceDiscTable.FromDate <= inventTransferJour.TransDate
&& priceDiscTable.ToDate >= inventTransferJour.TransDate;

unitPrice = priceDiscTable.Amount;
}
else
{
unitPrice =
abs(inventTrans.costValue())/abs(inventTrans.Qty);
}

totalInvAmt += inventTransferJourLine.QtyShipped * unitPrice;


totalInvAmtMST = totalInvAmt;
if (totalInvAmt >= 0)
{
typ = CLEInvConstant::INV;
}
else
{
typ = CLEInvConstant::CRN;
}

this.setItemValues(_keyId, lineNum, inventTransferJourLine.TableId,


inventTransferJourLine.RecId, 1
, inventTransferJourLine.ItemId, ecoResProductName, isserv,
hsnServCode, inventTransferJourLine.QtyShipped, unit, unitPrice);

//oldItemId = inventTransferJourLine.ItemId;
}

//End itemlist Array


writer.WriteEndArray();
}

private void calculateItemTaxes(TransDate _transDate, RefTableId _refTableId,


RefRecId _refrecId,ExchRate _exchRate, Voucher _voucher = '')
{
TaxTrans_IN taxTrans;
while select taxTrans
where taxTrans.TransDate == _transDate
&& taxTrans.TransTableId == _refTableId
&& taxTrans.TransRecId == _refrecId
&& (!_voucher ||
(_voucher && taxTrans.Voucher == _voucher))
{
itemAssessableVal =
TaxTrans::findRecId_IN(taxTrans.RefRecId).TaxBaseAmount;

if(taxTrans.TaxCode Like CLEInvConstant::CGST)


{
taxAmtCGST = abs(taxTrans.TaxAmount * _exchRate);
taxPerCGST = taxTrans.TaxValue;

totalGSTAmt += taxAmtCGST;
totalGSTPr += taxPerCGST;

totTaxAmtCGST += taxAmtCGST;
}
else if(taxTrans.TaxCode Like CLEInvConstant::SGST)
{
taxAmtSGST = abs(taxTrans.TaxAmount * _exchRate);
taxPerSGST = taxTrans.TaxValue;

totalGSTAmt += taxAmtSGST;
totalGSTPr += taxPerSGST;

totTaxAmtSGST += taxAmtSGST;
}
else if(taxTrans.TaxCode Like CLEInvConstant::IGST)
{
taxAmtIGST = abs(taxTrans.TaxAmount * _exchRate);
taxPerIGST = taxTrans.TaxValue;

totalGSTAmt += taxAmtIGST;
totalGSTPr += taxPerIGST;

totTaxAmtIGST += taxAmtIGST;
}
else if(taxTrans.TaxCode Like CLEInvConstant::CESS)
{
taxAmtCESS = abs(taxTrans.TaxAmount * _exchRate);
taxPerCESS = taxTrans.TaxValue;

totalCESSAmt += taxAmtCESS;
totalCESSPr += taxPerCESS;

totTaxAmtCESS += taxAmtCESS;
}
}
}

private void setItemValues(int _keyId, Counter _lineNum, RefTableId


_refTableId, RefRecId _refrecId,ExchRate _exchRate
, ItemId _itemId, ItemName _itemName, str _isserv, str _hsnServCode, Qty
_qty, SalesUnit _unit, SalesPrice _salesPrice
, DiscAmount _discAmount = 0, DiscAmount _amtDiscPercent = 0)
{
CLEInvAPIRequestBody eInvReqBodyTranDtls;
MarkupTrans markuptransLoc;
real lineOthCharges, discAmt;

select sum (Value) from markuptransLoc


where markuptransLoc.TransTableId == _refTableId
&& markuptransLoc.TransRecId == _refrecId;

lineOthCharges = markuptransLoc.Value * _exchRate;

discAmt = abs(_discAmount)+abs(_amtDiscPercent);

writer.WriteStartObject();
while select eInvReqBodyTranDtls
where eInvReqBodyTranDtls.APIId == apiInfo.APIId
&& eInvReqBodyTranDtls.ParentKeyId == _keyId
&& eInvReqBodyTranDtls.IsEnabled == NoYes::Yes
{
this.prepareJsonNode(eInvReqBodyTranDtls.ValueScope,
eInvReqBodyTranDtls.KeyFieldName, eInvReqBodyTranDtls.MultiValue);

if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::ProdName)
{
this.writeStrValue(_itemName);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::SlNo)
{
this.writeStrValue(strFmt("@SYS82282",_lineNum));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::ProdDesc)
{
this.writeStrValue('');
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::IsServc)
{
this.writeStrValue(_isserv);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::HsnCd)
{
this.writeStrValue(_hsnServCode);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Qty)
{
writer.WriteValue(abs(_qty));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Unit)
{
//this.writeStrValue(strUpr(_unit));
this.writeStrValue(strUpr('pcs'));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::AssAmt)
{
if (!itemAssessableVal)
{
writer.WriteValue(abs(round(_salesPrice * abs(_qty) *
_exchRate,0.01) - round(discAmt *_exchRate, 0.01)));

totAssValue += abs(round(_salesPrice * abs(_qty) *


_exchRate,0.01) - round(discAmt *_exchRate, 0.01));
}
else
{
writer.WriteValue(abs(round(itemAssessableVal * _exchRate,
0.01)));

totAssValue += abs(round(itemAssessableVal * _exchRate, 0.01));


}
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::CgstRt)
{
writer.WriteValue(taxPerCGST);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::CgstAmt)
{
writer.WriteValue(taxAmtCGST);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::SgstRt)
{
writer.WriteValue(taxPerSGST);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::SgstAmt)
{
writer.WriteValue(taxAmtSGST);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::IgstRt)
{
writer.WriteValue(taxPerIGST);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::IgstAmt)
{
writer.WriteValue(taxAmtIGST);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::CesRt)
{
writer.WriteValue(totalCESSPr);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::CesAmt)
{
writer.WriteValue(taxAmtCESS);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::OthChrg)
{
writer.WriteValue(abs(lineOthCharges));
}
else if (eInvReqBodyTranDtls.KeyFieldName ==
CLEInvConstant::CesNonAdvlAmt)
{
writer.WriteValue(0);
}
}
writer.WriteEndObject();
}

private void getSellerDtls(Integer _keyId)


{
CLEInvAPIRequestBody eInvReqBodyTranDtls;
while select eInvReqBodyTranDtls
where eInvReqBodyTranDtls.APIId == apiInfo.APIId
&& eInvReqBodyTranDtls.ParentKeyId == _keyId
&& eInvReqBodyTranDtls.IsEnabled == NoYes::Yes
{
this.prepareJsonNode(eInvReqBodyTranDtls.ValueScope,
eInvReqBodyTranDtls.KeyFieldName, eInvReqBodyTranDtls.MultiValue);
if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Gstin)
{
this.writeStrValue(sellerPrimaryGSTIN);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::LglNm)
{
this.writeStrValue(sellerName);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::TrdNm)
{
this.writeStrValue(sellerTrdName);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Addr1)
{
this.writeStrValue(subStr(strfmt("@SYS82282",
strRemoveCr(sellerPostalAddress.Street)),1,100));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Addr2)
{
writer.WriteNull();
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Loc)
{
this.writeStrValue(strfmt("@SYS82282", sellerPostalAddress.City));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Pin)
{
this.writeStrValue(strfmt("@SYS82282",
strRem(sellerPostalAddress.ZipCode, ' ')));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Stcd)
{
this.writeStrValue(strfmt("@SYS82282",
LogisticsAddressState::find(sellerPostalAddress.CountryRegionId,
sellerPostalAddress.State).StateCode_IN));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Ph)
{
this.writeStrValue(sellerPhone);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Em)
{
this.writeStrValue(sellerEmail);
}
}
//close object node
writer.WriteEndObject();
}

private void getShipDtls(Integer _keyId)


{
CLEInvAPIRequestBody eInvReqBodyTranDtls;
while select eInvReqBodyTranDtls
where eInvReqBodyTranDtls.APIId == apiInfo.APIId
&& eInvReqBodyTranDtls.ParentKeyId == _keyId
&& eInvReqBodyTranDtls.IsEnabled == NoYes::Yes
{
this.prepareJsonNode(eInvReqBodyTranDtls.ValueScope,
eInvReqBodyTranDtls.KeyFieldName, eInvReqBodyTranDtls.MultiValue);
if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Gstin)
{
writer.WriteNull();
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::LglNm)
{

this.writeStrValue(LogisticsLocation::find(deliveryPostalAddress.Location).Descript
ion);
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::TrdNm)
{
writer.WriteNull();
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Addr1)
{
this.writeStrValue(subStr(strfmt("@SYS82282",
deliveryPostalAddress.Street),1,100));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Addr2)
{
writer.WriteNull();
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Loc)
{
this.writeStrValue(strfmt("@SYS82282",
deliveryPostalAddress.City));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Pin)
{
if (deliveryPostalAddress.CountryRegionId == CLEInvConstant::IND)
{
this.writeStrValue(strRem(strfmt("@SYS82282",
deliveryPostalAddress.zipCode),' '));
}
else
{
this.writeStrValue(eInvReqBodyTranDtls.DefaultValue);
}
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Stcd)
{
if (deliveryPostalAddress.CountryRegionId == CLEInvConstant::IND)
{
this.writeStrValue(strfmt("@SYS82282",
LogisticsAddressState::find(deliveryPostalAddress.CountryRegionId,
deliveryPostalAddress.State).StateCode_IN));
}
else
{
this.writeStrValue(eInvReqBodyTranDtls.DefaultValue);
}
}
}

//close object node


writer.WriteEndObject();
}

private Amount invTotalAmtRecve_IN()


{
InventTransferJourLine inventTransJourLine;
real totals;
TaxTrans_IN taxTrans_IN;

select sum(NetAmtShip_In) from inventTransJourLine


where inventTransJourLine.TransferId == inventTransferJour.TransferId
&& inventTransJourLine.VoucherId == inventTransferJour.VoucherId;

select sum(TaxAmount) from taxTrans_IN


where taxTrans_IN.Voucher == inventTransferJour.VoucherId &&
taxTrans_IN.TransDate == inventTransferJour.TransDate;

taxAmt = abs(taxTrans_IN.TaxAmount);

totals = (inventTransJourLine.NetAmtShip_In
+ taxAmt);

return totals;
}

/// <summary>
/// update E-Way Bill
/// </summary>
/// <param name = "_refTableId">TableId</param>
/// <param name = "_refrecId">RecId</param>
/// <param name = "_documentId">Document</param>
/// <param name = "_action">update action</param>
public void updateEWB(RefTableId _refTableId, RefRecId _refrecId, Description
_documentId, CLEWBUpdateAction _action)
{
System.Net.HttpWebResponse response;
CLRObject clrObj;
System.Exception ex;

System.IO.Stream requestStream;
System.IO.StreamWriter streamWriter;
System.IO.StreamReader streamRead;

try
{
updateAction = _action;
parentTableId = _refTableId;
parentRecId = _refrecId;

apiInfo =
CLEInvAPIInfo::findByAPIType(CLEInvAPIType::EWBUpdate);
irnData = CLEInvIRNData::findValidEWB(_refrecId, _refTableId);
ewbNumber = irnData.EwayBillNo;
if (!ewbNumber)
{
throw error("@TIS:EWBInvalidForUpdate");
}

select firstonly invParameters;


new InteropPermission(InteropKind::ClrInterop).assert();
clrObj =
System.Net.WebRequest::Create(invParameters.HostUrl+apiInfo.RequestAPI+enum2Value(u
pdateAction));
request = clrObj;

// adding headers
this.addHeader();

//Req Stream
requestStream = request.GetRequestStream();
streamWriter = new System.IO.StreamWriter(requestStream);

//Prepare Json body

this.createJSONStrBody(apiInfo.ApiId, apiInfo.APIType);

// writing JSON
streamWriter.WriteAsync(reqBodyStr);
streamWriter.Flush();
streamWriter.Close();

//Response
response = request.GetResponse();
streamRead = new System.IO.StreamReader(response.GetResponseStream());

resBodyStr = streamRead.ReadToEnd();

this.insertReqLogs(apiInfo.APIId, _documentId, apiInfo.RequestAPI


, reqBodyStr, resBodyStr, _refTableId, _refRecId,
CLEWBStatus::Completed);

this.getEWBUpdateResponseKeyValues();

if (validResponse)
{
info(strFmt("@TIS:EWBUpdateValid", _documentId));
}
else
{
warning ("@TIS:EWBUpdateInvalid");
}
}
catch
{
//exception
ex = CLRInterop::getLastException().GetBaseException();

this.insertReqLogs(apiInfo.APIId, _documentId, apiInfo.RequestAPI


, reqBodyStr, ex.get_Message(), _refTableId, _refRecId,
CLEWBStatus::Error);

error(ex.get_Message());
}
}

/// <summary>
/// Update E-way bill - validity extension, PartB, Transporter Id update
/// </summary>
/// <param name = "_einvReqBody">CLEInvAPIRequestBody</param>
private void parmsUpdateEWB(CLEInvAPIRequestBody _einvReqBody)
{
if (updateAction == CLEWBUpdateAction::PARTB && !transportDetailsPartB)
{
transportDetailsPartB =
CLEWBTransportDetailsPartB::find(transportDetails.RecId);
}
else if (updateAction == CLEWBUpdateAction::EXTEND_VALIDITY && !
transportDetailsEwtValidity)
{
transportDetailsEwtValidity =
CLEWBTransportDetailsExtValidity::find(transportDetails.RecId);
}
else if (updateAction == CLEWBUpdateAction::UPDATE_TRANSPORTER_ID && !
transportDetailsTransporterId)
{
transportDetailsTransporterId =
CLEWBTransportDetailsTranspId::find(transportDetails.RecId);
}

//field values
if (_einvReqBody.KeyFieldName == CLEInvConstant::ewbNo)
{
//EWB
this.writeStrValue(ewbNumber);
}
else if (updateAction == CLEWBUpdateAction::PARTB)
{
if (_einvReqBody.KeyFieldName == CLEInvConstant::VehNo)
{
this.writeStrValue(transportDetailsPartB.VehicleNumber);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::fromPlace)
{
this.writeStrValue(transportDetailsPartB.FromPlace);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::fromState)
{
this.writeStrValue(LogisticsAddressState::find(CLEInvConstant::IND,
transportDetailsPartB.FromState).StateCode_IN);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::ReasonCode)
{
this.writeStrValue(enum2Value(transportDetailsPartB.Reason));
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::ReasonRemark)
{
this.writeStrValue(transportDetailsPartB.Remarks);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TransDocNo)
{
this.writeStrValue(transportDetailsPartB.TransportDocumentNumber);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TransDocDt)
{
this.writeStrValue(date2str(transportDetailsPartB.TransportDocDate,
123, 2, DateSeparator::Slash, 2, DateSeparator::Slash, DateSeparator::Slash, 4));
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TransMode)
{

this.writeStrValue(enum2Value(transportDetailsPartB.TransportMode));
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::VehType)
{

this.writeStrValue(enum2Value(transportDetailsEwtValidity.VehicleType));
}
}
else if (updateAction == CLEWBUpdateAction::EXTEND_VALIDITY)
{
if (_einvReqBody.KeyFieldName == CLEInvConstant::VehNo)
{
this.writeStrValue(transportDetailsEwtValidity.VehicleNumber);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::fromPlace)
{
this.writeStrValue(transportDetailsEwtValidity.FromPlace);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::fromState)
{
this.writeStrValue(LogisticsAddressState::find(CLEInvConstant::IND,
transportDetailsEwtValidity.FromState).StateCode_IN);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::ReasonCode)
{
this.writeStrValue(enum2Value(transportDetailsEwtValidity.Reason));
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::ReasonRemark)
{
this.writeStrValue(transportDetailsEwtValidity.Remarks);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TransDocNo)
{

this.writeStrValue(transportDetailsEwtValidity.TransportDocumentNumber);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TransDocDt)
{

this.writeStrValue(date2str(transportDetailsEwtValidity.TransportDocDate, 123, 2,
DateSeparator::Slash, 2, DateSeparator::Slash, DateSeparator::Slash, 4));
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TransMode)
{

this.writeStrValue(enum2Value(transportDetailsEwtValidity.TransportMode));
}
else if (_einvReqBody.KeyFieldName ==
CLEInvConstant::RemainingDistance)
{
this.writeIntValue(transportDetailsEwtValidity.RemainingDistance);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::FromPinCode)
{
this.writeStrValue(transportDetailsEwtValidity.FromZipCode);
}
else if (_einvReqBody.KeyFieldName ==
CLEInvConstant::ConsignmentStatus)
{

this.writeStrValue(enum2Value(transportDetailsEwtValidity.ConsignmentStatus));
}
}
else if (updateAction == CLEWBUpdateAction::UPDATE_TRANSPORTER_ID
&& _einvReqBody.KeyFieldName == CLEInvConstant::TransporterId)
{
this.writeStrValue(transportDetailsTransporterId.TransportId);
}
}

private void getEWBUpdateResponseKeyValues()


{
Map map;
MapEnumerator mapEnumeratorMain;
boolean inValid;
container dtValue;

CLEWBUpdateHistory updateHistory;

map = RetailCommonWebAPI::getMapFromJsonString(resBodyStr);

mapEnumeratorMain = map.getEnumerator();

if (!irnData)
{
return;
}
irnData.selectForUpdate(true);

while ( mapEnumeratorMain.moveNext() && !inValid)


{
switch (mapEnumeratorMain.currentKey())
{
case CLEInvConstant::errorDetails:
case CLEInvConstant::errors:
inValid = true;
break;

case CLEInvConstant::ewbStatus:
if (mapEnumeratorMain.currentKey() Like
CLEInvConstant::LikeFAILED)
{
inValid = true;
}
break;

case CLEInvConstant::UpdatedDate:
dtValue = mapEnumeratorMain.currentValue();
irnData.EWayDateTime =
str2datetime(con2str(dtValue), 321);
dtValue = conNull();
break;

case CLEInvConstant::ValidUpto:
dtValue = mapEnumeratorMain.currentValue();
irnData.EWayValidDateTime =
str2datetime(con2str(dtValue), 321);
dtValue = conNull();
break;
}
}

if (!inValid)
{
ttsBegin;
irnData.update();
ttsCommit;

updateHistory.IRNDataRefRecId = irnData.RecId;
updateHistory.EwayBillNo = irnData.EwayBillNo;
updateHistory.UpdateDateTime = irnData.EWayDateTime;
updateHistory.EWayValidDateTime = irnData.EWayValidDateTime;
updateHistory.UpdateAction = updateAction;
updateHistory.insert();

validResponse = true;
}
else
{
validResponse = false;
}
}

/// <summary>
/// Consolidate E-Way Bill
/// </summary>
/// <param name = "_ewbNumbersRecId">RecIds for ewbnumber data</param>
/// <param name = "_ewbNumbers">List of EWb Numbers in container</param>
/// <param name = "_action">update action</param>
public void generateConsolidateEWB(container _ewbNumbersRecId, container
_ewbNumbers, CLEWBConsolidateAction _action)
{
System.Net.HttpWebResponse response;
CLRObject clrObj;
System.Exception ex;

System.IO.Stream requestStream;
System.IO.StreamWriter streamWriter;
System.IO.StreamReader streamRead;
Counter ewbNumQty = conLen(_ewbNumbersRecId);

try
{
apiInfo =
CLEInvAPIInfo::findByAPIType(CLEInvAPIType::GenConsolidatedEWB);
consolidationAction = _action;

select firstonly invParameters;


new InteropPermission(InteropKind::ClrInterop).assert();
clrObj =
System.Net.WebRequest::Create(invParameters.HostUrl+apiInfo.RequestAPI+enum2Value(c
onsolidationAction));
request = clrObj;

for (Counter i = 1; i<=1; i++)


{
RefRecId ewbNumberRecIdLoc = conPeek(_ewbNumbersRecId, i);
irnData = CLEInvIRNData::find(ewbNumberRecIdLoc);
parentTableId = irnData.ParentTableId;
parentRecId = irnData.ParentRecId;

// adding headers
this.addHeader();

//Req Stream
requestStream = request.GetRequestStream();
streamWriter = new System.IO.StreamWriter(requestStream);

ewbNumbersConsolidation = con2Str(_ewbNumbers, ',');

//Prepare Json body


this.createJSONStrBody(apiInfo.ApiId, apiInfo.APIType);

// writing JSON
streamWriter.WriteAsync(reqBodyStr);
streamWriter.Flush();
streamWriter.Close();

//Response
response = request.GetResponse();
streamRead = new
System.IO.StreamReader(response.GetResponseStream());

resBodyStr = streamRead.ReadToEnd();
}
for (Counter j = 1; j<=ewbNumQty; j++)
{
RefRecId ewbNumberRecIdLoc1 = conPeek(_ewbNumbersRecId, j);
irnData = CLEInvIRNData::find(ewbNumberRecIdLoc1, true);
parentTableId = irnData.ParentTableId;
parentRecId = irnData.ParentRecId;

this.insertReqLogs(apiInfo.APIId, irnData.EwayBillNo,
apiInfo.RequestAPI
, reqBodyStr, resBodyStr, parentTableId, parentRecId,
CLEWBStatus::Completed);

this.getEWBConsolidateResponseKeyValues();

if (j==1)
{
if (validResponse)
{
info(strFmt("@TIS:EWBConsolidatedValid",
ewbNumbersConsolidation));
}
else
{
warning ("@TIS:EWBUpdateInvalid");
}
}

}
}
catch
{
//exception
ex = CLRInterop::getLastException().GetBaseException();

for (Counter l = 1; l<=ewbNumQty; l++)


{
RefRecId ewbNumberRecIdLoc2 = conPeek(_ewbNumbersRecId, l);
irnData = CLEInvIRNData::find(ewbNumberRecIdLoc2);
parentTableId = irnData.ParentTableId;
parentRecId = irnData.ParentRecId;

this.insertReqLogs(apiInfo.APIId, irnData.EwayBillNo,
apiInfo.RequestAPI
, reqBodyStr, ex.get_Message(), parentTableId, parentRecId,
CLEWBStatus::Error);
}

error(ex.get_Message());
}
}

/// <summary>
/// Regenerate consolidated EWB
/// </summary>
/// <param name = "_consolidatedEwbNumber">ewbnumber data</param>
/// <param name = "_action">update action</param>
public void reGenerateConsolidateEWB(CLEWBNumber _consolidatedEwbNumber,
CLEWBConsolidateAction _action)
{
System.Net.HttpWebResponse response;
CLRObject clrObj;
System.Exception ex;

System.IO.Stream requestStream;
System.IO.StreamWriter streamWriter;
System.IO.StreamReader streamRead;

try
{
apiInfo =
CLEInvAPIInfo::findByAPIType(CLEInvAPIType::GenConsolidatedEWB);
consolidationAction = _action;

select firstonly invParameters;


new InteropPermission(InteropKind::ClrInterop).assert();
clrObj =
System.Net.WebRequest::Create(invParameters.HostUrl+apiInfo.RequestAPI+enum2Value(c
onsolidationAction));
request = clrObj;

irnData = CLEInvIRNData::findByConsolidatedEWB(_consolidatedEwbNumber);
parentTableId = irnData.ParentTableId;
parentRecId = irnData.ParentRecId;

// adding headers
this.addHeader();

//Req Stream
requestStream = request.GetRequestStream();
streamWriter = new System.IO.StreamWriter(requestStream);

//Prepare Json body


this.createJSONStrBody(apiInfo.ApiId, apiInfo.APIType);

// writing JSON
streamWriter.WriteAsync(reqBodyStr);
streamWriter.Flush();
streamWriter.Close();

//Response
response = request.GetResponse();
streamRead = new System.IO.StreamReader(response.GetResponseStream());

resBodyStr = streamRead.ReadToEnd();

this.insertReqLogs(apiInfo.APIId, irnData.ConsolidatedEwayBillNo,
apiInfo.RequestAPI
, reqBodyStr, resBodyStr, parentTableId, parentRecId,
CLEWBStatus::Completed);

this.getEWBConsolidateResponseKeyValues();

if (validResponse)
{
info(strFmt("@TIS:EWBConsolidatedValid", ewbNumbersConsolidation));
}
else
{
warning ("@TIS:EWBUpdateInvalid");
}

}
catch
{
//exception
ex = CLRInterop::getLastException().GetBaseException();

this.insertReqLogs(apiInfo.APIId, irnData.ConsolidatedEwayBillNo,
apiInfo.RequestAPI
, reqBodyStr, ex.get_Message(), parentTableId, parentRecId,
CLEWBStatus::Error);

error(ex.get_Message());
}
}

/// <summary>
/// Update E-way bill - validity extension, PartB, Transporter Id update
/// </summary>
/// <param name = "_einvReqBody">CLEInvAPIRequestBody</param>
private void parmsGenerateConsolidatedEWB(CLEInvAPIRequestBody _einvReqBody)
{
if (_einvReqBody.KeyFieldName == CLEInvConstant::VehNo)
{
this.writeStrValue(transportDetails.VehicleNumber);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::fromPlace)
{
this.writeStrValue(transportDetails.ConsolidateFromPlace);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::fromState)
{
this.writeStrValue(LogisticsAddressState::find(CLEInvConstant::IND,
transportDetails.ConsolidateFromState).StateCode_IN);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::ReasonCode)
{
this.writeStrValue(enum2Value(transportDetails.ConsolidateReason));
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::ReasonRemark)
{
this.writeStrValue(transportDetails.ConsolidateRemarks);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TransDocNo)
{
this.writeStrValue(transportDetails.TransportDocumentNumber);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TransDocDt)
{
this.writeStrValue(date2str(transportDetails.TransportDocDate, 123, 2,
DateSeparator::Slash, 2, DateSeparator::Slash, DateSeparator::Slash, 4));
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TransMode)
{
this.writeStrValue(enum2Value(transportDetails.TransportMode));
}
else if (consolidationAction ==
CLEWBConsolidateAction::GENERATE_CONSOLIDATED_EWB
&& _einvReqBody.KeyFieldName == CLEInvConstant::EwbNumbers)
{
this.writeStrValue(ewbNumbersConsolidation);
}
else if (consolidationAction ==
CLEWBConsolidateAction::REGENERATE_CONSOLIDATED_EWB
&& _einvReqBody.KeyFieldName == CLEInvConstant::EwbNumbers)
{
this.writeStrValue(ewbNumbersConsolidation);
}
}

private void getEWBConsolidateResponseKeyValues()


{
Map map;
MapEnumerator mapEnumeratorMain;
boolean inValid;
container dtValue;

map = RetailCommonWebAPI::getMapFromJsonString(resBodyStr);

mapEnumeratorMain = map.getEnumerator();
if (!irnData)
{
return;
}
irnData.selectForUpdate(true);

while ( mapEnumeratorMain.moveNext() && !inValid)


{
switch (mapEnumeratorMain.currentKey())
{
case CLEInvConstant::errorDetails:
case CLEInvConstant::errors:
inValid = true;
break;

case CLEInvConstant::ConsolidatedEwbNumber:
irnData.ConsolidatedEwayBillNo =
mapEnumeratorMain.currentValue();
break;

case CLEInvConstant::ConsolidateEwbDate:
dtValue = mapEnumeratorMain.currentValue();
irnData.ConsolidatedEWayDateTime =
str2datetime(con2str(dtValue), 321);
dtValue = conNull();
break;
}
}

if (!inValid)
{
ttsBegin;
irnData.CLEWBStatus = CLEWBStatus::Completed;
irnData.update();
ttsCommit;

validResponse = true;
}
else
{
ttsBegin;
irnData.CLEWBStatus = CLEWBStatus::Error;
irnData.update();
ttsCommit;
validResponse = false;
}
}

/// <summary>
/// Multi vehicle E-Way Bill update
/// </summary>
/// <param name = "_refTableId">TableId</param>
/// <param name = "_refrecId">RecId</param>
/// <param name = "_documentId">Document</param>
public void updateMultiVehEWB(RefTableId _refTableId, RefRecId _refrecId,
Description _documentId)
{
System.Net.HttpWebResponse response;
CLRObject clrObj;
System.Exception ex;

System.IO.Stream requestStream;
System.IO.StreamWriter streamWriter;
System.IO.StreamReader streamRead;

try
{

parentTableId = _refTableId;
parentRecId = _refrecId;

apiInfo =
CLEInvAPIInfo::findByAPIType(CLEInvAPIType::MultiVehicleEWB);
irnData = CLEInvIRNData::findValidEWB(_refrecId, _refTableId);
ewbNumber = irnData.EwayBillNo;
if (!ewbNumber)
{
throw error("@TIS:EWBInvalidForUpdate");
}

select firstonly invParameters;


new InteropPermission(InteropKind::ClrInterop).assert();
clrObj =
System.Net.WebRequest::Create(invParameters.HostUrl+apiInfo.RequestAPI);
request = clrObj;

// adding headers
this.addHeader();

//Req Stream
requestStream = request.GetRequestStream();
streamWriter = new System.IO.StreamWriter(requestStream);

//Prepare Json body

this.createJSONStrBody(apiInfo.ApiId, apiInfo.APIType);

// writing JSON
streamWriter.WriteAsync(reqBodyStr);
streamWriter.Flush();
streamWriter.Close();

//Response
response = request.GetResponse();
streamRead = new System.IO.StreamReader(response.GetResponseStream());

resBodyStr = streamRead.ReadToEnd();

this.insertReqLogs(apiInfo.APIId, _documentId, apiInfo.RequestAPI


, reqBodyStr, resBodyStr, _refTableId, _refRecId,
CLEWBStatus::Completed);

this.getMultiVehEWBUpdateResponseKeyValues();

if (validResponse)
{
info(strFmt("@TIS:EWBUpdateValid", _documentId));
}
else
{
warning ("@TIS:EWBUpdateInvalid");
}
}
catch
{
//exception
ex = CLRInterop::getLastException().GetBaseException();

this.insertReqLogs(apiInfo.APIId, _documentId, apiInfo.RequestAPI


, reqBodyStr, ex.get_Message(), _refTableId, _refRecId,
CLEWBStatus::Error);

error(ex.get_Message());
}
}

/// <summary>
/// Multi vehicle E-way bill
/// </summary>
/// <param name = "_einvReqBody">CLEInvAPIRequestBody</param>
private void parmsMultiVehEWB(CLEInvAPIRequestBody _einvReqBody)
{
if (!transportDetailsMultiVehicle)
{
transportDetailsMultiVehicle =
CLEWBTransportDetailsMultiVehicle::find(transportDetails.RecId);
}

if (_einvReqBody.KeyFieldName == CLEInvConstant::ewbNo)
{
//EWB
this.writeStrValue(ewbNumber);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::fromPlace)
{
this.writeStrValue(transportDetailsMultiVehicle.FromPlace);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::fromState)
{
this.writeStrValue(LogisticsAddressState::find(CLEInvConstant::IND,
transportDetailsMultiVehicle.FromState).StateCode_IN);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::ReasonCode)
{
this.writeStrValue(enum2Value(transportDetailsMultiVehicle.Reason));
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::ReasonRemark)
{
this.writeStrValue(transportDetailsMultiVehicle.Remarks);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TransMode)
{

this.writeStrValue(enum2Value(transportDetailsMultiVehicle.TransportMode));
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::TotalQuantity)
{
writer.WriteValue(transportDetailsMultiVehicle.TotalQty);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::UnitOfMeasurement)
{
this.writeStrValue(transportDetailsMultiVehicle.UnitOfMEasurement);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::GroupNumber)
{
writer.WriteValue(0);
}
else if (_einvReqBody.KeyFieldName == CLEInvConstant::VehicleListDetails)
{
CLEWBMultiVehicleList multiVehicleList;
while select multiVehicleList
where multiVehicleList.ParentRecId ==
transportDetailsMultiVehicle.RecId
{
this.getMultiVehicleList(_einvReqBody.KeyId);
}
}
}

private void getMultiVehicleList(Integer _keyId)


{
CLEInvAPIRequestBody eInvReqBodyTranDtls;
CLEWBMultiVehicleList multiVehicleList;
writer.WriteStartObject();

while select eInvReqBodyTranDtls


where eInvReqBodyTranDtls.APIId == apiInfo.APIId
&& eInvReqBodyTranDtls.ParentKeyId == _keyId
&& eInvReqBodyTranDtls.IsEnabled == NoYes::Yes
{
this.prepareJsonNode(eInvReqBodyTranDtls.ValueScope,
eInvReqBodyTranDtls.KeyFieldName, eInvReqBodyTranDtls.MultiValue);

if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::VehicleNo)
{
this.writeStrValue(multiVehicleList.VehicleNumber);
}
else if (eInvReqBodyTranDtls.KeyFieldName ==
CLEInvConstant::DocumentNumber)
{
this.writeStrValue(multiVehicleList.TransportDocumentNumber);
}
else if (eInvReqBodyTranDtls.KeyFieldName ==
CLEInvConstant::DocumentDate)
{
this.writeStrValue(date2str(multiVehicleList.TransportDocDate, 123,
2, DateSeparator::Slash, 2, DateSeparator::Slash, DateSeparator::Slash, 4));
}
else if (eInvReqBodyTranDtls.KeyFieldName == CLEInvConstant::Quantity)
{
writer.writeValue(multiVehicleList.Quantity);
}
}
writer.WriteEndObject();
}

private void getMultiVehEWBUpdateResponseKeyValues()


{
Map map;
MapEnumerator mapEnumeratorMain;
boolean inValid;
container dtValue;

CLEWBUpdateHistory updateHistory;

map = RetailCommonWebAPI::getMapFromJsonString(resBodyStr);

mapEnumeratorMain = map.getEnumerator();

if (!irnData)
{
return;
}
irnData.selectForUpdate(true);

while ( mapEnumeratorMain.moveNext() && !inValid)


{
switch (mapEnumeratorMain.currentKey())
{
case CLEInvConstant::GroupNumber:
if (mapEnumeratorMain.currentValue() != 1)
{
inValid = true;
}
break;

case CLEInvConstant::UpdatedDate:
dtValue = mapEnumeratorMain.currentValue();
if (dtValue == conNull())
{
inValid = true;
}
else
{
irnData.EWayDateTime =
str2datetime(con2str(dtValue), 321);
dtValue = conNull();
}
break;
}
}

if (!inValid)
{
ttsBegin;
irnData.CLEWBStatus = CLEWBStatus::Completed;
irnData.update();
ttsCommit;

updateHistory.IRNDataRefRecId = irnData.RecId;
updateHistory.EwayBillNo = irnData.EwayBillNo;
updateHistory.UpdateDateTime = irnData.EWayDateTime;
updateHistory.EWayValidDateTime = irnData.EWayValidDateTime;
updateHistory.UpdateAction = updateAction;
updateHistory.insert();

validResponse = true;
}
else
{
ttsBegin;
irnData.CLEWBStatus = CLEWBStatus::Error;
irnData.update();
ttsCommit;
validResponse = false;
}
}

private void prepareJsonNode(CLEInvBodyValueScope _valueScope


, str 30 _keyFieldName
, NoYes _isMultiValued = NoYes::No)
{
if (_valueScope == CLEInvBodyValueScope::Node
&& _isMultiValued)
{
writer.WriteStartArray();
isMuliValuedParentNode = true;
}
else if (_valueScope == CLEInvBodyValueScope::Node
&& !_isMultiValued)
{
writer.WriteStartObject();
}
else if (_valueScope == CLEInvBodyValueScope::ParentElement
&& _isMultiValued)
{
writer.WritePropertyName(_keyFieldName);
writer.WriteStartArray();
}
else if (_valueScope == CLEInvBodyValueScope::ParentElement
&& !_isMultiValued)
{
writer.WritePropertyName(_keyFieldName);
writer.WriteStartObject();
}
else
{
writer.WritePropertyName(_keyFieldName);
}
}

private void writeStrValue(str _value)


{
if (_value)
{
writer.WriteValue(_value);
}
else
{
writer.writeNull();
}
}
private void writeIntValue(Int _value)
{
writer.WriteValue(_value);
}

private void writeInt64Value(Int64 _value)


{
if (_value)
{
writer.WriteValue(_value);
}
else
{
writer.writeNull();
}
}

private void writeRealValue(Real _value)


{
if (_value)
{
writer.WriteValue(_value);
}
else
{
writer.writeNull();
}
}

private void insertReqLogs(int _apiId, String50 _documentId


, String50 _requestAPI, Notes _reqBody, Notes _response, RefTableId
_refTableId, RefRecId _refRecId,CLEWBStatus _status)
{

CLEInvAPIRequestLogs reqLogs;
CLEInvIRNData irnDataLoc;

select * from irnDataLoc


where irnDataLoc.InvoiceId == _documentId &&
irnDataLoc.ParentRecId == _refRecId &&
irnDataLoc.ParentTableId == _refTableId;
ttsBegin;
if(!irnDataLoc.RecId)
{
reqLogs.APIId = _apiId;
reqLogs.InvoiceId = _documentId;
reqLogs.RequestAPI = _requestAPI;
reqLogs.RequestJsonStr = _reqBody;
reqLogs.ResponseJsonStr = _response;
reqLogs.TransTableId = _refTableId;
reqLogs.TransRecId = _refRecId;
reqLogs.CLEWBStatus = _status;
reqLogs.insert();
}
else if (irnDataLoc.RecId)
{

irnDataLoc.selectForUpdate(true);
reqLogs.APIId = _apiId;
reqLogs.InvoiceId = _documentId;
reqLogs.RequestAPI = _requestAPI;
reqLogs.RequestJsonStr = _reqBody;
reqLogs.ResponseJsonStr = _response;
reqLogs.TransTableId = _refTableId;
reqLogs.TransRecId = _refRecId;
reqLogs.CLEWBStatus = _status;
irnDataLoc.update();

ttsCommit;

// original code
//CLEInvAPIRequestLogs reqLogs;

//reqLogs.APIId = _apiId;
//reqLogs.InvoiceId = _documentId;
//reqLogs.RequestAPI = _requestAPI;
//reqLogs.RequestJsonStr = _reqBody;
//reqLogs.ResponseJsonStr = _response;
//reqLogs.TransTableId = _refTableId;
//reqLogs.TransRecId = _refRecId;
//reqLogs.CLEWBStatus = _status;
//reqLogs.insert();
}
// Transport details Changes Abhishek++
private boolean getTransportDetails()
{
transportDetails = CLEWBTransportDetails::find(parentRecId, parentTableId);
if (!transportDetails.TransportMode)
{
warning("@TIS:EWBTranspDetNA");
return false;
}

return true;
}
//---abhishek

/// <summary>
/// Generated E-Way bill (No IRN)
/// </summary>
/// <param name = "_vendInvoiceJour">VendInvoiceJour</param>
/// <returns>Boolean</returns>
public boolean generateEWayBillPurchReturns(VendInvoiceJour _vendInvoiceJour)
{
System.Net.HttpWebResponse response;
CLRObject clrObj;
System.Exception ex;

System.IO.Stream requestStream;
System.IO.StreamWriter streamWriter;
System.IO.StreamReader streamRead;

try
{
vendInvoiceJour = _vendInvoiceJour;
parentTableId = vendInvoiceJour.TableId;
parentRecId = vendInvoiceJour.RecId;

irnData = CLEInvIRNData::findIRN(vendInvoiceJour.RecId,
vendInvoiceJour.TableId);
sellerPrimaryGSTIN = irnData.GSTIN;
ewbNumber = irnData.EwayBillNo;
if (ewbNumber)
{
throw warning("@TIS:EWBExists");
}
apiInfo =
CLEInvAPIInfo::findByAPIType(CLEInvAPIType::GenEwayBillNoIRN);
select firstonly invParameters;

/* if(_custInvoiceJour.InvoiceAmountMST < 50000)


{
warning("@TIS:EInvInvalidAmtEWB");
return false;
}*/

new InteropPermission(InteropKind::ClrInterop).assert();
clrObj =
System.Net.WebRequest::Create(invParameters.HostUrl+apiInfo.RequestAPI);
request = clrObj;

// adding headers
if(!this.addHeader())
{
return false;

//Req Stream
}

//Req Stream
requestStream = request.GetRequestStream();
streamWriter = new System.IO.StreamWriter(requestStream);

//Prepare Json body


this.createJSONStrBody(apiInfo.ApiId, apiInfo.APIType);

// writing JSON
streamWriter.WriteAsync(reqBodyStr);
streamWriter.Flush();
streamWriter.Close();

//Response
response = request.GetResponse();
streamRead = new System.IO.StreamReader(response.GetResponseStream());
resBodyStr = streamRead.ReadToEnd();

this.insertReqLogs(apiInfo.APIId, vendInvoiceJour.InvoiceId,
apiInfo.RequestAPI
, reqBodyStr, resBodyStr, vendInvoiceJour.TableId,
vendInvoiceJour.RecId, CLEWBStatus::Completed);

this.getGenEWBResponseKeyValues();

if (validResponse)
{
info(strFmt("@TIS:EInvEWBGenerated", vendInvoiceJour.InvoiceId));
}
else
{
warning ("@TIS:EInvEWBcantGenerated");
}
}
catch
{
//exception
ex = CLRInterop::getLastException().GetBaseException();

this.insertReqLogs(apiInfo.APIId, vendInvoiceJour.InvoiceId,
apiInfo.RequestAPI
, reqBodyStr, ex.get_Message(), vendInvoiceJour.TableId,
vendInvoiceJour.RecId,CLEWBStatus::Error);

error(ex.get_Message());
}

return true;
}

private boolean setVariablesPurchReturn()


{
VendInvoiceTrans vendInvoiceTrans;
//CustInvoiceLineTaxExtensionIN lineTaxExtension;
TaxInformation_IN taxInformation, custTaxInformation;
TaxRegistrationNumbers_IN taxRegNumbers, custTaxRegNumbers;
CLEInvGSTINUnitList orgUnitList;
TaxWithholdTrans_IN taxWithholdTransLoc;
TransTaxInformationRelationView taxInformationRelationView;
TransTaxInformation transTaxInfo;

transportDetails = CLEWBTransportDetails::find(parentRecId, parentTableId);


if (!transportDetails)
{
warning("@TIS:EWBTranspDetNA");
return false;
}

totalInvAmt = vendInvoiceJour.InvoiceAmount;
totalInvAmtMST = vendInvoiceJour.InvoiceAmountMST;

typ = enum2Value(transportDetails.DocumentType);

no = vendInvoiceJour.InvoiceId;
Dt = date2str(vendInvoiceJour.InvoiceDate, 123, 2, DateSeparator::Slash, 2,
DateSeparator::Slash, DateSeparator::Slash, 4);

select sum(TaxWithholdAmount),
sum(TaxWithholdAmountOrigin),TaxWithholdValue from taxWithholdTransLoc
where taxWithholdTransLoc.Voucher ==
vendInvoiceJour.LedgerVoucher
&& taxWithholdTransLoc.TransDate ==
vendInvoiceJour.InvoiceDate;
tcsRate = taxWithholdTransLoc.TaxWithholdValue;
tcsAmt = taxWithholdTransLoc.TaxWithholdAmount;
preTcsAmt = taxWithholdTransLoc.TaxWithholdAmountOrigin *
(vendInvoiceJour.ExchRate/100);

voucher = vendInvoiceJour.ledgerVoucher;

select sum(value) from markupTrans


where markupTrans.TransTableId == vendInvoiceJour.TableId
&& markupTrans.TransRecId == vendInvoiceJour.RecId;

othChrgs = markupTrans.Value;

//
companyInfo = CompanyInfo::find();
vendTable = VendTable::find(vendInvoiceJour.InvoiceAccount);

select firstonly vendInvoiceTrans


where vendInvoiceTrans.PurchID == vendInvoiceJour.PurchId
&& vendInvoiceTrans.InvoiceId == vendInvoiceJour.InvoiceId
&& vendInvoiceTrans.InvoiceDate == vendInvoiceJour.InvoiceDate
&& vendInvoiceTrans.numberSequenceGroup ==
vendInvoiceJour.numberSequenceGroup;

select firstonly transTaxInfo


join taxInformationRelationView
where taxInformationRelationView.TransTaxInformationRefRecId ==
transTaxInfo.RecId
&& taxInformationRelationView.TransactionRefTableId ==
vendInvoiceTrans.TableId
&& taxInformationRelationView.TransactionRefRecId ==
vendInvoiceTrans.RecId;

taxInformation = TaxInformation_IN::find(transTaxInfo.TaxInformation);
custTaxInformation =
TaxInformation_IN::find(transTaxInfo.VendorTaxInformation);

taxRegNumbers = TaxRegistrationNumbers_IN::find(taxInformation.GSTIN);
sellerPostalAddress =
LogisticsPostalAddress::findByLocation(taxInformation.RegistrationLocation);

custTaxRegNumbers =
TaxRegistrationNumbers_IN::find(custTaxInformation.GSTIN);
buyerGSTIN = custTaxRegNumbers.RegistrationNumber;
if (buyerGSTIN)
{
supType = CLEInvSupType::B2B;
}

if(!custTaxInformation)
{
buyerPostalAddress =
LogisticsPostalAddress::findByLocation(LogisticsPostalAddress::findRecId(vendTable.
invoiceAddress().RecId).Location);
}
else
{
buyerPostalAddress =
LogisticsPostalAddress::findByLocation(custTaxInformation.RegistrationLocation);
}
deliveryPostalAddress =
LogisticsPostalAddress::findByLocation(LogisticsPostalAddress::findRecId(vendInvoic
eJour.DeliveryPostalAddress).Location);
sellerPrimaryGSTIN = taxRegNumbers.RegistrationNumber;

//for demo only


if (invParameters.StagingMode)
{
select firstOnly orgUnitList
where orgUnitList.StateId ==
LogisticsAddressState::find(sellerPostalAddress.CountryRegionId,
sellerPostalAddress.State).StateCode_IN;

//sellerPrimaryGSTIN =
TaxRegistrationNumbers_IN::find( orgUnitList.GSTRegistrationNumber).RegistrationNu
mber;
sellerPrimaryGSTIN =orgUnitList.DemoRegistrationNumber;
}
//for demo only - finish

sellerPhone = subStr(strKeep(companyInfo.phone(),
CLEInvConstant::phone),1,12);
sellerEmail = companyInfo.email();
sellerName = companyInfo.Name();
sellerTrdName = companyInfo.NameAlias;

buyerPhone = strKeep(vendTable.phone(),CLEInvConstant::phone);
buyerEmail = vendTable.email();
buyerName = vendTable.Name();
buyerTrdName = vendTable.nameAlias();
zipcode = strRemoveCr(buyerPostalAddress.ZipCode);
city = buyerPostalAddress.City;
stateCode =
LogisticsAddressState::find(buyerPostalAddress.CountryRegionId,
buyerPostalAddress.State).StateCode_IN;

return true;
}

private void getItemListPurchReturn(Integer _keyId)


{
VendInvoiceTrans vendInvoiceTrans;
//SalesLine_IN salesLine;
HSNCodeTable_IN hsnCodeTable;
ServiceAccountingCodeTable_IN serviceCodetable;
TransTaxInformation transTaxInfo;
TransTaxInformationRelationView taxInformationRelationView;

Counter lineNum;
ExchRate exchRate;
str isserv = CLEInvConstant::N, hsnServCode;

//CustInvoiceLine custInvLine;
//CustInvoiceTable custInvTable;

exchRate = vendInvoiceJour.ExchRate/100;
while select vendInvoiceTrans
where vendInvoiceTrans.PurchID == vendInvoiceJour.PurchId
&& vendInvoiceTrans.InvoiceId == vendInvoiceJour.InvoiceId
&& vendInvoiceTrans.InvoiceDate == vendInvoiceJour.InvoiceDate
&& vendInvoiceTrans.numberSequenceGroup ==
vendInvoiceJour.numberSequenceGroup
join taxInformationRelationView
where taxInformationRelationView.TransactionRefTableId ==
vendInvoiceTrans.TableId
&& taxInformationRelationView.TransactionRefRecId ==
vendInvoiceTrans.RecId
join transTaxInfo
where transTaxInfo.RecId ==
taxInformationRelationView.TransTaxInformationRefRecId
{
if (transTaxInfo.HSNCodeTable)
{
hsnCodeTable= HSNCodeTable_IN::find(transTaxInfo.HSNCodeTable);
hsnServCode = hsnCodeTable.Code;
}
else if(transTaxInfo.ServiceAccountingCodeTable)
{
serviceCodetable =
ServiceAccountingCodeTable_IN::find(transTaxInfo.ServiceAccountingCodeTable);
isserv = CLEInvConstant::Y;
hsnServCode = serviceCodetable.SAC;
}

totalGSTAmt = 0;
totalGSTPr = 0;
totalCESSAmt = 0;
totalCESSPr = 0;
taxAmtCGST = 0;
taxAmtSGST = 0;
taxAmtIGST = 0;
taxAmtCESS = 0;
taxPerCGST = 0;
taxPerSGST = 0;
taxPerIGST = 0;
taxPerCESS = 0;

lineNum++;

this.calculateItemTaxes(vendInvoiceTrans.InvoiceDate,
vendInvoiceTrans.TableId, vendInvoiceTrans.RecId, exchRate);

this.setItemValues(_keyId, lineNum, vendInvoiceTrans.TableId,


vendInvoiceTrans.RecId, exchRate
, vendInvoiceTrans.ItemId, vendInvoiceTrans.itemName()?
vendInvoiceTrans.itemName():vendInvoiceTrans.Name, isserv, hsnServCode,
vendInvoiceTrans.Qty?vendInvoiceTrans.Qty:1, vendInvoiceTrans.PurchUnit?
vendInvoiceTrans.PurchUnit:'NOS', vendInvoiceTrans.PurchPrice?
vendInvoiceTrans.PurchPrice:vendInvoiceTrans.LineAmountMST
, vendInvoiceTrans.discAmount());//,
custInvoiceTrans.amountDiscPercentInclTax());
}

//End itemlist Array


writer.WriteEndArray();
}

You might also like