project QadFinancials > class BPeriod > method GetDefaultPeriodDate

Description

Accounting Year, Accounting Period, Posting Date Defaults based on the context the method is called in:

- system will default all three parameters

- system will default posting date based on selected year/period
(YearIn <> 0, YearIn <> ?, PeriodIn <> ?)

- system will default accounting year/period based on selected posting date
(DateIn <> ?)

All the searches respect also the only partially supplied parameters
- ex. YearIn=?, PeriodIn<>? or YearIn<>?, PeriodIn=?

Modularity Parameters to be filled: yes,true,no,false,?
In case the system should return the closed accounting period for specified area, "no" or "false" is necessary to pass as a value in this modularity parameter.

Please Note: Zero Accounting Period is also valid (for Year Opening)


Parameters


iiYearIninputintegerYear of the period as input parameter.
iiPeriodIninputintegerPeriod of the period as input parameter.
itDateIninputdateDate as input parameter.
ilOpenForPurchaseinputlogicalOpenForPurchase.
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
ilOpenForSalesinputlogicalOpenForSales.
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
ilOpenForInventoryinputlogicalOpenForInventory.
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
oiYearoutputintegerYear
oiPeriodoutputintegerPeriod.
otPostingDateoutputdatePosting Date.
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankEntry.InitialValues
method BCInvoice.CreateMFPosting
method BCInvoice.DefaultValuesPostingDate
method BCInvoice.DefaultValuesPostingYear
method BCInvoice.InitialValues
method BCInvoice.ReplaceCInvoicePosting
method BDInvoice.DefaultValuesPostingDate
method BDInvoice.DefaultValuesPostingYear
method BDInvoice.GetDeductionApprRejDate
method BDInvoice.InitialValues
method BJournalEntry.DefaultValuesPostingForUI
method BJournalEntry.UpdateJournalDateInPostingInstance
method BPeriod.ApiGetDefaultPeriodDate


program code (program3/bperiod.p)

/* ------------------------------------------------------------------------ *
 * 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 <> ? */