# Selling — business logic

Selling is a shipment to a customer with revenue recorded. Technically it's
the same mechanism as expenditure (see [Expenditure and
transfer](expenditure_en.md) — stock check, lot write-off, splitting
across several lots), but with a different business meaning: here the goods
leave the company for good, and this very shipment is a source of income,
not just an asset moving around.

## How it differs from expenditure

- **No destination warehouse.** The goods leave the business — there's
  nowhere left to receive them, unlike expenditure, which can be a transfer
  between the company's own warehouses.
- **Reservation is always released.** If the item had a reservation for
  this customer or order, it's released in full for the shipped quantity,
  with no further conditions (on expenditure, reservation release only
  happens for a credit shipment to a specific partner).
- **The two prices on a line are always meaningfully different**: the
  write-off price (the lot's cost basis in stock) and the selling price
  (the retail/customer price) — the difference between them is exactly the
  line's gross margin.

## Selling below cost is allowed

A selling price lower than the lot's cost isn't an error: clearance sales,
promotions and writing off slow-moving stock are normal business. That's
why the system doesn't block such a sale by default. For a business that
does want this rule, there's a ready-made control "No sale below cost"
(for expenditure and selling): it's switched on during setup of a specific
installation, and then processing is refused if any line is priced below
its lot's cost. Which controls are active is shown in Tools → Control.

## An order closes automatically

If a selling line was picked against an open order position, the
corresponding order position closes automatically after processing (fully
or partially, based on the quantity actually shipped). The user doesn't
need to separately mark the order as fulfilled — that's a consequence of
the sale itself, not a separate action.

## Debt or payment

If an account is specified in the header, a cash document twin is
automatically created on processing for the sale amount: money is
considered received right away, with no separate "record payment" step, and
the customer's balance isn't adjusted. If no account is specified but a
customer is, the sale amount is subtracted from their balance, creating a
debt ("sale on credit").

The same applies at the point of sale: a receipt paid to an account goes
into an automatic payment document, while a receipt for a known customer
with no account is recorded as that customer's debt. Rolling back the
day's POS document returns those debts.

On rollback of a sale the goods go back to their lots, the order's shipped
quantity and the reservations the sale used up are restored, and a debt is
taken back off the customer's balance (for a paid sale the automatic
payment document disappears with it).

## A receipt isn't a separate entity

A receipt or invoice to the customer is a printed form of an already-saved
sale document, not an independent physical object with its own state. If a
customer loses their paper receipt, there's no "restore" operation needed —
the same document is printed again, as many times as needed, from the same
data. This is a direct consequence of the "reports are computed, not
stored" principle (see [Concept](concept_en.md#reports-computed-not-stored)):
a printed form is just another way to display data that already exists in
the document.
