Optima accounting in the API
The shared part of the Sancho accounting API, the fields every ERP has and the method descriptions, does not use Optima’s names. The same method has to work with another ERP too, so cashFlowItems.list says nothing about a payment schedule and accountingDocuments.post nothing about a buffer. Only the fields of the comarch-optima variant carry Optima’s names, for example position, the Lp. in the VAT register, and only the taxReporting block carries Polish tax marks, the JPK_V7 codes. This page shows which Optima object stands behind each name, how the integration reads and writes it, and why the name is what it is.
Methods, parameters and error codes are described on the Accounting page and in the reference.
How the integration reaches Optima
Section titled “How the integration reaches Optima”The integration service runs on the Windows host next to Optima. It reads the CDN.* tables of the company database over MS SQL. It writes through Optima’s COM API under one operator login, so Optima itself assigns numbers, computes dates and creates derived documents, the same as when someone works in the program.
Accounting writes (create, update and post) answer { result, warnings }. result is the object as read from Optima after the write, and warnings is empty except on a cash transaction and a settlement, described below with the ledger settlements. The integration stores your importSource in Optima as the import mark, unchanged: appId in *_ImportAppId and rowId in *_ImportRowId, on a VAT register entry (VaN_), a cash transaction (BZp_), a settlement (BRK_), a counterparty card (Knt_), and a fixed-asset or equipment card (SrT_, Wyp_). Without importSource Optima writes its own id there, and the document looks as if it was typed in the program. Optima keeps each *_ImportRowId once, regardless of letter case.
The integration’s login needs the Kasa/Bank Plus module (KBP), or the Podstawowy module (PODSTAWOWY) under the subscription model. The connector takes the modules its OPTIMA_MODULES setting names, in Optima’s names. Creating accounts, writing proposed journal entries and posting through post also need the Księga Handlowa module, which is KH or KHP on a classic key and FINANSEPRO or DODATKOWY_KH under the subscription model. Without it the API answers 422 with the reason ledgerNotLicensed, and accounting.profile has ledgerLicensed: false. Reading the chart of accounts does not need this module, only double-entry books.
API objects and their Optima counterparts
Section titled “API objects and their Optima counterparts”| In the API | In Optima | Tables | What the API does |
|---|---|---|---|
invoice |
purchase or sales invoice in the Handel module | CDN.TraNag, CDN.TraElem |
reads |
accountingDocument |
VAT register entry | CDN.VatNag, CDN.VatTab |
reads, creates, updates, deletes, posts |
vatRegister |
purchase or sales VAT register | CDN.Grupy |
reads |
proposedJournalEntry |
predekretacja, the proposed booking kept on the document | CDN.DekretyNag, CDN.DekretyElem |
reads and writes it with the accounting document |
journalEntry |
zapis księgowy, also called dekret | CDN.DekretyNag, CDN.DekretyElem |
shows it on the accounting document, creates it through post |
cashFlowItem |
entry in the payment schedule, preliminarz płatności | CDN.BnkZdarzenia |
reads |
cashAccount |
cash or bank register | CDN.BnkRachunki |
reads |
cashStatement |
cash or bank report | CDN.BnkRaporty |
reads, opens a new one when it writes a cash transaction |
cashTransaction |
cash or bank entry | CDN.BnkZapisy |
reads, creates, deletes |
settlement |
rozliczenie | CDN.BnkRozKwoty |
reads, creates, deletes |
ledgerSettlementItem |
rozrachunek on a settlement account | CDN.KsiRozrachunki |
reads |
ledgerAccount |
account in the chart of accounts | CDN.Konta |
reads, creates analytic accounts |
subledger account |
konto słownikowe, a dictionary account | CDN.Konta |
creates a counterparty’s account when it is missing |
journal |
dziennik | CDN.Dzienniki |
reads |
fiscalYear |
okres obrachunkowy | CDN.OkresyObrach |
reads |
accountingCategory |
kategoria | CDN.Kategorie |
reads |
paymentMethod |
forma płatności | CDN.FormyPlatnosci |
reads |
counterParty |
kontrahent | CDN.Kontrahenci |
reads, creates, updates, deletes |
asset with kind: "fixedAsset" |
środek trwały (fixed asset) | CDN.Trwale |
reads, creates, updates, disposes of, deletes |
asset with kind: "equipment" |
wyposażenie (equipment) | CDN.Wyposazenie |
reads, creates, updates, disposes of, deletes |
accountingProfile |
the company’s type of bookkeeping and the Księga Handlowa module of the integration’s login | CDN.Firma (setting 1204) |
reads |
Invoice and accounting document
Section titled “Invoice and accounting document”Optima keeps an invoice in two places. In the Handel module it is a trade document with product lines. In the VAT register it is an entry with amounts per rate, tax dates and JPK codes. The API shows both. The first is invoice, the second is accountingDocument. They are linked by invoiceId on the accounting document and accountingDocumentId on the invoice. Each of these fields has a value only when the other method serves the document it names. invoiceId names only an invoice of the same kind as the accounting document, an FZ in the purchase register or an FS in the sales register, because invoices.get serves only such invoices. accountingDocumentId has a value only while the VAT register entry the invoice names still exists.
Not every accounting document has an invoice in Handel. origin says how it got into the register.
origin |
How the document got into the register |
|---|---|
invoice |
carried over from an invoice of the same kind in Handel: an FZ into the purchase register, an FS into the sales register |
other |
carried over from Handel without an invoice of the same kind to name: from a receipt, a TaxFree document, the collective receipts entry or a document that is no longer there; likewise a sales-register entry that names a purchase invoice (FZ) |
eInvoice |
imported from KSeF in Optima |
imported |
with an import mark other than KSeF: from an importSource given in the API or from another application’s import |
manual |
typed in Optima, with no import mark |
kind is purchase or sales, the same as on an invoice. In Optima it is the register type, column VaN_Typ, with 1 for a purchase and 2 for a sale.
What Optima does itself on a write
Section titled “What Optima does itself on a write”- It assigns the accounting number and the position in the register.
- It computes the tax point date and the deduction date when you send
null. - It creates payment-schedule entries from the payment method and the due date. You see them as the document’s
cashFlowItems. - It checks that the document is not already there, by the duplicate control set up in the company.
- It creates the KP and KW cash slips and settles the payment, if the company has this turned on.
Limits that come from Optima
Section titled “Limits that come from Optima”- One transaction kind per document. Optima stores the transaction kind once, in the header. The integration computes a line’s tax category
taxRate.categoryfrom that kind and the rate. You cannot write a document whose lines need different transaction kinds. The answer is 422notSupportedwith the line’s path inpath. - A VAT line has no account.
lines[].accountgives 422notSupported. Accounts go in the proposed journal entry. - An update recreates the payments. After
accountingDocuments.updateOptima creates the payment-schedule entries again, so theidof each earliercashFlowItemstops existing. - The API does not write corrections.
documentTypecreditNoteordebitNoteand theprecedingInvoicefield give 422notSupported.
Posting
Section titled “Posting”accountingDocuments.post books the document by its proposed journal entry into the journal’s buffer. The accountant approves the entry in Optima. So after a successful post the document in result still has status: "draft", and its journalEntry.status is "draft". A post of a document that already has a journal entry, from an earlier post, from the accountant or from Optima’s booking agent, answers the same way and writes nothing. The document’s status is posted only once the entry that books it leaves the buffer. That entry is a journal entry, a KPiR entry or a ryczałt entry.
You cannot update or delete a document with such an entry through the API, whether the entry is in the buffer or not. The answer is 422 documentPosted. A document entered in KPiR or in the ryczałt records also gives documentPosted on post, and notDoubleEntry in a company that keeps those books.
VAT register
Section titled “VAT register”A vatRegister is a named register that every accounting document belongs to. A company splits its purchase register and its sales register into as many as it wants, for example ZAKUP, KOSZTY and WNT.
codeis the register’s name. Optima does not store a register id on the document, only this name, and the integration matches the register by name and type.- A purchase register takes only documents with
kind: "purchase". Any other gives 422vatRegisterKindMismatch. vatRegisterId: nullon a write takes the only active register of that kind. When there are several or none, the answer is 422invalidReferencewithpath: "vatRegisterId".
The VAT register is a concept of Polish tax law, and Optima has a separate object for it. That is why vatRegisterId, vatRegisterCode and position are fields of the comarch-optima variant, not of the shared part of the accounting document.
Proposed journal entry, journal entry and journal
Section titled “Proposed journal entry, journal entry and journal”A proposedJournalEntry is Optima’s predekretacja: debit and credit lines attached to an accounting document before it is posted. You give a journal, a booking date and lines with a debit account, a credit account or both.
- The two sides must balance to the grosz. Amounts are in PLN.
- The journal in
journalIdmust belong to the fiscal year that contains the booking date. - A company on the tax revenue and expense ledger, KPiR, or on the lump-sum tax, ryczałt, has no ledger, so it sends
proposedJournalEntry: null.
A journalEntry is the entry that books the document. post creates it from the proposed one, or the accountant or Optima’s booking agent books the document. The API shows it on the accounting document as id, number, journalId and status. status is draft while the entry is in the buffer and posted once approved. The API has no separate list of journal entries.
A journal is one of Optima’s partial journals, and a fiscalYear is its accounting period. A period in Optima does not have to last twelve months. A company on KPiR has both lists empty.
Payment schedule, cash and bank
Section titled “Payment schedule, cash and bank”A cashFlowItem is an amount a document is due to pay or receive on a given day. In Optima it is an entry in the payment schedule. It is not yet money that went through a till or a bank account. That is a cashTransaction.
An item stays on the list after it is settled. Its settlementStatus and its amounts settledAmount and remainingAmount change.
settlementStatus |
In Optima |
|---|---|
notApplicable |
not subject to settlement |
unsettled |
not settled |
partiallySettled |
settled in part |
settled |
settled in full |
direction is incoming for money coming in and outgoing for money going out. The comarch-optima variant also has transferState, the state of the transfer in Optima: draft (bufor), toExecute (do realizacji, to be executed), sentToBank (sent to the bank) or confirmed (confirmed by the bank). party is who pays or receives the money: counterParty, bank, employee, shareholder (wspólnik) or taxAuthority (a tax office). An Optima party of another kind, for example an operator, has kind: "other". sourceDocument.type says what created the item.
sourceDocument.type |
Source in Optima |
|---|---|
invoice |
a purchase or sales invoice in Handel (FZ, FS), with the id invoices.get takes |
accountingDocument |
a VAT register entry |
journalEntry |
a journal entry line on a settlement account; id is the journal entry and lineId its line |
taxDeclaration |
a tax declaration |
payroll |
a payroll list; id is the identifier Optima stores with the item (BZd_DokumentID) |
openingBalance |
the opening balance; id is the identifier Optima stores with the item (BZd_DokumentID) |
deposit |
a deposit; id and number name the Handel document it belongs to |
manual |
an entry typed by hand, with no source id |
other |
any other source, with no id; a Handel document that is not a purchase or sales invoice has its number in number |
The other objects in this part:
cashAccountis a cash or bank register.kindiscash,bankorcard. The API writes only to registers in PLN.cashStatementis a cash or bank report. Every cash transaction sits in one report. A day after the last report opens a new report, and a day in a gap between reports gives 422noOpenStatement. A day in a closed report gives 422statementClosed. The accountant closes a report in Optima.cashTransactionis a cash slip, KP or KW, or a bank statement line. Optima numbers it from the register’s numbering scheme. You cannot correct one, so delete it and create a new one. On create you can name only a counterparty. Banks, employees, shareholders and tax offices are read-only.settlementlinks two cash documents: a transaction with an item, two items, or two transactions. The two documents are insides: the first is the left side of the settlement in Optima, the second the right. Optima sets the settlement date.
Optima keeps the amounts of a cash transaction and a settlement to the grosz, from 0.01 to 9999999999999.99. An amount at most a millionth of a grosz away from a whole grosz (a little more for very large amounts) is written rounded to that grosz, for example 0.30000000000000004 as 0.3. An amount further from a whole grosz, one that rounds to zero or one above 9999999999999.99 gives 422 notSupported with the amount’s path in path.
Accounts and ledger settlements
Section titled “Accounts and ledger settlements”A ledgerAccount is an account in the chart of accounts of one fiscal year. Optima copies the chart into every new year, so an account’s id changes each year. Match accounts by number.
- The API creates only analytic accounts under an existing account. The accountant sets up synthetic accounts and their type.
isSettlementAccountmarks a settlement account.- Optima has no account type for equity, so
classification: "equity"never appears. Accounts that are both asset and liability, or both revenue and cost, haveclassification: "other".
A subledger account is Optima’s dictionary account: an analytic account opened for one dictionary entry under a parent account. In a write you name it by the parent account and the entry:
{ "kind": "subledger", "parentNumber": "202", "entry": { "kind": "counterParty", "id": 41 } }ledgerAccounts.ensureSubledgerAccount returns that account and creates it if it is missing. The API creates accounts only for counterparties. Accounts from the bank, employee, shareholder and tax-office dictionaries are read-only.
A ledgerSettlementItem is an amount to settle on a settlement account. It needs double-entry books. Optima keeps receivables and payables in two places, the payment schedule and the accounts, and it carries a settlement from cash to the accounts itself when the company has “Automatyczne rozliczenia i rozrachunki” turned on. When that carrying over fails, the cash transaction or settlement stays, and warnings in the answer has the stage ledgerSyncFailed with Optima’s message. When the company has that setting off, the accountant settles the ledger by hand. An ERP that keeps receivables and payables in one place shows them only as cashFlowItem.
Dictionaries
Section titled “Dictionaries”accountingCategoryis a category of costs or revenues. You pass it ascategoryIdon a document, a line, a proposed journal entry line and a cash transaction.paymentMethodis a payment method.kindiscash,transfer,cardornetting. In Optima a payment method also carries the default number of due days and the register the money goes through.counterPartyis a counterparty card, one for supplier and customer. Banks, employees, shareholders and tax offices have their own registers in Optima and are not counterparties. On a create Sancho compares neither the code nor the NIP. Optima refuses a code already in use, and creates a second card with a NIP that another card has, as its own window does.accountingProfilesays how the company keeps its books.bookkeepingisdoubleEntryfor a full ledger,kpirfor the tax revenue and expense ledger, KPiR, andryczaltfor the revenue records of the lump-sum tax, ryczałt.ledgerLicensedsays whether the integration’s login holds the Księga Handlowa module.baseCurrencyis alwaysPLNandcountryalwaysPL.
Deleting a counterparty
Section titled “Deleting a counterparty”counterParties.delete deletes the card through the CDN.Kontrahenci collection in COM, without loading the card, as Optima’s counterparty list does. The integration checks nothing first. Optima’s database triggers and foreign keys decide, and they run on every delete, in the program too. COM skips two checks of the list window: a card sent to the head office, and prints in the print archive. The API skips them too.
The trigger stops at the first rule the card breaks and reports its code. COM passes that code in the error number, and Optima replaces the error text with its own message, for example “Nie można kasować kontrahenta domyślnego” for the default card. The table name from the trigger does not reach Sancho. The integration answers 422 inUse, and subject holds OPT and the rule’s number:
| Optima rule | subject |
|---|---|
another table names the card, for example TraNag, TraElem, VatNag, BnkZdarzenia, DekretyNag, DokNag, EwidDodNag, DeklNag |
OPT32226 |
the card is a supplier on a product card (TwrDost) |
OPT32058 |
| the default card | OPT32334 |
| an online shop’s card | OPT32341 |
| a card sent to Detal or Comarch ERP Mobile | OPT32336, OPT32337 |
| recurring invoices | OPT32338 |
| another Optima rule | OPT and the rule’s number |
A database foreign key, for example from Towary or OfertyDok, has no rule code. The API returns such a refusal as 422 with no reason (relayedFailure).
When the card breaks no rule, the trigger removes its discounts, recipients, schemes and links itself. After the delete the integration reads the card again. If the card is still there, the write ends in an error, not in { "success": true }.
Fixed assets and equipment
Section titled “Fixed assets and equipment”The integration reads cards from the CDN.Trwale table (fixed assets, SrT_Typ 11) and CDN.Wyposazenie (equipment). It writes through the COM objects CDN.SrodkiTrwale and CDN.Wyposazenia, in the order Optima’s own spreadsheet import writes them. Optima assigns the ordinal number (Lp.).
Sancho checks no module when a fixed-asset card is written, and the customer’s Optima licence covers what the connector writes.
| Write field | Fixed asset | Equipment |
|---|---|---|
inventoryNumber |
NrInwent |
NrInwent |
name |
Nazwa1 (column SrT_Nazwa, up to 256 characters) |
Nazwa (up to 50 characters) |
description |
Opis |
Opis |
categoryId |
Kategoria (SrT_KatID) |
Kategoria (Wyp_KatID) |
purchaseDate |
DataZak |
DataZak |
value |
WartoscBilan |
WartoscZakup |
kst |
KRST |
|
inventoryBook |
Grupa, a CDN.Grupy group with Gru_Typ 11 |
|
commissioningDate |
DataPrz |
|
depreciationStartDate |
DataUmo, the start of the balance-sheet plan |
|
depreciation |
MetodaBil, StawkaBil, WspolczynnikBil |
|
taxDepreciation |
Metoda, Stawka, Wspolczynnik, WartoscKoszt, DataAmo and Bilansowa 1 |
|
quantity, unit |
Ilosc, JednostkaMiary |
|
holder |
a period in CDN.TrwaleOsobyOdpowiedzialne |
a period in CDN.WyposazenieOsobyOdpowiedzialne |
placeOfUse |
a period in CDN.TrwaleMiejscaUzytkowania |
a period in CDN.WyposazenieMiejscaUzytkowania |
importSource (create) |
ImportAppID (SrT_ImportAppId) and ImportWierszID (SrT_ImportRowId) |
ImportAppID (Wyp_ImportAppId) and ImportWierszID (Wyp_ImportRowId) |
dispose: status, date, reason |
Stan (1 liquidated, 2 sold), DataLikw, Likwidacja |
Stan, DataLikw, Likwidacja |
- Two depreciation plans.
depreciationis the balance-sheet plan.taxDepreciation: nullwritesBilansowa0, one plan for the balance sheet and tax. The integration then writes the date inDataUmotoDataAmo. On existing cards withBilansowa0,WartoscKosztequalsWartoscBilan, sovaluereadsWartoscBilan. Whether Optima also copies the value intoWartoscKosztafter anupdatechangesWartoscBilanhas not been checked yet. A separate tax plan setsBilansowa1 and needs a start date.taxDepreciation.startDate: nullwrites the date fromdepreciationStartDate, and that is what you read back. When both dates are empty, the integration refuses the write before it reaches Optima, and the API answers 500. - Depreciation methods are Optima’s codes:
none0,linear1,degressive2,oneOff3,natural4.naturalonly comes from a read, so that a card with that method passes through a write unchanged. - Category. The integration assigns a
CDN.Kategorieobject only whencategoryIdchanged, because assigning it overwrites the category description on the card. - Person responsible. With
employeeIdthe period gets the employee’s current history entry, as Optima’s import does. WithoutemployeeIdOptima stores only the first and last name fromname. - Equipment quantity.
Iloscin COM takes no empty value, soquantity: nullleaves the quantity on the card unchanged. - Checks before the write. The integration makes none of its own, so Optima decides. The API returns Optima’s refusal as 422 with no reason (
relayedFailure). Nothing stops a period’s deletion either:holder: nullorplaceOfUse: nulldeletes the current period, as deleting the row on the card does in Optima. - Disposal.
disposesetsStan,DataLikwandLikwidacjaand saves the card with Optima’s ordinary save, so for a fixed asset Optima creates the liquidation document (LT), unposted. - Deletion. The integration deletes the card through the COM collection, without loading it, and then reads the card again. If the card is still there, the write ends in an error. The integration returns Optima’s refusal as for a counterparty: 422
inUsewithOPTand the rule’s number insubject.
Where the names came from
Section titled “Where the names came from”We chose each name on its own. Then we checked all of them against systems used in Poland and Europe, among them enova365, Symfonia, SAP Business One, DATEV, Exact Online and Business Central. The question was the same each time: what will a user of that system understand by our name.
| Name | Rejected | Why |
|---|---|---|
accountingDocument |
vatRecord, accountingInvoice, accountingRecord |
Not every register entry is an invoice. It can be a customs declaration, an internal document or a periodic summary. A company exempt from VAT has such documents too. In several systems “record” means a single line on an account, and the Polish “zapis księgowy” is the journal entry. “Dokument księgowy”, accounting document, means the same thing in Optima, enova365 and Symfonia. |
kind with values purchase and sales |
direction |
In the API direction means the direction of money, incoming or outgoing. An invoice already has kind with these values, and Optima calls it the type. |
vatRegister |
journal, taxRegister |
It is the literal translation. The VAT register is a concept of tax law in Poland, Italy and Spain. journal is taken by the ledger journal. |
proposedJournalEntry |
preDecree, draftJournalEntry |
“Pre-decree” is not an English accounting term. draft is the state of a real journal entry in the buffer, and a proposed entry is not in the journal yet. |
journalEntry |
ledgerEntry, decree, voucher |
Most accounting APIs call it this. |
cashFlowItem |
payment, openItem, paymentScheduleItem |
It is a planned inflow or outflow, and everywhere else payment means money that already moved. The object stays on the list after it is settled, so openItem misled. With cashAccount, cashStatement and cashTransaction it forms one family under the cash:* scopes. |
cashAccount |
cashBankRegister, bankAccount |
A till is not a bank account. “Register” already means the VAT register in the API. |
cashStatement |
bankStatement, cashReport |
One name covers a cash report and a bank statement. “Report” sounds like an analysis. |
cashTransaction |
payment, bankTransaction |
Not every entry is a payment. It can be a bank fee or a transfer between the company’s own accounts. |
settlement |
allocation, reconciliation |
It is the literal “rozliczenie” and matches the fields settlementStatus and settledAmount. Elsewhere “reconciliation” means matching a bank statement to the books. |
ledgerSettlementItem |
ledgerSettlement, ledgerOpenItem |
It is one amount to settle, not a pair of documents. Settled items stay on the list, so “open” would mislead. |
ledgerAccount |
account |
In Sancho account is the customer’s account. |
subledger |
counterParty, dictionary |
Optima opens such accounts for employees, shareholders, banks and tax offices too. “Dictionary” means nothing outside Optima. |
journal, fiscalYear, accountingCategory, paymentMethod, counterParty and accountingProfile kept the names they had from the start. Most systems understand them, and counterParty is already published.
Two decisions from that review are about behaviour, not names:
postsays how far it reaches. In Optima and enova365 posting through the API lands in a buffer. In other systems it is a step in the program, or it changes the document’s id. Sopostanswers the document, and itsjournalEntry.statussays how far the entry got. The document hasstatus: "posted"only once the entry is approved.vatRegisterandledgerSettlementItemare Optima’s resources. Other systems have no VAT register, or keep receivables and payables in one place, and the rest of the contract works without these two resources.