project QadFinancials > class BPosting > method GetPostingVatVatGroup

Description

GetPostingVatVatGroup: this method will receive a bunch of paramaters and decide in its program-code, which VatGroup shoudl be used on a certain combination of input paramater values


Parameters


icJournalTypeCodeinputcharacterType of the Journal that is statedin the header ofthe posting (mandatory).
icVatCodeinputcharacterVat-code that is stated in the taxes of the posting-vat record (mandatory).
iiVatRuleSequenceinputintegerVatRule-sequence that is stated in the taxes of the posting-vat record (mandatory).
iiInvoiceVatGroupIDinputintegerInvocieVatGroupID: corresponds with field InvoiceVatGroup_ID of the appropriate VatRule-record of the VatCode-record.
iiCreditNoteVatGroupIDinputintegerCreditNoteVatGroupID: corresponds with field CreditNoteVatGroup_ID of the appropriate VatRule-record of the VatCode-record.
iiAbsorbedInvoiceVatGroupIDinputintegerAbsorbedInvoiceVatGroupID: corresponds with field AbsorbedInvoiceVatGroup_ID of the appropriate VatRule-record of the VatCode-record.
iiAbsorbedCreditNVatGroupIDinputintegerAbsorbedCreditNVatGroupID: corresponds with field AbsorbedCreditNVatGroup_ID of the appropriate VatRule-record of the VatCode-record.
iiRetainVoucherVatGroupIDinputintegerRetainVoucherVatGroupID: corresponds with field RetainVoucherVatGroup_ID of the appropriate VatRule-record of the VatCode-record.
iiRetainCVoucherVatGroupIDinputintegerRetainCVoucherVatGroupID: corresponds with field RetainCVoucherVatGroup_ID of the appropriate VatRule-record of the VatCode-record.
ilVatIsAbsorbedinputlogicalVatIsAbsorbed: mandatory information comming from the Vat-definition
ilVatIsRetainedinputlogicalVatIsRetained: mandatory information comming from the Vat-definition
iiPostingYearinputintegerOptional parameter used to raise error-messages
iiPostingVoucherinputintegerOptional parameter used to raise error-messages
iiPostingLineSequenceinputintegerOptional parameter used to raise error-messages
icPostingLineGLCodeinputcharacterOptional parameter used to raise error-messages
icPostingVatTcRowidinputcharacterOptional: tc_rowid of the PostingVat-record (only used for messaging)
oiDeterminedVatGroupIDoutputintegerDeterminedVatGroupID: this will be the VatGroup_ID to be used for a certain PostingVat-based upon all the input information
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BPosting.ValidateComponentPreAssignVatGroup
method BJournalEntry.AutoUpdatePostingVatVatGroups


program code (program4/bposting.p)

