# ERP Notification System - Use Cases & Implementation Plan

## Overview
Expand the calendar notification system to cover all time-sensitive events across the ERP system.

---

## 1. 🏢 SALES & CRM NOTIFICATIONS

### A. Quotes / Battery Quotes
**Table**: `quotes`, `battery_quotes`
**Date Field**: `valid_until`, `contract_end_date`

**Use Cases**:
- ⏰ **3 days before** quote expires → Notify sales rep to follow up
- ⏰ **1 day before** quote expires → HIGH PRIORITY reminder
- ⏰ **On expiration day** → Mark quote as expired, notify manager
- 📊 Contract renewal: 30 days before `contract_end_date`

**Priority**: HIGH (Revenue impact)

### B. CRM Opportunities
**Table**: `crm_opportunities`
**Date Field**: `expected_close_date`

**Use Cases**:
- ⏰ **7 days before** expected close → Remind sales rep to push deal
- ⏰ **3 days before** → Check deal status, update forecast
- ⏰ **On close date** → If not closed, notify manager for intervention

**Priority**: HIGH (Pipeline management)

### C. Client/Customer Activities
**Table**: `client_activities`, `customer_activities`
**Date Field**: `due_date`, `activity_date`

**Use Cases**:
- ⏰ **1 day before** due date → Remind assigned user
- ⏰ **On due date** → HIGH PRIORITY if not completed
- ⏰ **1 day overdue** → Escalate to manager

**Priority**: MEDIUM

---

## 2. 💰 ACCOUNTING & FINANCE NOTIFICATIONS

### A. Invoices
**Table**: `invoices`
**Date Field**: `due_date`

**Use Cases**:
- ⏰ **3 days before** payment due → Courtesy reminder to customer (automated email)
- ⏰ **1 day before** due → Finance team notified to follow up
- ⏰ **On due date** → Flag for collections
- ⏰ **7 days overdue** → Escalate to management
- ⏰ **30 days overdue** → Critical collection action

**Priority**: CRITICAL (Cash flow)

### B. Purchase Orders
**Table**: `purchase_orders`
**Date Field**: `expected_delivery_date`

**Use Cases**:
- ⏰ **On expected delivery** → Notify receiving team to verify arrival
- ⏰ **1 day overdue** → Contact supplier, notify procurement
- ⏰ **3 days overdue** → Escalate, check inventory impact

**Priority**: HIGH (Supply chain)

### C. Payment Terms
**Table**: `supplier_payments`, `customer_payments`
**Date Field**: `payment_date`, `scheduled_date`

**Use Cases**:
- ⏰ **2 days before** scheduled payment → AP team reviews/approves
- ⏰ **On payment date** → Execute payment, confirm
- ⏰ **1 day missed** → Alert CFO, investigate

**Priority**: CRITICAL (Vendor relations, credit)

### D. Bank Reconciliation
**Table**: `bank_reconciliations`
**Date Field**: `statement_date`

**Use Cases**:
- ⏰ **Monthly on statement close** → Remind accountant to reconcile
- ⏰ **5 days after month-end** → If not reconciled, escalate

**Priority**: MEDIUM (Compliance)

---

## 3. 📦 INVENTORY & MANUFACTURING

### A. Work Orders
**Table**: `work_orders`
**Date Field**: `due_date`, `start_date`

**Use Cases**:
- ⏰ **1 day before** start → Notify production team, check materials
- ⏰ **On due date** → If not complete, alert production manager
- ⏰ **2 days overdue** → Escalate, customer notification

**Priority**: HIGH (Production schedule)

### B. Maintenance Schedules
**Table**: `maintenance_schedules`
**Date Field**: `scheduled_date`, `next_maintenance_date`

**Use Cases**:
- ⏰ **7 days before** maintenance → Schedule technician
- ⏰ **1 day before** → Confirm parts available
- ⏰ **On maintenance day** → Notify operations to shutdown equipment

**Priority**: HIGH (Equipment uptime)

### C. Quality Inspections
**Table**: `quality_inspections`
**Date Field**: `scheduled_date`

**Use Cases**:
- ⏰ **1 day before** inspection → Notify QA team
- ⏰ **If overdue** → Alert quality manager

**Priority**: MEDIUM (Quality control)

### D. Lot/Serial Expiry
**Table**: `lot_tracking`, `certificates_of_analysis`
**Date Field**: `expiry_date`, `manufacturing_date`

**Use Cases**:
- ⏰ **30 days before** expiry → Plan to move/sell inventory
- ⏰ **7 days before** expiry → URGENT: Use or dispose
- ⏰ **On expiry** → Auto-flag as expired, remove from available stock

**Priority**: CRITICAL (Safety, compliance)

---

## 4. 👥 HUMAN RESOURCES

### A. Employee Contracts
**Table**: `employee_contracts`
**Date Field**: `end_date`, `renewal_date`

