project QadFinancials > class BYearClosing > method ValidateComponentAll

Description

ValidateComponentAll


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BYearClosing.ValidateComponent


program code (program4/byearclosing.p)

/* ============================ */
/* Validate YearClosing records */
/* ============================ */

if vcNumericFormat = ? or vcNumericFormat = ""
then do:
    <I-86 {bFcOpenInstance
         &CLASS           = "Session"}>
    <M-22 run GetCharacterValue
       (input  'vcNumericFormat':U (icName), 
        output vcNumericFormat (ocValue), 
        output viFcReturnSuper (oiReturnStatus)) in Session>
    
    <I-57 {bFcOpenInstance
         &CLASS           = "Session"}>

    if vcNumericFormat = ",":U or vcNumericFormat = "european":U then assign vcNumericFormat = "EUROPEAN":U.
    else assign vcNumericFormat = "AMERICAN":U.
           
end.

/* Year Closing Records should not be updated or deleted */
for each t_sYearClosing where
         t_sYearClosing.tc_Status = 'D':U or 
         t_sYearClosing.tc_Status = 'C':U:
    assign vcMessage      = if t_sYearClosing.tc_Status = 'D':U
                            then trim(#T-17'Year-End Closing records cannot be deleted.':200(20450)T-17#)               
                            else trim(#T-18'Year-end closing records cannot be modified.':200(20469)T-18#)
           oiReturnStatus = -1.
    <M-16 run SetMessage (input  vcMessage (icMessage), 
                      input  '':U (icArguments), 
                      input  'tYearClosing.YearClosingAccountingYear':U (icFieldName), 
                      input  string(t_sYearClosing.YearClosingAccountingYear) (icFieldValue), 
                      input  'E':U (icType), 
                      input  3 (iiSeverity), 
                      input  t_sYearClosing.tc_Rowid (icRowid), 
                      input  'QadFin-4665':U (icFcMsgNumber), 
                      input  '':U (icFcExplanation), 
                      input  '':U (icFcIdentification), 
                      input  '':U (icFcContext), 
                      output viFcReturnSuper (oiReturnStatus)) in BYearClosing>         
end. /* for each t_sYearClosing where tc_status = 'D' */         

for each t_sYearClosing where
         t_sYearClosing.tc_Status = 'N':U:

    /* Validate selected Layer of the closing */
    <M-53 run ValidateComponentAllLayer  (output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
    if viFcReturnSuper <> 0 and oiReturnStatus >= 0 then assign oiReturnStatus = viFcReturnSuper.

    /* Validate, Year closing was not executed already */
    <Q-80 assign vlFcQueryRecordsAvailable = YearClosingByCyYearID (NoCache)
       (input t_sYearClosing.Company_ID, (CompanyId)
        input t_sYearClosing.YearClosingAccountingYear, (YearClosingAccountingYear)
        input ?, (YearClosingID)
        input t_sYearClosing.Layer_ID, (LayerID)) in BYearClosing>
    if vlFcQueryRecordsAvailable <> false
    then do:
        assign vcMessage      = #T-50'Year-end closing is already complete for year &1 and layer &2.':255(395010811)T-50#
               vcMessage      = substitute(vcMessage, t_sYearClosing.YearClosingAccountingYear, t_sYearClosing.tcLayerCode)
               oiReturnStatus = -1.
        <M-35 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tYearClosing.YearClosingAccountingYear':U (icFieldName), 
            input  string(t_sYearClosing.YearClosingAccountingYear) (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sYearClosing.tc_Rowid (icRowid), 
            input  'qadfin-729099':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
    end.

    
    /* All accounting periods of the selected year should have status REPORTED */    
    <Q-1 assign vlFcQueryRecordsAvailable = PeriodByCyYearTypeStatus (NoCache)  (input t_sYearClosing.Company_ID, (CompanyId) 
                                                                  input t_sYearClosing.YearClosingAccountingYear, (PeriodYear) 
                                                                  input {&PERIODTYPECODE-NORMAL}, (PeriodTypeCode) 
                                                                  input '':U, (PeriodStatus) 
                                                                  input {&PERIODSTATUS-REPORTED}, (PeriodStatusNot)) in BPeriod >

    if vlFcQueryRecordsAvailable <> false
    then do:
        /* Some periods are not reported - these could be frozen, locked or open.                                           */
        /* If this is a management layer then we should check if an official layer has been run and the periods are frozen. */
        /* A management layer can be run when periods are frozen.                                                           */
        assign vlPeriodsAreNotReported = true.
        if t_sYearClosing.tcLayerTypeCode = {&LAYERTYPECODE-MANAGEMENT}
        then do:
            <Q-51 assign vlFcQueryRecordsAvailable = PeriodByCyYearTypeStatus (NoCache)
               (input t_sYearClosing.Company_ID, (CompanyId)
                input t_sYearClosing.YearClosingAccountingYear, (PeriodYear)
                input {&PERIODTYPECODE-NORMAL}, (PeriodTypeCode)
                input {&PERIODSTATUS-FROZEN}, (PeriodStatus)
                input '':U, (PeriodStatusNot)) in BPeriod>

            if vlFcQueryRecordsAvailable <> false
            then assign vlPeriodsAreNotReported = false.

        end. /* if t_sYearClosing.tcLayerTypeCode = {&LAYERTYPECODE-MANAGEMENT} */

        if vlPeriodsAreNotReported
        then do:
            assign vcMessage      = trim(substitute(#T-9'All GL periods of the year-end closing year should have status &1.':200(20316)T-9#, trim({&PERIODSTATUS-REPORTED-TR})))
                   oiReturnStatus = -1.
            <M-2 run SetMessage (input  vcMessage (icMessage), 
                         input  '':U (icArguments), 
                         input  'tYearClosing.YearClosingAccountingYear':U (icFieldName), 
                         input  string(t_sYearClosing.YearClosingAccountingYear) (icFieldValue), 
                         input  'E':U (icType), 
                         input  3 (iiSeverity), 
                         input  t_sYearClosing.tc_Rowid (icRowid), 
                         input  'QadFin-4625':U (icFcMsgNumber), 
                         input  '':U (icFcExplanation), 
                         input  '':U (icFcIdentification), 
                         input  '':U (icFcContext), 
                         output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
        end. /* if vlPeriodsAreNotReported */

    end.  /* if vlFcQueryRecordsAvailable <> false */                                                                 
                               
    /* All accounting periods in the previous year should have status FROZEN */
    <Q-3 assign vlFcQueryRecordsAvailable = PeriodByCyYearTypeStatus (NoCache)  (input t_sYearClosing.Company_ID, (CompanyId) 
                                                                  input t_sYearClosing.YearClosingAccountingYear - 1, (PeriodYear) 
                                                                  input {&PERIODTYPECODE-NORMAL}, (PeriodTypeCode) 
                                                                  input '':U, (PeriodStatus) 
                                                                  input {&PERIODSTATUS-FROZEN}, (PeriodStatusNot)) in BPeriod >
    if vlFcQueryRecordsAvailable <> false
    then do:
        assign vcMessage      = trim(substitute(#T-10'All GL periods of the previous year should have status &1.':200(20317)T-10#, trim({&PERIODSTATUS-FROZEN-TR})))
               oiReturnStatus = -1.
        <M-4 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tYearClosing.YearClosingAccountingYear':U (icFieldName), 
            input  string(t_sYearClosing.YearClosingAccountingYear) (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sYearClosing.tc_Rowid (icRowid), 
            input  'QadFin-4626':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BYearClosing>       
    end.                                                                  
    
    /* An accounting period should exist for the next year */
    <Q-5 assign vlFcQueryRecordsAvailable = PeriodByCyYearTypeStatus (NoCache)  (input t_sYearClosing.Company_ID, (CompanyId) 
                                                                  input t_sYearClosing.YearClosingAccountingYear + 1, (PeriodYear) 
                                                                  input {&PERIODTYPECODE-NORMAL}, (PeriodTypeCode) 
                                                                  input '':U, (PeriodStatus) 
                                                                  input '':U, (PeriodStatusNot)) in BPeriod >
    if vlFcQueryRecordsAvailable = false
    then do:
        assign vcMessage      = trim(#T-11'A GL period should exist for the next year.':200(20318)T-11#)
               oiReturnStatus = -1.
        <M-6 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tYearClosing.YearClosingAccountingYear':U (icFieldName), 
            input  string(t_sYearClosing.YearClosingAccountingYear) (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sYearClosing.tc_Rowid (icRowid), 
            input  'QadFin-4627':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BYearClosing>       
    end.                                                                   
    
    /* The Year Closing can not be run when QPosting records still exist */    
    <Q-7 assign vlFcQueryRecordsAvailable = QPostingLineByCompanyID (NoCache)  (input t_sYearClosing.Company_ID, (CompanyId)) in BQPosting >
    if vlFcQueryRecordsAvailable <> false
    then do:
        assign vcMessage      = trim(#T-12'Year-end closing cannot be performed when unprocessed History daemon records exist.':200(20319)t-12#)
               oiReturnStatus = -1.
        <M-8 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tYearClosing.YearClosingAccountingYear':U (icFieldName), 
            input  string(t_sYearClosing.YearClosingAccountingYear) (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sYearClosing.tc_Rowid (icRowid), 
            input  'QadFin-4628':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BYearClosing>                       
    end.
    
    /* Check the Addtional GL Numbering toggle of the company and numbering date validation */
    assign vhFcComponent = ?.
    <M-83 run CheckAdditionalGLNumbering
       (input  ? (icCompanyCode), 
        output vlIsAddGLNbr (olIsAddGLNbr), 
        input  t_sYearClosing.Company_ID (iiCompanyID), 
        output viFcReturnSuper (oiReturnStatus)) in BCompanyProperty>
    if viFcReturnSuper < 0 or (viFcReturnSuper >= 0 and oiReturnStatus >= 0)
    then assign oiReturnStatus = viFcReturnSuper.        
        
    /* Get the year-end closing date */
    <Q-70 run PeriodByYearPeriod (last) (Read) (NoCache)
       (input t_sYearClosing.Company_ID, (CompanyId)
        input t_sYearClosing.YearClosingAccountingYear, (PeriodYear)
        input ?, (PeriodPeriod)
        input ?, (PeriodId)
        output dataset tqPeriodByYearPeriod) in BPeriod >
    
    for first tqPeriodByYearPeriod:
        vtYearClosingDate = tqPeriodByYearPeriod.ttPeriodStartDate.
    end.
    
    if vlIsAddGLNbr
    then do:
        if t_sYearClosing.YearClosingTrnAddGLNbrDate < vtYearClosingDate 
        or t_sYearClosing.YearClosingCloAddGLNbrDate < vtYearClosingDate 
        or t_sYearClosing.YearClosingReoAddGLNbrDate < vtYearClosingDate 
        then do:
            assign vcMessage      = trim(#T-684'Additional GL Numbering date cannot be earlier than year-end closing date':200(944443418)T-684#)
                   oiReturnStatus = -1.
            <M-94 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tYearClosing.YearClosingAccountingYear':U (icFieldName), 
                input  string(t_sYearClosing.YearClosingAccountingYear) (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sYearClosing.tc_Rowid (icRowid), 
                input  'qadfin-187108':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BYearClosing>      
        end.
    end.
    
    /* ============= */                   
    /* Check Balance */
    /* ============= */    
    <M-15 run ValidateComponentAllCheckBalance (output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
    if viFcReturnSuper < 0 or (viFcReturnSuper >= 0 and oiReturnStatus >= 0)
    then assign oiReturnStatus = viFcReturnSuper.
    
    /* ========= */                    
    /* Check GLs */
    /* ========= */
    <M-13 run ValidateComponentAllGL (output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
    if viFcReturnSuper < 0 or (viFcReturnSuper >= 0 and oiReturnStatus >= 0)
    then assign oiReturnStatus = viFcReturnSuper.
    
    /* ============== */                    
    /* Check Journals */
    /* ============== */   
    <M-14 run ValidateComponentAllJournal (output viFcReturnSuper (oiReturnStatus)) in BYearClosing>            
    if viFcReturnSuper < 0 or (viFcReturnSuper >= 0 and oiReturnStatus >= 0)
    then assign oiReturnStatus = viFcReturnSuper.

    /* ================================================================== */
    /* Check, if there is not any uncleared auto-balance posting created  */
    /* ================================================================== */

    
    <I-65 {bFcStartAndOpenInstance
         &CLASS                = "BClosingPostingsReport"}>
                 
         
    
    assign vhFcComponent = ?.
    <M-78 run IsGLAutoBalClear
       (input  t_sYearClosing.Company_ID (iiCompanyId), 
        input  t_sYearClosing.YearClosingAccountingYear (iiPeriodYear), 
        input  ? (iiPeriodPeriod), 
        output vlIsAutoBalClear (olIsGLAutoBalClear), 
        output tGLAutoBalClearByYearClosing (tGLAutoBalClear), 
        input  vcNumericFormat (icNumericFormat), 
        input  t_sYearClosing.tcLayerCode (icLayerCode), 
        input  '' (icLayerTypeCode), 
        output viFcReturnSuper (oiReturnStatus)) in BClosingPostingsReport>
     
    if viFcReturnSuper < 0 or (viFcReturnSuper >= 0 and oiReturnStatus >= 0)
    then assign oiReturnStatus = viFcReturnSuper.
    
    <I-97 {bFcCloseAndStopInstance
         &CLASS           = "BClosingPostingsReport"}>
    
    if not vlIsAutoBalClear
    then do:
      
        /* =========================================================================== */
        /* Query the BCompanyProperty component to get the value for the               */
        /* CompanyPropertyAutoBalYEFailAc so we can determine which message to display */
        /* =========================================================================== */

        <Q-25 run CompanyPropertyForAllData (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            output dataset tqCompanyPropertyForAllData) in BCompanyProperty>
           
        find first tqCompanyPropertyForAllData where 
                   tqCompanyPropertyForAllData.tiCompany_ID = viCompanyId no-error.
        if available tqCompanyPropertyForAllData
        then do:

            if tqCompanyPropertyForAllData.tcCompanyPropertyAutoBalYEFailAc = {&YECLOSEAUTOBALANCECHECK-ERROR} or
               (tqCompanyPropertyForAllData.tcCompanyPropertyAutoBalYEFailAc <> {&YECLOSEAUTOBALANCECHECK-WARNING} and
               tqCompanyPropertyForAllData.tcCompanyPropertyAutoBalYEFailAc <> {&YECLOSEAUTOBALANCECHECK-NOACTION})
            then do:
                assign vcMessage = #T-96'The Auto Balance account contains outstanding, system-generated debit or credit totals. You must clear these totals using manual journal entries before you execute year-end closing.':255(672693341)T-96#.
                <M-23 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sYearClosing.tc_Rowid (icRowid), 
                    input  'qadfin-258027':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
                assign oiReturnStatus = -1.
            end.
            else if tqCompanyPropertyForAllData.tcCompanyPropertyAutoBalYEFailAc = {&YECLOSEAUTOBALANCECHECK-WARNING}
            then do:
                assign vcMessage = #T-41'The Auto Balance account contains outstanding, system-generated debit or credit totals. It is recommended that you clear these totals using manual journal entries before you execute year-end closing.':255(376457147)T-41#.
                <M-49 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'W':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sYearClosing.tc_Rowid (icRowid), 
                    input  'qadfin-681327':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BYearClosing>
                if oiReturnStatus = 0
                then assign oiReturnStatus = 1.
            end.
        end. /* if available tqCompanyPropertyForAllData */
    end. /* if not vlIsAutoBalClear */
                                                       
end. /* for each t_sYearClosing where tc_status = 'N' */