project QadFinancials > class BPaymentSelection > method ValidateComponentPostSummary


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPaymentSelection.ValidateComponentPost


program code (program4/bpaymentselection.p)

/* Summary Validations */
assign vlStart1 = false.

for each tSumCheck
         break by tSumCheck.tcSumCreditorCode
               by tSumCheck.tcSumCurrencyCode
               by tSumCheck.tiSumBank_ID:
    if first-of(tSumCheck.tiSumBank_ID)
    then do:
        assign vdPaymentAmt = 0.

        if tSumCheck.tiSumBank_ID = 0 or
           tSumCheck.tiSumBank_ID = ?
        then assign vcBankNumber = "":U.
        else do:
            if not vlStart1
            then do:
                <Q-11 run BankNumberByID  (Start) in BBankNumber >
                assign vlStart1 = true.
            end.

            <Q-12 run BankNumberByID (all) (Read) (Cache)
               (input tSumCheck.tiSumBank_ID, (BankNumber_ID)
                input ?, (CompanyId)
                output dataset tqBankNumberByID) in BBankNumber >

            find first tqBankNumberByID where
                       tqBankNumberByID.tiBankNumber_ID = tSumCheck.tiSumBank_ID
                       no-error.

            assign vcBankNumber = if available tqBankNumberByID
                                  then if tqBankNumberByID.tcBankNumberFormatted = "":U or
                                          tqBankNumberByID.tcBankNumberFormatted = ?
                                       then if tqBankNumberByID.tcBankNumber = ?
                                            then "":U
                                            else tqBankNumberByID.tcBankNumber
                                       else tqBankNumberByID.tcBankNumberFormatted
                                  else "":U.
        end.
    end.

    if tSumCheck.tcSumObjectType = {&PAYMENTSELECTIONTYPE-CREDITNOTE}    or
       tSumCheck.tcSumObjectType = {&PAYMENTSELECTIONTYPE-INVOICECORR}   or
      (tSumCheck.tcSumObjectType = {&PAYMENTSELECTIONTYPE-ADJUSTMENT}    and
       tSumCheck.tcPaymentCrDt   = {&CREDITDEBITABBREVIATION-CREDIT-TR})
    then assign vdPaymentAmt = vdPaymentAmt - abs(tSumCheck.tdSumPaymentAmtTC).
    else
        if (tSumCheck.tcSumObjectType = {&PAYMENTSELECTIONTYPE-ADJUSTMENT}    or
            tSumCheck.tcSumObjectType = {&PAYMENTSELECTIONTYPE-PREPAYMENTINV})
        then assign vdPaymentAmt = vdPaymentAmt + tSumCheck.tdSumPaymentAmtTC.
        else assign vdPaymentAmt = vdPaymentAmt + abs(tSumCheck.tdSumPaymentAmtTC).

    if last-of(tSumCheck.tiSumBank_ID) and
       vdPaymentAmt <= 0
    then do:
        assign vcLineDescript = tSumCheck.tcSumCreditorCode + ' - ':U +
                                tSumCheck.tcSumCurrencyCode + ' - ':U +
                                vcBankNumber                + chr(2)  +
                                tSumCheck.tcBusinessRelationCode.

        <M-3 run SetMessage
          (input  trim(#T-9'The supplier ($1) with business relation ($2) has a negative or zero payment balance.':250(17222)t-9#) (icMessage), 
           input  vcLineDescript (icArguments), 
           input  'vdPaymentAmt':U (icFieldName), 
           input  vdPaymentAmt (icFieldValue), 
           input  'E':U (icType), 
           input  3 (iiSeverity), 
           input  '':U (icRowid), 
           input  'QADFIN-1317':U (icFcMsgNumber), 
           input  '':U (icFcExplanation), 
           input  '':U (icFcIdentification), 
           input  '':U (icFcContext), 
           output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>

        assign oiReturnStatus = -1.
    end.
end.

if vlStart1
then do:
    <Q-14 run BankNumberByID  (Stop) in BBankNumber >
end.

assign vlStart1 = false.

if vcActivityCode <> {&PAYMENTSELECTIONACTIVITY-UNCONFIRM}
then do:
    
    /* Check Summary on Invoices with Possible Multiple Lines */
    for each tSumCheck where
             tSumCheck.tcSumObjectType = {&PAYMENTSELECTIONTYPE-INVOICE} or
             tSumCheck.tcSumObjectType = {&PAYMENTSELECTIONTYPE-INVOICECORR}
             break by tSumCheck.tcSumObjectType
                 by tSumCheck.tiSumObject_ID:
        accumulate tSumCheck.tiSumObject_ID         (count by tSumCheck.tiSumObject_ID)
                abs(tSumCheck.tdSumPaymentAmtTC) (total by tSumCheck.tiSumObject_ID).
                   
        if last-of(tSumCheck.tiSumObject_ID) and 
           (accum count by tSumCheck.tiSumObject_ID (tSumCheck.tiSumObject_ID)) > 1
        then do:
            if not vlStart1
            then do:
                assign vlStart1 = true.
                
                <Q-15 run CInvoiceByPaymentInfo  (Start) in BCInvoice>
            end.
            
            <Q-69 run CInvoiceByPaymentInfo (all) (Read) (Cache)
               (input ?, (CompanyId)
                input ?, (BusinessRelationCode)
                input tSumCheck.tiSumObject_ID, (CInvoice_ID)
                input ?, (PaymentGroupCode)
                input ?, (CurrencyCode)
                input ?, (DivisionCode)
                input ?, (BusinessRelationIsInterco)
                input ?, (CInvoiceType)
                input ?, (IsInvoiceApproved)
                input ?, (IsLockPayment)
                input ?, (CInvoiceIsSelected)
                input ?, (CInvoiceIsOpen)
                input ?, (BusinessRelationCountryCode)
                input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressTypeCode)
                output dataset tqCInvoiceByPaymentInfo) in BCInvoice>
                
            find first tqCInvoiceByPaymentInfo where
                       tqCInvoiceByPaymentInfo.tiCInvoice_ID = tSumCheck.tiSumObject_ID
            no-error.
            
            if available tqCInvoiceByPaymentInfo and 
            (accum total by tSumCheck.tiSumObject_ID (abs(tSumCheck.tdSumPaymentAmtTC))) >
            abs(tqCInvoiceByPaymentInfo.tdCInvoiceBalanceCreditTC - tqCInvoiceByPaymentInfo.tdCInvoiceBalanceDebitTC)
            then do:
                assign vcLineDescript = string(accum total by tSumCheck.tiSumObject_ID (abs(tSumCheck.tdSumPaymentAmtTC))) + chr(2)  +
                                        string(tqCInvoiceByPaymentInfo.tiPeriodYear, "9999":U)                             + "/":U   +
                                        tqCInvoiceByPaymentInfo.tcJournalCode                                              + "/":U   +
                                        string(tqCInvoiceByPaymentInfo.tiCInvoiceVoucher, "999999999":U)                   + " - ":U +
                                        tqCInvoiceByPaymentInfo.tcCInvoiceReference                                        + " - ":U +
                                        tSumCheck.tcSumObjectType.
                                        
                <M-56 run SetMessage
                   (input  #T-70'The payment amount ($1) exceeded the open balance: ($2).':250(16091)T-70# (icMessage), 
                    input  vcLineDescript (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  '':U (icRowid), 
                    input  'qadfin-205731':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BPaymentSelection>
                    
                assign oiReturnStatus = -1.
            end.
        end.
    end.
end. /* if vcActivityCode <> {&PAYMENTSELECTIONACTIVITY-UNCONFIRM} */




if vlStart1
then do:
    <Q-16 run CInvoiceByPaymentInfo  (Stop) in BCInvoice >
end.