void settleTransactions(ProjInvoiceJour _projInvoiceJour, LedgerJournalTrans _paymLedgerJournalTrans) { CustTable custTable = CustTable::find(_projInvoiceJour.InvoiceAccount); // find related transaciton LedgerJournalTrans paymLedgerJournalTransLoc; CustTransOpen invCustTransOpen, paymCustTransOpen; CustTrans invCustTrans, paymCustTrans; // Given the payment LedgerJournalTrans, find the related CustTrans which has CustTransOpen select firstonly paymLedgerJournalTransLoc where paymLedgerJournalTransLoc.RecId == _paymLedgerJournalTrans.RecId join paymCustTrans where paymCustTrans.Voucher == paymLedgerJournalTransLoc.Voucher && paymCustTrans.AccountNum == custTable.AccountNum && paymCustTrans.RecId == paymLedgerJournalTransLoc.CustTransId && paymCustTrans.TransType == LedgerTransType::GeneralJournal join paymCustTransOpen where paymCustTransOpen.RefRecId == paymCustTrans.RecId; // Find the related invoice to be settled against the payment journal in the query above select firstonly invCustTrans where invCustTrans.AccountNum == custTable.AccountNum && invCustTrans.Voucher == _projInvoiceJour.LedgerVoucher && invCustTrans.TransType == LedgerTransType::Project join invCustTransOpen where invCustTransOpen.RefRecId == invCustTrans.RecId; // Settlement SpecTransExecutionContext specTransExecutionContext = SpecTransExecutionContext::newFromSource(custTable); SpecTransManager specTransManager = SpecTransManager::newFromSpec(specTransExecutionContext.parmSpecContext()); Amount settleAmount = invCustTransOpen.AmountCur; //Prevent over settle if(settleAmount > (-paymCustTransOpen.AmountCur)) { settleAmount = (-paymCustTransOpen.AmountCur); } //Payment specTransManager.insert(paymCustTransOpen.DataAreaId, paymCustTransOpen.TableId, paymCustTransOpen.RecId, -settleAmount, paymCustTrans.CurrencyCode); //Invoice specTransManager.insert(invCustTransOpen.DataAreaId, invCustTransOpen.TableId, invCustTransOpen.RecId, settleAmount, invCustTrans.CurrencyCode); //Settle if(CustTrans::settleTransaction(specTransExecutionContext, CustTransSettleTransactionParameters::construct())) { info(strFmt("Settlement completed for Invoice %1, Journal reversal payment %2, Amount %3", _projInvoiceJour.ProjInvoiceId, _paymLedgerJournalTrans.JournalNum, settleAmount)); } else { throw Error("Settlement failed."); } }
If you found value in what I share, I've set up a Buy Me a Coffee page as a way to show your support.
Buy Me a CoffeeNo comments. Be the first one to comment on this post.
DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.
Authors are allowed to set their own "buy me a coffee" link.
Join us.