Find credit note original sales order on sales order invoice report
[ExtensionOf(classStr(SalesInvoiceDP))]
final class HIGSalesInvoiceDP_Extension
{
protected void populateSalesInvoiceHeaderFooterTmp(CustInvoiceJour _custInvoiceJour, CompanyInfo _companyInfo)
{
CustInvoiceTrans custInvoiceTrans,custInvoiceTransOrig;
SalesLine salesLine;
InventTransOrigin transOrigin,transOriginOrig;
InventTrans inventTrans;
next populateSalesInvoiceHeaderFooterTmp(_custInvoiceJour,_companyInfo);
salesInvoiceHeaderFooterTmp.BuyerAddress = _custInvoiceJour.deliveryAddress();
salesInvoiceHeaderFooterTmp.BuyerName = _custInvoiceJour.DeliveryName;
salesInvoiceHeaderFooterTmp.CompanyAddress = strReplace(salesInvoiceHeaderFooterTmp.CompanyAddress,"\n",",");
salesInvoiceHeaderFooterTmp.HIGDueDate = salesInvoiceHeaderFooterTmp.InvoiceDate + PaymTerm::find(_custInvoiceJour.Payment).NumOfDays ;
//salesInvoiceHeaderFooterTmp.CompanyBankAccount = BankAccountTable::find(_companyInfo.Bank).AccountNum;
salesInvoiceHeaderFooterTmp.CompanyEmail = _companyInfo.email();
// Code starts from here
if(_custInvoiceJour.InvoiceAmount <0)
{
select firstonly InvoiceId from custInvoiceTransOrig
join InventTransIdReturn from salesLine
where salesLine.InventTransIdReturn != ""
join InventTransId from custInvoiceTrans
where custInvoiceTrans.InvoiceId ==_custInvoiceJour.InvoiceId
&& custInvoiceTrans.InventTransId == salesLine.InventTransId
&& custInvoiceTransOrig.InventTransId == salesLine.InventTransIdReturn;
/* if(!custInvoiceTransOrig.InvoiceId)
{
select firstonly MarkingRefInventTransOrigin from inventTrans
exists join custInvoiceTrans
where custInvoiceTrans.InvoiceId ==_custInvoiceJour.InvoiceId
&& custInvoiceTrans.LineAmount <0
join transOrigin
where transOrigin.InventTransId == custInvoiceTrans.InventTransId
&& inventTrans.InventTransOrigin == transOrigin.RecId;
select firstonly InvoiceId from custInvoiceTransOrig
join transOriginOrig
where transOriginOrig.RecId == inventTrans.MarkingRefInventTransOrigin
&& transOriginOrig.InventTransId == custInvoiceTransOrig.InventTransId;
}*/
salesInvoiceHeaderFooterTmp.HIGPurchOrderFormNum =custInvoiceTransOrig.InvoiceId ;
}
// Code ends from here
else
{
InterCompanyPurchSalesReference salesRef;
select firstonly salesRef
where salesRef.SalesId == _custInvoiceJour.salesTable().SalesId;
if(salesRef.PurchId)
{
salesInvoiceHeaderFooterTmp.HIGPurchOrderFormNum = salesRef.PurchId;
}
else
{
salesInvoiceHeaderFooterTmp.HIGPurchOrderFormNum = _custInvoiceJour.salesTable().PurchOrderFormNum;
}
}
BankAccountTable bankAccTable = BankAccountTable::find(_companyInfo.Bank);
if(bankAccTable.CurrencyCode != "GBP")
{
salesInvoiceHeaderFooterTmp.HIGCompanyBankInfo = "Rounting No: "+bankAccTable.RegistrationNum+"\n"+ "Account Number: "+bankAccTable.AccountNum;
}
else
{
salesInvoiceHeaderFooterTmp.HIGCompanyBankInfo = "Sort Code: "+bankAccTable.BankSortCode+"\n"+ "Account Number: "+bankAccTable.AccountNum;
}
}
}
Comments
Post a Comment