Skip to content

Offers, Discount Codes & Vouchers

How scheduled offers, discount codes and vouchers differ, how they are configured, and how each is applied and counted at checkout.

13 min read

Overview

Kagami has three separate discount mechanisms. They live in different tables, have different rules, and are configured on different screens. A bill has one code field, so one code (a discount code, voucher or offer code) can be typed per bill. The "One code per bill, and stacking" section below explains how that code combines with other discounts.

Kagami promotional offers, coupon codes, bundle pricing rules, and special salon offer management

Offers Discount codes Vouchers
Table offers discount_codes discount_codes (same table, extra columns)
Typical use "Tuesday hair spa 20% off", festival and month-end deals Promo codes such as WELCOME10 Referral rewards, raffle prizes
Schedule (weekday / date / month-end) Yes (IST) No No (they only have an expiry)
Limited to services / categories Yes No (services_only flag on vouchers only) services_only flag only
Applied without typing a code Yes (auto_apply, called a Daily offer) No No (one-tap chip for referral rewards)
Per-client limit Yes (per_client_limit) No Bound to one client instead
Usage cap max_uses max_uses max_uses is 1
Redemption log offer_redemptions discount_code_usages discount_code_usages

"Voucher" is not a separate table. A voucher is a discount code row with extra columns (client_id, services_only, referral_event_id, referral_role, location_id). Gift cards are a fourth, unrelated mechanism: they hold a prepaid balance and are paid at checkout like a payment method, not a discount. See Checkout & POS.

How it works

One code field at checkout

The POS has one Promo Code field and the bill carries one discountCode. The server checks it in this order (web/src/lib/discount-codes/checkout-actions.ts, validateCodeAction; the same order is used when the invoice is created in web/src/lib/billing/actions.ts):

  1. Look it up as a discount code (validateCode). Codes are upper-cased and trimmed.
  2. Only if that returns exactly Invalid code (no such code for the brand), look it up as an offer (validateOfferCode).

So if the same string exists as both a discount code and an offer, the discount code is used.

Discount-code validation

validateCode runs these checks in order and returns the first failure:

Check Error shown
Code exists for the brand Invalid code
is_active Code is inactive
expires_at is in the past Code has expired
uses_count >= max_uses Code has reached maximum uses
Client-bound / referral voucher belongs to this client This voucher is tied to a client — select the client first, This voucher belongs to a different client
Referral still live Referral not found, This referral reward is no longer available
location_id matches the bill's location This voucher can only be used at the location it was earned at
Services-only voucher has a service on the bill This voucher applies to services only — add a service to the bill
Bill meets min_order_minor Minimum order ₹N required (or Minimum services ₹N required)

Discount amount: percent is round(basis * value / 100); fixed is min(value, basis). The basis is the bill subtotal after line discounts, or the services-only subtotal before any discount for services-only vouchers. value for fixed codes is in paise.

There is no per-client limit, weekday schedule or service scope on a plain discount code.

Offer validation

validateOfferRow (web/src/lib/marketing/offers-core.ts) applies the same checks to a typed offer code and to an auto-applied offer:

Check Error shown
Code exists, is_active, same brand Code not found or inactive.
now < valid_from This offer is not valid yet.
now > valid_to This offer has expired.
uses_count >= max_uses This offer has reached its usage limit.
Today (IST) matches the schedule This offer is only valid on <schedule>.
Scoped offer has at least one matching line This offer does not apply to the items on this bill.
Matching (eligible) subtotal >= min_spend_minor Minimum spend of ₹N required.
Client has fewer than per_client_limit rows in offer_redemptions You have already used this offer.

Things to know:

  • Per-client limit only runs when a client is on the bill. A guest bill skips it. per_client_limit of 0 means unlimited.
  • Minimum spend is checked against the eligible subtotal, not the whole bill, so a scoped offer needs enough of the covered services.
  • Discount amount (offerDiscountMinor): percentage is round(eligible * value_minor / 10000) (so value_minor is percent times 100, capped at 10000 by the create action); every other type is a flat value_minor capped at the eligible subtotal.
  • The offers.type enum also has free_service, gift_card and referral. The billing code has no special handling for them: they are treated as a flat amount off. The Daily Offers form only offers percentage and fixed_amount.

Schedules (IST)

All schedule logic is in web/src/lib/marketing/offer-scope.ts and uses IST (UTC+05:30, no DST). An offer can combine three rules, and they are a union: the offer runs if any rule matches. With none set it runs every day.

Rule Column Matches when
Weekdays weekdays (0 = Sunday to 6 = Saturday) The IST weekday is in the list
Specific dates specific_dates (IST YYYY-MM-DD) Today's IST date is in the list
Month end month_end_days (1 to 31) daysInMonth - today < N, i.e. the last N days of the month

Examples: month_end_days = 3 runs on the 28th, 29th and 30th of a 30-day month. Weekdays plus month end means "every Tuesday and also the last 3 days of the month".

