Build a return from ledger data
Build the rows of a return from the ledger, read what each row came from, and rebuild when the ledger changes.
On this page
The product reads the postings of your ledger for the period, sums them into the rows of the form and records which snapshot of the ledger it read. You do not send figures. If a figure is wrong, the cause is in the ledger, and the fix is there.
Wait for the period to end
A period is built after its last day. Before that, generateReturn answers
period_open. See Periods and due dates.Build the return
Send the revision you read. The answer is
accepted; the return becomesgeneratedand takes the newest snapshot.Read the rows
Each row has a
key, alabel, the figure, the VAT andfrom, the ledger balances it was summed from.Check against your own books
Compare the totals with the trial balance you keep. A difference points at a posting, not at the return.
curl
curl -X POST "$RDC_BASE_URL/declarations/v1/returns/dff3b09f-8bbd-488b-8b7d-f71eb11ef3af/generate" \
-H "Authorization: Bearer $RDC_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"operationId": "4b6f8fbf-33e1-4464-9142-f9ed6bf73a4b",
"expectedRevision": 1
}' JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/declarations/v1/returns/dff3b09f-8bbd-488b-8b7d-f71eb11ef3af/generate`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.RDC_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"operationId": "4b6f8fbf-33e1-4464-9142-f9ed6bf73a4b",
"expectedRevision": 1
}),
});
const result = await response.json(); Python
import os
import requests
response = requests.request(
'POST',
f'{os.environ["RDC_BASE_URL"]}/declarations/v1/returns/dff3b09f-8bbd-488b-8b7d-f71eb11ef3af/generate',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
json={
'operationId': '4b6f8fbf-33e1-4464-9142-f9ed6bf73a4b',
'expectedRevision': 1,
},
)
result = response.json() PHP
<?php
$body = <<<'JSON'
{
"operationId": "4b6f8fbf-33e1-4464-9142-f9ed6bf73a4b",
"expectedRevision": 1
}
JSON;
$curl = curl_init(getenv('RDC_BASE_URL') . '/declarations/v1/returns/dff3b09f-8bbd-488b-8b7d-f71eb11ef3af/generate');
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RDC_TOKEN'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => $body,
]);
$result = json_decode(curl_exec($curl), true);
curl_close($curl); C#
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/declarations/v1/returns/dff3b09f-8bbd-488b-8b7d-f71eb11ef3af/generate");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
request.Content = new StringContent("""
{
"operationId": "4b6f8fbf-33e1-4464-9142-f9ed6bf73a4b",
"expectedRevision": 1
}
""", System.Text.Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"operationId": "4b6f8fbf-33e1-4464-9142-f9ed6bf73a4b",
"status": "accepted",
"aggregateId": "dff3b09f-8bbd-488b-8b7d-f71eb11ef3af",
"aggregateRevision": 2
} Read the rows
curl
curl "$RDC_BASE_URL/declarations/v1/returns/3b559a77-5de4-4b9a-9e2e-ca6625d123f2/rows?limit=20" \
-H "Authorization: Bearer $RDC_TOKEN" JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/declarations/v1/returns/3b559a77-5de4-4b9a-9e2e-ca6625d123f2/rows?limit=20`, {
method: 'GET',
headers: {
Authorization: `Bearer ${process.env.RDC_TOKEN}`,
},
});
const result = await response.json(); Python
import os
import requests
response = requests.request(
'GET',
f'{os.environ["RDC_BASE_URL"]}/declarations/v1/returns/3b559a77-5de4-4b9a-9e2e-ca6625d123f2/rows?limit=20',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
)
result = response.json() PHP
<?php
$curl = curl_init(getenv('RDC_BASE_URL') . '/declarations/v1/returns/3b559a77-5de4-4b9a-9e2e-ca6625d123f2/rows?limit=20');
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RDC_TOKEN'),
],
]);
$result = json_decode(curl_exec($curl), true);
curl_close($curl); C#
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/declarations/v1/returns/3b559a77-5de4-4b9a-9e2e-ca6625d123f2/rows?limit=20");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"items": [
{
"key": "sales-21",
"label": "Supplies at 21%",
"ref": null,
"unit": "amount",
"value": "2947.04",
"vat": "618.89",
"partner": null,
"code": null,
"from": [
"707 credit, 21%",
"4427 credit, 21%"
]
},
{
"key": "sales-11",
"label": "Supplies at 11%",
"ref": null,
"unit": "amount",
"value": "57329.70",
"vat": "6306.27",
"partner": null,
"code": null,
"from": [
"707 credit, 11%",
"4427 credit, 11%"
]
},
{
"key": "ic-acquisitions",
"label": "Acquisitions from other member states",
"ref": null,
"unit": "amount",
"value": "5252.00",
"vat": "1102.92",
"partner": null,
"code": null,
"from": [
"371 debit",
"4427 credit"
]
},
{
"key": "purchases-21",
"label": "Domestic purchases at 21%",
"ref": null,
"unit": "amount",
"value": "3067.50",
"vat": "644.18",
"partner": null,
"code": null,
"from": [
"371 debit, 21%",
"4426 debit, 21%"
]
},
{
"key": "purchases-11",
"label": "Domestic purchases at 11%",
"ref": null,
"unit": "amount",
"value": "48236.00",
"vat": "5305.96",
"partner": null,
"code": null,
"from": [
"371 debit, 11%",
"4426 debit, 11%"
]
},
{
"key": "deductible-ic",
"label": "Deductible VAT on acquisitions from other member states",
"ref": null,
"unit": "amount",
"value": null,
"vat": "1102.92",
"partner": null,
"code": null,
"from": [
"4426 debit"
]
},
{
"key": "total-collected",
"label": "Total VAT collected",
"ref": 19,
"unit": "amount",
"value": null,
"vat": "8028.08",
"partner": null,
"code": null,
"from": [
"4427 credit"
]
},
{
"key": "total-deductible",
"label": "Total VAT deductible",
"ref": 30,
"unit": "amount",
"value": null,
"vat": "7053.06",
"partner": null,
"code": null,
"from": [
"4426 debit"
]
},
{
"key": "total-deducted",
"label": "Total VAT deducted",
"ref": 35,
"unit": "amount",
"value": null,
"vat": "7053.06",
"partner": null,
"code": null,
"from": [
"4426 debit"
]
},
{
"key": "recoverable",
"label": "Negative amount of VAT of the period",
"ref": 36,
"unit": "amount",
"value": null,
"vat": "0.00",
"partner": null,
"code": null,
"from": [
"4427 credit",
"4426 debit"
]
},
{
"key": "payable",
"label": "VAT payable in the period",
"ref": 37,
"unit": "amount",
"value": null,
"vat": "975.02",
"partner": null,
"code": null,
"from": [
"4427 credit",
"4426 debit"
]
}
],
"nextCursor": null
} The rows of the VAT return of October are 11. A row of D394 carries the tax code of the partner as the ledger holds it: a mistyped code in the ledger is a mistyped code in the return, and the authority will answer nok. Handle a rejection shows the way back.
When the ledger changes
A document posted late creates a newer snapshot. The return keeps the snapshot it was built from until you rebuild it with regenerateReturn, which replaces its evidence and puts it back to generated. A rebuild when the ledger has no newer snapshot is refused with source_unchanged.
curl
curl -X POST "$RDC_BASE_URL/declarations/v1/returns/3b559a77-5de4-4b9a-9e2e-ca6625d123f2/regenerate" \
-H "Authorization: Bearer $RDC_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"operationId": "e3f2c9a7-7037-4de9-bb01-7ad37d5f67af",
"expectedRevision": 4
}' JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/declarations/v1/returns/3b559a77-5de4-4b9a-9e2e-ca6625d123f2/regenerate`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.RDC_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"operationId": "e3f2c9a7-7037-4de9-bb01-7ad37d5f67af",
"expectedRevision": 4
}),
});
const result = await response.json(); Python
import os
import requests
response = requests.request(
'POST',
f'{os.environ["RDC_BASE_URL"]}/declarations/v1/returns/3b559a77-5de4-4b9a-9e2e-ca6625d123f2/regenerate',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
json={
'operationId': 'e3f2c9a7-7037-4de9-bb01-7ad37d5f67af',
'expectedRevision': 4,
},
)
result = response.json() PHP
<?php
$body = <<<'JSON'
{
"operationId": "e3f2c9a7-7037-4de9-bb01-7ad37d5f67af",
"expectedRevision": 4
}
JSON;
$curl = curl_init(getenv('RDC_BASE_URL') . '/declarations/v1/returns/3b559a77-5de4-4b9a-9e2e-ca6625d123f2/regenerate');
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RDC_TOKEN'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => $body,
]);
$result = json_decode(curl_exec($curl), true);
curl_close($curl); C#
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/declarations/v1/returns/3b559a77-5de4-4b9a-9e2e-ca6625d123f2/regenerate");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
request.Content = new StringContent("""
{
"operationId": "e3f2c9a7-7037-4de9-bb01-7ad37d5f67af",
"expectedRevision": 4
}
""", System.Text.Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"operationId": "e3f2c9a7-7037-4de9-bb01-7ad37d5f67af",
"status": "accepted",
"aggregateId": "3b559a77-5de4-4b9a-9e2e-ca6625d123f2",
"aggregateRevision": 5
}