Initial commit: Aplikasi Ketertiban Siswa

- Fitur: input pelanggaran, sistem poin, surat peringatan otomatis, SP progress
- Realtime notifikasi via Laravel Reverb + Echo
- Dashboard statistik, manajemen user, manajemen master data
- Login 2 kolom premium, user dropdown, pengaturan akun
- Tema biru kalem, logo sekolah dinamis, sidebar brand dinamis
- Sinkronisasi siswa dari Database Kesiswaan via API
This commit is contained in:
Bro
2026-07-21 22:43:13 +07:00
commit 1c35734f7b
116 changed files with 19664 additions and 0 deletions
@@ -0,0 +1,168 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\SpThreshold;
use App\Models\ViolationCategory;
use App\Models\ViolationType;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Illuminate\View\View;
class MasterDataController extends Controller
{
// === Violation Categories ===
public function categories(): View
{
$categories = ViolationCategory::orderBy('sort_order')->get();
return view('settings.categories', compact('categories'));
}
public function storeCategory(Request $request): RedirectResponse
{
$validated = $request->validate([
'name' => ['required', 'string', 'max:255'],
'color' => ['required', 'string', 'max:7'],
'description' => ['nullable', 'string', 'max:500'],
'sort_order' => ['nullable', 'integer', 'min:0'],
]);
$validated['slug'] = Str::slug($validated['name']);
ViolationCategory::create($validated);
return back()->with('success', 'Kategori pelanggaran berhasil ditambahkan.');
}
public function updateCategory(Request $request, ViolationCategory $category): RedirectResponse
{
$validated = $request->validate([
'name' => ['required', 'string', 'max:255'],
'color' => ['required', 'string', 'max:7'],
'description' => ['nullable', 'string', 'max:500'],
'sort_order' => ['nullable', 'integer', 'min:0'],
'is_active' => ['boolean'],
]);
$validated['slug'] = Str::slug($validated['name']);
$validated['is_active'] = $request->boolean('is_active');
$category->update($validated);
return back()->with('success', 'Kategori berhasil diperbarui.');
}
public function destroyCategory(ViolationCategory $category): RedirectResponse
{
if ($category->violationTypes()->count() > 0) {
return back()->with('error', 'Kategori masih memiliki jenis pelanggaran. Hapus jenis pelanggaran terlebih dahulu.');
}
$category->delete();
return back()->with('success', 'Kategori berhasil dihapus.');
}
// === Violation Types ===
public function types(Request $request): View
{
$query = ViolationType::with('category');
if ($request->filled('search')) {
$search = $request->search;
$query->where(function ($q) use ($search) {
$q->where('name', 'like', "%{$search}%")
->orWhere('default_sanction', 'like', "%{$search}%");
});
}
if ($request->filled('category_id')) {
$query->where('category_id', $request->category_id);
}
$types = $query->orderBy('category_id')->orderBy('name')->paginate(20);
$categories = ViolationCategory::orderBy('sort_order')->get();
return view('settings.violation-types', compact('types', 'categories'));
}
public function storeType(Request $request): RedirectResponse
{
$validated = $request->validate([
'category_id' => ['required', 'exists:violation_categories,id'],
'name' => ['required', 'string', 'max:255'],
'points' => ['required', 'integer', 'min:0', 'max:500'],
'default_sanction' => ['nullable', 'string', 'max:500'],
'description' => ['nullable', 'string', 'max:1000'],
]);
$validated['slug'] = Str::slug($validated['name']);
$validated['is_active'] = true;
ViolationType::create($validated);
return back()->with('success', 'Jenis pelanggaran berhasil ditambahkan.');
}
public function updateType(Request $request, ViolationType $type): RedirectResponse
{
$validated = $request->validate([
'category_id' => ['required', 'exists:violation_categories,id'],
'name' => ['required', 'string', 'max:255'],
'points' => ['required', 'integer', 'min:0', 'max:500'],
'default_sanction' => ['nullable', 'string', 'max:500'],
'description' => ['nullable', 'string', 'max:1000'],
'is_active' => ['boolean'],
]);
$validated['slug'] = Str::slug($validated['name']);
$validated['is_active'] = $request->boolean('is_active');
$type->update($validated);
return back()->with('success', 'Jenis pelanggaran berhasil diperbarui.');
}
public function destroyType(ViolationType $type): RedirectResponse
{
if ($type->violations()->count() > 0) {
return back()->with('error', 'Jenis pelanggaran ini sudah tercatat pada pelanggaran siswa. Nonaktifkan saja.');
}
$type->delete();
return back()->with('success', 'Jenis pelanggaran berhasil dihapus.');
}
// === SP Thresholds ===
public function thresholds(): View
{
$thresholds = SpThreshold::orderBy('min_points')->get();
return view('settings.thresholds', compact('thresholds'));
}
public function updateThresholds(Request $request): RedirectResponse
{
$thresholds = $request->validate([
'thresholds' => ['required', 'array'],
'thresholds.*.id' => ['required', 'exists:sp_thresholds,id'],
'thresholds.*.min_points' => ['required', 'integer', 'min:0'],
'thresholds.*.max_points' => ['nullable', 'integer', 'min:0'],
'thresholds.*.name' => ['required', 'string', 'max:255'],
'thresholds.*.default_description' => ['nullable', 'string', 'max:500'],
]);
foreach ($thresholds['thresholds'] as $data) {
SpThreshold::where('id', $data['id'])->update([
'name' => $data['name'],
'min_points' => $data['min_points'],
'max_points' => $data['max_points'],
'default_description' => $data['default_description'],
]);
}
return back()->with('success', 'Ambang batas SP berhasil diperbarui.');
}
}
@@ -0,0 +1,74 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\View\View;
class ResetController extends Controller
{
public function index(): View
{
$stats = [
'violations' => DB::table('violations')->count(),
'evidences' => DB::table('violation_evidences')->count(),
'sp_letters' => DB::table('sp_letters')->count(),
'notifications' => DB::table('notifications')->count(),
'students' => DB::table('students')->count(),
'classes' => DB::table('classes')->count(),
'settings' => DB::table('settings')->count(),
'users_other' => DB::table('users')->where('id', '!=', 1)->count(),
];
return view('settings.reset', compact('stats'));
}
public function reset(Request $request): RedirectResponse
{
$request->validate([
'confirm_password' => ['required', 'string'],
]);
if (!Hash::check($request->confirm_password, $request->user()->password)) {
return back()->with('error', 'Password salah. Reset dibatalkan.');
}
DB::statement('SET FOREIGN_KEY_CHECKS=0');
DB::table('violation_evidences')->delete();
DB::table('violations')->delete();
DB::table('sp_letters')->delete();
DB::table('notifications')->delete();
DB::table('students')->delete();
DB::table('classes')->delete();
DB::table('violation_types')->delete();
DB::table('violation_categories')->delete();
DB::table('sp_thresholds')->delete();
DB::table('settings')->delete();
User::where('id', '!=', 1)->delete();
User::where('id', 1)->update(['is_active' => true, 'role' => 'admin']);
DB::statement('SET FOREIGN_KEY_CHECKS=1');
$violationsDir = storage_path('app/public/violations');
if (is_dir($violationsDir)) {
$it = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($violationsDir, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($it as $file) {
if ($file->isDir()) rmdir($file->getRealPath());
else unlink($file->getRealPath());
}
}
return redirect()->route('users.index')
->with('success', 'Reset berhasil! Semua data pelanggaran, siswa, master data, dan user lain dihapus. Hanya akun admin yang tersisa.');
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Setting;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class SettingsController extends Controller
{
public function index(): View
{
$settings = Setting::where('group', 'school')->get()->keyBy('key');
return view('settings.index', compact('settings'));
}
public function update(Request $request): RedirectResponse
{
$validated = $request->validate([
'app_name' => ['required', 'string', 'max:255'],
'school_name' => ['required', 'string', 'max:255'],
'school_address' => ['nullable', 'string', 'max:500'],
'school_phone' => ['nullable', 'string', 'max:50'],
'kepala_sekolah_name' => ['nullable', 'string', 'max:255'],
'kepala_sekolah_nip' => ['nullable', 'string', 'max:50'],
'bk_koordinator_name' => ['nullable', 'string', 'max:255'],
]);
foreach ($validated as $key => $value) {
Setting::setValue($key, $value, 'school');
}
if ($request->hasFile('school_logo')) {
$path = $request->file('school_logo')->store('school', 'public');
Setting::setValue('school_logo', $path, 'school', 'Logo sekolah');
}
if ($request->hasFile('login_background')) {
$path = $request->file('login_background')->store('school', 'public');
Setting::setValue('login_background', $path, 'school', 'Background halaman login');
}
return back()->with('success', 'Pengaturan berhasil disimpan.');
}
}
@@ -0,0 +1,66 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Setting;
use App\Services\StudentSyncService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class SyncController extends Controller
{
protected StudentSyncService $syncService;
public function __construct(StudentSyncService $syncService)
{
$this->syncService = $syncService;
}
public function index(): View
{
$baseUrl = Setting::getValue('kesiswaan_base_url', '');
$savedToken = Setting::getValue('kesiswaan_token', '');
$hasToken = !empty($savedToken);
$studentCount = \App\Models\Student::count();
return view('settings.sync', compact('baseUrl', 'savedToken', 'hasToken', 'studentCount'));
}
public function syncNow(Request $request): RedirectResponse
{
$validated = $request->validate([
'base_url' => ['required', 'url'],
'token' => ['nullable', 'string'],
]);
// Use saved token if not provided in form
if (empty($validated['token'])) {
$validated['token'] = Setting::getValue('kesiswaan_token', '');
}
if (empty($validated['token'])) {
return back()->with('error', 'Token sinkronisasi harus diisi.');
}
$result = $this->syncService->sync($validated['base_url'], $validated['token']);
if (isset($result['error'])) {
return back()->with('error', $result['error']);
}
// Save to settings
Setting::setValue('kesiswaan_base_url', $validated['base_url'], 'integration', 'URL Database Kesiswaan');
Setting::setValue('kesiswaan_token', $validated['token'], 'integration', 'Token sinkronisasi');
$msg = 'Sinkron berhasil! ' . $result['students_created'] . ' siswa baru, ' . $result['students_updated'] . ' diperbarui, ' . $result['classes_created'] . ' kelas baru.';
if (!empty($result['errors'])) {
$skipped = count($result['errors']);
$msg .= ' (' . $skipped . ' dilewati — siswa tidak aktif/tanpa NISN).';
}
return back()->with('success', $msg);
}
}
@@ -0,0 +1,92 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\View\View;
class UserController extends Controller
{
public function index(Request $request): View
{
$query = User::query();
if ($request->filled('search')) {
$search = $request->search;
$query->where(function ($q) use ($search) {
$q->where('name', 'like', "%{$search}%")
->orWhere('username', 'like', "%{$search}%")
->orWhere('email', 'like', "%{$search}%");
});
}
if ($request->filled('role')) {
$query->where('role', $request->role);
}
$users = $query->orderBy('name')->paginate(20);
return view('users.index', compact('users'));
}
public function store(Request $request): RedirectResponse
{
$validated = $request->validate([
'name' => ['required', 'string', 'max:255'],
'username' => ['required', 'string', 'max:255', 'unique:users,username'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users,email'],
'password' => ['required', 'string', 'min:6'],
'role' => ['required', 'in:admin,bk,wali_kelas,staff'],
'is_active' => ['boolean'],
]);
$validated['password'] = Hash::make($validated['password']);
$validated['is_active'] = $request->boolean('is_active', true);
User::create($validated);
return redirect()->route('users.index')
->with('success', 'User berhasil ditambahkan.');
}
public function update(Request $request, User $user): RedirectResponse
{
$validated = $request->validate([
'name' => ['required', 'string', 'max:255'],
'username' => ['required', 'string', 'max:255', 'unique:users,username,' . $user->id],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users,email,' . $user->id],
'password' => ['nullable', 'string', 'min:6'],
'role' => ['required', 'in:admin,bk,wali_kelas,staff'],
'is_active' => ['boolean'],
]);
if (!empty($validated['password'])) {
$validated['password'] = Hash::make($validated['password']);
} else {
unset($validated['password']);
}
$validated['is_active'] = $request->boolean('is_active', true);
$user->update($validated);
return redirect()->route('users.index')
->with('success', 'User berhasil diperbarui.');
}
public function destroy(User $user): RedirectResponse
{
if ($user->id === auth()->id()) {
return back()->with('error', 'Tidak bisa menghapus akun sendiri.');
}
$user->delete();
return redirect()->route('users.index')
->with('success', 'User berhasil dihapus.');
}
}