Purchase Order Invoice posting with using X++ with custom VendInvoiceInfoLine fields
private boolean postPOInvoice(PurchTable purchTable)
{
PurchFormLetter letter = purchFormLetter::construct(DocumentStatus::Invoice);
PurchParmUpdate purchParmUpdate;
PurchLine purchLineLocal;
VendInvoiceInfoTable vendInvoiceInfoTable;
VendInvoiceInfoLine vendInvoiceInfoLine, vendInvoiceInfoLineFrom;
boolean ret = true;
letter.purchTable(purchTable);
letter.initParmDefault();
letter.transDate (systemdateget());
letter.specQty (PurchUpdate::All);
letter.parmParmTableNum(strFmt("%1-R", vendInvoiceJour.InvoiceId));
letter.proforma (false);
letter.printFormLetter (false);
letter.initParameters(letter.purchParmUpdate(), PrintOut::Current); // Printout
letter.initLinesQuery();
while select forUpdate vendInvoiceInfoLine where vendInvoiceInfoLine.ParmId == letter.ParmId()
{
purchLineLocal = vendInvoiceInfoLine.purchLine();
if(purchLineLocal.RemainPurchPhysical != 0)
{
vendInvoiceInfoLine.customField1 = <<customField1>>
vendInvoiceInfoLine.ReceiveNow = purchLineLocal.PurchQty;
vendInvoiceInfoLine.setQty(vendInvoiceInfoLine.vendInvoiceInfoTable().Ordering, letter.PurchParmUpdate().creditRemaining);
vendInvoiceInfoLine.setInventReceiveNow();
vendInvoiceInfoLine.setLineAmount();
if (vendInvoiceInfoLine.closed)
{
vendInvoiceInfoLine.remainAfter = 0;
vendInvoiceInfoLine.setRemainAfterInvent();
}
vendInvoiceInfoLine.update();
}
else
{
checkFailed(strFmt("Purchase order %1 does not have the remaining qty to invoice", purchTable.PurchId));
}
}
letter.run();
vendInvoiceJourNew = letter.getOutputContract().parmJournal();
}
info(strfmt("Purchase order posted with Invoice Id %1", vendInvoiceJourNew.InvoiceId));
return ret;
}
Comments
Post a Comment