class Invoice_Events
{
[PostHandlerFor(classStr(NW_InvoiceDP), methodStr(NW_InvoiceDP, processReport))]
public static void NW_InvoiceDP_Post_processReport(XppPrePostArgs args)
{
SalesTable SalesTable;
SalesLine SalesLine;
DirPartyPostalAddressView dirPartyPostalAddrlocal;
DirPartyLocationRolesView dirPartyLocationRoleslocal;
LogisticsLocationRole logisticsLocRole;
NW_InvoiceType InvoiceType;
CustInvoiceJour InvoiceJour;
DimensionAttributeValueSetStorage dimStorage;
NW_InvoiceDP dpInstance = args.getThis() as NW_InvoiceDP;
NW_InvoiceTmp InvoiceTmp = dpInstance.getASASSalesInvoiceTmp();
SalesTable = SalesTable::find(InvoiceTmp.SalesId);
select InvoiceType where InvoiceType.CodeType == SalesTable.InvoiceType;
select InvoiceJour where InvoiceJour.InvoiceId == InvoiceTmp.InvoiceId;
select firstOnly * from dirPartyPostalAddrlocal order by RecId desc
exists join dirPartyLocationRoleslocal
where dirPartyLocationRoleslocal.Location == dirPartyPostalAddrlocal.Location
&& dirPartyLocationRoleslocal.Party == CustTable::find(SalesTable.CustAccount).Party
&& dirPartyPostalAddrlocal.IsPrimary == NoYes::No
exists join logisticsLocRole
where logisticsLocRole.Name == 'Arabic Add' //like Delivery,Invoice,Business
&& logisticsLocRole.RecId == dirPartyLocationRoleslocal.LocationRole
&& logisticsLocRole.IsPostalAddress;
ttsbegin;
InvoiceTmp.ArAddress = dirPartyPostalAddrlocal.address;
InvoiceTmp.InvoiceTypeAr = InvoiceType.Arabic;
InvoiceTmp.InvoiceTypeEn = InvoiceType.English;
InvoiceTmp.ServiceMonth = strFmt("%1/%2",InvoiceJour.Month,InvoiceJour.Year);
select firstonly SalesLine where SalesLine.SalesId == SalesTable.SalesId;
dimStorage = DimensionAttributeValueSetStorage::find(SalesLine.DefaultDimension);
InvoiceTmp.Project = ProjTable::find(dimStorage.getDisplayValueByDimensionAttribute(DimensionAttribute::findByName('FD04_Profit_Center').RecId)).Name;
// CustTable.VATNum
InvoiceTmp.update();
ttscommit;
NW_InvoiceLineTmp InvoiceLineTmp = dpInstance.getASASSalesInvoiceLineTmp();
ttsbegin;
while select forUpdate InvoiceLineTmp
{
select SalesLine where SalesLine.SalesId == SalesTable.SalesId
&& SalesLine.LineAmount == InvoiceLineTmp.LineAmountMST
&& SalesLine.SalesQty == InvoiceLineTmp.qty;
InvoiceLineTmp.SalesUnit = SalesLine.SalesUnit;
InvoiceLineTmp.update();
}
ttscommit;
}
}