Files
Wabenhain/src/lib/sales.ts
T
Nick SzaunigandClaude Opus 5.5 e0b47faf45
Docker Image bauen und veroeffentlichen / build-and-push (push) Successful in 2m24s
feat(orders): reopen cancelled orders only after confirmation; accurate sales
Cancelled orders:
- Moving an order out of STORNIERT is possible again, but only after a
  warning is confirmed in the status form (OrderStatusForm); without
  the confirmation the server changes nothing.
- Reopening books the counter-entry to the cancellation: goods that the
  cancellation restocked are deducted again (atomically, only if enough
  stock is left, otherwise the order stays cancelled). A later second
  cancellation therefore restocks +1 again instead of leaving +2.
- The warning states that no new payment is collected.

Dashboard figures:
- One definition of a counted sale (lib/sales.ts): not unpaid (NEU),
  not cancelled, no refunded return. Used for revenue today/month, sold
  glasses, average cart, top products/categories, revenue trend and
  repeat customers.
- "Verkaufte Gläser" previously summed every order item, including
  cancelled orders and refunded returns.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2026-09-27 01:14:12 +02:00

19 lines
783 B
TypeScript

import type { Prisma } from "@/generated/prisma/client";
/**
* Welche Bestellungen zaehlen in der Auswertung (Admin-Dashboard) als Verkauf?
*
* - nicht "NEU": noch nicht bezahlt — die Ware ist nur reserviert, nicht verkauft
* - nicht "STORNIERT": Ware zurueckgebucht, Geld erstattet
* - keine erstattete Retoure: die Glaeser sind zurueck im Bestand und das Geld
* bei der Kundschaft; sie weiter als verkauft zu zaehlen, blaehte Umsatz und
* "Verkaufte Glaeser" auf
*
* EINE Definition fuer alle Kennzahlen, damit Umsatz, Glaeser, Warenkorbwert
* und Top-Produkte nicht auseinanderlaufen.
*/
export const COUNTED_SALE_WHERE = {
status: { notIn: ["NEU", "STORNIERT"] },
NOT: { returnRequest: { is: { status: "ERSTATTET" } } },
} satisfies Prisma.OrderWhereInput;