project QadFinancials > class BWithholdingTax > method CreateAndOrUpdateWHTSubExpense

Description

CreateAndOrUpdateWHTSubExpense: sub-method of CreateAndOrUpdateWHTSub that will create and/or update the WHT records based on input temp-table that differs from the class-table


Parameters


idCInvoiceTotalWHTAmtTCinputdecimal
idProRataAllocatedWHTinputdecimal
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BWithholdingTax.CreateAndOrUpdateWHTSub


program code (program7/bwithholdingtax.p)

/* ============================================================================================================== */
/* This method is a submethod of CreateAndOrUpdateWHTSub that is a submethod of CreateAndOrUpdateWHT              */
/*  - see that method for all details                                                                             */
/* ============================================================================================================== */
/* By now, we have loaded all instance-datas and created the new instances and filled there logical key           */
/* Now we will assign the other fields for the WHT-records that represent an Expense                              */
/* ============================================================================================================== */        

/* ==================================== */
/* Exception Handling - Initialisation  */
/* ==================================== */ 
assign oiReturnStatus           = -98
       viLocalReturnStatus      = 0.

/* =========== */
/* Start block */       
/* =========== */
EXPENSEBLOCK: DO :

    /* ================================================================ */
    /* Check that everything that that should be available is available */
    /* ================================================================ */
    assign vcMessage = "":U.
    if not available tInvoiceWHTPayment 
    then assign vcMessage = trim(substitute(#T-63'Internal error: A record of table &2 should be available but this is not the case. Method:=&1.':255(566293675)T-63#,"BWithholdingTax:CreateAndOrUpdateWHTSub":U,"tInvoiceWHTPayment":U)).
    if vcMessage = "":U and 
       not available tqCInvoiceWHTForWHTCreation 
    then assign vcMessage = trim(substitute(#T-23'Internal error: A record of table &2 should be available but this is not the case. Method:=&1.':255(566293675)T-23#,"BWithholdingTax:CreateAndOrUpdateWHTSub":U,"tqCInvoiceWHTForWHTCreation":U)).
    if vcMessage = "":U and 
       not available tWHT
    then assign vcMessage = trim(substitute(#T-28'Internal error: A record of table &2 should be available but this is not the case. Method:=&1.':255(566293675)T-28#,"BWithholdingTax:CreateAndOrUpdateWHTSub":U,"tWHT":U)).
    if vcMessage <> "":U
    then do :
        assign viLocalReturnStatus = -3.
        <M-32 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-63100':U (icFcMsgNumber), 
            input  '':U (icFcExplanation), 
            input  '':U (icFcIdentification), 
            input  '':U (icFcContext), 
            output viFcReturnSuper (oiReturnStatus)) in BWithholdingTax>
        leave EXPENSEBLOCK.
    end. /* if vcMessage <> "":U*/
    
    /* ==================================================================== */
    /* Assign all main fields of the WHT record that represents the Expense */
    /* ==================================================================== */
    assign /* Fill the ID fields - that aren't part of the logical key as those are already filled (tWHT.Company_ID - tWHT.CInvoiceWHT_ID - tWHT.BankStateAlloc_ID - tWHT.CDocumentInvoiceXref_ID - tWHT.WHTChargeType - tWHT.OIAdjustLn_ID - tWHT.CACInvoice_ID) */
           tWHT.Vat_ID                   = tqCInvoiceWHTForWHTCreation.tiVat_ID
           tWHT.CInvoice_ID              = tqCInvoiceWHTForWHTCreation.tiCInvoice_ID
           /* Fill in the upd RKBF */
           tWHT.tcCreditorCode           = tqCInvoiceWHTForWHTCreation.tcCreditorCode
           tWHT.tcGLCode                 = tqCInvoiceWHTForWHTCreation.tcGLCode
           tWHT.tcDivisionCode           = tqCInvoiceWHTForWHTCreation.tcDivisionCode
           tWHT.tcCostCentreCode         = tqCInvoiceWHTForWHTCreation.tcCostCentreCode
           tWHT.tcProjectCode            = tqCInvoiceWHTForWHTCreation.tcProjectCode
           tWHT.tcWHTCertFormatCode      = tqCInvoiceWHTForWHTCreation.tcWHTCertFormatCode
           tWHT.tcCurrencyCode           = tInvoiceWHTPayment.tcCurrencyCode
           /* Fill in the status of the WHT */
           tWHT.WHTStatus                = tInvoiceWHTPayment.tcWHTStatus
           /* Fill in the redundantly stored WHT fields */
           tWHT.WHTPeriodYear            = tInvoiceWHTPayment.tiPaymentAccountingYear
           tWHT.WHTPeriodPeriod          = tInvoiceWHTPayment.tiPaymentAccountingPeriod
           tWHT.WHTTaxType               = tqCInvoiceWHTForWHTCreation.tctx2_tax_type
           tWHT.WHTCreditorCode          = tqCInvoiceWHTForWHTCreation.tcCreditorCode
           tWHT.WHTCreditorSharedSetCode = tqCInvoiceWHTForWHTCreation.tcSharedSetCode
           tWHT.WHTCompanyCode           = tqCInvoiceWHTForWHTCreation.tcCompanyCode
           tWHT.WHTCompanyLCCurrencyCode = tqCInvoiceWHTForWHTCreation.tcLocalCurrencyCurrencyCode.
    
    /* ================================================================ */
    /* Assign amounts of the WHT record that represents the Expense     */
    /* ================================================================ */
    if tInvoiceWHTPayment.tlCreateWHT        = true or 
       tInvoiceWHTPayment.tlUpdateAllAmounts = true 
    then do :
        assign /* Store the discounts in data-items as they are used later on in the assignements */
               vdDiscountDebitTC             = if tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or 
                                                  tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}
                                               then (tInvoiceWHTPayment.tdDiscountAmountTC *
                                                     tqCInvoiceWHTForWHTCreation.tdCInvoiceWHTExpenseDebitTC / 
                                                     (tqCInvoiceWHTForWHTCreation.tdCInvoiceOriginalDebitTC - tqCInvoiceWHTForWHTCreation.tdCInvoiceVatCreditTC - tqCInvoiceWHTForWHTCreation.tdCInvoiceNonDiscAmtTC))
                                               else 0
               vdDiscountCreditTC            = if tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICE} or 
                                                  tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
                                               then (tInvoiceWHTPayment.tdDiscountAmountTC *
                                                     tqCInvoiceWHTForWHTCreation.tdCInvoiceWHTExpenseCreditTC / 
                                                    (tqCInvoiceWHTForWHTCreation.tdCInvoiceOriginalCreditTC - tqCInvoiceWHTForWHTCreation.tdCInvoiceVatDebitTC - tqCInvoiceWHTForWHTCreation.tdCInvoiceNonDiscAmtTC))
                                               else 0
               /* WHT Rate % must always be zero for expenses */
               tWHT.WHTPercentage            = 0
               /* Fill in the normal WHT fields */   
               tWHT.WHTCInvoicePostingDate   = tqCInvoiceWHTForWHTCreation.ttCInvoicePostingDate
               tWHT.WHTPaymentDate           = tInvoiceWHTPayment.ttPostingDate
               tWHT.WHTPaymentReference      = tInvoiceWHTPayment.tcPaymentReference
               tWHT.WHTCInvoiceReference     = substring(string(tqCInvoiceWHTForWHTCreation.tiCInvoicePostingYear)            + "/":U +
                                                         tqCInvoiceWHTForWHTCreation.tcJournalCode                            + "/":U +
                                                         string(tqCInvoiceWHTForWHTCreation.tiCInvoiceVoucher, "999999999":U) + "/":U +
                                                         tqCInvoiceWHTForWHTCreation.tcCInvoiceReference,
                                                         1,50,'Character':U)
               tWHT.WHTIsPrinted             = false
               tWHT.WHTChargeType            = {&WHTCHARGETYPE-EXPENSE}
               tWHT.WHTChargeAmtDebitTC      = tqCInvoiceWHTForWHTCreation.tdCInvoiceWHTExpenseDebitTC * idProRataAllocatedWHT 
               tWHT.WHTChargeAmtCreditTC     = tqCInvoiceWHTForWHTCreation.tdCInvoiceWHTExpenseCreditTC * idProRataAllocatedWHT 
               tWHT.WHTRetainedAmtDebitTC    = if tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICE} or 
                                                  tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
                                               then vdDiscountCreditTC
                                               else 0
               tWHT.WHTRetainedAmtCreditTC   = if tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICE} or 
                                                  tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
                                               then 0
                                               else vdDiscountDebitTC
               tWHT.WHTVATAmtDebitTC         = if tWHT.tc_Status = "N":U and 
                                                  (tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-CREDITNOTE} or 
                                                   tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}) and 
                                                  tqCInvoiceWHTForWHTCreation.tdCInvoiceVatCreditTC <> 0
                                               then (tqCInvoiceWHTForWHTCreation.tdCInvoiceVatCreditTC * tWHT.WHTChargeAmtDebitTC /
                                                     tqCInvoiceWHTForWHTCreation.tdCInvoiceVatBaseCreditTC)
                                               else 0
               tWHT.WHTVATAmtCreditTC        = if tWHT.tc_Status = "N":U and 
                                                  (tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICE} or 
                                                   tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}) and 
                                                  tqCInvoiceWHTForWHTCreation.tdCInvoiceVatDebitTC <> 0
                                               then (tqCInvoiceWHTForWHTCreation.tdCInvoiceVatDebitTC * tWHT.WHTChargeAmtCreditTC / 
                                                     tqCInvoiceWHTForWHTCreation.tdCInvoiceVatBaseDebitTC)
                                               else 0           
               tWHT.WHTVATAmtDebitTC         = <M-83 RoundAmount
                                                  (input  tWHT.WHTVATAmtDebitTC (idUnroundedAmount), 
                                                   input  ? (iiCurrencyID), 
                                                   input  tInvoiceWHTPayment.tcCurrencyCode (icCurrencyCode)) in BWithholdingTax>
               tWHT.WHTVATAmtCreditTC        = <M-7 RoundAmount
                                                  (input  tWHT.WHTVATAmtCreditTC (idUnroundedAmount), 
                                                   input  ? (iiCurrencyID), 
                                                   input  tInvoiceWHTPayment.tcCurrencyCode (icCurrencyCode)) in BWithholdingTax>                                                                                  
               /* If The CI holds retained-amounts then the vat amount must both be zero in thw WHT -  ticket FIN-4018 */
               tWHT.WHTVATAmtDebitTC         = if tqCInvoiceWHTForWHTCreation.tdCInvoiceVatDebitTC  <> 0 and
                                                  tqCInvoiceWHTForWHTCreation.tdCInvoiceVatCreditTC <> 0
                                               then 0
                                               else tWHT.WHTVATAmtDebitTC
               tWHT.WHTVATAmtCreditTC        = if tqCInvoiceWHTForWHTCreation.tdCInvoiceVatDebitTC  <> 0 and
                                                  tqCInvoiceWHTForWHTCreation.tdCInvoiceVatCreditTC <> 0
                                               then 0
                                               else tWHT.WHTVATAmtCreditTC
               tWHT.WHTTotAmtDebitTC         = tWHT.WHTChargeAmtDebitTC + tWHT.WHTVATAmtDebitTC
               tWHT.WHTTotAmtCreditTC        = tWHT.WHTChargeAmtCreditTC + tWHT.WHTVATAmtCreditTC
               tWHT.WHTPaidAmtDebitTC        = if tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICE} or 
                                                  tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
                                               then (tWHT.WHTTotAmtCreditTC - tWHT.WHTRetainedAmtDebitTC)
                                               else 0
               tWHT.WHTPaidAmtCreditTC       = if tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICE} or 
                                                  tqCInvoiceWHTForWHTCreation.tcCInvoiceType = {&INVOICETYPE-INVOICECORRECTION}
                                               then 0
                                               else (tWHT.WHTTotAmtDebitTC - tWHT.WHTRetainedAmtCreditTC)
               no-error. /* Needed as we are doing complex calculations in the previous large assign statement */
        /* Check for Progress-errors and raise error when needed */
        if error-status:error
        then do :
            assign viLocalReturnStatus  = -3
                   vcMessage      = trim(substitute(#T-21'Internal error occured while assigning the details of the Withholding Taxes.':255(206547406)T-21#),"1":U).
            if error-status:num-messages > 0
            then assign vcMessage = vcMessage + chr(10) + 
                                    trim(substitute(#T-95'Detailed info: &1 (&2)':252(49824)T-95#,error-status:Get-Message(1),string(error-status:Get-Number(1)))).
            <M-91 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-197057':U (icFcMsgNumber), 
                input  '':U (icFcExplanation), 
                input  '':U (icFcIdentification), 
                input  '':U (icFcContext), 
                output viFcReturnSuper (oiReturnStatus)) in BWithholdingTax>
            leave EXPENSEBLOCK.
        end. /* if error-status:error */  
    end. /* if tInvoiceWHTPayment.tlCreateWHT        = true or  */                                         
        
END. /* EXPENSEBLOCK */

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