project QadFinancials > class BPosting > method ValidateComponentPreAssignVatGroup

Description

ValidateComponentPreAssignVatGroup: submethod of ValidateComponentPre that takes care of the assignment of PostingVat.VatGroup_ID and that in-flight creates a VatGroup in a number of cases.


Parameters


oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPosting.ValidateComponentPre


program code (program4/bposting.p)

/* ============================================================================================================================== */
/* ValidateComponentPreAssignVatGroup: submethod of ValidateComponent that takes care of the assignment of PostingVat.VatGroup_ID */
/* and that in-flight creates a VatGroup in a number of cases. Note that the inflight create leads to the odd situation that      */
/* we have inter-component communication started from the validations: for that reason BVatGroup we have to make sure that the    */
/* call to StopExternalInstances is done in the very first beginning of the ValidateComponent                                     */
/* Functional sequence:                                                                                                           */
/* 1. Try to assign PostingVat.VatGroup_ID based upon the Vat and VatRule specified in the PostingVat and based upon the          */
/*    journal (invoice-creditnote) of the posting. If such a VatGroup can be found then use it on the PostingVat.                 */
/* 2. Try to assign PostingVat.VatGroup_ID based upon the Vat and VatRule specified in the PostingVat: only take the VatGroup     */
/*    for the invoice-side into account (omit the ones for credit-notes). If such a VatGroup can be found then use it             */
/* 3. If these steps does not result in a filled VatGroup then raise an error.                                                    */
/* ============================================================================================================================== */

/* ===================== */
/* Exception handling    */
/* ===================== */
assign oiReturnStatus      = -98
       viLocalReturnStatus = 0.