Separately from the schedule, the offer has an overall window: valid_from (defaults to now at creation) and valid_to. A bare date entered as the end date is stored as 23:59:59.999 IST, so "valid through" that day. The Daily Offers start date is stored as 00:00 IST.

Scope (services and categories)

service_ids and category_ids limit what an offer discounts. A bill line matches if its service is in service_ids or its service's category is in category_ids. With neither set the offer covers the whole bill, products included.

At POS, scoped offers discount only the matching service lines (after line discounts). Product lines are sent with no service id, so they only count toward an unscoped offer.

Auto-apply (Daily offers) at POS

findAutoOffer loads the brand's active offers with auto_apply = true, runs the same validation as a typed code, and picks the one with the highest discount in rupees. On a tie, one of the equally valued offers is applied.

The POS flow (web/src/app/(tenant)/dashboard/billing/checkout/pos-flow.tsx):

  1. Runs only for a service sale with at least one service line. Product edits do not trigger it. It waits 400 ms after the service lines change.
  2. Fills the Promo Code field with the offer's code and shows the offer name and amount.
  3. Is skipped, or removed with the message "Daily offer removed: this bill has a manual discount, and only one discount applies", when the bill has any manual invoice-level or line discount.
  4. Can be cleared by the biller. Clearing it stops auto-apply for the rest of that bill.
  5. The server does not trust the preview. The auto offer is just a discountCode string, so billing re-validates it when the invoice is created.

A typed offer (non-auto) is fixed at the amount calculated when it was applied. If the bill's items change, it is dropped with "Bill items changed. Re-apply the offer code."

One code per bill, and stacking

  • One code field per bill. A bill has a single discountCode, which is one discount code, voucher or offer code.
  • Auto offers do not combine with manual discounts. The POS removes the auto offer when the bill has a manual discount (above).
  • A typed code or offer can combine with a manual invoice discount and a spin-wheel prize. The amounts are added together and the total is capped at the bill subtotal (min(subtotal, manual + code + spin prize)).
  • A referral voucher cannot be combined with a manual discount or a spin prize. Billing returns "A referral reward can't be combined with another discount on the same bill".

Redemption and usage counting

After the invoice is created, billing records the redemption in a background step, so it does not block or fail the sale:

  • Discount code or voucher: redeemCode inserts a discount_code_usages row and adds 1 to uses_count. For referral vouchers it also notifies the owner.
  • Offer: redeemOfferCode inserts an offer_redemptions row and adds 1 to uses_count.

Failures are logged server-side and are not shown to the biller.

Neither counter is reduced when an invoice is later voided or refunded.

Usage limits and expiry for codes

Setting Discount code Offer
Total uses max_uses, blank = unlimited max_uses, blank = unlimited
Per client Not available per_client_limit (see defaults below)
Expiry expires_at, exact timestamp, checked against the current time valid_to, end of that day IST when a date is entered
Start Not available valid_from
Pause Activate / deactivate toggle Pause / Resume (Daily offers)

per_client_limit default when creating an offer: 1 for a plain offer, 0 (unlimited) when the offer has weekdays, dates, month-end days, or is auto-apply. The Offers form does not send a value, so it uses these defaults.

Vouchers

All vouchers are discount code rows. Three sources exist:

Source How it is built Rules
Referral flat reward createReferralVoucher Fixed amount, max_uses 1, bound to the referrer or the friend (client_id or matched by the friend's phone), services_only and min_order_minor come from the referral program, optionally pinned to a location, expires with the referral. One per side per referral (unique index).
Referral percentage reward createCode Code REF<BRAND4><6 digits>, max_uses 1, expiry from the program. Not bound to a client.
Raffle prize issuePrize in web/src/lib/raffles/service.ts Code RAFFLE-..., percent or fixed, max_uses 1, optional validity days. Not bound to the winner.

Referral voucher rules at checkout:

  • Needs the client selected on the bill.
  • The referrer's voucher works only once the referral status is rewarded. The friend's works while the referral is pending, qualified or rewarded.
  • The client's unspent vouchers appear as one-tap "Referral reward" chips under the Promo Code field.
  • The friend's voucher is switched off when their first bill qualifies the referral. All unspent vouchers for a referral are switched off when it is closed, cancelled or expired.

Where owners configure it

What Where Permission
Discount codes (and usage history, KPIs) Dashboard > Discount Codes (/dashboard/discount-codes) marketing.coupons
Discount codes and gift cards Dashboard > Settings > Vouchers (/dashboard/settings/vouchers) Discount codes tab: marketing.coupons. Gift cards tab (issuing a card): wallets.add_money
Scheduled / auto-apply offers Dashboard > Marketing > Daily Offers (/dashboard/marketing/daily-offers) marketing.coupons
Offers with a typed code /dashboard/marketing/offers ("Offers & promo codes") marketing.coupons

The Offers page is not linked from the sidebar nav (web/src/lib/nav/sections.ts); it is reached by URL. It lists offers without auto-apply, and the page only creates and lists: it has no pause, edit or delete. Daily Offers lists only auto-apply offers and can pause and resume them, but cannot edit or delete.

The Offers form takes: code, name, type, value, max uses, expiry date, weekdays, services / categories, and a description that the AI receptionist shares with clients. The Daily Offers form takes: name, when it runs (every day / days of week / specific dates / month end with a "last N days" number, default 3), start and end date, percentage or fixed rupees, and at least one service or category. The code is generated as AUTO- plus six characters.

Create-time rules enforced by the server

  • Value must be a whole number greater than zero; a percentage cannot exceed 100.
  • An auto-apply offer must be limited to at least one service or category ("otherwise it would discount every bill").
  • Weekdays outside 0 to 6 and malformed dates are dropped.
  • A code is required unless the offer is auto-apply.

What clients and staff see

  • Billing staff: the Promo Code section shows the applied code, its label and the amount off. A failed code shows the specific error from the tables above. Auto offers show the offer name and can be cleared.
  • Owners: Discount Codes shows Active Codes, Total Codes, Total Uses and Total Savings, plus a Usages tab (latest 100). Codes are shown as Active, Inactive, Expired or Used up. Delete has an undo window.
  • Clients on WhatsApp: the AI receptionist's get_promotional_offers tool reads offers only, not discount codes. It uses active offers inside their valid_from / valid_to window that have not hit max_uses, returns up to 10 (today's first), and checks schedule, scope and minimum price per service before pitching. For auto-apply offers it is told never to ask the client for a code. When the AI books a service it prices the best qualifying offer into the booking and does not add a negotiated discount on top.
  • External API / MCP: exposes a read-only list of offers with similar filters.
  • The client portal "Vouchers" tab shows gift cards only, not discount codes.

