Initial commit apps directory with .gitignore

This commit is contained in:
2026-02-22 15:15:41 +08:00
commit 0aa8cdd72c
228 changed files with 69672 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,48 @@
-- =====================================================
-- FIX ALFA ROLLBACK SCRIPT
-- Tanggal: 2026-01-12
-- Tujuan: Menghapus record ALFA yang salah terekap
-- =====================================================
--
-- INSTRUKSI:
-- 1. Jalankan STEP 1 dulu untuk melihat data yang akan dihapus
-- 2. Verifikasi outputnya benar (hanya record bukan XII-B)
-- 3. Jalankan STEP 2 untuk menghapus data
-- 4. Jalankan STEP 3 untuk verifikasi hasil
-- =====================================================
-- =====================================================
-- STEP 1: PREVIEW - Lihat data yang akan dihapus
-- Jalankan query ini PERTAMA untuk memastikan data benar
-- =====================================================
SELECT
class_name AS 'Kelas',
COUNT(*) AS 'Jumlah Siswa'
FROM attendance
WHERE date_str = '2026-01-12'
AND status = 'ALFA'
AND ai_verification = 'Otomatis dari Sistem'
AND class_name != 'XII-B'
GROUP BY class_name
ORDER BY class_name;
-- =====================================================
-- STEP 2: HAPUS DATA - Jalankan setelah preview benar
-- =====================================================
DELETE FROM attendance
WHERE date_str = '2026-01-12'
AND status = 'ALFA'
AND ai_verification = 'Otomatis dari Sistem'
AND class_name != 'XII-B';
-- =====================================================
-- STEP 3: VERIFIKASI - Pastikan hanya XII-B tersisa
-- =====================================================
SELECT
class_name AS 'Kelas',
COUNT(*) AS 'Jumlah ALFA Tersisa'
FROM attendance
WHERE date_str = '2026-01-12'
AND status = 'ALFA'
GROUP BY class_name
ORDER BY class_name;

View File

@@ -0,0 +1,25 @@
-- Migration: Add indexes for optimized daily attendance queries
-- Run this on your MySQL database to improve performance for large datasets
-- Index for daily attendance lookup (most common query pattern)
CREATE INDEX IF NOT EXISTS idx_attendance_date ON attendance(date_str);
-- Composite index for filtered daily queries (date + class + status)
CREATE INDEX IF NOT EXISTS idx_attendance_date_class ON attendance(date_str, class_name);
CREATE INDEX IF NOT EXISTS idx_attendance_date_status ON attendance(date_str, status);
CREATE INDEX IF NOT EXISTS idx_attendance_date_class_status ON attendance(date_str, class_name, status);
-- Index for user name search (LIKE queries)
CREATE INDEX IF NOT EXISTS idx_attendance_username ON attendance(user_name);
-- Index for pagination ordering (used with ORDER BY)
CREATE INDEX IF NOT EXISTS idx_attendance_classname_username ON attendance(class_name, user_name);
-- For faster COUNT queries
CREATE INDEX IF NOT EXISTS idx_attendance_status ON attendance(status);
-- Verify indexes were created
SHOW INDEX FROM attendance;
-- Performance tip: For very large tables (>100k rows), consider partitioning by month:
-- ALTER TABLE attendance PARTITION BY RANGE (YEAR(date_str) * 100 + MONTH(date_str));

View File

