feat: discount coupons (front 8.3)
Gestão creates coupons in the Site tab: a code, a percentage or an amount per billed metre, validity, a minimum of metres, use limits in all and per customer, one product or all, and a note; they can be paused and deleted (kept for history). The customer types the code at checkout; the server checks it when the quote is made and again at approval, discounts only the eligible items after the bands (never freight or the treatment) and keeps the coupon on the order. Tiny gets the discount, the e-mail and receipt show it, the order panel carries a badge and Números counts orders, metres, discount and money per coupon. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -622,3 +622,25 @@ CREATE INDEX IF NOT EXISTS product_prices_current ON dtf_local.product_prices(pr
|
||||
-- product: base price, then "from 5 m R$ Y", "from 20 m R$ Z" (jsonb list of
|
||||
-- {"from_metres": "5", "unit_cents": 1990}, strictly increasing, at most 5).
|
||||
ALTER TABLE dtf_local.product_prices ADD COLUMN IF NOT EXISTS bands jsonb NOT NULL DEFAULT '[]';
|
||||
|
||||
-- Front 8.3: discount coupons, created in the Kanban's Site tab. The id is
|
||||
-- generated in Python (schema.sql does not use gen_random_uuid). A deleted
|
||||
-- code may be created again; the orders that used it keep its id and code.
|
||||
CREATE TABLE IF NOT EXISTS dtf_local.coupons (
|
||||
id uuid PRIMARY KEY,
|
||||
code text NOT NULL CHECK (code ~ '^[A-Z0-9-]{3,30}$'),
|
||||
kind text NOT NULL CHECK (kind IN ('percent','per_metre')),
|
||||
value integer NOT NULL CHECK (value > 0), -- percent: 1..90; per_metre: cents per billed metre
|
||||
valid_from timestamptz NOT NULL DEFAULT now(),
|
||||
valid_until timestamptz,
|
||||
min_metres numeric(8,1),
|
||||
max_uses integer CHECK (max_uses > 0),
|
||||
max_uses_per_customer integer CHECK (max_uses_per_customer > 0),
|
||||
product text CHECK (product IN ('file','avulsa','uvfile','uv')), -- NULL = every product
|
||||
note text NOT NULL DEFAULT '',
|
||||
paused boolean NOT NULL DEFAULT false,
|
||||
deleted_at timestamptz,
|
||||
created_by text NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS coupons_live_code ON dtf_local.coupons(code) WHERE deleted_at IS NULL;
|
||||
|
||||
Reference in New Issue
Block a user