project QadFinancials > class BVAT > method GetVatTransactionType
Description
Gets the default transaction type based on the input parameters.
At least Country IDs or codes should be specified.
As the method compares Country IDs plus EU indicators it is better to specify also these indicators if you know them Otherwise the method will retrieve them for given counties itself.
Parameters
icVatInOut | input | character | Indicates Input/Output VAT |
iiOwnVatCountryId | input | integer | Own country ID |
icOwnVatCountryCode | input | character | Own Vat Country Code |
ilOwnVatCountryIsEU | input | logical | Indicates EU country |
icStartVatCountryCode | input | character | Starting point (country) of the Vat transaction |
ilStartVatCountryIsEU | input | logical | Indicates EU country |
icEndVatCountryCode | input | character | Ending point (country) of the Vat transaction |
ilEndVatCountryIsEU | input | logical | Indicates EU country |
ocVatTransactionType | output | character | Vat transaction type corresponding to the given input parameters |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program6/bvat.p)
/*Check input papameters - at least Country IDs or Codes should be specified*/
if ((iiOwnVatCountryId = 0 or iiOwnVatCountryId = ?) and (icOwnVatCountryCode = "":U or icOwnVatCountryCode = ?)) or
( /* (iiStartVatCountryId = 0 or iiStartVatCountryId = ?) and */ (icStartVatCountryCode = "":U or icStartVatCountryCode = ?)) or
( /* (iiEndVatCountryId = 0 or iiEndVatCountryId = ?) and */ (icEndVatCountryCode = "":U or icEndVatCountryCode = ?))
then return.
/*Get Is EU indications, plus country codes if not specified */
if ilOwnVatCountryIsEU = ? or ilStartVatCountryIsEU = ? or ilEndVatCountryIsEU = ? or
iiOwnVatCountryId = 0 or iiOwnVatCountryId = ? /* or
iiStartVatCountryId = 0 or iiStartVatCountryId = ? or
iiEndVatCountryId = 0 or iiEndVatCountryId = ? */
then do:
/*I assume there will not be much countries in the DB therefore I will get them all*/
<Q-1 run CountryByCode (all) (Read) (NoCache)
(input '':U, (CountryCode)
output dataset tqCountryByCode) in BCountry >
/*Own country*/
if ilOwnVatCountryIsEU = ? or iiOwnVatCountryId = 0 or iiOwnVatCountryId = ?
then do:
find first tqCountryByCode where
tqCountryByCode.tiCountry_ID = iiOwnVatCountryId or
tqCountryByCode.tcCountryCode = icOwnVatCountryCode no-error.
if not available tqCountryByCode
then return.
assign ilOwnVatCountryIsEU = tqCountryByCode.tlCountryIsEUCountry
iiOwnVatCountryId = tqCountryByCode.tiCountry_ID.
end.
/*Start country*/
if ilStartVatCountryIsEU = ? /* or iiStartVatCountryId = 0 or iiStartVatCountryId = ? */
then do:
find first tqCountryByCode where
/* tqCountryByCode.tiCountry_ID = iiStartVatCountryId or */
tqCountryByCode.tcCountryCode = icStartVatCountryCode no-error.
if not available tqCountryByCode
then return.
assign ilStartVatCountryIsEU = tqCountryByCode.tlCountryIsEUCountry.
/* iiStartVatCountryId = tqCountryByCode.tiCountry_ID. */
end.
/*End country*/
if ilEndVatCountryIsEU = ? /* or iiEndVatCountryId = 0 or iiEndVatCountryId = ? */
then do:
find first tqCountryByCode where
/* tqCountryByCode.tiCountry_ID = iiEndVatCountryId or */
tqCountryByCode.tcCountryCode = icEndVatCountryCode no-error.
if not available tqCountryByCode
then return.
assign ilEndVatCountryIsEU = tqCountryByCode.tlCountryIsEUCountry.
/* iiEndVatCountryId = tqCountryByCode.tiCountry_ID. */
end.
end.
/*Triangular Purchase/Sales*/
if ilOwnVatCountryIsEU and ilStartVatCountryIsEU and ilEndVatCountryIsEU /* and
iiOwnVatCountryId <> iiStartVatCountryId and
iiStartVatCountryId <> iiEndVatCountryId and
iiEndVatCountryId <> iiOwnVatCountryId */
then assign ocVatTransactionType = if icVatInOut = {&VATINOUT-INPUT}
then {&VATTRANSACTIONTYPE-TRIANGULARPURCHASE}
else if icVatInOut = {&VATINOUT-OUTPUT}
then {&VATTRANSACTIONTYPE-TRIANGULARSALES}
else "":U.
/*Inland Purchase/Sales*/
else if icStartVatCountryCode = icEndVatCountryCode
then assign ocVatTransactionType = if icVatInOut = {&VATINOUT-INPUT}
then {&VATTRANSACTIONTYPE-PURCHASE}
else if icVatInOut = {&VATINOUT-OUTPUT}
then {&VATTRANSACTIONTYPE-SALES}
else "":U.
/*EU - Acquisition/Supply*/
else if ilStartVatCountryIsEU and ilEndVatCountryIsEU
then assign ocVatTransactionType = if icVatInOut = {&VATINOUT-INPUT}
then {&VATTRANSACTIONTYPE-ACQUISITION}
else if icVatInOut = {&VATINOUT-OUTPUT}
then {&VATTRANSACTIONTYPE-SUPPLY}
else "":U.
/*Non EU - Import/Export*/
else if ilStartVatCountryIsEU <> ilEndVatCountryIsEU
then assign ocVatTransactionType = if icVatInOut = {&VATINOUT-INPUT}
then {&VATTRANSACTIONTYPE-IMPORT}
else if icVatInOut = {&VATINOUT-OUTPUT}
then {&VATTRANSACTIONTYPE-EXPORT}
else "":U.
/*in all other cases return blank value*/
else assign ocVatTransactionType = "":U.
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 = "GetVatTransactionType".
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.getvattransactiontype.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icVatInOut = <parameter value>
vhParameter::iiOwnVatCountryId = <parameter value>
vhParameter::icOwnVatCountryCode = <parameter value>
vhParameter::ilOwnVatCountryIsEU = <parameter value>
vhParameter::icStartVatCountryCode = <parameter value>
vhParameter::ilStartVatCountryIsEU = <parameter value>
vhParameter::icEndVatCountryCode = <parameter value>
vhParameter::ilEndVatCountryIsEU = <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.