project QadFinancials > class BBankImportLine > method GetDebtorByBankImpLine

Description

This method get the debtor based on the information of Bank Import Line.


Parameters


ilIsClearErrMsginputlogical
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankImportLine.ProcessBankImpLineDDocStatusChg
method BBankImportLine.ProcessBankImpLineNewBankEntry
method BBankImportLine.ProcessBankImpLineNewDDocument


program code (program6/bbankimportline.p)

/* =================================================================================================== */
/* Method      : GetDebtorByBankImpLine                                                                */
/* Desc        : This method get the debtor based on the information of BankImpLine                    */
/*               !!! This method has to be in the same segment as parent methods (expects correct      */
/*                   record in table tBankImpLine)  - segment 6                                        */
/* --------------------------------------------------------------------------------------------------- */
/* Params:  (I)  Name                 Description                                                      */
/*          (O)  Name                 Description                                                      */
/* =================================================================================================== */
/* The search is a cascaded search of                                                                  */
/* Try 1 : By DebtorCode                                                                               */
/* Try 2 : By Bank Number                                                                              */
/* Try 3 : By business relation remittance address                                                     */
/* Try 4 : By Invoice reference list                                                                   */
/* Try 5 : By Debtor name and Address                                                                  */
/* Try 6 : By DebtorName                                                                               */
/* =================================================================================================== */

/* =================================================================================================== */
/* if using custom matching logic, then return directly without executing standard matching logic.     */
/* =================================================================================================== */
if vlUseCustomMatching = yes
then return.

if ilIsClearErrMsg = ? then assign ilIsClearErrMsg = false.

assign oiReturnStatus = -98
       vlQAddStarted  = false
       vlDebtorCodeIsOK = false
       vcParam = '':U
       vcCriteria = '':U.

