project QadFinancials > class BCInvoice > method ValidateComponentPostTSM

Description

This method is a submethod of ValidateComponentPost.

This method validates the tsm number of the creditor invoice.


Parameters


iiHOAddressTypeIdinputintegerid of the head office address type
bhTTSMinput-outputhandlehandle of component TTSM
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCInvoice.ValidateComponentPost


program code (program5/bcinvoice.p)

/* TSM number cannot change if invoice was already selected */
if t_sCInvoice.tc_Status          = "C":U                         and
   t_sCInvoice.CInvoiceTSMNumber <> t_iCInvoice.CInvoiceTSMNumber and
   t_iCInvoice.CInvoiceIsSelected = true
then do:
    assign vcMessage      = trim(#T-8'You cannot modify the TSM number because the invoice is (partly) paid or included in a payment that is currently being processed.':150(1223)T-8#) + chr(10) +
                            trim(subst(#T-9'GL Calendar Year = &1; GL Period = &2; Daybook = &3; Voucher = &4.':255(969)T-9#, string(t_sCInvoice.CInvoicePostingYear), string(t_sCInvoice.CInvoicePostingPeriod), t_sCInvoice.tcJournalCode, string(t_sCInvoice.CInvoiceVoucher)))
           oiReturnStatus = -1.

    <M-7 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  'tCInvoice.CInvoiceTSMNumber':U (icFieldName), 
        input  t_sCInvoice.CInvoiceTSMNumber (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  t_sCInvoice.tc_Rowid (icRowid), 
        input  'QadFin-7117':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCInvoice>

    return.
end.

/* Validate format of TSM number */
if ((t_sCInvoice.tc_Status          = "N":U                         or
    (t_sCInvoice.tc_Status          = "C":U                         and
    (t_sCInvoice.CInvoiceTSMNumber <> t_iCInvoice.CInvoiceTSMNumber or
     t_sCInvoice.Creditor_ID       <> t_iCInvoice.Creditor_ID)))    and
     t_sCInvoice.Creditor_ID       <> 0                             and
     t_sCInvoice.Creditor_ID       <> ?)                                     or
     can-find(first t_sCInvoiceBank where
                    t_sCInvoiceBank.tc_ParentRowid = t_sCInvoice.tc_Rowid and
                   (t_sCInvoiceBank.tc_Status = 'C' or 
                    t_sCInvoiceBank.tc_Status = 'N'))                   
then do:
    if t_sCInvoice.CInvoiceTSMNumber <> "":U and
       t_sCInvoice.CInvoiceTSMNumber <> ?
    then do:
        <Q-10 run CreditorByCreditorCountry (all) (Read) (NoCache)
           (input ?, (CompanyId)
            input t_sCInvoice.Creditor_ID, (CreditorId)
            input ?, (CreditorCode)
            input ?, (AddressTypeCode)
            input iiHOAddressTypeId, (AddressTypeId)
            output dataset tqCreditorByCreditorCountry) in BCreditor >
        find first tqCreditorByCreditorCountry where
                   tqCreditorByCreditorCountry.tiCreditor_ID    = t_sCInvoice.Creditor_ID and
                   tqCreditorByCreditorCountry.tiAddressType_ID = iiHOAddressTypeId  
                   no-error.    
        if not available tqCreditorByCreditorCountry
        then do:
            <M-3 run SetMessage
               (input  trim(#T-6'A head office address was not defined for supplier $1.':255(65466)t-6#) (icMessage), 
                input  t_sCInvoice.tcCreditorCode (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sCInvoice.tc_Rowid (icRowid), 
                input  'QadFin-7115':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BCInvoice>
    
            assign oiReturnStatus = -1.
            next.
        end.
    end. /* if t_sCInvoice.CInvoiceTSMNumber <> "":U and */
    
    assign vcPaymentReferenceType = "".
    for each t_sCInvoiceBank where
             t_sCInvoiceBank.CInvoice_ID = t_sCInvoice.CInvoice_ID         and
             t_sCInvoiceBank.tc_Status  <> 'D'
             on error undo, throw:
        /* ========================================================================================== */     
        /* Fill in tcPayFormatTypeCode when it is not filled.                                         */
        /* This can happen when creating invoices using the integration.                              */
        /* ========================================================================================== */
        if (t_sCInvoiceBank.tcPayFormatTypeCode = ? or 
            t_sCInvoiceBank.tcPayFormatTypeCode = '')                     and
            t_sCInvoiceBank.BankNumber_ID      <> 0                       and
            t_sCInvoiceBank.BankNumber_ID      <> ?
        then do:
            <Q-55 run BankNumberForPayFormatBank (all) (Read) (NoCache)
               (input t_sCInvoice.Company_ID, (CompanyId)
                input ?, (ParentObjectID)
                input t_sCInvoiceBank.BankNumber_ID, (BankNumberID)
                output dataset tqBankNumberForPayFormatBank) in BBankNumber>             
            find first tqBankNumberForPayFormatBank where
                       tqBankNumberForPayFormatBank.tiBankNumber_ID = t_sCInvoiceBank.BankNumber_ID 
                       no-lock no-error.
            if available tqBankNumberForPayFormatBank
            then assign t_sCInvoiceBank.tcPayFormatTypeCode  = tqBankNumberForPayFormatBank.tcPayFormatTypeCode. 
        end. /* if (t_sCInvoiceBank.tcPayFormatTypeCode = ? or */
        
        /* =================================================================================================== */
        /* Check if the Payment reference should be of type SEPA (At least one payment attribute of type SEPA) */
        /* =================================================================================================== */     
        <Q-39 run PayFormatTypeByType (all) (Read) (Cache)
           (input t_sCInvoiceBank.tcPayFormatTypeCode, (PayFormatTypeCode)
            output dataset tqPayFormatTypeByType) in BPaymentFormat>
        find tqPayFormatTypeByType where
             tqPayFormatTypeByType.tcPayFormatTypeCode   = t_sCInvoiceBank.tcPayFormatTypeCode and
             tqPayFormatTypeByType.tlPayFormatTypeIsSEPA = true
             no-error.
        if available tqPayFormatTypeByType
        then assign vcPaymentReferenceType = {&VALIDATIONTYPE-SEPA}.        
    end. /* for each t_sCInvoiceBank where */

    /* Leave when SEPA and SEPA messages don't need to be shown (Company setting) */            
    if vcPaymentReferenceType = {&VALIDATIONTYPE-SEPA}
    then do:        
        <Q-20 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 = false
        then leave.
    end. /* if vcPaymentReferenceType = {&VALIDATIONTYPE-SEPA} */
    
    if t_sCInvoice.CInvoiceTSMNumber <> "":U and
       t_sCInvoice.CInvoiceTSMNumber <> ?
    then do:                         
        assign vhFcComponent = if bhTTSM = ? or
                                  not valid-handle(bhTTSM)
                               then ?
                               else bhTTSM.
    
        <M-88 run ValidateTSMNumber
           (input  t_sCInvoice.CInvoiceTSMNumber (icTSMNumber), 
            input  vcPaymentReferenceType (icValidationType), 
            input  tqCreditorByCreditorCountry.tiCountry_ID (iiCountryId), 
            input  tqCreditorByCreditorCountry.tcCountryCode (icCountryCode), 
            input  viSessionID (iiSessionId), 
            output vcMessage (ocErrorMessage), 
            output viFcReturnSuper (oiReturnStatus)) in TTSM>
        
        assign bhTTSM = vhFcComponent.

        if viFcReturnSuper <> 0 and oiReturnStatus >= 0
        then assign oiReturnStatus = viFcReturnSuper.            
    
        if viFcReturnSuper < 0
        then do:
            <M-5 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tCInvoice.CInvoiceTSMNumber':U (icFieldName), 
                input  t_sCInvoice.CInvoiceTSMNumber (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sCInvoice.tc_Rowid (icRowid), 
                input  'QadFin-7116':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BCInvoice>        
        end. /* if viFcReturnSuper < 0 */
        else if viFcReturnSuper > 0
             then do:
                <M-96 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tCInvoice.CInvoiceTSMNumber':U (icFieldName), 
                    input  t_sCInvoice.CInvoiceTSMNumber (icFieldValue), 
                    input  'W':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sCInvoice.tc_Rowid (icRowid), 
                    input  'qadfin-174656':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BCInvoice>                 
             end. /* if viFcReturnSuper > 0 */
    end. /*     if t_sCInvoice.CInvoiceTSMNumber <> "":U and */
    else do:
        if vcPaymentReferenceType = {&VALIDATIONTYPE-SEPA}
        then do:
            assign vcMessage = #T-53'This invoice uses a SEPA payment format, but no payment reference was entered.':255(990850269)T-53#.
            <M-48 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tCInvoice.CInvoiceTSMNumber':U (icFieldName), 
                input  t_sCInvoice.CInvoiceTSMNumber (icFieldValue), 
                input  'W':U (icType), 
                input  3 (iiSeverity), 
                input  t_sCInvoice.tc_Rowid (icRowid), 
                input  'qadfin-719295':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BCInvoice>                             
            if oiReturnStatus >= 0
            then assign oiReturnStatus = 1.       
        end. /* if vcPaymentReferenceType = {&VALIDATIONTYPE-SEPA} */
    end. /* else do: (empty TSM Number) */
end.