diff --git a/README.md b/README.md index 451eddd..8a9d576 100755 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ docker run -d --name cpas-tracker -p 3001:3001 -v cpas-data:/data cpas-tracker - **At-risk badge**: flags employees within 2 points of the next tier escalation - Search/filter by name, department, or supervisor - Click any employee name to open their full profile modal +- **πŸ“‹ Audit Log** button β€” filterable, paginated view of all system write actions ### Violation Form - Select existing employee or enter new employee by name @@ -66,11 +67,24 @@ docker run -d --name cpas-tracker -p 3001:3001 -v cpas-data:/data cpas-tracker - One-click PDF download immediately after submission ### Employee Profile Modal -- Full violation history with resolution status +- Full violation history with resolution status and **amendment count badge** per record +- **✎ Edit Employee** button β€” update name, department, or supervisor inline +- **Merge Duplicate** tab β€” reassign all violations from a duplicate record and delete it +- **Amend** button per active violation β€” edit non-scoring fields (location, notes, witness, etc.) with a full field-level diff history - Negate / restore individual violations (soft delete with resolution type + notes) - Hard delete option for data entry errors - PDF download for any historical violation record +### Audit Log +- Append-only log of every write action: employee created/edited/merged, violation logged/amended/negated/restored/deleted +- Filterable by entity type (employee / violation) and action +- Paginated with load-more; accessible from the Dashboard toolbar + +### Violation Amendment +- Edit submitted violations' non-scoring fields without delete-and-resubmit +- Point values, violation type, and incident date are immutable +- Every change is stored as a field-level diff (old β†’ new value) with timestamp and actor + ### CPAS Tier System | Points | Tier | Label | @@ -100,14 +114,19 @@ Scores are computed over a **rolling 90-day window** (negated violations exclude | GET | `/api/health` | Health check | | GET | `/api/employees` | List all employees | | POST | `/api/employees` | Create or upsert employee | +| PATCH | `/api/employees/:id` | Edit employee name, department, or supervisor | +| POST | `/api/employees/:id/merge` | Merge duplicate employee into target; reassigns all violations | | GET | `/api/employees/:id/score` | Get active CPAS score for employee | | GET | `/api/dashboard` | All employees with active points + violation counts | | POST | `/api/violations` | Log a new violation | -| GET | `/api/violations/employee/:id` | Get violation history for employee (with resolutions) | +| GET | `/api/violations/employee/:id` | Get violation history for employee (with resolutions + amendment counts) | | PATCH | `/api/violations/:id/negate` | Negate a violation (soft delete + resolution record) | | PATCH | `/api/violations/:id/restore` | Restore a negated violation | +| PATCH | `/api/violations/:id/amend` | Amend non-scoring fields with field-level diff logging | +| GET | `/api/violations/:id/amendments` | Get amendment history for a violation | | DELETE | `/api/violations/:id` | Hard delete a violation | | GET | `/api/violations/:id/pdf` | Download violation PDF | +| GET | `/api/audit` | Paginated audit log (filterable by entity_type, entity_id) | --- @@ -115,16 +134,16 @@ Scores are computed over a **rolling 90-day window** (negated violations exclude ``` cpas/ -β”œβ”€β”€ Dockerfile # Multi-stage: builds React + runs Express w/ Chromium +β”œβ”€β”€ Dockerfile # Multi-stage: builds React + runs Express w/ Chromium β”œβ”€β”€ .dockerignore -β”œβ”€β”€ package.json # Backend (Express) deps -β”œβ”€β”€ server.js # API + static file server +β”œβ”€β”€ package.json # Backend (Express) deps +β”œβ”€β”€ server.js # API + static file server β”œβ”€β”€ db/ -β”‚ β”œβ”€β”€ schema.sql # Tables + 90-day active score view -β”‚ └── database.js # SQLite connection (better-sqlite3) +β”‚ β”œβ”€β”€ schema.sql # Tables + 90-day active score view +β”‚ └── database.js # SQLite connection (better-sqlite3) + auto-migrations β”œβ”€β”€ pdf/ -β”‚ └── generator.js # Puppeteer PDF generation -└── client/ # React frontend (Vite) +β”‚ └── generator.js # Puppeteer PDF generation +└── client/ # React frontend (Vite) β”œβ”€β”€ package.json β”œβ”€β”€ vite.config.js β”œβ”€β”€ index.html @@ -132,28 +151,33 @@ cpas/ β”œβ”€β”€ main.jsx β”œβ”€β”€ App.jsx β”œβ”€β”€ data/ - β”‚ └── violations.js # All CPAS violation definitions + groups + β”‚ └── violations.js # All CPAS violation definitions + groups β”œβ”€β”€ hooks/ β”‚ └── useEmployeeIntelligence.js # Score + history hook └── components/ - β”œβ”€β”€ CpasBadge.jsx # Tier badge + color logic - β”œβ”€β”€ TierWarning.jsx # Pre-submit tier crossing alert - β”œβ”€β”€ Dashboard.jsx # Company-wide leaderboard - β”œβ”€β”€ ViolationForm.jsx # Violation entry form - β”œβ”€β”€ EmployeeModal.jsx # Employee profile + history modal - β”œβ”€β”€ NegateModal.jsx # Negate/resolve violation dialog - └── ViolationHistory.jsx # Violation list component + β”œβ”€β”€ CpasBadge.jsx # Tier badge + color logic + β”œβ”€β”€ TierWarning.jsx # Pre-submit tier crossing alert + β”œβ”€β”€ Dashboard.jsx # Company-wide leaderboard + audit log trigger + β”œβ”€β”€ ViolationForm.jsx # Violation entry form + β”œβ”€β”€ EmployeeModal.jsx # Employee profile + history modal + β”œβ”€β”€ EditEmployeeModal.jsx # Employee edit + merge duplicate + β”œβ”€β”€ AmendViolationModal.jsx # Non-scoring field amendment + diff history + β”œβ”€β”€ AuditLog.jsx # Filterable audit log panel + β”œβ”€β”€ NegateModal.jsx # Negate/resolve violation dialog + └── ViolationHistory.jsx # Violation list component ``` --- ## Database Schema -Three tables + one view: +Six tables + one view: - **`employees`** β€” id, name, department, supervisor - **`violations`** β€” full incident record including `prior_active_points` snapshot at time of logging - **`violation_resolutions`** β€” resolution type, details, resolved_by (linked to violations) +- **`violation_amendments`** β€” field-level diff log for violation edits; one row per changed field per amendment +- **`audit_log`** β€” append-only record of every write action (action, entity_type, entity_id, performed_by, details, timestamp) - **`active_cpas_scores`** (view) β€” sum of points for non-negated violations in rolling 90 days, grouped by employee --- @@ -177,26 +201,33 @@ Three tables + one view: | 4 | Tier crossing warning | Pre-submit alert when new points push employee to next tier | | 4 | Employee profile modal | Full history, negate/restore, hard delete, per-record PDF download | | 4 | Negate & restore | Soft-delete violations with resolution type + notes, fully reversible | +| 5 | Employee edit / merge | Update employee name/dept/supervisor; merge duplicate records without losing history | +| 5 | Violation amendment | Edit non-scoring fields with field-level audit trail | +| 5 | Audit log | Append-only log of all system writes; filterable panel in the dashboard | --- -### πŸ”² Proposed +### πŸ“‹ In Progress + +#### Reporting & Visibility +- **Expiration timeline** β€” per-employee view showing which active violations roll off the 90-day window and when; lets supervisors anticipate tier drops before they happen +- **Employee notes / flags** β€” free-text notes attached to an employee record (e.g. "on PIP", "union member") visible in the profile modal without affecting scoring + +--- + +### πŸ’‘ Proposed #### Reporting & Analytics - **Violation trends chart** β€” line/bar chart of violations per day/week/month, filterable by department or supervisor; useful for identifying systemic patterns vs. individual incidents - **Department heat map** β€” grid view showing violation density and average CPAS score by department; helps supervisors identify team-level risk -- **Expiration timeline** β€” visual showing which active violations will roll off the 90-day window and when, so supervisors can anticipate tier drops - **CSV / Excel export** β€” bulk export of violations or dashboard data for external reporting or payroll integration #### Employee Management -- **Employee edit / merge** β€” ability to update employee name, department, or supervisor without losing history; merge duplicate records created by name typos - **Supervisor view** β€” scoped dashboard showing only the employees under a given supervisor, useful for multi-supervisor environments -- **Employee notes / flags** β€” free-text notes attached to an employee record (e.g. "on PIP", "union member") visible in the profile modal without affecting scoring #### Violation Workflow - **Acknowledgment signature field** β€” a "received by employee" name/date field on the violation form that prints on the PDF, replacing the blank signature line - **Draft / pending violations** β€” save a violation as draft before finalizing, useful when incidents need review before being officially logged -- **Violation amendment** β€” edit a submitted violation's details (not points) with an audit trail, rather than delete-and-resubmit - **Bulk violation import** β€” CSV import for migrating historical records from paper logs or a prior system #### Notifications & Escalation @@ -206,7 +237,6 @@ Three tables + one view: #### Infrastructure & Ops - **Multi-user auth** β€” simple login with role-based access (admin, supervisor, read-only); currently the app has no auth and is assumed to run on a trusted internal network -- **Audit log** β€” immutable log of all creates, negates, restores, and deletes with timestamp and acting user, stored separately from the violations table - **Automated DB backup** β€” cron job or Docker health hook to snapshot `/data/cpas.db` to a mounted backup volume or remote location on a schedule - **Dark/light theme toggle** β€” the UI is currently dark-only; a toggle would improve usability in bright environments diff --git a/client/src/components/EmployeeModal.jsx b/client/src/components/EmployeeModal.jsx index 4706e87..d1a57f7 100755 --- a/client/src/components/EmployeeModal.jsx +++ b/client/src/components/EmployeeModal.jsx @@ -4,6 +4,8 @@ import CpasBadge, { getTier } from './CpasBadge'; import NegateModal from './NegateModal'; import EditEmployeeModal from './EditEmployeeModal'; import AmendViolationModal from './AmendViolationModal'; +import ExpirationTimeline from './ExpirationTimeline'; +import EmployeeNotes from './EmployeeNotes'; const s = { overlay: { @@ -201,7 +203,7 @@ export default function EmployeeModal({ employeeId, onClose }) {
- {tier ? tier.label : 'β€”'} + {tier ? tier.label : '–'}
Current Tier
@@ -209,6 +211,23 @@ export default function EmployeeModal({ employeeId, onClose }) { )} {score && } + {/* ── Employee Notes ── */} + {employee && ( + setEmployee(prev => ({ ...prev, notes }))} + /> + )} + + {/* ── Expiration Timeline ── */} + {score && score.active_points > 0 && ( + + )} + {/* ── Active Violations ── */}
Active Violations
{active.length === 0 ? ( diff --git a/client/src/components/EmployeeNotes.jsx b/client/src/components/EmployeeNotes.jsx new file mode 100644 index 0000000..26cf619 --- /dev/null +++ b/client/src/components/EmployeeNotes.jsx @@ -0,0 +1,146 @@ +import React, { useState } from 'react'; +import axios from 'axios'; + +const s = { + wrapper: { marginTop: '20px' }, + sectionHd: { + fontSize: '13px', fontWeight: 700, color: '#f8f9fa', textTransform: 'uppercase', + letterSpacing: '0.5px', marginBottom: '8px', + }, + display: { + background: '#181924', border: '1px solid #2a2b3a', borderRadius: '6px', + padding: '10px 12px', fontSize: '13px', color: '#f8f9fa', minHeight: '36px', + cursor: 'pointer', position: 'relative', + }, + displayEmpty: { + color: '#555770', fontStyle: 'italic', + }, + editHint: { + position: 'absolute', right: '8px', top: '8px', + fontSize: '10px', color: '#555770', + }, + textarea: { + width: '100%', background: '#0d1117', border: '1px solid #4d6fa8', + borderRadius: '6px', color: '#f8f9fa', fontSize: '13px', + padding: '10px 12px', resize: 'vertical', minHeight: '80px', + boxSizing: 'border-box', fontFamily: 'inherit', outline: 'none', + }, + actions: { display: 'flex', gap: '8px', marginTop: '8px' }, + saveBtn: { + background: '#1a3a6b', border: '1px solid #4d6fa8', color: '#90caf9', + borderRadius: '5px', padding: '5px 14px', fontSize: '12px', + cursor: 'pointer', fontWeight: 600, + }, + cancelBtn: { + background: 'none', border: '1px solid #444', color: '#888', + borderRadius: '5px', padding: '5px 14px', fontSize: '12px', + cursor: 'pointer', + }, + saving: { fontSize: '12px', color: '#9ca0b8', alignSelf: 'center' }, + tagRow: { display: 'flex', flexWrap: 'wrap', gap: '6px', marginBottom: '8px' }, + tag: { + display: 'inline-block', padding: '2px 8px', borderRadius: '10px', + fontSize: '11px', fontWeight: 600, background: '#1a2a3a', + color: '#90caf9', border: '1px solid #2a3a5a', cursor: 'default', + }, +}; + +// Quick-add tags for common HR flags +const QUICK_TAGS = ['On PIP', 'Union member', 'Probationary', 'Pending investigation', 'FMLA', 'ADA']; + +export default function EmployeeNotes({ employeeId, initialNotes, onSaved }) { + const [editing, setEditing] = useState(false); + const [draft, setDraft] = useState(initialNotes || ''); + const [saved, setSaved] = useState(initialNotes || ''); + const [saving, setSaving] = useState(false); + + const handleSave = async () => { + setSaving(true); + try { + await axios.patch(`/api/employees/${employeeId}/notes`, { notes: draft }); + setSaved(draft); + setEditing(false); + if (onSaved) onSaved(draft); + } finally { + setSaving(false); + } + }; + + const handleCancel = () => { + setDraft(saved); + setEditing(false); + }; + + const addTag = (tag) => { + const current = draft.trim(); + // Don't add a tag that's already present + if (current.includes(tag)) return; + setDraft(current ? `${current}\n${tag}` : tag); + }; + + // Parse saved notes into display lines + const lines = saved ? saved.split('\n').filter(Boolean) : []; + + return ( +
+
Notes & Flags
+ + {!editing ? ( +
{ setDraft(saved); setEditing(true); }} + title="Click to edit" + > + ✎ edit + {lines.length === 0 ? ( + No notes β€” click to add + ) : ( +
+ {lines.map((line, i) => ( + {line} + ))} +
+ )} +
+ ) : ( +
+ {/* Quick-add tag buttons */} +
+ {QUICK_TAGS.map(tag => ( + + ))} +
+ +