Wednesday 29 June 2016

Generate payments (Cheque) for vendor in AX using X++

static void GeneratePayment(Args _args)
{
    LedgerJournalTrans ledgerJournalTrans = LedgerJournalTrans::findRecId(5637186584, true);
    VendSumForPaym vendSumForPaym;
    boolean runDialog;
    LedgerJournalCheckPostResults postingResults_Client;
    LedgerPostingMessage logTxt;
    VendPaymModeTable vendPaymModeTable;
    DimensionAttributeValueCombination  dimAttrValComb;
    BankAccountTable bankAccountTable;
    ;

    vendSumForPaym = CustVendSumForPaym::newLedgerJournalTrans(LedgerJournalTrans);
    runDialog = vendSumForPaym.validateTransactions();
    if(!runDialog)
        throw error("@SYS319214");
 
    select firstfast vendPaymModeTable
            where vendPaymModeTable.PaymMode == ledgerJournalTrans.PaymMode
               && vendPaymModeTable.PaymentType == PaymentType::Check;

    dimAttrValComb = DimensionAttributeValueCombination::find(vendPaymModeTable.PaymentLedgerDimension);
    bankAccountTable = BankAccountTable::find(dimAttrValComb.DisplayValue);
     
    vendSumForPaym.parmBankAccountID(bankAccountTable.AccountID);
    vendSumForPaym.parmPaymMode(LedgerJournalTrans.PaymMode);
 
    if (vendSumForPaym.validate())
    {
        vendSumForPaym.run();
        if (ledgerJournalTrans.parmLedgerDimension())
        {
            postingResults_Client = LedgerJournalCheckPostResults::construct();
            logTxt = postingResults_Client.errorLogJournalLine(tableNum(LedgerJournalTrans), LedgerJournalTrans.RecId);
            if (logTxt)
            {
                throw error(strFmt('%1',logTxt));
            }
            else
            {
                CustVendPDCManager::updatePostDatedCheckNum(LedgerJournalTrans.journalNum);
            }
        }
    }
}

No comments:

Post a Comment