Background jobs

Referral voucher upkeep runs in the nightly referral maintenance job (runReferralMaintenance): it warns the owner 7 days before an unspent referral voucher expires, and when one lapses it notifies the owner and sets it inactive. Ordinary discount codes and offers have no job; they simply fail validation when expired or used up.

Data model

Table Key columns
offers brand_id, code (unique per brand), name, description, type, value_minor, min_spend_minor, max_uses, uses_count, per_client_limit, valid_from, valid_to, is_active, weekdays, specific_dates, month_end_days, service_ids, category_ids, auto_apply
offer_redemptions offer_id, client_id, appointment_id, discount_minor, redeemed_at
discount_codes brand_id, code (unique per brand), discount_type (percent / fixed), value (percent, or paise), min_order_minor, max_uses, uses_count, expires_at, is_active, description, plus voucher columns client_id, services_only, referral_event_id, referral_role, location_id
discount_code_usages discount_code_id, client_id, appointment_id, amount_saved_minor, used_at

campaigns.offer_id can point at an offer. Deleting a discount code deletes its usage rows (ON DELETE CASCADE).

Permissions

Action Permission Default roles
Create, toggle or delete discount codes; create or pause offers marketing.coupons org_owner, brand_manager, location_manager
Issue a gift card (Settings > Vouchers, Gift cards tab) wallets.add_money org_owner, brand_manager, location_manager
Apply a code or offer at checkout Signed-in user with access to the brand (finalising the bill needs the billing permission below) All roles that can open checkout
Make / finalise the bill itself Billing create permission Managers by default

Roles can be adjusted in role permissions. The pages themselves are visible to manager roles in the nav.

Edge cases and failure behaviour

  • Bad codes and expired or exhausted offers block checkout with the exact message; nothing is half-applied.
  • If the auto-offer lookup fails, the POS shows "Could not check today's offers: " followed by the reason and the bill continues without a discount.
  • A fixed discount can never exceed the eligible basis. The total of all discounts is capped at the bill subtotal.
  • Guest bills: offers skip the per-client limit; client-bound vouchers fail with "select the client first".
  • If recording the redemption fails after the invoice is created, the sale stands and the failure is logged server-side.
  • Services-only vouchers are measured on service lines before any discount.

Source

  • web/src/lib/marketing/offers-core.ts (validation, auto-apply, redemption)
  • web/src/lib/marketing/offer-scope.ts (schedule, scope, discount maths)
  • web/src/lib/marketing/offer-dates.ts (expiry to end of day IST)
  • web/src/lib/marketing/admin-actions.ts (createOfferAction, setOfferActiveAction)
  • web/src/lib/discount-codes/index.ts, admin-actions.ts, checkout-actions.ts
  • web/src/lib/billing/actions.ts (code resolution order, stacking rules, redemption)
  • web/src/app/(tenant)/dashboard/billing/checkout/pos-flow.tsx (Promo Code section, auto offer)
  • web/src/app/(tenant)/dashboard/discount-codes/, settings/vouchers/, marketing/offers/, marketing/daily-offers/
  • web/src/lib/referrals/rewards.ts, maintenance.ts; web/src/lib/raffles/service.ts
  • web/src/lib/ai/tools.ts (get_promotional_offers), web/src/lib/ai/workflows/appointments.ts (applicableOffer)
  • Migrations 0017, 0053, 0220, 0221, 0265, 0266