@@ -0,0 +1,82 @@
-- =====================================================
-- MIGRATION SCRIPT: Pengajuan Izin/Sakit Feature
-- Run this script on your MySQL database server
-- =====================================================
-- 1. Add phone column to staff_users table (for Guru BK WhatsApp notification)
ALTER TABLE staff_users
ADD COLUMN IF NOT EXISTS phone VARCHAR(20) AFTER role;
-- Alternative syntax if your MySQL version doesn't support IF NOT EXISTS:
-- First check if column exists, if not add it
-- SET @exist := (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'staff_users' AND COLUMN_NAME = 'phone');
-- SET @sql := IF(@exist = 0, 'ALTER TABLE staff_users ADD COLUMN phone VARCHAR(20) AFTER role', 'SELECT "Column already exists"');
-- PREPARE stmt FROM @sql;
-- EXECUTE stmt;
-- 2. Update attendance status ENUM to include SAKIT and IZIN
ALTER TABLE attendance
MODIFY COLUMN status ENUM('PRESENT', 'LATE', 'REGISTRATION', 'ALFA', 'SAKIT', 'IZIN') DEFAULT 'PRESENT';
-- 3. Create leave_requests table (Pengajuan Izin/Sakit dari Siswa)
CREATE TABLE IF NOT EXISTS leave_requests (
id VARCHAR(36) PRIMARY KEY,
student_id VARCHAR(36) NOT NULL COMMENT 'ID siswa yang mengajukan',
student_name VARCHAR(255) NOT NULL COMMENT 'Nama siswa',
student_nis VARCHAR(50) COMMENT 'NIS siswa',
student_class VARCHAR(100) COMMENT 'Kelas siswa',
request_type ENUM('SAKIT', 'IZIN') NOT NULL COMMENT 'Jenis pengajuan',
request_date VARCHAR(20) NOT NULL COMMENT 'Tanggal izin (YYYY-MM-DD)',
reason TEXT NOT NULL COMMENT 'Alasan pengajuan',
photo_evidence LONGTEXT COMMENT 'Bukti foto (base64 atau URL)',
status ENUM('PENDING', 'APPROVED', 'REJECTED') DEFAULT 'PENDING' COMMENT 'Status pengajuan',
reviewed_by VARCHAR(36) COMMENT 'ID Guru BK yang mereview',
reviewed_by_name VARCHAR(255) COMMENT 'Nama Guru BK yang mereview',
reviewed_at TIMESTAMP NULL COMMENT 'Waktu review',
rejection_reason TEXT COMMENT 'Alasan penolakan (wajib jika status REJECTED)',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT 'Waktu pengajuan dibuat',
INDEX idx_student (student_id),
INDEX idx_status (status),
INDEX idx_date (request_date),
INDEX idx_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- 4. Add Fonnte Token setting if not exists
INSERT IGNORE INTO settings (setting_key, setting_value)
VALUES ('FONNTE_TOKEN', '');
-- =====================================================
-- VERIFICATION QUERIES (Run to check if migration success)
-- =====================================================
-- Check staff_users has phone column:
-- DESCRIBE staff_users;
-- Check leave_requests table exists:
-- SHOW TABLES LIKE 'leave_requests';
-- Check attendance status enum:
-- SHOW COLUMNS FROM attendance LIKE 'status';
-- =====================================================
-- SAMPLE DATA FOR TESTING (Optional)
-- =====================================================
-- Create a sample Guru BK account with phone (change password hash as needed)
-- INSERT INTO staff_users (id, username, password, name, role, phone, is_active)
-- VALUES (
-- UUID(),
-- 'gurubk1',
-- SHA2('password123', 256), -- Password: password123
-- 'Guru BK Test',
-- 'GURU_BK',
-- '628123456789', -- WhatsApp number
-- TRUE
-- );
-- =====================================================
-- NOTES:
-- - Nomor WhatsApp harus format: 628xxxxxxxxxx (tanpa + atau 0)
-- - Fonnte Token didapat dari dashboard fonnte.com
-- - Guru BK bisa lebih dari 1, semua akan menerima notifikasi WA
-- =====================================================

View File

@@ -0,0 +1,86 @@
-- =====================================================
-- MIGRATION SCRIPT v2: Compatible Version
-- For MySQL 5.7+ / MariaDB 10.2+
-- =====================================================
-- =====================================================
-- STEP 1: Add phone column to staff_users
-- =====================================================
-- Check and add phone column (run this separately if error)
SET @dbname = DATABASE();
SET @tablename = 'staff_users';
SET @columnname = 'phone';
SET @preparedStatement = (SELECT IF(
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = @tablename AND COLUMN_NAME = @columnname) > 0,
'SELECT "Column phone already exists in staff_users"',
'ALTER TABLE staff_users ADD COLUMN phone VARCHAR(20) AFTER role'
));
PREPARE alterIfNotExists FROM @preparedStatement;
EXECUTE alterIfNotExists;
DEALLOCATE PREPARE alterIfNotExists;
-- =====================================================
-- STEP 2: Update attendance status ENUM
-- =====================================================
ALTER TABLE attendance
MODIFY COLUMN status ENUM('PRESENT', 'LATE', 'REGISTRATION', 'ALFA', 'SAKIT', 'IZIN') DEFAULT 'PRESENT';
-- =====================================================
-- STEP 3: Create leave_requests table
-- =====================================================
CREATE TABLE IF NOT EXISTS leave_requests (
id VARCHAR(36) NOT NULL,
student_id VARCHAR(36) NOT NULL,
student_name VARCHAR(255) NOT NULL,
student_nis VARCHAR(50) DEFAULT NULL,
student_class VARCHAR(100) DEFAULT NULL,
request_type ENUM('SAKIT', 'IZIN') NOT NULL,
request_date VARCHAR(20) NOT NULL,
reason TEXT NOT NULL,
photo_evidence LONGTEXT,
status ENUM('PENDING', 'APPROVED', 'REJECTED') DEFAULT 'PENDING',
reviewed_by VARCHAR(36) DEFAULT NULL,
reviewed_by_name VARCHAR(255) DEFAULT NULL,
reviewed_at TIMESTAMP NULL DEFAULT NULL,
rejection_reason TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
KEY idx_student (student_id),
KEY idx_status (status),
KEY idx_date (request_date),
KEY idx_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- =====================================================
-- STEP 4: Ensure Fonnte Token setting exists
-- =====================================================
INSERT INTO settings (setting_key, setting_value)
SELECT 'FONNTE_TOKEN', ''
WHERE NOT EXISTS (
SELECT 1 FROM settings WHERE setting_key = 'FONNTE_TOKEN'
);
-- =====================================================
-- VERIFICATION - Run these to confirm success
-- =====================================================
SELECT 'Checking staff_users phone column...' AS step;
SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'staff_users'
AND COLUMN_NAME = 'phone';
SELECT 'Checking leave_requests table...' AS step;
SELECT COUNT(*) as table_exists FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'leave_requests';
SELECT 'Checking attendance status enum...' AS step;
SHOW COLUMNS FROM attendance LIKE 'status';
SELECT 'Migration completed successfully!' AS result;