static void RB_invoiceConsolidatedPurchaseOrder(Args _args)
{
Purchformletter_invoice Purchformletter;
vendPackingSlipJour vendPackingSlipJour;
TmpFrmVirtual tmpFrmVirtual;
ParmId parmId;
VendInvoiceInfoTable vendinvoiceinfoTable;
vendInvoiceInfoLine vendInvoiceInfoLine;
int i;
container con;
PurchId PurchId;
purchline purchline;
List selectedList = new List(Types::Record);
;
try
{
//Getting the multiple purchase order in the container.
// Here i am using 2 purchase order 12020015,12020016
con+= ['12020015'];
con+= ['12020016'];
for (i = 1; i <= conLen(con); i++)
{
PurchId = conpeek(con,i);
ttsbegin;
tmpFrmVirtual.setTmp();
// Add the packing slips into tmpFrmVirtual
while select vendpackingslipjour
where vendpackingslipjour.PurchId == PurchId
{
tmpFrmVirtual.clear();
tmpFrmVirtual.TableNum = vendpackingslipjour.TableId;
tmpFrmVirtual.RecordNo = vendpackingslipjour.RecId;
tmpFrmVirtual.NoYes = NoYes::Yes;
tmpFrmVirtual.Id = vendpackingslipjour.PurchId;
tmpFrmVirtual.insert();
}
ttsCommit;
}
while select tmpFrmVirtual
{
selectedList.addEnd(tmpFrmVirtual);
}
// Construct form letter
Purchformletter = purchformletter::construct(DocumentStatus::Invoice);
// Add the packing slips to the purch form letter
Purchformletter.selectFromJournal(selectedList.pack());
purchformletter.sumBy(AccountOrder::Account);
purchformletter.reArrangeNow(true);
purchformletter.reArrange();
purchformletter.specQty(purchupdate::ReceiveNow);
purchformletter.parmNumber('EDICONS123');
parmId = purchformletter.parmId();
//Edit the vendInvoiceInfo table if you need it , otherwise this code is not needed.
ttsBegin;
select forupdate vendInvoiceInfoTable
where vendinvoiceinfoTable.ParmId == parmId;
vendInvoiceInfoTable.Num = 'EDICONS123';
vendInvoiceInfoTable.VarianceApproved = NoYes::Yes;
vendInvoiceInfoTable.DocumentDate = 15\03\2019;
vendInvoiceInfoTable.FixedDueDate = 16\03\2019;
vendInvoiceInfoTable.update();
for (i = 1; i <= conLen(con); i++)
{
PurchId = conpeek(con,i);
while select RecId from purchline
where purchline.PurchId == purchId &&
purchline.IsDeleted == NoYes::No
{
vendInvoiceInfoLine = vendInvoiceInfoLine::findByPurchLineRefRecId(purchLine.RecId,true);
vendInvoiceInfoLine.update();
}
}
ttsCommit;
//Post the consolidated invoice.
purchFormLetter.run();
if (purchFormLetter.parmJournalRecord().recid)
{
info("Invoice completed sucessfully");
}
}
catch
{
throw error(strFmt("Invoice failed"));
}
}