diff --git a/Distribution/docs/shop_po_invoice_operations_flow.md b/Distribution/docs/refactor_docs/shop_po_invoice_operations_flow.md similarity index 75% rename from Distribution/docs/shop_po_invoice_operations_flow.md rename to Distribution/docs/refactor_docs/shop_po_invoice_operations_flow.md index 5b7c6bb..cdbb870 100644 --- a/Distribution/docs/shop_po_invoice_operations_flow.md +++ b/Distribution/docs/refactor_docs/shop_po_invoice_operations_flow.md @@ -35,10 +35,28 @@ status transition and stock movement along the way. - Created via `ShopPOService.ConfirmAndCreateInvoiceAsync` — confirms the PO **and** creates an `Invoice` (`Status: Draft`, `PaymentStatus: Pending`) in one step, linking `ShopPO.InvoiceId`. - (No frontend UI currently calls this endpoint — only the plain `Confirm` action is wired up.) + The frontend calls it when **Configuration → Invoice Creation** is set to **Auto** (Mode A, the + confirm dialog and PO edit page read the mode); with **Manual** (Mode B, the default) it calls the + plain `Confirm` and the invoice is created later from `/sales/orders` → **Create Invoice**. - Lifecycle: `Draft → Printed → Finalized`. - - Finalizing can adjust the billed quantity per line (capped between `0` and the ordered - quantity) and recomputes `TotalAmount` from the adjusted lines. + - The invoice has its own lines (`InvoiceItem`), copied from the PO's active lines when it is + created (either mode). The PO's original quantity stays on `ShopPOItem` and is shown as + `orderedQuantity`. + - While `Draft`, lines can be edited (`PUT /invoices/{id}/items`): change quantity (`0..ordered` + on PO lines) and price (`>= 0`), **delete** a line (it is kept, struck through, excluded from + the total, and can be restored), or **add** a catalog item that was not on the PO (no ordered + quantity / max). `TotalAmount` is recomputed from the non-deleted lines. + - Finalizing applies the agent's edits from the printed copy to the lines (quantity capped + between `0` and the ordered quantity, or a line removed) and recomputes `TotalAmount`. + - Every change is snapshotted as an `InvoiceVersion` — see + [refactor_docs/order_invoice_lifecycle.md](refactor_docs/order_invoice_lifecycle.md#invoice-line-items--version-history). + - Frontend, `/sales/orders` row icons: **eye** = invoice preview, **pencil** (Draft) = open the edit page for the + draft invoice (`/sales/invoices/[id]/edit`: trash/undo icon per line, add-item row), **printer** (Draft) = + mark as printed and open the print tab; on Printed/Finalized the printer reprints without + changing status; plus finalize and record payment. `/sales/invoices/[id]` shows the items table + (ordered vs billed, Added/Removed badges), the version history, and the same actions. + - Invoice document and print tab: see + [refactor_docs/order_invoice_lifecycle.md](refactor_docs/order_invoice_lifecycle.md#invoice-screens--printing-frontend). - Payments (`payments` API) apply against the invoice, moving `PaymentStatus`: `Pending → PartiallyPaid → Paid`.