(Feat): More changes

This commit is contained in:
2025-11-28 19:04:35 +00:00
parent 25ed1d5c56
commit 8ac2eb1944
42 changed files with 3291 additions and 3407 deletions

View File

@@ -30,6 +30,16 @@ CREATE TABLE IF NOT EXISTS users (
department_id INT,
contractor_id INT,
is_active BOOLEAN DEFAULT TRUE,
-- Common fields for Employee and Contractor
phone_number VARCHAR(20),
aadhar_number VARCHAR(12),
bank_account_number VARCHAR(30),
bank_name VARCHAR(100),
bank_ifsc VARCHAR(20),
-- Contractor-specific fields
contractor_agreement_number VARCHAR(50),
pf_number VARCHAR(30),
esic_number VARCHAR(30),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (department_id) REFERENCES departments(id) ON DELETE SET NULL,
FOREIGN KEY (contractor_id) REFERENCES users(id) ON DELETE SET NULL
@@ -65,13 +75,38 @@ CREATE TABLE IF NOT EXISTS attendance (
check_in_time DATETIME,
check_out_time DATETIME,
work_date DATE NOT NULL,
status ENUM('CheckedIn', 'CheckedOut', 'Absent') DEFAULT 'CheckedIn',
status ENUM('CheckedIn', 'CheckedOut', 'Absent', 'HalfDay', 'Late') DEFAULT 'CheckedIn',
remark VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (employee_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (supervisor_id) REFERENCES users(id) ON DELETE CASCADE,
UNIQUE KEY unique_attendance (employee_id, work_date)
);
-- Create employee_swaps table for tracking employee department transfers
CREATE TABLE IF NOT EXISTS employee_swaps (
id INT AUTO_INCREMENT PRIMARY KEY,
employee_id INT NOT NULL,
original_department_id INT NOT NULL,
target_department_id INT NOT NULL,
original_contractor_id INT,
target_contractor_id INT,
swap_reason ENUM('LeftWork', 'Sick', 'FinishedEarly', 'Other') NOT NULL,
reason_details VARCHAR(500),
work_completion_percentage INT DEFAULT 0,
swap_date DATE NOT NULL,
swapped_by INT NOT NULL,
status ENUM('Active', 'Completed', 'Cancelled') DEFAULT 'Active',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
completed_at TIMESTAMP NULL,
FOREIGN KEY (employee_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (original_department_id) REFERENCES departments(id) ON DELETE CASCADE,
FOREIGN KEY (target_department_id) REFERENCES departments(id) ON DELETE CASCADE,
FOREIGN KEY (original_contractor_id) REFERENCES users(id) ON DELETE SET NULL,
FOREIGN KEY (target_contractor_id) REFERENCES users(id) ON DELETE SET NULL,
FOREIGN KEY (swapped_by) REFERENCES users(id) ON DELETE CASCADE
);
-- Create contractor_rates table
CREATE TABLE IF NOT EXISTS contractor_rates (
id INT AUTO_INCREMENT PRIMARY KEY,
@@ -89,6 +124,8 @@ CREATE TABLE IF NOT EXISTS contractor_rates (
CREATE INDEX idx_users_role ON users(role);
CREATE INDEX idx_users_department ON users(department_id);
CREATE INDEX idx_users_contractor ON users(contractor_id);
CREATE INDEX idx_users_phone ON users(phone_number);
CREATE INDEX idx_users_aadhar ON users(aadhar_number);
CREATE INDEX idx_work_allocations_employee ON work_allocations(employee_id);
CREATE INDEX idx_work_allocations_supervisor ON work_allocations(supervisor_id);
CREATE INDEX idx_work_allocations_contractor ON work_allocations(contractor_id);