project QadFinancials > class BCInvoice > method AdditionalUpdatesAllWorkObject

Description

This submethod of AdditionalUpdatesAll holds all program-code regarding the actions for the workobject (when you select Supplier Invoice Approval on system level, you get an extra field on invoice screen nl role, if you fill that, then a mail will be send to that person for the approve activity of the invoice)


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.AdditionalUpdatesAll


program code (program8/bcinvoice.p)

    
    /* ========================= */
    /* Set default return status */
    /* ========================= */
    assign oiReturnStatus = -98.
    
    /* ========================================================================================= */
    /* Reset the 2 instance-dep class-data-items that are used for sending mails on CI-approvals */
    /* They are both assigned further on in this method and used in method PostSave              */
    /* Assign local data-item that indicates access to BWorkObject                               */
    /* ========================================================================================= */
    assign vcRoleNameList       = '':U
           vcInstructionList    = '':U
           vlBWorkObjectStarted = false.
    
    /* ==================================================================== */
    /* Get variable that determines where BCInvoice was created.            */
    /* This variable will be set in session.                                */
    /* If CInvoiceRoleIsMandatory = false --> not mandatory                 */
    /* ==================================================================== */
    <I-1 {bFcOpenInstance
            &CLASS           = "Session"}>
    <M-2 run GetLogicalValue
       (input  'CInvoiceRoleIsMandatory':U (icName), 
        output vlRoleIsMandatory (olValue), 
        output viFcReturnSuper (oiReturnStatus)) in Session>
    if vlRoleIsMandatory <> true
    then do:
        assign oiReturnStatus = 0.
        return.
    end. /* if vlRoleIsMandatory = false */
    
    /* ================================================================ */
    /* Test if method should be run (only when company-property is set) */
    /* ================================================================ */
    <Q-4 run SystemPropertyByAll (all) (Read) (NoCache)  (output dataset tqSystemPropertyByAll) in BSystemProperty >

    if not can-find (first tqSystemPropertyByAll where 
                           tqSystemPropertyByAll.tlSysPropertyIsSpecCIApprove = true)
    then do:
        assign oiReturnStatus = 0.
        return.
    end. /* if not can-find */
    
    /* ================================================================================== */
    /* Start a block: errors in this block should be reflected in viWorkBlockReturnStatus */
    /* Go through all unapproved Invoices, CreditNotes and the corrections on it          */
    /* ================================================================================== */
    WORKBLOCKRETURNSTATUS: DO: 
        
        for each tCInvoice where
                 tCInvoice.CInvoiceIsInvoiceApproved <> true    and
                 tCInvoice.CInvoiceIsERS             <> true    and   
                 (tCInvoice.tc_Status    = 'N':U or
                  tCInvoice.tc_Status    = 'C':U)               and
                 (tCInvoice.CInvoiceType = {&INVOICETYPE-INVOICE}            or
                  tCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTE}         or
                  tCInvoice.CInvoiceType = {&INVOICETYPE-INVOICECORRECTION}  or
                  tCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}):    
            
            /* ================================================================ */
            /* State the WorkObject that was already linked to this CI (if any) */
            /* ================================================================ */
            assign viWorkObjectID = 0.
            if tCInvoice.tc_Status = 'C':U
            then do:
                find t_iCInvoice where
                     t_iCInvoice.tc_Rowid = tCInvoice.tc_Rowid
                     no-lock no-error.
                if available t_iCInvoice   
                then do:
                    if t_iCInvoice.Role_ID = tCInvoice.Role_ID
                    then next. /* next in case the the role is still the same */

                    if not vlStartLookupWorkObject
                    then do:
                        <Q-22 run LookupWorkObject  (Start) in BWorkObject >
                        assign vlStartLookupWorkObject = true.
                    end.
                    <Q-6 run LookupWorkObject (all) (Read) (NoCache)
                       (input viCompanyId, (CompanyId)
                        input vcFcComponentName, (BusComponentCode)
                        input tCInvoice.CInvoice_ID, (InternalObjectId)
                        output dataset tqLookupWorkObject) in BWorkObject >
                    find first tqLookupWorkObject no-lock no-error.
                    if available tqLookupWorkObject
                    then assign viWorkObjectID = tqLookupWorkObject.tiWorkObject_ID.
                end. /* if available t_iCInvoice */
            end. /* if tCInvoice.tc_Status = 'C':U */
            if viWorkObjectID            = 0 and 
               viCurrentDraftInstanceId <> ? and 
               viCurrentDraftInstanceId <> 0
            then do:
                <Q-7 run LookupWorkObject (all) (Read) (NoCache)
                   (input viCompanyId, (CompanyId)
                    input vcFcComponentName, (BusComponentCode)
                    input - viCurrentDraftInstanceId, (InternalObjectId)
                    output dataset tqLookupWorkObject) in BWorkObject >
                find first tqLookupWorkObject no-lock no-error.
                if available tqLookupWorkObject
                then assign viWorkObjectID = tqLookupWorkObject.tiWorkObject_ID.
            end. /* if viWorkObjectID = 0 and */
            
            /* ================================= */
            /* Check if the selected role exists */
            /* ================================= */
            assign vcMessage = '':U.
            if tCInvoice.tcRoleName = '':U OR
               tCInvoice.tcRoleName = ?
            then assign vcMessage = trim(#T-17'You must enter the role name.':200(1184)T-17#). 
            else do:
                <Q-8 assign vlFcQueryRecordsAvailable = RolePrim (NoCache)
                   (input 0, (RoleID)
                    input tCInvoice.tcRoleName, (RoleName)) in BRole >
                if vlFcQueryRecordsAvailable <> true
                then assign vcMessage = trim(substitute(#T-18'Role name (&1) is not defined in the system.':200(999890718)T-18#, trim(tCInvoice.tcRoleName) )).        
            end. /* Not if tCInvoice.tcRoleName = '':U */
            if vcMessage <> '':U
            then do:
                assign viWorkBlockReturnStatus = -1.
                <M-9 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tCInvoice.tcRoleName':U (icFieldName), 
                    input  tCInvoice.tcRoleName (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  tCInvoice.tc_Rowid (icRowid), 
                    input  'QADFIN-4467':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
                Leave WORKBLOCKRETURNSTATUS.
            end. /* if vcMessage <> '':U */
            
            /* ====================== */
            /* Check the company code */
            /* ====================== */
            <Q-10 run CompanyPrim (all) (Read) (NoCache)
               (input tCInvoice.Company_ID, (LookupCompanyId)
                input '':U, (CompanyCode)
                output dataset tqCompanyPrim) in BCompany >
            find tqCompanyPrim where
                 tqCompanyPrim.tiCompany_ID = tCInvoice.Company_ID
                 no-lock no-error.
            if not available tqCompanyPrim
            then do:
                assign vhFcComponent           = ?
                       viWorkBlockReturnStatus = -25.
                <M-11 run CreateCorruption
                   (input  'CInvoice':U (icTableName), 
                    input  trim(string(tCInvoice.CInvoicePostingYear)) + ' / ':U + trim(tcinvoice.tcjournalCode) + ' / ':U + trim(string(tcinvoice.cinvoicevoucher)) (icKey), 
                    input  trim(substitute(#T-19'The supplier invoice has an invalid entity ID (&1).':200(1186)T-19#, trim(string(tcinvoice.company_id)) )) (icDescription), 
                    input  ? (ilSkipMessage), 
                    output viFcReturnSuper (oiReturnStatus)) in BCorrLog>
                Leave WORKBLOCKRETURNSTATUS.
            end. /* if not available tqCompanyPrim */
            
            /* ================================================================================================= */
            /* Empty the temp-table that will be used as input for method BWorkObject.CreateOrUpdateWorkObject() */
            /* ================================================================================================= */
            empty temp-table tCInvoiceWorkObject.
            
            /* ==================================================== */
            /* Create a temp-table record with the WorkObject data  */
            /* ==================================================== */
            create tCInvoiceWorkObject.
            assign tCInvoiceWorkObject.tcActivityCode                = 'Approve':U
                   tCInvoiceWorkObject.tcExternal_ID                 = '':U
                   tCInvoiceWorkObject.tcRoleScopeBusinessField      = '':U
                   tCInvoiceWorkObject.tiIdentifier                  = 0    
                   tCInvoiceWorkObject.tiObjectFlexStatus_ID         = 0
                   tCInvoiceWorkObject.tiRoleScopeBusinessFieldValue = 0
                   tCInvoiceWorkObject.tcObjectReference             = tCInvoice.tcCInvoiceNumber
                   tCInvoiceWorkObject.tiRole_ID                     = tCInvoice.Role_ID
                   tCInvoiceWorkObject.tlIsInExternalControl         = false
                   tCInvoiceWorkObject.tlIsInInternalControl         = true
                   tCInvoiceWorkObject.tlIsReturnToSender            = true
                   tCInvoiceWorkObject.tlIsSendMail                  = false.
            assign tCInvoiceWorkObject.tcInstruction                 =                 
                       trim(substitute(#T-20'Approve supplier invoice &1/&2 &3/&4 in entity &5.':200(999890719)T-20#,
                                        trim(string(tCInvoice.CInvoicePostingYear)),
                                        trim(string(tCInvoice.CInvoicePostingPeriod)),
                                        trim(tCInvoice.tcJournalCode),
                                        trim(string(tCInvoice.CInvoiceVoucher)),
                                        trim(tqCompanyPrim.tcCompanyCode) )).
        
            /* ==================================================================== */
            /* Store the instruction and the RoleName for sending mails in PostSave */
            /* ==================================================================== */
            assign vcRoleNameList    = vcRoleNameList    + chr(4) + tCInvoice.tcRoleName
                   vcInstructionList = vcInstructionList + chr(4) + tCInvoiceWorkObject.tcInstruction.
            
            /* ============================================================== */
            /* Start&Open the WorkObject Instance in case it was not yet done */
            /* ============================================================== */
            if viBWorkObjectID = 0 or viBWorkObjectID = ?
            then do:
                <I-12 {bFcStartAndOpenInstance
                     &ADD-TO-TRANSACTION = "true"
                     &CLASS              = "BWorkObject"}>
                Assign vlBWorkObjectStarted = true.
            end. /* if viBWorkObjectID = 0 or viBWorkObjectID = ? */
            
            /* ========================================================== */
            /* Create the WorkObject based on the temp-table record       */
            /* The WorkObject will be closed after the for each tCInvoice */
            /* ========================================================== */
            <M-14 run CreateOrUpdateWorkObject
               (input  vcFcComponentName (icBusinessComponent), 
                input  tCInvoice.CInvoice_ID (iiObject_ID), 
                input  true (ilKeepPreviousData), 
                input  tCInvoiceWorkObject (tUpdWorkObject), 
                input-output viWorkObjectID (biWorkObject_ID), 
                output viFcReturnSuper (oiReturnStatus)) in BWorkObject>
            if viFcReturnSuper <> 0 
            then assign viWorkBlockReturnStatus = viFcReturnSuper.
            if viWorkBlockReturnStatus < 0
            then Leave WORKBLOCKRETURNSTATUS.
            
        end. /* for each tCInvoice where */
        
    END. /* WORKBLOCKRETURNSTATUS */
    
    if vlStartLookupWorkObject
    then do:
        <Q-23 run LookupWorkObject  (Stop) in BWorkObject >
    end.

    /* ============================= */
    /* close the workobject instance */
    /* ============================= */
    if vlBWorkObjectStarted = true
    then.   /* ========================================================================================================= */
            /* Normally we would here close BWorkObject we will not do it for performance                                */
            /* reasons as this way the Commit of the transaction does not have to re-open the instance to commit it.     */
            /* And in all other scenario's the instance of the class ill be closed by the de-activiate procedure of the  */
            /* appserver that is executed after each call to the appserver                                               */
            /* ========================================================================================================= */
    
    /* ====================================================== */
    /* State the global return based on WORKBLOCKRETURNSTATUS */
    /* ====================================================== */
    if viWorkBlockReturnStatus <> 0 
    then assign oiReturnStatus = viWorkBlockReturnStatus.
    if viWorkBlockReturnStatus < 0
    then Return.
    
    /* ========================================================================================= */
    /* Strip the 2 instance-dep class-data-items that are used for sending mails on CI-approvals */
    /* They are both assigned further on in this method and used in method PostSave              */
    /* ========================================================================================= */
    if vcRoleNameList <> '':U and 
       vcRoleNameList <> ?
    then assign vcRoleNameList = substring(vcRoleNameList, 2,-1,"CHARACTER":U).
    if vcInstructionList <> '':U and
       vcInstructionList <> ?
    then assign vcInstructionList = substring(vcInstructionList, 2,-1,"CHARACTER":U).
    
    /* ========================= */
    /* Set return status = OK    */
    /* ========================= */
    if oiReturnStatus = -98
    then assign oiReturnStatus = 0.