project QadFinancials > class BDInvoice > method ValidateComponentAllPostTSMNumber

validation procedure

Description

This method is a submethod of ValidateComponentAllPost. t_sDInvoice is available in this method. Make sure you keep the segments of these two methods the same.

If one of the payment formats is SEPA, then a sepa number is generated, otherwise this method validates the TSM Number : Number to be validated by modulus 97 (belgium)


Parameters


icDinvoiceTSMNumberinputcharacterTSM Number of debtor invoice
iiHOAddressTypeIdinputintegerID of the head office address type
icRowidinputcharacterContents of field tc_Rowid, if the target field is a field of a component temp-table.
iiDebtorIdinputintegerDebtor ID
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDInvoice.ValidateComponentAllPost


program code (program5/bdinvoice.p)

    assign vlIsSEPAPaymentType = false. 
    for each t_sDInvoiceBank where
             t_sDInvoiceBank.DInvoice_ID = t_sDInvoice.DInvoice_ID         and
             t_sDInvoiceBank.tc_Status  <> 'D'
             on error undo, throw:

        /* ========================================================================================== */
        /* Fill in tcPayFormatTypeCode when it is not filled.                                         */
        /* This can happen when creating invoices using tyhe integration. (ex. Invoice Post and Print */
        /* ========================================================================================== */
        if (t_sDInvoiceBank.tcPayFormatTypeCode = ? or 
            t_sDInvoiceBank.tcPayFormatTypeCode = '')                     and
            t_sDInvoiceBank.BankNumber_ID      <> 0                       and
            t_sDInvoiceBank.BankNumber_ID      <> ?
        then do:           
            <Q-43 run BankNumberForPayFormatBank (all) (Read) (NoCache)
               (input t_sDInvoice.Company_ID, (CompanyId)
                input ?, (ParentObjectID)
                input t_sDInvoiceBank.BankNumber_ID, (BankNumberID)
                output dataset tqBankNumberForPayFormatBank) in BBankNumber>             
            find first tqBankNumberForPayFormatBank where
                       tqBankNumberForPayFormatBank.tiBankNumber_ID = t_sDInvoiceBank.BankNumber_ID 
                       no-lock no-error.
            if available tqBankNumberForPayFormatBank
            then assign t_sDInvoiceBank.tcPayFormatTypeCode  = tqBankNumberForPayFormatBank.tcPayFormatTypeCode.        
        end. /* if (t_sDInvoiceBank.tcPayFormatTypeCode = ? or  */
                     
        /* ======================================================================================== */
        /* If one of the payment formats starts with "SEPA" we will generate the SEPA number for it */
        /* If the field was filled on UI, we will raise a warning to notify the user no SEPA number */
        /* will be used on the invoice.                                                             */
        /* In case it is not SEPA, we will validate the payment reference that was entered.         */
        /* ======================================================================================== */             
        <Q-22 run PayFormatTypeByType (all) (Read) (Cache)
           (input t_sDInvoiceBank.tcPayFormatTypeCode, (PayFormatTypeCode)
            output dataset tqPayFormatTypeByType) in BPaymentFormat>
        find tqPayFormatTypeByType where
             tqPayFormatTypeByType.tcPayFormatTypeCode   = t_sDInvoiceBank.tcPayFormatTypeCode and
             tqPayFormatTypeByType.tlPayFormatTypeIsSEPA = true
             no-error.
        if available tqPayFormatTypeByType
        then assign vlIsSEPAPaymentType = true.
    end. /* for each t_sCInvoiceBank where */

        
    
        
    if vlIsSEPAPaymentType = true
    then do:    
        /* ===================================================== */
        /* payment reference can only be changed before payment  */
        /* Check balance to see if invoice is payed              */
        /* ===================================================== */ 
        if t_sDInvoice.DInvoiceBalanceDebitTC  = t_sDInvoice.DInvoiceOriginalDebitTC and
           t_sDInvoice.DInvoiceBalanceCreditTC = t_sDInvoice.DInvoiceOriginalCreditTC
        then do:           
            /* unique key for the reference is the customer code + dinvoice_id */
            assign vcSEPAPaymentReferenceKey = t_sDInvoice.tcDebtorCode +
                                               string(t_sDInvoice.DInvoice_ID).
            <M-56 run GenerateSEPAReference
               (input  vcSEPAPaymentReferenceKey (icKeyToGenerate), 
                output vcSEPAPaymentReference (ocSEPAPaymentReference), 
                output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
            if viFcReturnSuper <> 0 and oiReturnStatus >= 0
            then assign oiReturnStatus = viFcReturnSuper.
            if viFcReturnSuper < 0
            then return.
            
            /* Warning if payment reference was already filled */
            if icDinvoiceTSMNumber <> "" and 
               icDinvoiceTSMNumber <> vcSEPAPaymentReference
            then do:
                /* Check if message needs to be shown (Company setting) */
                <Q-55 run CompanyPropertyByIDAllInfo (all) (Read) (NoCache)
                   (input viCompanyId, (CompanyId)
                    output dataset tqCompanyPropertyByIDAllInfo) in BCompanyProperty>
                find tqCompanyPropertyByIDAllInfo where
                     tqCompanyPropertyByIDAllInfo.tiCompany_ID = viCompanyId
                     no-lock no-error.
                if available tqCompanyPropertyByIDAllInfo and
                   tqCompanyPropertyByIDAllInfo.tlCompanyPropertyIsShowSEPAMsg = true
                then do:
                    assign vcMessage = #T-72'This invoice uses SEPA payments.  Entering a payment reference yourself will prevent a generated SEPA payment reference number to be assigned to the invoice.':255(744754119)T-72# + chr(10) +
                                       substitute(#T-13'Entered Payment Reference: &1':255(159699420)T-13#, icDinvoiceTSMNumber) + chr(10) +
                                       substitute(#T-67'Generated SEPA Payment Reference: &1':255(709785262)T-67#, vcSEPAPaymentReference).
                    <M-31 run SetMessage
                       (input  vcMessage (icMessage), 
                        input  '' (icArguments), 
                        input  'tDInvoice.DInvoiceTSMNumber' (icFieldName), 
                        input  icDinvoiceTSMNumber (icFieldValue), 
                        input  'W' (icType), 
                        input  3 (iiSeverity), 
                        input  t_sDInvoice.tc_Rowid (icRowid), 
                        input  'qadfin-739124':U (icFcMsgNumber), 
                        input  '' (icFcExplanation), 
                        input  '' (icFcIdentification), 
                        input  '' (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
                    if oiReturnStatus >= 0
                    then assign oiReturnStatus = 1.
                end. /* if available tqCompanyPropertyByIDAllInfo and */
            end. /* if icDinvoiceTSMNumber <> "" */ 
            else assign t_sDInvoice.DInvoiceTSMNumber = vcSEPAPaymentReference.
        end. /* t_sDInvoice.DInvoiceBalanceDebitTC  = t_sDInvoice.DInvoiceOriginalDebitTC */    
    end. /* if vlIsSEPAPaymentType = true */
        
    if icDinvoiceTSMNumber <> "":U and icDinvoiceTSMNumber <> ? and
       iiDebtorId          <> 0    and iiDebtorId          <> ? and
       vlIsSEPAPaymentType  = false 
    then do :
        <Q-8 run DebtorByDebtorCountry (all) (Read) (NoCache)
           (input ?, (CompanyId)
            input iiDebtorId, (DebtorId)
            input ?, (DebtorCode)
            input ?, (AddressTypeCode)
            input iiHOAddressTypeId, (AddressTypeId)
            output dataset tqDebtorByDebtorCountry) in BDebtor>
        find first tqDebtorByDebtorCountry where
                   tqDebtorByDebtorCountry.tiDebtor_ID      = iiDebtorId and
                   tqDebtorByDebtorCountry.tiAddressType_ID = iiHOAddressTypeId 
                   no-error.
        if not available tqDebtorByDebtorCountry
        then do:
            assign vcMessage      = trim(#T-5'The specified customer is not defined in the system.':50(49415)t-5#)
                   oiReturnStatus = -1.
            <M-2 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tDinvoice.DinvoiceTSMNumber':U (icFieldName), 
                input  icDinvoiceTSMNumber (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  icRowid (icRowid), 
                input  'QADFIN-423':U (icFcMsgNumber), 
                input  '' (icFcExplanation), 
                input  '' (icFcIdentification), 
                input  '' (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
        end.
        else do:        
            assign vhFcComponent = ?.
            <M-21 run ValidateTSMNumber
               (input  icDinvoiceTSMNumber (icTSMNumber), 
                input  '' (icValidationType), 
                input  tqDebtorByDebtorCountry.tiCountry_ID (iiCountryId), 
                input  tqDebtorByDebtorCountry.tcCountryCode (icCountryCode), 
                input  viSessionID (iiSessionId), 
                output vcErrorMessage (ocErrorMessage), 
                output viFcReturnSuper (oiReturnStatus)) in TTSM>
            /* remove from memory */
            run gipr_DeleteProcedure in vhFcComponent no-error.
            delete procedure vhFcComponent no-error.
            
            if viFcReturnSuper < 0
            then do:
                assign vcMessage      = vcErrorMessage
                       oiReturnStatus = -1.
                <M-4 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tDinvoice.DinvoiceTSMNumber':U (icFieldName), 
                    input  icDinvoiceTSMNumber (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  icRowid (icRowid), 
                    input  'QADFIN-424':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
            end. /* end viFcReturnSuper < 0 */
            else if viFcReturnSuper > 0
            then do:
                assign vcMessage      = vcErrorMessage
                       oiReturnStatus = -1.
                <M-93 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tDinvoice.DinvoiceTSMNumber':U (icFieldName), 
                    input  icDinvoiceTSMNumber (icFieldValue), 
                    input  'W':U (icType), 
                    input  3 (iiSeverity), 
                    input  icRowid (icRowid), 
                    input  'qadfin-702523':U (icFcMsgNumber), 
                    input  '' (icFcExplanation), 
                    input  '' (icFcIdentification), 
                    input  '' (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BDInvoice>
            end. /* end viFcReturnSuper < 0 */
        end. /* end available tqDebtorByDebtorCountry */
    end. /* end icDinvoiceTSMNumber <> "":U and iiDebtorId <> 0 */