project QadFinancials > class BExpenseNote > method ValidateComponent

Description

Write here all tests on database update (new / modify / delete) that cannot be coded with a validation mask.
The type of update can be found in tc_status (N/C/D).
If you find incorrect data, you must write an entry in tFcMessages (using SetMessage) and set the return status of this method to either +1 or -1.
Return status +1 = data will still be accepted.
Return status -1 = data will not be accepted.
This method is run from SetPublicTables, before transferring the received data into the class temp-tables.


Parameters


oiReturnStatusoutputinteger


Internal usage


unused


program code (program/bexpensenote.p)

<M-11 run PreValidateComponent  (output viPreValidateStatus (oiReturnStatus)) in BExpenseNote>

<ANCESTOR-CODE>

assign oiReturnStatus = if (oiReturnStatus  > 0 and 
                            viPreValidateStatus = 0) or 
                            oiReturnStatus  < 0
                        then oiReturnStatus
                        else viPreValidateStatus.

/*as I use tc_Status on UI side as an indicator of what row can be deleted 
I have to first realy delete those created & deleted records from t_o otherwise 
I get an CB error -4 at Save*/
for each t_oExpNoteCInvoice where
         t_oExpNoteCInvoice.tc_Status = "D":U or
         t_oExpNoteCInvoice.tc_Status = "":U:

    if not can-find(first t_iExpNoteCInvoice where
                          t_iExpNoteCInvoice.tc_rowid = t_oExpNoteCInvoice.tc_rowid)
    then delete t_oExpnoteCInvoice.
end.