/* =================================================================================================== */
/* Validate input parameters                                                                           */
/* =================================================================================================== */
if not available tBankImpLine
then do:
    assign vcMessage = trim(#T-2'Missing definition of imported bank line.':255(67965)T-2#).
    <M-1 run SetMessage
       (input  vcMessage (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'S':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'QadFin-7557':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    assign oiReturnStatus = -1.
    return.
end.

/* =================================================================================================== */
/* Preconditions                                                                                       */
/* =================================================================================================== */
if tBankImpLine.Debtor_ID = 0 then assign tBankImpLine.Debtor_ID = ?.

/* If debtor is known, there is not need to lookup it again */
if tBankImpLine.Debtor_ID <> ? and (tBankImpLine.BankImpLineDebtorCode = "":U or tBankImpLine.BankImpLineDebtorCode = ?)
then do:
    assign oiReturnStatus = 0.
    return.
end.

/* =================================================================================================== */
/* Get Debtor by the information in the Bank Import Line                                               */
/* =================================================================================================== */
/* Try 1 : Get Debtor by Code */
if tBankImpLine.BankImpLineDebtorCode <> "":U and 
   tBankImpLine.BankImpLineDebtorCode <> ?
then do:
    <Q-5 run DebtorByCode (all) (Read) (NoCache)
       (input ?, (CompanyId)
        input tBankImpLine.BankImpLineDebtorCode, (DebtorCode)
        output dataset tqDebtorByCode) in BDebtor >
    find first tqDebtorByCode no-error.
    if available tqDebtorByCode
    then do:
        assign tBankImpLine.Debtor_ID = tqDebtorByCode.tiDebtor_ID
                vlDebtorCodeIsOK       = true.

        /* Create Processing Info */
        assign vcParam = "DebtorCode = " + tqDebtorByCode.tcDebtorCode
               vcCriteria = "BankImpLineDebtorCode = " + tBankImpLine.BankImpLineDebtorCode.
        <M-73 run CreateBankImpLineProcessInfo
           (input  'DebtorByCode':U (icProcessName), 
            input  #T-31'Get customer info':255(989613730)T-31# (icProcessDesc), 
            input  vcParam (icProcessResult), 
            input  vcCriteria (icProcessParam), 
            input  'GetDebtorByBankImpLine':U (icParentRowName), 
            input  0 (iiProcessStatus), 
            output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    end.
end. /* if tBankImpLine.BankImpLineDebtorCode <> "":U and tBankImpLine.BankImpLineDebtorCode <> ? */

/* Try 2 : Get Debtor by it's bank Account */
if tBankImpLine.Debtor_ID              = ?    and
   tBankImpLine.BankImpLineBankNumber <> "":U and 
   tBankImpLine.BankImpLineBankNumber <> ?
then do:
    /* Create Processing Info */
    <M-54 run CreateBankImpLineProcessInfo
       (input  'GetBankNumberByNumber':U (icProcessName), 
        input  #T-77'Get customer info':255(989613730)T-77# (icProcessDesc), 
        input  ? (icProcessResult), 
        input  ? (icProcessParam), 
        input  'GetDebtorByBankImpLine':U (icParentRowName), 
        input  0 (iiProcessStatus), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>

    <M-24 run GetBankNumberByNumber
       (input  {&BANKNUMBERPARENTTYPE-DEBTOR} (icBankNumberParentType), 
        input  tBankImpLine.BankImpLineBankNumber (icBankNumber), 
        output viDummy (oiBankNumberId), 
        output vcDummy (ocBankNumber), 
        output viDebtor_ID (oiParentObjectId), 
        output vcDummy (ocParentObjectCode), 
        output viDummy (oiCurrencyId), 
        output vcDummy (ocCurrencyCode), 
        output viTransactionCompanyId (oiTransactionCompanyId), 
        input  ? (icBankImpCurrencyCode), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
     
    if viDebtor_ID <> ? and viDebtor_ID <> 0
    then do:
        assign tBankImpLine.Debtor_ID = viDebtor_ID.
    end.

    <M-36 run UpdateBankImpLineProcessResult
       (input  'GetBankNumberByNumber':U (icProcessName), 
        input  viFcReturnSuper (iiProcessStatus), 
        input  ? (icProcessResult), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>

end. /* if tBankImpLine.BankImpLineBankNumber <> "":U and tBankImpLine.BankImpLineBankNumber <> ? */

/* Try 3 : Get Debtor by it's business relation remittance address */
if tBankImpLine.Debtor_ID              = ? and
   ((tBankImpLine.BankImpLineDebtorCode <> "":U and tBankImpLine.BankImpLineDebtorCode <> ?) or
    (tBankImpLine.BankImpLineDebtorName <> "":U and tBankImpLine.BankImpLineDebtorName <> ?))
then do:
    if not vlQAddStarted
    then do:
        <Q-25 run AddressForDebtor  (Start) in BBusinessRelation >
        assign vlQAddStarted = true.
    end.

    <Q-8 run AddressForDebtor (all) (Read) (NoCache)
       (input {&ADDRESSTYPECODESYSTEM-REMITTANCE}, (AddressTypeCode)
        input ?, (CompanyId)
        input tBankImpLine.BankImpLineDebtorName, (AddressName)
        input tBankImpLine.BankImpLineDebtorCode, (AddressSearchName)
        input ?, (AddressLine)
        input ?, (AddressCity)
        input ?, (AddressZip)
        input ?, (AddressCountry)
        input ?, (BusinessRelationName1)
        output dataset tqAddressForDebtor) in BBusinessRelation >

    find first tqAddressForDebtor no-error.
    if available tqAddressForDebtor
    then do:
        assign tBankImpLine.Debtor_ID = tqAddressForDebtor.tiDebtor_ID.

        /* Create Processing Info */
        assign vcParam = "DebtorCode = " + tqAddressForDebtor.tcDebtorCode
               vcCriteria = "AddressTypeCode = " + {&ADDRESSTYPECODESYSTEM-REMITTANCE} + 
                            ";AddressName = " + tBankImpLine.BankImpLineDebtorName + 
                            ";AddressSearchName = " + tBankImpLine.BankImpLineDebtorCode.
        <M-38 run CreateBankImpLineProcessInfo
           (input  'AddressForDebtor':U (icProcessName), 
            input  #T-52'Get customer info':255(989613730)T-52# (icProcessDesc), 
            input  vcParam (icProcessResult), 
            input  vcCriteria (icProcessParam), 
            input  'GetDebtorByBankImpLine':U (icParentRowName), 
            input  0 (iiProcessStatus), 
            output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    end.
end. /* if (tBankImpLine.BankImpLineDebtorCode <> "":U and tBankImpLine.BankImpLineDebtorCode <> ?) or */

/* Try 4 : Get Debtor by invoice reference list */
if tBankImpLine.Debtor_ID              = ?    and
   tBankImpLine.BankImpLineInvRefList <> "":U and 
   tBankImpLine.BankImpLineInvRefList <> ?
then do:
    <Q-23 run DInvoiceByDebtorRef (all) (Read) (NoCache)
       (input ?, (CompanyId)
        input ?, (DebtorId)
        input tBankImpLine.BankImpLineInvRefList, (DInvoiceRefList)
        input ?, (DInvoiceIsOpen)
        input ?, (DebitTCAmount)
        input ?, (BankNumberId)
        input ?, (CurrencyId)
        input ?, (Voucher)
        input ?, (DInvoiceTSMNumber)
        output dataset tqDInvoiceByDebtorRef) in BDInvoice>
        
    find first tqDInvoiceByDebtorRef no-error.
    if available tqDInvoiceByDebtorRef
    then do:
        assign tBankImpLine.Debtor_ID = tqDInvoiceByDebtorRef.tiDebtor_ID.
    
        /* Create Processing Info */
        assign vcParam = "DebtorCode = " + tqDInvoiceByDebtorRef.tcDebtorCode
               vcCriteria = "DInvoiceRefList = " + tBankImpLine.BankImpLineInvRefList.
        <M-65 run CreateBankImpLineProcessInfo
           (input  'DInvoiceByDebtorRef':U (icProcessName), 
            input  #T-80'Get customer info':255(989613730)T-80# (icProcessDesc), 
            input  vcParam (icProcessResult), 
            input  vcCriteria (icProcessParam), 
            input  'GetDebtorByBankImpLine':U (icParentRowName), 
            input  0 (iiProcessStatus), 
            output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    end.
end. /* if tBankImpLine.BankImpLinePaymentRef <> "":U and tBankImpLine.BankImpLinePaymentRef <> ? */

/* Try 5 : Get debtor by Debtor name and Address */
if tBankImpLine.Debtor_ID              = ? and
   ((tBankImpLine.BankImpLineDebtorName      <> "":U and tBankImpLine.BankImpLineDebtorName     <> ?) or
    (tBankImpLine.BankImpLineAddressCity     <> "":U and tBankImpLine.BankImpLineAddressCity    <> ?) or
    (tBankImpLine.BankImpLineAddressCountry  <> "":U and tBankImpLine.BankImpLineAddressCountry <> ?) or
    (tBankImpLine.BankImpLineAddressLine     <> "":U and tBankImpLine.BankImpLineAddressLine    <> ?) or
    (tBankImpLine.BankImpLineAddressZip      <> "":U and tBankImpLine.BankImpLineAddressZip     <> ?))
then do:
    if not vlQAddStarted
    then do:
        <Q-16 run AddressForDebtor  (Start) in BBusinessRelation >
        assign vlQAddStarted = true.
    end.
    <Q-12 run AddressForDebtor (all) (Read) (NoCache)
       (input ?, (AddressTypeCode)
        input ?, (CompanyId)
        input ?, (AddressName)
        input ?, (AddressSearchName)
        input tBankImpLine.BankImpLineAddressLine, (AddressLine)
        input tBankImpLine.BankImpLineAddressCity, (AddressCity)
        input tBankImpLine.BankImpLineAddressZip, (AddressZip)
        input tBankImpLine.BankImpLineAddressCountry, (AddressCountry)
        input tBankImpLine.BankImpLineDebtorName, (BusinessRelationName1)
        output dataset tqAddressForDebtor) in BBusinessRelation >

    find first tqAddressForDebtor no-error.
    if available tqAddressForDebtor
    then do:
        assign tBankImpLine.Debtor_ID = tqAddressForDebtor.tiDebtor_ID.

        /* Create Processing Info */
        assign vcParam = "DebtorCode = " + tqAddressForDebtor.tcDebtorCode
               vcCriteria = "AddressLine = " + tBankImpLine.BankImpLineAddressLine +
                            ";AddressCity = " + tBankImpLine.BankImpLineAddressCity +
                            ";AddressZip = " + tBankImpLine.BankImpLineAddressZip +
                            ";AddressCountry = " + tBankImpLine.BankImpLineAddressCountry +
                            ";BusinessRelationName = " + tBankImpLine.BankImpLineDebtorName.
        <M-34 run CreateBankImpLineProcessInfo
           (input  'AddressForDebtor':U (icProcessName), 
            input  #T-71'Get customer info':255(989613730)T-71# (icProcessDesc), 
            input  vcParam (icProcessResult), 
            input  vcCriteria (icProcessParam), 
            input  'GetDebtorByBankImpLine':U (icParentRowName), 
            input  0 (iiProcessStatus), 
            output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    end.
end. /* if (tBankImpLine.BankImpLineDebtorName      <> "":U and tBankImpLine.BankImpLineDebtorName     <> ?) or */

/* Try 6 : Get debtor by debtor name */
if tBankImpLine.Debtor_ID              = ?    and
   tBankImpLine.BankImpLineDebtorName <> "":U and 
   tBankImpLine.BankImpLineDebtorName <> ?
then do:
    if not vlQAddStarted
    then do:
        <Q-17 run AddressForDebtor  (Start) in BBusinessRelation >
        assign vlQAddStarted = true.
    end.
    <Q-13 run AddressForDebtor (all) (Read) (NoCache)
       (input ?, (AddressTypeCode)
        input ?, (CompanyId)
        input ?, (AddressName)
        input ?, (AddressSearchName)
        input ?, (AddressLine)
        input ?, (AddressCity)
        input ?, (AddressZip)
        input ?, (AddressCountry)
        input tBankImpLine.BankImpLineDebtorName, (BusinessRelationName1)
        output dataset tqAddressForDebtor) in BBusinessRelation >

    find first tqAddressForDebtor no-error.
    if available tqAddressForDebtor
    then do:
        assign tBankImpLine.Debtor_ID = tqAddressForDebtor.tiDebtor_ID.
               
        /* Create Processing Info */
        assign vcParam = "DebtorCode = " + tqAddressForDebtor.tcDebtorCode
               vcCriteria = "BusinessRelationName = " + tBankImpLine.BankImpLineDebtorName.
        <M-44 run CreateBankImpLineProcessInfo
           (input  'AddressForDebtor':U (icProcessName), 
            input  #T-82'Get customer info':255(989613730)T-82# (icProcessDesc), 
            input  vcParam (icProcessResult), 
            input  vcCriteria (icProcessParam), 
            input  'GetDebtorByBankImpLine':U (icParentRowName), 
            input  0 (iiProcessStatus), 
            output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    end.
end. /* if tBankImpLine.BankImpLineDebtorName      <> "":U and tBankImpLine.BankImpLineDebtorName <> ? */ 

/* Stop started queries */
if vlQAddStarted
then do:
    <Q-27 run AddressForDebtor  (Stop) in BBusinessRelation >
end.

/* =========================================================== */
/*  Get the BankImpLineDebtorCode if it is still not filled in */
/* =========================================================== */
if tBankImpLine.Debtor_ID <> 0 and tBankImpLine.Debtor_ID <> ? and vlDebtorCodeIsOK = false   
then do:
    <Q-28 run DebtorPrim (all) (Read) (NoCache)
       (input ?, (CompanyId)
        input '':U, (DebtorCode)
        input tBankImpLine.Debtor_ID, (Debtor_ID)
        output dataset tqDebtorPrim) in BDebtor>

    find first tqDebtorPrim no-error.
    if available tqDebtorPrim
    then do:
        assign tBankImpLine.BankImpLineDebtorCode = tqDebtorPrim.tcDebtorCode.

        /* Create Processing Info */
        assign vcParam = "DebtorCode = " + tqDebtorPrim.tcDebtorCode
               vcCriteria = "Debtor_ID = " + string(tBankImpLine.Debtor_ID).
        <M-20 run CreateBankImpLineProcessInfo
           (input  'DebtorPrim':U (icProcessName), 
            input  #T-6'Get customer info':255(989613730)T-6# (icProcessDesc), 
            input  vcParam (icProcessResult), 
            input  vcCriteria (icProcessParam), 
            input  'GetDebtorByBankImpLine':U (icParentRowName), 
            input  0 (iiProcessStatus), 
            output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    end.
end.

/* ========================================= */
/* If debtor has not been found, report this */
/* ========================================= */
if tBankImpLine.Debtor_ID = ?
then do:
    if not ilIsClearErrMsg then
    do:
        assign vcMessage = trim(substitute(#T-21'The customer with code (&1) cannot be found. You can manually select a different customer.':255(68525)T-21#,
                                       trim(tBankImpLine.BankImpLineDebtorCode))).
        <M-22 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tBankImpLine.BankImpLineDebtorCode':U (icFieldName), 
            input  tBankImpLine.BankImpLineDebtorCode (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-7573':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    end.
    assign oiReturnStatus = -1.
    return.
end.    

/* =================================================================================================== */
/* Return                                                                                              */
/* =================================================================================================== */
if oiReturnStatus = -98 then assign oiReturnStatus = 0.