project QadFinancials > class BConsolid > method ValidateComponentPostSub1

Description

ValidateComponent got too big, so it needed a submethod.


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BConsolid.ValidateComponentPost


program code (program4/bconsolid.p)

/* ====================================================================================== */
/* ValidateComponent got too big (Progress 30K limit), so it needed a submethod.          */
/* Same segment, so records that were available in ValidateComponent are still available. */
/* ====================================================================================== */

assign viLocalReturnStatus = oiReturnStatus
       oiReturnStatus      = -98
       viSourceFromPeriod = 0
       viSourceFromYear = 0.

/* ================================= */
/* Check if to period >= From Period */
/* ================================= */
if t_sConsolid.tiFromPeriodYear > t_sConsolid.tiToPeriodYear or
   (t_sConsolid.tiFromPeriodYear   = t_sConsolid.tiToPeriodYear and
    t_sConsolid.tiFromPeriodPeriod > t_sConsolid.tiToPeriodPeriod)
then do:
    assign vcMessage           = trim(substitute(#T-39'The starting GL period (&1/&2) cannot be later than the ending GL period (&3/&4).':200(1318)T-39#, trim(string(t_sConsolid.tiFromPeriodYear)), trim(string(t_sConsolid.tiFromPeriodPeriod)), trim(string(t_sConsolid.tiToPeriodYear)), trim(string(t_sConsolid.tiToPeriodPeriod)) ))
           viLocalReturnStatus = -1.
    <M-25 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  t_sConsolid.tc_Rowid (icRowid), 
        input  'QadFin-8922':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BConsolid>    
end.

/* ========================================================== */
/* At least one Consolidation Layer record should be selected */
/* ========================================================== */
if not can-find(first t_sConsolidLayer where
                      t_sConsolidLayer.tc_ParentRowid = t_sConsolid.tc_Rowid)
then do:
    assign vcMessage           = trim(#T-47'You must select at least one consolidation layer.':100(62386)T-47#)
           viLocalReturnStatus = -1.
    <M-32 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  t_sConsolid.tc_Rowid (icRowid), 
        input  'QadFin-8929':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BConsolid>    
end. /* if not can-find(first t_sConsolidLayer where ... */

/* =============================================== */
/* Consolidation Layer Record should not yet exist */
/* =============================================== */
for each t_sConsolidLayer where
         t_sConsolidLayer.tc_ParentRowid = t_sConsolid.tc_Rowid and
         t_sConsolidLayer.tc_Status     <> "D":U:

    <Q-36 run ConsolidLayerBySourceCyLayer (all) (Read) (NoCache)
       (input t_sConsolid.tcSourceCompanyCode, (SourceCompanyCode)
        input t_sConsolid.ConsolidSourceLayerTypCode, (SourceLayerType)
        input t_sConsolid.ConsolidTargetLayerTypCode, (TargetLayerType)
        input t_sConsolidLayer.tcLayerCode, (TargetLayerCode)
        input t_sConsolid.ConsolidCompany_ID, (CompanyId)
        output dataset tqConsolidLayerBySourceCyLayer) in BConsolid >

    if can-find(first tqConsolidLayerBySourceCyLayer where
                      tqConsolidLayerBySourceCyLayer.tcSourceCompanyCode          = t_sConsolid.tcSourceCompanyCode                                     and
                      tqConsolidLayerBySourceCyLayer.tcConsolidSourceLayerTypCode = t_sConsolid.ConsolidSourceLayerTypCode                              and
                      tqConsolidLayerBySourceCyLayer.tcConsolidTargetLayerTypCode = t_sConsolid.ConsolidTargetLayerTypCode                              and
                      tqConsolidLayerBySourceCyLayer.tcLayerCode                  = t_sConsolidLayer.tcLayerCode                                        and
                      tqConsolidLayerBySourceCyLayer.tiConsolidCompany_ID         = t_sConsolid.ConsolidCompany_ID                                      and
                      tqConsolidLayerBySourceCyLayer.tiFromPeriodYearPeriod      <= (t_sConsolid.tiFromPeriodYear * 100) + t_sConsolid.tiFromPeriodPeriod and
                      tqConsolidLayerBySourceCyLayer.tiToPeriodYearPeriod        >= (t_sConsolid.tiFromPeriodYear * 100) + t_sConsolid.tiFromPeriodPeriod and
                      tqConsolidLayerBySourceCyLayer.tcConsolidStatus            <> {&CONSOLIDSTATUS-INITIAL}) or
       can-find(first tqConsolidLayerBySourceCyLayer where
                      tqConsolidLayerBySourceCyLayer.tcSourceCompanyCode          = t_sConsolid.tcSourceCompanyCode                                     and
                      tqConsolidLayerBySourceCyLayer.tcConsolidSourceLayerTypCode = t_sConsolid.ConsolidSourceLayerTypCode                              and
                      tqConsolidLayerBySourceCyLayer.tcConsolidTargetLayerTypCode = t_sConsolid.ConsolidTargetLayerTypCode                              and
                      tqConsolidLayerBySourceCyLayer.tcLayerCode                  = t_sConsolidLayer.tcLayerCode                                        and
                      tqConsolidLayerBySourceCyLayer.tiConsolidCompany_ID         = t_sConsolid.ConsolidCompany_ID                                      and
                      tqConsolidLayerBySourceCyLayer.tiFromPeriodYearPeriod      <= (t_sConsolid.tiToPeriodYear * 100) + t_sConsolid.tiToPeriodPeriod    and
                      tqConsolidLayerBySourceCyLayer.tiToPeriodYearPeriod        >= (t_sConsolid.tiToPeriodYear * 100) + t_sConsolid.tiToPeriodPeriod    and
                      tqConsolidLayerBySourceCyLayer.tcConsolidStatus            <> {&CONSOLIDSTATUS-INITIAL})
    then do:
        assign vcMessage           = trim(#T-40'At least one GL period from this selection had already been consolidated.':200(1319)T-40#)      + chr(10) +
                                     trim(substitute(#T-50'Subsidiary Entity: &1':255(999890619)T-50#, trim(t_sConsolid.tcSourceCompanyCode) )) + chr(10) +
                                     trim(substitute(#T-51'Layer Code: &1':255(999890620)T-51#, trim(t_sConsolidLayer.tcLayerCode) ))                                       
               viLocalReturnStatus = -1.
        <M-26 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sConsolid.tc_Rowid (icRowid), 
            input  'QadFin-8923':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BConsolid>         
    end. /* can-find ... */

    /* ======================================================================================================== */
    /* In case the previous period in the target entity was not consolidated yet, and there exists transactions */
    /* in the source entity in the period (or even before), a waring or error is raised                         */
    /* ======================================================================================================== */
    if t_sConsolid.ConsolidStatus <> {&CONSOLIDSTATUS-INITIAL}
    then do:
        <Q-34 run PeriodPrevPeriodByYearPeriod (last) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            input t_sConsolid.tiFromPeriodYear, (PeriodYear)
            input t_sConsolid.tiFromPeriodPeriod, (PeriodPeriod)
            output dataset tqPeriodPrevPeriodByYearPeriod) in BPeriod >   

        find last tqPeriodPrevPeriodByYearPeriod no-lock no-error.
        if available tqPeriodPrevPeriodByYearPeriod
        then do:
            /* check if previous period is consolidated in target or not */
            if not can-find(first tqConsolidLayerBySourceCyLayer where
                                  tqConsolidLayerBySourceCyLayer.tcSourceCompanyCode          = t_sConsolid.tcSourceCompanyCode                                     and
                                  tqConsolidLayerBySourceCyLayer.tcConsolidSourceLayerTypCode = t_sConsolid.ConsolidSourceLayerTypCode                              and
                                  tqConsolidLayerBySourceCyLayer.tcConsolidTargetLayerTypCode = t_sConsolid.ConsolidTargetLayerTypCode                              and
                                  tqConsolidLayerBySourceCyLayer.tcLayerCode                  = t_sConsolidLayer.tcLayerCode                                        and
                                  tqConsolidLayerBySourceCyLayer.tiConsolidCompany_ID         = t_sConsolid.ConsolidCompany_ID                                      and
                                  tqConsolidLayerBySourceCyLayer.tiToPeriodYearPeriod         = tqPeriodPrevPeriodByYearPeriod.tiPeriodYearPeriod)
            then do:
                
                /*load coa Cross Reference Periods between source and Consolidation Domain*/
                 <Q-65 run ConsolidPeriodXrefByPeriod (all) (Read) (NoCache)
                    (input t_sConsolid.SourceCompany_ID, (CompanyId)
                     input t_sConsolid.ConsolidCompany_ID, (ConsolidCompanyID)
                     input t_SConsolid.tcConsolidCompanyCode, (ConsolidCompanyCode)
                     input ?, (SourceYear)
                     input ?, (SourcePeriod)
                     input t_sConsolid.tiFromPeriodYear, (TargetYear)
                     input t_sConsolid.tiFromPeriodPeriod, (TargetPeriod)
                     output dataset tqConsolidPeriodXrefByPeriod) in BConsolidPeriodXref>
    
                /*Get the source Period and year Corresponding to Consolid "From Period" and "From Year"*/
                find first tqConsolidPeriodXrefByPeriod where
                           tqConsolidPeriodXrefByPeriod.tiConsolidPeriodYear   = t_sConsolid.tiFromPeriodYear        and
                           tqConsolidPeriodXrefByPeriod.tiConsolidperiodperiod = t_sConsolid.tiFromPeriodPeriod
                           no-lock no-error.

                if available tqConsolidPeriodXrefByPeriod
                then do:
                     assign viSourceFromPeriod = tqConsolidPeriodXrefByPeriod.tiPeriodPeriod
                            viSourceFromYear = tqConsolidPeriodXrefByPeriod.tiPeriodYear.
                 
                    /* Check if there were postings before this period in the source entity */
                    <Q-37 assign vlFcQueryRecordsAvailable = PostingHistByCyLayerBeforeYP (NoCache)
                       (input t_sConsolid.SourceCompany_ID, (CompanyId)
                        input t_sConsolidLayer.tcLayerCode, (LayerCode)
                        input (viSourceFromYear * 100) + viSourceFromPeriod, (BeforeYearPeriod)) in BPostingHist>
        
                    /* In case at least 1 transaction is found, an error (OFFICIAL layer) or warning (not OFFICIAL layer) is raised */
                    if vlFcQueryRecordsAvailable <> false
                    then do:
                        if t_sConsolid.ConsolidTargetLayerTypCode = {&CONSOLIDTARGETLAYERTYPE-OFFICIAL}
                        then do:
                            assign vcMessage       = trim(substitute(#T-41'The previous GL period (&1/&2) has not yet been consolidated.':200(1320)T-41#, trim(string(tqPeriodPrevPeriodByYearPeriod.tiPeriodYear)), trim(string(tqPeriodPrevPeriodByYearPeriod.tiPeriodPeriod)) ))
                                   viLocalReturnStatus = -1.
                            <M-27 run SetMessage
                               (input  vcMessage (icMessage), 
                                input  '':U (icArguments), 
                                input  '':U (icFieldName), 
                                input  '':U (icFieldValue), 
                                input  'E':U (icType), 
                                input  3 (iiSeverity), 
                                input  t_sConsolid.tc_Rowid (icRowid), 
                                input  'QadFin-8924':U (icFcMsgNumber), 
                                input  '' (icFcExplanation), 
                                input  '' (icFcIdentification), 
                                input  '' (icFcContext), 
                                output viFcReturnSuper (oiReturnStatus)) in BConsolid>
                        end. /* if t_sConsolid.ConsolidTargetLayerTypCode = {&CONSOLIDTARGETLAYERTYPE-OFFICIAL} */
                        else do:
                            assign vcMessage  = trim(substitute(#T-42'The previous GL period (&1/&2) has not yet been consolidated.':200(1320)T-42#, trim(string(tqPeriodPrevPeriodByYearPeriod.tiPeriodYear)), trim(string(tqPeriodPrevPeriodByYearPeriod.tiPeriodPeriod)) )).
                            if viLocalReturnStatus >= 0
                            then assign viLocalReturnStatus = 1.
                            <M-28 run SetMessage
                               (input  vcMessage (icMessage), 
                                input  '':U (icArguments), 
                                input  '':U (icFieldName), 
                                input  '':U (icFieldValue), 
                                input  'W':U (icType), 
                                input  3 (iiSeverity), 
                                input  t_sConsolid.tc_Rowid (icRowid), 
                                input  'QadFin-8925':U (icFcMsgNumber), 
                                input  '' (icFcExplanation), 
                                input  '' (icFcIdentification), 
                                input  '' (icFcContext), 
                                output viFcReturnSuper (oiReturnStatus)) in BConsolid>
                        end. /* else do: */
                    end. /* if vlFcQueryRecordsAvailable <> false */
                end. /* if available tqPeriodPrevPeriodByYearPeriod */
            end. /* if not can-find(first tqConsolidLayerBySourceCyLayer where */
        end. /* if available tqPeriodPrevPeriodByYearPeriod */
    end. /* if t_sConsolid.ConsolidStatus <> {&CONSOLIDSTATUS-INITIAL} */
end. /* for each t_sConsolidLayer where */

/* ================================================================== */
/* Check if the combination of Target and Source Layer types is valid */
/* ================================================================== */
if (t_sConsolid.ConsolidSourceLayerTypCode = {&CONSOLIDSOURCELAYERTYPE-MANAGEMENT} and
    t_sConsolid.ConsolidTargetLayerTypCode = {&CONSOLIDTARGETLAYERTYPE-OFFICIAL}       ) or
   (t_sConsolid.ConsolidSourceLayerTypCode = {&CONSOLIDSOURCELAYERTYPE-OFFICIAL}   and
    t_sConsolid.ConsolidTargetLayerTypCode = {&CONSOLIDTARGETLAYERTYPE-MANAGEMENT}     )
then do:
    assign vcMessage           = trim(#T-43'The layer type combination is invalid.':200(1321)T-43#) + chr(10) +
                                 trim(substitute(#T-44'Source layer type code: &1. Target layer type code: &2.':200(1322)T-44#, trim(t_sConsolid.ConsolidSourceLayerTypCode), trim(t_sConsolid.ConsolidTargetLayerTypCode) ))
           viLocalReturnStatus = -1.
    <M-29 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  'tConsolid.ConsolidSourceLayerTypCode':U (icFieldName), 
        input  t_sConsolid.ConsolidSourceLayerTypCode (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  t_sConsolid.tc_Rowid (icRowid), 
        input  'QadFin-8926':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BConsolid>
end. /* invalid layer type combination */

/* =============================== */
/* Get Consolidation Cycle Company */
/* =============================== */
<Q-35 run ConsolidCycleByCompanies (all) (Read) (NoCache)
   (input viCompanyId, (CompanyId)
    input t_sConsolid.tcSourceCompanyCode, (SourceCompanyCode)
    input 0, (SourceCompanyID)
    output dataset tqConsolidCycleByCompanies) in BConsolidCycle >
find tqConsolidCycleByCompanies where
     tqConsolidCycleByCompanies.tiCompany_ID        = t_sConsolid.ConsolidCompany_ID and
     tqConsolidCycleByCompanies.tcSourceCompanyCode = t_sConsolid.tcSourceCompanyCode
     no-lock no-error.
if not available tqConsolidCycleByCompanies
then do:    
    assign vcMessage           = trim(substitute(#T-45'The selected source entity (&1) is not defined in the consolidation cycle.':200(1323)T-45#, trim(t_sConsolid.tcSourceCompanyCode) ))
           viLocalReturnStatus = -1.
    <M-30 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  'tConsolid.tcSourceCompanyCode':U (icFieldName), 
        input  t_sConsolid.tcSourceCompanyCode (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  t_sConsolid.tc_Rowid (icRowid), 
        input  'QadFin-8927':U (icFcMsgNumber), 
        input  '' (icFcExplanation), 
        input  '' (icFcIdentification), 
        input  '' (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BConsolid>    
end. /* if not available tqConsolidCycleByCompanies */
else do:
    /* ====================================================================== */
    /* Check if there are no more QPostingLine records for the source company */
    /* ====================================================================== */
    <Q-38 assign vlFcQueryRecordsAvailable = QPostingLineByCompanyID (NoCache)  (input tqConsolidCycleByCompanies.tiSourceCompany_ID, (CompanyId)) in BQPosting >
    if vlFcQueryRecordsAvailable <> false
    then do:
        assign vcMessage           = trim(substitute(#T-48'The selected source entity (&1) still has unprocessed transactions in the history daemon.':200(65549)T-48#, trim(t_sConsolid.tcSourceCompanyCode) ))
               viLocalReturnStatus = -1.
        <M-49 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tConsolid.tcSourceCompanyCode':U (icFieldName), 
            input  t_sConsolid.tcSourceCompanyCode (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sConsolid.tc_Rowid (icRowid), 
            input  'QadFin-8931':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BConsolid>    
    end. /* if vlFcQueryRecordsAvailable <> false */

    /* ========================================== */
    /* Check if journal is defined for this layer */
    /* ========================================== */
    if (t_sConsolid.ConsolidTargetLayerTypCode = {&CONSOLIDTARGETLAYERTYPE-OFFICIAL} and
        (tqConsolidCycleByCompanies.tcOfficialJournalCode = '':U or
         tqConsolidCycleByCompanies.tcOfficialJournalCode = ?)                        ) or
        (t_sConsolid.ConsolidTargetLayerTypCode = {&CONSOLIDTARGETLAYERTYPE-MANAGEMENT} and
        (tqConsolidCycleByCompanies.tcManagementJournalCode = '':U or
         tqConsolidCycleByCompanies.tcManagementJournalCode = ?)                        ) or
        (t_sConsolid.ConsolidTargetLayerTypCode = {&CONSOLIDTARGETLAYERTYPE-TRANSIENT} and
        (tqConsolidCycleByCompanies.tcTransientJournalCode = '':U or
         tqConsolidCycleByCompanies.tcTransientJournalCode = ?)                        )
    then do:
        assign vcMessage           = trim(#T-46'No daybook code for this layer type was defined in the consolidation cycle.':200(1324)T-46#)
               viLocalReturnStatus = -1.
        <M-31 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sConsolid.tc_Rowid (icRowid), 
            input  'QadFin-8928':U (icFcMsgNumber), 
            input  '' (icFcExplanation), 
            input  '' (icFcIdentification), 
            input  '' (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BConsolid>    
    end. /*  if (t_sConsolid.ConsolidTargetLayerTypCode = {&CONSOLIDTARGETLAYERTYPE-OFFICIAL} and */
end. /* else do */

assign oiReturnStatus = viLocalReturnStatus.