project QadFinancials > class BCInvoice > method GetInvoiceAmount

Description

This method calculates amount of supplier invoice. Both total amount and VAT amounts


Parameters


iiCInvoiceIdinputinteger
olIsCInvoiceLoadedoutputlogicalIndicating, whether supplier invoice is loaded in instance of supplier invoice or not.
ocCurrencyCodeoutputcharacter
odAmountTCoutputdecimal
odAmountLCoutputdecimal
odDiscountPercentageoutputdecimal
odTaxAcrueReceiptRecovTCoutputdecimal
odTaxAcrueReceiptNonRecovTCoutputdecimal
odTaxAcrueInvoiceRecovTCoutputdecimal
odTaxAcrueInvoiceNonRecovTCoutputdecimal
odTaxAcrueReceiptRecovLCoutputdecimal
odTaxAcrueReceiptNonRecovLCoutputdecimal
odTaxAcrueInvoiceRecovLCoutputdecimal
odTaxAcrueInvoiceNonRecovLCoutputdecimal
oiReasonIdoutputinteger
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BAPMatching.DefaultValuesInvoiceAmount


program code (program6/bcinvoice.p)

/* =================================================================================================== */
/* Method      : GetInvoiceAmount                                                                      */
/* Desc        : This method calculates total amount of invoice and all kind of tax amounts. This      */
/*               is only working with supplier invoices readed in instance of component                */
/* --------------------------------------------------------------------------------------------------- */
/* Params:  (I)  CInvoiceId                ID of Supplier invoice                                      */
/*          (O)  IsCInvoiceLoaded          Flag indicating, whether invoice is loaded in instance of   */
/*                                         component                                                   */
/*          (O)  Currency                  Currency code                                               */
/*          (O)  AmountTC                  Amount of invoice in TC                                     */
/*          (O)  AmountLC                  Amount of invoice in LC                                     */
/*          (O)  DiscountPercentage        Percentage of discount                                      */
/*          (O)  TaxAcrueReceiptRecovTC    Amount of tax accrued at receipt recoverable                */
/*          (O)  TaxAcrueReceiptNonRecovTC Amount of tax accrued at receipt non recoverable            */
/*          (O)  TaxAcrueInvoiceRecovTC    Amount of tax accrued at invoice recoverable                */
/*          (O)  TaxAcrueInvoiceNonRecovTC Amount of tax accured at invoice non recoverable            */
/* =================================================================================================== */

assign oiReturnStatus = -98.

/* =================================================================================================== */
/* Default output values                                                                               */
/* =================================================================================================== */
assign olIsCInvoiceLoaded          = false
       ocCurrencyCode              = '':U
       odAmountTC                  = 0
       odAmountLC                  = 0
       odDiscountPercentage        = 0
       odTaxAcrueReceiptRecovTC    = 0
       odTaxAcrueReceiptNonRecovTC = 0
       odTaxAcrueInvoiceRecovTC    = 0
       odTaxAcrueInvoiceNonRecovTC = 0
       odTaxAcrueReceiptRecovLC    = 0
       odTaxAcrueReceiptNonRecovLC = 0
       odTaxAcrueInvoiceRecovLC    = 0
       odTaxAcrueInvoiceNonRecovLC = 0
       oiReasonId                  = ?.

/* =================================================================================================== */
/* Normalize input parameters                                                                          */
/* =================================================================================================== */
if iiCInvoiceId = 0 then assign iiCInvoiceId = ?.

/* =================================================================================================== */
/* Validate input parameters                                                                           */
/* =================================================================================================== */
if iiCInvoiceId = ?
then do:
    assign oiReturnStatus = 0.
    return.
end.

find tCInvoice where
     tCInvoice.CInvoice_ID = iiCInvoiceId
     no-error.
if not available tCInvoice
then do:
    assign oiReturnStatus = 0.
    return.
end.

assign olIsCInvoiceLoaded = true.

