New Changes
New Changes
/// 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);
// 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);
//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;
}
return 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;
}
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;
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);
taxInformation = TaxInformation_IN::find(transTaxInfo.TaxInformation);
custTaxInformation =
TaxInformation_IN::find(transTaxInfo.CustomerTaxInformation);
}
else if (custInvoiceJour.RefNum == RefNum::Cust)
{
custInvoiceLine =
CustInvoiceLine::findByParentRecId(custInvoiceJour.custInvoiceTable().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;
//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;
}
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;
othChrgs = markupTrans.Value;
//
supType = CLEInvSupType::B2B;
companyInfo = CompanyInfo::find();
InventTransferLine transferLine;
//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);
}
//sellerPrimaryGSTIN
=TaxRegistrationNumbers_IN::find( orgUnitList.GSTRegistrationNumber).RegistrationN
umber;
sellerPrimaryGSTIN =orgUnitList.DemoRegistrationNumber;
}
//for demo only - finish
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;
}
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);
//}
//sellerPrimaryGSTIN =
TaxRegistrationNumbers_IN::find( orgUnitList.GSTRegistrationNumber).RegistrationNu
mber;
sellerPrimaryGSTIN =orgUnitList.DemoRegistrationNumber;
}
//for demo only - finish
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();
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);
}
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");
}
// adding headers
this.addHeader();
//Req Stream
requestStream = request.GetRequestStream();
streamWriter = new System.IO.StreamWriter(requestStream);
// writing JSON
streamWriter.WriteAsync(reqBodyStr);
streamWriter.Flush();
streamWriter.Close();
//Response
response = request.GetResponse();
streamRead = new System.IO.StreamReader(response.GetResponseStream());
resBodyStr = streamRead.ReadToEnd();
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);
}
}
map = RetailCommonWebAPI::getMapFromJsonString(resBodyStr);
mapEnumeratorMain = map.getEnumerator();
if (!irnData)
{
return;
}
irnData.selectForUpdate(true);
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;
}
}
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);
}
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));
}
}
Counter lineNum;
ExchRate exchRate;
str isserv = CLEInvConstant::N, hsnServCode;
//CustInvoiceLine custInvLine;
//CustInvoiceTable custInvTable;
exchRate = custInvoiceJour.ExchRate/100;
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);
Counter lineNum;
str isserv = CLEInvConstant::N, hsnServCode;
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);
Counter lineNum;
str isserv = CLEInvConstant::N, hsnServCode;
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);
}
//oldItemId = inventTransferJourLine.ItemId;
}
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;
}
}
}
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)));
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);
}
}
}
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");
}
// adding headers
this.addHeader();
//Req Stream
requestStream = request.GetRequestStream();
streamWriter = new System.IO.StreamWriter(requestStream);
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.getEWBUpdateResponseKeyValues();
if (validResponse)
{
info(strFmt("@TIS:EWBUpdateValid", _documentId));
}
else
{
warning ("@TIS:EWBUpdateInvalid");
}
}
catch
{
//exception
ex = CLRInterop::getLastException().GetBaseException();
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);
}
}
CLEWBUpdateHistory updateHistory;
map = RetailCommonWebAPI::getMapFromJsonString(resBodyStr);
mapEnumeratorMain = map.getEnumerator();
if (!irnData)
{
return;
}
irnData.selectForUpdate(true);
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;
// adding headers
this.addHeader();
//Req Stream
requestStream = request.GetRequestStream();
streamWriter = new System.IO.StreamWriter(requestStream);
// 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();
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;
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);
// 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);
}
}
map = RetailCommonWebAPI::getMapFromJsonString(resBodyStr);
mapEnumeratorMain = map.getEnumerator();
if (!irnData)
{
return;
}
irnData.selectForUpdate(true);
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");
}
// adding headers
this.addHeader();
//Req Stream
requestStream = request.GetRequestStream();
streamWriter = new System.IO.StreamWriter(requestStream);
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.getMultiVehEWBUpdateResponseKeyValues();
if (validResponse)
{
info(strFmt("@TIS:EWBUpdateValid", _documentId));
}
else
{
warning ("@TIS:EWBUpdateInvalid");
}
}
catch
{
//exception
ex = CLRInterop::getLastException().GetBaseException();
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);
}
}
}
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();
}
CLEWBUpdateHistory updateHistory;
map = RetailCommonWebAPI::getMapFromJsonString(resBodyStr);
mapEnumeratorMain = map.getEnumerator();
if (!irnData)
{
return;
}
irnData.selectForUpdate(true);
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;
}
}
CLEInvAPIRequestLogs reqLogs;
CLEInvIRNData irnDataLoc;
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;
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);
// 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;
}
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;
othChrgs = markupTrans.Value;
//
companyInfo = CompanyInfo::find();
vendTable = VendTable::find(vendInvoiceJour.InvoiceAccount);
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;
//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;
}
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);