Description
This method is used to get a yearly Export Vat List by input parameters for Belgium.
Parameters
icConvertToCurrency | input | character | Convert To Currency Code. |
icVatNumberIdentity | input | character | Vat Number Identity. |
icVatNumberDeclaration | input | character | Vat Number Declaration. |
itFromTaxpointDate | input | date | From Tax Point Date |
itToTaxpointDate | input | date | To Tax Point Date |
icPeriodMark | input | character | Period Mark. |
idMinimumAmount | input | decimal | Minimum Amount. |
iiFromVatPeriod | input | integer | From Vat Period. |
iiToVatPeriod | input | integer | To Vat Period. |
iiFromVatYear | input | integer | From Vat Year. |
iiToVatYear | input | integer | To Vat Year |
tqVatExportListing | output | temp-table | Temp table of VatExportListing. |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program6/bvatexportlisting.p)
empty temp-table tqExportVATListingYearly.
assign viRecordCounter = 0.
/* ================*/
/* Get currency ID */
/* ================*/
if icConvertToCurrency = "":U or
icConvertToCurrency = ?
then assign vlUseLC = true.
else do:
assign vlUseLC = false.
<Q-3 run CurrencyPrim (all) (Read) (NoCache)
(input icConvertToCurrency, (CurrencyCode)
input ?, (Currency_ID)
output dataset tqCurrencyPrim) in BCurrency >
find first tqCurrencyPrim no-error.
if not available tqCurrencyPrim
then do:
<M-11 run SetMessage
(input #T-23'The specified currency code $1 is not defined in the system or is invalid.':100(3844)t-23# (icMessage),
input icConvertToCurrency (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-1861':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BVATExportListing>
assign oiReturnStatus = -1.
return.
end.
assign viExportCurrency_ID = tqCurrencyPrim.tiCurrency_ID.
end.
assign vtFromVatPeriod = ?
vtToVatPeriod = ?
vlFatalError = false.
if iiFromVatYear <> ? and
iiFromVatYear <> 0
then do:
if iiFromVatPeriod = ?
then assign iiFromVatPeriod = 1.
/* get all vat periods */
<Q-12 run VatPeriodByVatYearPeriod (first) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input iiFromVatYear, (VatPeriodYear)
input iiFromVatPeriod, (VatPeriodPeriod)
output dataset tqVatPeriodByVatYearPeriod) in BVATPeriod >
find first tqVatPeriodByVatYearPeriod no-error.
if available tqVatPeriodByVatYearPeriod
then assign vtFromVatPeriod = tqVatPeriodByVatYearPeriod.ttVatPeriodStartDate.
else assign vlFatalError = true.
end.
else if iiFromVatPeriod <> ?
then assign vlFatalError = true.
if iiToVatYear <> ? and
iiToVatYear <> 0
then do:
if iiToVatPeriod = ?
then assign iiToVatPeriod = 1.
/* get all vat periods */
<Q-13 run VatPeriodByVatYearPeriod (first) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input iiToVatYear, (VatPeriodYear)
input iiToVatPeriod, (VatPeriodPeriod)
output dataset tqVatPeriodByVatYearPeriod) in BVATPeriod >
find first tqVatPeriodByVatYearPeriod no-error.
if available tqVatPeriodByVatYearPeriod
then assign vtToVatPeriod = tqVatPeriodByVatYearPeriod.ttVatPeriodEndDate.
else assign vlFatalError = true.
end.
else if iiToVatPeriod <> ?
then assign vlFatalError = true.
/* If we couldn't find requestet VAt Period exit and announce error */
if vlFatalError
then do:
assign vcOutputMessage = trim(substitute(#T-24'The specified tax period [from-to]: [&1\&2 - &3\&4] is not defined in the system or is invalid.':100(3845)t-24#,string(iiFromVatYear),string(iiFromVatPeriod), string(iiFromVatYear),string(iiToVatPeriod))).
<M-16 run SetMessage (input vcOutputMessage (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'E':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-1862':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BVATExportListing>
assign oiReturnStatus = -1.
return.
end.
assign viListingYear = iiFromVatYear.
/* ================ */
/* Call base querry */
/* ================ */
<Q-17 run VatPostingsByDebtor (all) (Read) (NoCache)
(input viCompanyId, (CompanyId)
input itFromTaxpointDate, (FromTaxpointDate)
input iiFromVatYear, (FromVatPeriod)
input iiFromVatPeriod, (FromVatYear)
input {&GLTYPECODE-VAT}, (GLTypeCode)
input icPeriodMark, (PeriodMark)
input itFromTaxpointDate, (ToTaxpointDate)
input iiToVatPeriod, (ToVatPeriod)
input iiToVatYear, (ToVatYear)
input icVatNumberIdentity, (VatNumberIdentity)
input icVatNumberDeclaration, (VatNumberDeclaration)
output dataset tqVatPostingsByDebtor) in BBusinessRelation >
assign vdTempBaseSumByDebtorLC = 0
vdTempBaseSumByDebtorTC = 0
vdTempBaseSumByDebtorRC = 0
vdTempVatSumByDebtorLC = 0
vdTempVatSumByDebtorTC = 0
vdTempVatSumByDebtorRC = 0.
/* Algorith goes through debtors postinglines and sums all base and vat ammounts.
At final ammount it decides by the MinimumAmountFilter if it ads to output table */
/* BTS 4975 - JLA */
for each tqVatPostingsByDebtor where
tqVatPostingsByDebtor.tcCountryCode = "BE":U
break by tqVatPostingsByDebtor.tcVatNumberIdentity:
/* BTS 4975 - JLA */
/* BTS 4975 - JLA */
/* In case of debtor invoices, you should use credit - debet */
assign vdTempBaseSumByDebtorLC = vdTempBaseSumByDebtorLC + (tqVatPostingsByDebtor.tdPostingVatBaseCreditLC - tqVatPostingsByDebtor.tdPostingVatBaseDebitLC)
vdTempVatSumByDebtorLC = vdTempVatSumByDebtorLC + (tqVatPostingsByDebtor.tdPostingLineCreditLC - tqVatPostingsByDebtor.tdPostingLineDebitLC)
vdTempBaseSumByDebtorTC = vdTempBaseSumByDebtorTC + (tqVatPostingsByDebtor.tdPostingVatBaseCreditTC - tqVatPostingsByDebtor.tdPostingVatBaseDebitTC)
vdTempVatSumByDebtorTC = vdTempVatSumByDebtorTC + (tqVatPostingsByDebtor.tdPostingLineCreditTC - tqVatPostingsByDebtor.tdPostingLineDebitTC).
/* BTS 4975 - JLA */
/* BTS 4975 - JLA */
if last-of (tqVatPostingsByDebtor.tcVatNumberIdentity)
then do:
/* BTS 4975 - JLA */
if vlUseLC
then assign vdTempBaseSumByDebtorRC = vdTempBaseSumByDebtorLC
vdTempVatSumByDebtorRC = vdTempVatSumByDebtorLC.
else do:
if viExportCurrency_ID = tqVatPostingsByDebtor.tiCurrency_ID
then assign vdTempBaseSumByDebtorRC = vdTempBaseSumByDebtorTC
vdTempVatSumByDebtorRC = vdTempVatSumByDebtorTC.
else do:
<M-22 run GetReportExchangeRate
(input icConvertToCurrency (icConvertToCurrency),
input viExportCurrency_ID (iiExportCurrency_ID),
output vdExchangeRateValue (odExchangeRate),
output vdExchangeRateScale (odExchangeRateScale),
output viFcReturnSuper (oiReturnStatus)) in BVATExportListing>
if viFcReturnSuper <> 0
then do:
assign oiReturnStatus = -1.
return.
end.
assign vdTempBaseSumByDebtorRC = (vdExchangeRateValue * vdTempBaseSumByDebtorLC) * vdExchangeRateScale
vdTempVatSumByDebtorRC = (vdExchangeRateValue * vdTempVatSumByDebtorLC) * vdExchangeRateScale.
end.
end.
if vdTempBaseSumByDebtorRC >= idMinimumAmount or
idMinimumAmount = ?
then do:
assign viRecordCounter = viRecordCounter + 1.
create tqExportVATListingYearly.
assign tqExportVATListingYearly.tcDebtorCode = tqVatPostingsByDebtor.tcDebtorCode
tqExportVATListingYearly.tcVatNumberIdentity = tqVatPostingsByDebtor.tcVatNumberIdentity
tqExportVATListingYearly.tdBaseRC = vdTempBaseSumByDebtorRC
tqExportVATListingYearly.tdVatRC = vdTempVatSumByDebtorRC.
end.
assign vdTempBaseSumByDebtorLC = 0
vdTempVatSumByDebtorLC = 0
vdTempBaseSumByDebtorTC = 0
vdTempVatSumByDebtorTC = 0.
end.
end.
if viRecordCounter <= 0
then do:
<M-20 run SetMessage (input 'No results found for this query':U (icMessage),
input '':U (icArguments),
input '':U (icFieldName),
input '':U (icFieldValue),
input 'W':U (icType),
input 3 (iiSeverity),
input '':U (icRowid),
input 'QADFIN-1875':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BVATExportListing>
assign oiReturnStatus = -1.
return.
end.
<M-25 run ExportFormatting725 (input tqExportVATListingYearly (t_sqExportVATListingYearly),
output tqVatExportListing (tqVatExportListing),
output viFcReturnSuper (oiReturnStatus)) in BVATExportListing>
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 = "BVATExportListing".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiExportYearlyVatBE".
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/bvatexportlisting.apiexportyearlyvatbe.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icConvertToCurrency = <parameter value>
vhParameter::icVatNumberIdentity = <parameter value>
vhParameter::icVatNumberDeclaration = <parameter value>
vhParameter::itFromTaxpointDate = <parameter value>
vhParameter::itToTaxpointDate = <parameter value>
vhParameter::icPeriodMark = <parameter value>
vhParameter::idMinimumAmount = <parameter value>
vhParameter::iiFromVatPeriod = <parameter value>
vhParameter::iiToVatPeriod = <parameter value>
vhParameter::iiFromVatYear = <parameter value>
vhParameter::iiToVatYear = <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.