Refactor code structure and remove redundant sections for improved readability and maintainability

This commit is contained in:
Stefan
2026-07-10 21:03:55 +02:00
parent 42997c4f49
commit 83d1c28b29
18 changed files with 696 additions and 86 deletions
+16 -3
View File
@@ -51,9 +51,22 @@ Expiry: Server (timer) --SignalR draftExpiring{token,secondsLeft}--> warn "bit
`Sums`, `ValidationMessages`, `History`, `Version`, `Token`, `InvId`, `LastAccessUtc`.
- **Calculation** (`InvoiceDraftCalculator`, static/pure) ports the former client math:
`RecomputeItem` (quantity × price × VAT, the `quantChange` port), `RecomputeTotals`
(the `invSumUpdate`/`csms` aggregation + §13b reverse-charge), and `Validate`
(email/address/items/VAT-rate/negative-total checks). Being pure, it is exhaustively
unit-tested.
(the `invSumUpdate`/`csms` aggregation + §13b reverse-charge), `RecomputePositions`
(numbers every line except heading/free-text lines continuously across the whole invoice —
mirroring the editor's `invSumUpdate`, so the editor and the PDF show identical `Pos.` numbers,
including after a reorder),
and `Validate` (email/address/items/VAT-rate/negative-total checks). Being pure, it is
exhaustively unit-tested.
- **Sanitisation & reorder.** Scalar text deltas (`title`/`email`/`address`/`provisionperiod`/
`provisionlocation`) and the section heading (`block.replace`) are stripped of the editor's
TinyMCE HTML (`<p>…</p>`, `<br>`) to plain text in `ApplyDelta` (`HtmlToPlain`) — the backend
is the single source of truth, so no HTML reaches the DB, the PDF or a reloaded draft. Section
drags post a `block.order` delta (`["id",…]`) that reorders `Req`; positions are then
renumbered and pushed back via the view state (`applyState`/`applyPositions`). The change
history records the **changed field** (e.g. the new heading text), never the whole block JSON.
The PDF (`FuchsPdf`) renders a heading row per block (`FdsInvoiceData.InvoiceBlocks`) and shows
every position's price (set members are priced like standalone lines; only `setonly` collapses
them), so the PDF preview mirrors the online editor.
- **Orchestration** (`InvoiceDraftEditService`, scoped) opens sessions (from a fresh
payload or by reloading a DB draft via `fds__getInvoice`, reshaped like
`BuildInvoiceRequestList`), applies deltas (`ApplyDelta`), builds the view-state DTO,