Skip to main content

Rounding of document prices in the REST API

How to round prices on a received invoice or cash receipt via the Flexi API?

Written by Petr Pech

Since version 2021.9.1, it has been possible to round the prices of a received invoice or cash receipt via the REST API. The service is called zaokrouhli and is available in the faktura-prijata and pokladni-pohyb records.


Service description

This is the same service you can find in the desktop application:

  • received invoice detail > Services > Document price rounding

  • cash receipt detail > Services > Document price rounding

You pass the service the prices to which the document should be rounded. The difference from the existing totals is then written as a new item of type typPolozky.ucetni named Rounded, so that the document totals match the requested values.

⚠️ Document price rounding can only be used on a document with line items. For a document without its own items — for example, a cash receipt that is only a payment of an invoice — the service returns 201 with success true, but no rounding item is created. Always verify the result by checking the document totals.

It is called using the POST or PUT method on the endpoint of the relevant record:

POST https://demo.flexibee.eu/c/demo/faktura-prijata.xml
POST https://demo.flexibee.eu/c/demo/pokladni-pohyb.xml


Service input parameters

The service has a single input parameter, pozadovaneCeny — the prices used to calculate the rounding difference, specified per individual VAT rate:

Elements

Rate

zklZakl, dphZakl, celkZakl

Base rate — base, VAT, and including VAT

zklSniz, dphSniz, celkSniz

Reduced rate

zklSniz2, dphSniz2, celkSniz2

Second reduced rate

osv

Amount exempt from tax

🚨 The trio of values within a single rate must be internally consistent — the base plus VAT must equal the amount including VAT. Otherwise, the service returns 400 with code dokladKorekceCastekChybaSouctu and the message The sum of amounts in the 'base' rate does not match.

ℹ️ The requested prices are entered in the document's currency. For a document in a foreign currency, the amounts in the domestic currency are calculated using the document's exchange rate.


Usage examples

Received invoice at the base rate

POST https://demo.flexibee.eu/c/demo/faktura-prijata.xml
<winstrom version="1.0">
<faktura-prijata>
<!-- Přijatá faktura, která bude zaokrouhlena. -->
<id>code:PF0001/2021</id>
<!-- Lze uvést i další vlastnosti dokladu, jako při importu. -->
<zaokrouhli>
<pozadovaneCeny>
<!-- Základ částky pro základní sazbu. -->
<zklZakl>110</zklZakl>
<!-- DPH částky pro základní sazbu. -->
<dphZakl>23.1</dphZakl>
<!-- Částka pro základní sazbu včetně DPH. -->
<celkZakl>133.1</celkZakl>
</pozadovaneCeny>
</zaokrouhli>
</faktura-prijata>
</winstrom>

The response is 201 Created with the standard import result, and a rounding item is created on the document:

<winstrom version="1.0">
<faktura-prijata>
<id>code:PF0001/2021</id>
<sumCelkem>133.1</sumCelkem>
<polozkyDokladu>
<faktura-prijata-polozka>
<!-- Původní položka dokladu. -->
<typPolozkyK>typPolozky.obecny</typPolozkyK>
<sumZkl>100.0</sumZkl>
<sumDph>21.0</sumDph>
<sumCelkem>121.0</sumCelkem>
</faktura-prijata-polozka>
<faktura-prijata-polozka>
<!-- Položka, která vznikla při zaokrouhlení. -->
<typPolozkyK>typPolozky.ucetni</typPolozkyK>
<nazev>Zaokrouhleno</nazev>
<sumZkl>10.0</sumZkl>
<sumDph>2.1</sumDph>
<sumCelkem>12.1</sumCelkem>
</faktura-prijata-polozka>
</polozkyDokladu>
</faktura-prijata>
</winstrom>

Cash receipt at the zero rate

PUT https://demo.flexibee.eu/c/demo/pokladni-pohyb.xml
<winstrom version="1.0">
<pokladni-pohyb>
<!-- Pokladní pohyb, který bude zaokrouhlen. -->
<id>code:P-0001/2021</id>
<!-- Lze uvést i další vlastnosti dokladu, jako při importu. -->
<zaokrouhli>
<pozadovaneCeny>
<!-- Požadovaná částka osvobozená od daně. -->
<osv>140</osv>
</pozadovaneCeny>
</zaokrouhli>
</pokladni-pohyb>
</winstrom>

The result is again a rounding item on the document:

<winstrom version="1.0">
<pokladni-pohyb>
<id>code:P-0001/2021</id>
<sumCelkem>140</sumCelkem>
<polozkyDokladu>
<pokladni-pohyb-polozka>
<!-- Původní položka dokladu. -->
<typPolozkyK>typPolozky.obecny</typPolozkyK>
<sumZkl>130.0</sumZkl>
<sumDph>0.0</sumDph>
<sumCelkem>130.0</sumCelkem>
</pokladni-pohyb-polozka>
<pokladni-pohyb-polozka>
<!-- Položka, která vznikla při zaokrouhlení. -->
<typPolozkyK>typPolozky.ucetni</typPolozkyK>
<nazev>Zaokrouhleno</nazev>
<sumZkl>10.0</sumZkl>
<sumDph>0.0</sumDph>
<sumCelkem>10.0</sumCelkem>
</pokladni-pohyb-polozka>
</polozkyDokladu>
</pokladni-pohyb>
</winstrom>


Related

Did this answer your question?