/* =========================================================================================================================== */
    /* Method GetPostingVatVatGroup: this method will receive a bunch of paramaters and decide in its                              */
    /* program-code, which VatGroup should be used on a certain combination of input paramater values                              */
    /* Functional sequence:                                                                                                        */
    /* 1. Try to assign oiDeterminedVatGroupID based upon the Vat and VatRule specified in the PostingVat (input) 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 oiDeterminedVatGroupID based upon the Vat and VatRule specified in the PostingVat (input): 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 oiDeterminedVatGroupID then raise an error.                                   */
    /* =========================================================================================================================== */
    
    /* ===================== */
    /* Exception handling    */
    /* ===================== */
    assign oiReturnStatus = -98.
    
    
    /* =========================================================================================================================== */
    /* 0. First validate whether the required information is available:                                                            */
    /* JournalType, VatCode, VatRuleSequence                                                                                       */
    /* =========================================================================================================================== */
    assign vcMessage = "":U.
    if icJournalTypeCode = "":U or 
       icJournalTypeCode = ?
    then assign vcMessage = vcMessage + chr(10) + 
                            trim(#T-12'Cannot identify the tax group of a tax posting because the daybook code has not been specified on the posting.':255(65617)t-12#).
    if icVatCode = "":U or 
       icVatCode = ?
    then assign vcMessage = vcMessage + chr(10) + 
                            trim(#T-13'Cannot identify the tax group of a tax posting because the tax code on the VAT posting has not been specified.':255(65618)t-13#).
    if iiVatRuleSequence = 0 or 
       iiVatRuleSequence = ?
    then assign vcMessage = vcMessage + chr(10) + 
                            trim(#T-14'Cannot identify the tax group of a tax posting because the tax rule on the VAT posting has not been specified.':255(65619)t-14#).
    if ilVatIsAbsorbed= ? or 
       ilVatIsRetained = ?
    then assign vcMessage = vcMessage + chr(10) + 
                            trim(#T-51'Cannot identify the tax group of a tax posting because the Absorbed / Retained fields of the tax are not selected.':255(65622)t-51#).
    if vcMessage <> "":U
    then do :
        assign viLocalReturnStatus  = -1
               vcMessage            = trim(substitute(#T-15'The posting &1/&2/&3 is missing VAT group information. See details below.':255(64028)t-15#,string(iiPostingYear),icJournalTypeCode,string(iiPostingVoucher))) + chr(10) + 
                                      trim(substitute(#T-16'Posting line: sequence &1, GL account code &2.':255(64066)t-16#,iiPostingLineSequence,icPostingLineGLCode)) + 
                                      vcMessage.
        <M-1 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tPostingVat.tcVatCode':U (icFieldName), 
            input  icVatCode (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  icPostingVatTcRowid (icRowid), 
            input  'QadFin-7223':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
        next.
    end. /* if vcMessage <> "":U */
    
    /* ================================== */
    /* Main processing: Step 1 and step 2 */
    /* ================================== */
    assign vcMessage = "":U.
    if icJournalTypeCode = {&JOURNALTYPE-CREDITORCREDITNOTE}        or
       icJournalTypeCode = {&JOURNALTYPE-CREDITORCREDITNOTECORRECT} or
       icJournalTypeCode = {&JOURNALTYPE-DEBTORCREDITNOTE}          or
       icJournalTypeCode = {&JOURNALTYPE-DEBTORCREDITNOTECORRECT}
    then do :
        /* =========================================================================================================================== */
        /* 1. Try to assign oiDeterminedVatGroupID based upon the Vat and VatRule specified in the PostingVat (input) and based upon   */
        /*    the journal (invoice-creditnote) of the posting. If such a VatGroup can be found then use it on the PostingVat.          */
        /* This block concerns the credit-note side                                                                                    */
        /* =========================================================================================================================== */
        if iiVatRuleSequence > 1 and ilVatIsAbsorbed = true 
        then do :
            if iiAbsorbedCreditNVatGroupID <> 0 and 
               iiAbsorbedCreditNVatGroupID <> ?
            then assign oiDeterminedVatGroupID = iiAbsorbedCreditNVatGroupID.
            else assign vcMessage = trim(substitute(#T-22'Tax code &1 is marked as &2 but the associated tax group for the credit notes has not been specified.':255(64072)t-22#,icVatCode,trim(#T-23'Absorbed':50(64073)T-23#))).
        end. /* if ilVatIsAbsorbed = true */
        else do :
            if iiVatRuleSequence > 1 and ilVatIsRetained = true
            then do:
                if iiRetainCVoucherVatGroupID <> 0 and 
                   iiRetainCVoucherVatGroupID <> ?
                then assign oiDeterminedVatGroupID = iiRetainCVoucherVatGroupID.
                else assign vcMessage = trim(substitute(#T-24'Tax code &1 is marked as &2 but the associated tax group for the credit notes has not been specified.':255(64072)t-24#,icVatCode,trim(#T-25'Retained':50(64074)T-25#))).
            end. /* if ilVatIsRetained = true */
            else do :
                if iiVatRuleSequence      <= 1 and 
                   iiCreditNoteVatGroupID <> 0 and 
                   iiCreditNoteVatGroupID <> ?
                then assign oiDeterminedVatGroupID = iiCreditNoteVatGroupID.
                else assign vcMessage = trim(substitute(#T-26'Tax code &1 is marked as &2 but the associated tax group for the credit notes has not been specified.':255(64072)t-26#,icVatCode,trim(#T-27'Normal':50(64075)T-27#))).
            end.  /* Not if ilVatIsRetained = true */
        end. /* Not if ilVatIsAbsorbed = true */ 
    end. /* if icJournalTypeCode = {&JOURNALTYPE-CREDITORCREDITNOTE}        or */
    else do :
        if icJournalTypeCode = {&JOURNALTYPE-CREDITORINVOICE}        or
           icJournalTypeCode = {&JOURNALTYPE-CREDITORINVOICECORRECT} or
           icJournalTypeCode = {&JOURNALTYPE-DEBTORINVOICE}          or
           icJournalTypeCode = {&JOURNALTYPE-DEBTORINVOICECORRECT}   or
           icJournalTypeCode = {&JOURNALTYPE-DEBTORFINANCECHARGE}
        then do :
            /* =========================================================================================================================== */
            /* 1. Try to assign oiDeterminedVatGroupID based upon the Vat and VatRule specified in the PostingVat (input) and based upon   */
            /*    the journal (invoice-creditnote) of the posting. If such a VatGroup can be found then use it on the PostingVat.          */
            /* This block concerns the invoice side                                                                                        */
            /* =========================================================================================================================== */
            if iiVatRuleSequence > 1 and ilVatIsAbsorbed = true 
            then do :
                if iiAbsorbedInvoiceVatGroupID <> 0 and 
                   iiAbsorbedInvoiceVatGroupID <> ?
                then assign oiDeterminedVatGroupID = iiAbsorbedInvoiceVatGroupID.
                else assign vcMessage = trim(substitute(#T-28'Tax code &1 is marked as &2 but the associated tax group for the invoices has not been specified.':255(64077)t-28#,icVatCode,trim(#T-29'Absorbed':50(64073)T-29#))).
            end. /* if ilVatIsAbsorbed = true */
            else do :
                if iiVatRuleSequence > 1 and ilVatIsRetained = true
                then do:
                    if iiRetainVoucherVatGroupID <> 0 and 
                       iiRetainVoucherVatGroupID <> ?
                    then assign oiDeterminedVatGroupID = iiRetainVoucherVatGroupID.
                    else assign vcMessage = trim(substitute(#T-30'Tax code &1 is marked as &2 but the associated tax group for the invoices has not been specified.':255(64077)t-30#,icVatCode,trim(#T-31'Retained':50(64074)T-31#))).
                end. /* if ilVatIsRetained = true */
                else do :
                    if iiVatRuleSequence   <= 1 and 
                       iiInvoiceVatGroupID <> 0 and 
                       iiInvoiceVatGroupID <> ?
                    then assign oiDeterminedVatGroupID = iiInvoiceVatGroupID.
                    else assign vcMessage = trim(substitute(#T-32'Tax code &1 is marked as &2 but the associated tax group for the invoices has not been specified.':255(64077)t-32#,icVatCode,trim(#T-33'Normal':50(64075)T-33#))).
                end.  /* Not if ilVatIsRetained = true */
            end. /* Not if ilVatIsAbsorbed = true */  
        end. /* if icJournalTypeCode = {&JOURNALTYPE-CREDITORINVOICE}        or */
        else do :
            /* =========================================================================================================================== */
            /* 2. Try to assign oiDeterminedVatGroupID based upon the Vat and VatRule specified in the PostingVat (input): 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 */
            /* This block concerns the non-credit-note, not-invoice transactions                                                           */
            /* =========================================================================================================================== */
            if iiVatRuleSequence > 1 and ilVatIsAbsorbed = true 
            then do :
                if iiAbsorbedInvoiceVatGroupID <> 0 and 
                   iiAbsorbedInvoiceVatGroupID <> ?
                then assign oiDeterminedVatGroupID = iiAbsorbedInvoiceVatGroupID.
                else assign vcMessage = trim(substitute(#T-34'Tax code &1 is marked as &2 but the associated tax group for non-invoices and non-credit notes has not been specified.':255(64079)t-34#,icVatCode,trim(#T-35'Absorbed':50(64073)T-35#))).
            end. /* if ilVatIsAbsorbed = true */
            else do :
                if iiVatRuleSequence > 1 and ilVatIsRetained = true
                then do:
                    if iiRetainVoucherVatGroupID <> 0 and 
                       iiRetainVoucherVatGroupID <> ?
                    then assign oiDeterminedVatGroupID = iiRetainVoucherVatGroupID.
                    else assign vcMessage = trim(substitute(#T-36'Tax code &1 is marked as &2 but the associated tax group for non-invoices and non-credit notes has not been specified.':255(64079)t-36#,icVatCode,trim(#T-37'Retained':50(64074)T-37#))).
                end. /* if ilVatIsRetained = true */
                else do :
                    if iiVatRuleSequence    <= 1 and 
                       iiInvoiceVatGroupID  <> 0 and 
                       iiInvoiceVatGroupID  <> ?
                    then assign oiDeterminedVatGroupID = iiInvoiceVatGroupID.
                    else assign vcMessage = trim(substitute(#T-38'Tax code &1 is marked as &2 but the associated tax group for non-invoices and non-credit notes has not been specified.':255(64079)t-38#,icVatCode,trim(#T-39'Normal':50(64075)T-39#))).
                end.  /* Not if ilVatIsRetained = true */
            end. /* Not if ilVatIsAbsorbed = true */  
        end. /* Not if icJournalTypeCode = {&JOURNALTYPE-CREDITORINVOICE}        or */
    end. /* Not if icJournalTypeCode = {&JOURNALTYPE-CREDITORCREDITNOTE}        or */
    if vcMessage <> "":U 
    then do : 
        assign viLocalReturnStatus  = -1
               vcMessage            = vcMessage + chr(10) + 
                                      trim(substitute(#T-40'Posting: &1/&2/&3':255(64076)T-40#,string(iiPostingYear),icJournalTypeCode,string(iiPostingVoucher))) + chr(10) + 
                                      trim(substitute(#T-41'Posting line: sequence &1, GL account code &2.':255(64066)t-41#,string(iiPostingLineSequence),icPostingLineGLCode)) + chr(10) +
                                      trim(substitute(#T-42'Tax code: &1':255(64048)t-42#,icVatCode)) + chr(10) +
                                      trim(substitute(#T-43'Tax rule seq: &1':255(65620)t-43#,string(iiVatRuleSequence)))
               vhFcComponent        = ?.
        <M-8 run CreateCorruption
           (input  'VAT':U (icTableName), 
            input  vcDomainCode + '/':U + icvatCode (icKey), 
            input  vcMessage (icDescription), 
            input  false (ilSkipMessage), 
            output viFcReturnSuper (oiReturnStatus)) in BCorrLog>
    end. /* if vcMessage <> "":U */
    
    /* =============================================================== */
    /* 3. Raise an error in case the VatGroup is not yet filled by now */
    /* =============================================================== */
    if oiDeterminedVatGroupID = 0 or 
       oiDeterminedVatGroupID = ?
    then do: 
        assign viLocalReturnStatus  = -1
               vcMessage            = trim(substitute(#T-45'Cannot identify the tax group for the tax posting &1/&2/&3 based on the daybook code, tax code and tax rule.':255(64044)t-45#,string(iiPostingYear),icJournalTypeCode,string(iiPostingVoucher))) + chr(10) + 
                                      trim(substitute(#T-46'Posting line: sequence &1, GL account code &2.':255(64066)t-46#,iiPostingLineSequence,icPostingLineGLCode)) + chr(10) + 
                                      trim(substitute(#T-47'Daybook: &1':255(64047)T-47#,icJournalTypeCode)) + chr(10) + 
                                      trim(substitute(#T-48'Daybook type: &1':255(64046)t-48#,icJournalTypeCode)) + chr(10) + 
                                      trim(substitute(#T-49'Tax code: &1':255(64048)t-49#,icVatCode)) + chr(10) + 
                                      trim(substitute(#T-50'Tax rule seq: &1':255(65623)t-50#,string(iiVatRuleSequence))).
        <M-9 run SetMessage
           (input  vcMessage (icMessage), 
            input  '':U (icArguments), 
            input  'tPostingVat.tcVatCode':U (icFieldName), 
            input  icVatCode (icFieldValue), 
            input  'E':U (icType), 
            input  3 (iiSeverity), 
            input  icPostingVatTcRowid (icRowid), 
            input  'QadFin-7226':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BPosting>
    end. /* if oiDeterminedVatGroupID = 0 or  */
    
    /* ===================== */
    /* Exception handling    */
    /* ===================== */
    assign oiReturnStatus = viLocalReturnStatus.