web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How x++ settle or mark 1 invoice in 1 payment journal with 2 lines ?

(2) ShareShare
ReportReport
Posted on by 309

Hi guys,

I need to create customer payment journal in X which will settle customer invoices. My question is can we settle or mark 1 invoice in two different payment journal line ?

So the issue is in my payment journal creation, since I have 2 different payment mode, lets say 1 Cash 1 Giro, so I inserted in Payment journal (Ledgerjournaltrans) two line for each. But when settling the invoice which is same (1 invoice), after succeeded to mark 1 invoice, at the 2nd line I'm hit this error : 

This transaction has been marked for settlement by Customer Payment Tst-000000407 in company xxx.

I assumed this error happened because it is found out that I already mark the invoice in the 1st row. Lets say the invoice is 1,000 and the payment is 200 Cash and 800 Giro, I want these two payment settle it.

Is this possible ? may I know how the code looks like ?

To settle the invoice now, I'm using this code : 

void  AutosettlePayment(TempTable  _tmp, LedgerJournalTrans  _paymLedgerJournalTrans)
    {
        custvendopentransmanager manager;
        CustTransOpen   CustTransOpen;
        CustTrans  CustTransExt;
        ExchangeRateHelper  exchangeRateHelper;
        AmountCur  totalSettlement;
        CompanyInfo                         companyInfo;

        select firstOnly AccountNum, RefRecId, AmountCur from CustTransopen
                where CustTransOpen.AccountNum == _tmp.CustAccount
        join Invoice, RecId, AccountNum from CustTransExt
                where CustTransExt.Invoice == _tmp.InvoicetobeMarked
                && CustTransExt.RecId == CustTransopen.RefRecId
                && CustTransExt.AccountNum == CustTransOpen.AccountNum;

        if(CustTransopen && CustTransOpen.AmountCur >= _tmp.PaymentAmount)
        {
            manager = custvendopentransmanager::construct(ledgerJournalTrans);
            manager.updateTransMarked(CustTransOpen,true);

            select firstonly RecId from companyInfo
            where companyInfo.DataArea == ledgerJournalTrans.Company;
            exchangeRateHelpe = ExchangeRateHelper::newCurrency(Ledger::primaryLedger(companyInfo.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.AmountCurCredit = _tmp.PaymentAmount <= abs(totalSettlement) ? _tmp.PaymentAmount : 0;
            ledgerJournalTrans.SettleVoucher = SettlementType::SelectedTransact;
            ledgerJournalTrans.MarkedInvoice = _tmp.InvoicetobeMarked;
            ledgerJournalTrans.doupdate();
            ttsCommit;
        }
               
    }

Jut to informed, as in those code, I have a temptable contain the 2 payment, something like this: 

CUSTACCOUNT INVOICETOBEMARKED CUSTPAYMMODE INVOICEAMOUNT PAYMENTAMOUNT
BB5 I00000289 GIRO 1000 800
BB5 I00000289 CASH 1000 200

As mentioned, these 2 records are the one inserted in Payment Journal Lines (LedgerJournalTrans) with at each line inserted I will call this AutoSettlePayment method to mark the invoice. It is throw that error while "ledgerJournalTrans.doUpdate()" for the 2nd time, which mean while processing the 2nd line of Journal lines (the 2nd payment mode)

Thanks,

I have the same question (0)
  • Axel Cage Profile Picture
    309 on at

    Hi, may I know what is this code doing exactly ?

    manager = custvendopentransmanager::construct(ledgerJournalTrans);
    manager.updateTransMarked(CustTransOpen,true);

    I'm sorry, I'm just a citizen developer, so my knowledge about this coding is very limited. Gonna need some guidance.

    I only suspect whether this line actually mark CustTransOpen with the correct amount (which is smaller than the total invoice amount) and so when this method called again at the 2nd time (the 2nd payment line) and querying the top query : 

    select firstOnly AccountNum, RefRecId, AmountCur from CustTransopen
    where CustTransOpen.AccountNum == _tmp.CustAccount
    join Invoice, RecId, AccountNum from CustTransExt
    where CustTransExt.Invoice == _tmp.InvoicetobeMarked
    && CustTransExt.RecId == CustTransopen.RefRecId
    && CustTransExt.AccountNum == CustTransOpen.AccountNum;

    This query still giving the total invoice amount of 1000 when it should giving 1000 minus the 1st line amount (800) which is already marked before.

    Thanks,

  • André Arnaud de Calavon Profile Picture
    301,020 Super User 2025 Season 2 on at

    Hi Axel,

    For each CustTrans record (customer transaction), if not settled yet, there is at least one CustTransOpen record. The settlement will mark the open transaction. It is not possible to have two payments referring to one single CustTransOpen record at a time. You can split the CustTransOpen records first to create a line per payment method with the correct amount. Then you can mark one CustTransOpen record with the cash payment and the other with the Giro payment journal.

  • Axel Cage Profile Picture
    309 on at

    Hi Andre,

    Is there a function to split the record ?

    Thanks,

  • Axel Cage Profile Picture
    309 on at

    Btw, 

    If I tried to create manual Payment, it is possible ->

    The invoice :

    pastedimage1680052335542v4.png

    Payment journal (here I'm using the button "Settle transaction"

    pastedimage1680052304098v3.png

    The mark on each of the lines is pointing to the same invoice only the amount to settle is according to the partial amount we wanted  : 

    pastedimage1680052551321v5.png

    pastedimage1680052730796v6.png

    And if check CustTransOpen, it is still 1 line : 

    pastedimage1680052892325v7.png

    Thanks,

  • Alex VN Profile Picture
    1,994 on at

    Hi,

    I think may be this you already settle the 2 line with same payment journal line, hence you get this error.

    Please check if you provide the correct ledgerJournalTrans for 2 payment lines and not one. You can understand the below code to mark ledgerJournalTrans (payment) with CustTransOpen (open invoice line).

    manager = custvendopentransmanager::construct(ledgerJournalTrans);

    manager.updateTransMarked(CustTransOpen,true);

  • Suggested answer
    BillurSamdancioglu Profile Picture
    19,703 Most Valuable Professional on at

    You can not settle two payment lines with 1 invoice.

  • André Arnaud de Calavon Profile Picture
    301,020 Super User 2025 Season 2 on at

    Hi Axel,

    It has been many years ago when I looked at coding in this area. I can't remember the details what is available or how to do this.

  • Community member Profile Picture
    5 on at
    Is this resolved ? 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 646 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans