ganti format table
This commit is contained in:
@@ -1,150 +1,184 @@
|
||||
-- Tabel Template Sampling
|
||||
CREATE TABLE sampling_templates (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
template_name VARCHAR(100),
|
||||
description TEXT,
|
||||
is_active BOOLEAN DEFAULT true,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
SamplingTemplateID INT PRIMARY KEY AUTO_INCREMENT,
|
||||
SamplingTemplateName VARCHAR(100),
|
||||
SamplingTemplateDescription TEXT,
|
||||
SamplingTemplateIsActive BOOLEAN DEFAULT TRUE,
|
||||
SamplingTemplateCreatedAt DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
SamplingTemplateCreatedUserID INT,
|
||||
SamplingTemplateUpdatedAt DATETIME,
|
||||
SamplingTemplateUpdatedUserID INT,
|
||||
SamplingTemplateDeletedAt DATETIME,
|
||||
SamplingTemplateDeletedUserID INT
|
||||
);
|
||||
|
||||
-- Tabel Template Analisis
|
||||
CREATE TABLE analysis_templates (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
template_name VARCHAR(100),
|
||||
description TEXT,
|
||||
is_lab_analysis BOOLEAN DEFAULT true,
|
||||
is_active BOOLEAN DEFAULT true,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
AnalysisTemplateID INT PRIMARY KEY AUTO_INCREMENT,
|
||||
AnalysisTemplateName VARCHAR(100),
|
||||
AnalysisTemplateDescription TEXT,
|
||||
AnalysisTemplateIsLabAnalysis BOOLEAN DEFAULT TRUE,
|
||||
AnalysisTemplateIsActive BOOLEAN DEFAULT TRUE,
|
||||
AnalysisTemplateCreatedAt DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
AnalysisTemplateCreatedUserID INT,
|
||||
AnalysisTemplateUpdatedAt DATETIME,
|
||||
AnalysisTemplateUpdatedUserID INT,
|
||||
AnalysisTemplateDeletedAt DATETIME,
|
||||
AnalysisTemplateDeletedUserID INT
|
||||
);
|
||||
|
||||
-- Tabel Parameter Analisis
|
||||
CREATE TABLE analysis_parameters (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
parameter_code VARCHAR(20),
|
||||
parameter_name VARCHAR(100),
|
||||
testing_method VARCHAR(100),
|
||||
unit VARCHAR(20),
|
||||
standard_method_number VARCHAR(50),
|
||||
price DECIMAL(10,2),
|
||||
is_active BOOLEAN DEFAULT true,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
AnalysisParameterID INT PRIMARY KEY AUTO_INCREMENT,
|
||||
AnalysisParameterCode VARCHAR(20),
|
||||
AnalysisParameterName VARCHAR(100),
|
||||
AnalysisParameterTestingMethod VARCHAR(100),
|
||||
AnalysisParameterUnit VARCHAR(20),
|
||||
AnalysisParameterStandardMethodNumber VARCHAR(50),
|
||||
AnalysisParameterPrice DECIMAL(10,2),
|
||||
AnalysisParameterIsActive BOOLEAN DEFAULT TRUE,
|
||||
AnalysisParameterCreatedAt DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
AnalysisParameterCreatedUserID INT,
|
||||
AnalysisParameterUpdatedAt DATETIME,
|
||||
AnalysisParameterUpdatedUserID INT,
|
||||
AnalysisParameterDeletedAt DATETIME,
|
||||
AnalysisParameterDeletedUserID INT
|
||||
);
|
||||
|
||||
-- Tabel Template Parameter
|
||||
CREATE TABLE template_parameters (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
template_id INT,
|
||||
parameter_id INT,
|
||||
is_required BOOLEAN DEFAULT false,
|
||||
FOREIGN KEY (template_id) REFERENCES analysis_templates(id),
|
||||
FOREIGN KEY (parameter_id) REFERENCES analysis_parameters(id)
|
||||
TemplateParameterID INT PRIMARY KEY AUTO_INCREMENT,
|
||||
AnalysisTemplateID INT,
|
||||
AnalysisParameterID INT,
|
||||
TemplateParameterIsRequired BOOLEAN DEFAULT FALSE,
|
||||
TemplateParameterCreatedAt DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
TemplateParameterCreatedUserID INT,
|
||||
TemplateParameterUpdatedAt DATETIME,
|
||||
TemplateParameterUpdatedUserID INT,
|
||||
TemplateParameterDeletedAt DATETIME,
|
||||
TemplateParameterDeletedUserID INT
|
||||
);
|
||||
|
||||
-- Tabel Permintaan Layanan
|
||||
CREATE TABLE service_requests (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
request_code VARCHAR(20) UNIQUE,
|
||||
customer_id INT,
|
||||
request_type ENUM('sampling_analysis', 'analysis_only'),
|
||||
template_id INT,
|
||||
sampling_date DATE,
|
||||
sampling_location TEXT,
|
||||
gps_coordinates VARCHAR(50),
|
||||
status ENUM('draft', 'submitted', 'approved', 'rejected', 'in_progress', 'completed'),
|
||||
sampling_officer_id INT,
|
||||
testing_officer_id INT,
|
||||
total_amount DECIMAL(10,2),
|
||||
dp_amount DECIMAL(10,2),
|
||||
dp_status ENUM('unpaid', 'paid') DEFAULT 'unpaid',
|
||||
notes TEXT,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (customer_id) REFERENCES customers(id),
|
||||
FOREIGN KEY (template_id) REFERENCES analysis_templates(id),
|
||||
FOREIGN KEY (sampling_officer_id) REFERENCES users(id),
|
||||
FOREIGN KEY (testing_officer_id) REFERENCES users(id)
|
||||
ServiceRequestID INT PRIMARY KEY AUTO_INCREMENT,
|
||||
ServiceRequestCode VARCHAR(20) UNIQUE,
|
||||
CustomerID INT,
|
||||
ServiceRequestType ENUM('sampling_analysis', 'analysis_only'),
|
||||
AnalysisTemplateID INT,
|
||||
ServiceRequestSamplingDate DATE,
|
||||
ServiceRequestSamplingLocation TEXT,
|
||||
ServiceRequestGPSCoordinates VARCHAR(50),
|
||||
ServiceRequestStatus ENUM('draft', 'submitted', 'approved', 'rejected', 'in_progress', 'completed'),
|
||||
ServiceRequestSamplingOfficerID INT,
|
||||
ServiceRequestTestingOfficerID INT,
|
||||
ServiceRequestTotalAmount DECIMAL(10,2),
|
||||
ServiceRequestDPAmount DECIMAL(10,2),
|
||||
ServiceRequestDPStatus ENUM('unpaid', 'paid') DEFAULT 'unpaid',
|
||||
ServiceRequestNotes TEXT,
|
||||
ServiceRequestCreatedAt DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
ServiceRequestCreatedUserID INT,
|
||||
ServiceRequestUpdatedAt DATETIME,
|
||||
ServiceRequestUpdatedUserID INT,
|
||||
ServiceRequestDeletedAt DATETIME,
|
||||
ServiceRequestDeletedUserID INT
|
||||
);
|
||||
|
||||
-- Tabel Detail Parameter Permintaan
|
||||
CREATE TABLE request_parameters (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
request_id INT,
|
||||
parameter_id INT,
|
||||
price DECIMAL(10,2),
|
||||
status ENUM('pending', 'in_progress', 'completed', 'rejected'),
|
||||
result_value VARCHAR(50),
|
||||
result_unit VARCHAR(20),
|
||||
is_compliant BOOLEAN,
|
||||
notes TEXT,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (request_id) REFERENCES service_requests(id),
|
||||
FOREIGN KEY (parameter_id) REFERENCES analysis_parameters(id)
|
||||
RequestParameterID INT PRIMARY KEY AUTO_INCREMENT,
|
||||
ServiceRequestID INT,
|
||||
AnalysisParameterID INT,
|
||||
RequestParameterPrice DECIMAL(10,2),
|
||||
RequestParameterStatus ENUM('pending', 'in_progress', 'completed', 'rejected'),
|
||||
RequestParameterResultValue VARCHAR(50),
|
||||
RequestParameterResultUnit VARCHAR(20),
|
||||
RequestParameterIsCompliant BOOLEAN,
|
||||
RequestParameterNotes TEXT,
|
||||
RequestParameterCreatedAt DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
RequestParameterCreatedUserID INT,
|
||||
RequestParameterUpdatedAt DATETIME,
|
||||
RequestParameterUpdatedUserID INT,
|
||||
RequestParameterDeletedAt DATETIME,
|
||||
RequestParameterDeletedUserID INT
|
||||
);
|
||||
|
||||
-- Tabel Quotation
|
||||
CREATE TABLE quotations (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
quotation_code VARCHAR(20) UNIQUE,
|
||||
request_id INT,
|
||||
issue_date DATE,
|
||||
valid_until DATE,
|
||||
status ENUM('draft', 'sent', 'approved', 'rejected'),
|
||||
subtotal DECIMAL(10,2),
|
||||
tax_percentage DECIMAL(5,2),
|
||||
tax_amount DECIMAL(10,2),
|
||||
total_amount DECIMAL(10,2),
|
||||
terms_and_conditions TEXT,
|
||||
notes TEXT,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME ON UPDATE CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (request_id) REFERENCES service_requests(id)
|
||||
QuotationID INT PRIMARY KEY AUTO_INCREMENT,
|
||||
QuotationCode VARCHAR(20) UNIQUE,
|
||||
ServiceRequestID INT,
|
||||
QuotationIssueDate DATE,
|
||||
QuotationValidUntil DATE,
|
||||
QuotationStatus ENUM('draft', 'sent', 'approved', 'rejected'),
|
||||
QuotationSubtotal DECIMAL(10,2),
|
||||
QuotationTaxPercentage DECIMAL(5,2),
|
||||
QuotationTaxAmount DECIMAL(10,2),
|
||||
QuotationTotalAmount DECIMAL(10,2),
|
||||
QuotationTermsAndConditions TEXT,
|
||||
QuotationNotes TEXT,
|
||||
QuotationCreatedAt DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
QuotationCreatedUserID INT,
|
||||
QuotationUpdatedAt DATETIME,
|
||||
QuotationUpdatedUserID INT,
|
||||
QuotationDeletedAt DATETIME,
|
||||
QuotationDeletedUserID INT
|
||||
);
|
||||
|
||||
-- Tabel Peralatan Sampling
|
||||
CREATE TABLE sampling_equipment (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
equipment_name VARCHAR(100),
|
||||
equipment_code VARCHAR(50),
|
||||
is_available BOOLEAN DEFAULT true,
|
||||
last_calibration_date DATE,
|
||||
next_calibration_date DATE,
|
||||
notes TEXT,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
SamplingEquipmentID INT PRIMARY KEY AUTO_INCREMENT,
|
||||
SamplingEquipmentName VARCHAR(100),
|
||||
SamplingEquipmentCode VARCHAR(50),
|
||||
SamplingEquipmentIsAvailable BOOLEAN DEFAULT TRUE,
|
||||
SamplingEquipmentLastCalibrationDate DATE,
|
||||
SamplingEquipmentNextCalibrationDate DATE,
|
||||
SamplingEquipmentNotes TEXT,
|
||||
SamplingEquipmentCreatedAt DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
SamplingEquipmentCreatedUserID INT,
|
||||
SamplingEquipmentUpdatedAt DATETIME,
|
||||
SamplingEquipmentUpdatedUserID INT,
|
||||
SamplingEquipmentDeletedAt DATETIME,
|
||||
SamplingEquipmentDeletedUserID INT
|
||||
);
|
||||
|
||||
-- Tabel Peralatan yang Digunakan dalam Sampling
|
||||
CREATE TABLE request_equipment (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
request_id INT,
|
||||
equipment_id INT,
|
||||
usage_date DATE,
|
||||
return_date DATE,
|
||||
notes TEXT,
|
||||
FOREIGN KEY (request_id) REFERENCES service_requests(id),
|
||||
FOREIGN KEY (equipment_id) REFERENCES sampling_equipment(id)
|
||||
RequestEquipmentID INT PRIMARY KEY AUTO_INCREMENT,
|
||||
ServiceRequestID INT,
|
||||
SamplingEquipmentID INT,
|
||||
RequestEquipmentUsageDate DATE,
|
||||
RequestEquipmentReturnDate DATE,
|
||||
RequestEquipmentNotes TEXT,
|
||||
RequestEquipmentCreatedAt DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
RequestEquipmentCreatedUserID INT,
|
||||
RequestEquipmentUpdatedAt DATETIME,
|
||||
RequestEquipmentUpdatedUserID INT,
|
||||
RequestEquipmentDeletedAt DATETIME,
|
||||
RequestEquipmentDeletedUserID INT
|
||||
);
|
||||
|
||||
-- Contoh data template sampling
|
||||
INSERT INTO sampling_templates (template_name, description) VALUES
|
||||
INSERT INTO sampling_templates (SamplingTemplateName, SamplingTemplateDescription) VALUES
|
||||
('Air Limbah Industri', 'Template untuk sampling air limbah industri'),
|
||||
('Kualitas Udara Ambien', 'Template untuk sampling kualitas udara'),
|
||||
('Air Permukaan', 'Template untuk sampling air sungai/danau');
|
||||
|
||||
-- Contoh data parameter analisis
|
||||
INSERT INTO analysis_parameters (parameter_code, parameter_name, unit, price, method) VALUES
|
||||
INSERT INTO analysis_parameters (AnalysisParameterCode, AnalysisParameterName, AnalysisParameterUnit, AnalysisParameterPrice, AnalysisParameterTestingMethod) VALUES
|
||||
('BOD5', 'Biochemical Oxygen Demand', 'mg/L', 250000, 'SNI 6989.72:2009'),
|
||||
('COD', 'Chemical Oxygen Demand', 'mg/L', 200000, 'SNI 6989.2:2009'),
|
||||
('TSS', 'Total Suspended Solid', 'mg/L', 150000, 'SNI 06-6989.3-2004'),
|
||||
('PH', 'Derajat Keasaman', '-', 100000, 'SNI 06-6989.11-2004');
|
||||
|
||||
-- Contoh data permintaan layanan
|
||||
INSERT INTO service_requests (request_code, customer_id, request_type, sampling_date, sampling_location, status, total_amount) VALUES
|
||||
INSERT INTO service_requests (ServiceRequestCode, CustomerID, ServiceRequestType, ServiceRequestSamplingDate, ServiceRequestSamplingLocation, ServiceRequestStatus, ServiceRequestTotalAmount) VALUES
|
||||
('REQ001', 1, 'sampling_analysis', '2024-03-20', 'Plant A - Outlet IPAL', 'approved', 700000),
|
||||
('REQ002', 2, 'analysis_only', '2024-03-21', 'Lab Internal', 'submitted', 450000),
|
||||
('REQ003', 3, 'sampling_analysis', '2024-03-22', 'Intake Water Treatment', 'draft', 550000);
|
||||
|
||||
-- Contoh data parameter yang diminta
|
||||
INSERT INTO request_parameters (request_id, parameter_id, price) VALUES
|
||||
INSERT INTO request_parameters (ServiceRequestID, AnalysisParameterID, RequestParameterPrice) VALUES
|
||||
(1, 1, 250000),
|
||||
(1, 2, 200000),
|
||||
(1, 3, 150000),
|
||||
@@ -155,7 +189,7 @@ INSERT INTO request_parameters (request_id, parameter_id, price) VALUES
|
||||
(3, 4, 100000);
|
||||
|
||||
-- Contoh data quotation
|
||||
INSERT INTO quotations (quotation_code, request_id, issue_date, valid_until, status, total_amount) VALUES
|
||||
INSERT INTO quotations (QuotationCode, ServiceRequestID, QuotationIssueDate, QuotationValidUntil, QuotationStatus, QuotationTotalAmount) VALUES
|
||||
('QUO001', 1, '2024-03-15', '2024-04-15', 'approved', 700000),
|
||||
('QUO002', 2, '2024-03-16', '2024-04-16', 'sent', 450000),
|
||||
('QUO003', 3, '2024-03-17', '2024-04-17', 'draft', 550000);
|
||||
|
||||
Reference in New Issue
Block a user