Skip to main content

Document Cost Allocation Using the REST API

How to allocate a document using a service in the Flexi API?

Written by Petr Pech

Just as in the desktop or web application, you can use the Document Breakdown (Rozúčtování dokladu) function. It allows you to break down a document into individual line items. This function can only be used for a document that does not yet contain any items.

The function is available for these records

  • faktura-prijata

  • faktura-vydana

  • banka

  • pokladni-pohyb

  • pohledavka

  • zavazek


How to call it

The breakdown is sent using the method PUT to a specific document — meaning you specify the record type and the identifier of the document in the address:

PUT https://demo.flexibee.eu/c/demo/faktura-prijata/123.xml
PUT https://demo.flexibee.eu/c/demo/zavazek/code:ZAV0005-2024.json

A description of individual records can be found in the list of records.

💡 Before performing a live write, test the call with the ?dry-run=true parameter. The request will be processed and validated, but nothing will be written to the database.


Breakdown line parameters

The input data consists of individual breakdown lines with the accounting details needed for correct posting. All parameter names are case-sensitive.

Parameter

Meaning

Source record

typUcOp

Posting template

predpis-zauctovani

sazbaDph

VAT rate

sazba-dph

sumZkl

Base amount (decimal number)

zklMdUcet

Debit account for the base

ucet

zklDalUcet

Credit account for the base

ucet

sumDph

VAT amount (decimal number)

dphMdUcet

Debit account for VAT

ucet

dphDalUcet

Credit account for VAT

ucet

taxKey

Tax key

tax-key

clenDph

VAT line

cleneni-dph

clenKonVykDph

VAT ledger statement line

cleneni-kontrolni-hlaseni

stredisko

Cost center

stredisko

cinnost

Activity

cinnost

zakazka

Contract

zakazka

The value of the parameter is always the identifier of a record from the specified record type, typically in the form code:KÓD.

📝 The tax-key record is not available in all localizations. In a company using Czech localization, the call 400 returns the code akcePristupOdepren.


Usage examples

1. Breaking down a received invoice into two lines in XML

<winstrom version="1.0">
<faktura-prijata>
<rozuctujDoklad>
<radkyRozuctovani>
<radek>
<typUcOp>code:NÁKUP ZBOŽÍ A</typUcOp>
<sumZkl>75.0</sumZkl>
<sazbaDph>1</sazbaDph>
<zklMdUcet>code:131001</zklMdUcet>
<zklDalUcet>code:321001</zklDalUcet>
<clenDph>code:000P</clenDph>
</radek>
<radek>
<typUcOp>code:NÁKUP ZBOŽÍ B</typUcOp>
<sumZkl>25.0</sumZkl>
<sazbaDph>1</sazbaDph>
<zklMdUcet>code:131001</zklMdUcet>
<zklDalUcet>code:321001</zklDalUcet>
<clenDph>code:000P</clenDph>
</radek>
</radkyRozuctovani>
</rozuctujDoklad>
</faktura-prijata>
</winstrom>

The result is document items corresponding to the submitted lines:

<winstrom version="1.0">
<faktura-prijata>
<id>123</id>
<polozkyFaktury>
<faktura-prijata-polozka>
<typUcOp>code:NÁKUP ZBOŽÍ A</typUcOp>
<sumZkl>75.0</sumZkl>
<sazbaDph>1</sazbaDph>
<zklMdUcet>code:131001</zklMdUcet>
<zklDalUcet>code:321001</zklDalUcet>
<clenDph>code:000P</clenDph>
</faktura-prijata-polozka>
<faktura-prijata-polozka>
<typUcOp>code:NÁKUP ZBOŽÍ B</typUcOp>
<sumZkl>25.0</sumZkl>
<sazbaDph>1</sazbaDph>
<zklMdUcet>code:131001</zklMdUcet>
<zklDalUcet>code:321001</zklDalUcet>
<clenDph>code:000P</clenDph>
</faktura-prijata-polozka>
</polozkyFaktury>
</faktura-prijata>
</winstrom>

2. Breaking down a liability into two lines in JSON

{
"winstrom": {
"zavazek": {
"rozuctujDoklad": {
"radkyRozuctovani": [
{
"typUcOp": "code:CESTOVNÉ",
"sumZkl": "750.0",
"sazbaDph": "1",
"zklMdUcet": "code:512001",
"zklDalUcet": "code:314001",
"clenDph": "code:40-41"
},
{
"typUcOp": "code:CESTOVNÉ",
"sumZkl": "250.0",
"sazbaDph": "1",
"zklMdUcet": "code:512001",
"zklDalUcet": "code:314001",
"clenDph": "code:40-41"
}
]
}
}
}
}


Failed requests

The sum of the lines does not match the document amount

If the total of the line amounts does not match the total document amount, the following message is returned:

"message": "Suma položek nesouhlasí se sumou dokladu."

The parameter value does not exist in the data

The response is 400 with an error code NOT-FOUND and the name of the object that was searched for:

"code": "NOT-FOUND(cz.winstrom.vo.ucto.Ucet)(code:521002)"
"message": "Záznam pro parametr (zklMdUcet) nebyl v datovém zdroji nalezen: cz.winstrom.vo.ucto.Ucet#code:521002 [ZAV0005/2024]"

Syntactically incorrect entry

For example, a misspelled element name radkyRozuctovani:

{
"winstrom": {
"zavazek": {
"rozuctujDoklad": {
"radkyRoyuctovani": [

The response is 500 with the code importXmlInternalError and the message Interní chyba aplikace. Therefore, make sure to copy element names exactly.


Related

Did this answer your question?