**Use Cases**:
- ⏰ **60 days before** contract end → HR starts renewal process
- ⏰ **30 days before** → Notify manager, get approval
- ⏰ **7 days before** → URGENT: Finalize renewal or termination

**Priority**: HIGH (Legal, retention)

### B. Employee Training
**Table**: `employee_training`
**Date Field**: `due_date`, `completion_date`

**Use Cases**:
- ⏰ **7 days before** due → Remind employee
- ⏰ **On due date** → HIGH PRIORITY if incomplete
- ⏰ **Overdue** → Notify manager and HR

**Priority**: MEDIUM (Compliance)

### C. Performance Reviews
**Table**: `reviews`
**Date Field**: `review_date`

**Use Cases**:
- ⏰ **14 days before** → Notify manager to prepare
- ⏰ **3 days before** → Confirm meeting scheduled
- ⏰ **Overdue** → HR escalation

**Priority**: MEDIUM

### D. Probation/Termination
**Table**: `employee_separations`
**Date Field**: `last_working_date`, `notice_date`

**Use Cases**:
- ⏰ **7 days before** last working day → HR checklist
- ⏰ **1 day before** → IT revokes access, collect assets

**Priority**: HIGH (Security, legal)

### E. Time Off / Leave Requests
**Table**: `leave_requests`
**Date Field**: `start_date`, `end_date`

**Use Cases**:
- ⏰ **Pending approval > 3 days** → Remind manager
- ⏰ **1 day before** leave starts → Notify team

**Priority**: MEDIUM

---

## 5. 📋 COMPLIANCE & LEGAL

### A. Document Expiry
**Table**: `crm_documents`, `documents`
**Date Field**: `expiry_date`

**Use Cases**:
- ⏰ **30 days before** expiry → Start renewal (licenses, certifications)
- ⏰ **7 days before** → URGENT renewal needed
- ⏰ **On expiry** → Flag as expired, restrict usage

**Priority**: CRITICAL (Legal compliance)

### B. Tax Filing Deadlines
**Table**: `tax_filings`
**Date Field**: `due_date`

**Use Cases**:
- ⏰ **30 days before** → Gather documents
- ⏰ **7 days before** → Submit for review
- ⏰ **1 day before** → Final check before filing

**Priority**: CRITICAL (Legal, penalties)

---

## 6. 🎯 PROJECT MANAGEMENT

### A. Project Milestones
**Table**: `projects`, `project_tasks`
**Date Field**: `deadline`, `due_date`, `end_date`

**Use Cases**:
- ⏰ **At risk** (75% time used, <50% complete) → Alert PM
- ⏰ **1 day before** deadline → Status check
- ⏰ **Overdue** → Escalate, revise timeline

**Priority**: HIGH (Client satisfaction)

---

## Implementation Priority

### Phase 1 (Immediate - High ROI)
1. ✅ Calendar Events (DONE)
2. 💰 **Invoice Due Dates** (Cash flow critical)
3. 📋 **Quote Expiration** (Revenue loss prevention)
4. 📦 **Work Order Due Dates** (Production critical)
5. 🏷️ **Product Expiry Dates** (Safety/compliance)

### Phase 2 (30 days)
6. 📊 CRM Opportunity Close Dates
7. 💳 Payment Due Dates
8. 🔧 Equipment Maintenance
9. 📄 Contract Renewals
10. 📝 Document Expiry

### Phase 3 (60 days)
11. Customer/Client Activities
12. Employee Training Due
13. Performance Reviews
14. Purchase Order Delays
15. Project Milestones

### Phase 4 (90 days)
16. Tax Filing Deadlines
17. Bank Reconciliation Reminders
18. Leave Request Approvals
19. Quality Inspection Schedule
20. All remaining use cases

---

## Technical Implementation

### New Cron Scripts Needed
1. `invoice_notifications.php` - Daily at 6 AM
2. `quote_notifications.php` - Daily at 8 AM
3. `workorder_notifications.php` - Hourly during work hours
4. `expiry_notifications.php` - Daily at 7 AM
5. `contract_notifications.php` - Daily at 9 AM
6. `payment_notifications.php` - Daily at 5 AM (before business)

### Database Enhancements
- Add `notified_at` column to relevant tables
- Add `notification_status` enum to track escalations
- Create `notification_log` table for audit trail

### Notification Settings
- User preferences for notification types
- Escalation rules (when to notify manager)
- Quiet hours / Do Not Disturb
- Email vs. in-app preferences

---

## Success Metrics
- **Reduced Overdue Invoices**: Target <5% of invoices overdue
- **Quote Conversion**: Increase conversion by catching expiring quotes
- **On-Time Delivery**: Improve work order completion by 15%
- **Compliance**: Zero expired critical documents
- **User Engagement**: 80%+ users interact with notifications

---

## Next Steps
1. Review and prioritize with management
2. Create Phase 1 cron scripts
3. Add notification preferences to user settings
4. Implement escalation logic
5. Create dashboard for notification analytics
