parity(api): port the reference price formula with tests; SMS + MON-08 reports
Adds computeVariantPrice(), a verbatim port of the live formula at henza_server/app/Models/ProductVariant.php:183-190, with the per-customer making-charge offset as an explicit input defaulting to 0. The three superseded formulas commented out above it apply VAT to the whole price and are deliberately not ported (D4). 11 unit tests assert against hand calculations derived from the PHP source rather than from the implementation, covering: with and without the offset, VAT on the non-metal portion only, floor-to-nearest-1000, the extraPercent default of 7, and the equivalence between the app folding the offset into percent_pay and the server deriving it. 18 tests pass overall. Also adds the D0 name-split review report script (read-only) and two investigations the owner asked for: - SMS: the reference uses the Trez panel (smspanel.trez.ir, Sms.php:69,97) with production credentials committed to git (SEC-12 — rotate them). All 12 message templates catalogued; env var names proposed; nothing implemented pending approval. - MON-08: henza_pwa computes percent_pay, discount and rial_pay rather than asking the user (cart.vue:170-179, Mixins/product/index.ts:69-75), so Phase 2 item #1 is to derive them server-side and ignore the client's values. rash_weight stays read from the DB as a recorded deviation. Records the owner's two new standing rules: migrations only through the standard Prisma workflow, and every data deletion logged in CHANGELOG. [ref: henza_server/app/Models/{ProductVariant,Sms}.php, henza_pwa/src/views/cart.vue] Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
c71574b1d2
commit
7b598e9e8e
@@ -235,3 +235,74 @@ order routes 401 without a token, a spoofed body `customerId` ignored in favour
|
||||
of the token, own order readable, unknown/foreign order id 404, and the admin
|
||||
order route rejecting a customer token while admitting an admin one.
|
||||
Typecheck clean on api, user-app, user-app-v2 and shared-types.
|
||||
|
||||
---
|
||||
|
||||
## 2026-09-22 — migrate resolve, D13 scope, and the D0/percent migration set
|
||||
|
||||
### Standing rule adopted (owner, 2026-09-22)
|
||||
|
||||
1. **Migrations run only through the standard Prisma workflow** — `migrate dev`
|
||||
in development. **`prisma db execute` is no longer used to apply schema
|
||||
changes.** (It was used once, in the security hotfix, to create the
|
||||
`CustomerOtp` table; that is what the resolve below repairs.)
|
||||
2. **Every data deletion is recorded here** — including throwaway rows this
|
||||
session creates itself.
|
||||
|
||||
### Data deletions (rule 2, applied retroactively to this session)
|
||||
|
||||
| When | What | How many | Why |
|
||||
|---|---|---|---|
|
||||
| Security hotfix stage 3 | `SmsMessage` rows written by the OTP flow during testing, whose `body` still held the live code before the SEC-11 fix | 9 | They contained real OTP codes in a grid any `sms`-rid operator can read. Test data only; no customer-facing message was ever sent (no gateway is wired). |
|
||||
|
||||
No other data has been deleted in this project.
|
||||
|
||||
### Ledger repair — approved and executed
|
||||
|
||||
```
|
||||
npx prisma migrate resolve --applied 20260922000000_customer_otp
|
||||
→ Migration 20260922000000_customer_otp marked as applied.
|
||||
npx prisma migrate status
|
||||
→ 9 migrations found. Database schema is up to date!
|
||||
```
|
||||
|
||||
The `CustomerOtp` table already existed (created with `db execute` in stage 2);
|
||||
this wrote the missing `_prisma_migrations` row **without running any SQL**, so
|
||||
`migrate deploy` will no longer try to re-create the table. No schema change.
|
||||
|
||||
### Documentation
|
||||
|
||||
- **D13 recorded** — the retail storefront (wallet, cashback,
|
||||
`ConfigStatic['percent']`) is preserved but out of scope. `DECISIONS.md` §D13,
|
||||
`PROTECTED.md` §H, and status `⏸️` plus RULE C1 added to the audit skill.
|
||||
- **Endpoint count corrected: 412, not 369.** `routes/admin.php` has 151 live
|
||||
explicit routes, not the 117 the Phase 0 inventory recorded (DOC-01). Of the
|
||||
412, **109 are retail storefront**, 15 are `web.php` dev/ops, and **288 stay
|
||||
in scope** (218 admin + 70 B2B app).
|
||||
- **SMS provider report** — the reference uses the Trez panel
|
||||
(`smspanel.trez.ir`, `Sms.php:69,97`) with **credentials committed to git**
|
||||
(SEC-12, must be rotated). All 12 message templates catalogued, env var names
|
||||
proposed. **Nothing implemented; awaiting approval.**
|
||||
- **MON-08 answered** — `henza_pwa` **computes** `percent_pay`, `discount` and
|
||||
`rial_pay`; the user types none of them (`cart.vue:170-179`,
|
||||
`Mixins/product/index.ts:69-75`). So Phase 2 item #1 is to derive them
|
||||
server-side and ignore the client's values, with a comparison test proving the
|
||||
total is unchanged for an ordinary customer. `rash_weight` stays read from the
|
||||
DB, recorded as a deliberate deviation.
|
||||
|
||||
### New, not yet applied — awaiting approval
|
||||
|
||||
| File | Purpose |
|
||||
|---|---|
|
||||
| `prisma/migrations/20260922120000_customer_name_parts/migration.sql` | D0 — adds `firstName`/`lastName`, backfills first-token/rest, adds a `customer_sync_full_name` trigger keeping `fullName` in sync in both directions, indexes both parts. Additive; nothing dropped. |
|
||||
| `prisma/migrations/20260922120100_customer_making_charge_offset/migration.sql` | D9 — adds `makingChargeOffsetPercent DECIMAL(6,3) NOT NULL DEFAULT 0`. |
|
||||
| `scripts/report-name-split.cjs` | Read-only review report for names with more than two tokens (D0 requirement 3), with `--csv` output. |
|
||||
|
||||
### Added and already passing
|
||||
|
||||
| File | Purpose |
|
||||
|---|---|
|
||||
| `src/modules/pricing/variant-price.ts` | The reference price formula ported verbatim from `ProductVariant.php:183-190`, with the customer offset as an explicit input defaulting to 0. |
|
||||
| `src/modules/pricing/variant-price.spec.ts` | 11 tests against **hand calculations** derived from the PHP source, covering with/without the offset, the VAT-on-non-metal-portion-only rule, floor-to-1000, and the equivalence between the app folding the offset into `percent_pay` and the server deriving it. |
|
||||
|
||||
`npx jest` → **18 passed** (7 existing + 11 new), 2 suites.
|
||||
|
||||
Reference in New Issue
Block a user