# Business Flows

## End-to-End Flow (Conceptual)

1. **Admin sets up platform**
   - Creates subscription plans.
   - Creates/approves shops and assigns shopkeepers.
   - Optionally manages locations (countries/states/cities) and shop categories.

2. **Shopkeeper subscribes and publishes offers**
   - Gets a subscription plan assigned to the shop.
   - Creates discount offers:
     - Fixed amount or percentage.
     - Applicable to entire bill, a category, or a specific product/service.
   - Creates reward rules:
     - Points per purchase (fixed or percent-based).
     - Applicable to entire bill, a category, or a specific product/service.

3. **Customer/Guest discovers offers**
   - Customer logs in and can view active discounts in their “Discounts” page.
   - Guests can access the landing page and browse shops, but the current codebase does not provide a guest-facing offers list.

4. **Customer purchases and receives rewards**
   - At purchase time, the system applies the best-matching discount rule.
   - After purchase is recorded, the system adds reward points to the customer wallet and logs a ledger entry.
   - The customer’s points can later be used for discounts (redemption is not implemented in the current codebase).

## Admin Flow (Current Implementation)

### A) Subscription Plans

- Admin maintains subscription plan master data (title, price, duration).
- Admin assigns a subscription to a shop with start/end dates and status.

### B) Shop and Catalog Governance

- Admin can manage shops and high-level data needed for front browsing:
  - Shop category and shop location (city).
  - Shop status (active/inactive).

## Shopkeeper Flow (Current Implementation)

### A) Catalog Management

- Creates product categories and products.
- Creates service categories and services.

### B) Offer and Reward Setup

- Creates discount rules (active window, optional minimum amount).
- Creates reward rules (active window).

### C) Recording a Purchase (Order)

The system currently records orders via the shopkeeper panel:

1. Shopkeeper selects a customer.
2. Shopkeeper selects an item type (PRODUCT or SERVICE), item, and quantity.
3. System calculates:
   - Subtotal = unit_price × quantity
   - Discount = best discount among active, matching rules
   - Total = subtotal − discount
   - Points earned = best points among active, matching reward rules
4. System writes:
   - Order and order item rows
   - Wallet balance update (earn)
   - Ledger entry (earn)

## Customer Flow (Current Implementation)

### A) Discover Discounts

- Customer can view active discounts (all shops) in the “Discounts” page.
- Customer dashboard shows a short list of discounts and recent orders.

### B) Track Points

- Customer wallet shows current points balance.
- Customer can view order history.

## Referral and QR/Link Purchase Flows (Gap)

The flow you described includes referral points and QR/link-based purchase entry.
These features are not present in the current codebase (no referral tables/controllers and no QR generation/scanning routes), so they are not documented as “implemented behavior” yet.
