project QadFinancials > class BPeriod > method SynchronizePeriod

Description

Synchronize the company's accounting periods with the input GL calendar data for the domain.


Parameters


t_sGLCalendarForPeriodinputtemp-tableTemp table of Period.
iiCompanyIdinputintegerID of the company to synchronize periods for
icDomainCodeinputcharacterDomain associated with the company
icEntityCodeinputcharacterEntity code corresponds to the company
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCompany.AdditionalUpdates
method BGLCalendar.AdditionalUpdates


program code (program1/bperiod.p)

/* Set default return */
assign oiReturnStatus = -98.

/* CompanyId must be specified */
if iiCompanyId = ? or iiCompanyId = 0
then do:
    assign vcMessage = trim(#T-10'You must specify an entity ID.':100(4242)t-10#)
           oiReturnStatus = -1.
    <M-11 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  '-157':U (icFcMsgNumber), 
                      input  '':U (icFcExplanation), 
                      input  '':U (icFcIdentification), 
                      input  '':U (icFcContext), 
                      output viFcReturnSuper (oiReturnStatus)) in BPeriod>    
    return.
end.
    

/* Domain code must be specified */
if icDomainCode = ? or icDomainCode = ""
then do:
    assign vcMessage = trim(#T-2'You must specify a domain code.':100(4240)t-2#)
           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-9541':U:U (icFcMsgNumber), 
                     input  '':U (icFcExplanation), 
                     input  '':U (icFcIdentification), 
                     input  '':U (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BPeriod>    
    return.
end.

/* Entity code must be specified */
if icEntityCode = ? or icEntityCode = ""
then do:
    assign vcMessage = trim(#T-4'You must specify an entity code.':100(4241)t-4#)
           oiReturnStatus = -1.

    <M-5 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-9542':U:U (icFcMsgNumber), 
                     input  '':U (icFcExplanation), 
                     input  '':U (icFcIdentification), 
                     input  '':U (icFcContext), 
                     output viFcReturnSuper (oiReturnStatus)) in BPeriod>
    return.
end.

/* Clear the instance */
<M-1 run ClearData (output viFcReturnSuper (oiReturnStatus)) in BPeriod>

for each t_sGLcalendarForPeriod /*where t_sGLcalendarForPeriod.tc_status <> '':U */:

    /* The Period record needs to be located using business keys hence
    *  conditions are specified in free form 
    */ 
    assign vcFreeForm = "for each Period where Period.Company_ID = ":U + string(iiCompanyId) +
                        " and Period.PeriodYear = ":U + string(t_sGLcalendarForPeriod.GLCalendarYear) +
                        " and Period.PeriodPeriod = ":U + string(t_sGLcalendarForPeriod.GLCalendarPeriod).

    <M-6 run DataLoad (input  '':U (icRowids), 
                   input  '':U (icPkeys), 
                   input  '':U (icObjectIds), 
                   input  vcFreeForm (icFreeform), 
                   input  true (ilKeepPrevious), 
                   output viFcReturnSuper (oiReturnStatus)) in BPeriod>

    if (t_sGLcalendarForPeriod.tc_Status = "N":U or t_sGLcalendarForPeriod.tc_Status = "C":U) 
    then do:
        if t_sGLcalendarForPeriod.tc_Status = "N":U
        then do:
            if viFcReturnSuper = -4
            then do:

                /* Create record */
                <M-7 run AddDetailLine (input  'Period':U (icTable), 
                        input  '':U (icParentRowid), 
                        output viFcReturnSuper (oiReturnStatus)) in BPeriod>
                if viFcReturnSuper <> 0 
                then assign oiReturnStatus = viFcReturnSuper.
                if viFcReturnSuper < 0
                then return.
                assign tPeriod.Company_Id                = iiCompanyId
                       tPeriod.PeriodIsPostingGLAllowed  = true
                       tPeriod.PeriodIsPostingPurchAllow = true
                       tPeriod.PeriodIsPostingSalesAllow = true
                       tPeriod.PeriodIsPostingInvAllowed = true.
            end.
            else do:
                assign vcMessage = trim(substitute(#T-16'A period exists for year/period: &1/&2':150(59801)t-16#,string(t_sGLcalendarForPeriod.GLCalendarYear),string(t_sGLcalendarForPeriod.GLCalendarPeriod)))
                       vcFcContext = 'tPeriod.Company_ID=' + string (iiCompanyId)
                       oiReturnStatus = -1.
                <M-17 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-5398':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  vcFcContext (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPeriod>
                return.
            end.
        end. /* t_sGLcalendarForPeriod.tc_Status = "N":U */
        else do:
            if viFcReturnSuper = -4
            then do:
                assign vcMessage = trim(substitute(#T-12'The period does not exist for year/period: &1/&2':150(59802)t-12#,string(t_sGLcalendarForPeriod.GLCalendarYear),string(t_sGLcalendarForPeriod.GLCalendarPeriod)))
                       vcFcContext = 'tPeriod.Company_ID=' + string (icEntityCode)
                       oiReturnStatus = -1.
                <M-14 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-5379':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  vcFcContext (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPeriod>
                return.
            end.
            else 
            if viFcReturnSuper < 0
            then do:
                assign oiReturnStatus = viFcReturnSuper.
                return.
            end.
            else do:
                find first tPeriod where tPeriod.Company_Id = iiCompanyId
                                   and   tPeriod.PeriodYear = t_sGLcalendarForPeriod.GLCalendarYear
                                   and   tPeriod.PeriodPeriod = t_sGLcalendarForPeriod.GLCalendarPeriod no-error.
            end.
        end. /* t_sGLcalendarForPeriod.tc_Status <> "N":U */
        
        assign tPeriod.tcDomainCode         = icDomainCode
               tPeriod.tcEntityCode         = icEntityCode
               tPeriod.PeriodYear           = t_sGLcalendarForPeriod.GLCalendarYear
               tPeriod.PeriodPeriod         = t_sGLcalendarForPeriod.GLCalendarPeriod
               tPeriod.PeriodYearPeriod     = t_sGLcalendarForPeriod.GLCalendarYear * 100 +
                                              t_sGLcalendarForPeriod.GLCalendarPeriod
               tPeriod.PeriodStartDate      = t_sGLcalendarForPeriod.GLCalendarStartDate
               tPeriod.PeriodEndDate        = t_sGLcalendarForPeriod.GLCalendarEndDate
               tPeriod.PeriodTypeCode       = t_sGLCalendarForPeriod.GLCalendarTypeCode
               tPeriod.tc_status            = t_sGLCalendarForPeriod.tc_status.
               
    end. /* (t_sGLcalendarForPeriod.tc_Status = "N":U or t_sGLcalendarForPeriod.tc_Status = "C":U)  */
    
    else if t_sGLcalendarForPeriod.tc_Status = "D":U
    then do:

        /* Cannot use cascade delete.  Set tc_status to "D" so the record
        *  be deleted.
        */
        if vifcReturnSuper = -4
        then do:
            assign vcMessage = trim(substitute(#T-13'The period does not exist for year/period: &1/&2':150(59802)t-13#,string(t_sGLcalendarForPeriod.GLCalendarYear),string(t_sGLcalendarForPeriod.GLCalendarPeriod)))
                   vcFcContext = 'tPeriod.Company_ID=' + string (icEntityCode)
                   oiReturnStatus = -1.
            <M-15 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-5380':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  vcFcContext (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPeriod>
            return.
        end.

        for first tPeriod where tPeriod.Company_Id = iiCompanyId
                            and tPeriod.PeriodYear = t_sGLcalendarForPeriod.GLCalendarYear
                            and tPeriod.PeriodPeriod = t_sGLcalendarForPeriod.GLCalendarPeriod:

            assign tPeriod.tc_Status = t_sGLcalendarForPeriod.tc_Status.
        end.
    end. /* t_sGLcalendarForPeriod.tc_Status = "D":U */
    
end. /* for each t_sGLcalendarForPeriod */

/*Sort the table in ASC*/
for each tPeriod where 
         tPeriod.tc_Status = "N":U use-index i_parent :
    assign tPeriod.tc_Rowid = '-' + string(int(substring(tPeriod.tc_Rowid,2,length(tPeriod.tc_Rowid,"CHARACTER":U),"CHARACTER":U)),'9999').
end.


/* Validate the class temp-tables */
<M-8 run ValidateBC (output viFcReturnSuper (oiReturnStatus)) in BPeriod>

if viFcReturnSuper <> 0 
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.

/* Additional updates */
<M-9 run AdditionalUpdates (output viFcReturnSuper (oiReturnStatus)) in BPeriod>

if viFcReturnSuper <> 0 
then assign oiReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then return.

if oiReturnStatus = -98 then assign oiReturnStatus = 0.