project QadFinancials > class BAPMatching > method GetLogChargesPVOFromHeaderInfo


Parameters


icAPMatchingTcRowidinputcharacter
icCurrencyCodeinputcharacter
iiCInvoiceVoucherinputinteger
idCInvoiceExchangeRateinputdecimal
idCInvoiceRateScaleinputdecimal
ilCallGTMinputlogical
tPendingVoucherAPMinput-outputtemp-table
tPendingVoucherTaxAPMinput-outputtemp-table
tPendingVoucherWHTAPMinput-outputtemp-table
tPendingVoucherHeaderinputtemp-table
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program7/bapmatching.p)

/* ================== */
/* Exception handling */
/* Start Outer block  */
/* ================== */
assign oiReturnStatus      = -98
       viLocalReturnStatus = 0.
OUTERBLOCK: DO :
   
    /* ====================================== */
    /* Check header record and its company    */
    /* ====================================== */
    Find tAPMatching where 
         tAPMatching.tc_Rowid = icAPMatchingTcRowid
         no-lock no-error.
    if not available tAPMatching
    then do :
       assign viLocalReturnStatus = -3
              vcMsgAPMatching = trim(substitute(#T-1'Internal error: cannot find the Matching record based upon its rowid (&1).':255(68662)t-1#,icAPMatchingTcRowid)).
       <M-3 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-8282':U (icFcMsgNumber), 
           input  '':U (icFcExplanation), 
           input  '':U (icFcIdentification), 
           input  '':U (icFcContext), 
           output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
        Leave OUTERBLOCK.
    end. /* if not available tAPMatching */
    if tAPMatching.Company_ID <> viCompanyId
    then do :
       assign viLocalReturnStatus = -3
              vcMsgAPMatching = trim(substitute(#T-2'The system cannot calculate taxes because the entity used in the matching is not the current entity (&1).':255(70111)t-2#,vcCompanyCode)).
       <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-8283':U (icFcMsgNumber), 
           input  '':U (icFcExplanation), 
           input  '':U (icFcIdentification), 
           input  '':U (icFcContext), 
           output viFcReturnSuper (oiReturnStatus)) in BAPMatching>
       Leave OUTERBLOCK.
    end. /* if tAPMatching.Company_ID <> viCompanyId */
    
    /* ====================================================================================================================================================================== */
    /* Go through all tPendingVoucherHeader records to transfer the content of tPendingVoucherHeader into the underlying tPendingVoucherAPM and tPendingVoucherTaxAPM records */
    /* ====================================================================================================================================================================== */
    for each tPendingVoucherHeader : 
        if tPendingVoucherHeader.tlIsSelected = false
        then do:
            /* =============================================================================================================================================================== */
            /* If the tPendingVoucherHeader is not selected then delete it togehter with its underlying tPendingVoucherAPM, tPendingVoucherTaxAPM, tPendingVoucherWHT records  */
            /* =============================================================================================================================================================== */
            for each tPendingVoucherAPM where 
                     tPendingVoucherAPM.PvoDomain = tPendingVoucherHeader.tcPvoDomain and 
                     tPendingVoucherAPM.PvoID     = tPendingVoucherHeader.tiPvoID :
                for each tPendingVoucherTaxAPM where 
                         tPendingVoucherTaxAPM.tc_parentRowid = tPendingVoucherAPM.tc_rowid :
                    delete tPendingVoucherTaxAPM.            
                end. /* for each tPendingVoucherTaxAPM where */
                for each tPendingVoucherWHTAPM where 
                         tPendingVoucherWHTAPM.tc_parentRowid = tPendingVoucherAPM.tc_rowid :
                    delete tPendingVoucherWHTAPM.            
                end. /* for each tPendingVoucherWHTAPM where */
                delete tPendingVoucherAPM.
            end. /* for each tPendingVoucherAPM where */
            delete tPendingVoucherHeader.
        end. /* if tPendingVoucherHeader.tlIsSelected = false */
        else do:
            /* ============================================================================================ */
            /* If the tPendingVoucherHeader is selected and the price has changed and needs to be splitted  */
            /* then set vdSplittedAmountForThisHeader to zero to indicate that splitting is required        */
            /* else set vdSplittedAmountForThisHeader to unknown-value to indicate no splitting is required */
            /* ============================================================================================ */
            if tPendingVoucherHeader.tlSplittProRata   = true and 
              tPendingVoucherHeader.tdMatchUnitPrice <> tPendingVoucherHeader.tdPvodUnitPrice
            then assign vdSplittedAmountForThisHeader = 0.
            else assign vdSplittedAmountForThisHeader = ?.
            /* ============================================================================== */
            /* Go through all tPendingVoucherAPM records of the current tPendingVoucherHeader */
            /* ============================================================================== */
            for each tPendingVoucherAPM where 
                     tPendingVoucherAPM.PvoDomain = tPendingVoucherHeader.tcPvoDomain and 
                     tPendingVoucherAPM.PvoID     = tPendingVoucherHeader.tiPvoID
                     break by tPendingVoucherAPM.PvoID:
                /* =============================================================================== */
                /* Mark the tPendingVoucherAPM as being selected                                   */
                /* Mark the tPendingVoucherAPM as being finished when header is marked as finished */
                /* =============================================================================== */
                /* We need to store the IsFinished-flag, IsSelected-flag and MatchedAmount of the  */
                /* LogCharge Pvo-Header into the underlying APMatchingLn record. This is needed as */
                /* we want to have some validations on these fields that compare the value on the  */
                /* header against the value on the underlying APMatchingLn-records                 */
                /* =============================================================================== */
                assign tPendingVoucherAPM.tlIsSelected                      = tPendingVoucherHeader.tlIsSelected
                       tPendingVoucherAPM.APMatchingLnIsPvodFinished        = tPendingVoucherHeader.tlIsPvodFinished
                       tPendingVoucherAPM.tlLogChargeHeaderIsSelected       = tPendingVoucherHeader.tlIsSelected
                       tPendingVoucherAPM.tlLogChargeHeaderIsFinished       = tPendingVoucherHeader.tlIsPvodFinished
                       tPendingVoucherAPM.tdLogChargeHeaderMatchedAmountTC  = tPendingVoucherHeader.tdMatchUnitPrice.
                /* ============================================================================================================= */
                /* If splitting is required and it is the last tPendingVoucherAPM of the current tPendingVoucherHeader           */
                /* then assign APMatchingLnMatchUnitPrice = the not yet splitted value of tPendingVoucherHeader.tdMatchUnitPrice */
                /* else assign APMatchingLnMatchUnitPrice = APMatchingLnMatchUnitPrice * new-header-price / old-header-price     */
                /* Also re-assign APMatchingLnMatchAmtTC and APMatchingLnMatchAmtLC as the MatchUnitPrice is changed             */
                /* Also re-assign APMatchingLnVarRateTC and APMatchingLnVarRateLC as the MatchUnitPrice is changed               */
                /* ============================================================================================================= */
                if vdSplittedAmountForThisHeader <> ?
                then do :
                    if last-of (tPendingVoucherAPM.PvoID)
                    then assign tPendingVoucherAPM.APMatchingLnMatchUnitPrice = tPendingVoucherHeader.tdMatchUnitPrice - vdSplittedAmountForThisHeader.
                    else assign tPendingVoucherAPM.APMatchingLnMatchUnitPrice = <M-10 RoundAmount
                                                                                   (input  tPendingVoucherAPM.APMatchingLnMatchUnitPrice * tPendingVoucherHeader.tdMatchUnitPrice / tPendingVoucherHeader.tdPvodUnitPrice (idUnroundedAmount), 
                                                                                    input  ? (iiCurrencyID), 
                                                                                    input  icCurrencyCode (icCurrencyCode)) in BAPMatching>.
                    assign /* Fill Match-TC and LC */
                           tPendingVoucherAPM.APMatchingLnMatchAmtTC = tPendingVoucherAPM.APMatchingLnMatchUnitPrice
                           tPendingVoucherAPM.APMatchingLnMatchAmtLC = <M-11 RoundAmount
                                                                          (input  tPendingVoucherAPM.APMatchingLnMatchAmtTC * tPendingVoucherAPM.APMatchingLnPvodExchRate / tPendingVoucherAPM.APMatchingLnPvodExchRate2 (idUnroundedAmount), 
                                                                           input  viCompanyId (iiCurrencyID), 
                                                                           input  ? (icCurrencyCode)) in BAPMatching>
                           /* Fill-in the Var-Rate-TC and LC */
                           tPendingVoucherAPM.APMatchingLnVarRateTC  = tPendingVoucherAPM.APMatchingLnMatchAmtTC - tPendingVoucherAPM.APMatchingLnPvodOpenAmtTC
                           tPendingVoucherAPM.APMatchingLnVarRateLC  = <M-15 RoundAmount
                                                                          (input  tPendingVoucherAPM.APMatchingLnVarRateTC * tAPMatching.tdCInvoiceExchangeRate * tAPMatching.tdCInvoiceRateScale (idUnroundedAmount), 
                                                                           input  viCompanyId (iiCurrencyID), 
                                                                           input  ? (icCurrencyCode)) in BAPMatching>
                           /* Update the Splitted-amt */
                           vdSplittedAmountForThisHeader             = vdSplittedAmountForThisHeader + tPendingVoucherAPM.APMatchingLnMatchUnitPrice. 
                end. /* if vdSplittedAmountForThisHeader <> ? */ 
            end. /* for each tPendingVoucherAPM where */
            /* ======================================================================================================== */
            /* Internal check in case splitted is done: the new-header-price should equal the sum of the splitted-values */
            /* ======================================================================================================== */
            if tPendingVoucherHeader.tlSplittProRata   = true                                   and 
               tPendingVoucherHeader.tdMatchUnitPrice <> tPendingVoucherHeader.tdPvodUnitPrice  and
               tPendingVoucherHeader.tdMatchUnitPrice <> vdSplittedAmountForThisHeader
            then do:
               assign viLocalReturnStatus = -3
                      vcMsgAPMatching = trim(#T-9'Internal error. The header price is not equal to the sum of the split values.':255(70113)t-9#).
               <M-8 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-8288':U (icFcMsgNumber), 
                  input  '':U (icFcExplanation), 
                  input  '':U (icFcIdentification), 
                  input  '':U (icFcContext), 
                  output viFcReturnSuper (oiReturnStatus)) in BAPMatching> 
            end.      
        end. /* if tPendingVoucherHeader.tlIsSelected = true */
    end. /* for each tPendingVoucherHeader : */ 
   
    /* ================================================================================ */
    /* Call GTM in case: there are selected PvoHeaders and                              */
    /* - the MatchUnitPrice has been adapted and the difference needs to be splitted OR */
    /* - Calling GTM was asked explicitely                                              */
    /* ================================================================================ */
    if can-find (first tPendingVoucherHeader where 
                       tPendingVoucherHeader.tlIsSelected = true)           and 
       can-find (first tPendingVoucherAPM where
                       tPendingVoucherAPM.APMatchingLnTaxEnv <> "":U and 
                       tPendingVoucherAPM.APMatchingLnTaxEnv <> ?)          and
      (ilCallGTM = true or 
       can-find (first tPendingVoucherHeader where 
                       tPendingVoucherHeader.tlIsSelected     = true and 
                       tPendingVoucherHeader.tlSplittProRata  = true and 
                       tPendingVoucherHeader.tdMatchUnitPrice <> tPendingVoucherHeader.tdPvodUnitPrice))
    then do :
       /* ============================================= */
       /* Start PGTM once to avoid performance-overhead */
       /* Start Block to Capture errors after stop PGTM */
       /* ============================================= */
       <I-62 {bFcStartAndOpenInstance
            &ADD-TO-TRANSACTION   = "false"
            &CLASS                = "PGTM"}>
       assign viPGTMCallingBlockReturnStatus = 0.
       PGTMCALLINGBLOCK: DO :
           /* ============================================================================== */
           /* Go through the tPendingVoucherHeader that still exist - only the selected ones */
           /* Calling GTM is somtimes only needed for some tPendingVoucherHeader records     */
           /* ============================================================================== */
           for each tPendingVoucherHeader:
               if ilCallGTM = true or 
                  (tPendingVoucherHeader.tdMatchUnitPrice <> tPendingVoucherHeader.tdPvodUnitPrice and 
                   tPendingVoucherHeader.tlSplittProRata   = true)  
               then do :
                   /* ============================================================================== */
                   /* Go through all tPendingVoucherAPM records of the current tPendingVoucherHeader */
                   /* ============================================================================== */
                   for each tPendingVoucherAPM where 
                            tPendingVoucherAPM.PvoDomain           = tPendingVoucherHeader.tcPvoDomain and 
                            tPendingVoucherAPM.PvoID               = tPendingVoucherHeader.tiPvoID     and 
                            tPendingVoucherAPM.APMatchingLnTaxEnv <> "":U                              and 
                            tPendingVoucherAPM.APMatchingLnTaxEnv <> ?:
                       /* ================================================================================= */
                       /* Clear the existing tPendingVoucherTaxAPM records of the tPendingVoucherAPM record */
                       /* ================================================================================= */
                       for each tPendingVoucherTaxAPM where 
                                tPendingVoucherTaxAPM.tc_parentRowid = tPendingVoucherAPM.tc_rowid :
                           delete tPendingVoucherTaxAPM.
                       end. /* for each tPendingVoucherTaxAPM where */
                       /* ============================================== */
                       /* Call GTM indirectly by calling an local method */                
                       /* ============================================== */
                       <M-5 run CreateAPMatchingLNTaxFromGTM
                          (input  icAPMatchingTcRowid (icAPMatchingTcRowid), 
                           input  tPendingVoucherAPM.tc_Rowid (icAPMatchingLnTcRowid), 
                           input  icCurrencyCode (icCurrencyCode), 
                           input  '':U (icTransactionType), 
                           input  iiCInvoiceVoucher (icDocumentReference), 
                           input  '':U (icDocumentNumber), 
                           input  tPendingVoucherAPM.APMatchingLnIsTaxable (ilIsTaxable), 
                           input  false (ilIsTaxIncludedInTheAmount), 
                           input  tAPMatching.ttCInvoiceTaxPointDate (itTaxPointDate), 
                           input  tAPMatching.APMatchingDate (itPostingDate), 
                           input  tPendingVoucherAPM.APMatchingLnTaxEnv (icTaxEnvCode), 
                           input  tPendingVoucherAPM.APMatchingLnPvodFromTaxZone (icFromTaxZoneCode), 
                           input  tPendingVoucherAPM.APMatchingLnPvodToTaxZone (icToTaxZoneCode), 
                           input  tPendingVoucherAPM.APMatchingLnTaxClass (icTaxClassCode), 
                           input  tPendingVoucherAPM.APMatchingLnTaxUsage (icTaxUsageCode), 
                           input  tPendingVoucherAPM.APMatchingLnMatchAmtTC (idAmountTC), 
                           input  idCInvoiceExchangeRate (idCInvoiceTCLCRate), 
                           input  idCInvoiceRateScale (idCInvoiceTCLCScale), 
                           input  tAPMatching.tdCInvoiceCCRate (idCInvoiceTCCCRate), 
                           input  tAPMatching.tdCInvoiceCCScale (idCInvoiceTCCCScale), 
                           input  vcCompanyCode (icCompanyCode), 
                           input  1 (idAdjustmentFactor), 
                           input  tAPMatching.APMatchingCInvoiceDiscPct (idPaymentConditionPercentage), 
                           input  tAPMatching.tlCreditorAddrIsTaxInCity (ilIsTaxInCityOfShipTo), 
                           input  tAPMatching.tlShipToAddrIsTaxInCity (ilIsTaxInCityOfShipFrom), 
                           input  false (ilNeedToStartPGTMFromHere), 
                           output tAPMatchingLnTaxFromGTM (tAPMatchingLnTaxFromGTM), 
                           output tAPMatchingLnWHTFromGTM (tAPMatchingLnWHTFromGTM), 
                           output viFcReturnSuper (oiReturnStatus)) in BAPMatching> 
                       if vifcReturnSuper <> 0
                       then assign viPGTMCallingBlockReturnStatus = vifcReturnSuper.
                       if vifcReturnSuper < 0 
                       then Leave PGTMCALLINGBLOCK.
                       /* ================================================================================================= */
                       /* Store the output in the tPendingVoucherTaxAPM and empty tAPMatchingLnTaxFromGTM when it is copied */
                       /* ================================================================================================= */
                       for each tAPMatchingLnTaxFromGTM :
                           create tPendingVoucherTaxAPM.
                           buffer-copy tAPMatchingLnTaxFromGTM to tPendingVoucherTaxAPM.
                       end. /* for each tAPMatchingLnTaxFromGTM */
                       empty temp-table tAPMatchingLnTaxFromGTM.                
                       /* ================================================================================================= */
                       /* Store the output in the tPendingVoucherWHTAPM and empty tAPMatchingLnWHTFromGTM when it is copied */
                       /* ================================================================================================= */
                       for each tAPMatchingLnWHTFromGTM :
                           create tPendingVoucherWHTAPM.
                           buffer-copy tAPMatchingLnWHTFromGTM to tPendingVoucherWHTAPM.
                       end. /* for each tAPMatchingLnWHTFromGTM */
                       empty temp-table tAPMatchingLnWHTFromGTM. 
                   end. /* for each tPendingVoucherAPM where */
               end. /* if ilCallGTM = true or */
           end. /* for each tPendingVoucherHeader where */ 
       END. /* PGTMCALLINGBLOCK */  
       /* ========= */
       /* Stop PGTM */
       /* ========= */
        <I-7 {bFcCloseAndStopInstance
             &CLASS           = "PGTM"}>
       /* ============================= */
       /* Check for errors in the block */
       /* ============================= */
       if viPGTMCallingBlockReturnStatus <> 0
       then assign viLocalReturnStatus = viPGTMCallingBlockReturnStatus.
       if viPGTMCallingBlockReturnStatus < 0
       then Leave OUTERBLOCK.
    end. /* if can-find (first tPendingVoucherHeader where  */

END. /* OUTERBLOCK */   
   
/* ================== */
/* Exception handling */
/* ================== */
assign oiReturnStatus = viLocalReturnStatus.