Auto settle from custTransOpen when create journal payment lines via x++

example code :

public static void autoSettlementJournalFromPAYDetails(JournalId    _journalNum)
{
    CustVendOpenTransManager manager;
    CustTrans                custTrans;
    CustTransOpen            custTransOpen;
    LedgerJournalTrans       ledgerJournalTrans;
    AxLedgerJournalTable     axLedgerJournalTable;
    AxLedgerJournalTrans     axLedgerJournalTrans;
    ExchangeRateHelper       exchangeRateHelper;
    AmountCur                totalSettleAmount;
    AmountCur                amountCurDebit,amountCurCredit;
    HRSPayJournalDetails     hrsPayJournalDetails;
    HRSPayJournalTable       hrsPayJournalTable;
    
    int                      Row;


    AxLedgerJournalTable = AxLedgerJournalTable::newLedgerJournalTable(LedgerJournalTable::find(_journalNum));
    ttsBegin;
    //details journal lines from Pay Journal Details
    while select hrsPayJournalTable
    join hrsPayJournalDetails
    where
        hrsPayJournalTable.HRSPayJournalId == hrsPayJournalDetails.HRSPayJournalId
    &&  HRSPayJournalTable.JournalNum      == _journalNum
    {
        CustTrans    = CustTrans::findFromInvoice(hrsPayJournalDetails.ReferenceNumber,HRSPayJournalDetails.AccountNum);
        CustTransOpen  = CustTransOpen::findRefId(CustTrans.RecId);

        if(CustTransOpen)
        {

           //Create Trans ...
            axLedgerJournalTrans = new axLedgerJournalTrans();
            axLedgerJournalTrans.parmJournalNum(AxLedgerJournalTable.ledgerJournalTable().JournalNum);

            axLedgerJournalTrans.parmTransDate(today());
            axLedgerJournalTrans.parmDue(today());
            axLedgerJournalTrans.parmAccountType(LedgerJournalACType::Cust);
            axLedgerJournalTrans.parmLedgerDimension(DimensionStorage::getDynamicAccount(hrsPayJournalDetails.AccountNum, LedgerJournalACType::Cust));
            axLedgerJournalTrans.parmAmountCurCredit(hrsPayJournalDetails.Credit);
            axLedgerJournalTrans.parmAmountCurDebit(hrsPayJournalDetails.Debit);
            axLedgerJournalTrans.save();

            manager = CustVendOpenTransManager::construct(axLedgerJournalTrans.ledgerJournalTrans());
            manager.updateTransMarked(custTransOpen,true);
            if(hrsPayJournalDetails.Debit)
            {
                manager.updateSettleAmount(custTransOpen,hrsPayJournalDetails.Debit);
            }
            else
            {
                manager.updateSettleAmount(custTransOpen,hrsPayJournalDetails.Credit);
            }

            //update after settle
            ledgerJournalTrans = axLedgerJournalTrans.ledgerJournalTrans();
            ledgerJournalTrans.selectForUpdate(true);
            ledgerJournalTrans.SettleVoucher =  SettlementType::SelectedTransact;
            ledgerJournalTrans.update();
            Row++;
        }

    }
    ttsCommit;
    
    info(strFmt("Total Lines settled : %1",Row));

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s