feat: complete jobcard operations and access controls

This commit is contained in:
Marco0300
2026-09-01 20:07:20 +02:00
parent 703c3ca67d
commit 168c15c6ae
12 changed files with 1241 additions and 29 deletions
+20 -3
View File
@@ -86,7 +86,7 @@ CREATE TABLE IF NOT EXISTS sla_agreements (
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (client_id) REFERENCES clients(id) ON DELETE CASCADE,
INDEX sla_client_idx (client_id)
UNIQUE KEY sla_client_unique (client_id)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS jobcards (
@@ -121,6 +121,18 @@ CREATE TABLE IF NOT EXISTS jobcard_assignments (
FOREIGN KEY (assigned_by) REFERENCES users(id) ON DELETE SET NULL
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS jobcard_status_history (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
jobcard_id BIGINT UNSIGNED NOT NULL,
from_status VARCHAR(60) NOT NULL,
to_status VARCHAR(60) NOT NULL,
changed_by BIGINT UNSIGNED NULL,
changed_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (jobcard_id) REFERENCES jobcards(id) ON DELETE CASCADE,
FOREIGN KEY (changed_by) REFERENCES users(id) ON DELETE SET NULL,
INDEX status_history_jobcard_idx (jobcard_id, changed_at)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS time_entries (
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
jobcard_id BIGINT UNSIGNED NOT NULL,
@@ -166,6 +178,11 @@ INSERT IGNORE INTO permissions (name, description) VALUES
('clients.manage', 'Create and edit client records'),
('jobcards.view', 'View jobcards'),
('jobcards.manage', 'Create and update jobcards'),
('jobcards.assign', 'Assign technicians to jobcards'),
('jobcards.internal_notes', 'View and edit internal jobcard notes'),
('time_entries.record', 'Record technician time entries'),
('sla.view', 'View client SLA agreements and usage'),
('sla.manage', 'Configure client SLA agreements'),
('reports.view', 'View reports'),
('reports.export', 'Export reports'),
('users.manage', 'Manage users'),
@@ -178,10 +195,10 @@ SELECT r.id, p.id FROM roles r CROSS JOIN permissions p WHERE r.name = 'Administ
INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT r.id, p.id FROM roles r JOIN permissions p ON p.name IN
('dashboard.view','clients.view','jobcards.view','reports.view','reports.export')
('dashboard.view','clients.view','jobcards.view','reports.view','reports.export','sla.view')
WHERE r.name = 'Accounts';
INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT r.id, p.id FROM roles r JOIN permissions p ON p.name IN
('dashboard.view','clients.view','jobcards.view','jobcards.manage')
('dashboard.view','clients.view','jobcards.view','jobcards.manage','time_entries.record')
WHERE r.name = 'Technician';