VATBLOCK:
DO:
    /*IF VatRule_ID is not assigned get it assigned - CA767402*/
    <Q-10 run VatRuleByVatIDCode (all) (Read) (NoCache)
       (input t_sPostingVat.tcVatCode, (VatCode)
        input ?, (VatID)
        input {&VATRULEBASE-FULL}, (VatRuleBaseFull)
        input t_sPostingVat.tcVatInOut, (VatInOut)
        input t_sPostingVat.tcDomainCode, (DomainCode)
        output dataset tqVatRuleByVatIDCode) in BVAT >
        
    if t_sPostingVat.PostingVatIsAbsRet = true
    then find last tqVatRuleByVatIDCode no-error. /* the last one it the one for retained absorbed taxes */  
    else find first tqVatRuleByVatIDCode no-error.  /* the first one it the one for non-retained non-absorbed taxes */    

    if not available tqVatRuleByVatIDCode
    then do:
        assign vcMsgExplanation = <M-24 GetErrorExplanation
                                     (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                      input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                                      output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
        assign vcMessage           = trim(substitute(#T-20'Internal error: the tax-posting-line cannot be created as the Vat-rule cannot be found based upon the Domain (&1), Tax-code (&2) and Tax-direction (&3).':255(332065953)T-20#,t_sPostingVat.tcDomainCode,t_sPostingVat.tcVatCode,t_sPostingVat.tcVatInOut))
               viLocalReturnStatus = -3.
        <M-16 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-412661':U (icFcMsgNumber), 
            input  vcMsgExplanation (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        Leave VATBLOCK.
    end. /* if not available tqVatRuleByVatIDCode */ 
    assign t_sPostingVat.VatRule_ID = tqVatRuleByVatIDCode.tiVatRule_ID.
    
    /* ===================================================================== */
    /* Only go through the new records or the ones with a significant change */
    /* ===================================================================== */             
    if t_sPostingVat.tcVatCode  <> "":U and 
       t_sPostingVat.tcVatCode  <> ?    and
       t_sPostingVat.VatRule_ID <> 0    and 
       t_sPostingVat.VatRule_ID <> ?    and 
       (
        (t_sPostingVat.tc_Status = "N":U or
         (t_sPostingVat.tc_Status = "C":U and 
          can-find (first t_iPostingVat where 
                          t_iPostingVat.tc_Rowid = t_sPostingVat.tc_Rowid and 
                          (t_iPostingVat.tcVatCode  <> t_sPostingVat.tcVatCode or
                           t_iPostingVat.VatRule_ID <> t_sPostingVat.VatRule_ID)))) or 
        (t_sPosting.tc_Status = "N":U or
         (t_sPosting.tc_Status = "C":U and 
          can-find (first t_iPosting where 
                          t_iPosting.tc_Rowid        = t_sPosting.tc_Rowid and 
                          t_iPosting.tcJournalCode  <> t_sPosting.tcJournalCode))) 
        )
    then do :
        
        /* ============================================================== */
        /* 0. Read the VatRule based on the the PostingVat-information.   */
        /*    Read the journal of the posting to get the journaltype      */
        /* ============================================================== */
        <Q-82 run VatRuleByVatRuleIDVatIDCode (all) (Read) (Cache)
           (input t_sPostingVat.VatRule_ID, (VatRuleID)
            input ?, (VatID)
            input t_sPostingVat.tcVatCode, (VatCode)
            input ?, (DomainID)
            output dataset tqVatRuleByVatRuleIDVatIDCode) in BVAT >
        find first tqVatRuleByVatRuleIDVatIDCode 
                   no-error. /* no where clauses needed as the values are checked on blank before */
        if not available tqVatRuleByVatRuleIDVatIDCode
        then do :
            assign vcMsgExplanation = <M-59 GetErrorExplanation
                                         (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                          input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                                          output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
            assign viLocalReturnStatus  = -1
                   vcMessage            = trim(substitute(#T-87'The VAT-VAT Rule details referenced in the posting &1/&2/&3 cannot be found.':255(64040)t-87#,string(t_sPosting.PostingYear),t_sPosting.tcJournalCode,string(t_sPosting.PostingVoucher))) + chr(10) + 
                                          trim(substitute(#T-88'VAT code used: &1':255(64030)t-88#,t_sPostingVat.tcVatCode)) + chr(10) + 
                                          trim(substitute(#T-89'VAT Rule ID: &1':255(64031)t-89#,string(t_sPostingVat.VatRule_ID))).
            <M-83 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tPostingVat.tcVatCode':U (icFieldName), 
                input  t_sPostingVat.tcVatCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sPostingVat.tc_Rowid (icRowid), 
                input  'QadFin-7255':U (icFcMsgNumber), 
                input  vcMsgExplanation (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
            leave VATBLOCK.
        end. /* if no available tqVatRuleByVatRuleIDVatIDCode */
        
        <Q-47 run JournalByJournalLayerType (all) (Read) (Cache)
           (input 0, (JournalId)
            input t_sPosting.tcJournalCode, (JournalCode)
            input t_sPosting.Company_ID, (CompanyId)
            input '':U, (LayerTypeCode)
            output dataset tqJournalByJournalLayerType) in BJournal>
        find first tqJournalByJournalLayerType where
                   tqJournalByJournalLayerType.tcJournalCode = t_sPosting.tcJournalCode
                   no-error.
        if not available tqJournalByJournalLayerType
        then do :
            assign vcMsgExplanation = <M-53 GetErrorExplanation
                                         (input  t_sPosting.tc_Rowid (icPostingRowId), 
                                          input  t_sPostingLine.tc_Rowid (icPostingLineRowId), 
                                          output viFcReturnSuper (oiReturnStatus)) in BPosting>.
                              
            assign viLocalReturnStatus  = -1
                   vcMessage            = trim(substitute(#T-90'The daybook code(s) used in the posting &1/&2/&3 cannot be found.':255(64043)t-90#,string(t_sPosting.PostingYear),t_sPosting.tcJournalCode,string(t_sPosting.PostingVoucher))) + chr(10) + 
                                          trim(substitute(#T-91'Daybook Code used: &1':255(64042)T-91#,t_sPosting.tcJournalCode)).
            <M-85 run SetMessage
               (input  vcMessage (icMessage), 
                input  '':U (icArguments), 
                input  'tPosting.tcJournalCode':U (icFieldName), 
                input  t_sPosting.tcJournalCode (icFieldValue), 
                input  'E':U (icType), 
                input  3 (iiSeverity), 
                input  t_sPosting.tc_Rowid (icRowid), 
                input  'QadFin-7256':U (icFcMsgNumber), 
                input  vcMsgExplanation (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BPosting>
            leave VATBLOCK.
        end. /* if not available tqJournalByJournalLayerType */
    
        /* ==================================================================== */
        /* Main processing by a submethod that is also called from other places */
        /* ==================================================================== */
        <M-86 run GetPostingVatVatGroup
           (input  t_sPosting.tcJournalTypeCode (icJournalTypeCode), 
            input  t_sPostingVat.tcVatCode (icVatCode), 
            input  tqVatRuleByVatRuleIDVatIDCode.tiVatRuleSequence (iiVatRuleSequence), 
            input  tqVatRuleByVatRuleIDVatIDCode.tiInvoiceVatGroup_ID (iiInvoiceVatGroupID), 
            input  tqVatRuleByVatRuleIDVatIDCode.tiCreditNoteVatGroup_ID (iiCreditNoteVatGroupID), 
            input  tqVatRuleByVatRuleIDVatIDCode.tiAbsorbedInvoiceVatGroup_ID (iiAbsorbedInvoiceVatGroupID), 
            input  tqVatRuleByVatRuleIDVatIDCode.tiAbsorbedCreditNVatGroup_ID (iiAbsorbedCreditNVatGroupID), 
            input  tqVatRuleByVatRuleIDVatIDCode.tiRetainVoucherVatGroup_ID (iiRetainVoucherVatGroupID), 
            input  tqVatRuleByVatRuleIDVatIDCode.tiRetainCVoucherVatGroup_ID (iiRetainCVoucherVatGroupID), 
            input  tqVatRuleByVatRuleIDVatIDCode.tlVatIsAbsorbed (ilVatIsAbsorbed), 
            input  tqVatRuleByVatRuleIDVatIDCode.tlVatIsRetained (ilVatIsRetained), 
            input  t_sPosting.PostingYear (iiPostingYear), 
            input  t_sPosting.PostingVoucher (iiPostingVoucher), 
            input  t_sPostingLine.PostingLineSequence (iiPostingLineSequence), 
            input  t_sPostingLine.tcGLCode (icPostingLineGLCode), 
            input  t_sPostingVat.tc_Rowid (icPostingVatTcRowid), 
            output t_sPostingVat.VatGroup_ID (oiDeterminedVatGroupID), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0
        then assign viLocalReturnStatus  = viFcReturnSuper.
        if viFcReturnSuper < 0
        then leave VATBLOCK.    
    end. /* if t_sPostingVat.tcVatCode  <> "":U and */
end. /* VATBLOCK */

/* ===================== */
/* Exception handling    */
/* ===================== */
assign oiReturnStatus = viLocalReturnStatus.