USE EPMS;

CREATE TABLE salary(
    salaryID INT AUTO_INCREMENT PRIMARY KEY,
    grossSalary DECIMAL(15, 2) NOT NULL,
    totalDeduction DECIMAL(15, 2) NOT NULL,
    netSalary DECIMAL(15, 2) NOT NULL,
    month INT NOT NULL
);

CREATE TABLE department(
    deptCode VARCHAR(10) PRIMARY KEY,
    deptName VARCHAR(50) NOT NULL,
    salaryID INT NOT NULL,
    FOREIGN KEY (salaryID) REFERENCES salary(salaryID)
);

CREATE TABLE employee(
    empID INT AUTO_INCREMENT PRIMARY KEY,
    fname VARCHAR(50) NOT NULL,
    lname VARCHAR(50) NOT NULL,
    position VARCHAR(50) NOT NULL,
    address TEXT,
    telephone VARCHAR(20) NOT NULL,
    gender ENUM('Male', 'Female') NOT NULL,
    hireDate DATE NOT NULL,
    deptCode VARCHAR(10) NOT NULL,
    FOREIGN KEY (deptCode) REFERENCES department(deptCode)
);

CREATE TABLE users(
    userID INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) NOT NULL UNIQUE,
    passwordHash VARCHAR(255) NOT NULL
);

INSERT INTO salary (grossSalary, totalDeduction, netSalary, month) VALUES
(300000.00, 20000.00, 280000.00, 5),
(200000.00, 5000.00, 195000.00, 5),
(450000.00, 40000.00, 410000.00, 5),
(600000.00, 70000.00, 530000.00, 5);

INSERT INTO department (deptCode, deptName, salaryID) VALUES
('CW', 'Carwash', 1),
('ST', 'Stock', 2),
('MC', 'Mechanic', 3),
('ADMS', 'Administration Staff', 4);