Files
LAB_LINGKUNGAN/FOLDER/Managemen Pelanggan/query.sql
2025-04-24 11:26:20 +07:00

65 lines
3.0 KiB
SQL

-- Tabel Pelanggan
CREATE TABLE customers (
id INT PRIMARY KEY AUTO_INCREMENT,
customer_code VARCHAR(20) UNIQUE,
company_name VARCHAR(100),
customer_type ENUM('internal', 'external'),
address TEXT,
city VARCHAR(50),
postal_code VARCHAR(10),
phone VARCHAR(20),
email VARCHAR(100),
pic_name VARCHAR(100),
pic_phone VARCHAR(20),
pic_email VARCHAR(100),
registration_date DATETIME DEFAULT CURRENT_TIMESTAMP,
status ENUM('active', 'inactive') DEFAULT 'active',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME ON UPDATE CURRENT_TIMESTAMP
);
-- Tabel Riwayat Permintaan Analisis
CREATE TABLE analysis_requests (
id INT PRIMARY KEY AUTO_INCREMENT,
request_code VARCHAR(20) UNIQUE,
customer_id INT,
request_date DATETIME,
status ENUM('new', 'process', 'completed', 'cancelled'),
total_amount DECIMAL(10,2),
notes TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (customer_id) REFERENCES customers(id)
);
-- Tabel Riwayat Pembayaran
CREATE TABLE payments (
id INT PRIMARY KEY AUTO_INCREMENT,
request_id INT,
payment_code VARCHAR(20) UNIQUE,
payment_date DATETIME,
amount DECIMAL(10,2),
payment_method ENUM('cash', 'transfer', 'credit_card'),
payment_status ENUM('pending', 'completed', 'failed'),
proof_of_payment VARCHAR(255),
notes TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (request_id) REFERENCES analysis_requests(id)
);
-- Contoh data pelanggan
INSERT INTO customers (customer_code, company_name, customer_type, address, city, postal_code, phone, email, pic_name, pic_phone, pic_email) VALUES
('CUST001', 'PT Lingkungan Hijau', 'external', 'Jl. Raya Utama No. 123', 'Jakarta', '12345', '021-5551234', 'info@lingkunganhijau.com', 'Budi Santoso', '081234567890', 'budi@lingkunganhijau.com'),
('CUST002', 'Dinas Lingkungan Hidup', 'internal', 'Jl. Pemda No. 45', 'Bandung', '40111', '022-7891234', 'dlh@bandung.go.id', 'Siti Aminah', '087812345678', 'siti@bandung.go.id'),
('CUST003', 'CV Alam Lestari', 'external', 'Jl. Industri Blok A2', 'Surabaya', '60111', '031-8765432', 'contact@alamlestari.com', 'Rudi Hartono', '085678901234', 'rudi@alamlestari.com');
-- Contoh data permintaan analisis
INSERT INTO analysis_requests (request_code, customer_id, request_date, status, total_amount, notes) VALUES
('REQ001', 1, '2024-03-15 09:00:00', 'completed', 2500000, 'Analisis air limbah'),
('REQ002', 1, '2024-03-16 10:30:00', 'process', 1750000, 'Analisis kualitas udara'),
('REQ003', 2, '2024-03-17 13:15:00', 'new', 3000000, 'Analisis tanah');
-- Contoh data pembayaran
INSERT INTO payments (request_id, payment_code, payment_date, amount, payment_method, payment_status, notes) VALUES
(1, 'PAY001', '2024-03-15 14:30:00', 2500000, 'transfer', 'completed', 'Pembayaran lunas'),
(2, 'PAY002', '2024-03-16 11:00:00', 875000, 'transfer', 'completed', 'Pembayaran DP 50%'),
(3, 'PAY003', '2024-03-17 14:00:00', 1500000, 'transfer', 'pending', 'Menunggu konfirmasi transfer');