project QadFinancials > class BBankImportLine > method ProcessBankImpLineNewDDocument

Description

This method creates new customer document.


Parameters


ilIncludeAllEntitiesinputlogicalInclude All Entities
ilCreatedToPaidinputlogicalwhether to pay document
ilCreateBankEntryinputlogicalwhether to create banking entry
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankImportLine.ProcessBankImpLineAction


program code (program6/bbankimportline.p)

/* =================================================================================================== */
/* Method      : ProcessBankImpLineActionNewDDocument                                                  */
/* Desc        : This method creates new customer document                                             */
/*               !!! 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                                                      */
/* =================================================================================================== */
assign oiReturnStatus                = -98
       vcParam                       = '':U
       vcCriteira                    = '':U
       vcPayConfPIBFNoCustomerAction = {&PAYCONFNOCUSTOMERACT-ERROR}
       vcNoInvoiceAction             = {&PAYCONFNOINVOICEACT-CREATE-INIT-PAY}
       vdBankImpLinePaymentTC        = 0
       viCreateBEReturn              = 0
       vlIsCreatePrepayment          = no
       vlIsCreateUnallocatedBE       = no
       vlIsCreateInitialPayment      = no.
empty temp-table tInvoiceXref.

/* =================================================================================================== */
/* 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-7546':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    assign oiReturnStatus = -1.
    return.
end.
assign viLocalReturn = 0.

CREATE_DDOCUMENT:
do:
    if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.
    if viFcReturnSuper < 0  then leave CREATE_DDOCUMENT.
    
    if tBankImpLine.Debtor_ID <> 0
    then do:
        for each tBankImpLineDet:
            assign tBankImpLineDet.Debtor_ID = tBankImpLine.Debtor_ID.
        end.
    end.  
    
    /* =================================================================================================== */
    /* Get the currency of the Payment base on the Bank Import Line information                            */
    /* =================================================================================================== */
    <M-96 run CreateBankImpLineProcessInfo
       (input  'GetCurrencyByBankImpLine':U (icProcessName), 
        input  #T-85'Get payment currency':255(622508872)T-85# (icProcessDesc), 
        input  ? (icProcessResult), 
        input  ? (icProcessParam), 
        input  'ProcessBankImpLineNewDDocument':U (icParentRowName), 
        input  0 (iiProcessStatus), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>

    <M-85 run GetCurrencyByBankImpLine
       (output vilCurrencyId (oiCurrencyId), 
        output vclCurrencyCode (ocCurrencyCode), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.

    <M-69 run UpdateBankImpLineProcessResult
       (input  'GetCurrencyByBankImpLine':U (icProcessName), 
        input  viLocalReturn (iiProcessStatus), 
        input  ? (icProcessResult), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    if viLocalReturn < 0  then leave CREATE_DDOCUMENT.
    
    /* =================================================================================================== */
    /* Get the own banknumber and PayformatType base on the Bank Import Line information                   */
    /* =================================================================================================== */
    <M-59 run CreateBankImpLineProcessInfo
       (input  'GetOwnBankNumberByBankImpLine':U (icProcessName), 
        input  #T-62'Get own bank number and payment format type':255(932355768)T-62# (icProcessDesc), 
        input  ? (icProcessResult), 
        input  ? (icProcessParam), 
        input  'ProcessBankImpLineNewDDocument':U (icParentRowName), 
        input  0 (iiProcessStatus), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>

    <M-19 run GetOwnBankNumberByBankImpLine
       (output tBankImpLine.tiOwnBankNumber_ID (oiBankNumberId), 
        output vcOwnBankNumber (ocBankNumberNumber), 
        output viDummy (oiGLId), 
        output vcBankGLCode (ocGLCode), 
        output viDummy (oiBankPaymentFormatId), 
        output vcPayFormatTypeCode (ocPaymentFormatCode), 
        output viDummy (oiCurrencyId), 
        output vcDummy (ocCurrencyCode), 
        output viTransactionCompanyID (oiTransactionCompanyId), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.
    
    <M-505 run UpdateBankImpLineProcessResult
       (input  'GetOwnBankNumberByBankImpLine':U (icProcessName), 
        input  viLocalReturn (iiProcessStatus), 
        input  ? (icProcessResult), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>

    if viLocalReturn < 0  then leave CREATE_DDOCUMENT.

    /* =================================================================================================== */
    /* Get the PIBF Configuration properties                                                               */
    /* =================================================================================================== */  
    if tBankImpLine.tiOwnBankNumber_ID <> 0 and 
        tBankImpLine.tiOwnBankNumber_ID <> ? 
    then do: 
        <Q-32 run PAYConfByBankNumberID (all) (Read) (NoCache)
           (input viCompanyId, (CompanyId)
            input tBankImpLine.tiOwnBankNumber_ID, (BankNumberId)
            output dataset tqPayConfByBankNumberID) in BPayConf>

        find first tqPayConfByBankNumberID no-error.
        if available tqPayConfByBankNumberID
        then assign vcPayConfPIBFNoCustomerAction = tqPayConfByBankNumberID.tcPayConfPIBFNoCustomerAction
                    vcNoInvoiceAction       = tqPayConfByBankNumberID.tcPayConfPIBFNoInvoiceAction.
    end.

    /* =================================================================================================== */
    /* Accumulate invoice detail amount as payment amount and then create BE or DDocument header with it.  */
    /* =================================================================================================== */
    for each tBankImpLineDet no-lock:
        assign vdBankImpLinePaymentTC = vdBankImpLinePaymentTC + tBankImpLineDet.BankImpLineAmountTC.
    end.

    /* =================================================================================================== */
    /* Get the Debtor base on the Bank Import Line information                                             */
    /* =================================================================================================== */   
    /* Create processing info */
    <M-94 run CreateBankImpLineProcessInfo
       (input  'GetDebtorByBankImpLine':U (icProcessName), 
        input  #T-75'Get customer info':255(989613730)T-75# (icProcessDesc), 
        input  ? (icProcessResult), 
        input  ? (icProcessParam), 
        input  'ProcessBankImpLineNewDDocument':U (icParentRowName), 
        input  0 (iiProcessStatus), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>

    <M-89 run GetDebtorByBankImpLine
       (input  if vcPayConfPIBFNoCustomerAction = {&PAYCONFNOCUSTOMERACT-NEW-BE} then yes else no (ilIsClearErrMsg), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
        
    if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.

    <M-30 run UpdateBankImpLineProcessResult
       (input  'GetDebtorByBankImpLine':U (icProcessName), 
        input  viLocalReturn (iiProcessStatus), 
        input  ? (icProcessResult), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    if viLocalReturn < 0  then 
    do:
        if vcPayConfPIBFNoCustomerAction = {&PAYCONFNOCUSTOMERACT-NEW-BE} then
        do:
            /*=========================================================================================== */
            /* Create unallocated banking entry if customer doesn't exist                                 */
            /* ========================================================================================== */   
            assign oiReturnStatus = -98
                   viLocalReturn  = 3
                   viCreateBEReturn = 0.
                   
            <M-25 run CreateBankImpLineProcessInfo
               (input  'CreateUnallocatedBankEntry':U (icProcessName), 
                input  #T-90'Create Unallocated Bank Entry':50(505749338)T-90# (icProcessDesc), 
                input  ? (icProcessResult), 
                input  ? (icProcessParam), 
                input  'ProcessBankImpLineNewDDocument':U (icParentRowName), 
                input  0 (iiProcessStatus), 
                output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>

            <M-81 run CreateUnallocatedBankEntry
               (input  tBankImpLine.BankImpLineBankNumber (icOwnBankNumber), 
                input-output tBankImpLine.tiOwnBankNumber_ID (biOwnBankNumber_ID), 
                input-output vcBankGLCode (bcBankGLCode), 
                input-output tBankImpLine.BankImpLineOrigTransDate (btBankImpLineOrigTransDate), 
                input  tBankImpLine.BankImpLineValueDate (itBankImpLineValueDate), 
                input  tBankImpLine.BankImpLineBatchNbr (iiBankImpLineBatchNbr), 
                input  tBankImpLine.BankImpLine_ID (iiBankImpLine_ID), 
                input  tBankImpLine.BankImpLineStatNumber (icBankImpLineStatNumber), 
                input  tBankImpLine.BankImpLineInfo (icBankImpLineInfo), 
                output tBankImpLine.BankState_ID (oiBankState_ID), 
                input  tBankImpLine.BankImpLineInOut (icBankImpLineInOut), 
                input  tBankImpLine.BankImpLineDescription (icBankImpLineDescription), 
                input  tBankImpLine.BankImpLinePaymentRef (icBankImpLinePaymentRef), 
                input  tBankImpLine.BankImpLineInvRefList (icBankImpLineInvRefList), 
                input  tBankImpLine.BankImpLineDebtorCode (icBankImpLineDebtorCode), 
                input  tBankImpLine.BankImpLineCreditorCode (icBankImpLineCreditorCode), 
                input  vdBankImpLinePaymentTC (idBankImpLineAmountSumTC), 
                input  tBankImpLine.BankImpLineDebtorName (icBankImpLineDebtorName), 
                input  tBankImpLine.BankImpLineAddressLine (icBankImpLineAddressLine), 
                input  tBankImpLine.BankImpLineAddressCity (icBankImpLineAddressCity), 
                input  tBankImpLine.BankImpLineAddressZip (icBankImpLineAddressZip), 
                input  tBankImpLine.BankImpLineAddressCountry (icBankImpLineAddressCountry), 
                input  tBankImpLine.BankImpLineBankNumber (icBankImpLineBankNumber), 
                input  tBankImpLine.BankImpLineOrigAmountTC (idBankImpLineOrigAmountTC), 
                input  tBankImpLine.BankImpLineOrigCurrCode (icBankImpLineOrigCurrCode), 
                input  tBankImpLine.BankImpLineExchangeRate (idBankImpLineExchangeRate), 
                input  tBankImpLine.BankImpLineRateScale (idBankImpLineRateScale), 
                input  tBankImpLine.BankImpLineCost (icBankImpLineCost), 
                input  tBankImpLine.tc_Rowid (icBankImpLineRowID), 
                output vcMessageReference (ocBankingEntryReference), 
                output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
 
            assign viCreateBEReturn = viFcReturnSuper.
            <M-84 run UpdateBankImpLineProcessResult
               (input  'CreateUnallocatedBankEntry':U (icProcessName), 
                input  viCreateBEReturn (iiProcessStatus), 
                input  ? (icProcessResult), 
                output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>

            if viCreateBEReturn <> 0 then assign oiReturnStatus = viCreateBEReturn.
            else do:
                assign tBankImpLine.BankImpLineProcessedStatus = {&BANKIMPPROCSTATUS-PROCESSED-OK}
                       vlIsCreateUnallocatedBE = yes.
            end.
        end.

        leave CREATE_DDOCUMENT.
    end.
    
    if tBankImpLine.Debtor_ID <> 0
    then do:
        for each tBankImpLineDet:
            assign tBankImpLineDet.Debtor_ID = tBankImpLine.Debtor_ID.
        end.
    end.  

    /* =================================================================================================== */
    /* Get the Debtor BankNumber_ID base on the Bank Import Line information                               */
    /* =================================================================================================== */   
    <Q-6 run BankNumberByBankFileFormat (all) (Read) (NoCache)
       (input tBankImpLine.Debtor_ID, (ParentObjectId)
        input tBankImpLine.BankImpLineFileFormatCode, (BankFileFormat)
        input vcOwnBankNumber, (ownBankNumber)
        input {&PAYFORMATMODULE-AR}, (PayFormatTypeModule)
        input viCompanyId, (CompanyId)
        output dataset tqBankNumberByBankFileFormat) in BBankNumber>

    find first tqBankNumberByBankFileFormat no-error.
    if available tqBankNumberByBankFileFormat
    then do:
        /* find first tBankImpLine no-error. */
        assign tBankImpLine.BankImpLineBankNumber = tqBankNumberByBankFileFormat.tcParentBankNumber
               vilDebtorBankNumberId              = tqBankNumberByBankFileFormat.tiParentBankNumber_ID.

        assign vcCriteira = "DebtorCode = " + tBankImpLine.BankImpLineDebtorCode + 
                            ";BankFileFormat = " + tBankImpLine.BankImpLineFileFormatCode + 
                            ";ownBankNumber = " + string(vcOwnBankNumber) + 
                            ";PayFormatTypeModule = " + {&PAYFORMATMODULE-AR}.
        assign vcParam = "BankImpLineBankNumber = " + string(tBankImpLine.BankImpLineBankNumber).
        
        for each tBankImpLineDet:
            assign tBankImpLineDet.BankImpLineBankNumber = tBankImpLine.BankImpLineBankNumber.
        end.
    end.
    else do:
        assign vcMessage = trim(substitute(#T-20'The own bank &1 for payment format &2 is not defined for this customer.':255(68532)T-20#,
                                           tBankImpLine.BankImpLineOwnBankNumber,vcPayFormatTypeCode)).
        <M-21 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  '':U (icRowid), 
            input  'QadFin-7664':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
        assign oiReturnStatus = -1.

    end.

    <M-58 run CreateBankImpLineProcessInfo
       (input  'BankNumberByBankFileFormat':U (icProcessName), 
        input  #T-11'Get customer bank info':255(810157487)T-11# (icProcessDesc), 
        input  if oiReturnStatus = -1 then '':U else vcParam (icProcessResult), 
        input  if oiReturnStatus = -1 then '':U else vcCriteira (icProcessParam), 
        input  'ProcessBankImpLineNewDDocument':U (icParentRowName), 
        input  oiReturnStatus (iiProcessStatus), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    if oiReturnStatus = -1 then return.
    
    /* =================================================================================================== */
    /* Open the communication with BDDocument                                                              */
    /* =================================================================================================== */
    if viBDDocumentBankImpLineID = 0 or viBDDocumentBankImpLineID = ?
    then do:
        <I-15 {bFcStartAndOpenInstance
             &ADD-TO-TRANSACTION = "true"
             &CLASS              = "BDDocument"}>
    end.
    else if not valid-handle(vhBDDocumentBankImpLineInst)
    then do:
         <I-16 {bFcOpenInstance
              &CLASS           = "BDDocument"}>
    end.
    
    <M-74 run SetExternalUniqueIDForSetMessage
       (input  'true' (ilUseExternalUID), 
        output viFcReturnSuper (oiReturnStatus)) in BDDocument>
    /*
    /* =================================================================================================== */
    /* Clear the instance of DDocument before create the heaader                                           */
    /* =================================================================================================== */
    <M-7 run ClearData  (output viFcReturnSuper (oiReturnStatus)) in BDDocument>

    if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.
    if viFcReturnSuper < 0  then leave CREATE_DDOCUMENT.
      */  
    
    /* =================================================================================================== */
    /* Create the DDocument header if no payment for this bank import line exist                           */
    /* =================================================================================================== */
    assign viDDocumentId = tBankImpLine.DDocument_ID.
    if tBankImpLine.BankImpLineBatchNbr <> 0 and
       tBankImpLine.BankImpLineBatchNbr <> ?
    then do:
        assign vcBankImpLineRef = string(tBankImpLine.BankImpLineBatchNbr).
    end.
    else do:
        <Q-39 run GetBankImpByLineID (all) (Read) (NoCache)
           (input tBankImpLine.BankImpLine_ID, (BankImpLineID)
            output dataset tqGetBankImpByLineID) in BBankImportLine >
        find first tqGetBankImpByLineID where
                   tqGetBankImpByLineID.tiBankImpLine_ID = tBankImpLine.BankImpLine_ID
                   no-error.
        if available tqGetBankImpByLineID
        then assign vcBankImpLineRef = tqGetBankImpByLineID.tcBankImpFileName.
    end.
        
    <M-8 run CreateDDocumentHeader
       (input  tBankImpLine.Debtor_ID (iiDebtorId), 
        input  tBankImpLine.BankImpLineDebtorCode (icDebtorCode), 
        input  vilCurrencyId (iiCurrencyId), 
        input  vclCurrencyCode (icCurrencyCode), 
        input  vilDebtorBankNumberId (iiBankNumberId), 
        input  0 (iiGL_ID), 
        input  '' (icGLCode), 
        input  if tBankImpLine.BankImpLineorigTransDate = ? then tBankImpLine.BankImpLineValueDate else tBankImpLine.BankImpLineorigTransDate (itTransactionDate), 
        input  vdBankImpLinePaymentTC (idOriginalDebitTC), 
        input-output viDDocumentId (biDDocumentId), 
        output vcRowId (ocRowId), 
        input-output tBankImpLine.BankImpLinePaymentRef (bcReference), 
        input  tqBankNumberByBankFileFormat.tcPayFormatTypePayInstrument (icDocumentType), 
        input  vcBankImpLineRef (icBankImpLineRef), 
        input  tBankImpLine.tc_rowid (icBankImpLineRowID), 
        output vcMessageReference (ocMessageReference), 
        output viFcReturnSuper (oiReturnStatus)) in BDDocument>

    if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.

    /* Create processing info */
    <M-61 run CreateBankImpLineProcessInfo
       (input  'CreateDDocumentHeader':U (icProcessName), 
        input  #T-72'Get customer payment header':255(130975477)T-72# (icProcessDesc), 
        input  ? (icProcessResult), 
        input  ? (icProcessParam), 
        input  'ProcessBankImpLineNewDDocument':U (icParentRowName), 
        input  viLocalReturn (iiProcessStatus), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    if viLocalReturn < 0  
    then do:
/*
        <M-22 run StopAndCloseExternalInstances
           (input  false (ilIsCloseOnly), 
            output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
*/
        leave CREATE_DDOCUMENT.
    end.
    
    assign tBankImpLine.DDocument_ID = viDDocumentId.

    for each tBankImpLineDet:
        assign tBankImpLineDet.DDocument_ID = tBankImpLine.DDocument_ID.
    end.

    /* =================================================================================================== */
    /* Collect the invoioces base on the Bank Import Line information                                      */
    /* =================================================================================================== */    
    <M-44 run CreateBankImpLineProcessInfo
       (input  'GetInvoicesByBankImpLine':U (icProcessName), 
        input  #T-21'Collect the invoices':255(958281792)T-21# (icProcessDesc), 
        input  ? (icProcessResult), 
        input  ? (icProcessParam), 
        input  'ProcessBankImpLineNewDDocument':U (icParentRowName), 
        input  viLocalReturn (iiProcessStatus), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>

    <M-9 run GetInvoicesByBankImpLine
       (input  ilIncludeAllEntities (ilincludeAllEntities), 
        input  viCompanyId (iiCompanyId), 
        output tInvoiceXref (tInvoiceXref), 
        input  vilDebtorBankNumberId (iiBankNumberId), 
        input  vilCurrencyId (iiCurrencyId), 
        input  vcPayFormatTypeCode (icPaymentFormat), 
        input  tBankImpLine.BankImpLineInvRefList (icBankImpLineInvRefList), 
        output vdUnBalancedAmount (odUnBalancedAmount), 
        input  vcNoInvoiceAction (icNoInvoiceAction), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>

    if viFcReturnSuper <> 0 then assign viLocalReturn = viFcReturnSuper.

    /*====================================================================================================*/
    /*Set the Return Status to 3 when it's value is less than zero because it is not a blocking error and */
    /* we can save the tBankImpLine successfully later                                                    */
    /*====================================================================================================*/
    if viLocalReturn < 0 then assign viLocalReturn = 3.
    <M-55 run UpdateBankImpLineProcessResult
       (input  'GetInvoicesByBankImpLine':U (icProcessName), 
        input  viLocalReturn (iiProcessStatus), 
        input  ? (icProcessResult), 
        output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    
    /* =================================================================================================== */
    /* If no invoice, then create BE or Prepayment according to NoInvoiceAction                            */
    /* =================================================================================================== */
    if viLocalReturn = 3
    then do:
        /* Because the default NoInvoiceAction is create a initial payment, */
        /* and the processed status is Process-OK,                          */
        /* so the error messages are cleared for all three cases.           */
        for each tFcMessages where tFcMessages.tcFcRowid = 'BIL':U + tBankImpLine.tc_Rowid:
            delete tFcMessages .
        end.
    
        /* Create unallocated banking entry */
        if vcNoInvoiceAction = {&PAYCONFNOINVOICEACT-UNALLOCATED}
        then do:
            /* Remove new DDocument */
            <M-83 run RemoveNewDDocument
               (input  viDDocumentId (iiDDocument_ID), 
                output viFcReturnSuper (oiReturnStatus)) in BDDocument>
            
            assign tBankImpLine.DDocument_ID = 0.
            for each tBankImpLineDet:
                assign tBankImpLineDet.DDocument_ID = 0.
            end.
        
            assign oiReturnStatus = -98
                   tBankImpLine.BankImpLineProcessedStatus = {&BANKIMPPROCSTATUS-PROCESSED-OK}
                   vlIsCreateUnallocatedBE = yes.
        
            <M-95 run CreateBankImpLineProcessInfo
               (input  'CreateUnallocatedBankEntry':U (icProcessName), 
                input  #T-48'Create Unallocated Bank Entry':50(505749338)T-48# (icProcessDesc), 
                input  ? (icProcessResult), 
                input  ? (icProcessParam), 
                input  'ProcessBankImpLineNewDDocument':U (icParentRowName), 
                input  0 (iiProcessStatus), 
                output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
        
            <M-68 run CreateUnallocatedBankEntry
               (input  tBankImpLine.BankImpLineBankNumber (icOwnBankNumber), 
                input-output tBankImpLine.tiOwnBankNumber_ID (biOwnBankNumber_ID), 
                input-output vcBankGLCode (bcBankGLCode), 
                input-output tBankImpLine.BankImpLineOrigTransDate (btBankImpLineOrigTransDate), 
                input  tBankImpLine.BankImpLineValueDate (itBankImpLineValueDate), 
                input  tBankImpLine.BankImpLineBatchNbr (iiBankImpLineBatchNbr), 
                input  tBankImpLine.BankImpLine_ID (iiBankImpLine_ID), 
                input  tBankImpLine.BankImpLineStatNumber (icBankImpLineStatNumber), 
                input  tBankImpLine.BankImpLineInfo (icBankImpLineInfo), 
                output tBankImpLine.BankState_ID (oiBankState_ID), 
                input  tBankImpLine.BankImpLineInOut (icBankImpLineInOut), 
                input  tBankImpLine.BankImpLineDescription (icBankImpLineDescription), 
                input  tBankImpLine.BankImpLinePaymentRef (icBankImpLinePaymentRef), 
                input  tBankImpLine.BankImpLineInvRefList (icBankImpLineInvRefList), 
                input  tBankImpLine.BankImpLineDebtorCode (icBankImpLineDebtorCode), 
                input  tBankImpLine.BankImpLineCreditorCode (icBankImpLineCreditorCode), 
                input  vdBankImpLinePaymentTC (idBankImpLineAmountSumTC), 
                input  tBankImpLine.BankImpLineDebtorName (icBankImpLineDebtorName), 
                input  tBankImpLine.BankImpLineAddressLine (icBankImpLineAddressLine), 
                input  tBankImpLine.BankImpLineAddressCity (icBankImpLineAddressCity), 
                input  tBankImpLine.BankImpLineAddressZip (icBankImpLineAddressZip), 
                input  tBankImpLine.BankImpLineAddressCountry (icBankImpLineAddressCountry), 
                input  tBankImpLine.BankImpLineBankNumber (icBankImpLineBankNumber), 
                input  tBankImpLine.BankImpLineOrigAmountTC (idBankImpLineOrigAmountTC), 
                input  tBankImpLine.BankImpLineOrigCurrCode (icBankImpLineOrigCurrCode), 
                input  tBankImpLine.BankImpLineExchangeRate (idBankImpLineExchangeRate), 
                input  tBankImpLine.BankImpLineRateScale (idBankImpLineRateScale), 
                input  tBankImpLine.BankImpLineCost (icBankImpLineCost), 
                input  tBankImpLine.tc_Rowid (icBankImpLineRowID), 
                output vcMessageReference (ocBankingEntryReference), 
                output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
            
            assign viCreateBEReturn = viFcReturnSuper.
            <M-37 run UpdateBankImpLineProcessResult
               (input  'CreateUnallocatedBankEntry':U (icProcessName), 
                input  viCreateBEReturn (iiProcessStatus), 
                input  ? (icProcessResult), 
                output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
                
            if viCreateBEReturn <> 0 then assign viLocalReturn = viCreateBEReturn.
            
            leave CREATE_DDOCUMENT.
        end.
        /* Create prepayment */
        else if vcNoInvoiceAction = {&PAYCONFNOINVOICEACT-CREATE-PREPAY}
        then do:
            assign oiReturnStatus = -98
                   viLocalReturn  = 0
                   tBankImpLine.BankImpLineProcessedStatus = {&BANKIMPPROCSTATUS-PROCESSED-OK}
                   vlIsCreatePrepayment = yes.
        end.
        /* Create Initial payment */
        else assign vlIsCreateInitialPayment = yes.
    end. /* if viLocalReturn = 3 */

    /* =================================================================================================== */
    /* Allocate the invoioces                                                                              */
    /* =================================================================================================== */
    if viLocalReturn = 0
    then do:
        <M-10 run AllocateInvoices
           (input  tInvoiceXref (tDocInvoiceXref), 
            input  tInvoiceStageXref (tDocInvoiceStageXref), 
            input  viDDocumentId (iiDocumentId), 
            input  vcRowId (icParentRowId), 
            input  if vcNoInvoiceAction = {&PAYCONFNOINVOICEACT-CREATE-PREPAY} then vdUnBalancedAmount else 0 (idUnAllocatedAmount), 
            output viFcReturnSuper (oiReturnStatus)) in BDDocument>

        if viFcReturnSuper <> 0 
        then assign viLocalReturn = viFcReturnSuper.

        /*====================================================================================================*/
        /* Set the Return Status to 3 when it's value is less than zero because it is not a blocking error and*/
        /* we can save the tBankImpLine successfully later                                                    */
        /*====================================================================================================*/
        if viLocalReturn < 0 
        then assign viLocalReturn = 3.

        /* Create processing info */
        <M-72 run CreateBankImpLineProcessInfo
           (input  'AllocateInvoices':U (icProcessName), 
            input  #T-67'Allocate invoices to payment':255(590428421)T-67# (icProcessDesc), 
            input  ? (icProcessResult), 
            input  ? (icProcessParam), 
            input  'ProcessBankImpLineNewDDocument':U (icParentRowName), 
            input  viLocalReturn (iiProcessStatus), 
            output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    end.
    
    /* =================================================================================================== */
    /* Change the status to For collection                                                                 */
    /* =================================================================================================== */
    if viLocalReturn = 0
    then do:
        assign vcParam = "ToStatus = " + {&DOCUMENTSTATUS-INCASSO}.

        <M-11 run ChangeStatus
           (input  viDDocumentId (iiDDocumentId), 
            input  {&DOCUMENTSTATUS-INCASSO} (icToStatus), 
            input  vcBankImpLineRef (icBankImpLineRef), 
            input  tBankImpLine.tc_Rowid (icBankImpLineRowID), 
            output viFcReturnSuper (oiReturnStatus)) in BDDocument>

        if viFcReturnSuper <> 0 
        then assign viLocalReturn = viFcReturnSuper.

        /*====================================================================================================*/
        /*Set the Return Status to 3 when it's value is less than zero because it is not a blocking error and */
        /* we can save the tBankImpLine successfully later                                                    */
        /*====================================================================================================*/
        if viLocalReturn < 0 
        then assign viLocalReturn = 3.

        /* Create processing info */
        <M-902 run CreateBankImpLineProcessInfo
           (input  'ChangeStatus':U (icProcessName), 
            input  #T-97'Change customer payment status':255(213914093)T-97# (icProcessDesc), 
            input  vcParam (icProcessResult), 
            input  ? (icProcessParam), 
            input  'ProcessBankImpLineNewDDocument':U (icParentRowName), 
            input  viLocalReturn (iiProcessStatus), 
            output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    end.
    
    /* ====================================================================================================== */
    /* if the Create new checks in Paid Status is checked and create BankEntry is not checked then Change the */
    /* status to paid.                                                                                        */
    /* ====================================================================================================== */
    if ilCreatedToPaid and viLocalReturn = 0 and not ilCreateBankEntry
    then do:
        assign vcParam = "ToStatus = " + {&DOCUMENTSTATUS-PAID}.
        <M-12 run ChangeStatus
           (input  viDDocumentId (iiDDocumentId), 
            input  {&DOCUMENTSTATUS-PAID} (icToStatus), 
            input  vcBankImpLineRef (icBankImpLineRef), 
            output viFcReturnSuper (oiReturnStatus)) in BDDocument>

        if viFcReturnSuper <> 0 
        then assign viLocalReturn = viFcReturnSuper.

        /*====================================================================================================*/
        /*Set the Return Status to 3 when it's value is less than zero because it is not a blocking error and */
        /* we can save the tBankImpLine successfully later                                                    */
        /*====================================================================================================*/
        if viLocalReturn < 0 
        then assign viLocalReturn = 3.

        /* Create processing info */
        <M-60 run CreateBankImpLineProcessInfo
           (input  'ChangeStatus':U (icProcessName), 
            input  #T-92'Change customer payment status':255(213914093)T-92# (icProcessDesc), 
            input  vcParam (icProcessResult), 
            input  ? (icProcessParam), 
            input  'ProcessBankImpLineNewDDocument':U (icParentRowName), 
            input  viLocalReturn (iiProcessStatus), 
            output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    end.
        
    /* ====================================================================================================== */
    /* if the Create new checks in Paid Status and create banking entry is checked then Change the status to  */
    /* paid                                                                                                   */
    /* ====================================================================================================== */
    if ilCreatedToPaid and viLocalReturn = 0 and ilCreateBankEntry
    then do:
        <M-82 run ValDocumentStatus
           (input  viDDocumentId (iiDDocumentId), 
            input  {&DOCUMENTSTATUS-PAID} (icDDocumentStatus), 
            output viFcReturnSuper (oiReturnStatus)) in BDDocument>

        if viFcReturnSuper <> 0 
        then assign viLocalReturn = viFcReturnSuper.

        /*====================================================================================================*/
        /*Set the Return Status to 3 when it's value is less than zero because it is not a blocking error and */
        /* we can save the tBankImpLine successfully later                                                    */
        /*====================================================================================================*/
        if viLocalReturn < 0 then assign viLocalReturn = 3.
    end.
    
    /* =================================================================================================== */
    /* Validate the update the BDDocument                                                                  */
    /* =================================================================================================== */
    /* <M-13 run ValidateBCAndAdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BDDocument> 

    if (viFcReturnSuper > 0 and viLocalReturn = 0) or
        viFcReturnSuper < 0
    then assign viLocalReturn = viFcReturnSuper.
    */
    if viFcReturnSuper < 0  
    then leave CREATE_DDOCUMENT.
   
end. /* CREATE_DDOCUMENT */

/*
if valid-handle(vhBDDocumentBankImpLineInst)
then do:
    <I-17 {bFcCloseInstance
         &CLASS           = "BDDocument"}>
   
end.
*/

/* =================================================================================================== */
/* If there was error, then store this in processing file                                              */
/* If no error, then show warning message if "Create Unallocated BE" or "Create Prepayment"            */
/* =================================================================================================== */
if viLocalReturn < 0
then assign tBankImpLine.BankImpLineProcessedStatus = {&BANKIMPPROCSTATUS-PROCESSED-ERROR}.
else do:

    if vlIsCreatePrepayment and vcNoInvoiceAction = {&PAYCONFNOINVOICEACT-CREATE-PREPAY}
    then do:
        assign tBankImpLine.BankImpLineResultAction = {&BANKIMPORTRESULTACTION-CREATEPREPAY}
               tBankImpLine.tlIsDifferentAction     = true
               vcMessage = trim(substitute(#T-764'Please allocate prepayment later. (Year/Number/BankImportReference : &1)':255(610814803)T-764#,
                           vcMessageReference)).
        <M-27 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'I':U (icType), 
            input  4 (iiSeverity), 
            input  tBankImpLine.tc_Rowid (icRowid), 
            input  'qadfin-422089':U (icFcMsgNumber), 
            input  ? (icFcExplanation), 
            input  ? (icFcIdentification), 
            input  ? (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    end.
    else if vlIsCreateUnallocatedBE and
            (vcNoInvoiceAction = {&PAYCONFNOINVOICEACT-UNALLOCATED} or 
             vcPayConfPIBFNoCustomerAction = {&PAYCONFNOCUSTOMERACT-NEW-BE})
    then do:  
        assign tBankImpLine.BankImpLineResultAction = {&BANKIMPORTRESULTACTION-CREATEUNBE}
               tBankImpLine.tlIsDifferentAction     = true
               tBankImpLine.BankImpLinePaymentRef   = '':U    /* Clear payment reference cause there's no payment create */
               vcMessage = trim(substitute(#T-42'Please allocate bank entry later. (Year/Number/BankImportReference : &1)':255(297808028)T-42#, 
                           vcMessageReference)).
        <M-35 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'I':U (icType), 
            input  4 (iiSeverity), 
            input  tBankImpLine.tc_Rowid (icRowid), 
            input  'qadfin-738492':U (icFcMsgNumber), 
            input  ? (icFcExplanation), 
            input  ? (icFcIdentification), 
            input  ? (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    end.
    else if vlIsCreateInitialPayment and vcNoInvoiceAction  = {&PAYCONFNOINVOICEACT-CREATE-INIT-PAY}
    then do:
        assign tBankImpLine.BankImpLineResultAction = {&BANKIMPORTRESULTACTION-CREATEINITDDOC}
               tBankImpLine.tlIsDifferentAction     = true.
               vcMessage = trim(substitute(#T-34'Please allocate initial payment later. (Year/Number/BankImportReference : &1)':255(637078698)T-34#, 
                           vcMessageReference)).
        <M-18 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  '':U (icFieldName), 
            input  '':U (icFieldValue), 
            input  'I':U (icType), 
            input  4 (iiSeverity), 
            input  tBankImpLine.tc_Rowid (icRowid), 
            input  'qadfin-409377':U (icFcMsgNumber), 
            input  ? (icFcExplanation), 
            input  ? (icFcIdentification), 
            input  ? (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BBankImportLine>
    end.
    
    assign tBankImpLine.BankImpLineProcessedStatus = {&BANKIMPPROCSTATUS-PROCESSED-OK}.     
end.

/* =================================================================================================== */
/* Return                                                                                              */
/* =================================================================================================== */
if viLocalReturn <> 0 
then assign oiReturnStatus = viLocalReturn.
else 
if oiReturnStatus = -98 
then assign oiReturnStatus = 0.