for each t_sExpNote where t_sExpNote.tc_Status = "D":U:

    if t_sExpNote.tcEmployeeCode <> ? and
       t_sExpNote.tcEmployeeCode <> "":U and
       t_sExpNote.tcEmployeeCode <> "?":U
    then do:
        /* User has to be linked directly to employee */
        if vcActivityCode = {&EXPNOTEACTIVITY-DELETEOWN}
        then do:
            <Q-41 assign vlFcQueryRecordsAvailable = EmployeeLinkedToCreditorByUser (NoCache)
               (input viCompanyId, (CompanyId)
                input viUsrId, (Usr_ID)
                input false, (EmployeeIsExternal)
                input true, (EmployeeIsActiveExpNote)
                input ?, (EmployeeIsActive)
                input t_sExpNote.tcEmployeeCode, (EmployeeCode)) in BEmployee >
            if not vlFcQueryRecordsAvailable = true
            then do:                
                <M-42 run SetMessage
                   (input  #T-38'This user ($1) cannot work with expense notes of employee $2.':100(13813)T-38# (icMessage), 
                    input  vcUserName + chr(2) + t_sExpNote.tcEmployeeCode (icArguments), 
                    input  'viUsrId':U (icFieldName), 
                    input  string(viUsrId) (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sExpNote.tc_Rowid (icRowid), 
                    input  'QADFIN-3068':U (icFcMsgNumber), 
                    input  #T-40'When own activities are used, the user should be linked to an employee.':100(13814)T-40# (icFcExplanation), 
                    input  'BExpenseNote.ValidateComponent':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BExpenseNote>
                assign oiReturnStatus = -1.
            end.
        end.
    end.
end.

for each t_sExpNote where t_sExpNote.tc_Status <> "D":U:
    if t_sExpNote.tcEmployeeCode <> ? and
       t_sExpNote.tcEmployeeCode <> "":U and
       t_sExpNote.tcEmployeeCode <> "?":U
    then do:
        <Q-1 assign vlFcQueryRecordsAvailable = EmployeeLinkedToCreditorByUser (NoCache)
           (input viCompanyId, (CompanyId)
            input ?, (Usr_ID)
            input false, (EmployeeIsExternal)
            input true, (EmployeeIsActiveExpNote)
            input ?, (EmployeeIsActive)
            input t_sExpNote.tcEmployeeCode, (EmployeeCode)) in BEmployee >
        if vlFcQueryRecordsAvailable = false
        then do:
            assign vcMessage = #T-25'The employee must be an internal employee who is linked to a supplier and active for expense notes.':200(1921)t-25#.
            <M-2 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tExpNote.tcEmployeeCode':U (icFieldName), 
                input  t_sExpNote.tcEmployeeCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sExpNote.tc_Rowid (icRowid), 
                input  'QADFIN-2523':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BExpenseNote>
            assign oiReturnStatus = -1.
        end.

        /* User has to be linked directly to employee */
        if vcActivityCode = {&EXPNOTEACTIVITY-CREATEOWN} or
           vcActivityCode = {&EXPNOTEACTIVITY-MODIFYOWN} or           
           vcActivityCode = {&EXPNOTEACTIVITY-CONFIRMOWN} 
        then do:
            <Q-37 assign vlFcQueryRecordsAvailable = EmployeeLinkedToCreditorByUser (NoCache)
               (input viCompanyId, (CompanyId)
                input viUsrId, (Usr_ID)
                input false, (EmployeeIsExternal)
                input true, (EmployeeIsActiveExpNote)
                input ?, (EmployeeIsActive)
                input t_sExpNote.tcEmployeeCode, (EmployeeCode)) in BEmployee >
            if not vlFcQueryRecordsAvailable = true
            then do:                
                <M-39 run SetMessage
                   (input  #T-43'This user ($1) cannot work with expense notes of employee $2.':100(13813)T-43# (icMessage), 
                    input  vcUserName + chr(2) + t_sExpNote.tcEmployeeCode (icArguments), 
                    input  'viUsrId':U (icFieldName), 
                    input  string(viUsrId) (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sExpNote.tc_Rowid (icRowid), 
                    input  'QADFIN-3067':U (icFcMsgNumber), 
                    input  #T-44'When own activities are used, the user should be linked to an employee.':100(13814)T-44# (icFcExplanation), 
                    input  'BExpenseNote.ValidateComponent':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BExpenseNote>
                assign oiReturnStatus = -1.
            end.
       end.
    end.

    for each t_sExpNoteLine where t_sExpNoteLine.tc_Status <> "D":U and
                                  t_sExpNoteLine.ExpNote_ID = t_sExpNote.ExpNote_ID:
        if t_sExpNoteLine.ExpNoteLineUnitPrice < 0
        then do:
            assign vcMessage = #T-27'The unit price cannot be negative.':200(1923)t-27#.
            <M-5 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tExpNoteLine.ExpNoteLineUnitPrice':U (icFieldName), 
                input  t_sExpNoteLine.ExpNoteLineUnitPrice (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sExpNoteLine.tc_Rowid (icRowid), 
                input  'QADFIN-2699':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BExpenseNote>
            assign oiReturnStatus = -1.
        end.
        
        assign t_sExpNoteLine.ExpNoteLineBaseQTY = t_sExpNoteLine.ExpNoteLineQTY.

        if t_sExpNoteLine.tcProjectCode    <> "":U  and
           t_sExpNoteLine.tcProjectCode    <> ?     and
           t_sExpNoteLine.tcProjectCode    <> "?":U and
           t_sExpNoteLine.tcCostCentreCode <> "":U  and
           t_sExpNoteLine.tcCostCentreCode <> "?":U and
           t_sExpNoteLine.tcCostCentreCode <> ?
        then do:
            assign vcMessage = substitute(#T-29'You can enter either a project or a cost center (&1).':250(999890179)T-29#, t_sExpNoteLine.ExpNoteLineDate).
            <M-8 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tExpNoteLine.ExpNoteLineUnitPrice':U (icFieldName), 
                input  t_sExpNoteLine.ExpNoteLineUnitPrice (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sExpNoteLine.tc_Rowid (icRowid), 
                input  'QADFIN-2701':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BExpenseNote>
            assign oiReturnStatus = -1.
        end.

        if t_sExpNoteLine.tcProjectCode    <> "":U  and
           t_sExpNoteLine.tcProjectCode    <> ?     and
           t_sExpNoteLine.tcProjectCode    <> "?":U and
           (t_sExpNoteLine.tcBudgetWBSCode  = "":U  or
            t_sExpNoteLine.tcBudgetWBSCode  = "?":U or
            t_sExpNoteLine.tcBudgetWBSCode  = ?)
        then do:
            assign vcMessage = substitute(#T-30'You must specify a WBS topic because a project (&1) was defined.':250(1926)T-30#, t_sExpNoteLine.tcProjectCode).
            <M-9 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tExpNoteLine.tcBudgetWBSCode':U (icFieldName), 
                input  t_sExpNoteLine.tcBudgetWBSCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sExpNoteLine.tc_Rowid (icRowid), 
                input  'QADFIN-2702':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BExpenseNote>
            assign oiReturnStatus = -1.
        end.

        if t_sExpNoteLine.tcBudgetWBSCode    <> "":U  and
           t_sExpNoteLine.tcBudgetWBSCode    <> "?":U  and
           t_sExpNoteLine.tcBudgetWBSCode    <> ?  and
           (t_sExpNoteLine.tcProjectCode  = "":U  or
            t_sExpNoteLine.tcProjectCode  = "?":U or
            t_sExpNoteLine.tcProjectCode  = ?)
        then do:
            assign vcMessage = substitute(#T-31'No WBS topic is allowed because no project was specified (&1).':250(999890180)T-31#, t_sExpNoteLine.ExpNoteLineDate).
            <M-10 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tExpNoteLine.tcBudgetWBSCode':U (icFieldName), 
                input  t_sExpNoteLine.tcBudgetWBSCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sExpNoteLine.tc_Rowid (icRowid), 
                input  'QADFIN-2698':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BExpenseNote>
            assign oiReturnStatus = -1.
        end.
        
        assign vlSafIsApplicable = false.
        if (t_sExpNoteLine.tcProjectCode = "":U or 
            t_sExpNoteLine.tcProjectCode = ? or 
            t_sExpNoteLine.tcProjectCode = "?":U) and
           (t_sExpNoteLine.tcCostCentreCode = "":U or 
            t_sExpNoteLine.tcCostCentreCode = ? or 
            t_sExpNoteLine.tcCostCentreCode = "?":U)
        then do:
            if t_sExpNoteLine.tcGLCode = "":U or
               t_sExpNoteLine.tcGLCode = ?    or
               t_sExpNoteLine.tcGLCode = "?":U
            then assign vlSafIsApplicable = ?.
            else do:
                <Q-12 run GLByCode (all) (Read) (NoCache)
                   (input viCompanyId, (CompanyId)
                    input t_sExpNoteLine.tcGLCode, (GLCode)
                    output dataset tqGLByCode) in BGL >
                find first tqGLByCode no-error.
                if not available tqGLByCode
                then assign vlSafIsApplicable = ?.
                else assign vlSafIsApplicable = tqGLByCode.tlGLIsSafAccount.
            end.
        end.
        else do:
            if t_sExpNoteLine.tcProjectCode <> "":U and 
               t_sExpNoteLine.tcProjectCode <> ?    and
               t_sExpNoteLine.tcProjectCode <> "?":U
            then do:
                <Q-13 run ProjectByCode (all) (Read) (NoCache)
                   (input viCompanyId, (CompanyId)
                    input t_sExpNoteLine.tcProjectCode, (ProjectCode)
                    output dataset tqProjectByCode) in BProject >
                find first tqProjectByCode no-error.
                if not available tqProjectByCode
                then assign vlSafIsApplicable = ?.
                else assign vlSafIsApplicable = tqProjectByCode.tlProjectIsWithSaf.
            end.
            else do:
                <Q-14 run CostCentreByCode (all) (Read) (NoCache)
                   (input viCompanyId, (CompanyId)
                    input t_sExpNoteLine.tcCostCentreCode, (Code)
                    output dataset tqCostCentreByCode) in BCostCentre >
                find first tqCostCentreByCode no-error.
                if not available tqCostCentreByCode
                then assign vlSafIsApplicable = ?.
                else assign vlSafIsApplicable = tqCostCentreByCode.tlCostCentreIsWithSaf.
            end.
        end.
        if vlSafIsApplicable = false and
           t_sExpNoteLine.tcSafStructureCode <> "":U and
           t_sExpNoteLine.tcSafStructureCode <> ?    and
           t_sExpNoteLine.tcSafStructureCode <> "?":U
        then do:
            assign vcMessage = substitute(#T-32'SAF structure (&1) does not apply to GL account (&2), project (&3), and cost center (&4).':255(1928)t-32#,
                                          t_sExpNoteLine.tcSafStructureCode,
                                          t_sExpNoteLine.tcGLCode,
                                          t_sExpNoteLine.tcProjectCode,
                                          t_sExpNoteLine.tcCostCentreCode).
            <M-15 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tExpNoteLine.tcSafStructureCode':U (icFieldName), 
                input  t_sExpNoteLine.tcSafStructureCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sExpNoteLine.tc_Rowid (icRowid), 
                input  'QADFIN-2722':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BExpenseNote>
            assign oiReturnStatus = -1.
        end.
        
        if vlSafIsApplicable = true and
           (t_sExpNoteLine.tcSafStructureCode = "":U or
            t_sExpNoteLine.tcSafStructureCode = ?   or
            t_sExpNoteLine.tcSafStructureCode = "?":U)
        then do:
            assign vcMessage = substitute(#T-33'The SAF structure is missing for this combination of GL account (&1), project (&2), and cost center (&3).':255(1929)T-33#,
                                          t_sExpNoteLine.tcGLCode,
                                          t_sExpNoteLine.tcProjectCode,
                                          t_sExpNoteLine.tcCostCentreCode).
            <M-16 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tExpNoteLine.tcSafStructureCode':U (icFieldName), 
                input  t_sExpNoteLine.tcSafStructureCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sExpNoteLine.tc_Rowid (icRowid), 
                input  'QADFIN-2723':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BExpenseNote>
            assign oiReturnStatus = -1.
        end.
        
        <Q-17 run GLByCode (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            input t_sExpNoteLine.tcGLCode, (GLCode)
            output dataset tqGLByCode) in BGL >
        find first tqGLByCode no-error.
        if available tqGLByCode
        then do:
            if tqGLByCode.tlGLIsDivisionAccount = true and
               (t_sExpNoteLine.tcDivisionCode = "":U or
                t_sExpNoteLine.tcDivisionCode = ?    or
                t_sExpNoteLine.tcDivisionCode = "?":U)
            then do:
                assign vcMessage = substitute(#T-34'The sub-account is missing for this combination of GL account (&1), project (&2), and cost center (&3).':255(1930)T-34#,
                                              t_sExpNoteLine.tcGLCode,
                                              t_sExpNoteLine.tcProjectCode,
                                              t_sExpNoteLine.tcCostCentreCode).
                <M-18 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tExpNoteLine.tcGLCode':U (icFieldName), 
                    input  t_sExpNoteLine.tcGLCode (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sExpNoteLine.tc_Rowid (icRowid), 
                    input  'QADFIN-2724':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BExpenseNote>
                assign oiReturnStatus = -1.
            end.
        end.
        
        <M-36 run ValidateComponent1
           (input  0 (iiExpNoteLine_ID), 
            input  tqGLByCode.tlGLIsDivisionAccount (ilGLIsDivisionAccount), 
            output viFcReturnSuper (oiReturnStatus)) in BExpenseNote>
        assign oiReturnStatus = if (oiReturnStatus  > 0 and 
                                    viFcReturnSuper = 0) or 
                                    oiReturnStatus  < 0
                                then oiReturnStatus
                                else viFcReturnSuper.

        <M-20 run ValidateComponent2
           (input  0 (iiExpNoteLine_ID), 
            output viFcReturnSuper (oiReturnStatus)) in BExpenseNote>
        assign oiReturnStatus = if (oiReturnStatus  > 0 and 
                                    viFcReturnSuper = 0) or 
                                    oiReturnStatus  < 0
                                then oiReturnStatus
                                else viFcReturnSuper.

    end. /* for each t_sExpNoteLine */
end. /* for each t_sExpNote */
if not vlIsCalledFromAPIMethod
then do:
    <M-45 run StopExternalInstances  (output viFcReturnSuper (oiReturnStatus)) in BExpenseNote>
end.