project QadFinancials > class BAPMatching > method ValidateComponentPostAPMLn1


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.ValidateComponentPost


program code (program4/bapmatching.p)

/* ==================================================================================== */
    /* Note: this method is executed for every new/changed Lines of the non-deleted Headers */
    /* ==================================================================================== */
    
    /* ========================== */
    /* Set default return-status  */
    /* ========================== */
    assign oiReturnStatus = -98.
    
    /* ============================= */
    /* Check for record-availability */
    /* ============================= */
    if not available t_sAPMatchingLn or 
       not available t_sAPMatching
    then do :
        assign vcMsgAPMatching     = trim(substitute(#T-5'Internal error: no AP matching or AP matching line record is available.':252(56454)T-5#)).
               oiReturnStatus      = -1.
        <M-4 run SetMessage
           (input  vcMsgAPMatching (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-5647':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        Return.
    end. /* if not available t_sAPMatchingLn */
    
    /* ================== */
    /* Get initial values */
    /* ================== */
    if can-do("C,D":U, t_sAPMatchingLn.tc_Status)
    then do:
        find t_iAPMatchingLn where
             t_iAPMatchingLn.tc_Rowid = t_sAPMatchingLn.tc_Rowid
             no-error.
        if not available t_iAPMatchingLn
        then do:
            assign vcMsgAPMatching      = trim(substitute(#T-6'Internal Error: Initial values for APMatchingLn record with row ID &1 not found.':250(56081)T-6#,t_sAPmatchingLn.tc_Rowid))
                   oiReturnStatus       = -3.
            <M-1 run SetMessage
               (input  vcMsgAPMatching (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'S':U (icType), 
                input  1 (iiSeverity), 
                input  t_sAPMatchingLn.tc_Rowid (icRowid), 
                input  'QadFin-5235':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
            Return.
        end. /* if not available t_iAPMatchingLn */
    end. /* if can-do */
    
    /* ================================================================ */
    /* Currency of the Invoice should match the currencies of the PVOD  */
    /* If the Currencies are LC, then the exchange-rates should be 1    */
    /* If the Currencies are CC, then the CC-exchange-rates should be 1 */
    /* ================================================================ */
    if t_sAPMatching.tc_Status                  <> "D":U and 
       t_sAPMatchingLn.tc_Status                <> "D":U  and
       t_sAPMatchingLn.APMatchingLnPvodCurrency <> t_sAPMatching.tcCurrencyCode
    then do:
        assign vcMsgAPMatching     = trim(substitute(#T-7'The currency code (&2) on each matching line must be the same as the currency code on the matching header (&1).':253(56082)T-7#,tAPMatchingLn.APMatchingLnPvodCurrency,tAPMatching.tcCurrencyCode))
               viLocalReturnStatus = -1.
        <M-11 run SetMessage
           (input  vcMsgAPMatching (icMessage), 
            input  '':U (icArguments), 
            input  'tAPMatchingLn.APMatchingLnPvodCurrency':U (icFieldName), 
            input  t_sAPMatchingLn.APMatchingLnPvodCurrency (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sAPMatchingLn.tc_Rowid (icRowid), 
            input  'QadFin-5648':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    end. /* if t_sAPMatching.tc_Status <> "D":U and */
    if t_sAPMatchingLn.APMatchingLnPvodCurrency = vcCompanyLC and 
       (t_sAPMatchingLn.APMatchingLnPvodExchRate2 / t_sAPMatchingLn.APMatchingLnPvodExchRate) <> 1
    then do :
        assign vcMsgAPMatching     = trim(substitute(#T-53'Database corruption: Although the pending invoice details (&1/&2/&3) are specified in base currency, the exchange rate (&4 / &5) is not 1.':254(57030)T-53#,t_sAPMatchingLn.PvoDomain,string(t_sAPMatchingLn.PvoID),string(t_sAPMatchingLn.PvodLineID),string(t_sAPMatchingLn.APMatchingLnPvodExchRate2),string(t_sAPMatchingLn.APMatchingLnPvodExchRate)))
               viLocalReturnStatus = -1.
        <M-51 run SetMessage
           (input  vcMsgAPMatching (icMessage), 
            input  '':U (icArguments), 
            input  'tAPMatchingLn.APMatchingLnPvodCurrency':U (icFieldName), 
            input  t_sAPMatchingLn.APMatchingLnPvodCurrency (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sAPMatchingLn.tc_Rowid (icRowid), 
            input  'QadFin-5809':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    end. /* if t_sAPMatchingLn.APMatchingLnPvodCurrency = vcCompanyLC and */
    if vcCompanyCC = vcCompanyLC and 
       (t_sAPMatchingLn.APMatchingLnPvodCCRate * t_sAPMatchingLn.APMatchingLnPvodCCScale) <> 1
    then do :
        assign vcMsgAPMatching     = trim(substitute(#T-59'Database corruption: The pending invoice details (&1/&2/&3) hold a CC-exchange-rate (&4 / &5) allthough the base-currency and the statutory-currency of the current domain are the same.':254(999890912)T-59#,t_sAPMatchingLn.PvoDomain,string(t_sAPMatchingLn.PvoID),string(t_sAPMatchingLn.PvodLineID),string(t_sAPMatchingLn.APMatchingLnPvodCCRate),string(t_sAPMatchingLn.APMatchingLnPvodCCScale)))
               viLocalReturnStatus = -1.
        <M-58 run SetMessage
           (input  vcMsgAPMatching (icMessage), 
            input  '':U (icArguments), 
            input  'tAPMatchingLn.APMatchingLnPvodCCRate':U (icFieldName), 
            input  t_sAPMatchingLn.APMatchingLnPvodCCRate (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sAPMatchingLn.tc_Rowid (icRowid), 
            input  'QadFin-9376':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    end. /* if vcCompanyCC = vcCompanyLC and  */
    
    /* ======================================================== */
    /* Error for the PVO's on companies you dont have access to */
    /* ======================================================== */
    if not can-do(vcListAccessibleCompanyCodes,t_sAPMatchingLn.APMatchingLnPvodCompCode)
    then do :
        assign vcMsgAPMatching     = trim(substitute(#T-47'The entity (&1) of the matched pending invoice has been blocked. You are not permitted to match pending invoices for that entity.':250(56836)T-47#,t_sAPMatching.tcJournalCode)) + chr(10) + 
                                     trim(substitute(#T-48'Entity of the pending invoice: &1 / &2.':213(56838)T-48#,t_sAPMatchingLn.APMatchingLnPvodCompCode,string(t_sAPMatching.Company_ID))) + chr(10) + 
                                     trim(substitute(#T-50'List of accessible entities: &1':213(56840)T-50#,vcListAccessibleCompanyCodes)) + chr(10) + 
                                     trim(substitute(#T-49'Current user login: &1':213(56839)T-49#,vcUserLogin))
               viLocalReturnStatus = -1.
        <M-46 run SetMessage
           (input  vcMsgAPMatching (icMessage), 
            input  '':U (icArguments), 
            input  'tAPMatchingLn.APMatchingLnPvodCompCode':U (icFieldName), 
            input  t_sAPMatchingLn.APMatchingLnPvodCompCode (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sAPMatchingLn.tc_Rowid (icRowid), 
            input  'QadFin-5803':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    end. /* If not can-do */
    
    /* ================================================================================ */
    /* Company of the PVOD should belong to the same domain as domain of AP matching    */
    /* ================================================================================ */
    if t_sAPMatching.tc_Status                <> "D":U  and
       t_sAPMatchingLn.tc_Status              <> "D":U  and
       t_sAPMatchingLn.APMatchingLnPvodCompID <> t_sAPMatching.Company_ID
    then do:
        <Q-54 assign vlFcQueryRecordsAvailable = CompanyByDomainActive (NoCache)
           (input t_sAPMatchingLn.APMatchingLnPvodCompID, (CompanyId)
            input viDomainID, (DomainId)
            input true, (CompanyIsActive)) in BCompany >

        if vlFcQueryRecordsAvailable <> true
        then do:
            assign vcMsgAPMatching     = trim(substitute(#T-15'The company of the matched pending voucher should belong to the current domain.':250(59421)t-15#,t_sAPMatching.tcJournalCode)) + chr(10) + 
                                         trim(substitute(#T-16'Entity ID of the matching: &1.':213(56077)T-16#,string(t_sAPMatching.Company_ID))) + chr(10) + 
                                         trim(substitute(#T-56'Current domain &1 (&2).':255(59423)T-56#, vcDomainCode, viDomainID))  + chr(10) + 
                                         trim(substitute(#T-17'Entity ID of the pending invoice: &1 / &2.':213(56089)T-17#,string(t_sAPMatchingLn.APMatchingLnPvodCompID),t_sAPMatchingLn.APMatchingLnPvodCompCode))  + chr(10) + 
                                         trim(substitute(#T-57'Domain of pending voucher &1':255(59425)T-57#, t_sAPMatchingLn.PvoDomain))
                   viLocalReturnStatus = -1.
            <M-13 run SetMessage
               (input  vcMsgAPMatching (icMessage), 
                input  '':U (icArguments), 
                input  'tAPMatchingLn.APMatchingLnPvodCompCode':U (icFieldName), 
                input  t_sAPMatchingLn.APMatchingLnPvodCompCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sAPMatchingLn.tc_Rowid (icRowid), 
                input  'QadFin-5652':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        end.
    end. /* if t_sAPMatching.tc_Status                  <> "D":U and */
    
    /* ================================================================================ */
    /* Usage variances cannot exist for logistic charges                                */
    /* ================================================================================ */
    if (t_sAPMatching.tc_Status = "C":U or 
        t_sAPMatching.tc_Status = "N":U)  and
       t_sAPMatchingLn.tc_Status                  <> "D":U and 
       t_sAPMatchingLn.APMatchingLnPvodIsLgCharge  = true  and
       t_sAPMatchingLn.APMatchingLnVarUsageTC     <> 0     and 
       t_sAPMatchingLn.APMatchingLnVarUsageTC     <> ?
    then do:
        assign vcMsgAPMatching     = trim(substitute(#T-19'Pending invoice that represent logistic charges cannot have usage variances (current usage variance: &1).':250(56090)T-19#,string(t_sAPMatchingLn.APMatchingLnVarUsageTC))) 
               viLocalReturnStatus = -1.
        <M-18 run SetMessage
           (input  vcMsgAPMatching (icMessage), 
            input  '':U (icArguments), 
            input  'tAPMatchingLn.APMatchingLnVarUsageTC':U (icFieldName), 
            input  string(t_sAPMatchingLn.APMatchingLnVarUsageTC) (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  t_sAPMatchingLn.tc_Rowid (icRowid), 
            input  'QadFin-5653':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
    end. /* if (t_sAPMatching.tc_Status = "C":U or  */
    
    if t_sAPMatching.tc_Status        <> "D":U and
       t_sAPMatching.APMatchingStatus = {&APMATCHINGSTATUS-FINISHED}
    then do :
        assign viTotalMatchedInitial = 0.
        <Q-81 run APMatchingLnByStatusPvod (all) (Read) (NoCache)
           (input ?, (CompanyId)
            input t_sAPMatchingLn.PvoDomain, (PvoDomain)
            input t_sAPMatchingLn.PvoID, (PvoID)
            input t_sAPMatchingLn.PvodLineID, (PvodLineID)
            input {&APMATCHINGSTATUS-INITIAL}, (APMatchingStatus)
            input t_sAPMatchingLn.tc_Rowid, (SkipAPMatchingLnRowid)
            output dataset tqAPMatchingLnByStatusPvod) in BAPMatching>
        for each tqAPMatchingLnByStatusPvod:
            assign viTotalMatchedInitial = abs(viTotalMatchedInitial) + abs(tqAPMatchingLnByStatusPvod.tdAPMatchingLnMatchQty).
        end.
            
        find first tqAPMatchingLnByStatusPvod where
                   tqAPMatchingLnByStatusPvod.tiCInvoice_ID <> t_sAPMatching.CInvoice_ID no-lock no-error.
        if available tqAPMatchingLnByStatusPvod and
                     (((abs(t_sAPMatchingLn.APMatchingLnPvodOpenQty) - abs(viTotalMatchedInitial)) < abs(t_sAPMatchingLn.APMatchingLnMatchQty)) or
                      t_sAPMatchingLn.APMatchingLnIsPvodFinished)
        then do :
            assign vcMsgAPMatching     = trim(substitute(#T-77'This pending invoice is already selected in supplier invoice(&1/&2/&3) with registration number &4 in initial status.':255(979278477)T-77#,string(tqAPMatchingLnByStatusPvod.tiCInvoicePostingYear),string(tqAPMatchingLnByStatusPvod.tcJournalCode),string(tqAPMatchingLnByStatusPvod.tiCInvoiceVoucher),string(tqAPMatchingLnByStatusPvod.tiCInvoiceRegistrationNr)))
                   viLocalReturnStatus = -1.
                   
            <M-69 run SetMessage
               (input  vcMsgAPMatching (icMessage), 
                input  '':U (icArguments), 
                input  'tAPMatchingLn.PvodLineID':U (icFieldName), 
                input  string(t_sAPMatchingLn.PvodLineID) (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  '':U (icRowid), 
                input  'qadfin-746019':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
                
        end. /* if available tqAPMatchingLnByStatusPvod */
    end. /* if t_sAPMatching.tc_Status         <> "D":U and ...*/
    

    /* ============================================================================== */
    /* Set return-status = OK                                                         */
    /* ============================================================================== */
    assign oiReturnStatus = viLocalReturnStatus.