X++ to get addresses,GST Numbers,state code,HSN/SAC codes from Tax information of customer invoice journal in D365FO
TaxDocumentRowTransaction taxDocumentRowTransaction;
TaxDocumentRowTransaction_IN taxDocumentRowTransaction_IN;
TransTaxInformationHelper transTaxInformationHelper;
TransTaxInformation transTaxInformation, transTaxInformationItem;
LogisticsPostalAddress logisticsPostalAddress, supplierPostalAddress;
LogisticsAddressState logisticsAddressState, supplierState;
CustInvoiceTrans CustInvoiceTrans;
select taxDocumentRowTransaction
where taxDocumentRowTransaction.voucher == ""
&& taxDocumentRowTransaction.Source == TaxModuleType::SalesInvoice
join taxDocumentRowTransaction_IN
where taxDocumentRowTransaction_IN.TaxDocumentRowTransactionRecId == taxDocumentRowTransaction.RecId;
//Retrieving address of a sales invoice journal(Customer tax information address from transaction level)
logisticsPostalAddress = LogisticsPostalAddress::findRecId(taxDocumentRowTransaction.PartyPostalAddress);
logisticsAddressState = LogisticsAddressState::find(logisticsPostalAddress.CountryRegionId, logisticsPostalAddress.State);
//Retrieving address of a sales invoice journal (company address from the transaction level)
supplierPostalAddress = LogisticsPostalAddress::findRecId(taxDocumentRowTransaction.CompanyPostalAddress);
supplierState = LogisticsAddressState::find(supplierPostalAddress.CountryRegionId, supplierPostalAddress.State);
select firstonly CustInvoiceTrans
where CustInvoiceTrans.ParentRecId == custInvoiceJour.RecId;
// To get all the details from Tax Information at a Transaction level
transTaxInformationHelper = TransTaxInformationHelper::newHelper();
transTaxInformation = transTaxInformationHelper.getTransTaxInformation(tableNum(CustInvoiceTrans), custInvoiceTransLoc.RecId);
// To get the Company address from tax information.
LogisticsLocationEntity::location2PostalAddress(transTaxInformation.CompanyLocation, DateTimeUtil::getSystemDateTime(), true).Address;
LogisticsLocationEntity::location2PostalAddress(transTaxInformation.CustomerLocation, DateTimeUtil::getSystemDateTime(), true).City;
LogisticsLocationEntity::location2PostalAddress(transTaxInformation.CustomerLocation, DateTimeUtil::getSystemDateTime(), true).ZipCode;
// Customer tax information address
LogisticsLocationEntity::location2PostalAddress(transTaxInformation.CustomerLocation, DateTimeUtil::getSystemDateTime(), true).Address;
// To Find HSN/SAC Code
HSNCodeTable_IN::find(transTaxInformation.HSNCodeTable).Code;
ServiceAccountingCodeTable_IN::find(transTaxInformation.ServiceAccountingCodeTable).SAC;
//Warehouse address
inventLocationLogisticsLocation inventLocationLogisticsLocation;
logisticsLocation logisticsLocation;
LogisticsPostalAddress logisticsPostalAddress;
InventLocation inventFromLocation = InventLocation::find('warehouse');
Select firstOnly inventLocationLogisticsLocation
where inventLocationLogisticsLocation.InventLocation == inventFromLocation.RecId
&& inventLocationLogisticsLocation.IsPrimary == 1;
if (inventLocationLogisticsLocation)
{
select firstOnly logisticsLocation
where logisticsLocation.RecId == InventLocationLogisticsLocation.Location;
}
logisticsPostalAddress = logisticsPostalAddress::findByLocation(logisticsLocation.recid);
info(LogisticsPostalAddress.Address);
// Replace '\n' with null in address
TextBuffer textBuffer = new TextBuffer();
textBuffer.setText(Address);
textBuffer.Replace('\n','');
info(textBuffer.getText());
//Get GSTIn Numbers
TaxRegistrationNumbers_IN taxRegistrationNumbers_IN;
TaxInformation_IN taxInformation_IN;
select taxRegistrationNumbers_IN
join taxInformation_IN
where taxInformation_IN.GSTIN == taxRegistrationNumbers_IN.RecId
&& taxInformation_IN.RecID == transTaxInformation.CustomerTaxInformation;
Info(taxRegistrationNumbers_IN.RegistrationNumber);
//Company GSTIN
TaxRegistrationNumbers_IN::find(transTaxInformation.GSTIN).RegistrationNumber;
Keep Learning!!