/* =================================================================================================== */
/* Calculate amounts                                                                                   */
/* =================================================================================================== */
for each tCInvoiceVat where
         tCInvoiceVat.tc_ParentRowid = tCInvoice.tc_Rowid and
         tCInvoiceVat.tc_Status     <> 'D':U:
        
    if tCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTE} or 
       tCInvoice.CInvoiceType = {&INVOICETYPE-CREDITNOTECORRECTION}
    then assign vdNonRecTaxAmtTC  = - tCInvoiceVat.CInvoiceVatNonRecTaxAmtTC
                vdTotalTaxAmtTC   = vdTotalTaxAmtTC - tCInvoiceVat.CInvoiceVatVatDebitTC + tCInvoiceVat.CInvoiceVatVatCreditTC.
    else assign vdNonRecTaxAmtTC  = tCInvoiceVat.CInvoiceVatNonRecTaxAmtTC
                vdTotalTaxAmtTC   = vdTotalTaxAmtTC + tCInvoiceVat.CInvoiceVatVatDebitTC - tCInvoiceVat.CInvoiceVatVatCreditTC.        .
    
    if tCInvoiceVat.CInvoiceVatIsAccrRcpUs
    then assign odTaxAcrueReceiptRecovTC    = odTaxAcrueReceiptRecovTC
                                            + tCInvoiceVat.CInvoiceVatVatDebitTC
                                            - tCInvoiceVat.CInvoiceVatVatCreditTC 
                                            - vdNonRecTaxAmtTC
                odTaxAcrueReceiptNonRecovTC = odTaxAcrueReceiptNonRecovTC
                                            + vdNonRecTaxAmtTC.
    else assign odTaxAcrueInvoiceRecovTC    = odTaxAcrueInvoiceRecovTC
                                            + tCInvoiceVat.CInvoiceVatVatDebitTC
                                            - tCInvoiceVat.CInvoiceVatVatCreditTC 
                                            - vdNonRecTaxAmtTC
                odTaxAcrueInvoiceNonRecovTC = odTaxAcrueInvoiceNonRecovTC
                                            + vdNonRecTaxAmtTC.
end. /* for each tCInvoiceVat where */

assign odTaxAcrueReceiptRecovLC    = <M-2 RoundAmount
                                        (input  odTaxAcrueReceiptRecovTC * tCInvoice.CInvoiceExchangeRate * tCInvoice.CInvoiceRateScale (idUnroundedAmount), 
                                         input  viCompanyLCId (iiCurrencyID), 
                                         input  ? (icCurrencyCode)) in BCInvoice>
       odTaxAcrueReceiptNonRecovLC = <M-3 RoundAmount
                                        (input  odTaxAcrueReceiptNonRecovTC * tCInvoice.CInvoiceExchangeRate * tCInvoice.CInvoiceRateScale (idUnroundedAmount), 
                                         input  viCompanyLCId (iiCurrencyID), 
                                         input  ? (icCurrencyCode)) in BCInvoice>
       odTaxAcrueInvoiceRecovLC    = <M-4 RoundAmount
                                        (input  odTaxAcrueInvoiceRecovTC * tCInvoice.CInvoiceExchangeRate * tCInvoice.CInvoiceRateScale (idUnroundedAmount), 
                                         input  viCompanyLCId (iiCurrencyID), 
                                         input  ? (icCurrencyCode)) in BCInvoice>
       odTaxAcrueInvoiceNonRecovLC = <M-5 RoundAmount
                                        (input  odTaxAcrueInvoiceNonRecovTC * tCInvoice.CInvoiceExchangeRate * tCInvoice.CInvoiceRateScale (idUnroundedAmount), 
                                         input  viCompanyLCId (iiCurrencyID), 
                                         input  ? (icCurrencyCode)) in BCInvoice>.
                                                             
assign ocCurrencyCode = tCInvoice.tcCurrencyCode
       oiReasonId     = tCInvoice.Reason_ID
       odAmountTC     = tCInvoice.CInvoiceOriginalCreditTC - tCInvoice.CInvoiceOriginalDebitTC                          
                      - odTaxAcrueInvoiceRecovTC. 
       odAmountLC     = <M-7 RoundAmount
                           (input  odAmountTC * tCInvoice.CInvoiceExchangeRate * tCInvoice.CInvoiceRateScale (idUnroundedAmount), 
                            input  viCompanyLCId (iiCurrencyID), 
                            input  ? (icCurrencyCode)) in BCInvoice>.


/* =================================================================================================== */
/* Get properties for payment condition                                                                */
/* =================================================================================================== */
if tCInvoice.NormalPaymentCondition_ID <> 0 and
   tCInvoice.NormalPaymentCondition_ID <> ?
then do:
    <Q-6 run PaymentConditionByIdCode (all) (Read) (NoCache)
       (input tCInvoice.NormalPaymentCondition_ID, (PaymentConditionId)
        input ?, (PaymentConditionCode)
        output dataset tqPaymentConditionByIdCode) in BPaymentCondition >
    find first tqPaymentConditionByIdCode where
               tqPaymentConditionByIdCode.tiPaymentCondition_ID = tCInvoice.NormalPaymentCondition_ID
               no-error.
    if available tqPaymentConditionByIdCode
    then assign odDiscountPercentage = tqPaymentConditionByIdCode.tdPaymentConditionPercentage.
end.

/* =================================================================================================== */
/* Return                                                                                              */
/* =================================================================================================== */
if oiReturnStatus = -98 then assign oiReturnStatus = 0.