Sales order invoice posting using X++ with custom SalesParmLine fields
private boolean postSOInvoice(SalesTable salesTable)
{
SalesFormLetter letter = SalesFormLetter::construct(DocumentStatus::Invoice);
CustInvoiceTrans custInvoiceTransFrom;
SalesParmLine salesParmLine;
SalesParmUpdate salesParmUpdate;
SalesLine salesLineLocal;
boolean ret = true;
letter.salesTable(salesTable);
letter.initParmDefault();
letter.transDate (systemDateGet());
letter.specQty (SalesUpdate::All);
letter.proforma (false);
letter.printFormLetter (false);
letter.initParameters(letter.salesParmUpdate(), PrintOut::Current); // Printout
letter.initLinesQuery();
while select forUpdate salesParmLine where salesParmLine.ParmId == letter.parmId()
{
salesLineLocal = salesParmLine.salesLine();
if(salesLineLocal.RemainSalesPhysical != 0)
{
salesParmLine.custom field1 =<<customField1>>;
// changed the Qty
salesParmLine.DeliverNow = salesLineLocal.SalesQty;
// the following is stollen from the SalesEditLines form (field modified method)
salesParmLine.setQty(salesParmLine.salesParmTable().ordering, letter.SalesParmUpdate().creditRemaining);
salesParmLine.setInventDeliverNow();
salesParmLine.setLineAmount();
if (salesParmLine.closed)
{
salesParmLine.remainAfter = 0;
salesParmLine.setRemainAfterInvent();
}
salesParmLine.update();
}
else
{
checkFailed(strFmt("Sales order %1 does not have remainig qty to invoice", salesTable.SalesId));
}
}//end of while
letter.run();
custInvoiceJourNew = letter.getOutputContract().parmJournal();
}
info(strfmt("sales order posted with invoice Id %1", custInvoiceJourNew.InvoiceId));
return ret;
}
Comments
Post a Comment