project QadFinancials > class BBankCharge > method PreValidateComponent


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankCharge.ValidateComponent


program code (program1/bbankcharge.p)

/* =================================================================== */
/* The Bank Charges are part of an Internationalization module (Japan) */
/* They should only be accessible whenever there is a valid license.   */
/* NOTE: THIS CODE SHOULD MOVE TO INITINSTANCE WHEN BLF-4140 IS SOLVED */
/* =================================================================== */

/* Don't have to check for started instances for proxy classes */
<I-89 {bFcStartAndOpenInstance
     &ADD-TO-TRANSACTION   = "false"
     &CLASS                = "PLicense"}>

assign vcLicenseBankCharge = {&LICENSEBANKCHARGE}.
<M-80 run ValidateProgramLicense
   (input  vcLicenseBankCharge (icProgramName), 
    output viFcReturnSuper (oiReturnStatus)) in PLicense>
if viFcReturnSuper < 0 or 
  (viFcReturnSuper > 0 and oiReturnStatus = 0)
then assign oiReturnStatus = viFcReturnSuper.

<I-98 {bFcCloseAndStopInstance
     &CLASS           = "PLicense"}>

if oiReturnStatus < 0
then return.

assign oiReturnStatus = -98.

/* Remove the not necessary records by calling createbankchargerate */
for each t_sBankChargeRate where t_sBankChargeRate.BankChargeRateLineSeq = 0
                           and t_sBankChargeRate.BankChargeRateType ='':U:
    assign t_sBankChargeRate.tc_Status = 'D':U.
end.

