-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Aug 13, 2025 at 07:30 AM
-- Server version: 10.4.32-MariaDB
-- PHP Version: 8.2.12

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `spk_smp2mlp`
--

-- --------------------------------------------------------

--
-- Table structure for table `tb_batas_masalah`
--

CREATE TABLE `tb_batas_masalah` (
  `id_batas` int(10) UNSIGNED NOT NULL,
  `metode` enum('SAW','WP') NOT NULL,
  `batas_min` decimal(10,4) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `tb_batas_masalah`
--

INSERT INTO `tb_batas_masalah` (`id_batas`, `metode`, `batas_min`, `created_at`) VALUES
(2, 'WP', 0.4000, '2025-08-13 04:32:53'),
(3, 'SAW', 0.4000, '2025-08-13 04:34:26');

-- --------------------------------------------------------

--
-- Table structure for table `tb_hasil_saw`
--

CREATE TABLE `tb_hasil_saw` (
  `id_hasil` int(10) UNSIGNED NOT NULL,
  `id_siswa` int(10) UNSIGNED NOT NULL,
  `nilai_akhir` decimal(12,6) NOT NULL,
  `periode` varchar(20) DEFAULT NULL,
  `peringkat` int(11) NOT NULL,
  `status` enum('bermasalah','tidak_bermasalah') NOT NULL,
  `id_user` int(10) UNSIGNED NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `tb_hasil_saw`
--

INSERT INTO `tb_hasil_saw` (`id_hasil`, `id_siswa`, `nilai_akhir`, `periode`, `peringkat`, `status`, `id_user`, `created_at`) VALUES
(73, 3, 1.000000, '2024/2025', 1, 'tidak_bermasalah', 1, '2025-08-12 23:41:25'),
(74, 1, 0.775706, '2024/2025', 2, 'tidak_bermasalah', 1, '2025-08-12 23:41:25'),
(75, 2, 0.600885, '2024/2025', 3, 'tidak_bermasalah', 1, '2025-08-12 23:41:25');

-- --------------------------------------------------------

--
-- Table structure for table `tb_hasil_wp`
--

CREATE TABLE `tb_hasil_wp` (
  `id_hasil` int(10) UNSIGNED NOT NULL,
  `id_siswa` int(10) UNSIGNED NOT NULL,
  `nilai_akhir` decimal(20,10) NOT NULL,
  `periode` varchar(20) DEFAULT NULL,
  `peringkat` int(11) NOT NULL,
  `status` enum('bermasalah','tidak_bermasalah') NOT NULL,
  `id_user` int(10) UNSIGNED NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `tb_hasil_wp`
--

INSERT INTO `tb_hasil_wp` (`id_hasil`, `id_siswa`, `nilai_akhir`, `periode`, `peringkat`, `status`, `id_user`, `created_at`) VALUES
(23, 3, 0.4449240000, '2024/2025', 1, 'tidak_bermasalah', 1, '2025-08-12 23:41:28'),
(24, 1, 0.3326020000, '2024/2025', 2, 'bermasalah', 1, '2025-08-12 23:41:28'),
(25, 2, 0.2224740000, '2024/2025', 3, 'bermasalah', 1, '2025-08-12 23:41:28');

-- --------------------------------------------------------

--
-- Table structure for table `tb_kriteria`
--

CREATE TABLE `tb_kriteria` (
  `id_kriteria` int(10) UNSIGNED NOT NULL,
  `kode` varchar(10) NOT NULL,
  `nama_kriteria` varchar(100) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `tb_kriteria`
--

INSERT INTO `tb_kriteria` (`id_kriteria`, `kode`, `nama_kriteria`, `created_at`) VALUES
(1, 'C1', 'Nilai Rata-rata Raport', '2025-08-12 00:38:54'),
(2, 'C2', 'Peringkat Kelas', '2025-08-12 00:38:54'),
(3, 'C3', 'Sikap & Kedisiplinan', '2025-08-12 00:38:54'),
(4, 'C4', 'Keikutsertaan Organisasi', '2025-08-12 00:38:54');

-- --------------------------------------------------------

--
-- Table structure for table `tb_kriteria_metode`
--

CREATE TABLE `tb_kriteria_metode` (
  `id_k_metode` int(10) UNSIGNED NOT NULL,
  `id_kriteria` int(10) UNSIGNED NOT NULL,
  `metode` enum('SAW','WP') NOT NULL,
  `bobot` decimal(5,4) NOT NULL DEFAULT 0.0000,
  `sifat` enum('benefit','cost') NOT NULL,
  `urutan` int(11) DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `tb_kriteria_metode`
--

INSERT INTO `tb_kriteria_metode` (`id_k_metode`, `id_kriteria`, `metode`, `bobot`, `sifat`, `urutan`, `created_at`) VALUES
(1, 1, 'SAW', 0.4000, 'benefit', 1, '2025-08-12 00:38:54'),
(2, 2, 'SAW', 0.3000, 'cost', 2, '2025-08-12 00:38:54'),
(3, 3, 'SAW', 0.2000, 'benefit', 3, '2025-08-12 00:38:54'),
(4, 4, 'SAW', 0.1000, 'benefit', 4, '2025-08-12 00:38:54'),
(5, 1, 'WP', 0.4000, 'benefit', 1, '2025-08-12 00:38:54'),
(6, 2, 'WP', 0.3000, 'cost', 2, '2025-08-12 00:38:54'),
(7, 3, 'WP', 0.2000, 'benefit', 3, '2025-08-12 00:38:54'),
(8, 4, 'WP', 0.1000, 'benefit', 4, '2025-08-12 00:38:54');

-- --------------------------------------------------------

--
-- Table structure for table `tb_nilai`
--

CREATE TABLE `tb_nilai` (
  `id_nilai` int(10) UNSIGNED NOT NULL,
  `id_siswa` int(10) UNSIGNED NOT NULL,
  `id_k_metode` int(10) UNSIGNED NOT NULL,
  `periode` varchar(20) NOT NULL,
  `nilai` decimal(10,2) NOT NULL,
  `sumber` enum('input_manual','import') DEFAULT 'input_manual',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `tb_nilai`
--

INSERT INTO `tb_nilai` (`id_nilai`, `id_siswa`, `id_k_metode`, `periode`, `nilai`, `sumber`, `created_at`) VALUES
(1, 1, 1, '2024/2025', 85.00, 'input_manual', '2025-08-12 00:38:54'),
(2, 1, 2, '2024/2025', 2.00, 'input_manual', '2025-08-12 00:38:54'),
(3, 1, 3, '2024/2025', 90.00, 'input_manual', '2025-08-12 00:38:54'),
(4, 1, 4, '2024/2025', 2.00, 'input_manual', '2025-08-12 00:38:54'),
(5, 2, 1, '2024/2025', 78.00, 'input_manual', '2025-08-12 00:38:54'),
(6, 2, 2, '2024/2025', 5.00, 'input_manual', '2025-08-12 00:38:54'),
(7, 2, 3, '2024/2025', 80.00, 'input_manual', '2025-08-12 00:38:54'),
(8, 2, 4, '2024/2025', 1.00, 'input_manual', '2025-08-12 00:38:54'),
(9, 3, 1, '2024/2025', 92.00, 'input_manual', '2025-08-12 00:38:54'),
(10, 3, 2, '2024/2025', 1.00, 'input_manual', '2025-08-12 00:38:54'),
(11, 3, 3, '2024/2025', 95.00, 'input_manual', '2025-08-12 00:38:54'),
(12, 3, 4, '2024/2025', 3.00, 'input_manual', '2025-08-12 04:13:51'),
(13, 1, 5, '2024/2025', 85.00, 'input_manual', '2025-08-12 08:18:55'),
(14, 1, 6, '2024/2025', 2.00, 'input_manual', '2025-08-12 08:19:00'),
(15, 1, 7, '2024/2025', 90.00, 'input_manual', '2025-08-12 08:19:03'),
(16, 1, 8, '2024/2025', 2.00, 'input_manual', '2025-08-12 08:19:06'),
(17, 2, 5, '2024/2025', 78.00, 'input_manual', '2025-08-12 08:19:09'),
(18, 2, 6, '2024/2025', 5.00, 'input_manual', '2025-08-12 08:19:11'),
(19, 2, 7, '2024/2025', 80.00, 'input_manual', '2025-08-12 08:19:15'),
(20, 2, 8, '2024/2025', 1.00, 'input_manual', '2025-08-12 08:19:17'),
(21, 3, 5, '2024/2025', 92.00, 'input_manual', '2025-08-12 08:19:20'),
(22, 3, 6, '2024/2025', 1.00, 'input_manual', '2025-08-12 08:19:22'),
(23, 3, 7, '2024/2025', 95.00, 'input_manual', '2025-08-12 08:19:25'),
(24, 3, 8, '2024/2025', 3.00, 'input_manual', '2025-08-12 08:19:27');

-- --------------------------------------------------------

--
-- Table structure for table `tb_perbandingan`
--

CREATE TABLE `tb_perbandingan` (
  `id` int(10) UNSIGNED NOT NULL,
  `id_siswa` int(10) UNSIGNED NOT NULL,
  `nilai_saw` decimal(12,6) NOT NULL,
  `peringkat_saw` int(11) NOT NULL,
  `nilai_wp` decimal(20,10) NOT NULL,
  `peringkat_wp` int(11) NOT NULL,
  `selisih` decimal(20,10) GENERATED ALWAYS AS (`nilai_saw` - `nilai_wp`) VIRTUAL,
  `periode` varchar(20) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `tb_perbandingan`
--

INSERT INTO `tb_perbandingan` (`id`, `id_siswa`, `nilai_saw`, `peringkat_saw`, `nilai_wp`, `peringkat_wp`, `periode`, `created_at`) VALUES
(37, 3, 1.000000, 1, 0.4449240000, 1, '2024/2025', '2025-08-13 04:41:29'),
(38, 1, 0.775706, 2, 0.3326020000, 2, '2024/2025', '2025-08-13 04:41:29'),
(39, 2, 0.600885, 3, 0.2224740000, 3, '2024/2025', '2025-08-13 04:41:29');

-- --------------------------------------------------------

--
-- Table structure for table `tb_periode`
--

CREATE TABLE `tb_periode` (
  `id_periode` int(10) UNSIGNED NOT NULL,
  `periode` varchar(20) NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `tb_periode`
--

INSERT INTO `tb_periode` (`id_periode`, `periode`, `is_active`, `created_at`) VALUES
(1, '2024/2025', 1, '2025-08-12 04:00:36'),
(3, '2023/2024', 0, '2025-08-12 04:01:37');

-- --------------------------------------------------------

--
-- Table structure for table `tb_siswa`
--

CREATE TABLE `tb_siswa` (
  `id_siswa` int(10) UNSIGNED NOT NULL,
  `nisn` varchar(20) DEFAULT NULL,
  `nama` varchar(100) NOT NULL,
  `kelas` varchar(20) DEFAULT NULL,
  `jenis_kelamin` enum('Laki-laki','Perempuan') DEFAULT NULL,
  `tahun_ajaran` varchar(20) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `tb_siswa`
--

INSERT INTO `tb_siswa` (`id_siswa`, `nisn`, `nama`, `kelas`, `jenis_kelamin`, `tahun_ajaran`, `created_at`, `updated_at`) VALUES
(1, '001', 'Andi Pratama', '9A', 'Laki-laki', '2024/2025', '2025-08-12 00:38:54', NULL),
(2, '002', 'Beni Santoso', '9A', 'Laki-laki', '2024/2025', '2025-08-12 00:38:54', NULL),
(3, '003', 'Citra Lestari', '9B', 'Perempuan', '2024/2025', '2025-08-12 00:38:54', NULL);

-- --------------------------------------------------------

--
-- Table structure for table `tb_user`
--

CREATE TABLE `tb_user` (
  `id_user` int(10) UNSIGNED NOT NULL,
  `username` varchar(50) NOT NULL,
  `password_hash` varchar(255) NOT NULL,
  `nama` varchar(100) NOT NULL,
  `role` enum('Admin','Guru_BK','Wali_Kelas') NOT NULL DEFAULT 'Guru_BK',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `tb_user`
--

INSERT INTO `tb_user` (`id_user`, `username`, `password_hash`, `nama`, `role`, `created_at`, `updated_at`) VALUES
(1, 'admin', '21232f297a57a5a743894a0e4a801fc3', 'Admin', 'Admin', '2025-08-10 06:39:43', NULL),
(2, 'guru', '77e69c137812518e359196bb2f5e9bb9', 'Guru', 'Wali_Kelas', '2025-08-10 18:15:12', NULL),
(3, 'gurubk', '2ac04ec7fa4d34385573011704636f6c', 'Guru BK', 'Guru_BK', '2025-08-10 18:23:16', '2025-08-10 18:27:14');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `tb_batas_masalah`
--
ALTER TABLE `tb_batas_masalah`
  ADD PRIMARY KEY (`id_batas`);

--
-- Indexes for table `tb_hasil_saw`
--
ALTER TABLE `tb_hasil_saw`
  ADD PRIMARY KEY (`id_hasil`),
  ADD KEY `id_siswa` (`id_siswa`);

--
-- Indexes for table `tb_hasil_wp`
--
ALTER TABLE `tb_hasil_wp`
  ADD PRIMARY KEY (`id_hasil`),
  ADD KEY `id_siswa` (`id_siswa`);

--
-- Indexes for table `tb_kriteria`
--
ALTER TABLE `tb_kriteria`
  ADD PRIMARY KEY (`id_kriteria`);

--
-- Indexes for table `tb_kriteria_metode`
--
ALTER TABLE `tb_kriteria_metode`
  ADD PRIMARY KEY (`id_k_metode`),
  ADD KEY `id_kriteria` (`id_kriteria`);

--
-- Indexes for table `tb_nilai`
--
ALTER TABLE `tb_nilai`
  ADD PRIMARY KEY (`id_nilai`),
  ADD KEY `id_siswa` (`id_siswa`),
  ADD KEY `idx_id_k_metode` (`id_k_metode`);

--
-- Indexes for table `tb_perbandingan`
--
ALTER TABLE `tb_perbandingan`
  ADD PRIMARY KEY (`id`),
  ADD KEY `id_siswa` (`id_siswa`);

--
-- Indexes for table `tb_periode`
--
ALTER TABLE `tb_periode`
  ADD PRIMARY KEY (`id_periode`);

--
-- Indexes for table `tb_siswa`
--
ALTER TABLE `tb_siswa`
  ADD PRIMARY KEY (`id_siswa`);

--
-- Indexes for table `tb_user`
--
ALTER TABLE `tb_user`
  ADD PRIMARY KEY (`id_user`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `tb_batas_masalah`
--
ALTER TABLE `tb_batas_masalah`
  MODIFY `id_batas` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `tb_hasil_saw`
--
ALTER TABLE `tb_hasil_saw`
  MODIFY `id_hasil` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=76;

--
-- AUTO_INCREMENT for table `tb_hasil_wp`
--
ALTER TABLE `tb_hasil_wp`
  MODIFY `id_hasil` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=26;

--
-- AUTO_INCREMENT for table `tb_kriteria`
--
ALTER TABLE `tb_kriteria`
  MODIFY `id_kriteria` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--
-- AUTO_INCREMENT for table `tb_kriteria_metode`
--
ALTER TABLE `tb_kriteria_metode`
  MODIFY `id_k_metode` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=25;

--
-- AUTO_INCREMENT for table `tb_nilai`
--
ALTER TABLE `tb_nilai`
  MODIFY `id_nilai` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=25;

--
-- AUTO_INCREMENT for table `tb_perbandingan`
--
ALTER TABLE `tb_perbandingan`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=40;

--
-- AUTO_INCREMENT for table `tb_periode`
--
ALTER TABLE `tb_periode`
  MODIFY `id_periode` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `tb_siswa`
--
ALTER TABLE `tb_siswa`
  MODIFY `id_siswa` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- AUTO_INCREMENT for table `tb_user`
--
ALTER TABLE `tb_user`
  MODIFY `id_user` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `tb_hasil_saw`
--
ALTER TABLE `tb_hasil_saw`
  ADD CONSTRAINT `tb_hasil_saw_ibfk_1` FOREIGN KEY (`id_siswa`) REFERENCES `tb_siswa` (`id_siswa`) ON DELETE CASCADE;

--
-- Constraints for table `tb_hasil_wp`
--
ALTER TABLE `tb_hasil_wp`
  ADD CONSTRAINT `tb_hasil_wp_ibfk_1` FOREIGN KEY (`id_siswa`) REFERENCES `tb_siswa` (`id_siswa`) ON DELETE CASCADE;

--
-- Constraints for table `tb_kriteria_metode`
--
ALTER TABLE `tb_kriteria_metode`
  ADD CONSTRAINT `tb_kriteria_metode_ibfk_1` FOREIGN KEY (`id_kriteria`) REFERENCES `tb_kriteria` (`id_kriteria`) ON DELETE CASCADE;

--
-- Constraints for table `tb_nilai`
--
ALTER TABLE `tb_nilai`
  ADD CONSTRAINT `fk_tb_nilai_k_metode` FOREIGN KEY (`id_k_metode`) REFERENCES `tb_kriteria_metode` (`id_k_metode`) ON DELETE CASCADE,
  ADD CONSTRAINT `tb_nilai_ibfk_1` FOREIGN KEY (`id_siswa`) REFERENCES `tb_siswa` (`id_siswa`) ON DELETE CASCADE;

--
-- Constraints for table `tb_perbandingan`
--
ALTER TABLE `tb_perbandingan`
  ADD CONSTRAINT `tb_perbandingan_ibfk_1` FOREIGN KEY (`id_siswa`) REFERENCES `tb_siswa` (`id_siswa`) ON DELETE CASCADE;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
