Fix 6 bugs from code review

Critical:
- Single-order discount used wrong column names (discount_pct/discount_flat_cents
  → discount_type/discount_value). Discounts were silently $0.
- Single-order discount skipped allowed_emails and expires_at checks
- Free orders now set paid_at = NOW()

High:
- Discount usage now tracked in discount_usage table + current_uses incremented
- Flat discount only replaces bundle when flat >= bundle (was always replacing)

Minor:
- Removed unused CDR profile fetch in EntityStep

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
justin 2026-05-22 02:16:38 -05:00
parent 4125b0f09f
commit d4c4ae003e
3 changed files with 49 additions and 16 deletions

View file

@ -338,9 +338,7 @@
entity.contact_name = d.rmd.contact_name;
}
intoInputs(entity);
// Also try loading from our DB in case we have a richer record
const dbResp = await fetch(`${API}/api/v1/cdr/profile/by-entity/${frn}`).catch(() => null);
// Look up by FRN in telecom_entities
// Look up by FRN in telecom_entities (richer record)
try {
const teResp = await fetch(`${API}/api/v1/entities/telecom?frn=${frn}`);
if (teResp.ok) {