for each t_sBankCharge where t_sBankCharge.tc_Status = 'N':U:
    assign t_sBankCharge.BusinessRelation_ID = 0.
    if t_sBankCharge.tcBusinessRelationCode <> ? and t_sBankCharge.tcBusinessRelationCode <> '':U then
    do:
        /* Re-assign business relation id. */
        <Q-51 run BusinessRelationPrim (all) (Read) (Cache)
           (input ?, (BusinessRelationId)
            input t_sBankCharge.tcBusinessRelationCode, (BusinessRelationCode)
            output dataset tqBusinessRelationPrim) in BBusinessRelation>
        find first tqBusinessRelationPrim no-error.
        if available tqBusinessRelationPrim then
            assign t_sBankCharge.BusinessRelation_ID = tqBusinessRelationPrim.tiBusinessRelation_ID.
    end.
    if t_sBankCharge.BusinessRelation_ID = 0 then
    do:
        assign vcMessage = trim(#T-283'You must specify an existing business relation code.':255(862553675)T-283#).
        <M-22 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'Own Bank Business Relation':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  ? (icRowid), 
            input  'qadfin-699033':U (icFcMsgNumber), 
            input  ? (icFcExplanation), 
            input  ? (icFcIdentification), 
            input  ? (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankCharge>
        return.
    end.
    if t_sBankCharge.tcCurrencyCode <> vcCompanyCC and t_sBankCharge.tcCurrencyCode <> vcCompanyLC then
    do:
        assign vcMessage = trim(#T-49'The currency must be the base currency or statutory currency of the current domain.':255(788967560)T-49#).
        <M-9 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  t_sBankCharge.tcCurrencyCode (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  ? (icRowid), 
            input  'qadfin-530761':U (icFcMsgNumber), 
            input  ? (icFcExplanation), 
            input  ? (icFcIdentification), 
            input  ? (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankCharge>
            return.        
    end.
end. /* end for each t_sBankCharge */

<Q-73 run BusinessRelationForOwnBank  (Start) in BBusinessRelation>

for each t_sBankCharge where t_sBankCharge.tc_Status = 'N':U
                       break by t_sBankCharge.BusinessRelation_ID:    
    if last-of(BusinessRelation_ID) then
    do:
       if t_sBankCharge.BusinessRelation_ID > 0 then 
       do:
          <Q-97 run BusinessRelationForOwnBank (all) (Read) (NoCache)
             (input ?, (CompanyId)
              input ?, (DomainID)
              input t_sBankCharge.BusinessRelation_ID, (BusinessRelation_ID)
              output dataset tqBusinessRelationForOwnBank) in BBusinessRelation> 
           find first tqBusinessRelationForOwnBank where tqBusinessRelationForOwnBank.tiBusinessRelation_ID = t_sBankCharge.BusinessRelation_ID no-error.
           if not available tqBusinessRelationForOwnBank then
           do:
                assign vcMessage = trim(substitute(#T-17'The business relation must be linked to a bank account with AP bank charge activated and the bank currency is &1.':255(303725835)T-17#, t_sBankCharge.tcCurrencyCode)).
                <M-31 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  t_sBankCharge.tcBusinessRelationCode (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  ? (icRowid), 
                    input  'qadfin-746568':U (icFcMsgNumber), 
                    input  ? (icFcExplanation), 
                    input  ? (icFcIdentification), 
                    input  ? (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BBankCharge>
                return. 
           end. 
       end.
    end.
end. /* end for each t_sBankCharge */
<Q-28 run BusinessRelationForOwnBank  (Stop) in BBusinessRelation>
/* Validate no gap between the rate settings */
for each t_sBankChargeRate where t_sBankChargeRate.tc_Status <> 'D' 
                       break by t_sBankChargeRate.BankCharge_ID 
                       by t_sBankChargeRate.BankChargeRateType 
                       by t_sBankChargeRate.BankChargeRateLineSeq:
    /* Charge amount should be > 0 and < from amount */
   if t_sBankChargeRate.BankChargeRatePayFromTC < 0 then
   do:
        assign vcMessage = trim(#T-40'The Payment Amount From value must be zero or greater.':255(611007875)T-40#).
        <M-48 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  ? (icRowid), 
            input  'qadfin-655398':U (icFcMsgNumber), 
            input  ? (icFcExplanation), 
            input  ? (icFcIdentification), 
            input  ? (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankCharge>
       return.
   end.
   /* Charge amount should be > 0 and < from amount */
   if t_sBankChargeRate.BankChargeRatePayToTC < 0 then
   do:
        assign vcMessage = trim(#T-92'The Payment Amount To value must be zero or greater.':255(116009536)T-92#).
        <M-91 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  ? (icRowid), 
            input  'qadfin-247158':U (icFcMsgNumber), 
            input  ? (icFcExplanation), 
            input  ? (icFcIdentification), 
            input  ? (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankCharge>
       return.
   end.
   /* Charge amount should be > 0 and < from amount */
   if t_sBankChargeRate.BankChargeRateChargeTC < 0 then
   do:
        assign vcMessage = trim(#T-35'The Bank Charge Amount value must be zero or greater.':255(360254929)T-35#).
        <M-87 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  ? (icRowid), 
            input  'qadfin-152743':U (icFcMsgNumber), 
            input  ? (icFcExplanation), 
            input  ? (icFcIdentification), 
            input  ? (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankCharge>
       return.
   end.
   if t_sBankChargeRate.BankChargeRateChargeTC >= t_sBankChargeRate.BankChargeRatePayToTC then
   do:
        assign vcMessage = trim(#T-60'The bank charge amount must be less than the value in the Payment Amount To field.':255(455304809)T-60#).
        <M-67 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  string(t_sBankChargeRate.BankChargeRateChargeTC) (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  ? (icRowid), 
            input  'qadfin-799993':U (icFcMsgNumber), 
            input  ? (icFcExplanation), 
            input  ? (icFcIdentification), 
            input  ? (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankCharge>
       return.
   end.
   /* From always <= to , cannot be zero at same time */
   if t_sBankChargeRate.BankChargeRatePayFromTC >= t_sBankChargeRate.BankChargeRatePayToTC then
   do:
       assign vcMessage = trim(substitute(#T-46'The Payment Amount From must be less than the Payment Amount To in line &1.':255(23727676)T-46#, t_sBankChargeRate.BankChargeRateLineSeq)).
       <M-34 run SetMessage
          (input  vcMessage (icMessage), 
           input  '':U (icArguments), 
           input  '':U (icFieldName), 
           input  '':U (icFieldValue), 
           input  'E':U (icType), 
           input  3 (iiSeverity), 
           input  ? (icRowid), 
           input  'qadfin-445698':U (icFcMsgNumber), 
           input  ? (icFcExplanation), 
           input  ? (icFcIdentification), 
           input  ? (icFcContext), 
           output viFcReturnSuper (oiReturnStatus)) in BBankCharge>
       return.
   end.
   
   /* Curr from paid amount should always be same before to paid amount*/
   if first-of(t_sBankChargeRate.BankChargeRateType) then
   do:
       assign vdpreToPaidTC = 0.
   end.
   else do:
       if t_sBankChargeRate.BankChargeRatePayFromTC <> vdpreToPaidTC then
       do:
            assign vcMessage = trim(substitute(#T-36'The Payment Amount From must be the same as the Payment Amount To of the previous line &1.':255(897553604)T-36#, (t_sBankChargeRate.BankChargeRateLineSeq - 1))).
            <M-7 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  ? (icRowid), 
                input  'qadfin-424758':U (icFcMsgNumber), 
                input  ? (icFcExplanation), 
                input  ? (icFcIdentification), 
                input  ? (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BBankCharge>
             return.
       end.
   end.
   assign vdpreToPaidTC = t_sBankChargeRate.BankChargeRatePayToTC.
   
   /* Validate rounding method */
   find first t_sBankCharge where t_sBankCharge.BankCharge_ID = t_sBankChargeRate.BankCharge_ID no-error.
   if available t_sBankCharge then 
   do:
        vdRoundAmount = <M-26 RoundAmount
                            (input  t_sBankChargeRate.BankChargeRatePayFromTC (idUnroundedAmount), 
                             input  t_sBankCharge.Currency_ID (iiCurrencyID), 
                             input  ? (icCurrencyCode)) in BBankCharge>.
             
        if vdRoundAmount <>  t_sBankChargeRate.BankChargeRatePayFromTC then assign oiReturnStatus = -1.
        if oiReturnStatus <> -1 then 
        do:
            vdRoundAmount = <M-41 RoundAmount
                               (input  t_sBankChargeRate.BankChargeRatePayToTC (idUnroundedAmount), 
                                input  t_sBankCharge.Currency_ID (iiCurrencyID), 
                                input  ? (icCurrencyCode)) in BBankCharge>.
                        
            if vdRoundAmount <>  t_sBankChargeRate.BankChargeRatePayToTC then assign oiReturnStatus = -1.
        end.
        if oiReturnStatus <> -1 then 
        do:
            vdRoundAmount = <M-88 RoundAmount
                               (input  t_sBankChargeRate.BankChargeRateChargeTC (idUnroundedAmount), 
                                input  t_sBankCharge.Currency_ID (iiCurrencyID), 
                                input  ? (icCurrencyCode)) in BBankCharge>.
                 
            if vdRoundAmount <>  t_sBankChargeRate.BankChargeRateChargeTC then assign oiReturnStatus = -1.
        end.
        if oiReturnStatus = -1 then
        do:
            assign vcMessage = trim(#T-96'The amount is not correctly rounded. Check the rounding method linked to the currency.':150(422940729)T-96#).
            <M-93 run SetMessage                
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  ? (icRowid), 
                input  'qadfin-387695':U (icFcMsgNumber), 
                input  ? (icFcExplanation), 
                input  ? (icFcIdentification), 
                input  ? (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BBankCharge>
             return.              
         end.
     end. /* end  if available t_sBankCharge then */ 
end. /* end for each t_sBankChargeRate */

assign oiReturnStatus = 0.