first commit

This commit is contained in:
sas.fajri
2025-04-24 10:25:31 +07:00
commit ccca4e7f4f
26 changed files with 8470 additions and 0 deletions

View File

@@ -0,0 +1,307 @@
-- Database Structure for Environmental Laboratory Management System
-- Based on the workflow diagram provided
-- Create database
CREATE DATABASE IF NOT EXISTS lab_lingkungan;
USE lab_lingkungan;
-- Customers table (Internal and External)
CREATE TABLE customers (
customer_id INT AUTO_INCREMENT PRIMARY KEY,
customer_name VARCHAR(100) NOT NULL,
customer_type ENUM('Internal', 'External') NOT NULL,
contact_person VARCHAR(100),
phone_number VARCHAR(20),
email VARCHAR(100),
address TEXT,
company_name VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- Sample Types table
CREATE TABLE sample_types (
sample_type_id INT AUTO_INCREMENT PRIMARY KEY,
type_name VARCHAR(100) NOT NULL,
description TEXT,
standard_method TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Analysis Parameters table
CREATE TABLE analysis_parameters (
parameter_id INT AUTO_INCREMENT PRIMARY KEY,
parameter_name VARCHAR(100) NOT NULL,
unit VARCHAR(50),
method VARCHAR(100),
sample_type_id INT,
standard_value VARCHAR(100),
price DECIMAL(10, 2),
FOREIGN KEY (sample_type_id) REFERENCES sample_types(sample_type_id),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Service Requests table
CREATE TABLE service_requests (
request_id INT AUTO_INCREMENT PRIMARY KEY,
customer_id INT NOT NULL,
request_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
request_type ENUM('Sampling and Analysis', 'Analysis Only') NOT NULL,
project_name VARCHAR(200),
project_location TEXT,
status ENUM('Draft', 'Submitted', 'Quotation Sent', 'Approved', 'Rejected', 'Completed', 'Cancelled') DEFAULT 'Draft',
admin_id INT,
quotation_number VARCHAR(50),
quotation_date DATE,
approved_date DATE,
payment_proof VARCHAR(255),
payment_date DATE,
total_amount DECIMAL(12, 2),
notes TEXT,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- Request Parameters (mapping between requests and required parameters)
CREATE TABLE request_parameters (
request_parameter_id INT AUTO_INCREMENT PRIMARY KEY,
request_id INT NOT NULL,
parameter_id INT NOT NULL,
quantity INT DEFAULT 1,
price_per_unit DECIMAL(10, 2),
FOREIGN KEY (request_id) REFERENCES service_requests(request_id),
FOREIGN KEY (parameter_id) REFERENCES analysis_parameters(parameter_id),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Sampling Plans table
CREATE TABLE sampling_plans (
plan_id INT AUTO_INCREMENT PRIMARY KEY,
request_id INT NOT NULL,
planned_date DATE NOT NULL,
location TEXT NOT NULL,
coordinates VARCHAR(100),
sampling_method TEXT,
equipment_needed TEXT,
sampling_officer_id INT,
status ENUM('Planned', 'Confirmed', 'Completed', 'Cancelled') DEFAULT 'Planned',
notes TEXT,
FOREIGN KEY (request_id) REFERENCES service_requests(request_id),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- Samples table
CREATE TABLE samples (
sample_id INT AUTO_INCREMENT PRIMARY KEY,
request_id INT NOT NULL,
plan_id INT,
sample_code VARCHAR(50) NOT NULL,
sample_type_id INT NOT NULL,
sampling_date DATETIME,
sampling_location TEXT,
sampling_officer_id INT,
received_date DATETIME,
received_by INT,
sample_condition TEXT,
preparation_notes TEXT,
preservation_method TEXT,
status ENUM('Planned', 'Collected', 'Received', 'In Preparation', 'In Analysis', 'Analysis Complete', 'Verified', 'Reported') DEFAULT 'Planned',
FOREIGN KEY (request_id) REFERENCES service_requests(request_id),
FOREIGN KEY (plan_id) REFERENCES sampling_plans(plan_id),
FOREIGN KEY (sample_type_id) REFERENCES sample_types(sample_type_id),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- Analysis Results table
CREATE TABLE analysis_results (
result_id INT AUTO_INCREMENT PRIMARY KEY,
sample_id INT NOT NULL,
parameter_id INT NOT NULL,
analyst_id INT,
analysis_date DATETIME,
result_value VARCHAR(100),
unit VARCHAR(50),
method_used VARCHAR(100),
is_within_standard BOOLEAN,
notes TEXT,
status ENUM('Planned', 'In Progress', 'Completed', 'Verified', 'Rejected') DEFAULT 'Planned',
verified_by INT,
verification_date DATETIME,
FOREIGN KEY (sample_id) REFERENCES samples(sample_id),
FOREIGN KEY (parameter_id) REFERENCES analysis_parameters(parameter_id),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- Reports table
CREATE TABLE reports (
report_id INT AUTO_INCREMENT PRIMARY KEY,
request_id INT NOT NULL,
report_number VARCHAR(50) NOT NULL,
report_date DATE NOT NULL,
prepared_by INT,
verified_by INT,
approved_by INT,
status ENUM('Draft', 'Verified', 'Approved', 'Sent', 'Received') DEFAULT 'Draft',
file_path VARCHAR(255),
notes TEXT,
FOREIGN KEY (request_id) REFERENCES service_requests(request_id),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- Users table (Staff)
CREATE TABLE users (
user_id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
full_name VARCHAR(100) NOT NULL,
email VARCHAR(100) UNIQUE,
role ENUM('Admin', 'Sampling Officer', 'Lab Analyst', 'Verification Officer', 'Manager') NOT NULL,
department VARCHAR(100),
is_active BOOLEAN DEFAULT TRUE,
last_login DATETIME,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- Activity Logs table
CREATE TABLE activity_logs (
log_id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
action VARCHAR(255) NOT NULL,
table_name VARCHAR(100),
record_id INT,
details TEXT,
ip_address VARCHAR(45),
user_agent TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(user_id)
);
-- Insert sample data for testing
-- Sample Users
INSERT INTO users (username, password, full_name, email, role, department) VALUES
('admin1', '$2y$10$somehashedpassword1', 'Administrator 1', 'admin1@lab.com', 'Admin', 'Administration'),
('sampler1', '$2y$10$somehashedpassword2', 'Sampling Officer 1', 'sampler1@lab.com', 'Sampling Officer', 'Field Operations'),
('analyst1', '$2y$10$somehashedpassword3', 'Lab Analyst 1', 'analyst1@lab.com', 'Lab Analyst', 'Laboratory'),
('verifier1', '$2y$10$somehashedpassword4', 'Verification Officer 1', 'verifier1@lab.com', 'Verification Officer', 'Quality Control'),
('manager1', '$2y$10$somehashedpassword5', 'Manager 1', 'manager1@lab.com', 'Manager', 'Management');
-- Sample Types
INSERT INTO sample_types (type_name, description, standard_method) VALUES
('Air Limbah', 'Sampel air limbah dari industri atau fasilitas', 'SNI 6989.59:2008'),
('Air Permukaan', 'Sampel air sungai, danau, atau badan air lainnya', 'SNI 6989.57:2008'),
('Air Tanah', 'Sampel air dari sumur atau mata air', 'SNI 6989.58:2008'),
('Tanah', 'Sampel tanah untuk analisis parameter lingkungan', 'SNI 8520:2018'),
('Udara Ambien', 'Sampel udara ambient untuk analisis kualitas udara', 'SNI 7119:2017');
-- Analysis Parameters
INSERT INTO analysis_parameters (parameter_name, unit, method, sample_type_id, standard_value, price) VALUES
('pH', '-', 'SNI 06-6989.11-2004', 1, '6-9', 50000.00),
('TSS', 'mg/L', 'SNI 06-6989.3-2004', 1, '100', 75000.00),
('COD', 'mg/L', 'SNI 6989.73:2009', 1, '100', 125000.00),
('BOD', 'mg/L', 'SNI 6989.72:2009', 1, '30', 150000.00),
('Ammonia', 'mg/L', 'SNI 06-6989.30-2005', 1, '10', 100000.00),
('Logam Berat Pb', 'mg/L', 'SNI 6989.8:2009', 1, '0.1', 200000.00),
('Total Coliform', 'MPN/100mL', 'SNI 01-2897-1992', 2, '1000', 175000.00),
('DO', 'mg/L', 'SNI 06-6989.14-2004', 2, '4', 80000.00),
('Sulfida', 'mg/L', 'SNI 6989.70:2009', 1, '0.5', 125000.00),
('Minyak & Lemak', 'mg/L', 'SNI 6989.10:2011', 1, '10', 150000.00);
-- Sample Customers
INSERT INTO customers (customer_name, customer_type, contact_person, phone_number, email, address, company_name) VALUES
('PT. Industri Tekstil Nusantara', 'External', 'Budi Santoso', '08123456789', 'budi@tekstilnusantara.com', 'Jl. Industri No. 123, Bandung', 'PT. Industri Tekstil Nusantara'),
('Dinas Lingkungan Hidup Kota', 'External', 'Siti Aminah', '08765432100', 'siti@dlh.kotabjb.go.id', 'Jl. Pemkot No. 45, Kota BJB', 'Dinas Lingkungan Hidup Kota BJB'),
('Departemen Produksi', 'Internal', 'Rudi Hartono', '08567891234', 'rudi@internal.lab.com', 'Gedung Utama Lt. 2, Lab Lingkungan', 'Lab Lingkungan'),
('PT. Kimia Farma', 'External', 'Diana Putri', '08123456790', 'diana@kimiafarma.co.id', 'Jl. Pahlawan No. 67, Jakarta', 'PT. Kimia Farma'),
('Departemen R&D', 'Internal', 'Hendra Wijaya', '08567891235', 'hendra@internal.lab.com', 'Gedung Riset Lt. 3, Lab Lingkungan', 'Lab Lingkungan');
-- Sample Service Requests
INSERT INTO service_requests (customer_id, request_type, project_name, project_location, status, quotation_number, quotation_date, approved_date, total_amount) VALUES
(1, 'Sampling and Analysis', 'Pemantauan Limbah Triwulan I 2025', 'Pabrik Tekstil Bandung', 'Approved', 'Q-2025-001', '2025-01-15', '2025-01-20', 2500000.00),
(2, 'Sampling and Analysis', 'Monitoring Kualitas Air Sungai Citarum', 'Sungai Citarum, 5 titik sampling', 'Completed', 'Q-2025-002', '2025-02-10', '2025-02-15', 3750000.00),
(3, 'Analysis Only', 'Analisis Limbah Internal Bulanan', 'IPAL Gedung Utama', 'In Progress', 'Q-2025-003', '2025-03-05', '2025-03-07', 1250000.00),
(4, 'Sampling and Analysis', 'Audit Lingkungan Semester I', 'Pabrik Farmasi Jakarta', 'Quotation Sent', 'Q-2025-004', '2025-03-20', NULL, 4500000.00),
(5, 'Analysis Only', 'Pengujian Efisiensi Filter Karbon', 'Lab R&D', 'Submitted', NULL, NULL, NULL, NULL);
-- Sample Request Parameters
INSERT INTO request_parameters (request_id, parameter_id, quantity, price_per_unit) VALUES
(1, 1, 1, 50000.00), -- pH for Request 1
(1, 2, 1, 75000.00), -- TSS for Request 1
(1, 3, 1, 125000.00), -- COD for Request 1
(1, 4, 1, 150000.00), -- BOD for Request 1
(1, 5, 1, 100000.00), -- Ammonia for Request 1
(2, 1, 5, 50000.00), -- pH for Request 2 (5 titik)
(2, 2, 5, 75000.00), -- TSS for Request 2 (5 titik)
(2, 7, 5, 175000.00), -- Total Coliform for Request 2 (5 titik)
(2, 8, 5, 80000.00), -- DO for Request 2 (5 titik)
(3, 1, 1, 50000.00), -- pH for Request 3
(3, 2, 1, 75000.00), -- TSS for Request 3
(3, 3, 1, 125000.00), -- COD for Request 3
(3, 4, 1, 150000.00), -- BOD for Request 3
(4, 1, 3, 50000.00), -- pH for Request 4 (3 titik)
(4, 2, 3, 75000.00), -- TSS for Request 4 (3 titik)
(4, 3, 3, 125000.00), -- COD for Request 4 (3 titik)
(4, 4, 3, 150000.00), -- BOD for Request 4 (3 titik)
(4, 6, 3, 200000.00), -- Logam Berat Pb for Request 4 (3 titik)
(4, 9, 3, 125000.00), -- Sulfida for Request 4 (3 titik)
(4, 10, 3, 150000.00);-- Minyak & Lemak for Request 4 (3 titik)
-- Sample Sampling Plans
INSERT INTO sampling_plans (request_id, planned_date, location, coordinates, sampling_method, equipment_needed, sampling_officer_id, status) VALUES
(1, '2025-01-25', 'Outlet IPAL PT. Industri Tekstil Nusantara', '-6.914744, 107.609810', 'Grab Sampling sesuai SNI 6989.59:2008', 'Botol sampling, pH meter, termometer, cool box', 2, 'Completed'),
(2, '2025-02-20', 'Sungai Citarum - Titik 1 (Hulu)', '-6.947890, 107.632505', 'Grab Sampling sesuai SNI 6989.57:2008', 'Botol sampling, pH meter, DO meter, termometer, cool box', 2, 'Completed'),
(2, '2025-02-20', 'Sungai Citarum - Titik 2', '-6.933456, 107.621234', 'Grab Sampling sesuai SNI 6989.57:2008', 'Botol sampling, pH meter, DO meter, termometer, cool box', 2, 'Completed'),
(2, '2025-02-20', 'Sungai Citarum - Titik 3', '-6.925678, 107.612345', 'Grab Sampling sesuai SNI 6989.57:2008', 'Botol sampling, pH meter, DO meter, termometer, cool box', 2, 'Completed'),
(2, '2025-02-20', 'Sungai Citarum - Titik 4', '-6.912345, 107.603456', 'Grab Sampling sesuai SNI 6989.57:2008', 'Botol sampling, pH meter, DO meter, termometer, cool box', 2, 'Completed'),
(2, '2025-02-20', 'Sungai Citarum - Titik 5 (Hilir)', '-6.901234, 107.594567', 'Grab Sampling sesuai SNI 6989.57:2008', 'Botol sampling, pH meter, DO meter, termometer, cool box', 2, 'Completed'),
(4, '2025-04-05', 'Outlet IPAL PT. Kimia Farma', '-6.186486, 106.834091', 'Grab Sampling sesuai SNI 6989.59:2008', 'Botol sampling, pH meter, termometer, cool box', 2, 'Planned'),
(4, '2025-04-05', 'Area Produksi PT. Kimia Farma', '-6.186123, 106.833987', 'Grab Sampling sesuai SNI 6989.59:2008', 'Botol sampling, pH meter, termometer, cool box', 2, 'Planned'),
(4, '2025-04-05', 'Area Penyimpanan Bahan Baku PT. Kimia Farma', '-6.185789, 106.834567', 'Grab Sampling sesuai SNI 6989.59:2008', 'Botol sampling, pH meter, termometer, cool box', 2, 'Planned');
-- Sample Samples
INSERT INTO samples (request_id, plan_id, sample_code, sample_type_id, sampling_date, sampling_location, sampling_officer_id, received_date, received_by, sample_condition, preparation_notes, status) VALUES
(1, 1, 'ITN-2025-001', 1, '2025-01-25 10:15:00', 'Outlet IPAL PT. Industri Tekstil Nusantara', 2, '2025-01-25 15:30:00', 3, 'Baik, suhu 20°C', 'Sampel disaring untuk analisis TSS', 'Analysis Complete'),
(2, 2, 'SC-H-2025-001', 2, '2025-02-20 08:30:00', 'Sungai Citarum - Titik 1 (Hulu)', 2, '2025-02-20 16:00:00', 3, 'Baik, suhu 19°C', 'Sampel diawetkan dengan H₂SO₄ untuk COD', 'Analysis Complete'),
(2, 3, 'SC-2-2025-002', 2, '2025-02-20 09:45:00', 'Sungai Citarum - Titik 2', 2, '2025-02-20 16:00:00', 3, 'Baik, suhu 19°C', 'Sampel diawetkan dengan H₂SO₄ untuk COD', 'Analysis Complete'),
(2, 4, 'SC-3-2025-003', 2, '2025-02-20 11:00:00', 'Sungai Citarum - Titik 3', 2, '2025-02-20 16:00:00', 3, 'Baik, suhu 20°C', 'Sampel diawetkan dengan H₂SO₄ untuk COD', 'Analysis Complete'),
(2, 5, 'SC-4-2025-004', 2, '2025-02-20 13:15:00', 'Sungai Citarum - Titik 4', 2, '2025-02-20 16:00:00', 3, 'Baik, suhu 20°C', 'Sampel diawetkan dengan H₂SO₄ untuk COD', 'Analysis Complete'),
(2, 6, 'SC-I-2025-005', 2, '2025-02-20 14:30:00', 'Sungai Citarum - Titik 5 (Hilir)', 2, '2025-02-20 16:00:00', 3, 'Baik, suhu 21°C', 'Sampel diawetkan dengan H₂SO₄ untuk COD', 'Analysis Complete'),
(3, NULL, 'INT-2025-001', 1, NULL, 'IPAL Gedung Utama', NULL, '2025-03-10 10:00:00', 3, 'Baik, suhu 22°C', 'Sampel dikirim oleh Departemen Produksi', 'In Analysis');
-- Sample Analysis Results (for request 1 and 2)
INSERT INTO analysis_results (sample_id, parameter_id, analyst_id, analysis_date, result_value, unit, method_used, is_within_standard, status, verified_by, verification_date) VALUES
(1, 1, 3, '2025-01-26 09:00:00', '7.6', '-', 'SNI 06-6989.11-2004', TRUE, 'Verified', 4, '2025-01-27 10:00:00'),
(1, 2, 3, '2025-01-26 11:00:00', '45', 'mg/L', 'SNI 06-6989.3-2004', TRUE, 'Verified', 4, '2025-01-27 10:00:00'),
(1, 3, 3, '2025-01-26 13:00:00', '87', 'mg/L', 'SNI 6989.73:2009', TRUE, 'Verified', 4, '2025-01-27 10:00:00'),
(1, 4, 3, '2025-01-26 15:00:00', '28', 'mg/L', 'SNI 6989.72:2009', TRUE, 'Verified', 4, '2025-01-27 10:00:00'),
(1, 5, 3, '2025-01-26 16:00:00', '3.5', 'mg/L', 'SNI 06-6989.30-2005', TRUE, 'Verified', 4, '2025-01-27 10:00:00'),
(2, 1, 3, '2025-02-21 09:00:00', '7.2', '-', 'SNI 06-6989.11-2004', TRUE, 'Verified', 4, '2025-02-22 11:00:00'),
(2, 2, 3, '2025-02-21 11:00:00', '12', 'mg/L', 'SNI 06-6989.3-2004', TRUE, 'Verified', 4, '2025-02-22 11:00:00'),
(2, 7, 3, '2025-02-21 13:00:00', '210', 'MPN/100mL', 'SNI 01-2897-1992', TRUE, 'Verified', 4, '2025-02-22 11:00:00'),
(2, 8, 3, '2025-02-21 15:00:00', '5.6', 'mg/L', 'SNI 06-6989.14-2004', TRUE, 'Verified', 4, '2025-02-22 11:00:00'),
(3, 1, 3, '2025-02-21 09:30:00', '7.1', '-', 'SNI 06-6989.11-2004', TRUE, 'Verified', 4, '2025-02-22 11:00:00'),
(3, 2, 3, '2025-02-21 11:30:00', '18', 'mg/L', 'SNI 06-6989.3-2004', TRUE, 'Verified', 4, '2025-02-22 11:00:00'),
(3, 7, 3, '2025-02-21 13:30:00', '320', 'MPN/100mL', 'SNI 01-2897-1992', TRUE, 'Verified', 4, '2025-02-22 11:00:00'),
(3, 8, 3, '2025-02-21 15:30:00', '5.2', 'mg/L', 'SNI 06-6989.14-2004', TRUE, 'Verified', 4, '2025-02-22 11:00:00');
-- Sample Reports
INSERT INTO reports (request_id, report_number, report_date, prepared_by, verified_by, approved_by, status, file_path) VALUES
(1, 'LHU-2025-001', '2025-01-29', 3, 4, 5, 'Sent', '/reports/2025/LHU-2025-001.pdf'),
(2, 'LHU-2025-002', '2025-02-25', 3, 4, 5, 'Sent', '/reports/2025/LHU-2025-002.pdf');
-- Sample Activity Logs
INSERT INTO activity_logs (user_id, action, table_name, record_id, details, ip_address) VALUES
(1, 'CREATE', 'service_requests', 1, 'Created new service request for PT. Industri Tekstil Nusantara', '192.168.1.100'),
(1, 'UPDATE', 'service_requests', 1, 'Updated status to Approved', '192.168.1.100'),
(2, 'CREATE', 'sampling_plans', 1, 'Created sampling plan for request #1', '192.168.1.101'),
(2, 'CREATE', 'samples', 1, 'Collected sample ITN-2025-001', '192.168.1.101'),
(3, 'UPDATE', 'samples', 1, 'Sample received at laboratory', '192.168.1.102'),
(3, 'CREATE', 'analysis_results', 1, 'Recorded pH analysis result', '192.168.1.102'),
(4, 'UPDATE', 'analysis_results', 1, 'Verified analysis result', '192.168.1.103'),
(5, 'CREATE', 'reports', 1, 'Created report LHU-2025-001', '192.168.1.104');