Thursday, June 13, 2019

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

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;
    }

}

How to enable the dimension fields based on the Item selected on the form.

[Form] public class KMTShipFromWarehouses extends FormRun {     InventDimCtrl_Frm_EditDimensions        inventDimFormSetup;     /// ...