Tuesday, 22 November 2016

How to mark Vendor open settlement transaction using x++ code in Ax 2012

public void settlementnew(InvoiceId   _invoice)
{
    custvendopentransmanager            manager;
    VendTransOpen                       vendTransOpen;
    VendTrans                           vendTrans;
    ExchangeRateHelper                  exchangeRateHelper;
    AmountCur                           totalSettlement;

    //To mark particular invoice based on Acc num
    select vendtransopen where vendTransOpen.AccountNum ==AccountNumb
                join vendTrans where vendTrans.Invoice == _invoice
                     && vendTrans.RecId == vendtransopen.RefRecId
                    && vendTrans.AccountNum == vendTransOpen.AccountNum;
   
    if(vendtransopen)
    {
        //To check transaction line which we want to settle
        manager = custvendopentransmanager::construct(ledgerJournalTrans);
        manager.updateTransMarked(vendTransOpen,true);
   
        //To get total settlement
        exchangeRateHelper = ExchangeRateHelper::newCurrency(Ledger::primaryLedger(CompanyInfo::findDataArea(ledgerJournalTrans.Company).RecId),ledgerJournalTrans.CurrencyCode);
        totalSettlement    = SpecTransManager::getTotalSettleAmountForSpecReference(
                                ledgerJournalTrans.Company,
                                ledgerJournalTrans.TableId,
                                ledgerJournalTrans.RecId,
                                ledgerJournalTrans.CurrencyCode,
                                ledgerJournalTrans.Company,
                                ledgerJournalTrans.TransDate,
                                exchangeRateHelper.prepareExchangeRateForStorage(ledgerJournalTrans.crossrate()));
        //To update in ledgerJournal trans
        ttsBegin;
        ledgerJournalTrans.selectForUpdate(true);
        ledgerJournalTrans.AmountCurDebit   = abs(totalSettlement);
        ledgerJournalTrans.SettleVoucher    = SettlementType::SelectedTransact;
        ledgerJournalTrans.update();
        ttsCommit;
    }

}

http://www.andesoft.net/automatic-mark-settlement-transactions-payment-journal-ax-2012/

2 comments: