project QadFinancials > class BCreditorReport > method CreditorWHTCertificate

report procedure

Description

main procedure for Withholding Tax Certificate report


Parameters


icLanguageCodeinputcharacter
tFilterinputtemp-table
dcrCreditorWHTCertificateoutputdataset
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program1/bcreditorreport.p)

empty temp-table tqCreditorWHTCertificate.
empty temp-table tqCreditorWHTCertificateByPay.
empty temp-table tqCreditorWHTCerditicateComp.

<M-32 run GetReportLabels
   (input  'CreditorWHTCertificate':U (icReportName), 
    input  icLanguageCode (icLanguageCode), 
    input  tFilter (tFilter), 
    output tqHeader (tqHeader), 
    output tqFilter (tqFilter), 
    output tqText (tqText), 
    output viFcReturnSuper (oiReturnStatus)) in BCreditorReport>
    
if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
    assign oiReturnStatus = viFcReturnSuper.
    return.
end. /* if viFcReturnSuper < 0 */



<M-89 run SetDataItemsBasedOnFilterTT  (output viFcReturnSuper (oiReturnStatus)) in BCreditorReport>

/* Initialize some default values */
if viAccYearFilter1 < 1 then assign viAccYearFilter1 = ?.
if vcFromCreditorCodeFilter1 = "" then assign vcFromCreditorCodeFilter1 = ?.
if vcToCreditorCodeFilter1 = "" then assign vcToCreditorCodeFilter1 = ?.
if vcCRCompanyFilter = ? or vcCRCompanyFilter = "" then assign vcCRCompanyFilter = vcCompanyCode.
if vcCurrencyCodeFilter1 = ? or vcCurrencyCodeFilter1 = "" then assign vcCurrencyCodeFilter1  = vcCurrencyBC.

if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
    assign oiReturnStatus = viFcReturnSuper.
    return.
end. /* if viFcReturnSuper < 0 */

assign viCompanyIDLocal = 0.
for first tqCompanyByDomainActive
    where tqCompanyByDomainActive.tcCompanyCode = vcCRCompanyFilter:
    assign viCompanyIDLocal = tqCompanyByDomainActive.tiCompany_ID.
end.
if viCompanyIDLocal <= 0
then do:
    assign oiReturnStatus = 0.
    return.
end.

/* Validate Currency */
<Q-95 run CurrencyPrim (all) (Read) (NoCache)
   (input vcCurrencyCodeFilter1, (CurrencyCode)
    input ?, (Currency_ID)
    output dataset tqCurrencyPrim) in BCurrency >
find first tqCurrencyPrim no-error.
if not available tqCurrencyPrim or
   vcCurrencyCodeFilter1 = "" or
   vcCurrencyCodeFilter1 = ?
then do:
    assign oiReturnStatus = -1.
    <M-86 run SetMessage
       (input  #T-4'Please fill in a valid currency code.':255(934914366)T-4# (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'qadfin-533228':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCreditorReport>
    return.
end.

/* Get Currencies */
assign vhFcComponent = ?.
<Q-57 run CurrencyById (all) (Read) (NoCache)
   (input ?, (CurrencyId)
    output dataset tqCurrencyById) in BCurrency >

if vlReprintCertificateFilter <> true
then vlReprintCertificateFilter = false.
else vlReprintCertificateFilter = ?.

assign vcWHTIDList = "":U.

/* Get company information */
<Q-22 run CompanyForAddressInfo (all) (Read) (NoCache)
   (input viCompanyIDLocal, (CompanyId)
    output dataset tqCompanyForAddressInfo) in BCompany >
for each tqCompanyForAddressInfo:
    create tqCreditorWHTCerditicateComp.
    buffer-copy tqCompanyForAddressInfo to tqCreditorWHTCerditicateComp.
end.
find first tqCreditorWHTCerditicateComp no-error.
if not available tqCreditorWHTCerditicateComp
then do:
    assign oiReturnStatus = -1.
    <M-90 run SetMessage
       (input  #T-18'Could not get the Company information.':100(658630164)T-18# (icMessage), 
        input  '':U (icArguments), 
        input  '':U (icFieldName), 
        input  '':U (icFieldValue), 
        input  'E':U (icType), 
        input  3 (iiSeverity), 
        input  '':U (icRowid), 
        input  'qadfin-18798':U (icFcMsgNumber), 
        input  '':U (icFcExplanation), 
        input  '':U (icFcIdentification), 
        input  '':U (icFcContext), 
        output viFcReturnSuper (oiReturnStatus)) in BCreditorReport>
    return.
end.

<Q-20 run CreditorWT (all) (Read) (NoCache)
   (input viCompanyIDLocal, (CompanyId)
    input vcCertificateFormatFilter, (CertFormatCode)
    input vtFromCreationDateFilter, (FromCreateDate)
    input viFromCDocumentNumberFilter, (FromPaymentNumber)
    input ?, (FromVoucher)
    input viFromWHTNumberFilter, (FromWHTNumber)
    input vlReprintCertificateFilter, (IsPrinted)
    input vcPaySelCodeFilter, (PaySelCode)
    input vtToCreationDateFilter, (ToCreateDate)
    input vcToCreditorCodeFilter1, (ToCreditorCode)
    input ?, (toJournalCode)
    input viToCDocumentNumberFilter, (ToPaymentNumber)
    input ?, (ToVoucher)
    input viAccYearFilter1, (Year)
    input ?, (FromPeriod)
    input vcFromCreditorCodeFilter1, (FromCreditorCode)
    input ?, (FromJournalCode)
    input viToWHTNumberFilter, (ToWHTNumber)
    output dataset tqCreditorWT) in BCreditorReport >    

if ((viFromCDocumentNumberFilter = ? or viFromCDocumentNumberFilter = 0)  or
    (viToCDocumentNumberFilter   = ? or viToCDocumentNumberFilter   = 0)) and
   (vcPaySelCodeFilter = ? or vcPaySelCodeFilter = "":U)
then do :   
    <Q-6 run CreditorWTDirectBank (all) (Read) (NoCache)
       (input viCompanyIDLocal, (CompanyId)
        input ?, (FromVoucher)
        input ?, (ToVoucher)
        input vcCertificateFormatFilter, (CertFormatCode)
        input vcFromCreditorCodeFilter1, (FromCreditorCode)
        input ?, (FromJournalCode)
        input ?, (FromPeriod)
        input viFromWHTNumberFilter, (FromWHTNumber)
        input vlReprintCertificateFilter, (IsPrinted)
        input vtToCreationDateFilter, (ToCreateDate)
        input vcToCreditorCodeFilter1, (ToCreditorCode)
        input ?, (ToJournalCode)
        input viToWHTNumberFilter, (ToWHTNumber)
        input viAccYearFilter1, (Year)
        output dataset tqCreditorWTDirectBank) in BCreditorReport>
    
    for each tqCreditorWTDirectBank no-lock:
        create tqCreditorWT.
        buffer-copy tqCreditorWTDirectBank to tqCreditorWT.  
    end. /*for each tqCreditorWTDirectBank no-lock:*/                      
end. /*if ((viFromCDocumentNumberFilter = ? or viFromCDocumentNumberFilter = "":U) or*/
   
for each tqCreditorWT break by tqCreditorWT.tcCInvoiceReference by tqCreditorWT.tcVatCode:
    for first tqCurrencyById no-lock
    where tqCurrencyById.tiCurrency_ID = tqCreditorWT.tiCInvoiceCurrency_ID:
    end.
    if available tqCurrencyById
    then do:
        if tqCurrencyById.tcCurrencyCode = vcCurrencyCodeFilter1
        then do:
            assign
               vdVATExchangeRateTCtoRC = 1
               vdVATExchangeRateScaleFactor = 1
               vdExchangeRateTCtoRC = 1
               vdExchangeRateScaleFactor = 1.
        end.
        else do:
            /*Get VAT Exchangerate from TC to Report Currency*/
            <M-91 run GetExchangeRate
               (input  ? (iiCompanyID), 
                input  tqCreditorWT.tiCInvoiceCurrency_ID (iiFromCurrencyID), 
                input  ? (icFromCurrencyCode), 
                input  ? (iiToCurrencyID), 
                input  vcCurrencyCodeFilter1 (icToCurrencyCode), 
                input  ? (iiExchangeRateTypeID), 
                input  {&EXCHANGERATETYPE-VAT} (icExchangeRateTypeCode), 
                input  today (itValidityDate), 
                output vdVATExchangeRateTCtoRC (odExchangeRate), 
                output vdVATExchangeRateScaleFactor (odExchangeScaleFactor), 
                output oiReturnStatus (oiReturnStatus)) in BCreditorReport>
            if oiReturnStatus < 0 then 
            do:
              assign oiReturnStatus = -1.    
              return.
            end.
              
            /* Get Exchangerate from Transaction Currency to Reporting Currency */
             <M-80 run GetExchangeRate
                (input  ? (iiCompanyID), 
                 input  tqCreditorWT.tiCInvoiceCurrency_ID (iiFromCurrencyID), 
                 input  ? (icFromCurrencyCode), 
                 input  ? (iiToCurrencyID), 
                 input  vcCurrencyCodeFilter1 (icToCurrencyCode), 
                 input  ? (iiExchangeRateTypeID), 
                 input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode), 
                 input  today (itValidityDate), 
                 output vdExchangeRateTCtoRC (odExchangeRate), 
                 output vdExchangeRateScaleFactor (odExchangeScaleFactor), 
                 output oiReturnStatus (oiReturnStatus)) in BCreditorReport>
            if oiReturnStatus < 0 then 
            do:
              assign oiReturnStatus = -1.    
              return.
            end. /* if viFcReturnSuper < 0 */

        end. /* if tqCurrencyById... */
    end. /* if available tqCurrencyById */

    create tqCreditorWHTCertificate.
    buffer-copy tqCreditorWT to tqCreditorWHTCertificate.

    vdExchangeRateTCtoRC = vdExchangeRateTCtoRC * vdExchangeRateScaleFactor.
    vdVATExchangeRateTCtoRC = vdVATExchangeRateTCtoRC * vdVATExchangeRateScaleFactor.
    
    if tqCreditorWT.tcWHTChargeType = "WHTFEE" then
    do: 
        tqCreditorWHTCertificate.tdWHTFees         = (tqCreditorWT.tdWHTChargeAmtCreditTC - tqCreditorWT.tdWHTChargeAmtDebitTC)
                                                     * vdExchangeRateTCtoRC.
        tqCreditorWHTCertificate.tdWHTExpenseAmt   = 0. 
    end.
    
        
    if tqCreditorWT.tcWHTChargeType = "WHTEXPENSE" then
    do: 
        tqCreditorWHTCertificate.tdWHTFees         = 0.
        tqCreditorWHTCertificate.tdWHTExpenseAmt   = (tqCreditorWT.tdWHTChargeAmtCreditTC - tqCreditorWT.tdWHTChargeAmtDebitTC) 
                                                     * vdExchangeRateTCtoRC. 
    end.
    
    assign       
           tqCreditorWHTCertificate.tdWHTTax          = (tqCreditorWT.tdWHTVATAmtCreditTC - tqCreditorWT.tdWHTVATAmtDebitTC) * vdExchangeRateTCtoRC
           tqCreditorWHTCertificate.tdWHTAmt          = (tqCreditorWT.tdWHTAmtCreditTC - tqCreditorWT.tdWHTAmtDebitTC) * vdVATExchangeRateTCtoRC
           tqCreditorWHTCertificate.tdWHTInvoiceTotal = (tqCreditorWT.tdCInvoiceOriginalCreditTC - tqCreditorWT.tdCInvoiceOriginalDebitTC) * vdExchangeRateTCtoRC
           tqCreditorWHTCertificate.tdWHTTotalPaid    = (tqCreditorWT.tdWHTPaidAmtDebitTC - tqCreditorWT.tdWHTPaidAmtCreditTC) * vdExchangeRateTCtoRC
           tqCreditorWHTCertificate.tdWHTTaxableFees  = (tqCreditorWT.tdWHTTaxableFeesCreditTC - tqCreditorWT.tdWHTTaxableFeesDebitTC) * vdExchangeRateTCtoRC
           tqCreditorWHTCertificate.tiWHTMonth        = Month(tqCreditorWHTCertificate.ttWHTPaymentDate)
           tqCreditorWHTCertificate.tcCInvoiceReference = string(tqCreditorWT.tiCInvoicePostingYear) 
                               + "/" + tqCreditorWT.tcJournalCode + "/" + string(tqCreditorWT.tiCInvoiceVoucher, "999999999").
           tqCreditorWHTCertificate.tcCurrencyCodeFilter1 = vcCurrencyCodeFilter1.

    if lookup(string(tqCreditorWT.tiWHT_ID), vcWHTIDList, chr(4)) = 0
    then assign vcWHTIDList = vcWHTIDList + string(tqCreditorWT.tiWHT_ID) + chr(4).
end. /* for each tqCreditorWT */

if vlWHTCertificateByPayFilter = true
then do:

    <Q-31 run CreditorWHTByDocument (all) (Read) (NoCache)
       (input viCompanyIDLocal, (CompanyId)
        input vcFromCreditorCodeFilter1, (FromCreditorCode)
        input vcToCreditorCodeFilter1, (ToCreditorCode)
        input viFromWHTNumberFilter, (FromWHTNumber)
        input viToWHTNumberFilter, (ToWHTNumber)
        input viAccYearFilter1, (Year)
        input vcCertificateFormatFilter, (CertificateFormat)
        input viFromCDocumentNumberFilter, (FromPaymentNumber)
        input viToCDocumentNumberFilter, (ToPaymentNumber)
        input vcPaySelCodeFilter, (PaySelCode)
        input vtFromCreationDateFilter, (FromPaymentCreationDate)
        input vtToCreationDateFilter, (ToPaymentCreationDate)
        input vlReprintCertificateFilter, (IsPrinted)
        output dataset tqCreditorWHTByDocument) in BCreditorReport >
 /*
    define variable subtotalDisc as decimal init 0.
    define variable subtotalAlloc as decimal init 0.
    define variable subtotalRetained as decimal init 0.
 */
    define buffer bufWHTByDocument for tqCreditorWHTByDocument.

    for each tqCreditorWHTByDocument break by tqCreditorWHTByDocument.tiCdocument_ID:
        for first tqCurrencyById no-lock
        where tqCurrencyById.tiCurrency_ID = tqCreditorWHTByDocument.tiCInvoiceCurrency_ID:
        end.
        if available tqCurrencyById
        then do:
            if tqCurrencyById.tcCurrencyCode = vcCurrencyCodeFilter1
            then do:
                assign vdExchangeRateTCtoRC = 1
                       vdExchangeRateScaleFactor = 1
                       vdVATExchangeRateTCtoRC = 1
                       vdVATExchangeRateScaleFactor = 1.
            end.
            else do:

                /*Get VAT Exchangerate from TC to Report Currency*/
                <M-64 run GetExchangeRate
                   (input  ? (iiCompanyID), 
                    input  tqCreditorWHTByDocument.tiCInvoiceCurrency_ID (iiFromCurrencyID), 
                    input  ? (icFromCurrencyCode), 
                    input  ? (iiToCurrencyID), 
                    input  vcCurrencyCodeFilter1 (icToCurrencyCode), 
                    input  ? (iiExchangeRateTypeID), 
                    input  {&EXCHANGERATETYPE-VAT} (icExchangeRateTypeCode), 
                    input  today (itValidityDate), 
                    output vdVATExchangeRateTCtoRC (odExchangeRate), 
                    output vdVATExchangeRateScaleFactor (odExchangeScaleFactor), 
                    output oiReturnStatus (oiReturnStatus)) in BCreditorReport>
                if oiReturnStatus < 0 then 
                do:
                   assign oiReturnStatus = -1.    
                   return.
                end. /* if viFcReturnSuper < 0 */
              
                /* Get Accounting Exchangerate from Transaction Currency to Reporting Currency */
                <M-29 run GetExchangeRate
                   (input  ? (iiCompanyID), 
                    input  tqCreditorWHTByDocument.tiCInvoiceCurrency_ID (iiFromCurrencyID), 
                    input  ? (icFromCurrencyCode), 
                    input  ? (iiToCurrencyID), 
                    input  vcCurrencyCodeFilter1 (icToCurrencyCode), 
                    input  ? (iiExchangeRateTypeID), 
                    input  {&EXCHANGERATETYPE-ACCOUNTING} (icExchangeRateTypeCode), 
                    input  today (itValidityDate), 
                    output vdExchangeRateTCtoRC (odExchangeRate), 
                    output vdExchangeRateScaleFactor (odExchangeScaleFactor), 
                    output oiReturnStatus (oiReturnStatus)) in BCreditorReport>
                if oiReturnStatus < 0 then 
                do:
                  assign oiReturnStatus = -1.    
                  return.
                end. /* if viFcReturnSuper < 0 */

            end. /* if tqCurrencyById.tcCurrencyCode... */
        end. /* if available tqCurrencyById */


        vdExchangeRateTCtoRC = vdExchangeRateTCtoRC * vdExchangeRateScaleFactor.
        vdVATExchangeRateTCtoRC = vdVATExchangeRateTCtoRC * vdVATExchangeRateScaleFactor.
 
        create tqCreditorWHTCertificateByPay.
        buffer-copy tqCreditorWHTByDocument to tqCreditorWHTCertificateByPay.
  
        if first-of(tqCreditorWHTByDocument.tiCDocument_ID) then
        do:
           vdSubtotalDisc = 0.
           vdSubtotalAlloc = 0.
           vdSubtotalRetained = 0.
           vdSubtotalAmtPaid = 0.
/*
           <Q-53 run GetAmountByPayment (all) (Read) (NoCache)
              (input tqCreditorWHTByDocument.ticompany_id, (CompanyId)
               input tqCreditorWHTByDocument.ticdocument_id, (CDocumentID)
               output dataset tqGetAmountByPayment) in BCreditorReport >
           
           for each tqGetAmountByPayment:
              if tqGetAmountByPayment.tcCInvoiceType = "CREDITNOTE" then
                 vdSubtotalDisc = vdSubtotalDisc - (tqGetAmountByPayment.tdCdocumentInvoiceXrefDiscTc *  vdExchangeRateTCtoRC) .
              else
                 vdSubtotalDisc = vdSubtotalDisc + (tqGetAmountByPayment.tdCdocumentInvoiceXrefDiscTc *  vdExchangeRateTCtoRC) .
                 
              vdSubtotalAlloc = vdSubtotalAlloc + tqGetAmountByPayment.tdCdocumentInvoiceXrefAlloTc *  vdExchangeRateTCtoRC.
           end.
*/

           for each bufWHTByDocument where bufWHTByDocument.tiCDocument_id = tqCreditorWHTByDocument.tiCDocument_ID:
              
              vdSubtotalRetained = vdSubtotalRetained + (bufWHTByDocument.tdWHTRetainedAmtDebitTC - bufWHTByDocument.tdWHTRetainedAmtCreditTC) * vdExchangeRateTCtoRC.
              vdSubtotalAlloc = vdSubtotalAlloc + (bufWHTByDocument.tdWHTTotAmtCreditTC  - bufWHTByDocument.tdWHTTotAmtDebitTC) * vdExchangeRateTCtoRC.
              vdSubtotalDisc = vdSubtotalDisc +
                  ((bufWHTByDocument.tdWHTRetainedAmtDebitTC - bufWHTByDocument.tdWHTRetainedAmtCreditTC) - (bufWHTByDocument.tdWHTAmtCreditTC  - bufWHTByDocument.tdWHTAmtDebitTC ))
                     * vdExchangeRateTCtoRC.

              vdSubtotalAmtPaid = vdSubtotalAmtPaid + 
                         (bufWHTByDocument.tdWHTPaidAmtDebitTC - bufWHTByDocument.tdWHTPaidAmtCreditTC) * vdExchangeRateTCtoRC.
             
           end.
        end.
        
        assign 
               tqCreditorWHTCertificateByPay.tdWHTAmt         = (tqCreditorWHTByDocument.tdWHTAmtCreditTC - tqCreditorWHTByDocument.tdWHTAmtDebitTC) * vdVATExchangeRateTCtoRC
               tqCreditorWHTCertificateByPay.tdWHTTaxableFees = (tqCreditorWHTByDocument.tdWHTTaxableFeesCreditTC - tqCreditorWHTByDocument.tdWHTTaxableFeesDebitTC) * vdExchangeRateTCtoRC
               tqCreditorWHTCertificateByPay.tdAmountPaid     = vdSubtotalAmtPaid
               tqCreditorWHTCertificateByPay.tdCheckAmount    = vdSubtotalAlloc
               tqCreditorWHTCertificateByPay.tdDiscount       = vdSubtotalDisc
               tqCreditorWHTCertificateByPay.tdDeductions     = vdSubtotalRetained.
    end. /* for each tqCreditorWHTByDocument */
end. /* if vlWHTCertificateByPayFilter = true */

/* Run UpdateCInvoiceWHTPrintedStatus to mark the WHT records as printed. */
assign vcWHTIDList = trim(vcWHTIDList, chr(4)).

<I-68 {bFcStartAndOpenInstance
     &ADD-TO-TRANSACTION   = "no"
     &CLASS                = "BWithholdingTax"}>


<M-10 run UpdateWHTPrintedStatus
   (input  vcWHTIDList (icPKeys), 
    output viFcReturnSuper (oiReturnStatus)) in BWithholdingTax>

<M-52 run ValidateBCAndAdditionalUpdates  (output viFcReturnSuper (oiReturnStatus)) in BWithholdingTax>

<M-25 run DataSave  (output viFcReturnSuper (oiReturnStatus)) in BWithholdingTax>

if viFcReturnSuper <> 0 and viLocalReturnStatus >= 0
then assign viLocalReturnStatus = viFcReturnSuper.
if viFcReturnSuper < 0
then do:
    assign oiReturnStatus = viFcReturnSuper.
    return.
end. 

assign oiReturnStatus = viLocalReturnStatus.
<I-82 {bFcCloseInstance
     &CLASS           = "BWithholdingTax"}>