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");
}
}
Is there an equivalent in D365 for FiscalCalendars::findPeriodByPeriodCodeDate()?
ReplyDelete