project QadFinancials > class BBankEntry > method ValidateComponentPost

Description

Validate the Banking Entry Posting data


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BBankEntry.ValidateComponent


program code (program4/bbankentry.p)

    /* ============= */
    /* Start queries */
    /* ============= */
    <Q-43 run DDocumentPostingLineForPostingDate  (Start) in BDDocument >
    <Q-72 run CDocumentPostingLineForPostingDate  (Start) in BCDocument >
    
    /* ========================== */
    /* Go through all allocations */
    /* ========================== */
    for each t_sBankState where
             t_sBankState.tc_Status     <> "D":U,
        each t_sBankStateLine where
             t_sBankStateLine.tc_ParentRowid = t_sBankState.tc_Rowid and
             t_sBankStateLine.tc_Status <> "D":U,
        each t_sBankStateAlloc where
             t_sBankStateAlloc.tc_ParentRowid = t_sBankStateLine.tc_Rowid and
             t_sBankStateAlloc.tc_Status <> "D":U :
        
        /* ======================================================================== */
        /* Raise an error if the document-posting-date is after the BE-posting-date */
        /* ======================================================================== */
        for each t_sBankStateAllocColl where
                 t_sBankStateAllocColl.tc_ParentRowid = t_sBankStateAlloc.tc_Rowid and
                 t_sBankStateAllocColl.tc_Status  <> "D":U:
    
            if t_sBankStateAllocColl.DDocument_ID <> 0 and t_sBankStateAllocColl.DDocument_ID <> ?
            then do:
                /* Check the payment posting date of debtor with Banking Entry Posting Date  */
                <Q-67 run DDocumentPostingLineForPostingDate (all) (Read) (NoCache)
                   (input ?, (CompanyId)
                    input t_sBankStateAllocColl.DDocument_ID, (Document_ID)
                    output dataset tqDDocumentPostingLineForPostDat) in BDDocument >
                find first tqDDocumentPostingLineForPostDat no-error.
                if available tqDDocumentPostingLineForPostDat
                then do:
                     if tqDDocumentPostingLineForPostDat.ttPostingDate > t_sBankStateLine.BankStateLinePostingDate
                     then do:
                        assign oiReturnStatus = -1
                               vcMessage = trim(substitute(#T-69'Payment posting date can not be after banking entry posting date. (Payment reference : &1/&2 Banking entry line: &3/&4/&5)':255(156690703)T-69#,t_sBankStateAllocColl.tiDDocumentYear,t_sBankStateAllocColl.tiDDocumentNumber,t_sBankState.BankStateYear,t_sBankState.BankStateNumber,t_sBankStateLine.BankStateLineNumber)).
                               vcDatetemp =     <M-32 DisplayDate  (input  t_sBankStateLine.BankStateLinePostingDate (itDate)) in BBankEntry>.
                        <M-50 run SetMessage
                           (input  vcMessage (icMessage), 
                            input  '':U (icArguments), 
                            input  'tBankStateLine.BankStateLinePostingDate':U (icFieldName), 
                            input  vcDatetemp (icFieldValue), 
                            input  'E':U (icType), 
                            input  3 (iiSeverity), 
                            input  t_sBankStateAllocColl.tc_Rowid (icRowid), 
                            input  'QadFin-346907':U (icFcMsgNumber), 
                            input  '':U (icFcExplanation), 
                            input  '':U (icFcIdentification), 
                            input  '':U (icFcContext), 
                            output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
                     end. /* if tqDDocumentPostingLineForPostDat.ttPostingDate */
                end. /* if available tqDDocumentPostingLineForPostDat */
            end. /* if t_sBankStateAllocColl.DDocument_ID <> 0 and */
            else do : 
                if t_sBankStateAllocColl.CDocument_ID <> 0 and t_sBankStateAllocColl.CDocument_ID <> ?
                then do:
                     /* Check the payment posting date creditor with Banking Entry Posting Date  */
                     <Q-17 run CDocumentPostingLineForPostingDate (all) (Read) (NoCache)
                        (input ?, (CompanyId)
                         input t_sBankStateAllocColl.CDocument_ID, (Document_ID)
                         output dataset tqCDocumentPostingLineForPostDat) in BCDocument >
                     find first tqCDocumentPostingLineForPostDat no-error.
                     if available tqCDocumentPostingLineForPostDat
                     then do:
                          if tqCDocumentPostingLineForPostDat.ttPostingDate > t_sBankStateLine.BankStateLinePostingDate
                          then do:
                               assign oiReturnStatus = -1
                                      vcMessage = trim(substitute(#T-48'Payment posting date can not be after banking entry posting date. (Payment reference : &1/&2 Banking entry line: &3/&4/&5)':255(156690703)T-48#,t_sBankStateAllocColl.tiCDocumentYear,t_sBankStateAllocColl.tiCDocumentNumber,t_SBankState.BankStateYear,t_sBankState.BankStateNumber,t_sBankStateLine.BankStateLineNumber)).
                                vcDatetemp1 =       <M-46 DisplayDate  (input  t_sBankStateLine.BankStateLinePostingDate (itDate)) in BBankEntry>.
                               <M-9 run SetMessage
                                  (input  vcMessage (icMessage), 
                                   input  '':U (icArguments), 
                                   input  'tBankStateLine.BankStateLinePostingDate':U (icFieldName), 
                                   input  vcDatetemp1 (icFieldValue), 
                                   input  'E':U (icType), 
                                   input  3 (iiSeverity), 
                                   input  t_sBankStateAllocColl.tc_Rowid (icRowid), 
                                   input  'QadFin-699770':U (icFcMsgNumber), 
                                   input  '':U (icFcExplanation), 
                                   input  '':U (icFcIdentification), 
                                   input  '':U (icFcContext), 
                                   output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
                          end. /* if tqCDocumentPostingLineForPostDat.ttPostingDate */
                     end. /* if available tqCDocumentPostingLineForPostDat */         
                end. /* else if t_sBankStateAllocColl.CDocument_ID <> 0 and */
            end. /* Not if t_sBankStateAllocColl.DDocument_ID <> 0 and */
        
        end. /* for each t_sBankStateAllocColl where */
                       
        /* ==================================================================================================== */
        /* Stage-specific validation:                                                                           */
        /* - Go through all stages of the allocation and make sure the AllocatedTC=PaidTC+DiscountTC            */
        /* - The sum of these 3 fields on the the stages, should equal the corresponding field on invoice level */
        /* - Validate on the invoice-level that AllocatedTC=PaidTC+DiscountTC                                   */
        /* ==================================================================================================== */
        if can-find (first t_sBankStateStageAlloc where
                           t_sBankStateStageAlloc.tc_ParentRowid  = t_sBankStateAlloc.tc_Rowid and
                           t_sBankStateStageAlloc.tc_Status      <> "D":U) and 
           ((t_sBankStateAlloc.DInvoice_ID <> 0 and 
             t_sBankStateAlloc.DInvoice_ID <> ?) Or 
            (t_sBankStateAlloc.CInvoice_ID <> 0 and 
             t_sBankStateAlloc.CInvoice_ID <> ?))
        then STAGEALLOACTIONBLOCK: DO : 
            assign vdSumAmountTC   = 0
                   vdSumPaidTC     = 0
                   vdSumDiscountTC = 0
                   vdSumWHTTC      = 0.
            for each t_sBankStateStageAlloc where
                     t_sBankStateStageAlloc.tc_ParentRowid  = t_sBankStateAlloc.tc_Rowid and
                     t_sBankStateStageAlloc.tc_Status      <> "D":U:
                if absolute(t_sBankStateStageAlloc.BankStateStageAllocAmntTC) <> absolute(t_sBankStateStageAlloc.BankStateStageAllocPaidTC) + absolute(t_sBankStateStageAlloc.BankStateStageAllocDiscTC) + absolute(t_sBankStateStageAlloc.BankStateStageAllocWHTTC)
                then do :
                    assign oiReturnStatus = -1
                          vcMessage       = trim(substitute(#T-56'Incorrect stage-details for invoice &1: the allocated amount (&2) should equal the sum of the paid amount (&3) the discount amount (&4) and the WHT amount (&5).':255(194262676)T-56#,t_sBankStateAlloc.tcDocNumberReference,t_sBankStateStageAlloc.BankStateStageAllocAmntTC,t_sBankStateStageAlloc.BankStateStageAllocPaidTC,t_sBankStateStageAlloc.BankStateStageAllocDiscTC,t_sBankStateStageAlloc.BankStateStageAllocWHTTC)).
                    <M-82 run SetMessage
                       (input  vcMessage (icMessage), 
                        input  '':U (icArguments), 
                        input  'tBankStateStageAlloc.BankStateStageAllocAmntTC':U (icFieldName), 
                        input  t_sBankStateStageAlloc.BankStateStageAllocAmntTC (icFieldValue), 
                        input  'E':U (icType), 
                        input  3 (iiSeverity), 
                        input  t_sBankStateStageAlloc.tc_Rowid (icRowid), 
                        input  'QadFin-537429':U (icFcMsgNumber), 
                        input  '':U (icFcExplanation), 
                        input  '':U (icFcIdentification), 
                        input  '':U (icFcContext), 
                        output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
                    Leave STAGEALLOACTIONBLOCK.
                end. /* t_sBankStateStageAlloc.BankStateStageAllocAmntTC <> t_sBankStateStageAlloc.BankStateStageAllocPaidTC + t_sBankStateStageAlloc.BankStateStageAllocDiscTC */
                assign vdSumAmountTC   = vdSumAmountTC + absolute(t_sBankStateStageAlloc.BankStateStageAllocAmntTC)
                       vdSumPaidTC     = vdSumPaidTC + absolute(t_sBankStateStageAlloc.BankStateStageAllocPaidTC)
                       vdSumDiscountTC = vdSumDiscountTC + absolute(t_sBankStateStageAlloc.BankStateStageAllocDiscTC)
                       vdSumWHTTC      = vdSumWHTTC + absolute(t_sBankStateStageAlloc.BankStateStageAllocWHTTC).
            end. /* for each t_sBankStateAllocStage where */
            
            /* check the absolute values because for invoice corrections, it is the opposite */
            if vdSumAmountTC   <> absolute(t_sBankStateAlloc.BankStateAllocAmountTC)   or 
               vdSumPaidTC     <> absolute(t_sBankStateAlloc.BankStateAllocPaidAmtTC)  or
               vdSumDiscountTC <> absolute(t_sBankStateAlloc.BankStateAllocDiscountTC) or
               vdSumWHTTC      <> absolute(t_sBankStateAlloc.BankStateAllocWHTAmtTC)
            then do :
                assign oiReturnStatus = -1
                       vcMessage       = trim(substitute(#T-97'The sum of the stage-details should equal the corresponding fields on the invoice-level- - Invoice:&1.':255(318050036)T-97#,t_sBankStateAlloc.tcDocNumberReference)) + chr(10) + 
                                         trim(substitute(#T-92'Allocated amount on invoice-level: &1':255(91272501)T-92#,t_sBankStateAlloc.BankStateAllocAmountTC)) + chr(10) + 
                                         trim(substitute(#T-45'Sum of the allocated amounts on the stages: &1':255(360587195)T-45#,vdSumAmountTC)) + chr(10) + 
                                         trim(substitute(#T-24'Paid amount on invoice-level: &1':255(70285423)T-24#,t_sBankStateAlloc.BankStateAllocPaidAmtTC)) + chr(10) + 
                                         trim(substitute(#T-78'Sum of the paid amounts on the stages: &1':255(507438273)T-78#,vdSumPaidTC)) + chr(10) + 
                                         trim(substitute(#T-60'Discount amount on invoice-level: &1':255(81534921)T-60#,t_sBankStateAlloc.BankStateAllocDiscountTC)) + chr(10) + 
                                         trim(substitute(#T-33'Sum of the discount amounts on the stages: &1':255(856245850)T-33#,vdSumDiscountTC)) + chr(10) +
                                         trim(substitute(#T-57'WHT amount on invoice-level: &1':255(345623959)T-57#,t_sBankStateAlloc.BankStateAllocWHTAmtTC)) + chr(10) +
                                         trim(substitute(#T-96'Sum of the WHT amounts on the stages: &1':255(627873930)T-96#,vdSumWHTTC)).
                <M-88 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tBankStateAlloc.BankStateAllocAmountTC':U (icFieldName), 
                    input  string(t_sBankStateAlloc.BankStateAllocAmountTC) (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sBankStateAlloc.tc_Rowid (icRowid), 
                    input  'QadFin-664264':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
                Leave STAGEALLOACTIONBLOCK.
            end. /* if vdSumAmountTC   <> t_sBankStateAlloc.BankStateAllocAmountTC or */
            if absolute(t_sBankStateAlloc.BankStateAllocAmountTC) <> absolute(t_sBankStateAlloc.BankStateAllocPaidAmtTC) + absolute(t_sBankStateAlloc.BankStateAllocDiscountTC) + absolute(t_sBankStateAlloc.BankStateAllocWHTAmtTC)
            then do :
                assign oiReturnStatus = -1
                      vcMessage       = trim(substitute(#T-80'Incorrect allocation-details for invoice &1: the allocated amount (&2) should equal the sum of the paid amount (&3), the discount amount (&4) and the WHT amount (&5).':255(390819858)T-80#,t_sBankStateAlloc.tcDocNumberReference,t_sBankStateAlloc.BankStateAllocAmountTC,t_sBankStateAlloc.BankStateAllocPaidAmtTC,t_sBankStateAlloc.BankStateAllocDiscountTC,t_sBankStateAlloc.BankStateAllocWHTAmtTC)).
                <M-28 run SetMessage
                   (input  vcMessage (icMessage), 
                    input  '':U (icArguments), 
                    input  'tBankStateAlloc.BankStateAllocAmountTC':U (icFieldName), 
                    input  string(t_sBankStateAlloc.BankStateAllocAmountTC) (icFieldValue), 
                    input  'E':U (icType), 
                    input  3 (iiSeverity), 
                    input  t_sBankStateAlloc.tc_Rowid (icRowid), 
                    input  'QadFin-932716':U (icFcMsgNumber), 
                    input  '':U (icFcExplanation), 
                    input  '':U (icFcIdentification), 
                    input  '':U (icFcContext), 
                    output viFcReturnSuper (oiReturnStatus)) in BBankEntry>
                Leave STAGEALLOACTIONBLOCK.
            end. /* absolute(t_sBankStateAlloc.BankStateAllocAmountTC) <> absolute(t_sBankStateAlloc.BankStateAllocPaidAmtTC) + absolute(t_sBankStateAlloc.BankStateAllocDiscountTC) */
            
        end. /* if can-find (first t_sBankStateStageAlloc where - STAGEALLOACTIONBLOCK */
        
    end. /* for each t_sBankState */
    
    /* ============= */
    /* Stop queries  */
    /* ============= */
    <Q-31 run DDocumentPostingLineForPostingDate  (Stop) in BDDocument >
    <Q-65 run CDocumentPostingLineForPostingDate  (Stop) in BCDocument >