project QadFinancials > class BBankNumber > method GetParentBankData


Parameters


iiCompanyIDinputinteger
icCreditorCodeinputcharacter
icDebtorCodeinputcharacter
icPaymentInstrumentinputcharacter
oiBankNumberIDoutputinteger
ocBankNumberoutputcharacter
ocBankNumberExtensionoutputcharacter
icOwnBankNumberinputcharacter
icGLCodeinputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BCDocument.DataLoadByInput
method BDDocument.ApiStdMaintainTT
method BDDocument.DataLoadByInput
method BDInvoice.ApiCreateDInvoicesFinCharge
method BDInvoice.ApiStdMaintainTTWithIntPost
method BDInvoice.StdMaintainTTWithIntPost
method BOpenItemAdjustment.OIAdjCommitSubCInvoice
method BOpenItemAdjustment.OIAdjCommitSubDInvoice


program code (program3/bbanknumber.p)

assign oiReturnStatus = -98
       viLocalReturn  = 0.

MAIN_BLOCK:
do on error undo, leave:
    /* Default values output parameter */
    assign oiBankNumberID        = 0
           ocBankNumber          = ?
           ocBankNumberExtension = ?.    
    
    /* Normalize input parameters */
    if icCreditorCode      = "":U then icCreditorCode      = ?.
    if icDebtorCode        = "":U then icDebtorCode        = ?.
    if icPaymentInstrument = "":U then icPaymentInstrument = ?.


    /* Type of bank account Customer/Supplier */
    assign vcParentType = (if icCreditorCode <> ?
                              then {&BANKNUMBERPARENTTYPE-CREDITOR}
                              else {&BANKNUMBERPARENTTYPE-DEBTOR}).


    /* Check the type of the payment INLAND/FOREIGN */
    if icPaymentInstrument <> ?
    then do:
        assign vcPayFormatTypePayType = {&PAYFORMATPAYTYPE-FOREIGN}.

        /* Retrieve creditor or debtor's country code to determine if payment is inland or foreign*/
        if vcParentType = {&BANKNUMBERPARENTTYPE-CREDITOR}
        then do:
            <Q-84 run CreditorAddressInfoByCreditor (all) (Read) (NoCache)
               (input ?, (CreditorId)
                input iiCompanyID, (CompanyId)
                input icCreditorCode, (CreditorCode)
                input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
                output dataset tqCreditorAddressInfoByCreditor) in BCreditor >
              for first tqCreditorAddressInfoByCreditor:
                assign vcCountryCode = tqCreditorAddressInfoByCreditor.tcCountryCode.
              end.
        end. /*if(icCreditorCode <> ?) */
        else do:
            <Q-53 run DebtorByDebtor (all) (Read) (NoCache)
               (input iiCompanyID, (CompanyId)
                input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
                input ?, (DebtorId)
                input icDebtorCode, (DebtorCode)
                output dataset tqDebtorByDebtor) in BDebtor >
            for first tqDebtorByDebtor:
                assign vcCountryCode = tqDebtorByDebtor.tcCountryCode.
            end.
        end. /* else do */
        
        /* Retrieve own company's country code to determine if payment is within the same country (inland) */
        <Q-30 run CompanyPropertyByBusinessRel (all) (Read) (NoCache)
           (input iiCompanyID, (CompanyId)
            input {&ADDRESSTYPECODESYSTEM-HEADOFFICE}, (AddressType)
            output dataset tqCompanyPropertyByBusinessRel) in BCompanyProperty >
        for first tqCompanyPropertyByBusinessRel:
            assign vlInland               = (tqCompanyPropertyByBusinessRel.tcAddressCountryCode = vcCountryCode)
                   vcPayFormatTypePayType = {&PAYFORMATPAYTYPE-INLAND}.
        end.
    end. /* Check the type of the payment INLAND/FOREIGN */

    /* Get Supplier's bank numbers */
    if vcParentType = {&BANKNUMBERPARENTTYPE-CREDITOR}
    then do:
        <Q-64 run CreditorForBankNumber (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            input ?, (Creditor_ID)
            input icCreditorCode, (CreditorCode)
            output dataset tqCreditorForBankNumber) in BCreditor >

        if icPaymentInstrument <> ?
        then do:
             
            /* Determine if there is only one bank which matches criteria */
            find tqCreditorForBankNumber where
                 tqCreditorForBankNumber.tcPayFormatTypePayInstrument = icPaymentInstrument        and
                 (tqCreditorForBankNumber.tcPayFormatTypePayType      = vcPayFormatTypePayType or
                  tqCreditorForBankNumber.tcPayFormatTypePayType      = {&PAYFORMATPAYTYPE-BOTH}) and
                 tqCreditorForBankNumber.tiCompany_ID                 = iiCompanyID
                 no-error.
        
            /* Determine if there is a company specific default bank which matches the criteria */
            if not available tqCreditorForBankNumber
            then find first tqCreditorForBankNumber where
                            tqCreditorForBankNumber.tcPayFormatTypePayInstrument = icPaymentInstrument       and
                            (tqCreditorForBankNumber.tcPayFormatTypePayType      = vcPayFormatTypePayType or
                             tqCreditorForBankNumber.tcPayFormatTypePayType      = {&PAYFORMATPAYTYPE-BOTH}) and
                            tqCreditorForBankNumber.tlBankNumberIsDefault                                    and
                            tqCreditorForBankNumber.tiCompany_ID                 = iiCompanyID
                            no-error.

            /* Determine if any bank matches the criteria but is not in this company (cross company payment) */
            if not available tqCreditorForBankNumber
            then find first tqCreditorForBankNumber  where
                            tqCreditorForBankNumber.tcPayFormatTypePayInstrument = icPaymentInstrument       and
                            (tqCreditorForBankNumber.tcPayFormatTypePayType      = vcPayFormatTypePayType or
                             tqCreditorForBankNumber.tcPayFormatTypePayType      = {&PAYFORMATPAYTYPE-BOTH})
                            no-error.
            
        end. /* if(icPaymentInstrument <> ?) */
        
        /* Use default bank for this company if no banks match the criteria, or payment instrument not specified */
        if not available tqCreditorForBankNumber
        then find first tqCreditorForBankNumber  where
                        tqCreditorForBankNumber.tlBankNumberIsDefault and
                        tqCreditorForBankNumber.tiCompany_ID = iiCompanyID
                        no-error.
        
        /* Use any default bank (assumes a cross company payment) */
        if not available tqCreditorForBankNumber
        then find first tqCreditorForBankNumber  where
                        tqCreditorForBankNumber.tlBankNumberIsDefault
                        no-error.
        
        if available tqCreditorForBankNumber
        then assign oiBankNumberID        = tqCreditorForBankNumber.tiBankNumber_ID
                    ocBankNumber          = tqCreditorForBankNumber.tcBankNumber
                    ocBankNumberExtension = tqCreditorForBankNumber.tcBankNumberExtension.
    end. /* if vcParentType = {&BANKNUMBERPARENTTYPE-CREDITOR} */
    
    /* Get Customers's bank numbers */
    else do:

        <Q-18 run DebtorForBankNumber (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            input ?, (DebtorID)
            input icDebtorCode, (DebtorCode)
            output dataset tqDebtorForBankNumber) in BDebtor >

        if icPaymentInstrument <> ?
        then do:
            
            /* Determine if there is only one bank which matches criteria */
             find tqDebtorForBankNumber where
                  tqDebtorForBankNumber.tcPayFormatTypePayInstrument = icPaymentInstrument       and
                 (tqDebtorForBankNumber.tcPayFormatTypePayType      = vcPayFormatTypePayType or
                  tqDebtorForBankNumber.tcPayFormatTypePayType      = {&PAYFORMATPAYTYPE-BOTH})  and
                  tqDebtorForBankNumber.tiCompany_ID                 = iiCompanyID               and
                 (if icOwnBankNumber <> ? and icOwnBankNumber <> "":U
                  then tqDebtorForBankNumber.tcOwnBankNumber = icOwnBankNumber
                  else true)                                                                     and
                 (if icGLCode <> ? and icGLCode <> "":U
                  then tqDebtorForBankNumber.tcGLCode = icGLCode
                  else true)    no-error.
            
            /* Determine if there is a company specific default bank which matches the criteria */
            if not available tqDebtorForBankNumber
            then find first tqDebtorForBankNumber where
                            tqDebtorForBankNumber.tcPayFormatTypePayInstrument = icPaymentInstrument       and
                            (tqDebtorForBankNumber.tcPayFormatTypePayType      = vcPayFormatTypePayType or
                             tqDebtorForBankNumber.tcPayFormatTypePayType      = {&PAYFORMATPAYTYPE-BOTH}) and
                            tqDebtorForBankNumber.tlBankNumberIsDefault                                    and
                            tqDebtorForBankNumber.tiCompany_ID                 = iiCompanyID
                            no-error.
                    
            /* Determine if any bank matches the criteria but is not in this company (cross company payment) */
            if not available tqDebtorForBankNumber
            then find first tqDebtorForBankNumber  where
                            tqDebtorForBankNumber.tcPayFormatTypePayInstrument = icPaymentInstrument       and
                            (tqDebtorForBankNumber.tcPayFormatTypePayType      = vcPayFormatTypePayType or
                             tqDebtorForBankNumber.tcPayFormatTypePayType      = {&PAYFORMATPAYTYPE-BOTH})
                            no-error.
                    end. /* if(icPaymentInstrument <> ?) */
        
        /* Use default bank for this company if no banks match the criteria, or payment instrument not specified */
        if not available tqDebtorForBankNumber
        then find first tqDebtorForBankNumber  where
                        tqDebtorForBankNumber.tlBankNumberIsDefault and
                        tqDebtorForBankNumber.tiCompany_ID = iiCompanyID
                        no-error.
                
        /* Use any default bank (assumes a cross company payment) */
        if not available tqDebtorForBankNumber
        then find first tqDebtorForBankNumber  where
                        tqDebtorForBankNumber.tlBankNumberIsDefault
                        no-error.
                
        if available tqDebtorForBankNumber
        then assign oiBankNumberID        = tqDebtorForBankNumber.tiBankNumber_ID
                    ocBankNumber          = tqDebtorForBankNumber.tcBankNumber
                    ocBankNumberExtension = tqDebtorForBankNumber.tcBankNumberExtension.

        
    end.
end. /* MAIN_BLOCK */

assign oiReturnStatus = viLocalReturn.