Wednesday, 22 November 2017

Create Customer Payment journal for Multiple Invoices via X++ in D365 or AX 2012

In my case, I am going to create Payment journal and vouchers based on multiple Free text invoices. Same process can also be followed for multiple Sales orders.
Create a button on Free text invoice / All sales order form and and set 'MultiSelect' property to YES.

Then, On clicked method of the button, write the code as below

void clicked()
{
    CustInvoiceTable        custInvoiceTable_loc;    
    SysOperationProgress    progressBar = new SysOperationProgress();
    Counter                 progressCount,progressTotal;
    Ledgerjournalname       ledgerjournalname;
    LedgerjournalTable      LedgerjournalTable;
    LedgerjournalTrans      LedgerjournalTrans;
    CustTable               custtable_loc;
    NumberSeq               numberSeq;
    CustParameters          custParametersExt;
    #avifiles
    super();

        for (custInvoiceTable_loc = getFirstSelection(CustInvoiceTable_ds);custInvoiceTable_loc;custInvoiceTable_loc = CustInvoiceTable_ds.getNext())
        {//this is just for total count
            if (custInvoiceTable_loc.Posted == NoYes::Yes)
            {
                progressTotal++;
            }
        }
        progressBar.setCaption(strfmt("Creating payment lines"));
        progressBar.setAnimation(#aviUpdate);
        progressBar.setTotal(progressTotal);
        progressCount = 1;

        select ledgerjournalname where ledgerjournalname.JournalName == custParametersExt.CustPaymJournalName;

        ttsBegin;
        LedgerjournalTable.JournalName = ledgerjournalname.JournalName;
        LedgerjournalTable.initFromLedgerJournalName();
        LedgerjournalTable.JournalNum  = JournalTableData::newTable(LedgerjournalTable).nextJournalId();
        LedgerjournalTable.insert();

        for (custInvoiceTable_loc = getFirstSelection(CustInvoiceTable_ds);custInvoiceTable_loc;custInvoiceTable_loc = CustInvoiceTable_ds.getNext())
        {
            progressBar.setText(strfmt("Creating payment for invoice %1,total payment created",custInvoiceTable_loc.InvoiceId,progressCount));
            progressBar.setCount(progressCount);

            if (custInvoiceTable_loc.Posted == NoYes::Yes)
            {
               custtable_loc   = CustTable::find(custInvoiceTable_loc.InvoiceAccount);
               numberSeq                               =   NumberSeq::newGetVoucherFromId((ledgerjournalname.NumberSequenceTable));
               LedgerjournalTrans.Voucher              =   numberSeq.voucher();
               LedgerjournalTrans.JournalNum           =   LedgerjournalTable.JournalNum;
               LedgerjournalTrans.AccountType          =   LedgerJournalACType::Cust;
               LedgerjournalTrans.Company              =   curext();
               LedgerjournalTrans.parmAccount(custtable_loc.AccountNum,LedgerjournalTrans.AccountType);
               LedgerjournalTrans.initFromCustTable(custtable_loc);
               LedgerjournalTrans.TransDate            =   systemDateGet();
               LedgerjournalTrans.Invoice              =   custInvoiceTable_loc.InvoiceId; //Marked Invoice can also be selected if required for settlement
               LedgerjournalTrans.ExchRate             =   Currency::exchRate(LedgerjournalTrans.CurrencyCode);

               LedgerjournalTrans.Txt                  =   strFmt('Payment for Invoice %1',LedgerjournalTrans.Invoice);
    
               LedgerjournalTrans.OffsetAccountType    =   LedgerJournalACType::Bank;//Select as required;
               LedgerJournalTrans.parmOffsetAccount(custParametersExt.BankAccountID,LedgerjournalTrans.OffsetAccountType);

               LedgerjournalTrans.DefaultDimension         =   custtable_loc.DefaultDimension;
               LedgerjournalTrans.OffsetDefaultDimension   =   custtable_loc.DefaultDimension;
               LedgerjournalTrans.TransactionType          =   LedgerTransType::Payment;
               LedgerjournalTrans.InstallmentNum   = installmentNum;
               LedgerjournalTrans.PaymMode         = custPaymMode;
   
               LedgerjournalTrans.AmountCurCredit  =   custInvoiceTable_loc.InvoiceAmount()
    
               LedgerjournalTrans.insert();
            }

            progressCount++;
        }
        ttscommit;

    CustInvoiceTable_ds.reread();
}

That's it!!

3 comments:

  1. Good articles, Have you heard of LFDS (Le_Meridian Funding Service, Email: lfdsloans@outlook.com --WhatsApp Contact:+1-9893943740--lfdsloans@lemeridianfds.com) is as USA/UK funding service they grant me loan of $95,000.00 to launch my business and I have been paying them annually for two years now and I still have 2 years left although I enjoy working with them because they are genuine Loan lender who can give you any kind of loan.

    ReplyDelete
  2. The Outbooks Proposal Tool's "Client Payment" feature streamlines the payment process for accounting firms, enhancing both efficiency and client satisfaction.

    ReplyDelete