Tuesday, 18 April 2017

Due Date calculation using x++ code in Ax 2012 R3

Due Date Calculation
Customers
//Added by Rajendra - Due date calculation on 18-04-2017
public TransDate HM_DueDate()
{
    ProjInvoiceJour   ProjInvoiceJour;
    str s;
   
    select ProjInvoiceJour where ProjInvoiceJour.ProjInvoiceId == custTrans.Invoice;
    if(ProjInvoiceJour.RecId)
    {
        s = strFmt('%1',ProjInvoiceJour.InvoiceDate + PaymTerm::find(custTable::find(custTrans.AccountNum).PaymTermId).NumOfDays);
    }
    else
    {
        if(custTrans.DocumentDate)
        {
            s = strFmt('%1',custTrans.DocumentDate + PaymTerm::find(custTable::find(custTrans.AccountNum).PaymTermId).NumOfDays);
        }
        else
        {
            s = strFmt('%1',datenull());
        }
    }
    return str2Date(s,213);
}


In General Journal due date calculation

ledgerJournalTrans.Payment      = termsofPayment;
if(ledgerJournalTrans.Payment)
{
   ledgerJournalTrans.Due = ledgerJournalEngine.getDueDateBaseDate(ledgerJournalTrans);
   ledgerJournalTrans.Due = PaymCalendarSourceLedgerJournalTrans::getUpdatedDueDate(ledgerJournalTrans,this.paymDayId(ledgerJournalTrans));
}

public PaymDayId paymDayId(LedgerJournalTrans _ledgerJournalTrans)
{
    PaymDayId   paymDayId;
    CompanyId   companyId;
    LedgerJournalEngine ledgerJournalEngine = new ledgerJournalEngine();
    ;

    if (xDataArea::exist(_ledgerJournalTrans.Company))
    {
        companyId =_ledgerJournalTrans.Company;
    }
    else
    {
        companyId = curext();
    }

    changecompany(companyId)
    {
        switch(_ledgerJournalTrans.AccountType)
        {
            case LedgerJournalACType::Cust :
                paymDayId = ledgerJournalEngine.findCustTable(_ledgerJournalTrans).PaymDayId;
                break;

            case LedgerJournalACType::Vend :
                paymDayId = _ledgerJournalTrans.findVendTable().PaymDayId;
                break;

            default :
                paymDayId = '';
        }
    }
    return paymDayId;

}

No comments:

Post a Comment