project QadFinancials > class BPeriod > method ValidateComponentPrePC

Description

Submethod of ValidateComponentPre (called before the ancestor-code of ValidateComponent): this method will hold all validations related to the Periodic-costing


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPeriod.ValidateComponentPre


program code (program4/bperiod.p)

/* =============================== */
/* Exception handling - main block */
/* =============================== */
assign oiReturnStatus      = -98
       viLocalReturnStatus = 0.
MAINPCVALIDATIONBLOCK: DO :
    
    /* ================================================================================================= */
    /* Field PeriodIsPostingPCAllowed has been added after SP5 and as the Financials need to be able to  */
    /* run with MfgPro versions >= SP5, we might thus get external calls that do not provide us a value  */
    /* for this field. In these cases, we will set the value of this new field from ? to false. This is  */
    /* needed as this field is marked as mandatory in the DB and in the CB-repository and connot be ?    */          
    /* ================================================================================================= */
    for each t_sPeriod where 
             t_sPeriod.tc_Status                <> "D":U and 
             t_sPeriod.PeriodIsPostingPCAllowed  = ? :
        assign t_sPeriod.PeriodIsPostingPCAllowed = false
               t_sPeriod.tc_Status = (if t_sPeriod.tc_Status = "":U then "C" else t_sPeriod.tc_Status).
    end.  /* for each t_sPeriod where */         
    
    /* ========================================================================================================= */
    /* Skip all PC-related validations in case the Periodidc-costing module is not active for the current domain */ 
    /* In this case we only validate that the Periodic-costing-flag is off                                       */
    /* We thus assume here that all periods in the business-instance belong to companies in the current domain   */
    /* ========================================================================================================= */
    if vlPeriodicCostingModIsActive = ? 
    then do :
        <M-27 run PeriodicCostingModuleIsActive
           (input  vcDomainCode (icDomainCode), 
            output vlPeriodicCostingModIsActive (olPeriodicCostingModuleIsActive), 
            output viFcReturnSuper (oiReturnStatus)) in BPeriod>
        if viFcReturnSuper <> 0 
        then assign viLocalReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0 
        then Leave MAINPCVALIDATIONBLOCK. 
    end.  /* if vlPeriodicCostingModIsActive = ?  */
    if vlPeriodicCostingModIsActive <> true
    then do :
        Find first t_sPeriod where 
                   t_sPeriod.tc_Status                <> "D":U and 
                   t_sPeriod.PeriodIsPostingPCAllowed  = true
                   no-lock no-error.
        if available t_sPeriod
        then do :
            assign viLocalReturnStatus = -1
                   vcMessage = trim(substitute(#T-29'Period: &1 / &2; The sub-ledger for Period-costing can only be open in case the Periodic-costing is activated for the current domain.':255(733757251)T-29#, t_sPeriod.PeriodYear, t_sPeriod.PeriodPeriod)).
            <M-28 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tPeriod.PeriodYearPeriod':U (icFieldName), 
                input  t_sPeriod.PeriodYearPeriod (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sPeriod.tc_Rowid (icRowid), 
                input  'QadFin-9812':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPeriod>
        end. /* if available t_sPeriod */
        Leave MAINPCVALIDATIONBLOCK.
    end. /* if vlPeriodicCostingModIsActive <> true */
    
    /* ============================================================== */
    /* Go through all loaded periods that are new, deleted or changed */
    /* ============================================================== */
    for each t_sPeriod where 
             t_sPeriod.tc_Status <> "":U :
        
        /* =================================================================== */
        /* Find the initial loaded values in case it concerns a non-new record */
        /* =================================================================== */
        if t_sPeriod.tc_Status <> "N":U and 
           t_sPeriod.tc_Status <> "":U
        then do :
            Find t_iPeriod where 
                 t_iPeriod.tc_Rowid = t_sPeriod.tc_Rowid
                 no-lock no-error.
            if not available t_iPeriod
            then Leave MAINPCVALIDATIONBLOCK. /* Leave as in this case there is a huge problem that will be tackled in the ancestor code of ValidateComponent */
        end. /* if t_sPeriod.tc_Status <> "N":U and  */
        
        /* ============================================================================================ */
        /* When a certain period with an end-date in the past is being re-opened for PC, all other past */
        /* periods situated after the re-opened one and before today should be open for PC as well.     */
        /* ============================================================================================ */
        if t_sPeriod.PeriodIsPostingPCAllowed = true  and 
           t_sPeriod.tc_Status                = "C":U and 
           t_sPeriod.PeriodStartDate          < today and
           t_iPeriod.PeriodIsPostingPCAllowed = false
        then do :
            CHECKDBANDINSTANCEBLOCK : DO :
                /* Look in the instance */
                find first btsPeriod where 
                           btsPeriod.Company_ID                = t_sPeriod.Company_ID      and 
                           btsPeriod.PeriodStartDate           > t_sPeriod.PeriodStartDate and
                           btsPeriod.PeriodStartDate          <= today                     and
                           btsPeriod.PeriodIsPostingPCAllowed  = false                     and
                           btsPeriod.tc_Status <> "D":U
                           no-lock no-error.
                if available btsPeriod
                then do :
                    assign viLocalReturnStatus = -1
                           vcMessage           = trim(substitute(#T-42'Period: &1 / &2; The sub-ledger for Period-costing of this period cannot be opened as there is a future period that is still closed for sub-ledger Period-costing: &3 / &4.':255(489984209)T-42#, t_sPeriod.PeriodYear, t_sPeriod.PeriodPeriod, btsPeriod.PeriodYear, btsPeriod.PeriodPeriod)) .
                    <M-3 run SetMessage
                       (input  vcMessage (icMessage), 
                        input  '':U (icArguments), 
                        input  'tPeriod.PeriodYearPeriod':U (icFieldName), 
                        input  t_sPeriod.PeriodYearPeriod (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  t_sPeriod.tc_Rowid (icRowid), 
                        input  'QadFin-9784':U (icFcMsgNumber), 
                        input  '':U (icFcExplanation), 
                        input  '':U (icFcIdentification), 
                        input  '':U (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BPeriod>
                    Leave CHECKDBANDINSTANCEBLOCK.
                end. /* if available btsPeriod */
                /* Look in the db and check if a db-record in not marked for deletion */
                else do :
                    <Q-4 run PeriodByStartDatePCAllowed (all) (Read) (NoCache)
                       (input t_sPeriod.Company_ID, (CompanyId)
                        input false, (PeriodIsPostingPCAllowed)
                        input t_sPeriod.PeriodStartDate, (PeriodStartDateAfter)
                        input today, (PeriodStartDateBefore)
                        output dataset tqPeriodByStartDatePCAllowed) in BPeriod >
                    for each tqPeriodByStartDatePCAllowed where 
                             tqPeriodByStartDatePCAllowed.tiCompany_ID                = t_sPeriod.Company_ID and 
                             tqPeriodByStartDatePCAllowed.tlPeriodIsPostingPCAllowed  = false                and 
                             tqPeriodByStartDatePCAllowed.ttPeriodStartDate          <= today                and
                             tqPeriodByStartDatePCAllowed.ttPeriodStartDate          > t_sPeriod.PeriodStartDate :
                        if not can-find (btsPeriod where
                                         btsPeriod.Period_ID = tqPeriodByStartDatePCAllowed.tiPeriod_ID and 
                                         btsPeriod.tc_Status = "D":U) And
                           not can-find (btsPeriod where
                                         btsPeriod.Period_ID                = tqPeriodByStartDatePCAllowed.tiPeriod_ID and
                                         btsPeriod.PeriodIsPostingPCAllowed = true                                     and
                                         btsPeriod.tc_Status               = "C":U) 
                        then do :
                            assign viLocalReturnStatus = -1
                                   vcMessage = trim(substitute(#T-93'Period: &1 / &2; The sub-ledger for Period-costing of this period cannot be opened as there is a future period that is still closed for sub-ledger Period-costing: &3 / &4.':255(489984209)T-93#, t_sPeriod.PeriodYear, t_sPeriod.PeriodPeriod, tqPeriodByStartDatePCAllowed.tiPeriodYear, tqPeriodByStartDatePCAllowed.tiPeriodPeriod)).
                            <M-5 run SetMessage
                               (input  vcMessage (icMessage), 
                                input  '':U (icArguments), 
                                input  'tPeriod.PeriodYearPeriod':U (icFieldName), 
                                input  t_sPeriod.PeriodYearPeriod (icFieldValue), 
                                input  'E':U (icType), 
                                input  3 (iiSeverity), 
                                input  t_sPeriod.tc_Rowid (icRowid), 
                                input  'QadFin-9785':U (icFcMsgNumber), 
                                input  '':U (icFcExplanation), 
                                input  '':U (icFcIdentification), 
                                input  '':U (icFcContext), 
                                output viFcReturnSuper (oiReturnStatus)) in BPeriod>
                            Leave CHECKDBANDINSTANCEBLOCK.
                        end. /* if not can-find */
                    end. /* for each tqPeriodByStartDatePCAllowed where  */
                end. /* Not if available btsPeriod */
            END. /* CHECKDBANDINSTANCEBLOCK */
        end. /* if t_sPeriod.PeriodIsPostingPCAllowed = true  and */
                                                                                        
        /* ============================================================================= */
        /* PeriodIsPostingPCAllowed can only be changed from false to true in case:      */
        /*  - The Period-status is Locked or Opened                                      */
        /*  - Following flags in the Period are false: Inventory, AP and Sales are false */
        /*  - The GL-flag in the Period is true                                          */
        /*  - The current activity (vcActivityCode) is ModifyAccountingYear              */
        /*    (meaning the change was done from the maintenance-form in the Financials)  */
        /* A warning should be raised in case PeriodIsPostingPCAllowed is changed from   */
        /* false to true to inform the user he has to take some actions in the PC-module */
        /* ============================================================================= */
        if t_sPeriod.tc_Status                = "C":U and 
           t_sPeriod.PeriodIsPostingPCAllowed = true  and
           t_sPeriod.PeriodIsPostingPCAllowed  <> t_iPeriod.PeriodIsPostingPCAllowed
        then do :
            if (t_sPeriod.PeriodStatus <> {&PERIODSTATUS-LOCKED} and
                t_sPeriod.PeriodStatus <> {&PERIODSTATUS-OPEN})      or
               (vcActivityCode <> "":U and /* no error should be raised when this is done via an api */
                (t_sPeriod.PeriodIsPostingInvAllowed  = true or 
                 t_sPeriod.PeriodIsPostingPurchAllow  = true or 
                 t_sPeriod.PeriodIsPostingSalesAllow  = true or
                 t_sPeriod.PeriodIsPostingGLAllowed   = false))
            then do :
                assign viLocalReturnStatus = -1
                       vcMessage = trim(substitute(#T-13'Period: &1 / &2; The sub-ledger for Period-costing can only be re-opened for locked or open periods when the G/L subledger is open and all other sub-ledgers are closed.':255(710773039)T-13#, t_sPeriod.PeriodYear, t_sPeriod.PeriodPeriod)) + chr(10) + 
                                   trim(substitute(#T-14'Period Status: &1':255(227659198)T-14#, t_sPeriod.PeriodStatus)) + chr(10) + 
                                   trim(substitute(#T-15'Open for G/L: &1':255(825528423)T-15#, t_sPeriod.PeriodIsPostingGLAllowed)) + chr(10) + 
                                   trim(substitute(#T-16'Open for Purchasing: &1':255(583999904)T-16#, t_sPeriod.PeriodIsPostingPurchAllow)) + chr(10) + 
                                   trim(substitute(#T-17'Open for Sales: &1':255(606066623)T-17#, t_sPeriod.PeriodIsPostingSalesAllow)) + chr(10) + 
                                   trim(substitute(#T-18'Open for Inventory: &1':255(52836284)T-18#, t_sPeriod.PeriodIsPostingInvAllowed)).
                <M-12 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tPeriod.PeriodYearPeriod':U (icFieldName), 
                    input  t_sPeriod.PeriodYearPeriod (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sPeriod.tc_Rowid (icRowid), 
                    input  'QadFin-9787':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPeriod>
            end. /* if t_sPeriod.PeriodStatus <> {&PERIODSTATUS-LOCKED} or */
            if vcActivityCode <> "ModifyAccountingYear":U and 
               vcActivityCode <> "":U
            then do :
                assign viLocalReturnStatus = -1
                       vcMessage = trim(substitute(#T-20'Period: &1 / &2; The sub-ledger for Period-costing can only be re-opened in case it is initiated from within the Financials or via an api.':255(81243786)T-20#, t_sPeriod.PeriodYear, t_sPeriod.PeriodPeriod)) + chr(10) + 
                                   trim(substitute(#T-21'Current Activity: &1.':255(915913494)T-21#, vcActivityCode)) + chr(10) + 
                                   trim(substitute(#T-22'Expected Activity: &1':255(519411996)T-22#, "ModifyAccountingYear":U)).
                <M-19 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tPeriod.PeriodYearPeriod':U (icFieldName), 
                    input  t_sPeriod.PeriodYearPeriod (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sPeriod.tc_Rowid (icRowid), 
                    input  'QadFin-9788':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPeriod>
            end. /* if vcActivityCode <> "ModifyAccountingYear":U */
            if viLocalReturnStatus >= 0
            then do :
                assign viLocalReturnStatus = +1 
                       vcMessage = trim(substitute(#T-8'You have re-opened a period (&1 / &2) for Periodic-costing; make sure to execute the Reverse-function in the Periodic-costing module.':255(957915884)T-8#, t_sPeriod.PeriodYear, t_sPeriod.PeriodPeriod)).
                <M-9 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tPeriod.PeriodYearPeriod':U (icFieldName), 
                    input  t_sPeriod.PeriodYearPeriod (icFieldValue), 
                    input  'W':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sPeriod.tc_Rowid (icRowid), 
                    input  'QadFin-9786':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPeriod>
            end. /* if viLocalReturnStatus >= 0 */
        end. /* if t_sPeriod.PeriodIsPostingPCAllowed = true  and */
        
        /* ==================================================================================== */
        /* PeriodIsPostingPCAllowed can only be changed from true to false in case the current  */
        /* activity (vcActivityCode) is ModifyAccountingYear and no transient postings exists   */
        /* on Periodic-Costing daybooks for that period and all previous periods in this entity */
        /* are closed for period costing as well                                                */
        /* not needed to test on other flags                                                    */
        /* ==================================================================================== */
        if t_sPeriod.PeriodIsPostingPCAllowed = false and 
           t_sPeriod.tc_Status                = "C":U and 
           t_iPeriod.PeriodIsPostingPCAllowed = true and 
           vcActivityCode                     = "ModifyAccountingYear":U
        then do :
            <Q-52 assign vlFcQueryRecordsAvailable = PostingByJrnlTypebyLayerType (NoCache)
               (input t_sPeriod.Company_ID, (CompanyId)
                input t_sPeriod.PeriodPeriod, (Period)
                input t_sPeriod.PeriodYear, (PeriodYear)
                input {&JOURNALTYPE-PERIODICCOSTING}, (JournalType)
                input {&LAYERTYPECODE-TRANSIENT}, (LayerTypeCode)) in BPosting>
            if vlFcQueryRecordsAvailable = true or vlFcQueryRecordsAvailable = ?
            then do:
                assign viLocalReturnStatus = -1
                       vcMessage = trim(substitute(#T-50'Period: &1 / &2; The sub-ledger for Period-costing can only be closed when no transient postings on Periodic-Costing daybooks exists for this period.':255(871844860)T-50#, t_sPeriod.PeriodYear, t_sPeriod.PeriodPeriod)) + chr(10) + 
                                   trim(substitute(#T-31'Current Activity: &1.':255(915913494)T-31#, vcActivityCode)) + chr(10) + 
                                   trim(substitute(#T-68'Prohibited Activity: &1':255(117806159)T-68#, "ModifyAccountingYear":U)).
                <M-67 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tPeriod.PeriodYearPeriod':U (icFieldName), 
                    input  t_sPeriod.PeriodYearPeriod (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sPeriod.tc_Rowid (icRowid), 
                    input  'qadfin-483418':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPeriod>
            end. /* if vlFcQueryRecordsAvailable = true or .. */

            /* all previous periods in this entity must be closed for period costing */
            CHECKDBANDINSTANCEBLOCK : DO :
                /* Look in the instance */
                find first btsPeriod where 
                           btsPeriod.Company_ID               = t_sPeriod.Company_ID      and 
                           btsPeriod.PeriodEndDate            < t_sPeriod.PeriodStartDate and
                           btsPeriod.PeriodIsPostingPCAllowed = true                      and
                           btsPeriod.tc_Status <> "D":U
                           no-lock no-error.
                if available btsPeriod
                then do :
                    assign viLocalReturnStatus = -1
                           vcMessage           = trim(substitute(#T-6'Period: &1 / &2; The sub-ledger for Period-costing of this period cannot be closed as there is a previous period that is still open for sub-ledger Period-costing: &3 / &4.':255(575033259)T-6#, t_sPeriod.PeriodYear, t_sPeriod.PeriodPeriod, btsPeriod.PeriodYear, btsPeriod.PeriodPeriod)).
                    <M-71 run SetMessage
                       (input  vcMessage (icMessage), 
                        input  '':U (icArguments), 
                        input  'tPeriod.PeriodYearPeriod':U (icFieldName), 
                        input  t_sPeriod.PeriodYearPeriod (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  t_sPeriod.tc_Rowid (icRowid), 
                        input  'qadfin-695471':U (icFcMsgNumber), 
                        input  '':U (icFcExplanation), 
                        input  '':U (icFcIdentification), 
                        input  '':U (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BPeriod>
                    Leave CHECKDBANDINSTANCEBLOCK.
                end. /* if available btsPeriod */
                /* Look in the db and check if a db-record in not marked for deletion */
                else do :
                    <Q-91 run PeriodByEndDatePCAllowed (all) (Read) (NoCache)
                       (input t_sPeriod.Company_ID, (CompanyId)
                        input true, (PeriodIsPostingPCAllowed)
                        input t_sPeriod.PeriodStartDate, (PeriodEndDateBefore)
                        output dataset tqPeriodByEndDatePCAllowed) in BPeriod>
                    for each tqPeriodByEndDatePCAllowed where 
                             tqPeriodByEndDatePCAllowed.tiCompany_ID                = t_sPeriod.Company_ID and 
                             tqPeriodByEndDatePCAllowed.tlPeriodIsPostingPCAllowed  = true                 and 
                             tqPeriodByEndDatePCAllowed.ttPeriodEndDate             < t_sPeriod.PeriodStartDate :
                        if not can-find (btsPeriod where
                                         btsPeriod.Period_ID = tqPeriodByEndDatePCAllowed.tiPeriod_ID and 
                                         btsPeriod.tc_Status = "D":U) And
                           not can-find (btsPeriod where
                                         btsPeriod.Period_ID                = tqPeriodByEndDatePCAllowed.tiPeriod_ID and
                                         btsPeriod.PeriodIsPostingPCAllowed = true                                   and
                                         btsPeriod.tc_Status               = "C":U) 
                        then do :
                            assign viLocalReturnStatus = -1
                                   vcMessage = trim(substitute(#T-81'Period: &1 / &2; The sub-ledger for Period-costing of this period cannot be closed as there is a previous period that is still open for sub-ledger Period-costing: &3 / &4.':255(575033259)T-81#, t_sPeriod.PeriodYear, t_sPeriod.PeriodPeriod, tqPeriodByEndDatePCAllowed.tiPeriodYear, tqPeriodByEndDatePCAllowed.tiPeriodPeriod)).
                            <M-62 run SetMessage
                               (input  vcMessage (icMessage), 
                                input  '':U (icArguments), 
                                input  'tPeriod.PeriodYearPeriod':U (icFieldName), 
                                input  t_sPeriod.PeriodYearPeriod (icFieldValue), 
                                input  'E':U (icType), 
                                input  3 (iiSeverity), 
                                input  t_sPeriod.tc_Rowid (icRowid), 
                                input  'qadfin-795794':U (icFcMsgNumber), 
                                input  '':U (icFcExplanation), 
                                input  '':U (icFcIdentification), 
                                input  '':U (icFcContext), 
                                output viFcReturnSuper (oiReturnStatus)) in BPeriod>
                            Leave CHECKDBANDINSTANCEBLOCK.
                        end. /* if not can-find */
                    end. /* for each tqPeriodByStartDatePCAllowed where  */
                end. /* Not if available btsPeriod */
            END. /* CHECKDBANDINSTANCEBLOCK */
        end. /* if t_sPeriod.PeriodIsPostingPCAllowed = false and  */

    end. /* for each t_sPeriod where t_sPeriod.tc_Status <> "":U */
    
    
/* =============================== */
/* Exception handling - main block */
/* =============================== */
END. /* MAINPCVALIDATIONBLOCK */
assign oiReturnStatus = viLocalReturnStatus.