# Cash and bank — business logic

A cash document records money movement: payment to a supplier, receipt
from a customer, transfer between the company's own accounts, payment for
services. It doesn't move goods — only money, and lives by its own separate
logic, not tied to warehouse lots.

## Manual and automatic

A cash document can be created by the user manually (on its own), or
automatically — as a "twin" of a receiving or expenditure/selling document,
if a payment account is specified in their header. In that case payment is
processed together with the goods document, on the same date, with no
separate step. The automatic document gets its own number of the form
`G-…`, derived from the type, number and date of the source document — so a
receiving and a sale that happen to share a number and date each get their
own payment document and never share one.

**An automatic payment document lives and dies with its source.** It can't
be rolled back on its own — the system refuses and asks you to roll back
the source document; when the source is rolled back, its payment document
disappears together with it. If an administrator corrects the number or
date of the source document (Special Operations), the payment document is
renamed along with it, so the link isn't lost.

**Why this matters:** without this link, every payment would require two
separate documents and two separate user actions, and it's easy to forget
to process the payment separately — goods shipped, but the money side of
the operation left unrecorded.

## A line is a transaction on its own

Every cash document line is a complete transaction in itself:
- **Debit / Credit** — money leaves or arrives. Usually only one of the two
  amounts is filled; both at once is a rare case of a compound entry (e.g.
  a currency conversion with a fee).
- **Destination account** — for a transfer between the company's own
  accounts: one account "from," the other "to."
- **Linked document** — which receiving/expenditure/sale is being paid by
  this line.

## What happens on processing

For each line: if the link to a related document isn't set yet, the
current document's number and date are used; if a counterparty is
specified, their balance is updated (the difference between debit and
credit is added to the balance: paying a supplier reduces the debt owed to
them, receiving from a customer increases what they owe, or reduces what's
owed to them). A cash document by itself never recalculates stock — it's a
purely monetary operation, fully separate from lot accounting. A rollback
of a cash document reverses exactly these balance changes line by line.

## Services aren't a separate document type

Paying for a service (a consultation, delivery billed as its own line item,
etc.) is entered as an ordinary cash document line — its meaning is set not
by a document type, but by the line's classifier ("operation reason"), the
same as any other transaction. There's deliberately no separate "service
document" form with special rules — that would be an extra type just for a
special case that's perfectly well described by the general cash document
mechanism.
