project QadFinancials > class BPeriod > method YearClosingCreatePeriods

Description

YearClosingCreatePeriods: This public method will be run from BYearClosing.AdditionalUpdatesCreatePeriods and will create a closing period in the year that needs to be closed and will create an opening period in the next year (when it does not yet exists)


Parameters


iiCompanyIDinputintegerCompany id
iiYearClosingAccountingYearinputintegerAccounting Year
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BYearClosing.AdditionalUpdatesCreatePeriods


program code (program6/bperiod.p)

/* ==================================================== */
/* Check if the closing period has been created already */
/* ==================================================== */
assign vlCreateClosingPeriod = true.
<Q-95 run PeriodByYearType (all) (Read) (NoCache)
   (input iiCompanyID, (CompanyId)
    input iiYearClosingAccountingYear, (PeriodYear)
    input {&PERIODTYPECODE-YEARCLOSING}, (PeriodTypeCode)
    output dataset tqPeriodByYearType) in BPeriod>
find first tqPeriodByYearType where
           tqPeriodByYearType.tiCompany_ID     = iiCompanyID                   and
           tqPeriodByYearType.tiPeriodYear     = iiYearClosingAccountingYear   and
           tqPeriodByYearType.tcPeriodTypeCode = {&PERIODTYPECODE-YEARCLOSING} and
           tqPeriodByYearType.tiPeriodPeriod   > 0
           no-lock no-error.
if available tqPeriodByYearType
then assign vlCreateClosingPeriod = false.

/* ====================== */                      
/* Add the Closing Period */
/* ====================== */

