project QadFinancials > class BVAT > method ApiGetPercentageFormula

Description

This method returns the percentage formula and his value that are calculated based on the percentage and operator.


Parameters


icVatPercentCodeinputcharacterVat Percentage Code
icOperatorinputcharacterOperator
ocPercentageFormulaoutputcharacterPercentage Formula
odValueoutputdecimalvalue of percentage formula
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method BVAT.Calculate


program code (program3/bvat.p)

if icVatPercentCode = ? or
   icVatPercentCode = "":U or
   (icOperator      <> "*":U and
    icOperator      <> "+":U and
    icOperator      <> "-":U and
    icOperator      <> "/":U)
then do:
    assign vcMessage = trim(#T-5'Cannot determine the percentage formula.':200(3828)T-5#) + " ":U +
                       trim(#T-6'One of the input parameters is invalid:':200(3829)t-6#) + " ":U +
                       trim(substitute(#T-7'Tax Percentage Code = &1':200(3830)T-7#, icVatPercentCode)) + ", ":U +
                       trim(substitute(#T-8'Operator = &1':200(3831)t-8#, icOperator)).
    <M-2 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'W':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1147':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BVAT>
                     
    assign oiReturnStatus = 1.
    return.
end.    
<Q-1 run LookupPercent (all) (Read) (NoCache)
          (input ?, (vatpercent_ID)
           input today, (ValidityDate)
           input icVatPercentCode, (VatPercentCode)
           output dataset tqLookupPercent) in BVatPercent >
find first tqLookupPercent no-error.
if not available tqLookupPercent
then do:
    assign vcMessage = trim(#T-9'Cannot determine the percentage formula.':200(3828)T-9#) + " ":U +
                       trim(#T-10'The tax percentage cannot be found for the following combination:':200(3822)t-10#) + " ":U +
                       trim(substitute(#T-11'Tax Percentage Code = &1':200(3830)T-11#, icVatPercentCode)) + ", ":U +
                       trim(substitute(#T-12'Date: &1 - today':200(3832)t-12#, <M-4 DisplayDate (input  today (itDate)) in BVAT>)).
    <M-3 run SetMessage (input  vcMessage (icMessage),
                     input  '':U (icArguments),
                     input  '':U (icFieldName),
                     input  '':U (icFieldValue),
                     input  'W':U (icType),
                     input  3 (iiSeverity),
                     input  '':U (icRowid),
                     input  'QADFIN-1148':U (icFcMsgNumber),
                     input  '' (icFcExplanation),
                     input  '' (icFcIdentification),
                     input  '' (icFcContext),
                     output viFcReturnSuper (oiReturnStatus)) in BVAT>
                     
    assign oiReturnStatus = 1.
    return.
end.

assign vdVatPercentage = tqLookupPercent.tdVatPercentLinePercentage.

case icOperator:
    when "*":U
    then do:
        assign ocPercentageFormula = string(vdVatPercentage) + " / 100":U
               odValue             = vdVatPercentage / 100.
    end.
    when "+":U or when "-":U
    then do:
        assign ocPercentageFormula = "1 + ":U + string(vdVatPercentage) + " / 100":U
               odValue             = 1 + (vdVatPercentage / 100).
    end.
    when "/":U
    then do:
        assign ocPercentageFormula = "1 / (1 + ":U + string(vdVatPercentage) + " / 100)":U
               odValue             = 1 / (1 + (vdVatPercentage / 100)).
    end.
end case.


Sample code: how to call this method through RPCRequestService (QXtend Inbound)

define temp-table ttContext no-undo
    field propertyQualifier as character
    field propertyName as character
    field propertyValue as character
    index entityContext is primary unique
        propertyQualifier
        propertyName
    index propertyQualifier
        propertyQualifier.

define dataset dsContext for ttContext.

define variable vhContextDS as handle no-undo.
define variable vhExceptionDS as handle no-undo.
define variable vhServer as handle no-undo.
define variable vhInputDS as handle no-undo.
define variable vhInputOutputDS as handle no-undo.
define variable vhOutputDS as handle no-undo.
define variable vhParameter as handle no-undo.

/* Create context */
create ttContext.
assign ttContext.propertyName = "programName"
       ttContext.propertyValue = "BVAT".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiGetPercentageFormula".
create ttContext.
assign ttContext.propertyName = "applicationId"
       ttContext.propertyValue = "fin".
create ttContext.
assign ttContext.propertyName = "entity"
       ttContext.propertyValue = "1000".
create ttContext.
assign ttContext.propertyName = "userName"
       ttContext.propertyValue = "mfg".
create ttContext.
assign ttContext.propertyName = "password"
       ttContext.propertyValue = "".

/* Create input dataset */
create dataset vhInputDS.
vhInputDS:read-xmlschema("file", "xml/bvat.apigetpercentageformula.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icVatPercentCode = <parameter value>
       vhParameter::icOperator = <parameter value>.

/* Connect the AppServer */
create server vhServer.
vhServer:connect("-URL <appserver-url>").

if not vhServer:connected()
then do:
    message "Could not connect AppServer" view-as alert-box error title "Error".
    return.
end.

/* Run */
assign vhContextDS = dataset dsContext:handle.

run program/rpcrequestservice.p on vhServer
    (input-output dataset-handle vhContextDS by-reference,
           output dataset-handle vhExceptionDS,
     input        dataset-handle vhInputDS by-reference,
     input-output dataset-handle vhInputOutputDS by-reference,
           output dataset-handle vhOutputDS).

/* Handle output however you want, in this example, we dump it to xml */
if valid-handle(vhExceptionDS)
then vhExceptionDS:write-xml("file", "Exceptions.xml", true).

if valid-handle(vhOutputDS)
then vhOutputDS:write-xml("file", "Output.xml", true).

/* Cleanup */
vhServer:disconnect().
assign vhServer = ?.

if valid-handle(vhInputDS)
then delete object vhInputDS.

if valid-handle(vhOutputDS)
then delete object vhOutputDS.

if valid-handle(vhExceptionDS)
then delete object vhExceptionDS.