| iiYearIn | input | integer | Year of the period as input parameter. |
| iiPeriodIn | input | integer | Period of the period as input parameter. |
| itDateIn | input | date | Date as input parameter. |
| ilOpenForPurchase | input | logical | OpenForPurchase. Values: ----------- no - the returned period should be closed for purchase yes - the returned period should be open for purchase ? - the purchase status does not matter |
| ilOpenForSales | input | logical | OpenForSales. Values: ----------- no - the returned period should be closed for sales yes - the returned period should be open for sales ? - the sales status does not matter |
| ilOpenForInventory | input | logical | OpenForInventory. Values: ----------- no - the returned period should be closed for inventory yes - the returned period should be open for inventory ? - the inventory status does not matter |
| oiYear | output | integer | Year |
| oiPeriod | output | integer | Period. |
| otPostingDate | output | date | Posting Date. |
| oiReturnStatus | output | integer | Return status of the method. |
QadFinancials
/* ------------------------------------------------------------------------ *
* This method provides period (normally default one) *
* Period is calculated based on the entered date or based on the *
* accounting year and period *
* !!! If there is not valid period then this procedure have to return *
* empty output values (year = 0, period = 0 and postingDate = ? *
* ------------------------------------------------------------------------ */
assign oiYear = 0
oiPeriod = 0
otPostingDate = ?.
/* In case of not accounting year and(or) accounting period filled-in,
we take as a leading parameter itDateIn */
if iiYearIn = 0 or iiYearIn = ? or iiPeriodIn = ?
then assign iiYearIn = ?
iiPeriodIn = ?.
/* If the YearIn, PeriodIn and DateIn are not specified we take systemdate as DateIn,
please note 0 Accounting Period is also valid (for YearOpening) */
if (iiYearIn = 0 or iiYearIn = ?) and
iiPeriodIn = ? and
itDateIn = ?
then assign itDateIn = today.
/* First Branch : Defaulting Posting Date - based on AccYear,AccPeriod */
if iiYearIn <> 0 and iiYearIn <> ? and
iiPeriodIn <> ? and
itDateIn = ?
then do:
/* Get period */
<Q-1 run PeriodByYearPeriodNull (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input iiYearIn, (PeriodYear)
input iiPeriodIn, (PeriodPeriod)
input ?, (PeriodId)
output dataset tqPeriodByYearPeriodNull) in BPeriod >
/* Period does not exist -> there is nothing to return */
find tqPeriodByYearPeriodNull where
tqPeriodByYearPeriodNull.tiCompany_ID = viCompanyId and
tqPeriodByYearPeriodNull.tiPeriodYear = iiYearIn and
tqPeriodByYearPeriodNull.tiPeriodPeriod = iiPeriodIn
no-error.
/* Status of Period */
if available(tqPeriodByYearPeriodNull) and
tqPeriodByYearPeriodNull.tlPeriodIsPostingGLAllowed and
(ilOpenForInventory = ? or tqPeriodByYearPeriodNull.tlPeriodIsPostingInvAllowed = ilOpenForInventory) and
(ilOpenForPurchase = ? or tqPeriodByYearPeriodNull.tlPeriodIsPostingPurchAllow = ilOpenForPurchase) and
(ilOpenForSales = ? or tqPeriodByYearPeriodNull.tlPeriodIsPostingSalesAllow = ilOpenForSales)
then assign oiYear = iiYearIn
oiPeriod = iiPeriodIn
otPostingDate = if today >= tqPeriodByYearPeriodNull.ttPeriodStartDate and
today <= tqPeriodByYearPeriodNull.ttPeriodEndDate
then today
else tqPeriodByYearPeriodNull.ttPeriodEndDate.
end. /* if iiYearIn <> 0 and iiYearIn <> ? and */
/* Second Branch :Defaulting Year/Period/PostingDate based on input date */
else if itDateIn <> ?
then do:
/* Get All periods that cover itDateIn using Start/End date */
<Q-2 run PeriodByStartEndDate (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input itDateIn, (Date)
output dataset tqPeriodByStartEndDate) in BPeriod >
/* Check if the "Normal" Period is OK */
find first tqPeriodByStartEndDate where
tqPeriodByStartEndDate.tiCompany_ID = viCompanyId and
tqPeriodByStartEndDate.tcPeriodTypeCode = {&PERIODTYPECODE-NORMAL} and
tqPeriodByStartEndDate.tlPeriodIsPostingGLAllowed = true and
(ilOpenForInventory = ? or tqPeriodByStartEndDate.tlPeriodIsPostingInvAllowed = ilOpenForInventory) and
(ilOpenForPurchase = ? or tqPeriodByStartEndDate.tlPeriodIsPostingPurchAllow = ilOpenForPurchase) and
(ilOpenForSales = ? or tqPeriodByStartEndDate.tlPeriodIsPostingSalesAllow = ilOpenForSales)
no-error.
if not available tqPeriodByStartEndDate
then find first tqPeriodByStartEndDate where
tqPeriodByStartEndDate.tiCompany_ID = viCompanyId and
tqPeriodByStartEndDate.tlPeriodIsPostingGLAllowed = true and
(ilOpenForInventory = ? or tqPeriodByStartEndDate.tlPeriodIsPostingInvAllowed = ilOpenForInventory) and
(ilOpenForPurchase = ? or tqPeriodByStartEndDate.tlPeriodIsPostingPurchAllow = ilOpenForPurchase) and
(ilOpenForSales = ? or tqPeriodByStartEndDate.tlPeriodIsPostingSalesAllow = ilOpenForSales)
no-error.
if available tqPeriodByStartEndDate
then assign oiYear = tqPeriodByStartEndDate.tiPeriodYear
oiPeriod = tqPeriodByStartEndDate.tiPeriodPeriod
otPostingDate = itDateIn.
/* if system was not able to find any period for required date, try to check if there is */
/* just one opened period or take last opened before date */
else if itDateIn = today
then do:
/* Search the Period for the case there is only one open (input parameters to be applied) */
/* if the output was not assigned yet */
<Q-5 run PeriodByCompanyIsOpen (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input true, (IsPostingGLAllowed)
output dataset tqPeriodByCompanyIsOpen) in BPeriod >
/* Check if only one */
find tqPeriodByCompanyIsOpen where
tqPeriodByCompanyIsOpen.tiCompany_ID = viCompanyId and
tqPeriodByCompanyIsOpen.tlPeriodIsPostingGLAllowed = true and
(ilOpenForPurchase = ? or tqPeriodByCompanyIsOpen.tlPeriodIsPostingPurchAllow = ilOpenForPurchase) and
(ilOpenForSales = ? or tqPeriodByCompanyIsOpen.tlPeriodIsPostingSalesAllow = ilOpenForSales) and
(ilOpenForInventory = ? or tqPeriodByCompanyIsOpen.tlPeriodIsPostingInvAllowed = ilOpenForInventory)
no-error.
if not available tqPeriodByCompanyIsOpen
then find last tqPeriodByCompanyIsOpen where
tqPeriodByCompanyIsOpen.tiCompany_ID = viCompanyId and
tqPeriodByCompanyIsOpen.tlPeriodIsPostingGLAllowed = true and
tqPeriodByCompanyIsOpen.ttPeriodEndDate <= today and
(ilOpenForPurchase = ? or tqPeriodByCompanyIsOpen.tlPeriodIsPostingPurchAllow = ilOpenForPurchase) and
(ilOpenForSales = ? or tqPeriodByCompanyIsOpen.tlPeriodIsPostingSalesAllow = ilOpenForSales) and
(ilOpenForInventory = ? or tqPeriodByCompanyIsOpen.tlPeriodIsPostingInvAllowed = ilOpenForInventory)
no-error.
if available tqPeriodByCompanyIsOpen
then assign oiYear = tqPeriodByCompanyIsOpen.tiPeriodYear
oiPeriod = tqPeriodByCompanyIsOpen.tiPeriodPeriod
otPostingDate = tqPeriodByCompanyIsOpen.ttPeriodEndDate.
end. /* else */
end. /* Brach 2 : if itDateIn <> ? */