(Feat-Fix): New Reporting system, more seeded data, fixed subdepartments and activity inversion, login page changes, etc etc

This commit is contained in:
2025-12-18 08:15:31 +00:00
parent 916ee19677
commit ac29bb2882
24 changed files with 3306 additions and 207 deletions

View File

@@ -13,12 +13,22 @@ CREATE TABLE IF NOT EXISTS sub_departments (
id INT AUTO_INCREMENT PRIMARY KEY,
department_id INT NOT NULL,
name VARCHAR(100) NOT NULL,
primary_activity VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (department_id) REFERENCES departments(id) ON DELETE CASCADE,
UNIQUE KEY unique_subdept (department_id, name)
);
-- Create activities table (activities belong to sub-departments)
CREATE TABLE IF NOT EXISTS activities (
id INT AUTO_INCREMENT PRIMARY KEY,
sub_department_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
unit_of_measurement ENUM('Per Bag', 'Fixed Rate-Per Person') NOT NULL DEFAULT 'Per Bag',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (sub_department_id) REFERENCES sub_departments(id) ON DELETE CASCADE,
UNIQUE KEY unique_activity (sub_department_id, name)
);
-- Create users table
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
@@ -120,6 +130,19 @@ CREATE TABLE IF NOT EXISTS contractor_rates (
FOREIGN KEY (sub_department_id) REFERENCES sub_departments(id) ON DELETE SET NULL
);
-- Create standard_rates table (default rates for comparison with contractor rates)
CREATE TABLE IF NOT EXISTS standard_rates (
id INT AUTO_INCREMENT PRIMARY KEY,
sub_department_id INT,
activity VARCHAR(255),
rate DECIMAL(10, 2) NOT NULL,
effective_date DATE NOT NULL,
created_by INT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (sub_department_id) REFERENCES sub_departments(id) ON DELETE SET NULL,
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE CASCADE
);
-- Create indexes for better query performance
CREATE INDEX idx_users_role ON users(role);
CREATE INDEX idx_users_department ON users(department_id);
@@ -136,3 +159,6 @@ CREATE INDEX idx_attendance_date ON attendance(work_date);
CREATE INDEX idx_attendance_status ON attendance(status);
CREATE INDEX idx_contractor_rates_contractor ON contractor_rates(contractor_id);
CREATE INDEX idx_contractor_rates_date ON contractor_rates(effective_date);
CREATE INDEX idx_standard_rates_subdept ON standard_rates(sub_department_id);
CREATE INDEX idx_standard_rates_date ON standard_rates(effective_date);
CREATE INDEX idx_standard_rates_created_by ON standard_rates(created_by);

View File

@@ -0,0 +1,23 @@
-- Migration: Add standard_rates table
-- Run this migration to add the standard_rates table for supervisor-managed default rates
-- Create standard_rates table (default rates for comparison with contractor rates)
CREATE TABLE IF NOT EXISTS standard_rates (
id INT AUTO_INCREMENT PRIMARY KEY,
sub_department_id INT,
activity VARCHAR(255),
rate DECIMAL(10, 2) NOT NULL,
effective_date DATE NOT NULL,
created_by INT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (sub_department_id) REFERENCES sub_departments(id) ON DELETE SET NULL,
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE CASCADE
);
-- Create indexes for standard_rates
CREATE INDEX idx_standard_rates_subdept ON standard_rates(sub_department_id);
CREATE INDEX idx_standard_rates_date ON standard_rates(effective_date);
CREATE INDEX idx_standard_rates_created_by ON standard_rates(created_by);
-- Verify table was created
SELECT 'standard_rates table created successfully' AS status;