project QadFinancials > class BOpenItemAdjustment > method OIAdjCommitValidateThree

Description

submethod fo OIAdjCommit : This method will handle all validations related to the business relation


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BOpenItemAdjustment.OIAdjCommit


program code (program8/bopenitemadjustment.p)

    
    /* ====================================== */
    /* Exception handling - processing block  */
    /* ====================================== */
    assign oiReturnStatus      = -98
           viLocalReturnStatus = 0.
    
    VALIDATIONTHREEBLOCK : DO :
        
        /* First just find 'some' OIAdj - as we can than compare it against the others */
        find first tOIAdj no-lock no-error. /* No need to check the availablity as this is done before */
        
        
        find first btOIAdj where
                   btOIAdj.tiCompanyId <> tOIAdj.tiCompanyId
                   no-lock no-error.
        if available btOIAdj
        then assign vlFoundNotCurrCy = true.
    
        find first btOIAdj where
                   btOIAdj.tlCompIsCompens = false
                   no-lock no-error.
        if available btOIAdj
        then assign vlAllCompIsCompens = false
                    vcEntityCode       = btOIAdj.tcCompanyCode.
    
        find first btOIAdj where
                   btOIAdj.tlBusinessRelationIsCompens = false
                   no-lock no-error.
        if available btOIAdj
        then assign vlAllBusinessRelationIsCompens  = false
                    vcBusinessRelationCode          = btOIAdj.tcBusinessRelationCode.
    
        <Q-17 run CompanyPropertyByIDAllInfo (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            output dataset tqCompanyPropertyByIDAllInfo) in BCompanyProperty >
        find first tqCompanyPropertyByIDAllInfo where
                   tqCompanyPropertyByIDAllInfo.tiCompany_ID = viCompanyId
                   no-lock no-error.
        if not available tqCompanyPropertyByIDAllInfo
        then do:
            assign viLocalReturnStatus = -1
                   vcMsgOIAdj          = trim(#T-86'Current Entity not found':255(571769131)T-86#). 
            <M-51 run SetMessage
               (input  vcMsgOIAdj (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-890470':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            leave VALIDATIONTHREEBLOCK.
        end.
    
        /* When the flag for AP/AR Compensation is set to false at entity level, then no AP/AR compensation */
        /* is allowed in open item adjustment. If there exists AP/AR compensation in open item adjustment,  */
        /* then give error “                                                                                */
        if not tqCompanyPropertyByIDAllInfo.tlCompanyPropertyIsCompens and
           can-find(first btOIAdj where
                          btOIAdj.tcInvoiceOrigin <> tOIAdj.tcInvoiceOrigin)
        then do:
            assign viLocalReturnStatus = -1
                   vcMsgOIAdj          = trim(substitute(#T-78'Entity (&1) does not allow AP/AR compensation.':255(926568003)T-78#,tqCompanyPropertyByIDAllInfo.tcCompanyPropertyCode)).
            <M-26 run SetMessage
               (input  vcMsgOIAdj (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-120359':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            leave VALIDATIONTHREEBLOCK.
        end.
    
        /* When the flag for AP/AR Compensation is set to true at entity level and      */ 
        /* there exists AP/AR compensation in open item adjustment,                     */
        /* If the AP/AR compensation is used in several entities (cross company)        */
        /* then the involved entities must all have AP/AR compensation flag set to true */
        /* at entity level otherwise error                                              */
        if tqCompanyPropertyByIDAllInfo.tlCompanyPropertyIsCompens           and
           can-find(first btOIAdj where
                          btOIAdj.tcInvoiceOrigin <> tOIAdj.tcInvoiceOrigin) and
           vlFoundNotCurrCy and not vlAllCompIsCompens
        then do:
            assign viLocalReturnStatus = -1
                   vcMsgOIAdj          = trim(substitute(#T-89'Entity (&1) does not allow AP/AR compensation.':255(926568003)T-89#,vcEntityCode)).
            <M-54 run SetMessage
               (input  vcMsgOIAdj (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-181317':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            leave VALIDATIONTHREEBLOCK.
        end.
    
        /* When the flag for AP/AR Compensation is set to true at entity level and      */ 
        /* there exists AP/AR compensation in open item adjustment,                     */
        /* For any of two selected items from same entity or from different entites where both        */
        /* have the flag AP/AR Compensation allowed on true, but one or both of the involved business */
        /* relations have the flag AP/AR compensation allowed on false then give error “              */
        if tqCompanyPropertyByIDAllInfo.tlCompanyPropertyIsCompens           and
           can-find(first btOIAdj where
                          btOIAdj.tcInvoiceOrigin <> tOIAdj.tcInvoiceOrigin) and
           not vlAllBusinessRelationIsCompens
       then do:
            assign viLocalReturnStatus = -1
                   vcMsgOIAdj          = trim(substitute(#T-38'Customer/Supplier compensation for business relation (&1) must be true because it is true at entity level.':255(128854382)T-38#,vcBusinessRelationCode)).
            <M-35 run SetMessage
               (input  vcMsgOIAdj (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-769829':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            leave VALIDATIONTHREEBLOCK.
        end.
    
        /* if current entity has netting restriction related or none, other entities are involved  */
        /* and in one entity the netting restriction is single and in another entity */
        /* it is another value and bus rel are different then give error         */
        if (tqCompanyPropertyByIDAllInfo.tcCompanyPropertyOINetRestr = {&COMPANYPROPERTYOINETRESTR-RELATED} or
            tqCompanyPropertyByIDAllInfo.tcCompanyPropertyOINetRestr = {&COMPANYPROPERTYOINETRESTR-NONE})   and
           vlFoundNotCurrCy                                                                                 and
           can-find (first btOIAdj where
                           btOIAdj.tcCompOINetRest          = {&COMPANYPROPERTYOINETRESTR-SINGLE})         and
           can-find (first btOIAdj where
                           btOIAdj.tcCompOINetRest          <> {&COMPANYPROPERTYOINETRESTR-SINGLE})
        then do:
            find first btOIAdj where
                       btOIAdj.tcCompOINetRest = {&COMPANYPROPERTYOINETRESTR-SINGLE}
                       no-lock no-error.
            if available btOIAdj
            then assign vcBusinessRelationCode = btOIAdj.tcBusinessRelationCode
                        vcEntityCode           = btOIAdj.tcCompanyCode.
            find first btOIAdj where
                       btOIAdj.tcCompOINetRest <> {&COMPANYPROPERTYOINETRESTR-SINGLE}
                       no-lock no-error.
            if available btOIAdj
            then do:
                if btOIAdj.tcBusinessRelationCode   <> vcBusinessRelationCode
                then do:
                    assign viLocalReturnStatus = -1
                           vcMsgOIAdj          = trim(substitute(#T-72'The open item netting restriction setting of entity (&1) only allows you to net open items of a single business relation':255(779928765)T-72#,vcEntityCode)).
                    <M-97 run SetMessage
                       (input  vcMsgOIAdj (icMessage), 
                        input  '':U (icArguments), 
                        input  '':U (icFieldName), 
                        input  '':U (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  '':U (icRowid), 
                        input  'QadFin-515463':U (icFcMsgNumber), 
                        input  '' (icFcExplanation), 
                        input  '' (icFcIdentification), 
                        input  '' (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
                    leave VALIDATIONTHREEBLOCK.
                end.
            end.
        end.
    
        /* if current entity has netting restriction related or none, other entities are involved  */
        /* in one entity the netting restriction is related and in another entity it is none */
        /* bus rel are different but group names are empty or different then give error      */
        if (tqCompanyPropertyByIDAllInfo.tcCompanyPropertyOINetRestr = {&COMPANYPROPERTYOINETRESTR-RELATED} or
            tqCompanyPropertyByIDAllInfo.tcCompanyPropertyOINetRestr = {&COMPANYPROPERTYOINETRESTR-NONE})   and
           vlFoundNotCurrCy                                                                                 and
           can-find (first btOIAdj where
                           btOIAdj.tcCompOINetRest          = {&COMPANYPROPERTYOINETRESTR-RELATED})         and
           can-find (first btOIAdj where
                           btOIAdj.tcCompOINetRest          = {&COMPANYPROPERTYOINETRESTR-NONE})
        then do:
            find first btOIAdj where
                       btOIAdj.tcCompOINetRest = {&COMPANYPROPERTYOINETRESTR-RELATED}
                       no-lock no-error.
            if available btOIAdj
            then assign vcBusinessRelationCode = btOIAdj.tcBusinessRelationCode
                        vcCorporateGroupCode   = btOIAdj.tcCorporateGroupCode
                        vcEntityCode           = btOIAdj.tcCompanyCode.
            find first btOIAdj where
                       btOIAdj.tcCompOINetRest = {&COMPANYPROPERTYOINETRESTR-NONE}
                       no-lock no-error.
            if available btOIAdj
            then do:
                if btOIAdj.tcBusinessRelationCode   <> vcBusinessRelationCode   and
                  (btOIAdj.tcCorporateGroupCode     <> vcCorporateGroupCode     or
                   btOIAdj.tcCorporateGroupCode     = "":U                      or
                   vcCorporateGroupCode             = "":U)
                then do:
                    assign viLocalReturnStatus = -1
                           vcMsgOIAdj          = trim(substitute(#T-24'The open item netting restriction setting of entity (&1) only allows you to net open items of business relations that belong to the same corporate group.':255(813375631)T-24#,vcEntityCode)).
                    <M-9 run SetMessage
                       (input  vcMsgOIAdj (icMessage), 
                        input  '':U (icArguments), 
                        input  '':U (icFieldName), 
                        input  '':U (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  '':U (icRowid), 
                        input  'QadFin-185224':U (icFcMsgNumber), 
                        input  '' (icFcExplanation), 
                        input  '' (icFcIdentification), 
                        input  '' (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
                    leave VALIDATIONTHREEBLOCK.
                end.
            end.
        end.
    
        /* if current entity has netting restriction related, no other entities are involded */
        /* bus rel are different but group names are empty or different then give error      */
        if tqCompanyPropertyByIDAllInfo.tcCompanyPropertyOINetRestr = {&COMPANYPROPERTYOINETRESTR-RELATED}  and 
           not vlFoundNotCurrCy                                                                             and
           can-find (first btOIAdj where
                           btOIAdj.tcBusinessRelationCode   <> tOIAdj.tcBusinessRelationCode                and
                          (btOIAdj.tcCorporateGroupCode     <> tOIAdj.tcCorporateGroupCode                  or
                           btOIAdj.tcCorporateGroupCode     = "":U                                          or
                           tOIAdj.tcCorporateGroupCode      = "":U))
        then do:
            assign viLocalReturnStatus = -1
                   vcMsgOIAdj          = trim(substitute(#T-94'The open item netting restriction setting of entity (&1) only allows you to net open items of business relations that belong to the same corporate group.':255(813375631)T-94#,tOIAdj.tcCompanyCode)).
            <M-96 run SetMessage
               (input  vcMsgOIAdj (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-295483':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            leave VALIDATIONTHREEBLOCK.
        end.
    
        /* if current entity has netting restriction single and business relations are different then give error */
        if tqCompanyPropertyByIDAllInfo.tcCompanyPropertyOINetRestr = {&COMPANYPROPERTYOINETRESTR-SINGLE} and
           can-find (first btOIAdj where
                           btOIAdj.tcBusinessRelationCode   <> tOIAdj.tcBusinessRelationCode)
        then do:
            assign viLocalReturnStatus = -1
                   vcMsgOIAdj          = trim(substitute(#T-63'The open item netting restriction setting of entity (&1) only allows you to net open items of a single business relation.':255(968932251)T-63#,tqCompanyPropertyByIDAllInfo.tcCompanyPropertyCode)).
            <M-3 run SetMessage
               (input  vcMsgOIAdj (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'QadFin-900824':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
            leave VALIDATIONTHREEBLOCK.
        end. /* end if tqCompanyPropertyByIDAllInfo.tcCompanyPropertyOINetRestr = {&COMPANYPROPERTYOINETRESTR-SINGLE} ... */ 
        
        /* =================================================================================================== */
        /* Block OIAdj for Complex WHT - Temporarely solution as for the 2012-release this is not fully tested */
        /* Block WHT open item adjustment functionality for multi currency and/or multi entity                 */
        /* We should block these 2 situations:                                                                 */
        /*    1. One of the OIAdjLines holds WHT and not all OIAdjLines have the same currency                 */
        /*    2. One of the OIAdjLines holds WHT and at least one OIAdjLine refers to a company that is not    */
        /*       the same company as the one the OIAdj is being created in                                     */
        /* =================================================================================================== */
        Find first tOIAdj where
                   tOIAdj.tdAdjustmentWHTAmountTC <> 0 and 
                   tOIAdj.tdAdjustmentWHTAmountTC <> ?
                   no-lock no-error. 
        if available tOIAdj
        then do :
            assign vcMsgOIAdj = "":U.
            find first btOIAdj where
                       rowid(btOIAdj)                <> rowid(tOIAdj) and 
                       btOIAdj.tcInvoiceCurrencyCode <> tOIAdj.tcInvoiceCurrencyCode
                       no-lock no-error.
            if available btOIAdj
            then assign vcMsgOIAdj = trim(substitute(#T-16'Open Item Adjustments on invoices including withholding taxes cannot be combined with invoices with another currency':255(355279162)T-16#)) + chr(10) + 
                                     trim(substitute(#T-8'Invoice &1 holds withholding taxes and is in currecy &2.':255(112173879)T-8#, tOIAdj.tcInvoiceNumberReference, tOIAdj.tcInvoiceCurrencyCode)) + chr(10) + 
                                     trim(substitute(#T-27'Invoice &1 is in currecy &2.':255(58559105)T-27#, btOIAdj.tcInvoiceNumberReference, btOIAdj.tcInvoiceCurrencyCode)).
            
            if vcMsgOIAdj <> "":U 
            then do :
                assign viLocalReturnStatus = -1.
                <M-68 run SetMessage
                   (input  vcMsgOIAdj (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'qadfin-97543':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BOpenItemAdjustment>
                Leave VALIDATIONTHREEBLOCK.
            end. /* if vcMsgOIAdj <> "":U  */            
        end. /* if available tOIAdj */
        
    END. /* VALIDATIONTHREEBLOCK */
    
    /* =================== */
    /* Exception handling  */
    /* =================== */
    assign oiReturnStatus = viLocalReturnStatus.