7.5 KiB
7.5 KiB
✅ KPI & TAT Reporting System - Setup Complete!
🎉 What's Been Implemented
1. TAT Alerts Table (tat_alerts)
Purpose: Store every TAT notification (50%, 75%, 100%) for display and KPI analysis
Features:
- ✅ Records all TAT notifications sent
- ✅ Tracks timing, completion status, and compliance
- ✅ Stores metadata for rich reporting
- ✅ Displays like the shared image: "Reminder 1: 50% of SLA breach reminder have been sent"
Example Query:
-- Get TAT alerts for a specific request (for UI display)
SELECT
alert_type,
threshold_percentage,
alert_sent_at,
alert_message
FROM tat_alerts
WHERE request_id = 'YOUR_REQUEST_ID'
ORDER BY alert_sent_at ASC;
2. Eight KPI Views Created
All views are ready to use for reporting and dashboards:
| View Name | Purpose | KPI Category |
|---|---|---|
vw_request_volume_summary |
Request counts, status, cycle times | Volume & Status |
vw_tat_compliance |
TAT compliance tracking | TAT Efficiency |
vw_approver_performance |
Approver metrics, response times | Approver Load |
vw_tat_alerts_summary |
TAT alerts with response times | TAT Efficiency |
vw_department_summary |
Department-wise statistics | Volume & Status |
vw_daily_kpi_metrics |
Daily trends and metrics | Trends |
vw_workflow_aging |
Aging analysis | Volume & Status |
vw_engagement_metrics |
Comments, documents, collaboration | Engagement & Quality |
3. Complete KPI Coverage
All KPIs from your requirements are now supported:
✅ Request Volume & Status
- Total Requests Created
- Open Requests (with age)
- Approved Requests
- Rejected Requests
✅ TAT Efficiency
- Average TAT Compliance %
- Avg Approval Cycle Time
- Delayed Workflows
- TAT Breach History
✅ Approver Load
- Pending Actions (My Queue)
- Approvals Completed (Today/Week)
- Approver Performance Metrics
✅ Engagement & Quality
- Comments/Work Notes Added
- Attachments Uploaded
- Spectator Participation
📊 Example Queries
Show TAT Reminders (Like Your Image)
-- For displaying TAT alerts in Request Detail screen
SELECT
CASE
WHEN alert_type = 'TAT_50' THEN '⏳ 50% of SLA breach reminder have been sent'
WHEN alert_type = 'TAT_75' THEN '⚠️ 75% of SLA breach reminder have been sent'
WHEN alert_type = 'TAT_100' THEN '⏰ TAT breached - Immediate action required'
END as reminder_text,
'Reminder sent by system automatically' as description,
alert_sent_at
FROM tat_alerts
WHERE request_id = 'REQUEST_ID'
AND level_id = 'LEVEL_ID'
ORDER BY threshold_percentage ASC;
TAT Compliance Rate
SELECT
ROUND(
COUNT(CASE WHEN completed_within_tat = true THEN 1 END) * 100.0 /
NULLIF(COUNT(CASE WHEN completed_within_tat IS NOT NULL THEN 1 END), 0),
2
) as compliance_percentage
FROM vw_tat_compliance;
Approver Performance Leaderboard
SELECT
approver_name,
department,
ROUND(tat_compliance_percentage, 2) as compliance_percent,
approved_count,
ROUND(avg_response_time_hours, 2) as avg_response_hours,
breaches_count
FROM vw_approver_performance
WHERE total_assignments > 0
ORDER BY tat_compliance_percentage DESC
LIMIT 10;
Department Comparison
SELECT
department,
total_requests,
approved_requests,
ROUND(approved_requests * 100.0 / NULLIF(total_requests, 0), 2) as approval_rate,
ROUND(avg_cycle_time_hours / 24, 2) as avg_cycle_days
FROM vw_department_summary
WHERE department IS NOT NULL
ORDER BY total_requests DESC;
🚀 How TAT Alerts Work
1. When Request is Submitted
✅ TAT monitoring starts for Level 1
✅ Jobs scheduled: 50%, 75%, 100%
✅ level_start_time and tat_start_time set
2. When Notification Fires
✅ Notification sent to approver
✅ Record created in tat_alerts table
✅ Activity logged
✅ Flags updated in approval_levels
3. Display in UI
// Frontend can fetch and display like:
const alerts = await getTATAlerts(requestId, levelId);
alerts.forEach(alert => {
console.log(`Reminder ${alert.threshold_percentage}%: ${alert.alert_message}`);
console.log(`Sent at: ${formatDate(alert.alert_sent_at)}`);
});
📈 Analytical Reports Supported
- Request Lifecycle Report - Complete timeline with TAT
- Approver Performance Report - Leaderboard & metrics
- Department-wise Summary - Cross-department comparison
- TAT Breach Report - All breached requests with reasons
- Priority Distribution - Express vs Standard analysis
- Workflow Aging - Long-running requests
- Daily/Weekly Trends - Time-series analysis
- Engagement Metrics - Collaboration tracking
🎯 Next Steps
1. Setup Upstash Redis (REQUIRED)
TAT notifications need Redis to work:
- Go to: https://console.upstash.com/
- Create free Redis database
- Copy connection URL
- Add to
.env:REDIS_URL=rediss://default:PASSWORD@host.upstash.io:6379 TAT_TEST_MODE=true - Restart backend
See: START_HERE.md or TAT_QUICK_START.md
2. Test TAT Notifications
- Create request with 6-hour TAT (becomes 6 minutes in test mode)
- Submit request
- Wait for notifications: 3min, 4.5min, 6min
- Check
tat_alertstable - Verify display in Request Detail screen
3. Build Frontend Reports
Use the KPI views to build:
- Dashboard cards
- Charts (pie, bar, line)
- Tables with filters
- Export to CSV
📚 Documentation
| Document | Purpose |
|---|---|
docs/KPI_REPORTING_SYSTEM.md |
Complete KPI guide with all queries |
docs/TAT_NOTIFICATION_SYSTEM.md |
TAT system architecture |
TAT_QUICK_START.md |
Quick setup for TAT |
START_HERE.md |
Start here for TAT setup |
backend_structure.txt |
Database schema reference |
🔍 Database Schema Summary
tat_alerts (NEW)
├─ alert_id (PK)
├─ request_id (FK → workflow_requests)
├─ level_id (FK → approval_levels)
├─ approver_id (FK → users)
├─ alert_type (TAT_50, TAT_75, TAT_100)
├─ threshold_percentage (50, 75, 100)
├─ tat_hours_allocated
├─ tat_hours_elapsed
├─ tat_hours_remaining
├─ level_start_time
├─ alert_sent_at
├─ expected_completion_time
├─ alert_message
├─ notification_sent
├─ notification_channels (array)
├─ is_breached
├─ was_completed_on_time
├─ completion_time
├─ metadata (JSONB)
└─ created_at
approval_levels (UPDATED)
├─ ... existing fields ...
├─ tat50_alert_sent (NEW)
├─ tat75_alert_sent (NEW)
├─ tat_breached (NEW)
└─ tat_start_time (NEW)
8 Views Created:
├─ vw_request_volume_summary
├─ vw_tat_compliance
├─ vw_approver_performance
├─ vw_tat_alerts_summary
├─ vw_department_summary
├─ vw_daily_kpi_metrics
├─ vw_workflow_aging
└─ vw_engagement_metrics
✅ Implementation Checklist
- Create
tat_alertstable - Add TAT status fields to
approval_levels - Create 8 KPI views for reporting
- Update TAT processor to log alerts
- Export
TatAlertmodel - Run all migrations successfully
- Create comprehensive documentation
- Setup Upstash Redis (YOU DO THIS)
- Test TAT notifications (YOU DO THIS)
- Build frontend KPI dashboards (YOU DO THIS)
🎉 Status: READY TO USE!
- ✅ Database schema complete
- ✅ TAT alerts logging ready
- ✅ KPI views optimized
- ✅ All migrations applied
- ✅ Documentation complete
Just connect Redis and you're good to go!
Last Updated: November 4, 2025
Team: Royal Enfield Workflow System