Check if Invoice Date is in current Ledger Period using X++



public boolean AS_isInvoiceInCurrentLedgerPeriod(TransDate _transDate, TransDate _oldDate)
{
    FiscalCalendarPeriod         oldPeriod;
    FiscalCalendarPeriod         newPeriod;
    FiscalCalendarRecId          fiscalCalendarRecId = CompanyInfo::fiscalCalendarRecId();
    LedgerFiscalCalendarPeriod   ledgerFiscalCalendarPeriod;

    if (!FiscalCalendars::findYearEndClosingPeriodByDate(fiscalCalendarRecId, _transDate).RecId)
    {
        // The transaction date is not in a valid period.
        return checkFailed("@GLS54501");
    }

    oldPeriod = FiscalCalendars::findPeriodByPeriodCodeDate(fiscalCalendarRecId, _oldDate);
    newPeriod = FiscalCalendars::findPeriodByPeriodCodeDate(fiscalCalendarRecId, _transDate);

    if (!newPeriod.RecId)
    {
        // The transaction date is not in a valid period.
        return checkFailed("@GLS54501");
    }

    select firstonly Status from ledgerFiscalCalendarPeriod
        where ledgerFiscalCalendarPeriod.FiscalCalendarPeriod == newPeriod.RecId
            && ledgerFiscalCalendarPeriod.Ledger == Ledger::current();

    if (ledgerFiscalCalendarPeriod.Status == FiscalPeriodStatus::Open)
    {
        if ( newPeriod.StartDate != oldPeriod.StartDate) //!isSimpleMethod           &&
        {
            return false;
        }
        return true;
    }
    else
    {
        // The period of this date is closed or stopped
        return checkFailed("@GLS54751");
    }
}

Comments

  1. Is there an equivalent in D365 for FiscalCalendars::findPeriodByPeriodCodeDate()?

    ReplyDelete

Post a Comment

Popular posts from this blog

Sales order invoice posting using X++ with custom SalesParmLine fields

Create a custom lookup with multiple data sources on form using X++

SalesTable2Line custom field update prompt on Sales order in AX 2012