
Phase 3 → File 03 → ChatGPT

# SALES & INVENTORY LOGIC REFINEMENT

You are a senior backend architect.

I will paste my current SaleController below.

Improve it to:

1. Deduct inventory from the user's assigned warehouse
2. Prevent negative stock
3. Log inventory transaction history
4. Calculate:
   - Total yearly sales
   - % target achieved
   - Proportional yearly return if below 85%
5. Return structured JSON response for dashboard

Rules:
- Yearly target stored in users table
- Sale includes:
  - product_id
  - quantity
- Inventory table:
  - warehouse_id
  - product_id
  - quantity

Do NOT rewrite entire system.
Improve logic only.
Make it production safe.

# SALES, TARGET & PERFORMANCE LOGIC REFINEMENT

You are a senior backend architect.

Improve my SaleController and related logic to include:

1. Inventory Deduction
   - Deduct from user's warehouse
   - Prevent negative stock
   - Log inventory transactions

2. Yearly Target Tracking
   - Total yearly sales
   - % target achieved
   - Proportional return if < 85%

3. Target Projection Engine
   - Based on current date
   - Calculate projected end-of-year sales
   - Return forecast %
   - Flag if projected below threshold

4. Performance Scorecard Calculations
   - Current month sales
   - Previous month sales
   - Growth %
   - Best-selling product
   - Slowest-moving product

5. Weekly Compliance Logic
   - Track if weekly sales submitted
   - Compliance %
   - Missed weeks counter

6. Return Simulation Logic
   - Accept hypothetical additional sales amount
   - Recalculate return
   - Return simulation result

IMPORTANT:
- Do not rewrite full system
- Improve business logic only
- Keep it production-safe
- Return structured JSON for dashboard