if vlCreateClosingPeriod
then do:
    /* Find the last period of the selected year */
    <Q-1 run PeriodByYearPeriod (last) (Read) (NoCache)
              (input iiCompanyID, (CompanyId)
               input iiYearClosingAccountingYear, (PeriodYear)
               input 0, (PeriodPeriod)
               input 0, (PeriodId)
               output dataset tqPeriodByYearPeriod) in BPeriod >
    find last tqPeriodByYearPeriod where
              tqPeriodByYearPeriod.tiCompany_ID = iiCompanyID and
              tqPeriodByYearPeriod.tiPeriodYear = iiYearClosingAccountingYear
              no-lock no-error.
    if not available tqPeriodByYearPeriod
    then do:
        assign vcMessage      = trim(substitute(#T-2'Cannot find a period for accounting year &1.':200(59379)t-2#, trim(string(iiYearClosingAccountingYear)) ))
               oiReturnStatus = -1.
        <M-3 run SetMessage (input  vcMessage (icMessage), 
                         input  '':U (icArguments), 
                         input  '':U (icFieldName), 
                         input  '':U (icFieldValue), 
                         input  'E':U (icType), 
                         input  3 (iiSeverity), 
                         input  '':U (icRowid), 
                         input  'QadFin-4651':U (icFcMsgNumber), 
                         input  '':U (icFcExplanation), 
                         input  '':U (icFcIdentification), 
                         input  '':U (icFcContext), 
                         output viFcReturnSuper (oiReturnStatus)) in BPeriod>
        return.                                
    end.     
    
    /* Find the last NORMAL period of the selected year (for the date) */
    <Q-14 run PeriodByYearType (last) (Read) (NoCache)
       (input iiCompanyID, (CompanyId)
        input iiYearClosingAccountingYear, (PeriodYear)
        input {&PERIODTYPECODE-NORMAL}, (PeriodTypeCode)
        output dataset tqPeriodByYearType) in BPeriod >
    find last tqPeriodByYearType where
              tqPeriodByYearType.tiCompany_ID     = iiCompanyID                 and
              tqPeriodByYearType.tiPeriodYear     = iiYearClosingAccountingYear and
              tqPeriodByYearType.tcPeriodTypeCode = {&PERIODTYPECODE-NORMAL}
              no-lock no-error.
    if not available tqPeriodByYearType
    then do:
        assign vcMessage      = trim(substitute(#T-13'Cannot find a normal accounting period for accounting year &1.':200(59380)t-13#, trim(string(iiYearClosingAccountingYear)) ))
               oiReturnStatus = -1.
        <M-12 run SetMessage (input  vcMessage (icMessage), 
                         input  '':U (icArguments), 
                         input  '':U (icFieldName), 
                         input  '':U (icFieldValue), 
                         input  'E':U (icType), 
                         input  3 (iiSeverity), 
                         input  '':U (icRowid), 
                         input  'QadFin-5976':U (icFcMsgNumber), 
                         input  '':U (icFcExplanation), 
                         input  '':U (icFcIdentification), 
                         input  '':U (icFcContext), 
                         output viFcReturnSuper (oiReturnStatus)) in BPeriod>
        return.                                
    end.     
    
    
    /* Create the period */
    <M-4 run AddDetailLine (input  'Period':U (icTable), 
                            input  '':U (icParentRowid), 
                            output viFcReturnSuper (oiReturnStatus)) in BPeriod>
    if viFcReturnSuper < 0 
    then do :
        assign oiReturnStatus = viFcReturnSuper.
        return.
    end. /* if viFcReturnSuper < 0  */                        
    
    assign tPeriod.PeriodYear                = iiYearClosingAccountingYear
           tPeriod.PeriodPeriod              = tqPeriodByYearPeriod.tiPeriodPeriod + 1
           tPeriod.PeriodYearPeriod          = (tPeriod.PeriodYear * 100) + tPeriod.PeriodPeriod
           tPeriod.PeriodStartDate           = tqPeriodByYearType.ttPeriodEndDate
           tPeriod.PeriodEndDate             = tPeriod.PeriodStartDate
           tPeriod.PeriodTypeCode            = {&PERIODTYPECODE-YEARCLOSING}
           tPeriod.PeriodStatus              = {&PERIODSTATUS-OPEN}
           tPeriod.PeriodIsPostingGLAllowed  = true
           tPeriod.PeriodIsPostingPurchAllow = false
           tPeriod.PeriodIsPostingSalesAllow = false
           tPeriod.PeriodIsPostingInvAllowed = false
           tPeriod.PeriodIsPostingOtherAllow = false
           tPeriod.PeriodIsReportChecked     = true.

end. /* if vlCreateClosingPeriod */

/* ====================== */                            
/* Add the opening period */
/* ====================== */

/* Check if period 00 exists, else return */
<Q-5 run PeriodPrim (all) (Read) (NoCache)
          (input iiCompanyID, (CompanyId)
           input 0, (PeriodId)
           input iiYearClosingAccountingYear + 1, (PeriodYear)
           input 0, (PeriodPeriod)
           output dataset tqPeriodPrim) in BPeriod >
find tqPeriodPrim where
     tqPeriodPrim.tiCompany_ID   = iiCompanyID                     and
     tqPeriodPrim.tiPeriodYear   = iiYearClosingAccountingYear + 1 and
     tqPeriodPrim.tiPeriodPeriod = 0                           
     no-lock no-error.
if available tqPeriodPrim
then return.           

/* Find the first period of the next year */
<Q-10 run PeriodByYearPeriod (all) (Read) (NoCache)
          (input iiCompanyID, (CompanyId)
           input iiYearClosingAccountingYear + 1, (PeriodYear)
           input 1, (PeriodPeriod)
           input 0, (PeriodId)
           output dataset tqPeriodByYearPeriod) in BPeriod >
find tqPeriodByYearPeriod where
     tqPeriodByYearPeriod.tiCompany_ID   = iiCompanyID                     and
     tqPeriodByYearPeriod.tiPeriodYear   = iiYearClosingAccountingYear + 1 and
     tqPeriodByYearPeriod.tiPeriodPeriod = 1                           
     no-lock no-error.
if not available tqPeriodByYearPeriod
then do:
    assign vcMessage      = trim(substitute(#T-8'Cannot find a GL period for GL calendar year &1.':200(20431)t-8#, trim(string(iiYearClosingAccountingYear + 1)) ))
           oiReturnStatus = -1.
    <M-7 run SetMessage (input  vcMessage (icMessage), 
                     input  '':U (icArguments), 
                     input  '':U (icFieldName), 
                     input  '':U (icFieldValue), 
                     input  'E':U (icType), 
                     input  3 (iiSeverity), 
                     input  '':U (icRowid), 
                     input  'QadFin-4652':U (icFcMsgNumber), 
                     input  '':U (icFcExplanation), 
                     input  '':U (icFcIdentification), 
                     input  '':U (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BPeriod>
    return.                  
end.

/* Create period when necessary */
<M-9 run AddDetailLine (input  'Period':U (icTable), 
                        input  '':U (icParentRowid), 
                        output viFcReturnSuper (oiReturnStatus)) in BPeriod>
if viFcReturnSuper < 0 
then do :
    assign oiReturnStatus = viFcReturnSuper.
    return.
end. /* if viFcReturnSuper < 0  */                        

assign tPeriod.PeriodYear                = iiYearClosingAccountingYear + 1
       tPeriod.PeriodPeriod              = 0
       tPeriod.PeriodYearPeriod          = tPeriod.PeriodYear * 100
       tPeriod.PeriodStartDate           = tqPeriodByYearPeriod.ttPeriodStartDate
       tPeriod.PeriodEndDate             = tPeriod.PeriodStartDate
       tPeriod.PeriodTypeCode            = {&PERIODTYPECODE-YEARCLOSING}
       tPeriod.PeriodStatus              = {&PERIODSTATUS-OPEN}
       tPeriod.PeriodIsPostingGLAllowed  = true
       tPeriod.PeriodIsPostingPurchAllow = false
       tPeriod.PeriodIsPostingSalesAllow = false
       tPeriod.PeriodIsPostingInvAllowed = false
       tPeriod.PeriodIsPostingOtherAllow = false.