project QadFinancials > class BDDocument > method ValidateComponentPreDInvoice

validation procedure


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BDDocument.ValidateComponentPre


program code (program4/bddocument.p)

<Q-98 run DInvoiceBankForDDocument  (Start) in BDInvoice >
for each t_sDDocument where
         t_sDDocument.tc_Status <> "D":U and
         t_sDDocument.tc_Status <> "":U:

    /* need to do this here because in ancestorcode mandatory validation is executed */
    if t_sDDocument.DDocumentStatus       = {&DOCUMENTSTATUS-INIT} and
       t_sDDocument.tcDebtorBankNumber   <> ? and
       t_sDDocument.tcDebtorBankNumber   <> "":U and
       t_sDDocument.tcOwnBankNumber      <> ? and
       t_sDDocument.tcOwnBankNumber      <> "":U and
       t_sDDocument.tcPayFormatTypeCode  <> ? and
       t_sDDocument.tcPayFormatTypeCode  <> "":U and
       t_sDDocument.tcDebtorCode         <> ? and
       t_sDDocument.tcDebtorCode         <> "":U
    then do:
        if not vlStartDebtorPrim
        then do:
             <Q-102 run DebtorPrim  (Start) in BDebtor >
             assign vlStartDebtorPrim = true.                
        end.
        <Q-103 run DebtorPrim (all) (Read) (NoCache)
           (input t_sDDocument.Company_ID, (CompanyId)
            input t_sDDocument.tcDebtorCode, (DebtorCode)
            input ?, (Debtor_ID)
            output dataset tqDebtorPrim) in BDebtor >
        find first tqDebtorPrim where
                   tqDebtorPrim.tcDebtorCode = t_sDDocument.tcDebtorCode
                   no-error.
        if available tqDebtorPrim
        then do:
            if not vlStart1
            then do:
                <Q-104 run BankNumberForParentObject  (Start) in BBankNumber >
                assign vlStart1 = true.
            end. /* if not vlStart1 */
            <Q-105 run BankNumberForParentObject (all) (Read) (NoCache)
               (input viCompanyId, (CompanyId)
                input tqDebtorPrim.tiDebtor_ID, (ParentObjectID)
                input t_sDDocument.tcDebtorBankNumber, (BankNumber)
                input t_sDDocument.tcOwnBankNumber, (OwnBankNumber)
                input t_sDDocument.tcPayFormatTypeCode, (PayFormatTypeCode)
                output dataset tqBankNumberForParentObject) in BBankNumber >
            find first tqBankNumberForParentObject where
                       tqBankNumberForParentObject.tcBankNumber         = t_sDDocument.tcDebtorBankNumber   and
                       tqBankNumberForParentObject.tcOwnBankNumber      = t_sDDocument.tcOwnBankNumber      and
                       tqBankNumberForParentObject.tcPayFormatTypeCode  = t_sDDocument.tcPayFormatTypeCode  and
                       tqBankNumberForParentObject.tiParentObject_ID    = tqDebtorPrim.tiDebtor_ID 
                       no-error.
            assign t_sDDocument.BankNumber_ID = if available tqBankNumberForParentObject
                                                then tqBankNumberForParentObject.tiBankNumber_ID
                                                else 0.
        end. /* end available tqDeborPrim */
    end. /* end t_sDDocument.DDocumentStatus = {&DOCUMENTSTATUS-INIT} */

    /* Update bank account of the invoice */
    for each t_sDDocumentInvoiceXref where
             t_sDDocumentInvoiceXref.DDocument_ID                = t_sDDocument.DDocument_ID and
             t_sDDocumentInvoiceXref.tc_Status                  <> "D":U                     and
             t_sDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC <> 0                         and
             t_sDDocumentInvoiceXref.tcDInvoiceType             <> {&INVOICETYPE-PREPAYMENT} and
             t_sDDocumentInvoiceXref.tcDInvoiceType             <> {&INVOICETYPE-DEDUCTION}:
        <Q-87 run DInvoiceBankForDDocument (all) (Read) (NoCache)
           (input t_sDDocumentInvoiceXref.DInvoice_ID, (DInvoiceId)
            input ?, (CompanyId)
            output dataset tqDInvoiceBankForDDocument) in BDInvoice >
        find first tqDInvoiceBankForDDocument where
                   tqDInvoiceBankForDDocument.tiDInvoice_ID = t_sDDocumentInvoiceXref.DInvoice_ID no-error.
        if not available tqDInvoiceBankForDDocument
        then do:
            assign vcMsg          = #T-89'Bank Details not found for Invoice $1':255(999890349)T-89#
                   oiReturnStatus = -1.
            <M-88 run SetMessage
               (input  vcMsg (icMessage), 
                input  t_sDDocumentInvoiceXref.tcDInvoiceReference (icArguments), 
                input  '':U (icFieldName), 
                input  '':U (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sDDocumentInvoiceXref.tc_Rowid (icRowid), 
                input  'QadFin-8696':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BDDocument>
            return.
        end. /* if not available tqDInvoiceBankForDDocument */

        if tqDInvoiceBankForDDocument.tcOwnBankNumber <> t_sDDocument.tcOwnBankNumber or
           tqDInvoiceBankForDDocument.tcPayFormatTypeCode <> t_sDDocument.tcPayFormatTypeCode 
        then do:
            if tqDInvoiceBankForDDocument.tcPayFormatTypeCode <> t_sDDocument.tcPayFormatTypeCode
            then do:
                <Q-90 assign vlFcQueryRecordsAvailable = PayFormatGroupPrim (NoCache)
                   (input ?, (PayFormatGroupID)
                    input t_sDDocument.tcPayFormatTypeCode, (PayFormatTypeCode)
                    input ?, (PayFormatGroupSequence)) in BPaymentFormat >
                if vlFcQueryRecordsAvailable <> false
                then assign viCanBeChanged = -1.
                
                else do:
                    <Q-91 assign vlFcQueryRecordsAvailable = PayFormatGroupPrim (NoCache)
                       (input ?, (PayFormatGroupID)
                        input tqDInvoiceBankForDDocument.tcPayFormatTypeCode, (PayFormatTypeCode)
                        input ?, (PayFormatGroupSequence)) in BPaymentFormat >
                    if vlFcQueryRecordsAvailable = true or
                       vlFcQueryRecordsAvailable = ?
                    then assign viCanBeChanged = 1.
                   
                end. /* else do */
            end. /* if t_iPaySel.tcPayFormatTypeCode <> t_sPaySel.tcPayFormatTypeCode */
            if viCanBeChanged = 1
            then do:
                assign vcMsg          = #T-68'The payment's Payment Format has no payment level attributes. The values for payment level attributes of allocated open items cannot be kept in the payment.':255(70681)T-68#
                       oiReturnStatus = 1.
                <M-63 run SetMessage
                   (input  vcMsg (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'W':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sDDocument.tc_Rowid (icRowid), 
                    input  'QadFin-8482':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BDDocument>
            end. /* if viCanBeChanged = 1 */
            else if viCanBeChanged = -1
            then do:
                assign vcMsg          = #T-69'Open items with different payment level attribute values cannot be allocated to one single payment using the same payment format.':255(70682)T-69#
                       oiReturnStatus = -1.
                <M-64 run SetMessage
                   (input  vcMsg (icMessage), 
                    input  '':U (icArguments), 
                    input  '':U (icFieldName), 
                    input  '':U (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sDDocument.tc_Rowid (icRowid), 
                    input  'QadFin-8483':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BDDocument>
                if vlStart1
                then do:
                    <Q-65 run BankNumberForParentObject  (Stop) in BBankNumber >
                end. /* if vlStart1 */
               
                if valid-handle(vhBBankNumber2Inst)
                then do:
                    <I-67 {bFcCloseInstance
                         &CLASS           = "BBankNumber"}>
                end. /* if valid-handle(vhBBankNumber3Inst) */
                return.
            end. /* else if viCanBeChanged = -1 */



            /* Check if the bank number has defined for the customer */
            if not vlStart1
            then do:
                <Q-37 run BankNumberForParentObject  (Start) in BBankNumber >
                assign vlStart1 = true.
            end. /* if not vlStart1 */
            <Q-38 run BankNumberForParentObject (all) (Read) (NoCache)
               (input viCompanyId, (CompanyId)
                input tqDInvoiceBankForDDocument.tiDebtor_ID, (ParentObjectID)
                input t_sDDocument.tcDebtorBankNumber, (BankNumber)
                input t_sDDocument.tcOwnBankNumber, (OwnBankNumber)
                input t_sDDocument.tcPayFormatTypeCode, (PayFormatTypeCode)
                output dataset tqBankNumberForParentObject) in BBankNumber >

            find first tqBankNumberForParentObject where
                   tqBankNumberForParentObject.tcBankNumber         = t_sDDocument.tcDebtorBankNumber and
                   tqBankNumberForParentObject.tcOwnBankNumber      = t_sDDocument.tcOwnBankNumber      and
                   tqBankNumberForParentObject.tcPayFormatTypeCode  = t_sDDocument.tcPayFormatTypeCode  and
                   tqBankNumberForParentObject.tiParentObject_ID    = tqDInvoiceBankForDDocument.tiDebtor_ID no-error.
            /* Create the bank number for customer if it does not exist before */
            if not available tqBankNumberForParentObject
            then do:
                if not vlStart2
                then do:
                    <Q-95 run BankNumberForOwnBankNumber  (Start) in BBankNumber >
                    assign vlStart2 = true.
                end.
                <Q-93 run BankNumberForOwnBankNumber (all) (Read) (NoCache)
                   (input viCompanyId, (CompanyId)
                    input t_sDDocument.tcOwnBankNumber, (OwnBankNumber)
                    input t_sDDocument.tcGLCode, (OwnGLCode)
                    input t_sDDocument.tcPayFormatTypeCode, (PayFormatTypeCode)
                    output dataset tqBankNumberForOwnBankNumber) in BBankNumber >
                find first tqBankNumberForOwnBankNumber where
                           tqBankNumberForOwnBankNumber.tcOwnBankNumber = t_sDDocument.tcOwnBankNumber and
                           tqBankNumberForOwnBankNumber.tcOwnGLCode     = t_sDDocument.tcGLCode        and
                           tqBankNumberForOwnBankNumber.tcPayFormatTypeCode = t_sDDocument.tcPayFormatTypeCode no-error.
                if not available tqBankNumberForOwnBankNumber
                then do:
                    assign vcMsg = trim(#T-92'Own Bank Number Combination does not exist.':255(999890111)T-92#).
                    <M-94 run SetMessage
                       (input  vcMsg (icMessage), 
                        input  '':U (icArguments), 
                        input  '':U (icFieldName), 
                        input  '':U (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  t_sDDocument.tc_Rowid (icRowid), 
                        input  'QadFin-8876':U (icFcMsgNumber), 
                        input  '':U (icFcExplanation), 
                        input  '':U (icFcIdentification), 
                        input  '':U (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BDDocument>
                    assign oiReturnStatus = -1.
                    if vlStart2 = true
                    then do:
                        <Q-96 run BankNumberForOwnBankNumber  (Stop) in BBankNumber >
                    end.
                    return.
                end.
                create tCreateBankNumber.
                assign tCreateBankNumber.tiOldBankNumberId     = t_sDDocument.BankNumber_ID
                       tCreateBankNumber.tiBankPayFormatId     = tqBankNumberForOwnBankNumber.tiBankPayFormat_ID
                       tCreateBankNumber.tlIsFormatTypeChanged = if t_sDDocument.tcPayFormatTypeCode = tqDInvoiceBankForDDocument.tcPayFormatTypeCode
                                                                 then false
                                                                 else true
                       tCreateBankNumber.tlIsBankNumberDefault = false.
            end. /* if not available tqBankNumberForPayFormatBank */
            else do:
                assign t_sDDocument.BankNumber_ID = tqBankNumberForParentObject.tiBankNumber_ID.
            end. /* else do */

            
            create tUpdateDInvBankNumber.
            assign tUpdateDInvBankNumber.tiDInvoiceId          = t_sDDocumentInvoiceXref.DInvoice_ID
                   tUpdateDInvBankNumber.tiNewBankNumberId     = if available tqBankNumberForParentObject then tqBankNumberForParentObject.tiBankNumber_ID
                                                                 else t_sDDocument.BankNumber_ID
                   tUpdateDInvBankNumber.tiOldBankNumberId     = tqDInvoiceBankForDDocument.tiBankNumber_ID
                   tUpdateDInvBankNumber.tdDInvoiceBankToPayTC = t_sDDocumentInvoiceXref.DDocumentInvoiceXrefAlloTC - abs(t_sDDocumentInvoiceXref.DDocumentInvoiceXrefDiscTC)
                   tUpdateDInvBankNumber.tlPayFormatChanged    = if t_sDDocument.tcPayFormatTypeCode = tqDInvoiceBankForDDocument.tcPayFormatTypeCode
                                                                 then false
                                                                 else true.
        end. /* if tqDInvoiceBankByDInvoiceID.tiBankNumber_ID <> t_sDDocument.BankNumber_ID */
    end. /* for each t_sDDocument: */
end. /* for each t_sDDocumentInvoiceXref where */


if vlStart1
then do:
    <Q-48 run BankNumberForParentObject  (Stop) in BBankNumber >
end. /* if vlStart1 */
if vlStart2 = true
then do:
    <Q-97 run BankNumberForOwnBankNumber  (Stop) in BBankNumber >
end.
if vlStartDebtorPrim
then do:
    <Q-106 run DebtorPrim  (Stop) in BDebtor >
end.

<Q-99 run DInvoiceBankForDDocument  (Stop) in BDInvoice >

if can-find(first tCreateBankNumber)
then do:
    if not valid-handle(vhBBankNumber2Inst)
    then do:
        <I-50 {bFcStartAndOpenInstance
             &ADD-TO-TRANSACTION = "true"
             &CLASS              = "BBankNumber"}>
    end. /* if not valid-handle(vhBBankNumber2Inst) */
    else do:
        <I-51 {bFcOpenInstance
             &CLASS           = "BBankNumber"}>
    end. /* else do: */

    <M-52 run CreateBankNumberAsCopy
       (input-output tCreateBankNumber (tBankNumberToCreate), 
        input  true (ilClearData), 
        output viFcReturnSuper (oiReturnStatus)) in BBankNumber>

    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then do:
        <I-53 {bFcCloseInstance
             &CLASS           = "BBankNumber"}>
        return.
    end. /* if viFcReturnSuper < 0 */


    for each t_sDDocument where t_sDDocument.tc_Status <> 'D':U:
        find first tCreateBankNumber where
                   tCreateBankNumber.tiOldBankNumberId = t_sDDocument.BankNumber_ID and
                   tCreateBankNumber.tiNewBankNumberId <> 0 and
                   tCreateBankNumber.tiNewBankNumberId <> ?
        no-error.
        if available tCreateBankNumber
        then do:
            assign t_sDDocument.BankNumber_ID = tCreateBankNumber.tiNewBankNumberId.

            for each t_sDDocumentInvoiceXref where t_sDDocumentInvoiceXref.DDocument_ID = t_sDDocument.DDocument_ID,
                each tUpdateDInvBankNumber   where tUpdateDInvBankNumber.tiDInvoiceId = t_sDDocumentInvoiceXref.DInvoice_ID:
                assign tUpdateDInvBankNumber.tiNewBankNumberId = tCreateBankNumber.tiNewBankNumberId.
            end.
        end.
    end. 
  
    <M-100 run ValidateBCAndAdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BBankNumber>
    if viFcReturnSuper <> 0 then assign oiReturnStatus = viFcReturnSuper.

    <I-101 {bFcCloseInstance
         &CLASS           = "BBankNumber"}>
end. /* if can-find(first tCreateBankNumber) */