Use this skill when the user wants to re-run, replay or audit a day's grocery baskets against the store coupon handbook: deciding which bogo, percent and amount coupons apply, applying the member discount, and producing receipts.csv and rejected-coupons.json from input.json. Not for other pricing or discount tasks that don't follow this handbook.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Coupon Checkout?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/gabrielmoreira-coupon-checkout-8680f4fd)
---
name: coupon-checkout
description: "Use this skill when the user wants to re-run, replay or audit a day's grocery baskets against the store coupon handbook: deciding which bogo, percent and amount coupons apply, applying the member discount, and producing receipts.csv and rejected-coupons.json from input.json. Not for other pricing or discount tasks that don't follow this handbook."
---
# Coupon checkout re-run
Recompute every basket of one day by hand (no code execution needed), then write two files beside `input.json`.
## Inputs
Read `input.json`: `day`, `products` ({sku, dept, priceCents}), `coupons`, `members` (id -> "gold"|"basic"), `baskets` ({basket, member, lines:[{sku,qty}], codes}). All money is integer cents. If a sku is missing from products, or a member ID is missing from `members`, do not guess silently: treat a missing member as no member discount, and note it in your final reply.
## Outputs (beside input.json)
- `receipts.csv`: header `basket,subtotal,discount,total`, one row per basket in input order. Dollars with exactly two decimals, no sign. Format cents `c` as `floor(c/100)` + "." + two-digit `c mod 100` (e.g. 5 -> `0.05`, 2616 -> `26.16`, 0 -> `0.00`). `discount = subtotal - total`. Basket IDs are copied as given.
- `rejected-coupons.json`: JSON array of `{"basket":..,"code":..,"reason":..}`; `[]` if none. Order: basket order, then the order codes were handed over. Reasons: `unknown`, `expired`, `not-best`, `below-minimum`, `used`.
## Steps per basket (process baskets in input order; keep a global set `redeemed` of amount codes)
1. **Subtotal** = sum of `price * qty` over lines.
2. **Classify each code** in handed-over order:
- not in `coupons` -> reject `unknown`.
- `day > expiresDay` -> reject `expired` (`day == expiresDay` is still valid).
- else it is valid; keep it by type. Expired/unknown codes do nothing else.
3. **Bogo** (at most one valid): on its sku's line, `free = floor(qty/2)`. Line amount = `price * (qty - free)`. All other lines: amount = `price * qty`. (qty 1 -> 0 free, 4 -> 2, 5 -> 2.) Bogo is never rejected once valid.
4. **Percent**: for each valid percent coupon compute `D = sum over lines with line.dept == coupon.dept of floor(lineAmount * percent / 100)`, using line amounts from step 3 (integer division, drop the fraction per line, not on the total). Pick the largest `D`; tie -> the code that is smaller in plain ASCII order (uppercase before lowercase, digits before letters, compare character by character). Every other valid percent coupon -> reject `not-best` (record in handed-over order with the other rejections). A chosen coupon with D = 0 is still the used one. Percent discount `P` = chosen D (0 if none).
5. **After-percent amount** `A = sum(line amounts) - P`.
6. **Amount coupon** (at most one that is valid):
- if its code is in `redeemed` -> reject `used` (checked before the minimum).
- else if `A < minSpendCents` -> reject `below-minimum`; do NOT add to `redeemed`.
- else (`A >= minSpendCents`, equality passes) it is used: `A = A - amountCents`; add code to `redeemed`; set `usedAmount = true`.
The undiscounted subtotal never counts toward the minimum. Only expired/unknown amount codes never reach this step and are never redeemed.
7. **Member**: eligible if member is "gold", or member is "basic" and `usedAmount` is false. Null member -> none. If eligible, `M = floor(A * 5 / 100)`, else 0.
8. `total = A - M`; `discount = subtotal - total`. Write the row.
Rejections from steps 2, 4, 6 for one basket must be listed in the order the codes were handed over, not step order: collect them, then sort by position in `codes`.
## Worked example
Basic member, day valid; codes: PCT10 (10% dairy), AMT5 (500 off, min 3000). Lines: 2 cheese (dairy) at 1595, bread 245. Subtotal 3435. Percent: floor(3190*10/100)=319 -> A=3116. 3116 >= 3000 -> A=2616, amount used, so basic gets no 5%. total 2616 -> row `...,34.35,8.19,26.16`. Same basket as gold: M=floor(2616*5/100)=130, total 2486.
## Care points
- Do arithmetic carefully, line by line; recheck every product and sum, as nothing can be executed.
- Amount codes are redeemed only by baskets processed earlier in the day order; a rejected `below-minimum` code stays available for later baskets.
- Don't reorder baskets; don't skip baskets with no codes (they still get a row).
- Output only these two files; JSON must be valid (double quotes, basket value in the same type as input).