Source Code SPK F-AHP
This commit is contained in:
parent
570353ca4d
commit
c9ef53936f
|
|
@ -0,0 +1,18 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.{yml,yaml}]
|
||||
indent_size = 2
|
||||
|
||||
[docker-compose.yml]
|
||||
indent_size = 4
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
APP_NAME=Laravel
|
||||
APP_ENV=local
|
||||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
LOG_DEPRECATIONS_CHANNEL=null
|
||||
LOG_LEVEL=debug
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=laravel
|
||||
DB_USERNAME=root
|
||||
DB_PASSWORD=
|
||||
|
||||
BROADCAST_DRIVER=log
|
||||
CACHE_DRIVER=file
|
||||
FILESYSTEM_DISK=local
|
||||
QUEUE_CONNECTION=sync
|
||||
SESSION_DRIVER=file
|
||||
SESSION_LIFETIME=120
|
||||
|
||||
MEMCACHED_HOST=127.0.0.1
|
||||
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_MAILER=smtp
|
||||
MAIL_HOST=mailpit
|
||||
MAIL_PORT=1025
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
MAIL_FROM_ADDRESS="hello@example.com"
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
AWS_DEFAULT_REGION=us-east-1
|
||||
AWS_BUCKET=
|
||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||
|
||||
PUSHER_APP_ID=
|
||||
PUSHER_APP_KEY=
|
||||
PUSHER_APP_SECRET=
|
||||
PUSHER_HOST=
|
||||
PUSHER_PORT=443
|
||||
PUSHER_SCHEME=https
|
||||
PUSHER_APP_CLUSTER=mt1
|
||||
|
||||
VITE_APP_NAME="${APP_NAME}"
|
||||
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||
VITE_PUSHER_HOST="${PUSHER_HOST}"
|
||||
VITE_PUSHER_PORT="${PUSHER_PORT}"
|
||||
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
||||
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
* text=auto eol=lf
|
||||
|
||||
*.blade.php diff=html
|
||||
*.css diff=css
|
||||
*.html diff=html
|
||||
*.md diff=markdown
|
||||
*.php diff=php
|
||||
|
||||
/.github export-ignore
|
||||
CHANGELOG.md export-ignore
|
||||
.styleci.yml export-ignore
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteRule ^(.*)$ public/$1 [L]
|
||||
</IfModule>
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*/
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
// $schedule->command('inspire')->hourly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*/
|
||||
protected function commands(): void
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* The list of the inputs that are never flashed to the session on validation exceptions.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register the exception handling callbacks for the application.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->reportable(function (Throwable $e) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\HasilSeleksi;
|
||||
use App\Models\Periode;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||
// tambahan
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting; // <-- TAMBAHKAN INI
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
class HasilSeleksiExport implements FromCollection, WithHeadings, WithMapping, ShouldAutoSize, WithStyles, WithColumnFormatting
|
||||
{
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
|
||||
protected $periode_id;
|
||||
protected $status;
|
||||
protected $limit;
|
||||
|
||||
public function __construct($periode_id, $status = null, $limit = null)
|
||||
{
|
||||
$this->periode_id = $periode_id;
|
||||
$this->status = $status;
|
||||
$this->limit = $limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ambil koleksi data berdasarkan filter
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
$query = HasilSeleksi::with('warga')
|
||||
->where('periode_id', $this->periode_id)
|
||||
->orderBy('ranking', 'asc');
|
||||
|
||||
// Filter berdasarkan status keputusan
|
||||
if ($this->status) {
|
||||
$query->where('status_keputusan', $this->status);
|
||||
}
|
||||
|
||||
// Filter berdasarkan kuota periode
|
||||
if ($this->limit == 'kuota') {
|
||||
$periode = Periode::find($this->periode_id);
|
||||
if ($periode) {
|
||||
$query->take($periode->kuota);
|
||||
}
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Header Excel
|
||||
*/
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Ranking',
|
||||
'Nama Warga',
|
||||
'NIK',
|
||||
'Skor Akhir (V)',
|
||||
'Status Keputusan'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Mapping Data
|
||||
*/
|
||||
public function map($hasil): array
|
||||
{
|
||||
return [
|
||||
$hasil->ranking,
|
||||
$hasil->warga->nama,
|
||||
$hasil->warga->nik . ' ', // Tambah spasi agar NIK tidak jadi format scientific (E+) di Excel
|
||||
(float) $hasil->skor_akhir,
|
||||
// number_format($hasil->skor_akhir, 8),
|
||||
$hasil->status_keputusan,
|
||||
];
|
||||
}
|
||||
|
||||
//menampilkan 4 digit
|
||||
public function columnFormats(): array
|
||||
{
|
||||
return [
|
||||
'D' => '0.0000', // <-- Mengunci Kolom D (Skor Akhir) agar selalu menampilkan 4 angka di belakang koma
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Styling sederhana (Opsional: Membuat header Bold)
|
||||
*/
|
||||
public function styles(Worksheet $sheet)
|
||||
{
|
||||
return [
|
||||
1 => ['font' => ['bold' => true]],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Kriteria;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
|
||||
class TemplateWargaExport implements FromArray, WithHeadings, WithTitle, ShouldAutoSize
|
||||
{
|
||||
public function title(): string
|
||||
{
|
||||
return 'Template Import Warga';
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
$kriterias = Kriteria::orderBy('kode', 'asc')->get();
|
||||
|
||||
// Baris 1: Header untuk Sistem (nik, nama, c1_..., dst)
|
||||
$header = ['nik', 'nama', 'alamat', 'rt', 'rw'];
|
||||
foreach ($kriterias as $k) {
|
||||
$header[] = strtolower($k->kode) . '_' . strtolower(str_replace(' ', '_', $k->nama));
|
||||
}
|
||||
|
||||
return $header;
|
||||
}
|
||||
|
||||
public function array(): array
|
||||
{
|
||||
$kriterias = Kriteria::with('subKriterias')->orderBy('kode', 'asc')->get();
|
||||
|
||||
// Baris 2: Panduan untuk Admin (Contoh isi)
|
||||
$guideline = ['Contoh: 3512xxx', 'Nama Lengkap', 'Alamat', '001', '002'];
|
||||
foreach ($kriterias as $k) {
|
||||
$opsi = $k->subKriterias->pluck('nama_sub')->implode(' , ');
|
||||
$guideline[] = 'PILIH: [' . $opsi . ']';
|
||||
}
|
||||
|
||||
return [$guideline];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Warga;
|
||||
use App\Models\Kriteria;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
|
||||
class WargaExport implements FromQuery, WithHeadings, WithMapping, ShouldAutoSize
|
||||
{
|
||||
protected $request;
|
||||
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function query()
|
||||
{
|
||||
// Gunakan logic filter yang sama dengan Index
|
||||
$query = Warga::with(['details']);
|
||||
|
||||
if ($this->request->filled('search')) {
|
||||
$search = $this->request->search;
|
||||
$query->where(function($q) use ($search) {
|
||||
$q->where('nama', 'LIKE', "%$search%")->orWhere('nik', 'LIKE', "%$search%");
|
||||
});
|
||||
}
|
||||
|
||||
if ($this->request->filled('rt')) {
|
||||
$query->where('rt', str_pad($this->request->rt, 3, '0', STR_PAD_LEFT));
|
||||
}
|
||||
|
||||
if ($this->request->filled('rw')) {
|
||||
$query->where('rw', str_pad($this->request->rw, 3, '0', STR_PAD_LEFT));
|
||||
}
|
||||
|
||||
// Filter Kriteria
|
||||
$kriterias = Kriteria::all();
|
||||
foreach ($kriterias as $k) {
|
||||
$filterKey = 'f_kriteria_' . $k->id;
|
||||
if ($this->request->filled($filterKey)) {
|
||||
$nilaiFilter = $this->request->get($filterKey);
|
||||
$query->whereHas('details', function($q) use ($k, $nilaiFilter) {
|
||||
$q->where('kriteria_id', $k->id)->where('nilai_asli', $nilaiFilter);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
$header = ['No', 'Nama Lengkap', 'NIK', 'RT', 'RW', 'Status Verifikasi'];
|
||||
|
||||
// Tambahkan nama kriteria secara dinamis ke header excel
|
||||
$kriterias = Kriteria::orderBy('kode', 'asc')->get();
|
||||
foreach ($kriterias as $k) {
|
||||
$header[] = $k->nama;
|
||||
}
|
||||
|
||||
return $header;
|
||||
}
|
||||
|
||||
public function map($warga): array
|
||||
{
|
||||
static $no = 0;
|
||||
$no++;
|
||||
|
||||
$row = [
|
||||
$no,
|
||||
$warga->nama,
|
||||
$warga->nik . " ", // Spasi agar NIK tidak jadi scientific number di Excel
|
||||
$warga->rt,
|
||||
$warga->rw,
|
||||
strtoupper($warga->status_verifikasi),
|
||||
];
|
||||
|
||||
// Isi nilai kriteria secara dinamis
|
||||
$kriterias = Kriteria::orderBy('kode', 'asc')->get();
|
||||
foreach ($kriterias as $k) {
|
||||
$detail = $warga->details->where('kriteria_id', $k->id)->first();
|
||||
$row[] = $detail ? $detail->nilai_asli : '-';
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Pengaturan;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
/**
|
||||
* Halaman My Profile
|
||||
*/
|
||||
public function profile()
|
||||
{
|
||||
$user = Auth::user();
|
||||
return view('account.profile', compact('user'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Data Profil (Nama, Username, Alamat, & Password)
|
||||
*/
|
||||
public function updateProfile(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$request->validate([
|
||||
'nama_lengkap' => 'required|string|max:255',
|
||||
'username' => 'required|string|alpha_dash|unique:users,username,' . $user->id,
|
||||
'alamat' => 'nullable|string',
|
||||
'password_baru' => 'nullable|min:8|confirmed',
|
||||
], [
|
||||
'username.unique' => 'Username sudah digunakan.',
|
||||
'password_baru.confirmed' => 'Konfirmasi password baru tidak cocok.'
|
||||
]);
|
||||
|
||||
// Update data dasar
|
||||
$user->nama_lengkap = $request->nama_lengkap;
|
||||
$user->username = $request->username;
|
||||
$user->alamat = $request->alamat;
|
||||
|
||||
// Update password jika diisi
|
||||
if ($request->filled('password_baru')) {
|
||||
$user->password = Hash::make($request->password_baru);
|
||||
}
|
||||
|
||||
$user->save();
|
||||
|
||||
return back()->with('success', 'Profil Anda berhasil diperbarui!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Halaman Account Settings (PIN Pakar)
|
||||
*/
|
||||
public function settings()
|
||||
{
|
||||
$user = Auth::user();
|
||||
$pinPakar = Pengaturan::where('nama_pengaturan', 'pin_pakar')->first();
|
||||
|
||||
return view('account.settings', compact('user', 'pinPakar'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update PIN Pakar (Dibatasi hanya untuk Admin)
|
||||
*/
|
||||
public function updatePin(Request $request)
|
||||
{
|
||||
// Proteksi tambahan: hanya role admin yang boleh ubah PIN
|
||||
if (Auth::user()->role !== 'admin') {
|
||||
return back()->with('error', 'Hanya Admin yang dapat mengubah PIN Perbandingan.');
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'pin_baru' => 'required|numeric|digits:6',
|
||||
], [
|
||||
'pin_baru.digits' => 'PIN harus berupa 6 digit angka.'
|
||||
]);
|
||||
|
||||
// PERBAIKAN: Gunakan updateOrCreate agar otomatis membuat data jika belum ada
|
||||
Pengaturan::updateOrCreate(
|
||||
['nama_pengaturan' => 'pin_pakar'], // Kriteria pencarian
|
||||
['nilai_pengaturan' => $request->pin_baru] // Data yang diisi/diupdate
|
||||
);
|
||||
|
||||
return back()->with('success', 'PIN Keamanan Pakar berhasil diperbarui!');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function showLogin()
|
||||
{
|
||||
return view('login');
|
||||
}
|
||||
|
||||
public function showRegister()
|
||||
{
|
||||
return view('register');
|
||||
}
|
||||
|
||||
public function register(Request $request)
|
||||
{
|
||||
// Tambahkan custom message di parameter kedua validate()
|
||||
$request->validate([
|
||||
'nama_lengkap' => 'required|string|max:255',
|
||||
'username' => 'required|string|unique:users,username',
|
||||
'password' => 'required|min:6',
|
||||
'alamat' => 'required',
|
||||
], [
|
||||
'username.unique' => 'Maaf, username ini sudah terdaftar. Silakan buat username lain.',
|
||||
'password.min' => 'Kata sandi terlalu pendek, minimal harus 6 karakter.',
|
||||
]);
|
||||
|
||||
User::create([
|
||||
'nama_lengkap' => $request->nama_lengkap,
|
||||
'username' => $request->username,
|
||||
'password' => Hash::make($request->password),
|
||||
'alamat' => $request->alamat,
|
||||
'role' => 'verifikator', // Default role saat daftar
|
||||
'status' => 'nonaktif',
|
||||
]);
|
||||
|
||||
return redirect('/login')->with('success', 'Registrasi berhasil! Akun Anda sedang ditinjau. Silakan hubungi Admin Desa untuk aktivasi.');
|
||||
}
|
||||
|
||||
public function login(Request $request)
|
||||
{
|
||||
// Validasi input
|
||||
$credentials = $request->validate([
|
||||
'username' => 'required',
|
||||
'password' => 'required',
|
||||
]);
|
||||
|
||||
// 1. Cari user berdasarkan username terlebih dahulu untuk cek statusnya
|
||||
$user = \App\Models\User::where('username', $request->username)->first();
|
||||
|
||||
if ($user) {
|
||||
// 2. Cek apakah akun aktif
|
||||
if ($user->status !== 'aktif') {
|
||||
return back()->with('error', 'Akun Anda belum aktif. Silakan hubungi Admin Desa untuk aktivasi.')->withInput($request->only('username'));
|
||||
}
|
||||
|
||||
// 3. Jika aktif, baru coba lakukan proses login (Auth::attempt)
|
||||
if (Auth::attempt($credentials)) {
|
||||
$request->session()->regenerate();
|
||||
|
||||
// Redirect sesuai role
|
||||
if ($user->role === 'admin') {
|
||||
return redirect()->intended(route('admin.dashboard'));
|
||||
}
|
||||
|
||||
if ($user->role === 'verifikator') {
|
||||
return redirect()->intended(route('verifikator.dashboard'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Jika user tidak ditemukan atau password salah
|
||||
return back()->withErrors([
|
||||
'username' => 'Username atau password salah.',
|
||||
])->withInput($request->only('username'));
|
||||
}
|
||||
|
||||
public function logout(Request $request)
|
||||
{
|
||||
Auth::logout();
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return redirect('/login');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, ValidatesRequests;
|
||||
}
|
||||
|
|
@ -0,0 +1,165 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\HasilSeleksi;
|
||||
use App\Models\Kriteria;
|
||||
use App\Models\Periode;
|
||||
use App\Models\User;
|
||||
use App\Models\Warga;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
// Tambahkan Request di parameter fungsi
|
||||
public function adminDashboard(Request $request)
|
||||
{
|
||||
return view('admin.dashboard', $this->getDashboardData($request));
|
||||
}
|
||||
|
||||
public function verifikatorDashboard(Request $request)
|
||||
{
|
||||
return view('verifikator.dashboard', $this->getDashboardData($request));
|
||||
}
|
||||
|
||||
private function getDashboardData(Request $request)
|
||||
{
|
||||
// 1. Ambil SEMUA periode untuk pilihan di dropdown
|
||||
$semuaPeriode = Periode::orderBy('id', 'desc')->get();
|
||||
|
||||
// 2. Tentukan periode mana yang sedang ingin dilihat
|
||||
$periodeId = $request->query('periode_id');
|
||||
|
||||
if ($periodeId) {
|
||||
$periodeDitampilkan = Periode::find($periodeId);
|
||||
} else {
|
||||
// Default: Cari yang aktif, jika tidak ada, ambil yang paling baru
|
||||
$periodeDitampilkan = Periode::where('is_aktif', true)->first() ?? Periode::latest()->first();
|
||||
}
|
||||
|
||||
// Default value untuk statistik periode terpilih
|
||||
$utama = 0;
|
||||
$cadangan = 0;
|
||||
$tidakLayak = 0;
|
||||
$dialihkan = 0;
|
||||
$kuota = 0;
|
||||
$topWarga = collect();
|
||||
|
||||
if ($periodeDitampilkan) {
|
||||
$kuota = $periodeDitampilkan->kuota;
|
||||
|
||||
// Hitung status keputusan untuk grafik batang/pie periode terpilih
|
||||
$hasilStats = HasilSeleksi::where('periode_id', $periodeDitampilkan->id)
|
||||
->selectRaw('status_keputusan, count(*) as total')
|
||||
->groupBy('status_keputusan')
|
||||
->pluck('total', 'status_keputusan');
|
||||
|
||||
$utama = $hasilStats['Layak Prioritas Utama'] ?? 0;
|
||||
$cadangan = $hasilStats['Layak Cadangan'] ?? 0;
|
||||
$tidakLayak = $hasilStats['Tidak Layak'] ?? 0;
|
||||
$dialihkan = $hasilStats['Dialihkan (Pemerataan)'] ?? 0;
|
||||
|
||||
// Ambil 5 peringkat teratas untuk tabel ranking
|
||||
$topWarga = HasilSeleksi::with('warga')
|
||||
->where('periode_id', $periodeDitampilkan->id)
|
||||
->orderBy('ranking', 'asc')
|
||||
->take(5)
|
||||
->get();
|
||||
}
|
||||
|
||||
// 3. Rekap semua status verifikasi warga (Global - Seluruh Warga di Sistem)
|
||||
$wargaStats = Warga::selectRaw('status_verifikasi, count(*) as total')
|
||||
->groupBy('status_verifikasi')
|
||||
->pluck('total', 'status_verifikasi');
|
||||
|
||||
$totalWarga = array_sum($wargaStats->toArray());
|
||||
|
||||
$wargaPendingList = Warga::where('status_verifikasi', 'pending')
|
||||
->orderBy('created_at', 'asc')
|
||||
->take(5)
|
||||
->get();
|
||||
|
||||
// 4. LOGIKA TAMBAHAN: Data Tren Histori (Line Chart)
|
||||
// Mengambil 6 periode terakhir secara urutan ID (kronologis)
|
||||
$periodeTren = Periode::orderBy('id', 'asc')->take(6)->get();
|
||||
$labelTren = [];
|
||||
$dataUtamaTren = [];
|
||||
|
||||
foreach ($periodeTren as $pt) {
|
||||
$labelTren[] = $pt->nama_periode; // Contoh: "April 2026"
|
||||
|
||||
// Hitung jumlah warga yang masuk Prioritas Utama di periode ini
|
||||
$jumlahUtama = HasilSeleksi::where('periode_id', $pt->id)
|
||||
->where('status_keputusan', 'Layak Prioritas Utama')
|
||||
->count();
|
||||
|
||||
$dataUtamaTren[] = $jumlahUtama;
|
||||
}
|
||||
|
||||
|
||||
// demografi
|
||||
$semuaKriteria = Kriteria::all();
|
||||
|
||||
// Tangkap ID kriteria dari request dropdown (misal: ?kriteria_chart=2)
|
||||
$selectedKriteriaId = $request->query('kriteria_chart');
|
||||
|
||||
// Jika tidak ada yang dipilih (pertama kali load), otomatis pilih kriteria urutan pertama
|
||||
if (!$selectedKriteriaId && $semuaKriteria->count() > 0) {
|
||||
$selectedKriteriaId = $semuaKriteria->first()->id;
|
||||
}
|
||||
|
||||
$kriteriaDitampilkan = null;
|
||||
$statistikKriteria = collect(); // Set nilai default kosong agar tidak error
|
||||
|
||||
// Jika ada kriteria yang aktif/terpilih, baru jalankan query ke database
|
||||
if ($selectedKriteriaId) {
|
||||
$kriteriaDitampilkan = \App\Models\Kriteria::find($selectedKriteriaId);
|
||||
|
||||
// PERUBAHAN DI SINI: Tambahkan "warga_details." di dalam where()
|
||||
$statistikKriteria = \App\Models\WargaDetail::where('warga_details.kriteria_id', $selectedKriteriaId)
|
||||
->join('sub_kriterias', 'warga_details.sub_kriteria_id', '=', 'sub_kriterias.id')
|
||||
->selectRaw('sub_kriterias.nama_sub as label, count(*) as total')
|
||||
->groupBy('sub_kriterias.nama_sub')
|
||||
->pluck('total', 'label');
|
||||
}
|
||||
|
||||
return [
|
||||
'user' => Auth::user(),
|
||||
'countUser' => User::count(),
|
||||
'countWarga' => $totalWarga,
|
||||
'countVerif' => $wargaStats['setuju'] ?? 0,
|
||||
'countPending' => $wargaStats['pending'] ?? 0,
|
||||
'countTolak' => $wargaStats['tolak'] ?? 0,
|
||||
'countKriteria' => Kriteria::count(),
|
||||
|
||||
// Variabel Chart Batang & Ranking Periode Terpilih
|
||||
'chartUtama' => $utama,
|
||||
'chartCadangan' => $cadangan,
|
||||
'chartTidakLayak' => $tidakLayak,
|
||||
'chartDialihkan' => $dialihkan,
|
||||
'countRanking' => $utama + $cadangan + $tidakLayak + $dialihkan,
|
||||
|
||||
// Variabel Kuota & Tabel Top 5
|
||||
'kuota' => $kuota,
|
||||
'persentaseKuota' => $kuota > 0 ? round(($utama / $kuota) * 100) : 0,
|
||||
'topWarga' => $topWarga,
|
||||
|
||||
// Variabel Untuk Grafik Tren Histori (Line Chart)
|
||||
'labelTren' => $labelTren,
|
||||
'dataUtamaTren' => $dataUtamaTren,
|
||||
|
||||
'wargaPendingList' => $wargaPendingList,
|
||||
|
||||
// Variabel Untuk Filter Dropdown
|
||||
'semuaPeriode' => $semuaPeriode,
|
||||
'periodeDitampilkan' => $periodeDitampilkan,
|
||||
'namaPeriode' => $periodeDitampilkan ? $periodeDitampilkan->nama_periode : 'Belum Ada Periode',
|
||||
|
||||
// demografi
|
||||
'semuaKriteria' => $semuaKriteria,
|
||||
'kriteriaDitampilkan' => $kriteriaDitampilkan,
|
||||
'statistikKriteria' => $statistikKriteria,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,189 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Kriteria;
|
||||
use App\Models\SubKriteria;
|
||||
use App\Models\Warga;
|
||||
use App\Models\WargaDetail;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class KriteriaController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
// Tangkap request 'per_page', default-nya 10
|
||||
$perPage = $request->input('per_page', 10);
|
||||
|
||||
// Gunakan orderBy untuk mengurutkan, lalu paginate dan appends
|
||||
$kriterias = Kriteria::query()
|
||||
->orderBy('kode', 'asc')
|
||||
->paginate($perPage)
|
||||
->appends($request->query());
|
||||
|
||||
return view('kriteria.index', compact('kriterias', 'perPage'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method untuk menampilkan form tambah dengan Kode Otomatis
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$lastKriteria = Kriteria::orderBy('id', 'desc')->first();
|
||||
|
||||
if ($lastKriteria) {
|
||||
$lastNumber = (int) substr($lastKriteria->kode, 1);
|
||||
$nextNumber = $lastNumber + 1;
|
||||
} else {
|
||||
$nextNumber = 1;
|
||||
}
|
||||
|
||||
$nextKode = 'C' . $nextNumber;
|
||||
|
||||
return view('kriteria.create', compact('nextKode'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method untuk menyimpan data baru sekaligus sinkronisasi data warga
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'kode' => 'required|string|max:5|unique:kriterias,kode',
|
||||
'nama' => 'required|string|max:255',
|
||||
'nama_sub_default' => 'required|string|max:255', // Validasi sub-kriteria default
|
||||
], [
|
||||
'kode.unique' => 'Kode Kriteria sudah digunakan!',
|
||||
'kode.required' => 'Kode harus diisi',
|
||||
'nama.required' => 'Nama Kriteria harus diisi',
|
||||
'nama_sub_default.required' => 'Nama Sub-Kriteria awal wajib diisi untuk sinkronisasi warga.',
|
||||
]);
|
||||
|
||||
try {
|
||||
// Menggunakan Transaksi agar jika salah satu proses gagal, database tidak berantakan
|
||||
DB::transaction(function () use ($request) {
|
||||
|
||||
// 1. Simpan Kriteria Baru
|
||||
$kriteria = Kriteria::create([
|
||||
'kode' => strtoupper($request->kode),
|
||||
'nama' => $request->nama,
|
||||
'bobot_global' => 0,
|
||||
]);
|
||||
|
||||
// 2. Buat satu Sub-Kriteria Default (Nilai terendah/awal)
|
||||
// Kode formatnya S.C1.1
|
||||
$subDefault = SubKriteria::create([
|
||||
'kriteria_id' => $kriteria->id,
|
||||
'kode' => 'S.' . $kriteria->kode . '.1',
|
||||
'nama_sub' => $request->nama_sub_default,
|
||||
'nilai_acuan' => 1, // Default nilai acuan terendah
|
||||
'bobot_lokal' => 0,
|
||||
]);
|
||||
|
||||
// 3. Tarik semua warga yang sudah ada
|
||||
$allWarga = Warga::all();
|
||||
|
||||
// 4. Masukkan data kriteria baru ini ke setiap warga di tabel warga_details
|
||||
// Ini memastikan warga lama tetap punya data lengkap saat perhitungan F-AHP
|
||||
foreach ($allWarga as $warga) {
|
||||
WargaDetail::create([
|
||||
'warga_id' => $warga->id,
|
||||
'kriteria_id' => $kriteria->id,
|
||||
'sub_kriteria_id' => $subDefault->id,
|
||||
'nilai_asli' => 0,
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
return redirect()->route('kriteria.index')
|
||||
->with('success', 'Kriteria berhasil ditambah dan disinkronkan ke seluruh data warga!');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Jika ada error, kembali ke form dengan pesan error
|
||||
return redirect()->back()
|
||||
->with('error', 'Gagal menyimpan data: ' . $e->getMessage())
|
||||
->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$kriteria = Kriteria::findOrFail($id);
|
||||
return view('kriteria.edit', compact('kriteria'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$request->validate([
|
||||
'nama' => 'required|string|max:255',
|
||||
]);
|
||||
|
||||
$kriteria = Kriteria::findOrFail($id);
|
||||
$kriteria->update(['nama' => $request->nama]);
|
||||
|
||||
return redirect()->route('kriteria.index')->with('success', 'Kriteria berhasil diperbarui!');
|
||||
}
|
||||
|
||||
// public function destroy($id)
|
||||
// {
|
||||
// // Catatan: Pastikan di Model Kriteria sudah diatur OnDelete Cascade
|
||||
// // atau hapus manual relasi terkait jika tidak menggunakan cascade.
|
||||
// $kriteria = Kriteria::findOrFail($id);
|
||||
// $kriteria->delete();
|
||||
|
||||
// return redirect()->route('kriteria.index')->with('success', 'Kriteria berhasil dihapus!');
|
||||
// }
|
||||
public function destroy($id)
|
||||
{
|
||||
|
||||
// ===================================================================
|
||||
// 1. PAGAR PELINDUNG ARSIP
|
||||
// Cek apakah sistem sudah pernah menghasilkan riwayat Hasil Seleksi
|
||||
// ===================================================================
|
||||
$adaHasilSeleksi = DB::table('hasil_seleksis')->count();
|
||||
|
||||
if ($adaHasilSeleksi > 0) {
|
||||
return redirect()->back()->with('error', 'Gagal! Kriteria tidak bisa dihapus karena sudah menjadi arsip riwayat Hasil Seleksi. Silakan Edit (Update) saja namanya jika ada perubahan aturan.');
|
||||
}
|
||||
|
||||
// ingat jika belum ada riwayat ya lanjut proses seperti biasa
|
||||
|
||||
// Menggunakan DB Transaction untuk memastikan integritas data
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
$kriteria = Kriteria::findOrFail($id);
|
||||
|
||||
// 1. Hapus data perbandingan pakar yang melibatkan kriteria ini
|
||||
// Jika tidak dihapus, data ini akan menjadi 'sampah' dan merusak perhitungan matriks
|
||||
DB::table('perbandingans')
|
||||
->where('kriteria_kiri_id', $id)
|
||||
->orWhere('kriteria_kanan_id', $id)
|
||||
->delete();
|
||||
|
||||
// 2. Hapus data detail warga yang terkait dengan kriteria ini
|
||||
// (Langkah antisipasi jika di database belum terset OnDelete Cascade)
|
||||
DB::table('warga_details')->where('kriteria_id', $id)->delete();
|
||||
|
||||
// 3. Hapus kriteria utama
|
||||
$kriteria->delete();
|
||||
|
||||
// 4. Hitung ulang bobot global untuk kriteria yang tersisa
|
||||
// Kita memanggil fungsi updateWeights() dari PerbandinganController secara dinamis
|
||||
$perbandinganController = new \App\Http\Controllers\PerbandinganController();
|
||||
$perbandinganController->updateWeights();
|
||||
|
||||
DB::commit();
|
||||
|
||||
return redirect()->route('kriteria.index')
|
||||
->with('success', 'Kriteria berhasil dihapus dan bobot global telah diperbarui secara otomatis!');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
|
||||
return redirect()->route('kriteria.index')
|
||||
->with('error', 'Gagal menghapus kriteria: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\HasilSeleksi;
|
||||
use App\Models\Kriteria;
|
||||
use App\Models\Pengumuman;
|
||||
use App\Models\ProfilDesa;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LandingPageController extends Controller
|
||||
{
|
||||
// Lalu ubah fungsi index() menjadi seperti ini:
|
||||
public function index()
|
||||
{
|
||||
$pengumumans = Pengumuman::where('status', 'aktif')->latest()->take(5)->get();
|
||||
$kriterias = Kriteria::orderBy('kode', 'asc')->get();
|
||||
|
||||
// Mengambil data profil desa (baris pertama)
|
||||
$profil = ProfilDesa::first();
|
||||
|
||||
return view('landing-page.index', compact('pengumumans', 'kriterias', 'profil'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fitur Cek Status Bansos untuk Warga menggunakan NIK
|
||||
*/
|
||||
public function cekBansos(Request $request)
|
||||
{
|
||||
// Validasi input NIK (Harus angka dan 16 digit sesuai standar KTP)
|
||||
$request->validate([
|
||||
'nik' => 'required|numeric|digits:16'
|
||||
], [
|
||||
'nik.required' => 'Nomor NIK tidak boleh kosong.',
|
||||
'nik.numeric' => 'Format NIK harus berupa angka.',
|
||||
'nik.digits' => 'NIK harus berjumlah tepat 16 digit.'
|
||||
]);
|
||||
|
||||
$nik = $request->input('nik');
|
||||
|
||||
// Mencari data di tabel hasil_seleksi melalui relasi ke tabel warga berdasarkan NIK
|
||||
$hasil = HasilSeleksi::whereHas('warga', function ($query) use ($nik) {
|
||||
$query->where('nik', $nik);
|
||||
})->with(['warga', 'periode'])->latest()->first();
|
||||
|
||||
if ($hasil) {
|
||||
// Jika ketemu, kembalikan ke landing page dengan data hasil seleksi
|
||||
return redirect()->back()
|
||||
->with('hasil_pencarian', $hasil)
|
||||
->withFragment('cek-bansos'); // Otomatis scroll ke section cek-bansos
|
||||
} else {
|
||||
// Jika tidak ketemu, kirim pesan error
|
||||
return redirect()->back()
|
||||
->with('error_pencarian', 'Maaf, NIK ' . $nik . ' belum terdaftar atau belum masuk dalam tahap perhitungan periode ini.')
|
||||
->withFragment('cek-bansos');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Pengumuman;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class PengumumanController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$pengumumans = Pengumuman::latest()->get();
|
||||
return view('pengumuman.index', compact('pengumumans'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('pengumuman.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'judul' => 'required|string|max:255',
|
||||
'deskripsi' => 'nullable|string',
|
||||
'foto' => 'required|image|mimes:jpeg,png,jpg|max:2048',
|
||||
'status' => 'required|in:aktif,nonaktif'
|
||||
]);
|
||||
|
||||
// Proses upload foto
|
||||
$fotoPath = $request->file('foto')->store('pengumuman', 'public');
|
||||
|
||||
Pengumuman::create([
|
||||
'judul' => $request->judul,
|
||||
'deskripsi' => $request->deskripsi,
|
||||
'foto' => $fotoPath,
|
||||
'status' => $request->status,
|
||||
]);
|
||||
|
||||
return redirect()->route('pengumuman.index')->with('success', 'Data pengumuman berhasil ditambahkan!');
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$pengumuman = Pengumuman::findOrFail($id);
|
||||
return view('pengumuman.edit', compact('pengumuman'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$pengumuman = Pengumuman::findOrFail($id);
|
||||
|
||||
$request->validate([
|
||||
'judul' => 'required|string|max:255',
|
||||
'deskripsi' => 'nullable|string',
|
||||
'foto' => 'nullable|image|mimes:jpeg,png,jpg|max:2048', // Nullable karena foto tidak harus diganti
|
||||
'status' => 'required|in:aktif,nonaktif'
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'judul' => $request->judul,
|
||||
'deskripsi' => $request->deskripsi,
|
||||
'status' => $request->status,
|
||||
];
|
||||
|
||||
// Jika user mengunggah foto baru
|
||||
if ($request->hasFile('foto')) {
|
||||
// Hapus foto lama
|
||||
if (Storage::disk('public')->exists($pengumuman->foto)) {
|
||||
Storage::disk('public')->delete($pengumuman->foto);
|
||||
}
|
||||
// Simpan foto baru
|
||||
$data['foto'] = $request->file('foto')->store('pengumuman', 'public');
|
||||
}
|
||||
|
||||
$pengumuman->update($data);
|
||||
|
||||
return redirect()->route('pengumuman.index')->with('success', 'Data pengumuman berhasil diperbarui!');
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$pengumuman = Pengumuman::findOrFail($id);
|
||||
|
||||
// Hapus foto dari storage
|
||||
if (Storage::disk('public')->exists($pengumuman->foto)) {
|
||||
Storage::disk('public')->delete($pengumuman->foto);
|
||||
}
|
||||
|
||||
$pengumuman->delete();
|
||||
|
||||
return redirect()->route('pengumuman.index')->with('success', 'Pengumuman berhasil dihapus!');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,668 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Kriteria;
|
||||
use App\Models\Pengaturan;
|
||||
use App\Models\Perbandingan;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PerbandinganController extends Controller
|
||||
{
|
||||
/**
|
||||
* ==============================================================================
|
||||
* FUNGSI 1: INDEX()
|
||||
* Fungsi ini bertugas menyiapkan data untuk ditampilkan di halaman form kuesioner.
|
||||
* ==============================================================================
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// Variabel $kriterias mengambil seluruh data kriteria dari database, diurutkan berdasarkan kodenya (C1, C2, dst).
|
||||
$kriterias = Kriteria::orderBy('kode', 'asc')->get();
|
||||
|
||||
// Variabel $allData mengambil semua riwayat perbandingan yang sudah pernah diisi oleh pakar sebelumnya.
|
||||
$allData = Perbandingan::all();
|
||||
|
||||
// Variabel $pairs adalah array kosong yang akan kita isi dengan pasangan kriteria.
|
||||
// TIPS SIDANG: Sistem menggunakan algoritma Kombinatorial untuk memasangkan kriteria secara otomatis.
|
||||
// Jika ada Kriteria A, B, dan C, sistem akan membuat pasangan: A-B, A-C, dan B-C.
|
||||
$pairs = [];
|
||||
$n = count($kriterias); // Menghitung total kriteria yang ada
|
||||
|
||||
// Looping pertama ($i) menentukan kriteria di sisi KIRI
|
||||
for ($i = 0; $i < $n; $i++) {
|
||||
// Looping kedua ($j) menentukan kriteria di sisi KANAN.
|
||||
// Kenapa $j = $i + 1? Agar Kriteria A tidak dipasangkan dengan dirinya sendiri (A-A),
|
||||
// dan mencegah duplikasi terbalik (jika sudah ada A-B, tidak perlu buat B-A di kuesioner).
|
||||
for ($j = $i + 1; $j < $n; $j++) {
|
||||
$pairs[] = [
|
||||
'kiri' => $kriterias[$i],
|
||||
'kanan' => $kriterias[$j],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Variabel $existingPakar mengecek ke database, pakar nomor berapa saja yang sudah mengisi kuesioner.
|
||||
$existingPakar = Perbandingan::distinct()->pluck('pakar_ke')->toArray();
|
||||
|
||||
// Jika database masih kosong (belum ada yang mengisi sama sekali), default-kan ke Pakar 1.
|
||||
if (empty($existingPakar)) {
|
||||
$existingPakar = [1];
|
||||
} else {
|
||||
// Jika sudah ada pakar (misal pakar 2 dan 3), tapi pakar 1 tidak ada, tambahkan angka 1 di urutan paling depan.
|
||||
if (! in_array(1, $existingPakar)) {
|
||||
array_unshift($existingPakar, 1);
|
||||
}
|
||||
}
|
||||
sort($existingPakar); // Mengurutkan nomor pakar dari terkecil ke terbesar
|
||||
|
||||
// Mengambil kode PIN keamanan dari database agar tidak sembarang orang bisa input kuesioner.
|
||||
// Jika di database tidak ada PIN, default-nya adalah '123456'.
|
||||
$pengaturan = Pengaturan::where('nama_pengaturan', 'pin_pakar')->first();
|
||||
$pinSistem = $pengaturan ? $pengaturan->nilai_pengaturan : '123456';
|
||||
|
||||
// Mengirim semua variabel yang sudah diolah di atas ke tampilan layar (View).
|
||||
return view('perhitungan.index', compact('kriterias', 'pairs', 'existingPakar', 'allData', 'pinSistem'));
|
||||
}
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* FUNGSI 2: HITUNG()
|
||||
* Fungsi ini bertugas menerima data yang disubmit dari form kuesioner,
|
||||
* menyimpannya ke database, lalu memicu perhitungan ulang bobot Fuzzy AHP.
|
||||
* ==============================================================================
|
||||
*/
|
||||
public function hitung(Request $request)
|
||||
{
|
||||
// 1. Validasi PIN Keamanan
|
||||
$pengaturan = Pengaturan::where('nama_pengaturan', 'pin_pakar')->first();
|
||||
$pinSistem = $pengaturan ? $pengaturan->nilai_pengaturan : '123456';
|
||||
|
||||
// Jika PIN yang dimasukkan user tidak sama dengan PIN sistem, tolak dan kembalikan ke halaman sebelumnya.
|
||||
if ($request->input('pin_rahasia') !== $pinSistem) {
|
||||
return redirect()->back()->with('error', 'Akses Ditolak! PIN Keamanan salah.');
|
||||
}
|
||||
|
||||
// 2. Menangkap inputan dari form kuesioner
|
||||
$pakarKe = $request->input('pakar_ke'); // Nomor seri pakar (misal: Pakar 1)
|
||||
$kiriIds = $request->input('kiri_id'); // Kumpulan ID kriteria sisi kiri
|
||||
$kananIds = $request->input('kanan_id'); // Kumpulan ID kriteria sisi kanan
|
||||
$nilaiSkalas = $request->input('nilai_skala'); // Kumpulan angka skala 1-9 yang dipilih pakar
|
||||
|
||||
// ====================================================================
|
||||
// TAMBAHAN: CEK KONSISTENSI (CR) SEBELUM SIMPAN
|
||||
// ====================================================================
|
||||
$kriteriaIds = Kriteria::orderBy('kode', 'asc')->pluck('id')->toArray();
|
||||
$n = count($kriteriaIds);
|
||||
$matrixTemp = array_fill(0, $n, array_fill(0, $n, 1.0));
|
||||
$idToIndex = array_flip($kriteriaIds);
|
||||
|
||||
foreach ($kiriIds as $index => $kiriId) {
|
||||
$i = $idToIndex[$kiriId];
|
||||
$j = $idToIndex[$kananIds[$index]];
|
||||
$val = (float) $nilaiSkalas[$index];
|
||||
$matrixTemp[$i][$j] = $val;
|
||||
$matrixTemp[$j][$i] = 1.0 / $val;
|
||||
}
|
||||
|
||||
$nilaiCR = $this->checkConsistency($matrixTemp, $n);
|
||||
|
||||
// Jika tidak konsisten (> 10%), tolak data!
|
||||
if ($nilaiCR > 0.10) {
|
||||
$crPersen = round($nilaiCR * 100, 2);
|
||||
return redirect()->back()->with('error', "Gagal! Data Pakar $pakarKe Tidak Konsisten (CR = $crPersen%). Silakan perbaiki perbandingan.");
|
||||
}
|
||||
|
||||
// selesai gaes hadu pusing, kalau bisa memilih ulang sepertinya akan membangun si saja daripada rumus
|
||||
|
||||
// 3. Menyimpan ke database menggunakan DB::transaction
|
||||
// TIPS SIDANG: Database Transaction menjamin integritas data. Jika sistem mati di tengah proses simpan,
|
||||
// seluruh data yang sedang diproses akan di-Rollback (dibatalkan), sehingga tidak ada data yang masuk setengah-setengah.
|
||||
DB::transaction(function () use ($pakarKe, $kiriIds, $kananIds, $nilaiSkalas) {
|
||||
foreach ($kiriIds as $index => $kiriId) {
|
||||
// updateOrCreate berarti: Kalau data sudah ada (berdasarkan pakar, kriteria kiri & kanan), update nilainya.
|
||||
// Kalau datanya belum ada, buat baris data baru di tabel perbandingan.
|
||||
Perbandingan::updateOrCreate(
|
||||
[
|
||||
'pakar_ke' => $pakarKe,
|
||||
'kriteria_kiri_id' => $kiriId,
|
||||
'kriteria_kanan_id' => $kananIds[$index],
|
||||
],
|
||||
['nilai_skala' => $nilaiSkalas[$index]]
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Setelah data berhasil disimpan, otomatis panggil fungsi perhitungan matriks Fuzzy AHP
|
||||
$this->updateWeights();
|
||||
|
||||
// Kembalikan pengguna ke halaman kuesioner dengan pesan sukses
|
||||
return redirect()->back()->with('success', "Data Pakar $pakarKe berhasil disimpan & Bobot diperbarui!");
|
||||
}
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* FUNGSI 3: UPDATE WEIGHTS() - JANTUNG ALGORITMA FUZZY AHP
|
||||
* Fungsi ini melakukan perhitungan matematis penuh untuk mencari Bobot Global kriteria.
|
||||
* ==============================================================================
|
||||
*/
|
||||
private function updateWeights()
|
||||
{
|
||||
$kriterias = Kriteria::orderBy('kode', 'asc')->get();
|
||||
$ids = $kriterias->pluck('id')->toArray(); // Mengambil kumpulan ID kriteria saja
|
||||
$allData = Perbandingan::all();
|
||||
|
||||
// Jika database perbandingan masih kosong, set semua bobot jadi 0 dan hentikan proses.
|
||||
if ($allData->isEmpty()) {
|
||||
Kriteria::query()->update(['bobot_global' => 0]);
|
||||
return;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// TAHAP 1: MEMBENTUK MATRIKS KONSENSUS MULTI-PAKAR (GEOMETRIC MEAN)
|
||||
// -------------------------------------------------------------------------
|
||||
$matrixConsensus = [];
|
||||
foreach ($ids as $i) { // $i mewakili Baris
|
||||
foreach ($ids as $j) { // $j mewakili Kolom
|
||||
|
||||
// Jika Baris dan Kolom adalah kriteria yang sama (misal C1 vs C1), nilainya mutlak 1 (1.0, 1.0, 1.0)
|
||||
if ($i == $j) {
|
||||
$matrixConsensus[$i][$j] = [1.0, 1.0, 1.0];
|
||||
continue; // Lanjut ke iterasi berikutnya
|
||||
}
|
||||
|
||||
// Ambil semua nilai dari seluruh pakar yang membandingkan Kriteria i (kiri) vs Kriteria j (kanan)
|
||||
$scores = $allData->where('kriteria_kiri_id', $i)
|
||||
->where('kriteria_kanan_id', $j)
|
||||
->pluck('nilai_skala')->toArray();
|
||||
|
||||
// Jika datanya ketemu (diinput searah oleh pakar):
|
||||
if (count($scores) > 0) {
|
||||
// RUMUS GEOMETRIC MEAN: Akar pangkat n dari (x1 * x2 * ... * xn)
|
||||
// pow() adalah fungsi pangkat. Di sini kita memangkatkan total kali (array_product) dengan 1/jumlah_pakar (count).
|
||||
$geoMeanValue = pow(array_product($scores), 1 / count($scores));
|
||||
|
||||
// Langsung ubah nilai Geometric Mean menjadi nilai rentang Fuzzy (TFN)
|
||||
$matrixConsensus[$i][$j] = $this->mapToTfn($geoMeanValue);
|
||||
|
||||
// Jika datanya tidak ketemu, berarti kita sedang memproses area matriks kebalikan (Diagonal Bawah)
|
||||
} else {
|
||||
// Cari data perbandingan dengan urutan terbalik (j vs i)
|
||||
$revScores = $allData->where('kriteria_kiri_id', $j)
|
||||
->where('kriteria_kanan_id', $i)
|
||||
->pluck('nilai_skala')->toArray();
|
||||
|
||||
if (count($revScores) > 0) {
|
||||
// Hitung Geometric Mean dari nilai kebalikan
|
||||
$geoMeanRev = pow(array_product($revScores), 1 / count($revScores));
|
||||
$tfnRev = $this->mapToTfn($geoMeanRev);
|
||||
|
||||
// RUMUS INVERS TFN: (1/Upper, 1/Medium, 1/Lower)
|
||||
// Posisi Lower dan Upper ditukar letaknya.
|
||||
$matrixConsensus[$i][$j] = [
|
||||
1 / $tfnRev[2],
|
||||
1 / $tfnRev[1],
|
||||
1 / $tfnRev[0]
|
||||
];
|
||||
} else {
|
||||
// Jaring pengaman jika data benar-benar tidak ada
|
||||
$matrixConsensus[$i][$j] = [1.0, 1.0, 1.0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// TAHAP 2: HITUNG NILAI SINTESIS EXTENT (Si)
|
||||
// -------------------------------------------------------------------------
|
||||
$rowSums = []; // Untuk menyimpan total penjumlahan horizontal (per baris)
|
||||
$totalSum = [0.0, 0.0, 0.0]; // Untuk menyimpan total keseluruhan dari semua elemen matriks
|
||||
|
||||
foreach ($ids as $i) {
|
||||
$rSum = [0.0, 0.0, 0.0];
|
||||
foreach ($ids as $j) {
|
||||
// Menjumlahkan nilai Lower (indeks 0), Medium (indeks 1), Upper (indeks 2) per baris
|
||||
$rSum[0] += $matrixConsensus[$i][$j][0];
|
||||
$rSum[1] += $matrixConsensus[$i][$j][1];
|
||||
$rSum[2] += $matrixConsensus[$i][$j][2];
|
||||
}
|
||||
$rowSums[$i] = $rSum;
|
||||
|
||||
// Tambahkan total baris tadi ke grand total keseluruhan matriks
|
||||
$totalSum[0] += $rSum[0];
|
||||
$totalSum[1] += $rSum[1];
|
||||
$totalSum[2] += $rSum[2];
|
||||
}
|
||||
|
||||
$si = [];
|
||||
foreach ($ids as $i) {
|
||||
// RUMUS SINTESIS (Si): Total Baris dikali Invers dari Grand Total Matriks.
|
||||
// Karena ini Invers, indeks Grand Total-nya dibalik (2, 1, 0).
|
||||
// TIPS SIDANG: Jelaskan bahwa di sini kita mempertahankan tipe data float tanpa dibulatkan
|
||||
// agar tidak terjadi Compounding Error (Penumpukan Galat/Salah Hitung).
|
||||
$si[$i] = [
|
||||
$rowSums[$i][0] * (1 / $totalSum[2]), // Lower baris / Upper total
|
||||
$rowSums[$i][1] * (1 / $totalSum[1]), // Medium baris / Medium total
|
||||
$rowSums[$i][2] * (1 / $totalSum[0]), // Upper baris / Lower total
|
||||
];
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// TAHAP 3: HITUNG DERAJAT KEMUNGKINAN (V Matrix) & NILAI MINIMUM (d')
|
||||
// -------------------------------------------------------------------------
|
||||
$vMatrix = [];
|
||||
foreach ($ids as $i) {
|
||||
foreach ($ids as $j) {
|
||||
// Membandingkan probabilitas Si milik kriteria i dengan Si milik kriteria j
|
||||
$vMatrix[$i][$j] = ($i == $j) ? 1.0 : $this->calculateV($si[$i], $si[$j]);
|
||||
}
|
||||
}
|
||||
|
||||
$dPrime = []; // dPrime adalah nilai Bobot yang belum dinormalisasi
|
||||
foreach ($ids as $i) {
|
||||
$vals = [];
|
||||
foreach ($ids as $j) {
|
||||
if ($i !== $j) {
|
||||
$vals[] = $vMatrix[$i][$j];
|
||||
}
|
||||
}
|
||||
// RUMUS CHANG: Kita cari nilai Minimum (Terkecil) dari hasil perbandingan irisan tadi.
|
||||
$dPrime[$i] = count($vals) > 0 ? min($vals) : 0.0;
|
||||
}
|
||||
|
||||
$sumDPrime = array_sum($dPrime); // Menjumlahkan seluruh nilai dPrime
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// TAHAP 4: NORMALISASI BOBOT & SIMPAN KE DATABASE
|
||||
// -------------------------------------------------------------------------
|
||||
foreach ($ids as $id) {
|
||||
// RUMUS NORMALISASI: Nilai dPrime kriteria tersebut dibagi Total dPrime keseluruhan.
|
||||
// Hasil normalisasi ini pasti jika dijumlahkan semuanya akan bernilai 1.
|
||||
$finalWeight = ($sumDPrime > 0) ? ($dPrime[$id] / $sumDPrime) : 0.0;
|
||||
|
||||
// Menyimpan hasil akhir (Bobot Global) ke database kriteria.
|
||||
// Dibulatkan 6 angka di belakang koma untuk akurasi tinggi di database.
|
||||
Kriteria::where('id', $id)->update(['bobot_global' => round($finalWeight, 4)]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* FUNGSI RUMUS V: DERAJAT KEMUNGKINAN (Degree of Possibility)
|
||||
* ==============================================================================
|
||||
* Berfungsi menghitung seberapa besar kemungkinan rentang Fuzzy (Si baris)
|
||||
* lebih besar dari rentang Fuzzy (Si kolom).
|
||||
*/
|
||||
private function calculateV(array $si_baris, array $si_kolom): float
|
||||
{
|
||||
[$l1, $m1, $u1] = $si_kolom; // Nilai M1 (Lower, Medium, Upper)
|
||||
[$l2, $m2, $u2] = $si_baris; // Nilai M2 (Lower, Medium, Upper)
|
||||
|
||||
// Jika titik Puncak (Medium) baris lebih besar/sama dengan kolom, probabilitasnya mutlak 100% (1.0)
|
||||
if ($m2 >= $m1) return 1.0;
|
||||
|
||||
// Jika titik paling bawah kolom lebih besar dari titik paling atas baris, probabilitasnya 0% (0.0)
|
||||
if ($l1 >= $u2) return 0.0;
|
||||
|
||||
// Jika saling bersinggungan/beririsan, hitung luas irisan segitiganya.
|
||||
$num = $l1 - $u2; // Pembilang
|
||||
$den = ($m2 - $u2) - ($m1 - $l1); // Penyebut
|
||||
|
||||
// Cegah error pembagian dengan nol (Division by Zero)
|
||||
return ($den == 0) ? 0.0 : ($num / $den);
|
||||
}
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* FUNGSI MAPPING TFN (Triangular Fuzzy Number)
|
||||
* ==============================================================================
|
||||
* Berfungsi mengonversi angka mutlak skala 1-9 menjadi rentang keraguan (TFN).
|
||||
*/
|
||||
private function mapToTfn($val): array
|
||||
{
|
||||
// Kamus Skala Dasar TFN
|
||||
$baseTFN = [
|
||||
1 => [1.0, 1.0, 1.0], 2 => [0.5, 1.0, 1.5], 3 => [1.0, 1.5, 2.0],
|
||||
4 => [1.5, 2.0, 2.5], 5 => [2.0, 2.5, 3.0], 6 => [2.5, 3.0, 3.5],
|
||||
7 => [3.0, 3.5, 4.0], 8 => [3.5, 4.0, 4.5], 9 => [4.0, 4.5, 4.5],
|
||||
];
|
||||
|
||||
// Jika nilainya mendekati 1 (skala sama penting), kembalikan kemutlakan 1.0
|
||||
if ($val >= 0.99 && $val <= 1.01) return $baseTFN[1];
|
||||
|
||||
if ($val > 1) {
|
||||
// Jika nilai rasio positif (kiri lebih penting dari kanan), bulatkan nilainya untuk mencocokkan ke kamus dasar.
|
||||
$key = min(9, (int) round($val));
|
||||
return $baseTFN[$key];
|
||||
} else {
|
||||
// Jika nilai rasio desimal/negatif (kanan lebih penting dari kiri), dicari invers-nya dulu (1 / nilai)
|
||||
$originalKey = max(1, min(9, (int) round(1 / $val)));
|
||||
$tfn = $baseTFN[$originalKey];
|
||||
|
||||
// Kembalikan dalam bentuk Invers Fuzzy (dibalik posisinya)
|
||||
return [1 / $tfn[2], 1 / $tfn[1], 1 / $tfn[0]];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* FUNGSI KONVERSI SKALA 1000 (LARGEST REMAINDER METHOD)
|
||||
* ==============================================================================
|
||||
* Mengubah bobot desimal (contoh: 0.33) menjadi angka bulat skala ribuan (contoh: 330)
|
||||
* yang total keseluruhannya dipastikan akurat 1000.
|
||||
*/
|
||||
private function toBobot1000(array $weights): array
|
||||
{
|
||||
$keys = array_keys($weights);
|
||||
$float = array_map(fn($w) => $w * 1000, $weights); // Mengkalikan bobot asli dengan 1000
|
||||
|
||||
$result = [];
|
||||
|
||||
// 1. Bulatkan nilai hasil kali ke bawah menggunakan floor()
|
||||
// Fungsi max(1, ...) memastikan bahwa kriteria sekecil apapun tidak akan menjadi 0.
|
||||
// Ini melindungi parameter sistem yang berprioritas rendah agar tetap valid.
|
||||
foreach ($float as $key => $val) {
|
||||
$result[$key] = max(1, floor($val));
|
||||
}
|
||||
|
||||
// 2. Cek apakah totalnya sudah 1000? Cari tahu selisih kekurangannya.
|
||||
$remainder = 1000 - (int) array_sum($result);
|
||||
|
||||
if ($remainder > 0) {
|
||||
$sortedKeys = $keys;
|
||||
|
||||
// 3. Urutkan kriteria berdasarkan siapa yang punya angka pecahan desimal terbesar di belakang koma.
|
||||
usort($sortedKeys, function ($a, $b) use ($float) {
|
||||
$decA = $float[$a] - floor($float[$a]);
|
||||
$decB = $float[$b] - floor($float[$b]);
|
||||
return $decB <=> $decA; // Urutkan menurun (Descending)
|
||||
});
|
||||
|
||||
// 4. Bagikan poin sisa (kekurangan) satu per satu kepada kriteria yang menduduki peringkat desimal terbesar.
|
||||
for ($k = 0; $k < $remainder; $k++) {
|
||||
$result[$sortedKeys[$k]] += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Pastikan format akhirnya adalah Integer (angka bulat tanpa koma)
|
||||
return array_map('intval', $result);
|
||||
}
|
||||
|
||||
|
||||
// tahun cek ahp
|
||||
private function checkConsistency($matrix, $n)
|
||||
{
|
||||
$RI = [1 => 0, 2 => 0, 3 => 0.58, 4 => 0.90, 5 => 1.12, 6 => 1.24, 7 => 1.32, 8 => 1.41, 9 => 1.45];
|
||||
if ($n < 3) return 0.0;
|
||||
|
||||
$colSum = array_fill(0, $n, 0);
|
||||
foreach ($matrix as $row) { foreach ($row as $j => $val) { $colSum[$j] += $val; } }
|
||||
|
||||
$priorityVector = [];
|
||||
foreach ($matrix as $i => $row) {
|
||||
$rowSum = 0;
|
||||
foreach ($row as $j => $val) {
|
||||
// JARING PENGAMAN: Mencegah error "Division by Zero"
|
||||
$normalizedVal = ($colSum[$j] == 0) ? 0 : ($val / $colSum[$j]);
|
||||
$rowSum += $normalizedVal;
|
||||
}
|
||||
$priorityVector[$i] = $rowSum / $n;
|
||||
}
|
||||
|
||||
$lambdaMax = 0;
|
||||
foreach ($colSum as $j => $sum) { $lambdaMax += ($sum * $priorityVector[$j]); }
|
||||
|
||||
$ci = ($lambdaMax - $n) / ($n - 1);
|
||||
return $ci / $RI[$n];
|
||||
}
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* FUNGSI HAPUS DATA PAKAR
|
||||
* ==============================================================================
|
||||
*/
|
||||
public function hapusPakar(Request $request)
|
||||
{
|
||||
$pakarDihapus = $request->input('pakar_dihapus');
|
||||
|
||||
// Mencegah Pakar 1 (pakar utama) untuk dihapus agar sistem tidak error karena kosong
|
||||
if ($pakarDihapus == 1) {
|
||||
return redirect()->back()->with('error', 'Pakar 1 tidak dapat dihapus.');
|
||||
}
|
||||
|
||||
// Hapus data dari tabel perbandingan
|
||||
Perbandingan::where('pakar_ke', $pakarDihapus)->delete();
|
||||
|
||||
// Hitung ulang bobot setelah datanya berkurang
|
||||
$this->updateWeights();
|
||||
|
||||
return redirect()->back()->with('success', "Data Pakar $pakarDihapus dihapus.");
|
||||
}
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* FUNGSI DETAIL() - UNTUK TAMPILAN LAPORAN
|
||||
* ==============================================================================
|
||||
* TIPS SIDANG: Fungsi ini isinya adalah replika persis (copy-paste logika) dari
|
||||
* fungsi updateWeights(). Bedanya, updateWeights() memproses secara rahasia
|
||||
* di belakang layar (background) untuk disimpan ke database.
|
||||
* Sedangkan fungsi detail() bertujuan menangkap setiap langkah prosesnya
|
||||
* sehingga penguji bisa melihat step-by-step perhitungannya.
|
||||
*/
|
||||
/**
|
||||
* ==============================================================================
|
||||
* FUNGSI DETAIL() - UNTUK TAMPILAN LAPORAN (WEB & PDF)
|
||||
* ==============================================================================
|
||||
* Fungsi ini menangkap setiap langkah matematis Fuzzy AHP untuk transparansi data.
|
||||
*/
|
||||
public function detail(Request $request) // Tambahkan parameter Request $request
|
||||
{
|
||||
// 1. DATA DASAR
|
||||
// Mengambil semua data kriteria dan kuesioner dari database
|
||||
$kriterias = Kriteria::orderBy('kode', 'asc')->get();
|
||||
$kodes = $kriterias->pluck('kode')->toArray(); // Daftar kode kriteria ['C1', 'C2', ...]
|
||||
$ids = $kriterias->pluck('id')->toArray(); // Daftar ID kriteria [1, 2, ...]
|
||||
$allData = Perbandingan::all();
|
||||
|
||||
// Cek jika kuesioner belum diisi sama sekali
|
||||
if ($allData->isEmpty()) {
|
||||
return redirect()->route('perbandingan.index')->with('error', 'Data masih kosong!');
|
||||
}
|
||||
|
||||
// 2. MAPPING TFN (FUZZIFIKASI)
|
||||
// Mengonversi nilai skala 1-9 menjadi array Fuzzy (Triangular Fuzzy Number)
|
||||
$dataKuesioner = $allData->map(function ($item) {
|
||||
$item->tfn = $this->mapToTfn($item->nilai_skala);
|
||||
return $item;
|
||||
});
|
||||
|
||||
// 3. GENERATE PAIRS (Untuk Tabel Ringkasan PDF)
|
||||
// Membuat pasangan perbandingan secara dinamis untuk ditampilkan di laporan
|
||||
$dynamicPairs = [];
|
||||
$n = count($kriterias);
|
||||
for ($i = 0; $i < $n; $i++) {
|
||||
for ($j = $i + 1; $j < $n; $j++) {
|
||||
$dynamicPairs[] = [
|
||||
'kiri_kode' => $kriterias[$i]->kode,
|
||||
'kiri_nama' => $kriterias[$i]->nama,
|
||||
'kanan_kode' => $kriterias[$j]->kode,
|
||||
'kanan_nama' => $kriterias[$j]->nama,
|
||||
];
|
||||
}
|
||||
}
|
||||
$groupedKuesioner = $allData->groupBy('pakar_ke');
|
||||
|
||||
// ========================================================================
|
||||
// TAHAP 1: MATRIKS CRISP (GEOMETRIC MEAN - KONSENSUS MULTI-PAKAR)
|
||||
// ========================================================================
|
||||
$crispMatrix = [];
|
||||
foreach ($ids as $i) {
|
||||
foreach ($ids as $j) {
|
||||
$kodeI = $kriterias->where('id', $i)->first()->kode;
|
||||
$kodeJ = $kriterias->where('id', $j)->first()->kode;
|
||||
|
||||
if ($i == $j) {
|
||||
$crispMatrix[$kodeI][$kodeJ] = 1.0;
|
||||
continue;
|
||||
}
|
||||
|
||||
$scores = $allData->where('kriteria_kiri_id', $i)->where('kriteria_kanan_id', $j)->pluck('nilai_skala')->toArray();
|
||||
|
||||
if (count($scores) > 0) {
|
||||
// Rata-rata ukur jika data searah
|
||||
$crispMatrix[$kodeI][$kodeJ] = pow(array_product($scores), 1 / count($scores));
|
||||
} else {
|
||||
// Kebalikan (1/GM) jika data berlawanan arah
|
||||
$revScores = $allData->where('kriteria_kiri_id', $j)->where('kriteria_kanan_id', $i)->pluck('nilai_skala')->toArray();
|
||||
$crispMatrix[$kodeI][$kodeJ] = count($revScores) > 0 ? 1 / pow(array_product($revScores), 1 / count($revScores)) : 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// ---> TAMBAHAN BARU: UJI KONSISTENSI AHP (EIGEN, CI, CR) <---
|
||||
// ========================================================================
|
||||
$nKriteria = count($kodes);
|
||||
$colSums = [];
|
||||
$priorityVector = [];
|
||||
$lambdaMax = 0;
|
||||
$ci = 0;
|
||||
$cr = 0;
|
||||
$riBaku = [1=>0.00, 2=>0.00, 3=>0.58, 4=>0.90, 5=>1.12, 6=>1.24, 7=>1.32, 8=>1.41, 9=>1.45];
|
||||
$ri = $riBaku[$nKriteria] ?? 1.45;
|
||||
|
||||
// 1. Hitung total per kolom dari Matriks Crisp
|
||||
foreach ($kodes as $j) {
|
||||
$sum = 0;
|
||||
foreach ($kodes as $i) {
|
||||
$sum += $crispMatrix[$i][$j];
|
||||
}
|
||||
$colSums[$j] = $sum;
|
||||
}
|
||||
|
||||
// 2. Normalisasi & Cari Nilai Eigen (Priority Vector)
|
||||
foreach ($kodes as $i) {
|
||||
$rowSum = 0;
|
||||
foreach ($kodes as $j) {
|
||||
$normalizedVal = ($colSums[$j] == 0) ? 0 : ($crispMatrix[$i][$j] / $colSums[$j]);
|
||||
$rowSum += $normalizedVal;
|
||||
}
|
||||
$priorityVector[$i] = $rowSum / $nKriteria;
|
||||
}
|
||||
|
||||
// 3. Cari Lambda Max
|
||||
foreach ($kodes as $j) {
|
||||
$lambdaMax += ($colSums[$j] * $priorityVector[$j]);
|
||||
}
|
||||
|
||||
// 4. Hitung CI dan CR
|
||||
if ($nKriteria > 1) {
|
||||
$ci = ($lambdaMax - $nKriteria) / ($nKriteria - 1);
|
||||
$cr = ($ri > 0) ? ($ci / $ri) : 0;
|
||||
}
|
||||
|
||||
// tutup
|
||||
|
||||
// ========================================================================
|
||||
// TAHAP 2: MATRIKS FUZZY (TFN)
|
||||
// ========================================================================
|
||||
$matrix = [];
|
||||
foreach ($kodes as $i) {
|
||||
foreach ($kodes as $j) {
|
||||
if (array_search($i, $kodes) <= array_search($j, $kodes)) {
|
||||
$matrix[$i][$j] = $this->mapToTfn($crispMatrix[$i][$j]);
|
||||
} else {
|
||||
$tfnAtas = $matrix[$j][$i];
|
||||
// Invers Fuzzy: (1/u, 1/m, 1/l)
|
||||
$matrix[$i][$j] = [1 / $tfnAtas[2], 1 / $tfnAtas[1], 1 / $tfnAtas[0]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// TAHAP 3: NILAI SINTESIS FUZZY (Si)
|
||||
// ========================================================================
|
||||
$rowSums = [];
|
||||
$totalSum = [0.0, 0.0, 0.0];
|
||||
foreach ($kodes as $i) {
|
||||
$rSum = [0.0, 0.0, 0.0];
|
||||
foreach ($kodes as $j) {
|
||||
$rSum[0] += $matrix[$i][$j][0];
|
||||
$rSum[1] += $matrix[$i][$j][1];
|
||||
$rSum[2] += $matrix[$i][$j][2];
|
||||
}
|
||||
$rowSums[$i] = $rSum;
|
||||
$totalSum[0] += $rSum[0];
|
||||
$totalSum[1] += $rSum[1];
|
||||
$totalSum[2] += $rSum[2];
|
||||
}
|
||||
|
||||
$si = [];
|
||||
foreach ($kodes as $i) {
|
||||
$si[$i] = [
|
||||
$rowSums[$i][0] * (1 / $totalSum[2]),
|
||||
$rowSums[$i][1] * (1 / $totalSum[1]),
|
||||
$rowSums[$i][2] * (1 / $totalSum[0]),
|
||||
];
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// TAHAP 4: DERAJAT KEMUNGKINAN (V MATRIX) & d' (MINIMUM DEGREE)
|
||||
// ========================================================================
|
||||
$vMatrix = [];
|
||||
foreach ($kodes as $i) {
|
||||
foreach ($kodes as $j) {
|
||||
$vMatrix[$i][$j] = ($i == $j) ? 1.0 : $this->calculateV($si[$i], $si[$j]);
|
||||
}
|
||||
}
|
||||
|
||||
$dPrime = [];
|
||||
foreach ($kodes as $i) {
|
||||
$vals = [];
|
||||
foreach ($kodes as $j) {
|
||||
if ($i !== $j) { $vals[] = $vMatrix[$i][$j]; }
|
||||
}
|
||||
$dPrime[$i] = count($vals) > 0 ? min($vals) : 0.0;
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// TAHAP 5: NORMALISASI FINAL & SKALA 1000
|
||||
// ========================================================================
|
||||
$sumDPrime = array_sum($dPrime);
|
||||
$finalWeights = [];
|
||||
foreach ($kodes as $i) {
|
||||
$finalWeights[$i] = ($sumDPrime > 0) ? ($dPrime[$i] / $sumDPrime) : 0.0;
|
||||
}
|
||||
|
||||
// Konversi ke bobot bulat 1000 menggunakan Largest Remainder Method
|
||||
$bobot1000 = $this->toBobot1000($finalWeights);
|
||||
$pakarList = $allData->pluck('pakar_ke')->unique()->sort();
|
||||
|
||||
// ========================================================================
|
||||
// LOGIKA EXPORT PDF
|
||||
// ========================================================================
|
||||
if ($request->has('export') && $request->export == 'pdf') {
|
||||
// Memanggil View khusus PDF (Anda bisa membuat file perbandingan.pdf)
|
||||
$pdf = Pdf::loadView('perhitungan.pdf', compact(
|
||||
'crispMatrix', 'matrix', 'si', 'vMatrix', 'dPrime',
|
||||
'kodes', 'dataKuesioner', 'kriterias', 'pakarList',
|
||||
'finalWeights', 'bobot1000', 'dynamicPairs', 'groupedKuesioner',
|
||||
// Variabel Tambahan AHP:
|
||||
'colSums', 'priorityVector', 'lambdaMax', 'ci', 'cr', 'ri', 'nKriteria'
|
||||
))->setPaper('A4', 'landscape');
|
||||
|
||||
return $pdf->stream('Laporan_FAHP_Kriteria_Global.pdf');
|
||||
}
|
||||
|
||||
// Mengirimkan semua data langkah demi langkah tersebut ke file detail.blade.php
|
||||
return view('perhitungan.detail', compact(
|
||||
'crispMatrix', 'matrix', 'si', 'vMatrix', 'dPrime',
|
||||
'kodes', 'dataKuesioner', 'kriterias', 'pakarList',
|
||||
'finalWeights', 'bobot1000', 'dynamicPairs', 'groupedKuesioner',
|
||||
// Variabel Tambahan AHP:
|
||||
'colSums', 'priorityVector', 'lambdaMax', 'ci', 'cr', 'ri', 'nKriteria'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,647 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Kriteria;
|
||||
use App\Models\Pengaturan;
|
||||
use App\Models\PerbandinganSub;
|
||||
use App\Models\SubKriteria;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PerbandinganSubKriteriaController extends Controller
|
||||
{
|
||||
/**
|
||||
* ==============================================================================
|
||||
* FUNGSI 1: INDEX()
|
||||
* Bertugas menampilkan daftar kriteria induk, dan jika sebuah kriteria dipilih,
|
||||
* sistem akan membuatkan form kuesioner pasangan (pairwise) untuk anak-anaknya (Sub-Kriteria).
|
||||
* ==============================================================================
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
// 1. Ambil daftar kriteria induk untuk dropdown pilihan
|
||||
$kriterias = Kriteria::orderBy('kode', 'asc')->get();
|
||||
// Tangkap ID kriteria induk yang sedang dipilih oleh user di layar
|
||||
$selectedKriteriaId = $request->input('kriteria_id');
|
||||
|
||||
$subKriterias = [];
|
||||
$pairs = [];
|
||||
$allData = [];
|
||||
|
||||
// Jika user sudah memilih kriteria induk di dropdown:
|
||||
if ($selectedKriteriaId) {
|
||||
// Ambil semua anak-anaknya (Sub-Kriteria) yang berinduk pada kriteria tersebut
|
||||
$subKriterias = SubKriteria::where('kriteria_id', $selectedKriteriaId)
|
||||
->orderBy('kode', 'asc')
|
||||
->get();
|
||||
|
||||
// 2. Tahap pembuatan pasangan Pairwise (Algoritma Kombinasi)
|
||||
// Sistem akan memasangkan setiap Sub-Kriteria secara otomatis.
|
||||
// Contoh: Sub S1 vs S2, S1 vs S3, S2 vs S3.
|
||||
$n = count($subKriterias);
|
||||
for ($i = 0; $i < $n; $i++) {
|
||||
for ($j = $i + 1; $j < $n; $j++) {
|
||||
$pairs[] = [
|
||||
'kiri' => $subKriterias[$i],
|
||||
'kanan' => $subKriterias[$j],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Ambil semua data jawaban kuesioner yang sudah tersimpan untuk sub-kriteria ini
|
||||
$allData = PerbandinganSub::with(['subKiri', 'subKanan'])
|
||||
->where('kriteria_id', $selectedKriteriaId)
|
||||
->get();
|
||||
}
|
||||
|
||||
// 3. Deteksi urutan pakar
|
||||
$existingPakar = PerbandinganSub::where('kriteria_id', $selectedKriteriaId)
|
||||
->distinct()
|
||||
->pluck('pakar_ke')
|
||||
->toArray();
|
||||
|
||||
if (empty($existingPakar)) {
|
||||
$existingPakar = [1]; // Jika belum ada sama sekali, set default Pakar 1
|
||||
}
|
||||
sort($existingPakar);
|
||||
|
||||
// 4. Ambil PIN keamanan dari database
|
||||
$pengaturan = Pengaturan::where('nama_pengaturan', 'pin_pakar')->first();
|
||||
$pinSistem = $pengaturan ? $pengaturan->nilai_pengaturan : '123456';
|
||||
|
||||
return view('perbandingan_sub.index', compact(
|
||||
'kriterias', 'selectedKriteriaId', 'subKriterias', 'pairs', 'existingPakar', 'allData', 'pinSistem'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* FUNGSI 2: SIMPAN()
|
||||
* Menerima kiriman form kuesioner, menyimpannya, lalu memicu perhitungan Fuzzy AHP.
|
||||
* ==============================================================================
|
||||
*/
|
||||
public function simpan(Request $request)
|
||||
{
|
||||
$pengaturan = Pengaturan::where('nama_pengaturan', 'pin_pakar')->first();
|
||||
$pinSistem = $pengaturan ? $pengaturan->nilai_pengaturan : '123456';
|
||||
|
||||
// Validasi PIN dulu
|
||||
if ($request->input('pin_rahasia') !== $pinSistem) {
|
||||
return redirect()->back()->with('error', 'Akses Ditolak! PIN Keamanan salah.');
|
||||
}
|
||||
|
||||
$pakarKe = $request->input('pakar_ke');
|
||||
$kriteriaId = $request->input('kriteria_id');
|
||||
$kiriIds = $request->input('sub_kiri_id');
|
||||
$kananIds = $request->input('sub_kanan_id');
|
||||
$nilaiSkalas= $request->input('nilai_skala');
|
||||
|
||||
if (! $kiriIds) {
|
||||
return redirect()->back()->with('error', 'Tidak ada data disimpan.');
|
||||
}
|
||||
|
||||
|
||||
// CEK KONSISTENSI (CR) SEBELUM SIMPAN
|
||||
|
||||
$subKriteriaIds = SubKriteria::where('kriteria_id', $kriteriaId)->orderBy('kode', 'asc')->pluck('id')->toArray();
|
||||
$n = count($subKriteriaIds);
|
||||
|
||||
// Buat matriks bayangan untuk dicek
|
||||
$matrixTemp = array_fill(0, $n, array_fill(0, $n, 1.0));
|
||||
$idToIndex = array_flip($subKriteriaIds);
|
||||
|
||||
foreach ($kiriIds as $index => $kiriId) {
|
||||
$i = $idToIndex[$kiriId];
|
||||
$j = $idToIndex[$kananIds[$index]];
|
||||
$val = (float) $nilaiSkalas[$index];
|
||||
$matrixTemp[$i][$j] = $val;
|
||||
$matrixTemp[$j][$i] = 1.0 / $val;
|
||||
}
|
||||
|
||||
$nilaiCR = $this->checkConsistency($matrixTemp, $n);
|
||||
|
||||
// Jika tidak konsisten (> 10%), tolak data!
|
||||
if ($nilaiCR > 0.10) {
|
||||
$crPersen = round($nilaiCR * 100, 2);
|
||||
return redirect()->back()->with('error', "Gagal! Data Pakar $pakarKe Tidak Konsisten (CR = $crPersen%). Silakan perbaiki perbandingan.");
|
||||
}
|
||||
// selesai cek lanjut ke database
|
||||
|
||||
// Gunakan Transaction agar kalau error di tengah jalan, database batal menyimpan (Rollback)
|
||||
DB::transaction(function () use ($pakarKe, $kriteriaId, $kiriIds, $kananIds, $nilaiSkalas) {
|
||||
foreach ($kiriIds as $index => $kiriId) {
|
||||
PerbandinganSub::updateOrCreate(
|
||||
[
|
||||
'pakar_ke' => $pakarKe,
|
||||
'kriteria_id' => $kriteriaId,
|
||||
'sub_kiri_id' => $kiriId,
|
||||
'sub_kanan_id' => $kananIds[$index],
|
||||
],
|
||||
['nilai_skala' => $nilaiSkalas[$index]]
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Pemicu perhitungan matematis Fuzzy AHP setelah data berhasil masuk
|
||||
$this->updateLocalWeights($kriteriaId);
|
||||
|
||||
return redirect()->back()->with('success', "Data Pakar $pakarKe berhasil disimpan.");
|
||||
}
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* FUNGSI 3: UPDATE LOCAL WEIGHTS (CORE FUZZY AHP)
|
||||
* TIPS SIDANG: Sistem menjaga akurasi dengan tidak melakukan pembulatan round()
|
||||
* selama proses menengah, untuk menghindari Compounding Error (Penumpukan Galat).
|
||||
* ==============================================================================
|
||||
*/
|
||||
private function updateLocalWeights($kriteriaId)
|
||||
{
|
||||
$subs = SubKriteria::where('kriteria_id', $kriteriaId)->get();
|
||||
$ids = $subs->pluck('id')->toArray();
|
||||
$n = count($ids);
|
||||
|
||||
$allData = PerbandinganSub::where('kriteria_id', $kriteriaId)->get();
|
||||
|
||||
// if ($allData->isEmpty() || count($ids) < 2) {
|
||||
// return;
|
||||
// }
|
||||
if ($n < 2 || $allData->isEmpty()) {
|
||||
SubKriteria::where('kriteria_id', $kriteriaId)
|
||||
->update(['bobot_lokal' => ($n == 1 ? 1.0 : 0)]);
|
||||
return;
|
||||
}
|
||||
|
||||
// TAHAP 1: KONSENSUS MULTI-PAKAR (GEOMETRIC MEAN)
|
||||
$matrixConsensus = [];
|
||||
foreach ($ids as $i) {
|
||||
foreach ($ids as $j) {
|
||||
if ($i == $j) {
|
||||
$matrixConsensus[$i][$j] = [1.0, 1.0, 1.0];
|
||||
continue;
|
||||
}
|
||||
|
||||
$scores = $allData->where('sub_kiri_id', $i)->where('sub_kanan_id', $j)->pluck('nilai_skala')->toArray();
|
||||
|
||||
if (count($scores) > 0) {
|
||||
// Rumus Rata-rata Geometrik (Akar pangkat n)
|
||||
$gm = pow(array_product($scores), 1 / count($scores));
|
||||
$matrixConsensus[$i][$j] = $this->mapToTfn($gm);
|
||||
} else {
|
||||
// Jika data ada di sisi sebaliknya (kanan vs kiri)
|
||||
$revScores = $allData->where('sub_kiri_id', $j)->where('sub_kanan_id', $i)->pluck('nilai_skala')->toArray();
|
||||
if (count($revScores) > 0) {
|
||||
$gmRev = pow(array_product($revScores), 1 / count($revScores));
|
||||
$tfnRev = $this->mapToTfn($gmRev);
|
||||
|
||||
// INVERS FUZZY: Dibalik urutannya (1/Upper, 1/Medium, 1/Lower).
|
||||
// Dibiarkan float murni tanpa di round()!
|
||||
$matrixConsensus[$i][$j] = [
|
||||
1 / $tfnRev[2],
|
||||
1 / $tfnRev[1],
|
||||
1 / $tfnRev[0]
|
||||
];
|
||||
} else {
|
||||
$matrixConsensus[$i][$j] = [1.0, 1.0, 1.0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TAHAP 2: NILAI SINTESIS FUZZY (Si)
|
||||
$rowSums = [];
|
||||
$totalSum = [0.0, 0.0, 0.0];
|
||||
|
||||
// 2A: Hitung total Baris (Row) dan Grand Total Matriks
|
||||
foreach ($ids as $i) {
|
||||
$rSum = [0.0, 0.0, 0.0];
|
||||
foreach ($ids as $j) {
|
||||
$rSum[0] += $matrixConsensus[$i][$j][0];
|
||||
$rSum[1] += $matrixConsensus[$i][$j][1];
|
||||
$rSum[2] += $matrixConsensus[$i][$j][2];
|
||||
}
|
||||
$rowSums[$i] = $rSum;
|
||||
$totalSum[0] += $rSum[0];
|
||||
$totalSum[1] += $rSum[1];
|
||||
$totalSum[2] += $rSum[2];
|
||||
}
|
||||
|
||||
// 2B: Hitung Si (Baris dikali Invers Grand Total)
|
||||
$si = [];
|
||||
foreach ($ids as $i) {
|
||||
// Dibiarkan presisi tinggi (float) tanpa round()
|
||||
$si[$i] = [
|
||||
$rowSums[$i][0] / $totalSum[2],
|
||||
$rowSums[$i][1] / $totalSum[1],
|
||||
$rowSums[$i][2] / $totalSum[0],
|
||||
];
|
||||
}
|
||||
|
||||
// TAHAP 3: DERAJAT KEMUNGKINAN (V Matrix)
|
||||
$vMatrix = [];
|
||||
foreach ($ids as $i) {
|
||||
foreach ($ids as $j) {
|
||||
// Menghitung probabilitas perpotongan area segitiga antar Fuzzy
|
||||
$vMatrix[$i][$j] = ($i == $j) ? 1.0 : $this->calculateV($si[$i], $si[$j]);
|
||||
}
|
||||
}
|
||||
|
||||
// TAHAP 4: MINIMUM DEGREE & NORMALISASI
|
||||
$dPrime = [];
|
||||
foreach ($ids as $i) {
|
||||
$vals = [];
|
||||
foreach ($ids as $j) {
|
||||
if ($j !== $i) {
|
||||
$vals[] = $vMatrix[$i][$j];
|
||||
}
|
||||
}
|
||||
// Mencari irisan terkecil
|
||||
$dPrime[$i] = count($vals) > 0 ? min($vals) : 0.0;
|
||||
}
|
||||
|
||||
$sumDPrime = array_sum($dPrime);
|
||||
|
||||
// Tahap Normalisasi agar total seluruh bobot bernilai 1.0
|
||||
foreach ($ids as $id) {
|
||||
$finalWeight = ($sumDPrime > 0) ? ($dPrime[$id] / $sumDPrime) : 0.0;
|
||||
// Simpan hasil akhir ke database dengan presisi tinggi (6 angka belakang koma) aslinya 6 diganti 4
|
||||
SubKriteria::where('id', $id)->update(['bobot_lokal' => round($finalWeight, 4)]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* FUNGSI RUMUS V (PERPOTONGAN ORDINAT METODE CHANG)
|
||||
* ==============================================================================
|
||||
*/
|
||||
private function calculateV(array $si_baris, array $si_kolom): float
|
||||
{
|
||||
[$l1, $m1, $u1] = $si_kolom; // Segitiga Kolom
|
||||
[$l2, $m2, $u2] = $si_baris; // Segitiga Baris
|
||||
|
||||
// Jika nilai Puncak baris >= kolom, kemungkinan = 100% (1.0)
|
||||
if ($m2 >= $m1) return 1.0;
|
||||
// Jika dasar kolom lebih tinggi dari ujung atas baris = 0%
|
||||
if ($l1 >= $u2) return 0.0;
|
||||
|
||||
$num = $l1 - $u2; // Pembilang
|
||||
$den = ($m2 - $u2) - ($m1 - $l1); // Penyebut
|
||||
|
||||
// Dibiarkan tanpa round() agar presisi matematis terjaga
|
||||
return ($den == 0) ? 0.0 : ($num / $den);
|
||||
}
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* FUNGSI MAPPING TFN (SKALA SAATY KE FUZZY)
|
||||
* ==============================================================================
|
||||
*/
|
||||
private function mapToTfn($val): array
|
||||
{
|
||||
$baseTFN = [
|
||||
1 => [1.0, 1.0, 1.0], 2 => [0.5, 1.0, 1.5], 3 => [1.0, 1.5, 2.0],
|
||||
4 => [1.5, 2.0, 2.5], 5 => [2.0, 2.5, 3.0], 6 => [2.5, 3.0, 3.5],
|
||||
7 => [3.0, 3.5, 4.0], 8 => [3.5, 4.0, 4.5], 9 => [4.0, 4.5, 4.5],
|
||||
];
|
||||
|
||||
if ($val >= 0.99 && $val <= 1.01) return $baseTFN[1];
|
||||
|
||||
if ($val > 1) {
|
||||
$key = min(9, (int) round($val));
|
||||
return $baseTFN[$key];
|
||||
} else {
|
||||
$originalKey = max(1, min(9, (int) round(1 / $val)));
|
||||
$tfn = $baseTFN[$originalKey];
|
||||
|
||||
// Dibiarkan presisi tinggi (float) tanpa round()
|
||||
return [1 / $tfn[2], 1 / $tfn[1], 1 / $tfn[0]];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* FUNGSI ALGORITMA SKALA 1000 (LARGEST REMAINDER METHOD)
|
||||
* ==============================================================================
|
||||
* TIPS SIDANG: Ini digunakan untuk menahan agar parameter dengan kepentingan
|
||||
* terendah sekalipun tetap memiliki bobot > 0, dan total akhir pasti pas 1000.
|
||||
*/
|
||||
private function toBobot1000(array $weights): array
|
||||
{
|
||||
$keys = array_keys($weights);
|
||||
$float = array_map(fn($w) => $w * 1000, $weights);
|
||||
|
||||
$result = [];
|
||||
|
||||
// Pembulatan ke bawah dengan penahan Minimum 1
|
||||
foreach ($float as $key => $val) {
|
||||
$result[$key] = max(1, floor($val));
|
||||
}
|
||||
|
||||
// Cari selisih kurangnya
|
||||
$remainder = 1000 - (int) array_sum($result);
|
||||
|
||||
if ($remainder > 0) {
|
||||
$sortedKeys = $keys;
|
||||
usort($sortedKeys, function ($a, $b) use ($float) {
|
||||
$decA = $float[$a] - floor($float[$a]);
|
||||
$decB = $float[$b] - floor($float[$b]);
|
||||
return $decB <=> $decA; // Urutkan sisa desimal terbesar ke terkecil
|
||||
});
|
||||
|
||||
// Berikan sisa +1 ke kriteria yang pecahannya paling besar
|
||||
for ($k = 0; $k < $remainder; $k++) {
|
||||
$result[$sortedKeys[$k]] += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return array_map('intval', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* FUNGSI DETAIL (UNTUK HALAMAN LAPORAN / CETAK HTML & PDF)
|
||||
* ==============================================================================
|
||||
* TIPS SIDANG: Fungsi ini isinya adalah replika persis (copy-paste logika) dari
|
||||
* fungsi updateLocalWeights(). Bedanya, updateLocalWeights() memproses rahasia di background.
|
||||
* Sedangkan fungsi detail() menangkap setiap langkah prosesnya untuk dicetak ke layar (transparansi).
|
||||
*/
|
||||
public function detail(Request $request)
|
||||
{
|
||||
// 1. Menangkap ID Kriteria Induk dari URL (jika ada)
|
||||
$selectedKriteriaId = $request->input('kriteria_id');
|
||||
$kriterias = Kriteria::orderBy('kode', 'asc')->get();
|
||||
|
||||
// Inisialisasi collection kosong agar View tidak error (Undefined Variable) saat kriteria belum dipilih
|
||||
$allData = collect([]);
|
||||
|
||||
// Jika user belum memilih Kriteria Induk, kembalikan ke layar pemilihan
|
||||
if (! $selectedKriteriaId) {
|
||||
return view('perbandingan_sub.detail', compact('kriterias', 'selectedKriteriaId', 'allData'));
|
||||
}
|
||||
|
||||
// 2. Ambil data Induk dan Anak-anaknya (Sub-Kriteria)
|
||||
$kriteriaInduk = Kriteria::findOrFail($selectedKriteriaId);
|
||||
$subs = SubKriteria::where('kriteria_id', $selectedKriteriaId)->orderBy('kode', 'asc')->get();
|
||||
// Pluck berfungsi mengekstrak 1 kolom spesifik jadi array tunggal. Contoh: ['S1', 'S2', 'S3']
|
||||
$kodes = $subs->pluck('kode')->toArray();
|
||||
|
||||
// 3. Ambil data mentah kuesioner yang sudah diisi oleh semua pakar
|
||||
$allData = PerbandinganSub::with(['subKiri', 'subKanan'])
|
||||
->where('kriteria_id', $selectedKriteriaId)->get();
|
||||
|
||||
if ($allData->isEmpty()) {
|
||||
return redirect()->route('perbandingansub.index', ['kriteria_id' => $selectedKriteriaId])
|
||||
->with('error', 'Data perbandingan untuk kriteria ini masih kosong!');
|
||||
}
|
||||
|
||||
// 4. MAP TO TFN (Fuzzifikasi Awal)
|
||||
// Menyuntikkan array TFN (l, m, u) ke dalam setiap jawaban pakar agar bisa ditampillkan di tabel ringkasan
|
||||
$allData->map(function ($item) {
|
||||
$item->tfn = $this->mapToTfn($item->nilai_skala);
|
||||
return $item;
|
||||
});
|
||||
|
||||
// 5. GENERATE DYNAMIC PAIRS & GROUPING (Untuk Tabel Ringkasan Multi-Pakar)
|
||||
// Menggabungkan sub-kriteria (S1 vs S2, S1 vs S3) khusus untuk ditampilkan di tabel View.
|
||||
$dynamicPairs = [];
|
||||
$n = count($subs);
|
||||
for ($i = 0; $i < $n; $i++) {
|
||||
for ($j = $i + 1; $j < $n; $j++) {
|
||||
$dynamicPairs[] = [
|
||||
'kiri_kode' => $subs[$i]->kode,
|
||||
'kiri_nama' => $subs[$i]->nama_sub ?? $subs[$i]->nama,
|
||||
'kanan_kode' => $subs[$j]->kode,
|
||||
'kanan_nama' => $subs[$j]->nama_sub ?? $subs[$j]->nama,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Mengelompokkan data kuesioner berdasarkan siapa yang mengisinya (Pakar 1, Pakar 2, dst)
|
||||
$groupedKuesioner = $allData->groupBy('pakar_ke');
|
||||
$pakarList = $groupedKuesioner->keys()->sort();
|
||||
|
||||
// ========================================================================
|
||||
// TAHAP 1: CRISP MATRIX (GEOMETRIC MEAN - KONSENSUS PAKAR)
|
||||
// ========================================================================
|
||||
$crispMatrix = [];
|
||||
foreach ($kodes as $iKode) {
|
||||
foreach ($kodes as $jKode) {
|
||||
// Konversi kode menjadi ID asli database
|
||||
$iId = $subs->where('kode', $iKode)->first()->id;
|
||||
$jId = $subs->where('kode', $jKode)->first()->id;
|
||||
|
||||
if ($iId == $jId) {
|
||||
$crispMatrix[$iKode][$jKode] = 1.0;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Cari penilaian searah
|
||||
$scores = $allData->where('sub_kiri_id', $iId)->where('sub_kanan_id', $jId)->pluck('nilai_skala')->toArray();
|
||||
|
||||
if (count($scores) > 0) {
|
||||
$crispMatrix[$iKode][$jKode] = pow(array_product($scores), 1 / count($scores));
|
||||
} else {
|
||||
// Cari penilaian berlawanan (Invers)
|
||||
$revScores = $allData->where('sub_kiri_id', $jId)->where('sub_kanan_id', $iId)->pluck('nilai_skala')->toArray();
|
||||
$crispMatrix[$iKode][$jKode] = count($revScores) > 0 ? (1 / pow(array_product($revScores), 1 / count($revScores))) : 1.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// ---> TAMBAHAN BARU: UJI KONSISTENSI AHP (EIGEN, CI, CR) <---
|
||||
// ========================================================================
|
||||
$nKriteria = count($kodes);
|
||||
$colSums = [];
|
||||
$priorityVector = [];
|
||||
$lambdaMax = 0;
|
||||
$ci = 0;
|
||||
$cr = 0;
|
||||
$riBaku = [1=>0.00, 2=>0.00, 3=>0.58, 4=>0.90, 5=>1.12, 6=>1.24, 7=>1.32, 8=>1.41, 9=>1.45];
|
||||
$ri = $riBaku[$nKriteria] ?? 1.45;
|
||||
|
||||
// 1. Hitung total per kolom
|
||||
foreach ($kodes as $j) {
|
||||
$sum = 0;
|
||||
foreach ($kodes as $i) { $sum += $crispMatrix[$i][$j]; }
|
||||
$colSums[$j] = $sum;
|
||||
}
|
||||
|
||||
// 2. Normalisasi & Cari Nilai Eigen
|
||||
foreach ($kodes as $i) {
|
||||
$rowSum = 0;
|
||||
foreach ($kodes as $j) {
|
||||
$normalizedVal = ($colSums[$j] == 0) ? 0 : ($crispMatrix[$i][$j] / $colSums[$j]);
|
||||
$rowSum += $normalizedVal;
|
||||
}
|
||||
$priorityVector[$i] = $rowSum / $nKriteria;
|
||||
}
|
||||
|
||||
// 3. Cari Lambda Max
|
||||
foreach ($kodes as $j) { $lambdaMax += ($colSums[$j] * $priorityVector[$j]); }
|
||||
|
||||
// 4. Hitung CI dan CR
|
||||
if ($nKriteria > 1) {
|
||||
$ci = ($lambdaMax - $nKriteria) / ($nKriteria - 1);
|
||||
$cr = ($ri > 0) ? ($ci / $ri) : 0;
|
||||
}
|
||||
// selesai
|
||||
|
||||
// ========================================================================
|
||||
// TAHAP 2: FUZZY MATRIX (TFN)
|
||||
// ========================================================================
|
||||
$matrix = [];
|
||||
foreach ($kodes as $i) {
|
||||
foreach ($kodes as $j) {
|
||||
// array_search digunakan untuk membedakan area diagonal atas dan bawah matriks
|
||||
if (array_search($i, $kodes) <= array_search($j, $kodes)) {
|
||||
$matrix[$i][$j] = $this->mapToTfn($crispMatrix[$i][$j]);
|
||||
} else {
|
||||
$tfnAtas = $matrix[$j][$i];
|
||||
// Invers TFN tanpa fungsi round() agar presisi
|
||||
$matrix[$i][$j] = [1 / $tfnAtas[2], 1 / $tfnAtas[1], 1 / $tfnAtas[0]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// TAHAP 3: ROW SUMS & NILAI SINTESIS (Si)
|
||||
// ========================================================================
|
||||
$rowSums = [];
|
||||
$totalSum = [0.0, 0.0, 0.0];
|
||||
foreach ($kodes as $i) {
|
||||
$rSum = [0.0, 0.0, 0.0];
|
||||
foreach ($kodes as $j) {
|
||||
$rSum[0] += $matrix[$i][$j][0];
|
||||
$rSum[1] += $matrix[$i][$j][1];
|
||||
$rSum[2] += $matrix[$i][$j][2];
|
||||
}
|
||||
$rowSums[$i] = $rSum;
|
||||
$totalSum[0] += $rSum[0];
|
||||
$totalSum[1] += $rSum[1];
|
||||
$totalSum[2] += $rSum[2];
|
||||
}
|
||||
|
||||
$si = [];
|
||||
foreach ($kodes as $i) {
|
||||
// Formula Si: Baris L / Total U , Baris M / Total M , Baris U / Total L
|
||||
$si[$i] = [
|
||||
$rowSums[$i][0] / $totalSum[2],
|
||||
$rowSums[$i][1] / $totalSum[1],
|
||||
$rowSums[$i][2] / $totalSum[0],
|
||||
];
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// TAHAP 4: V MATRIX (Derajat Kemungkinan)
|
||||
// ========================================================================
|
||||
$vMatrix = [];
|
||||
foreach ($kodes as $i) {
|
||||
foreach ($kodes as $j) {
|
||||
$vMatrix[$i][$j] = ($i == $j) ? 1.0 : $this->calculateV($si[$i], $si[$j]);
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// TAHAP 5: d'(Ai) & NORMALISASI (W)
|
||||
// ========================================================================
|
||||
$dPrime = [];
|
||||
foreach ($kodes as $i) {
|
||||
$vals = [];
|
||||
foreach ($kodes as $j) {
|
||||
if ($j !== $i) {
|
||||
$vals[] = $vMatrix[$i][$j];
|
||||
}
|
||||
}
|
||||
// Cari nilai Minimum
|
||||
$dPrime[$i] = count($vals) > 0 ? min($vals) : 0.0;
|
||||
}
|
||||
|
||||
$sumDPrime = array_sum($dPrime);
|
||||
$finalWeights = [];
|
||||
foreach ($kodes as $i) {
|
||||
$finalWeights[$i] = ($sumDPrime > 0) ? ($dPrime[$i] / $sumDPrime) : 0.0;
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// TAHAP AKHIR: KONVERSI KE SKALA 1000 UNTUK VIEW (Anti-Nol)
|
||||
// ========================================================================
|
||||
$bobot1000 = $this->toBobot1000($finalWeights);
|
||||
|
||||
// ========================================================================
|
||||
// OUTPUT: EXPORT PDF ATAU TAMPILAN WEB BIASA
|
||||
// ========================================================================
|
||||
if ($request->has('export') && $request->export == 'pdf') {
|
||||
// Pastikan use Barryvdh\DomPDF\Facade\Pdf; sudah ada di header file
|
||||
$pdf = Pdf::loadView('perbandingan_sub.pdf', compact(
|
||||
'kriterias', 'selectedKriteriaId', 'kriteriaInduk',
|
||||
'crispMatrix', 'matrix', 'si', 'vMatrix',
|
||||
'dPrime', 'kodes', 'subs', 'allData',
|
||||
'finalWeights', 'sumDPrime', 'bobot1000', 'pakarList',
|
||||
'dynamicPairs', 'groupedKuesioner',
|
||||
'colSums', 'priorityVector', 'lambdaMax', 'ci', 'cr', 'ri', 'nKriteria'
|
||||
))->setPaper('A4', 'landscape'); // Pakai landscape agar matriksnya muat
|
||||
|
||||
return $pdf->stream('Laporan_FAHP_SubKriteria_'.$kriteriaInduk->kode.'.pdf');
|
||||
}
|
||||
|
||||
return view('perbandingan_sub.detail', compact(
|
||||
'kriterias', 'selectedKriteriaId', 'kriteriaInduk',
|
||||
'crispMatrix', 'matrix', 'si', 'vMatrix',
|
||||
'dPrime', 'kodes', 'subs', 'allData',
|
||||
'finalWeights', 'sumDPrime', 'bobot1000', 'pakarList',
|
||||
'dynamicPairs', 'groupedKuesioner',
|
||||
'colSums', 'priorityVector', 'lambdaMax', 'ci', 'cr', 'ri', 'nKriteria'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* FUNGSI HELPER: UJI KONSISTENSI AHP (SATUAN)
|
||||
* ==============================================================================
|
||||
*/
|
||||
private function checkConsistency($matrix, $n)
|
||||
{
|
||||
$RI = [1 => 0, 2 => 0, 3 => 0.58, 4 => 0.90, 5 => 1.12, 6 => 1.24, 7 => 1.32, 8 => 1.41, 9 => 1.45];
|
||||
if ($n < 3) return 0.0; // Jika kriteria cuma 1 atau 2, otomatis konsisten
|
||||
|
||||
// Hitung Total Kolom
|
||||
$colSum = array_fill(0, $n, 0);
|
||||
foreach ($matrix as $row) { foreach ($row as $j => $val) { $colSum[$j] += $val; } }
|
||||
|
||||
// Cari Eigen Vector
|
||||
$priorityVector = [];
|
||||
foreach ($matrix as $i => $row) {
|
||||
$rowSum = 0;
|
||||
foreach ($row as $j => $val) {
|
||||
// Jaring pengaman cegah Division by Zero
|
||||
$normalizedVal = ($colSum[$j] == 0) ? 0 : ($val / $colSum[$j]);
|
||||
$rowSum += $normalizedVal;
|
||||
}
|
||||
$priorityVector[$i] = $rowSum / $n;
|
||||
}
|
||||
|
||||
// Cari Lambda Max
|
||||
$lambdaMax = 0;
|
||||
foreach ($colSum as $j => $sum) { $lambdaMax += ($sum * $priorityVector[$j]); }
|
||||
|
||||
$ci = ($lambdaMax - $n) / ($n - 1);
|
||||
return $ci / $RI[$n];
|
||||
}
|
||||
|
||||
public function hapusPakar(Request $request)
|
||||
{
|
||||
if ($request->pakar_dihapus == 1) {
|
||||
return redirect()->back()->with('error', 'Pakar 1 adalah pakar utama dan tidak dapat dihapus. Silakan lakukan Update data jika ada perubahan.');
|
||||
}
|
||||
|
||||
PerbandinganSub::where('kriteria_id', $request->kriteria_id)
|
||||
->where('pakar_ke', $request->pakar_dihapus)->delete();
|
||||
|
||||
$this->updateLocalWeights($request->kriteria_id);
|
||||
|
||||
return redirect()->back()->with('success', "Data Pakar $request->pakar_dihapus dihapus.");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Periode;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PeriodeController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$periodes = Periode::latest()->get();
|
||||
return view('periode.index', compact('periodes'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'nama_periode' => 'required|string|max:255',
|
||||
'kuota' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
Periode::create([
|
||||
'nama_periode' => $request->nama_periode,
|
||||
'kuota' => $request->kuota,
|
||||
'is_aktif' => false, // Default tidak aktif saat baru dibuat
|
||||
]);
|
||||
|
||||
return redirect()->back()->with('success', 'Periode berhasil ditambahkan!');
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$request->validate([
|
||||
'nama_periode' => 'required|string|max:255',
|
||||
'kuota' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
$periode = Periode::findOrFail($id);
|
||||
$periode->update($request->only('nama_periode', 'kuota'));
|
||||
|
||||
return redirect()->back()->with('success', 'Periode berhasil diperbarui!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Logika Inti: Mengaktifkan satu periode dan mematikan yang lain
|
||||
*/
|
||||
public function aktifkan($id)
|
||||
{
|
||||
DB::transaction(function () use ($id) {
|
||||
// Set semua periode jadi tidak aktif
|
||||
Periode::query()->update(['is_aktif' => false]);
|
||||
|
||||
// Set periode terpilih jadi aktif
|
||||
$periode = Periode::findOrFail($id);
|
||||
$periode->update(['is_aktif' => true]);
|
||||
});
|
||||
|
||||
return redirect()->back()->with('success', 'Periode ' . Periode::find($id)->nama_periode . ' kini aktif!');
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$periode = Periode::findOrFail($id);
|
||||
|
||||
if ($periode->is_aktif) {
|
||||
return redirect()->back()->with('error', 'Tidak bisa menghapus periode yang sedang aktif!');
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// 2. PAGAR PELINDUNG ARSIP HISTORI
|
||||
// Cek apakah periode ini sudah punya data riwayat seleksi warga
|
||||
// ===================================================================
|
||||
if ($periode->hasilSeleksis()->count() > 0) {
|
||||
return redirect()->back()->with('error', 'Gagal! Periode ini tidak bisa dihapus karena sudah menyimpan arsip riwayat Hasil Seleksi Bansos. Biarkan saja sebagai histori laporan Desa.');
|
||||
}
|
||||
|
||||
$periode->delete();
|
||||
return redirect()->back()->with('success', 'Periode berhasil dihapus!');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ProfilDesa;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ProfilDesaController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
// Mengambil semua data profil desa (biasanya hanya ada 1)
|
||||
$profils = ProfilDesa::all();
|
||||
return view('profil_desa.index', compact('profils'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
// PENGAMAN: Jika profil desa sudah ada, arahkan langsung ke halaman Edit.
|
||||
// Desa Bendelan tidak perlu punya 2 profil ganda.
|
||||
$existingProfil = ProfilDesa::first();
|
||||
if ($existingProfil) {
|
||||
return redirect()->route('profil_desa.edit', $existingProfil->id)
|
||||
->with('info', 'Profil desa sudah dibuat. Silakan perbarui data di sini.');
|
||||
}
|
||||
|
||||
return view('profil_desa.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'sejarah_singkat' => 'nullable|string',
|
||||
'visi' => 'nullable|string',
|
||||
'misi' => 'nullable|string',
|
||||
'nama_kepala_desa' => 'nullable|string|max:255',
|
||||
'foto_kepala_desa' => 'nullable|image|mimes:jpeg,png,jpg|max:2048',
|
||||
]);
|
||||
|
||||
$data = $request->except('foto_kepala_desa');
|
||||
|
||||
if ($request->hasFile('foto_kepala_desa')) {
|
||||
$data['foto_kepala_desa'] = $request->file('foto_kepala_desa')->store('profil_desa', 'public');
|
||||
}
|
||||
|
||||
ProfilDesa::create($data);
|
||||
|
||||
return redirect()->route('profil_desa.index')->with('success', 'Profil Desa Bendelan berhasil disimpan!');
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$profil = ProfilDesa::findOrFail($id);
|
||||
return view('profil_desa.edit', compact('profil'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$profil = ProfilDesa::findOrFail($id);
|
||||
|
||||
$request->validate([
|
||||
'sejarah_singkat' => 'nullable|string',
|
||||
'visi' => 'nullable|string',
|
||||
'misi' => 'nullable|string',
|
||||
'nama_kepala_desa' => 'nullable|string|max:255',
|
||||
'foto_kepala_desa' => 'nullable|image|mimes:jpeg,png,jpg|max:2048',
|
||||
]);
|
||||
|
||||
$data = $request->except('foto_kepala_desa');
|
||||
|
||||
// Jika ada update foto kepala desa
|
||||
if ($request->hasFile('foto_kepala_desa')) {
|
||||
if ($profil->foto_kepala_desa && Storage::disk('public')->exists($profil->foto_kepala_desa)) {
|
||||
Storage::disk('public')->delete($profil->foto_kepala_desa);
|
||||
}
|
||||
$data['foto_kepala_desa'] = $request->file('foto_kepala_desa')->store('profil_desa', 'public');
|
||||
}
|
||||
|
||||
$profil->update($data);
|
||||
|
||||
return redirect()->route('profil_desa.index')->with('success', 'Profil Desa Bendelan berhasil diperbarui!');
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$profil = ProfilDesa::findOrFail($id);
|
||||
|
||||
if ($profil->foto_kepala_desa && Storage::disk('public')->exists($profil->foto_kepala_desa)) {
|
||||
Storage::disk('public')->delete($profil->foto_kepala_desa);
|
||||
}
|
||||
|
||||
$profil->delete();
|
||||
|
||||
return redirect()->route('profil_desa.index')->with('success', 'Profil Desa berhasil dihapus!');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,204 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Kriteria;
|
||||
use App\Models\Warga;
|
||||
|
||||
class RankingController extends Controller
|
||||
{
|
||||
/**
|
||||
* Menampilkan Halaman Ranking Utama
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data = $this->getRankingData();
|
||||
|
||||
// Jika bobot belum dihitung, arahkan kembali ke menu perbandingan
|
||||
if (isset($data['redirect'])) {
|
||||
return redirect()->route('perbandingan.index')->with('error', $data['error']);
|
||||
}
|
||||
|
||||
return view('perankingan.index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Menampilkan Detail Perhitungan Tiap Warga (Untuk Sidang / Dosen)
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$warga = Warga::findOrFail($id);
|
||||
$bobot = Kriteria::pluck('bobot', 'kode')->toArray();
|
||||
|
||||
if (empty($bobot) || array_sum($bobot) == 0) {
|
||||
return redirect()->route('perbandingan.index')->with('error', 'Bobot kriteria belum dihitung.');
|
||||
}
|
||||
|
||||
// 1. Dapatkan Skor (1-5) dari Data Riil sesuai Tabel Validasi Desa
|
||||
$skor = [
|
||||
'C1' => $this->skorPendapatan($warga->c1_pendapatan),
|
||||
'C2' => $this->skorTanggungan($warga->c2_tanggungan),
|
||||
'C3' => $this->skorRumah($warga->c3_status_rumah),
|
||||
'C4' => $this->skorAset($warga->c4_aset),
|
||||
'C5' => $this->skorPekerjaan($warga->c5_pekerjaan),
|
||||
'C6' => $this->skorUsia($warga->c6_usia),
|
||||
];
|
||||
|
||||
// 2. Format Data Riil untuk Ditampilkan di Tabel Detail
|
||||
$dataRiil = [
|
||||
'C1' => 'Rp ' . number_format((int) preg_replace('/[^0-9]/', '', $warga->c1_pendapatan), 0, ',', '.'),
|
||||
'C2' => $warga->c2_tanggungan . ' Orang',
|
||||
'C3' => $warga->c3_status_rumah,
|
||||
'C4' => $warga->c4_aset,
|
||||
'C5' => $warga->c5_pekerjaan,
|
||||
'C6' => $warga->c6_usia . ' Tahun',
|
||||
];
|
||||
|
||||
$namaKriteria = [
|
||||
'C1' => 'Pendapatan', 'C2' => 'Jumlah Tanggungan', 'C3' => 'Status Tempat Tinggal',
|
||||
'C4' => 'Kepemilikan Aset', 'C5' => 'Pekerjaan', 'C6' => 'Usia Kepala Keluarga',
|
||||
];
|
||||
|
||||
// 3. Susun Array Detail Perhitungan
|
||||
$perhitungan = [];
|
||||
$totalSkorAkhir = 0;
|
||||
|
||||
foreach ($skor as $kode => $nilaiSkor) {
|
||||
$nilaiBobot = $bobot[$kode] ?? 0;
|
||||
// Normalisasi: Skor dibagi 5 (Karena nilai maksimal di tabel adalah 5)
|
||||
$normalisasi = $nilaiSkor / 5;
|
||||
$hasilKali = $normalisasi * $nilaiBobot;
|
||||
$totalSkorAkhir += $hasilKali;
|
||||
|
||||
$perhitungan[$kode] = [
|
||||
'nama' => $namaKriteria[$kode],
|
||||
'riil' => $dataRiil[$kode],
|
||||
'skor' => $nilaiSkor,
|
||||
'normalisasi' => $normalisasi,
|
||||
'bobot' => $nilaiBobot,
|
||||
'hasil' => $hasilKali
|
||||
];
|
||||
}
|
||||
|
||||
// Kirim ke view (Pastikan file resources/views/perankingan/show.blade.php sudah dibuat)
|
||||
return view('perankingan.show', compact('warga', 'perhitungan', 'totalSkorAkhir'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Logika Utama Perhitungan Ranking
|
||||
*/
|
||||
private function getRankingData()
|
||||
{
|
||||
// 1. Ambil Bobot Final dari Tabel Kriteria (Hasil F-AHP Chang)
|
||||
$bobot = Kriteria::pluck('bobot', 'kode')->toArray();
|
||||
|
||||
// Validasi: Pastikan bobot sudah dihitung
|
||||
if (empty($bobot) || array_sum($bobot) == 0) {
|
||||
return [
|
||||
'redirect' => true,
|
||||
'error' => 'Bobot kriteria belum dihitung. Silakan lakukan perhitungan di menu Perbandingan terlebih dahulu!',
|
||||
];
|
||||
}
|
||||
|
||||
// 2. Ambil Warga yang sudah di-setujui oleh Verifikator Desa
|
||||
$wargas = Warga::where('status_verifikasi', 'setuju')->get();
|
||||
$hasilRanking = [];
|
||||
$threshold = 0.65; // Ambang batas kelayakan (65%)
|
||||
|
||||
foreach ($wargas as $w) {
|
||||
// TAHAP TRANSFORMASI: Data Riil -> Skor (1, 3, 4, 5)
|
||||
$s1 = $this->skorPendapatan($w->c1_pendapatan);
|
||||
$s2 = $this->skorTanggungan($w->c2_tanggungan);
|
||||
$s3 = $this->skorRumah($w->c3_status_rumah);
|
||||
$s4 = $this->skorAset($w->c4_aset);
|
||||
$s5 = $this->skorPekerjaan($w->c5_pekerjaan);
|
||||
$s6 = $this->skorUsia($w->c6_usia);
|
||||
|
||||
/**
|
||||
* TAHAP PERHITUNGAN:
|
||||
* Rumus: Σ ((Skor / 5) * Bobot)
|
||||
* Normalisasi skor dibagi 5 (karena skor tertinggi 5) sebelum dikalikan bobot.
|
||||
*/
|
||||
$totalSkor = (
|
||||
(($s1 / 5) * ($bobot['C1'] ?? 0)) +
|
||||
(($s2 / 5) * ($bobot['C2'] ?? 0)) +
|
||||
(($s3 / 5) * ($bobot['C3'] ?? 0)) +
|
||||
(($s4 / 5) * ($bobot['C4'] ?? 0)) +
|
||||
(($s5 / 5) * ($bobot['C5'] ?? 0)) +
|
||||
(($s6 / 5) * ($bobot['C6'] ?? 0))
|
||||
);
|
||||
|
||||
$hasilRanking[] = [
|
||||
'id' => $w->id, // PENTING: Ditambahkan agar tombol "Detail" bisa mendeteksi ID Warga
|
||||
'nama' => $w->nama,
|
||||
'nik' => $w->nik,
|
||||
'rt_rw' => "RT $w->rt / RW $w->rw",
|
||||
'skor_akhir' => $totalSkor,
|
||||
'status' => $totalSkor >= $threshold ? 'LAYAK' : 'TIDAK LAYAK',
|
||||
];
|
||||
}
|
||||
|
||||
// 3. TAHAP PERANGKINGAN: Urutkan Skor Terbesar ke Terkecil
|
||||
usort($hasilRanking, function ($a, $b) {
|
||||
return $b['skor_akhir'] <=> $a['skor_akhir'];
|
||||
});
|
||||
|
||||
return [
|
||||
'hasilRanking' => $hasilRanking,
|
||||
'threshold' => $threshold,
|
||||
];
|
||||
}
|
||||
|
||||
// --- HELPER SCORING: DISINKRONKAN DENGAN TABEL DATA RIIL ---
|
||||
|
||||
private function skorPendapatan($val)
|
||||
{
|
||||
// Pastikan input berupa angka murni (hapus "Rp" atau titik jika ada)
|
||||
$val = (int) preg_replace('/[^0-9]/', '', $val);
|
||||
|
||||
if ($val <= 500000) return 5;
|
||||
if ($val <= 1000000) return 4;
|
||||
if ($val <= 1500000) return 3;
|
||||
return 1; // > Rp 1.500.000
|
||||
}
|
||||
|
||||
private function skorTanggungan($val)
|
||||
{
|
||||
$val = (int) $val;
|
||||
if ($val >= 5) return 5;
|
||||
if ($val >= 3) return 3; // Range 3-4 Orang
|
||||
return 1; // Range 1-2 Orang
|
||||
}
|
||||
|
||||
private function skorRumah($val)
|
||||
{
|
||||
$val = strtolower($val); // antisipasi huruf besar/kecil
|
||||
if (str_contains($val, 'numpang') || str_contains($val, 'menumpang')) return 5;
|
||||
if (str_contains($val, 'sewa') || str_contains($val, 'kontrak')) return 3;
|
||||
return 1; // Milik Sendiri
|
||||
}
|
||||
|
||||
private function skorAset($val)
|
||||
{
|
||||
$val = strtolower($val);
|
||||
if (str_contains($val, 'tidak memiliki')) return 5;
|
||||
if (str_contains($val, 'elektronik') || str_contains($val, 'tv') || str_contains($val, 'hp')) return 3;
|
||||
return 1; // Memiliki Kendaraan (Motor/Mobil)
|
||||
}
|
||||
|
||||
private function skorPekerjaan($val)
|
||||
{
|
||||
$val = strtolower($val);
|
||||
if (str_contains($val, 'tidak bekerja') || str_contains($val, 'lansia')) return 5;
|
||||
if (str_contains($val, 'tani') || str_contains($val, 'serabutan')) return 4;
|
||||
return 1; // Karyawan / Wiraswasta
|
||||
}
|
||||
|
||||
private function skorUsia($val)
|
||||
{
|
||||
$val = (int) $val;
|
||||
if ($val >= 60) return 5; // Lansia
|
||||
if ($val >= 45) return 3; // 45 - 59 Tahun
|
||||
return 1; // < 45 Tahun
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Exports\HasilSeleksiExport;
|
||||
use App\Models\HasilSeleksi;
|
||||
use App\Models\Periode;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class RiwayatSeleksiController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
// 1. Ambil semua daftar periode untuk dropdown filter
|
||||
$listPeriode = Periode::orderBy('created_at', 'desc')->get();
|
||||
|
||||
// 2. Ambil ID periode dari request. Default ke periode terbaru jika belum pilih.
|
||||
$selectedPeriodeId = $request->input('periode_id', optional($listPeriode->first())->id);
|
||||
|
||||
// 3. Inisialisasi variabel default
|
||||
$periode = null;
|
||||
$results = collect();
|
||||
$mean = 0;
|
||||
$countUtama = 0;
|
||||
$countCadangan = 0;
|
||||
$countTidakLayak = 0;
|
||||
$countDialihkan = 0;
|
||||
|
||||
// --- HITUNG RATA-RATA GLOBAL (PASSING GRADE) ---
|
||||
// Ini diambil dari seluruh sejarah data di tabel hasil_seleksi
|
||||
$passingGrade = HasilSeleksi::avg('skor_akhir') ?? 0;
|
||||
|
||||
$perPage = $request->input('per_page', 10);
|
||||
$search = $request->input('search');
|
||||
|
||||
// 4. Jika ada periode yang ditemukan/dipilih
|
||||
if ($selectedPeriodeId) {
|
||||
$periode = Periode::find($selectedPeriodeId);
|
||||
|
||||
if ($periode) {
|
||||
// Query dasar untuk hasil seleksi pada periode terpilih
|
||||
$query = HasilSeleksi::with('warga')->where('periode_id', $periode->id);
|
||||
|
||||
// --- HITUNG STATISTIK PERIODE TERPILIH ---
|
||||
// Menggunakan clone agar query utama tidak terganggu agregasi
|
||||
$mean = (clone $query)->avg('skor_akhir') ?? 0;
|
||||
$countUtama = (clone $query)->where('status_keputusan', 'Layak Prioritas Utama')->count();
|
||||
$countCadangan = (clone $query)->where('status_keputusan', 'Layak Cadangan')->count();
|
||||
$countTidakLayak = (clone $query)->where('status_keputusan', 'Tidak Layak')->count();
|
||||
$countDialihkan = (clone $query)->where('status_keputusan', 'Dialihkan (Pemerataan)')->count();
|
||||
|
||||
// --- LOGIKA PENCARIAN ---
|
||||
if ($search) {
|
||||
$query->whereHas('warga', function ($q) use ($search) {
|
||||
$q->where('nama', 'like', "%{$search}%")
|
||||
->orWhere('nik', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
// --- EKSEKUSI PAGINATION ---
|
||||
$results = $query->orderBy('ranking', 'asc')->paginate($perPage);
|
||||
|
||||
// Menjaga agar filter periode, search, dan per_page tetap ada di link pagination
|
||||
$results->appends($request->all());
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Kirim data ke View
|
||||
return view('riwayat.index', [
|
||||
'listPeriode' => $listPeriode,
|
||||
'periode' => $periode,
|
||||
'results' => $results,
|
||||
'selectedPeriodeId' => $selectedPeriodeId,
|
||||
'perPage' => $perPage,
|
||||
'search' => $search,
|
||||
|
||||
// Statistik untuk Box Info & Kondisional Export
|
||||
'mean' => $mean,
|
||||
'passingGrade' => $passingGrade,
|
||||
'countUtama' => $countUtama,
|
||||
'countCadangan' => $countCadangan,
|
||||
'countTidakLayak' => $countTidakLayak,
|
||||
'countDialihkan' => $countDialihkan,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Export data riwayat ke Excel menggunakan class HasilSeleksiExport yang sudah ada.
|
||||
*/
|
||||
public function exportExcel(Request $request)
|
||||
{
|
||||
$periodeId = $request->query('periode_id');
|
||||
$status = $request->query('status');
|
||||
$limit = $request->query('limit');
|
||||
|
||||
if (! $periodeId) {
|
||||
return back()->with('error', 'Gagal Export! Pilih periode terlebih dahulu.');
|
||||
}
|
||||
|
||||
$periode = Periode::findOrFail($periodeId);
|
||||
|
||||
// 1. VALIDASI DATA: Cek apakah ada data yang akan di-export
|
||||
$checkQuery = HasilSeleksi::where('periode_id', $periodeId);
|
||||
|
||||
if ($status) {
|
||||
$checkQuery->where('status_keputusan', $status);
|
||||
}
|
||||
|
||||
if ($limit == 'kuota') {
|
||||
$checkQuery->take($periode->kuota);
|
||||
}
|
||||
|
||||
// Jika hasil query kosong
|
||||
if ($checkQuery->count() === 0) {
|
||||
$pesanStatus = $status ? "kategori [$status]" : 'seluruh data';
|
||||
|
||||
return back()->with('error', "Gagal Export! Tidak ada $pesanStatus pada arsip periode ".$periode->nama_periode);
|
||||
}
|
||||
|
||||
// 2. Jalankan Export
|
||||
$fileName = 'Arsip-Seleksi-'.str_replace(' ', '-', $periode->nama_periode).'.xlsx';
|
||||
|
||||
return Excel::download(new HasilSeleksiExport($periodeId, $status, $limit), $fileName);
|
||||
}
|
||||
|
||||
public function exportPdf(Request $request)
|
||||
{
|
||||
// --- TAMBAHAN UNTUK MENGATASI ERROR 500 (MEMORY & TIMEOUT) ---
|
||||
// Meminta izin ke server untuk melonggarkan batas waktu dan RAM
|
||||
// karena proses render PDF sangat berat.
|
||||
ini_set('max_execution_time', 600); // Ekstra waktu sampai 10 menit
|
||||
set_time_limit(600); // Backup setting waktu
|
||||
ini_set('memory_limit', '1024M'); // Meminta RAM hingga 1 GB
|
||||
// --------------------------------------------------------------
|
||||
|
||||
$periodeId = $request->query('periode_id');
|
||||
$status = $request->query('status');
|
||||
$limit = $request->query('limit');
|
||||
|
||||
if (! $periodeId) {
|
||||
return back()->with('error', 'Gagal Export! Pilih periode terlebih dahulu.');
|
||||
}
|
||||
|
||||
$periode = Periode::findOrFail($periodeId);
|
||||
|
||||
// 1. Bangun Query
|
||||
$query = HasilSeleksi::with('warga')
|
||||
->where('periode_id', $periodeId)
|
||||
->orderBy('ranking', 'asc');
|
||||
|
||||
if ($status) {
|
||||
$query->where('status_keputusan', $status);
|
||||
}
|
||||
|
||||
if ($limit == 'kuota') {
|
||||
$query->take($periode->kuota);
|
||||
}
|
||||
|
||||
// 2. VALIDASI DATA: Ambil data dan cek ketersediaannya
|
||||
$results = $query->get();
|
||||
|
||||
if ($results->isEmpty()) {
|
||||
$pesanStatus = $status ? "kategori [$status]" : 'seluruh data';
|
||||
|
||||
return back()->with('error', "Gagal Export PDF! Tidak ada $pesanStatus pada arsip periode ".$periode->nama_periode);
|
||||
}
|
||||
|
||||
// 3. Generate PDF
|
||||
$pdf = Pdf::loadView('seleksi.pdf', compact('results', 'periode'));
|
||||
$fileName = 'Arsip-PDF-'.str_replace(' ', '-', $periode->nama_periode).'.pdf';
|
||||
|
||||
return $pdf->setPaper('a4', 'potrait')->download($fileName);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,350 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Exports\HasilSeleksiExport;
|
||||
use App\Models\HasilSeleksi;
|
||||
use App\Models\Kriteria;
|
||||
use App\Models\Periode;
|
||||
use App\Models\SubKriteria;
|
||||
use App\Models\Warga;
|
||||
use App\Models\WargaDetail;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class SeleksiController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$periode = Periode::where('is_aktif', true)->first();
|
||||
|
||||
// Ambil daftar warga yang sudah disetujui untuk ditampilkan di pilihan checkbox (Targeted)
|
||||
$wargaSiap = Warga::where('status_verifikasi', 'setuju')
|
||||
->where('status_bansos_riil', 'aktif') // <-- TAMBAHAN FILTER
|
||||
->orderBy('nama', 'asc')
|
||||
->get();
|
||||
$jumlahWargaSiap = $wargaSiap->count();
|
||||
|
||||
// Inisialisasi default
|
||||
$results = collect();
|
||||
$mean = 0;
|
||||
$countUtama = 0;
|
||||
$countCadangan = 0;
|
||||
$countTidakLayak = 0;
|
||||
$countDialihkan = 0;
|
||||
$passingGrade = 0;
|
||||
|
||||
// --- VARIABEL UNTUK CEK DATA USANG (STALE DATA) ---
|
||||
$butuhHitungUlang = false;
|
||||
|
||||
$perPage = $request->input('per_page', 10);
|
||||
$search = $request->input('search');
|
||||
|
||||
if ($periode) {
|
||||
// --- HITUNG STATISTIK BERDASARKAN HASIL SELEKSI ---
|
||||
$statsQuery = HasilSeleksi::where('periode_id', $periode->id);
|
||||
|
||||
$mean = (clone $statsQuery)->avg('skor_akhir') ?? 0;
|
||||
$countUtama = (clone $statsQuery)->where('status_keputusan', 'Layak Prioritas Utama')->count();
|
||||
$countCadangan = (clone $statsQuery)->where('status_keputusan', 'Layak Cadangan')->count();
|
||||
$countTidakLayak = (clone $statsQuery)->where('status_keputusan', 'Tidak Layak')->count();
|
||||
$countDialihkan = (clone $statsQuery)->where('status_keputusan', 'Dialihkan (Pemerataan)')->count();
|
||||
|
||||
$passingGrade = HasilSeleksi::avg('skor_akhir') ?? 0;
|
||||
|
||||
// --- QUERY UNTUK MENAMPILKAN TABEL HASIL ---
|
||||
$query = HasilSeleksi::with('warga')->where('periode_id', $periode->id);
|
||||
|
||||
if ($search) {
|
||||
$query->whereHas('warga', function ($q) use ($search) {
|
||||
$q->where('nama', 'like', "%{$search}%")
|
||||
->orWhere('nik', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
$results = $query->orderBy('ranking', 'asc')->paginate($perPage);
|
||||
$results->appends(['search' => $search, 'per_page' => $perPage]);
|
||||
|
||||
// --- LOGIKA PENGECEKAN DATA BERUBAH (STALE DATA) ---
|
||||
// Cari waktu terakhir kali sistem melakukan perhitungan (created_at terakhir di HasilSeleksi)
|
||||
$terakhirDihitung = (clone $statsQuery)->max('created_at');
|
||||
|
||||
if ($terakhirDihitung) {
|
||||
// 1. Cek apakah ada profil utama warga yang diupdate setelah perhitungan terakhir
|
||||
$profilBerubah = Warga::where('status_verifikasi', 'setuju')
|
||||
->where('status_bansos_riil', 'aktif') // <-- TAMBAHAN FILTER
|
||||
->where('updated_at', '>', $terakhirDihitung)
|
||||
->exists();
|
||||
|
||||
// 2. Cek apakah ada data kriteria/pendapatan (WargaDetail) yang diupdate setelah perhitungan terakhir
|
||||
// Kita pakai whereHas untuk memastikan hanya mengecek detail milik warga yang statusnya 'setuju'
|
||||
$detailBerubah = WargaDetail::whereHas('warga', function ($q) {
|
||||
$q->where('status_verifikasi', 'setuju');
|
||||
})
|
||||
->where('updated_at', '>', $terakhirDihitung)
|
||||
->exists();
|
||||
|
||||
// Jika salah satu saja ada yang berubah, maka munculkan peringatan hitung ulang
|
||||
if ($profilBerubah || $detailBerubah) {
|
||||
$butuhHitungUlang = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return view('seleksi.index', compact(
|
||||
'periode', 'results', 'mean', 'jumlahWargaSiap', 'wargaSiap',
|
||||
'search', 'perPage', 'countUtama', 'countCadangan', 'countTidakLayak', 'countDialihkan',
|
||||
'butuhHitungUlang', 'passingGrade'
|
||||
));
|
||||
}
|
||||
|
||||
public function prosesHitung(Request $request)
|
||||
{
|
||||
// 1. Inisialisasi & Validasi Parameter Awal
|
||||
// Mencari periode yang sedang aktif untuk memastikan hasil perhitungan tersimpan di konteks waktu yang benar.
|
||||
$periode = Periode::where('is_aktif', true)->first();
|
||||
if (! $periode) {
|
||||
return redirect()->back()->with('error', 'Gagal! Tidak ada periode yang sedang aktif.');
|
||||
}
|
||||
|
||||
// Mengambil input mode perhitungan (murni/pemerataan) dan cakupan target warga (semua/pilihan manual).
|
||||
$modeHitung = $request->input('mode_hitung', 'murni');
|
||||
$targetWarga = $request->input('target_warga', 'semua');
|
||||
|
||||
// 2. Validasi Kesiapan Bobot F-AHP (Constraint Check)
|
||||
// Memastikan pakar telah menyelesaikan perbandingan matriks.
|
||||
// SPK tidak bisa berjalan jika bobot (weight) bernilai 0 karena perhitungan akan menjadi tidak valid/bias.
|
||||
$cekKriteria = Kriteria::where('bobot_global', 0)->orWhereNull('bobot_global')->count();
|
||||
$cekSub = SubKriteria::where('bobot_lokal', 0)->orWhereNull('bobot_lokal')->count();
|
||||
|
||||
if ($cekKriteria > 0 || $cekSub > 0) {
|
||||
return redirect()->back()->with('error', 'Gagal! Bobot F-AHP belum lengkap.');
|
||||
}
|
||||
|
||||
// 3. Data Acquisition (Pengambilan Data Warga)
|
||||
// Hanya mengambil warga dengan status 'setuju' (yang sudah lolos verifikasi lapangan).
|
||||
$queryWarga = Warga::with(['details.kriteria', 'details.subKriteria'])
|
||||
->where('status_verifikasi', 'setuju')
|
||||
->where('status_bansos_riil', 'aktif'); // <-- TAMBAHAN FILTER
|
||||
|
||||
// Jika user memilih mode 'Targeted', filter data berdasarkan ID yang dipilih saja.
|
||||
if ($targetWarga == 'pilih') {
|
||||
$request->validate([
|
||||
'selected_warga' => 'required|array|min:1',
|
||||
], ['selected_warga.required' => 'Pilih minimal satu warga!']);
|
||||
|
||||
$queryWarga->whereIn('id', $request->selected_warga);
|
||||
}
|
||||
|
||||
$wargas = $queryWarga->get();
|
||||
|
||||
if ($wargas->isEmpty()) {
|
||||
return redirect()->back()->with('error', 'Tidak ada data warga yang valid.');
|
||||
}
|
||||
|
||||
try {
|
||||
// Menggunakan Database Transaction untuk menjamin integritas data (atomicity).
|
||||
// Jika proses gagal di tengah jalan, data lama tidak akan rusak/hilang.
|
||||
DB::beginTransaction();
|
||||
|
||||
// Reset data lama pada periode berjalan sebelum menulis hasil perhitungan baru.
|
||||
HasilSeleksi::where('periode_id', $periode->id)->delete();
|
||||
|
||||
// 4. Tahap Analisis Historis (Untuk Mode Pemerataan)
|
||||
// Mengidentifikasi warga yang sudah menerima bantuan di periode sebelumnya
|
||||
// untuk mengimplementasikan prinsip keadilan distributif (agar bantuan tidak menumpuk di satu pihak).
|
||||
$penerimaLalu = [];
|
||||
if ($modeHitung == 'pemerataan') {
|
||||
$periodeLalu = Periode::where('id', '!=', $periode->id)->latest('id')->first();
|
||||
if ($periodeLalu) {
|
||||
$penerimaLalu = HasilSeleksi::where('periode_id', $periodeLalu->id)
|
||||
->where('status_keputusan', 'Layak Prioritas Utama')
|
||||
->pluck('warga_id')
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Tahap Matematis: Perhitungan Skor Akhir (Aggregation)
|
||||
// Menggunakan rumus V = Σ (W * w) sesuai kaidah Fuzzy AHP.
|
||||
// W = Bobot Global Kriteria, w = Bobot Lokal Sub-Kriteria.
|
||||
$tempHasil = [];
|
||||
foreach ($wargas as $w) {
|
||||
$totalSkor = 0;
|
||||
foreach ($w->details as $detail) {
|
||||
$bobotGlobal = $detail->kriteria->bobot_global ?? 0;
|
||||
$bobotLokal = $detail->subKriteria->bobot_lokal ?? 0;
|
||||
$totalSkor += ($bobotGlobal * $bobotLokal);
|
||||
}
|
||||
|
||||
$tempHasil[] = [
|
||||
'warga_id' => $w->id,
|
||||
// 'skor' => $totalSkor,
|
||||
'skor' => round($totalSkor, 4),
|
||||
'nik' => $w->nik,
|
||||
];
|
||||
}
|
||||
|
||||
// 6. Tahap Sorting & Penentuan Benchmark (Ranking & Statistics)
|
||||
// Mengurutkan dari skor tertinggi (paling membutuhkan) ke terendah.
|
||||
// Jika skor sama, NIK digunakan sebagai tie-breaker agar hasil ranking tetap deterministik.
|
||||
$sortedResults = collect($tempHasil)->sort(function ($a, $b) {
|
||||
if ($a['skor'] === $b['skor']) {
|
||||
return $a['nik'] <=> $b['nik'];
|
||||
}
|
||||
|
||||
return $b['skor'] <=> $a['skor'];
|
||||
})->values();
|
||||
|
||||
// Menghitung rata-rata lokal untuk klasifikasi kelompok 'Layak Cadangan'.
|
||||
$rataRataLokal = $sortedResults->avg('skor');
|
||||
|
||||
// AMBIL PASSING GRADE GLOBAL (Threshold Adaptif)
|
||||
// Ini adalah rata-rata historis seluruh data yang pernah diseleksi.
|
||||
// Menjadi instrumen validasi agar warga yang 'mampu' tidak lolos meski kuota tersedia.
|
||||
$passingGrade = HasilSeleksi::avg('skor_akhir') ?? 0;
|
||||
|
||||
// 7. Tahap Klasifikasi (Hybrid Decision Logic)
|
||||
// Menggabungkan metode ranking, batasan kuota, dan ambang batas (threshold) statistik.
|
||||
$kuotaTerpakai = 0;
|
||||
foreach ($sortedResults as $index => $res) {
|
||||
$ranking = $index + 1;
|
||||
$wargaId = $res['warga_id'];
|
||||
$skor = $res['skor'];
|
||||
|
||||
// A. VALIDASI AMBANG BATAS (Objective Filter)
|
||||
// Jika skor di bawah standar kelayakan desa (Passing Grade), langsung divonis 'Tidak Layak'.
|
||||
if ($skor < $passingGrade && $passingGrade > 0) {
|
||||
$status = 'Tidak Layak';
|
||||
}
|
||||
// B. VALIDASI PEMERATAAN (Social Fairness)
|
||||
// Jika warga sudah pernah dapat, status dialihkan untuk memberikan kesempatan pada yang lain.
|
||||
elseif ($modeHitung == 'pemerataan' && in_array($wargaId, $penerimaLalu)) {
|
||||
$status = 'Dialihkan (Pemerataan)';
|
||||
}
|
||||
// C. VALIDASI KUOTA & RATA-RATA LOKAL (Resource Allocation)
|
||||
else {
|
||||
if ($kuotaTerpakai < $periode->kuota) {
|
||||
$status = 'Layak Prioritas Utama';
|
||||
$kuotaTerpakai++;
|
||||
} elseif ($skor >= $rataRataLokal) {
|
||||
$status = 'Layak Cadangan';
|
||||
} else {
|
||||
$status = 'Tidak Layak';
|
||||
}
|
||||
}
|
||||
|
||||
// Simpan hasil keputusan ke tabel hasil_seleksi.
|
||||
HasilSeleksi::create([
|
||||
'periode_id' => $periode->id,
|
||||
'warga_id' => $wargaId,
|
||||
'skor_akhir' => $skor,
|
||||
'ranking' => $ranking,
|
||||
'status_keputusan' => $status,
|
||||
]);
|
||||
}
|
||||
|
||||
DB::commit(); // Finalisasi penyimpanan data ke database.
|
||||
|
||||
$msg = ($targetWarga == 'pilih') ? count($wargas).' warga berhasil dihitung.' : 'Seluruh warga berhasil diproses.';
|
||||
|
||||
return redirect()->route('seleksi.index')->with('success', $msg);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback(); // Batalkan semua perubahan jika terjadi error untuk menjaga konsistensi data.
|
||||
|
||||
return redirect()->back()->with('error', 'Terjadi kesalahan sistem: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$result = HasilSeleksi::with([
|
||||
'warga.details.kriteria',
|
||||
'warga.details.subKriteria',
|
||||
])->findOrFail($id);
|
||||
|
||||
return view('seleksi.show', compact('result'));
|
||||
}
|
||||
|
||||
public function exportExcel(Request $request)
|
||||
{
|
||||
// 1. Pastikan ada periode yang aktif
|
||||
$periode = Periode::where('is_aktif', true)->first();
|
||||
if (!$periode) {
|
||||
return back()->with('error', 'Gagal Export! Periode aktif tidak ditemukan.');
|
||||
}
|
||||
|
||||
$status = $request->query('status');
|
||||
$limit = $request->query('limit');
|
||||
|
||||
// 2. VALIDASI DATA: Cek apakah ada data yang akan di-export
|
||||
$checkQuery = HasilSeleksi::where('periode_id', $periode->id);
|
||||
|
||||
if ($status) {
|
||||
$checkQuery->where('status_keputusan', $status);
|
||||
}
|
||||
|
||||
if ($limit == 'kuota') {
|
||||
$checkQuery->take($periode->kuota);
|
||||
}
|
||||
|
||||
// Jika hasil query nol, kembalikan dengan pesan error
|
||||
if ($checkQuery->count() === 0) {
|
||||
$pesan = $status ? "untuk kategori [$status]" : "";
|
||||
return back()->with('error', "Gagal Export! Tidak ada data $pesan pada periode " . $periode->nama_periode);
|
||||
}
|
||||
|
||||
// 3. Jalankan Export jika data tersedia
|
||||
return Excel::download(
|
||||
new HasilSeleksiExport($periode->id, $status, $limit),
|
||||
'Hasil-Seleksi-'.$periode->nama_periode.'.xlsx'
|
||||
);
|
||||
}
|
||||
|
||||
public function exportPdf(Request $request)
|
||||
{
|
||||
// --- SUNTIKAN TENAGA UNTUK SERVER MENGATASI ERROR 500 ---
|
||||
ini_set('max_execution_time', 600); // Waktu maksimal diperpanjang jadi 10 menit
|
||||
set_time_limit(600); // Backup pengaturan waktu
|
||||
ini_set('memory_limit', '1024M'); // Kapasitas memori (RAM) diperbesar jadi 1 GB
|
||||
// --------------------------------------------------------
|
||||
|
||||
// 1. Pastikan ada periode yang aktif
|
||||
$periode = Periode::where('is_aktif', true)->first();
|
||||
if (!$periode) {
|
||||
return back()->with('error', 'Gagal Export! Periode aktif tidak ditemukan.');
|
||||
}
|
||||
|
||||
$status = $request->query('status');
|
||||
$limit = $request->query('limit');
|
||||
|
||||
// 2. Siapkan Query
|
||||
$query = HasilSeleksi::with('warga')
|
||||
->where('periode_id', $periode->id)
|
||||
->orderBy('ranking', 'asc');
|
||||
|
||||
if ($status) {
|
||||
$query->where('status_keputusan', $status);
|
||||
}
|
||||
|
||||
if ($limit == 'kuota') {
|
||||
$query->take($periode->kuota);
|
||||
}
|
||||
|
||||
// 3. VALIDASI DATA: Cek ketersediaan record
|
||||
$results = $query->get();
|
||||
|
||||
if ($results->isEmpty()) {
|
||||
$pesan = $status ? "untuk kategori [$status]" : "";
|
||||
return back()->with('error', "Gagal Export PDF! Tidak ada data $pesan pada periode " . $periode->nama_periode);
|
||||
}
|
||||
|
||||
// 4. Generate PDF jika data tersedia
|
||||
$pdf = Pdf::loadView('seleksi.pdf', compact('results', 'periode'));
|
||||
$pdf->setPaper('a4', 'potrait');
|
||||
|
||||
return $pdf->download('Laporan-Seleksi-'.$periode->nama_periode.'.pdf');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,183 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Kriteria;
|
||||
use App\Models\SubKriteria;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SubkriteriaController extends Controller
|
||||
{
|
||||
public function index(\Illuminate\Http\Request $request)
|
||||
{
|
||||
// Tangkap request 'per_page', default-nya 10
|
||||
$perPage = $request->input('per_page', 10);
|
||||
|
||||
// Gunakan paginate pada Kriteria (Induk)
|
||||
$kriterias = Kriteria::query()
|
||||
->with(['subKriterias' => function ($query) {
|
||||
$query->orderBy('nilai_acuan', 'asc');
|
||||
}])
|
||||
->orderBy('kode', 'asc')
|
||||
->paginate($perPage)
|
||||
->appends($request->query());
|
||||
|
||||
return view('subkriteria.index', compact('kriterias', 'perPage'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$kriterias = Kriteria::all();
|
||||
return view('subkriteria.create', compact('kriterias'));
|
||||
}
|
||||
|
||||
public function getByKriteria($kriteria_id)
|
||||
{
|
||||
$subs = SubKriteria::where('kriteria_id', $kriteria_id)
|
||||
->orderBy('nilai_acuan', 'asc')
|
||||
->get();
|
||||
|
||||
return response()->json($subs);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'kriteria_id' => 'required|exists:kriterias,id',
|
||||
'nama_sub' => 'required|array',
|
||||
'nama_sub.*' => 'required|string|max:255',
|
||||
'nilai_acuan' => 'required|array',
|
||||
'nilai_acuan.*' => 'required|numeric',
|
||||
]);
|
||||
|
||||
DB::transaction(function () use ($request) {
|
||||
|
||||
SubKriteria::where('kriteria_id', $request->kriteria_id)->update(['bobot_lokal' => 0]);
|
||||
|
||||
foreach ($request->nama_sub as $index => $nama) {
|
||||
SubKriteria::create([
|
||||
'kriteria_id' => $request->kriteria_id,
|
||||
'nama_sub' => $nama,
|
||||
'nilai_acuan' => $request->nilai_acuan[$index],
|
||||
'kode' => 'TEMP-'.uniqid(),
|
||||
'bobot_lokal' => 0,
|
||||
]);
|
||||
}
|
||||
$this->refreshSubKriteriaCodes($request->kriteria_id);
|
||||
});
|
||||
|
||||
return redirect()->route('subkriteria.index')->with('success', 'Data berhasil ditambah & Bobot lokal direset. Silakan lakukan perbandingan ulang pakar.');
|
||||
}
|
||||
|
||||
// --- METHOD EDIT ---
|
||||
public function edit($id)
|
||||
{
|
||||
$subkriteria = SubKriteria::findOrFail($id);
|
||||
// Kita ambil data kriteria induknya saja untuk label di view
|
||||
$kriteria = Kriteria::findOrFail($subkriteria->kriteria_id);
|
||||
|
||||
return view('subkriteria.edit', compact('subkriteria', 'kriteria'));
|
||||
}
|
||||
|
||||
// --- METHOD UPDATE ---
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$request->validate([
|
||||
'nama_sub' => 'required|string|max:255',
|
||||
'nilai_acuan' => 'required|numeric',
|
||||
]);
|
||||
|
||||
$sub = SubKriteria::findOrFail($id);
|
||||
|
||||
DB::transaction(function () use ($request, $sub) {
|
||||
// Update data sub kriteria
|
||||
$sub->update([
|
||||
'nama_sub' => $request->nama_sub,
|
||||
'nilai_acuan' => $request->nilai_acuan,
|
||||
]);
|
||||
|
||||
// Refresh kode agar jika urutan berubah, S.C1.1 dst tetap rapi
|
||||
$this->refreshSubKriteriaCodes($sub->kriteria_id);
|
||||
});
|
||||
|
||||
return redirect()->route('subkriteria.index')->with('success', 'Sub Kriteria berhasil diperbarui!');
|
||||
}
|
||||
|
||||
private function refreshSubKriteriaCodes($kriteria_id)
|
||||
{
|
||||
$kriteria = Kriteria::find($kriteria_id);
|
||||
$subs = SubKriteria::where('kriteria_id', $kriteria_id)
|
||||
->orderBy('nilai_acuan', 'asc')
|
||||
->get();
|
||||
|
||||
foreach ($subs as $sub) {
|
||||
$sub->kode = 'TEMP-'.$sub->id.'-'.uniqid();
|
||||
$sub->save();
|
||||
}
|
||||
|
||||
foreach ($subs as $index => $sub) {
|
||||
$sub->kode = 'S.'.$kriteria->kode.'.'.($index + 1);
|
||||
$sub->save();
|
||||
}
|
||||
}
|
||||
|
||||
// public function destroy($id)
|
||||
// {
|
||||
// $sub = SubKriteria::findOrFail($id);
|
||||
// $k_id = $sub->kriteria_id;
|
||||
// $sub->delete();
|
||||
|
||||
// $this->refreshSubKriteriaCodes($k_id);
|
||||
|
||||
// return redirect()->route('subkriteria.index')->with('success', 'Sub Kriteria dihapus!');
|
||||
// }
|
||||
public function destroy($id)
|
||||
{
|
||||
// ===================================================================
|
||||
// 1. PAGAR PELINDUNG ARSIP
|
||||
// Cek apakah sistem sudah pernah menghasilkan riwayat Hasil Seleksi
|
||||
// ===================================================================
|
||||
$adaHasilSeleksi = DB::table('hasil_seleksis')->count();
|
||||
|
||||
if ($adaHasilSeleksi > 0) {
|
||||
return redirect()->back()->with('error', 'Gagal! Sub-Kriteria tidak bisa dihapus karena kriteria induknya sudah menjadi arsip riwayat Hasil Seleksi. Silakan Edit (Update) saja namanya jika ada perubahan.');
|
||||
}
|
||||
|
||||
// jika lolos gass lanjut hapus heheee
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
$sub = SubKriteria::findOrFail($id);
|
||||
$k_id = $sub->kriteria_id;
|
||||
|
||||
// 1. Validasi: Jangan biarkan kriteria tidak punya subkriteria sama sekali
|
||||
$count = SubKriteria::where('kriteria_id', $k_id)->count();
|
||||
if ($count <= 1) {
|
||||
return redirect()->back()->with('error', 'Gagal! Kriteria wajib memiliki minimal satu sub-kriteria.');
|
||||
}
|
||||
|
||||
// 2. Antisipasi data warga: Pindahkan warga yang memilih sub ini ke sub lain yang tersisa
|
||||
$subLain = SubKriteria::where('kriteria_id', $k_id)->where('id', '!=', $id)->first();
|
||||
DB::table('warga_details')
|
||||
->where('sub_kriteria_id', $id)
|
||||
->update(['sub_kriteria_id' => $subLain->id]);
|
||||
|
||||
// 3. Hapus Subkriteria
|
||||
$sub->delete();
|
||||
|
||||
// 4. Reset bobot lokal semua subkriteria yang tersisa di kriteria ini
|
||||
SubKriteria::where('kriteria_id', $k_id)->update(['bobot_lokal' => 0]);
|
||||
|
||||
// 5. Rapikan kode S.C1.1 dst
|
||||
$this->refreshSubKriteriaCodes($k_id);
|
||||
|
||||
DB::commit();
|
||||
return redirect()->route('subkriteria.index')->with('success', 'Sub-Kriteria dihapus & Bobot lokal direset!');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return redirect()->back()->with('error', 'Terjadi kesalahan: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
|
||||
// $users = User::paginate(10);
|
||||
// Pagination default 10 per halaman
|
||||
public function index(Request $request)
|
||||
{
|
||||
// Tangkap request 'per_page', default-nya 10, bisa dipilih 10, 25, 50, atau 100
|
||||
$perPage = $request->input('per_page', 10);
|
||||
|
||||
// Pagination dengan nilai dinamis, dan tambahkan 'appends' agar parameter di URL tidak hilang saat pindah halaman
|
||||
$users = User::query()->paginate($perPage)->appends($request->query());
|
||||
|
||||
return view('admin.index', compact('users', 'perPage'));
|
||||
}
|
||||
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'nama_lengkap' => 'required',
|
||||
'username' => 'required|unique:users',
|
||||
'password' => 'required|min:6',
|
||||
'alamat' => 'required',
|
||||
'role' => 'required'
|
||||
]);
|
||||
|
||||
User::create([
|
||||
'nama_lengkap' => $request->nama_lengkap,
|
||||
'username' => $request->username,
|
||||
'password' => Hash::make($request->password),
|
||||
'alamat' => $request->alamat,
|
||||
'role' => $request->role,
|
||||
'status' => 'aktif',
|
||||
]);
|
||||
|
||||
return redirect()->route('users.index')->with('success', 'User berhasil ditambahkan');
|
||||
}
|
||||
|
||||
public function edit(User $user)
|
||||
{
|
||||
return view('admin.edit', compact('user'));
|
||||
}
|
||||
|
||||
public function update(Request $request, User $user)
|
||||
{
|
||||
$request->validate([
|
||||
'nama_lengkap' => 'required',
|
||||
'username' => 'required|unique:users,username,'.$user->id,
|
||||
'alamat' => 'required',
|
||||
'role' => 'required'
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'nama_lengkap' => $request->nama_lengkap,
|
||||
'username' => $request->username,
|
||||
'alamat' => $request->alamat,
|
||||
'role' => $request->role,
|
||||
];
|
||||
|
||||
// Update password hanya jika diisi
|
||||
if ($request->filled('password')) {
|
||||
$data['password'] = Hash::make($request->password);
|
||||
}
|
||||
|
||||
$user->update($data);
|
||||
return redirect()->route('users.index')->with('success', 'User berhasil diperbarui');
|
||||
}
|
||||
|
||||
public function toggleStatus(User $user)
|
||||
{
|
||||
// 1. Cegah matikan akun sendiri
|
||||
if (Auth::id() === $user->id) {
|
||||
return back()->with('error', 'Anda tidak dapat menonaktifkan akun Anda sendiri!');
|
||||
}
|
||||
|
||||
// 2. Cegah mematikan Admin terakhir
|
||||
if ($user->role === 'admin' && $user->status === 'aktif') {
|
||||
$jumlahAdminAktif = User::where('role', 'admin')->where('status', 'aktif')->count();
|
||||
if ($jumlahAdminAktif <= 1) {
|
||||
return back()->with('error', 'Sistem menolak! Harus tersisa minimal 1 akun Admin yang aktif.');
|
||||
}
|
||||
}
|
||||
|
||||
// Balikkan status
|
||||
$statusBaru = $user->status === 'aktif' ? 'nonaktif' : 'aktif';
|
||||
$user->update(['status' => $statusBaru]);
|
||||
|
||||
$pesan = $statusBaru === 'aktif'
|
||||
? "Akun {$user->username} berhasil diaktifkan!"
|
||||
: "Akun {$user->username} berhasil dinonaktifkan!";
|
||||
|
||||
return back()->with('success', $pesan);
|
||||
}
|
||||
|
||||
public function destroy(User $user)
|
||||
{
|
||||
// 1. Cegah hapus akun sendiri
|
||||
if (Auth::id() === $user->id) {
|
||||
return back()->with('error', 'Anda tidak dapat menghapus akun Anda sendiri!');
|
||||
}
|
||||
|
||||
// 2. Cegah hapus Admin terakhir
|
||||
if ($user->role === 'admin') {
|
||||
$jumlahAdmin = User::where('role', 'admin')->count();
|
||||
if ($jumlahAdmin <= 1) {
|
||||
return back()->with('error', 'Sistem menolak! Harus tersisa minimal 1 akun Admin di dalam database.');
|
||||
}
|
||||
}
|
||||
|
||||
$user->delete();
|
||||
return back()->with('success', 'Data pengguna berhasil dihapus!');
|
||||
}
|
||||
|
||||
// FUNGSI BARU: Mereset Password
|
||||
public function resetPassword(User $user)
|
||||
{
|
||||
// Proteksi ganda: Pastikan hanya admin yang bisa melakukan eksekusi ini
|
||||
if (Auth::user()->role !== 'admin') {
|
||||
return redirect()->back()->with('error', 'Anda tidak memiliki akses untuk reset password.');
|
||||
}
|
||||
|
||||
// Set password kembali ke default: '123456'
|
||||
$user->update([
|
||||
'password' => Hash::make('123456')
|
||||
]);
|
||||
|
||||
return redirect()->route('users.index')->with('success', 'Password pengguna ' . $user->username . ' berhasil direset menjadi: 123456');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Warga;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class VerifikasiController extends Controller
|
||||
{
|
||||
/**
|
||||
* Menampilkan daftar warga (Antrean & Riwayat)
|
||||
*/
|
||||
/**
|
||||
* Menampilkan daftar warga (Antrean & Riwayat)
|
||||
*/
|
||||
public function verifikasiIndex(Request $request)
|
||||
{
|
||||
// Menangkap request parameter
|
||||
$tab = $request->query('tab', 'pending');
|
||||
$perPage = $request->query('per_page', 10);
|
||||
$search = $request->query('search'); // Menangkap kata kunci pencarian
|
||||
|
||||
// Inisialisasi Query dasar
|
||||
$query = Warga::query();
|
||||
|
||||
// 1. Filter berdasarkan Tab (Antrean / Riwayat)
|
||||
if ($tab == 'riwayat') {
|
||||
$query->with('verifikator')
|
||||
->whereIn('status_verifikasi', ['setuju', 'tolak'])
|
||||
->latest('updated_at');
|
||||
} else {
|
||||
$query->where('status_verifikasi', 'pending')
|
||||
->latest();
|
||||
}
|
||||
|
||||
// 2. Logika Pencarian (Search)
|
||||
if (!empty($search)) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('nama', 'LIKE', "%{$search}%")
|
||||
->orWhere('nik', 'LIKE', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
// 3. Eksekusi Paginate
|
||||
$wargas = $query->paginate($perPage);
|
||||
|
||||
// Appends berguna agar saat pindah halaman/tab, parameter tidak hilang
|
||||
$wargas->appends([
|
||||
'tab' => $tab,
|
||||
'per_page' => $perPage,
|
||||
'search' => $search
|
||||
]);
|
||||
|
||||
return view('verifikator.index', compact('wargas', 'tab', 'perPage', 'search'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Menampilkan detail dokumen dan kriteria warga
|
||||
*/
|
||||
public function verifikasiShow($id)
|
||||
{
|
||||
$warga = Warga::with(['details.kriteria', 'details.subKriteria', 'verifikator'])->findOrFail($id);
|
||||
|
||||
return view('verifikator.show', compact('warga'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Menyimpan keputusan verifikator SATUAN (Setuju/Tolak)
|
||||
*/
|
||||
public function verifikasiProses(Request $request, $id)
|
||||
{
|
||||
$request->validate([
|
||||
'status' => 'required|in:setuju,tolak',
|
||||
'catatan' => 'nullable|string|max:500',
|
||||
]);
|
||||
|
||||
$warga = Warga::findOrFail($id);
|
||||
|
||||
$warga->update([
|
||||
'status_verifikasi' => $request->status,
|
||||
'catatan' => $request->catatan,
|
||||
'verified_by' => Auth::id(), // Menyimpan ID verifikator
|
||||
]);
|
||||
|
||||
$pesan = $request->status == 'setuju' ? 'Data berhasil disetujui!' : 'Data telah ditolak.';
|
||||
|
||||
return redirect()->route('verifikasi.index', ['tab' => 'pending'])->with('success', $pesan);
|
||||
}
|
||||
|
||||
/**
|
||||
* Menyimpan keputusan verifikator MASSAL (Setuju/Tolak)
|
||||
*/
|
||||
public function verifikasiMassal(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'warga_ids' => 'required|array|min:1',
|
||||
'action' => 'required|in:setuju,tolak',
|
||||
], [
|
||||
'warga_ids.required' => 'Pilih minimal satu data warga untuk diverifikasi massal.',
|
||||
]);
|
||||
|
||||
// Update banyak data sekaligus
|
||||
Warga::whereIn('id', $request->warga_ids)->update([
|
||||
'status_verifikasi' => $request->action,
|
||||
'catatan' => 'Diverifikasi secara massal oleh sistem.',
|
||||
'verified_by' => Auth::id(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$jumlah = count($request->warga_ids);
|
||||
$pesan = $request->action == 'setuju' ? "$jumlah data berhasil disetujui massal!" : "$jumlah data ditolak massal.";
|
||||
|
||||
return redirect()->route('verifikasi.index', ['tab' => 'pending'])->with('success', $pesan);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,389 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Exports\TemplateWargaExport;
|
||||
use App\Exports\WargaExport;
|
||||
use App\Imports\WargaImport; // <-- PASTIKAN INI ADA
|
||||
use App\Models\Kriteria;
|
||||
use App\Models\SubKriteria;
|
||||
use App\Models\Warga;
|
||||
use App\Models\WargaDetail;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class WargaController extends Controller
|
||||
{
|
||||
/**
|
||||
* Menampilkan daftar warga dengan pagination.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$perPage = $request->get('per_page', 10);
|
||||
$kriterias = Kriteria::orderBy('kode', 'asc')->get();
|
||||
|
||||
// Eager loading 'details' untuk menghindari N+1 Query saat looping di tabel
|
||||
$query = Warga::with(['details.kriteria', 'details.subKriteria']);
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$search = $request->search;
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('nama', 'LIKE', "%$search%")
|
||||
->orWhere('nik', 'LIKE', "%$search%");
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->filled('rt')) {
|
||||
$query->where('rt', str_pad($request->rt, 3, '0', STR_PAD_LEFT));
|
||||
}
|
||||
|
||||
if ($request->filled('rw')) {
|
||||
$query->where('rw', str_pad($request->rw, 3, '0', STR_PAD_LEFT));
|
||||
}
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status_verifikasi', $request->status);
|
||||
}
|
||||
|
||||
foreach ($kriterias as $k) {
|
||||
$filterKey = 'f_kriteria_'.$k->id;
|
||||
if ($request->filled($filterKey)) {
|
||||
$nilaiFilter = $request->get($filterKey);
|
||||
$query->whereHas('details', function ($q) use ($k, $nilaiFilter) {
|
||||
$q->where('kriteria_id', $k->id)
|
||||
->where('nilai_asli', $nilaiFilter);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$wargas = $query->latest()->paginate($perPage)->appends($request->all());
|
||||
|
||||
return view('warga.index', compact('wargas', 'kriterias'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Form tambah warga.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$kriterias = Kriteria::with('subKriterias')->orderBy('kode', 'asc')->get();
|
||||
|
||||
return view('warga.create', compact('kriterias'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Menyimpan data warga manual (Identitas + Kriteria Dinamis + Files).
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
// 1. Validasi Identitas Dasar & Dokumen
|
||||
$rules = [
|
||||
'nik' => 'required|digits:16|unique:wargas,nik',
|
||||
'nama' => 'required|string|max:255',
|
||||
'alamat' => 'required',
|
||||
'rt' => 'required|max:3',
|
||||
'rw' => 'required|max:3',
|
||||
'files' => 'nullable|array',
|
||||
'files.*' => 'nullable|mimes:jpg,jpeg,png,pdf|max:2048',
|
||||
];
|
||||
|
||||
// 2. Validasi Dinamis untuk Input Kriteria
|
||||
$kriterias = Kriteria::all();
|
||||
foreach ($kriterias as $k) {
|
||||
$rules['kriteria_'.$k->id] = 'required';
|
||||
}
|
||||
|
||||
$request->validate($rules);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
// 3. Handling Multiple File Upload
|
||||
$paths = [];
|
||||
if ($request->hasFile('files')) {
|
||||
foreach ($request->file('files') as $file) {
|
||||
$paths[] = $file->store('dokumen_warga', 'public');
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Simpan Data Utama Warga
|
||||
$warga = Warga::create([
|
||||
'nik' => $request->nik,
|
||||
'nama' => $request->nama,
|
||||
'alamat' => $request->alamat,
|
||||
'rt' => $request->rt,
|
||||
'rw' => $request->rw,
|
||||
'dokumen_pendukung' => $paths,
|
||||
'status_verifikasi' => 'pending',
|
||||
'status_bansos_riil' => 'aktif',
|
||||
]);
|
||||
|
||||
// 5. Simpan Detail Kriteria
|
||||
$this->saveWargaDetails($warga, $request, $kriterias);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return redirect()->route('warga.index')->with('success', 'Data Warga Berhasil Ditambahkan!');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
Log::error('Error Store Warga: '.$e->getMessage());
|
||||
|
||||
return redirect()->back()->withInput()->with('error', 'Gagal menyimpan data: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Import Data dari Excel/CSV.
|
||||
*/
|
||||
public function importExcel(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'file_excel' => 'required|mimes:xlsx,xls,csv|max:10240',
|
||||
]);
|
||||
|
||||
try {
|
||||
Excel::import(new WargaImport, $request->file('file_excel'));
|
||||
|
||||
return redirect()->route('warga.index')->with('success', 'Import Data Berhasil!');
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error Import Warga: '.$e->getMessage());
|
||||
|
||||
return redirect()->back()->with('error', 'Gagal Import: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Form Edit Warga.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$warga = Warga::with('details')->findOrFail($id);
|
||||
$kriterias = Kriteria::with('subKriterias')->orderBy('kode', 'asc')->get();
|
||||
|
||||
return view('warga.edit', compact('warga', 'kriterias'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update data warga.
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$warga = Warga::findOrFail($id);
|
||||
|
||||
$rules = [
|
||||
'nik' => 'required|digits:16|unique:wargas,nik,'.$id,
|
||||
'nama' => 'required|string|max:255',
|
||||
'alamat' => 'required',
|
||||
'rt' => 'required|max:3',
|
||||
'rw' => 'required|max:3',
|
||||
'files.*' => 'nullable|mimes:jpg,jpeg,png,pdf|max:2048',
|
||||
'status_bansos_riil' => 'required|in:aktif,meninggal,pindah,mampu',
|
||||
];
|
||||
|
||||
$kriterias = Kriteria::all();
|
||||
foreach ($kriterias as $k) {
|
||||
$rules['kriteria_'.$k->id] = 'required';
|
||||
}
|
||||
|
||||
$request->validate($rules);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$paths = is_array($warga->dokumen_pendukung) ? $warga->dokumen_pendukung : [];
|
||||
|
||||
if ($request->has('hapus_dokumen')) {
|
||||
foreach ($request->hapus_dokumen as $fileToDelete) {
|
||||
Storage::disk('public')->delete($fileToDelete);
|
||||
}
|
||||
$paths = array_diff($paths, [$fileToDelete]);
|
||||
}
|
||||
|
||||
if ($request->hasFile('files')) {
|
||||
foreach ($request->file('files') as $file) {
|
||||
$path = $file->store('dokumen_warga', 'public');
|
||||
$paths[] = $path;
|
||||
}
|
||||
}
|
||||
|
||||
// --- LOGIKA CERDAS: ALUR PENOLAKAN ---
|
||||
$statusBaru = $warga->status_verifikasi;
|
||||
$catatanBaru = $warga->catatan;
|
||||
$verifikatorBaru = $warga->verified_by;
|
||||
|
||||
// Jika sebelumnya ditolak, lalu datanya diperbaiki, kembalikan ke antrean verifikasi
|
||||
if ($warga->status_verifikasi === 'tolak') {
|
||||
$statusBaru = 'pending';
|
||||
$catatanBaru = null;
|
||||
$verifikatorBaru = null;
|
||||
}
|
||||
// -------------------------------------
|
||||
|
||||
$warga->update([
|
||||
'nik' => $request->nik,
|
||||
'nama' => $request->nama,
|
||||
'alamat' => $request->alamat,
|
||||
'rt' => str_pad($request->rt, 3, '0', STR_PAD_LEFT),
|
||||
'rw' => str_pad($request->rw, 3, '0', STR_PAD_LEFT),
|
||||
'dokumen_pendukung' => array_values($paths),
|
||||
'status_verifikasi' => $statusBaru,
|
||||
'catatan' => $catatanBaru,
|
||||
'verified_by' => $verifikatorBaru,
|
||||
'status_bansos_riil' => $request->status_bansos_riil,
|
||||
]);
|
||||
|
||||
$this->saveWargaDetails($warga, $request, $kriterias, true);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return redirect()->route('warga.index')->with('success', 'Data Berhasil Diperbarui!');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
Log::error('Error Update Warga: '.$e->getMessage());
|
||||
|
||||
return redirect()->back()->with('error', 'Gagal update: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function bulkUpdate(Request $request)
|
||||
{
|
||||
// 1. Validasi input
|
||||
$request->validate([
|
||||
'ids' => 'required|string', // Kita kirim string ID yang dipisah koma dari JS
|
||||
'kriteria_id' => 'required|exists:kriterias,id',
|
||||
'sub_kriteria_id' => 'required|exists:sub_kriterias,id'
|
||||
]);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
// Ubah string "1,2,3" menjadi array [1,2,3]
|
||||
$idsArray = explode(',', $request->ids);
|
||||
$sub = SubKriteria::findOrFail($request->sub_kriteria_id);
|
||||
|
||||
// 2. Eksekusi Update Massal
|
||||
WargaDetail::whereIn('warga_id', $idsArray)
|
||||
->where('kriteria_id', $request->kriteria_id)
|
||||
->update([
|
||||
'sub_kriteria_id' => $sub->id,
|
||||
'nilai_asli' => $sub->nama_sub
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
return redirect()->back()->with('success', count($idsArray) . ' Data warga berhasil di-update secara massal!');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return redirect()->back()->with('error', 'Gagal update massal: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method Privat: Logika simpan detail kriteria.
|
||||
*/
|
||||
private function saveWargaDetails($warga, $request, $kriterias, $isUpdate = false)
|
||||
{
|
||||
foreach ($kriterias as $k) {
|
||||
$nilaiInput = $request->input('kriteria_'.$k->id);
|
||||
|
||||
$sub = SubKriteria::where('kriteria_id', $k->id)
|
||||
->where('nama_sub', $nilaiInput)
|
||||
->first();
|
||||
|
||||
$dataDetail = [
|
||||
'sub_kriteria_id' => $sub ? $sub->id : null,
|
||||
'nilai_asli' => $nilaiInput,
|
||||
];
|
||||
|
||||
if ($isUpdate) {
|
||||
WargaDetail::updateOrCreate(
|
||||
['warga_id' => $warga->id, 'kriteria_id' => $k->id],
|
||||
$dataDetail
|
||||
);
|
||||
} else {
|
||||
WargaDetail::create(array_merge([
|
||||
'warga_id' => $warga->id,
|
||||
'kriteria_id' => $k->id,
|
||||
], $dataDetail));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download Template XLSX Dinamis.
|
||||
*/
|
||||
public function downloadTemplate()
|
||||
{
|
||||
// Pastikan facade Excel diimport (use Maatwebsite\Excel\Facades\Excel;)
|
||||
return Excel::download(new TemplateWargaExport, 'template_import_warga.xlsx');
|
||||
}
|
||||
|
||||
public function exportExcel(Request $request)
|
||||
{
|
||||
$nama_file = 'Data_Warga_'.date('d-m-Y_H-i').'.xlsx';
|
||||
|
||||
return Excel::download(new WargaExport($request), $nama_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus Data Warga beserta filenya.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
$warga = Warga::findOrFail($id);
|
||||
if ($warga->dokumen_pendukung) {
|
||||
foreach ($warga->dokumen_pendukung as $file) {
|
||||
Storage::disk('public')->delete($file);
|
||||
}
|
||||
}
|
||||
$warga->delete();
|
||||
|
||||
return redirect()->route('warga.index')->with('success', 'Data Warga Berhasil Dihapus!');
|
||||
} catch (\Exception $e) {
|
||||
return redirect()->back()->with('error', 'Gagal menghapus data.');
|
||||
}
|
||||
}
|
||||
|
||||
public function bulkDelete(Request $request)
|
||||
{
|
||||
// 1. Validasi input
|
||||
$request->validate([
|
||||
'ids' => 'required|string', // String ID yang dipisah koma
|
||||
]);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
// Ubah string "1,2,3" menjadi array [1,2,3]
|
||||
$idsArray = explode(',', $request->ids);
|
||||
|
||||
// Ambil data warga
|
||||
$wargas = Warga::whereIn('id', $idsArray)->get();
|
||||
|
||||
// Lakukan looping hapus agar file fisik dan detailnya ikut terhapus
|
||||
foreach ($wargas as $warga) {
|
||||
if ($warga->dokumen_pendukung) {
|
||||
foreach ($warga->dokumen_pendukung as $file) {
|
||||
Storage::disk('public')->delete($file);
|
||||
}
|
||||
}
|
||||
// Hapus warga (akan otomatis menghapus detail & hasil seleksi berkat fungsi boot di Model)
|
||||
$warga->delete();
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
return redirect()->back()->with('success', count($idsArray) . ' Data warga berhasil dihapus massal!');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return redirect()->back()->with('error', 'Gagal menghapus massal: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array<int, class-string|string>
|
||||
*/
|
||||
protected $middleware = [
|
||||
// \App\Http\Middleware\TrustHosts::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Illuminate\Http\Middleware\HandleCors::class,
|
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array<string, array<int, class-string|string>>
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
|
||||
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's middleware aliases.
|
||||
*
|
||||
* Aliases may be used instead of class names to conveniently assign middleware to routes and groups.
|
||||
*
|
||||
* @var array<string, class-string|string>
|
||||
*/
|
||||
protected $middlewareAliases = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
|
||||
'precognitive' => \Illuminate\Foundation\Http\Middleware\HandlePrecognitiveRequests::class,
|
||||
'signed' => \App\Http\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
'checkRole' => \App\Http\Middleware\CheckRole::class,
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*/
|
||||
protected function redirectTo(Request $request): ?string
|
||||
{
|
||||
return $request->expectsJson() ? null : route('login');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CheckRole
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ...$roles): Response
|
||||
{
|
||||
if (!Auth::check()) {
|
||||
return redirect('/login');
|
||||
}
|
||||
|
||||
// 2. Ambil role user saat ini
|
||||
$userRole = Auth::user()->role;
|
||||
|
||||
// 3. Cek apakah role user ada di dalam daftar roles yang diizinkan
|
||||
if (in_array($userRole, $roles)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// Jika tidak cocok, lempar error 403
|
||||
abort(403, 'Anda tidak memiliki akses ke halaman ini.');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
|
||||
|
||||
class PreventRequestsDuringMaintenance extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
// use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, string ...$guards): Response
|
||||
{
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
// return redirect(RouteServiceProvider::HOME);
|
||||
if (Auth::user()->role === 'admin') {
|
||||
return redirect()->route('admin.dashboard');
|
||||
} elseif (Auth::user()->role === 'verifikator') {
|
||||
return redirect()->route('verifikator.dashboard');
|
||||
}
|
||||
|
||||
// Jaga-jaga kalau role tidak terdeteksi
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
'current_password',
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||
|
||||
class TrustHosts extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the host patterns that should be trusted.
|
||||
*
|
||||
* @return array<int, string|null>
|
||||
*/
|
||||
public function hosts(): array
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array<int, string>|string|null
|
||||
*/
|
||||
protected $proxies;
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers =
|
||||
Request::HEADER_X_FORWARDED_FOR |
|
||||
Request::HEADER_X_FORWARDED_HOST |
|
||||
Request::HEADER_X_FORWARDED_PORT |
|
||||
Request::HEADER_X_FORWARDED_PROTO |
|
||||
Request::HEADER_X_FORWARDED_AWS_ELB;
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Routing\Middleware\ValidateSignature as Middleware;
|
||||
|
||||
class ValidateSignature extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the query string parameters that should be ignored.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
// 'fbclid',
|
||||
// 'utm_campaign',
|
||||
// 'utm_content',
|
||||
// 'utm_medium',
|
||||
// 'utm_source',
|
||||
// 'utm_term',
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
namespace App\Imports;
|
||||
|
||||
use App\Models\Kriteria;
|
||||
use App\Models\SubKriteria;
|
||||
use App\Models\Warga;
|
||||
use App\Models\WargaDetail;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Concerns\ToModel;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
|
||||
use Maatwebsite\Excel\Concerns\WithBatchInserts;
|
||||
use Maatwebsite\Excel\Concerns\WithChunkReading;
|
||||
|
||||
class WargaImport implements ToModel, WithHeadingRow, SkipsEmptyRows, WithBatchInserts, WithChunkReading
|
||||
{
|
||||
public function model(array $row)
|
||||
{
|
||||
// 1. Validasi: Abaikan jika NIK tidak ada/kosong
|
||||
if (!isset($row['nik']) || empty($row['nik'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 2. Filter: Abaikan jika ini baris contoh atau instruksi dari template
|
||||
// str_contains memastikan kita tidak memasukkan data dummy 'Contoh: 3512...'
|
||||
$nikValue = strtolower((string)$row['nik']);
|
||||
if (str_contains($nikValue, 'contoh') || str_contains($nikValue, '3512')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Menggunakan Database Transaction agar jika satu detail gagal, semua dibatalkan (aman)
|
||||
return DB::transaction(function () use ($row) {
|
||||
|
||||
// Bersihkan data NIK dari spasi yang tidak sengaja terketik
|
||||
$nik = trim((string) $row['nik']);
|
||||
|
||||
/*
|
||||
| 3. SIMPAN/UPDATE DATA WARGA
|
||||
| Menggunakan updateOrCreate agar jika NIK sudah ada, data lama diperbarui
|
||||
| bukannya membuat data duplikat yang menyebabkan error.
|
||||
*/
|
||||
$warga = Warga::updateOrCreate(
|
||||
['nik' => $nik],
|
||||
[
|
||||
'nama' => $row['nama'] ?? '-',
|
||||
'alamat' => $row['alamat'] ?? '-',
|
||||
// str_pad memastikan RT/RW selalu 3 digit (misal: 1 jadi 001)
|
||||
'rt' => str_pad($row['rt'] ?? '0', 3, '0', STR_PAD_LEFT),
|
||||
'rw' => str_pad($row['rw'] ?? '0', 3, '0', STR_PAD_LEFT),
|
||||
'status_verifikasi' => 'pending',
|
||||
'status_bansos_riil' => 'aktif',
|
||||
]
|
||||
);
|
||||
|
||||
// 4. PROSES DETAIL KRITERIA (DINAMIS)
|
||||
$kriterias = Kriteria::all();
|
||||
foreach ($kriterias as $k) {
|
||||
$kode = strtolower($k->kode); // Misal: c1
|
||||
|
||||
// Mencari header kolom excel yang cocok dengan kode kriteria
|
||||
$keyFound = null;
|
||||
foreach ($row as $key => $val) {
|
||||
if (str_starts_with(strtolower($key), $kode)) {
|
||||
$keyFound = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($keyFound) {
|
||||
$nilaiExcel = trim((string)$row[$keyFound]);
|
||||
|
||||
// Lewati jika teksnya masih instruksi bawaan template "PILIH: [...]"
|
||||
if (str_starts_with(strtolower($nilaiExcel), 'pilih:')) continue;
|
||||
|
||||
// Mencari ID SubKriteria berdasarkan teks yang tertulis di sel Excel
|
||||
$sub = SubKriteria::where('kriteria_id', $k->id)
|
||||
->where('nama_sub', $nilaiExcel)
|
||||
->first();
|
||||
|
||||
/*
|
||||
| Hanya simpan jika SubKriteria ditemukan di database.
|
||||
| Ini mencegah error "Integrity constraint violation" jika teks Excel salah.
|
||||
*/
|
||||
if ($sub) {
|
||||
WargaDetail::updateOrCreate(
|
||||
['warga_id' => $warga->id, 'kriteria_id' => $k->id],
|
||||
['sub_kriteria_id' => $sub->id, 'nilai_asli' => $nilaiExcel]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
| 5. RETURN NULL
|
||||
| Sangat Penting! Memberitahu Laravel Excel bahwa kita sudah menyimpan
|
||||
| data secara manual di atas, sehingga sistem tidak mencoba melakukan
|
||||
| insert otomatis kedua kalinya yang memicu error "Duplicate Entry".
|
||||
*/
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| PENGATURAN LIMITASI & PERFORMA
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* batchSize:
|
||||
* Menentukan berapa banyak data yang diproses dalam satu "tembakan" SQL.
|
||||
* Angka 500-1000 sangat ideal untuk menghemat kinerja database.
|
||||
*/
|
||||
public function batchSize(): int
|
||||
{
|
||||
return 500;
|
||||
}
|
||||
|
||||
/**
|
||||
* chunkSize:
|
||||
* Membaca file Excel per 500 baris.
|
||||
* Tanpa ini, jika Anda upload 1000 data, server akan mencoba membaca semuanya
|
||||
* sekaligus ke memori RAM yang bisa menyebabkan "Memory Exhausted".
|
||||
*/
|
||||
public function chunkSize(): int
|
||||
{
|
||||
return 500;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Berita extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class HasilSeleksi extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['periode_id', 'warga_id', 'skor_akhir', 'ranking', 'status_keputusan'];
|
||||
|
||||
public function periode()
|
||||
{
|
||||
return $this->belongsTo(Periode::class);
|
||||
}
|
||||
|
||||
public function warga()
|
||||
{
|
||||
return $this->belongsTo(Warga::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Kriteria extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['kode', 'nama', 'bobot_global'];
|
||||
|
||||
public function subKriterias()
|
||||
{
|
||||
return $this->hasMany(SubKriteria::class)->orderBy('bobot_lokal', 'desc');
|
||||
}
|
||||
|
||||
public function wargaDetails()
|
||||
{
|
||||
return $this->hasMany(WargaDetail::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Pengaturan extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
'nama_pengaturan',
|
||||
'nilai_pengaturan',
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Pengumuman extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $table = 'pengumumen';
|
||||
protected $fillable = [
|
||||
'judul',
|
||||
'deskripsi',
|
||||
'foto',
|
||||
'status'
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Perbandingan extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['pakar_ke', 'kriteria_kiri_id', 'kriteria_kanan_id', 'nilai_skala'];
|
||||
|
||||
public function kriteriaKiri()
|
||||
{
|
||||
return $this->belongsTo(Kriteria::class, 'kriteria_kiri_id');
|
||||
}
|
||||
|
||||
public function kriteriaKanan()
|
||||
{
|
||||
return $this->belongsTo(Kriteria::class, 'kriteria_kanan_id');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PerbandinganSub extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['pakar_ke', 'kriteria_id', 'sub_kiri_id', 'sub_kanan_id', 'nilai_skala'];
|
||||
|
||||
public function kriteria()
|
||||
{
|
||||
return $this->belongsTo(Kriteria::class);
|
||||
}
|
||||
|
||||
public function subKiri()
|
||||
{
|
||||
return $this->belongsTo(SubKriteria::class, 'sub_kiri_id');
|
||||
}
|
||||
|
||||
public function subKanan()
|
||||
{
|
||||
return $this->belongsTo(SubKriteria::class, 'sub_kanan_id');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Periode extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['nama_periode', 'kuota', 'is_aktif'];
|
||||
|
||||
public function hasilSeleksis()
|
||||
{
|
||||
return $this->hasMany(HasilSeleksi::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProfilDesa extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
'sejarah_singkat',
|
||||
'visi',
|
||||
'misi',
|
||||
'nama_kepala_desa',
|
||||
'foto_kepala_desa'
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SubKriteria extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = ['kriteria_id', 'kode','nama_sub', 'nilai_acuan', 'bobot_lokal'];
|
||||
|
||||
public function kriteria()
|
||||
{
|
||||
return $this->belongsTo(Kriteria::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'nama_lengkap',
|
||||
'username',
|
||||
'password',
|
||||
'alamat',
|
||||
'role',
|
||||
'status',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
|
||||
public function wargaTerverifikasi()
|
||||
{
|
||||
return $this->hasMany(Warga::class, 'verified_by');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Warga extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'nik', 'nama', 'alamat', 'rt', 'rw',
|
||||
'dokumen_pendukung', 'status_verifikasi', 'catatan',
|
||||
'verified_by', 'status_bansos_riil',
|
||||
];
|
||||
|
||||
protected $casts = ['dokumen_pendukung' => 'array'];
|
||||
|
||||
protected static function boot() {
|
||||
parent::boot();
|
||||
static::deleting(function($warga) {
|
||||
// 1. Hapus nilai detail kuesionernya (C1-C6)
|
||||
$warga->details()->delete();
|
||||
|
||||
// 2. Hapus riwayat rankingnya di Hasil Seleksi
|
||||
$warga->hasilSeleksis()->delete();
|
||||
});
|
||||
}
|
||||
|
||||
public function details()
|
||||
{
|
||||
return $this->hasMany(WargaDetail::class);
|
||||
}
|
||||
|
||||
public function hasilSeleksis()
|
||||
{
|
||||
return $this->hasMany(HasilSeleksi::class);
|
||||
}
|
||||
|
||||
public function verifikator()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'verified_by');
|
||||
}
|
||||
|
||||
public function getDetailByKriteria($kriteriaId)
|
||||
{
|
||||
return $this->details()->where('kriteria_id', $kriteriaId)->first();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WargaDetail extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['warga_id', 'kriteria_id', 'sub_kriteria_id', 'nilai_asli'];
|
||||
|
||||
public function warga()
|
||||
{
|
||||
return $this->belongsTo(Warga::class);
|
||||
}
|
||||
|
||||
public function kriteria()
|
||||
{
|
||||
return $this->belongsTo(Kriteria::class);
|
||||
}
|
||||
|
||||
public function subKriteria()
|
||||
{
|
||||
return $this->belongsTo(SubKriteria::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
Paginator::useBootstrap();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
// use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The model to policy mappings for the application.
|
||||
*
|
||||
* @var array<class-string, class-string>
|
||||
*/
|
||||
protected $policies = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any authentication / authorization services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class BroadcastServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
Broadcast::routes();
|
||||
|
||||
require base_path('routes/channels.php');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event to listener mappings for the application.
|
||||
*
|
||||
* @var array<class-string, array<int, class-string>>
|
||||
*/
|
||||
protected $listen = [
|
||||
Registered::class => [
|
||||
SendEmailVerificationNotification::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if events and listeners should be automatically discovered.
|
||||
*/
|
||||
public function shouldDiscoverEvents(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The path to your application's "home" route.
|
||||
*
|
||||
* Typically, users are redirected here after authentication.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const HOME = '/home';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, and other route configuration.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
|
||||
});
|
||||
|
||||
$this->routes(function () {
|
||||
Route::middleware('api')
|
||||
->prefix('api')
|
||||
->group(base_path('routes/api.php'));
|
||||
|
||||
Route::middleware('web')
|
||||
->group(base_path('routes/web.php'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\Warga; // Pastikan model Warga sudah ada
|
||||
|
||||
class ViewServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function boot(): void
|
||||
{
|
||||
// View Composer akan mengirimkan data ke layout/app (atau file layout utama kamu)
|
||||
View::composer('layout.app', function ($view) {
|
||||
if (Auth::check()) {
|
||||
$user = Auth::user();
|
||||
$notifCount = 0;
|
||||
$notifData = collect();
|
||||
$notifTitle = "";
|
||||
|
||||
if ($user->role == 'admin') {
|
||||
// Admin melihat warga yang statusnya Ditolak dan butuh edit
|
||||
$query = Warga::where('status_verifikasi', 'tolak');
|
||||
$notifCount = $query->count();
|
||||
$notifData = $query->latest()->take(5)->get();
|
||||
$notifTitle = "Data Perlu Perbaikan";
|
||||
} elseif ($user->role == 'verifikator') {
|
||||
// Verifikator melihat warga yang masih Pending (perlu disetujui)
|
||||
$query = Warga::where('status_verifikasi', 'pending');
|
||||
$notifCount = $query->count();
|
||||
$notifData = $query->latest()->take(5)->get();
|
||||
$notifTitle = "Menunggu Persetujuan";
|
||||
}
|
||||
|
||||
$view->with([
|
||||
'notifCount' => $notifCount,
|
||||
'notifData' => $notifData,
|
||||
'notifTitle' => $notifTitle
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
define('LARAVEL_START', microtime(true));
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register The Auto Loader
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Composer provides a convenient, automatically generated class loader
|
||||
| for our application. We just need to utilize it! We'll require it
|
||||
| into the script here so that we do not have to worry about the
|
||||
| loading of any of our classes manually. It's great to relax.
|
||||
|
|
||||
*/
|
||||
|
||||
require __DIR__.'/vendor/autoload.php';
|
||||
|
||||
$app = require_once __DIR__.'/bootstrap/app.php';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Run The Artisan Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When we run the console application, the current CLI command will be
|
||||
| executed in this console and the response sent back to a terminal
|
||||
| or another output device for the developers. Here goes nothing!
|
||||
|
|
||||
*/
|
||||
|
||||
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
|
||||
|
||||
$status = $kernel->handle(
|
||||
$input = new Symfony\Component\Console\Input\ArgvInput,
|
||||
new Symfony\Component\Console\Output\ConsoleOutput
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Shutdown The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Once Artisan has finished running, we will fire off the shutdown events
|
||||
| so that any final work may be done by the application before we shut
|
||||
| down the process. This is the last thing to happen to the request.
|
||||
|
|
||||
*/
|
||||
|
||||
$kernel->terminate($input, $status);
|
||||
|
||||
exit($status);
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Create The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The first thing we will do is create a new Laravel application instance
|
||||
| which serves as the "glue" for all the components of Laravel, and is
|
||||
| the IoC container for the system binding all of the various parts.
|
||||
|
|
||||
*/
|
||||
|
||||
$app = new Illuminate\Foundation\Application(
|
||||
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Bind Important Interfaces
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Next, we need to bind some important interfaces into the container so
|
||||
| we will be able to resolve them when needed. The kernels serve the
|
||||
| incoming requests to this application from both the web and CLI.
|
||||
|
|
||||
*/
|
||||
|
||||
$app->singleton(
|
||||
Illuminate\Contracts\Http\Kernel::class,
|
||||
App\Http\Kernel::class
|
||||
);
|
||||
|
||||
$app->singleton(
|
||||
Illuminate\Contracts\Console\Kernel::class,
|
||||
App\Console\Kernel::class
|
||||
);
|
||||
|
||||
$app->singleton(
|
||||
Illuminate\Contracts\Debug\ExceptionHandler::class,
|
||||
App\Exceptions\Handler::class
|
||||
);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Return The Application
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This script returns the application instance. The instance is given to
|
||||
| the calling script so we can separate the building of the instances
|
||||
| from the actual running of the application and sending responses.
|
||||
|
|
||||
*/
|
||||
|
||||
return $app;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
*
|
||||
!.gitignore
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
{
|
||||
"name": "laravel/laravel",
|
||||
"type": "project",
|
||||
"description": "The skeleton application for the Laravel framework.",
|
||||
"keywords": ["laravel", "framework"],
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^8.1",
|
||||
"barryvdh/laravel-dompdf": "^3.1",
|
||||
"doctrine/dbal": "^3.10",
|
||||
"guzzlehttp/guzzle": "^7.2",
|
||||
"laravel/framework": "^10.10",
|
||||
"laravel/sanctum": "^3.3",
|
||||
"laravel/tinker": "^2.8",
|
||||
"maatwebsite/excel": "^3.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"barryvdh/laravel-ide-helper": "^3.1",
|
||||
"fakerphp/faker": "^1.9.1",
|
||||
"laravel/pint": "^1.0",
|
||||
"laravel/sail": "^1.18",
|
||||
"mockery/mockery": "^1.4.4",
|
||||
"nunomaduro/collision": "^7.0",
|
||||
"phpunit/phpunit": "^10.1",
|
||||
"spatie/laravel-ignition": "^2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "app/",
|
||||
"Database\\Factories\\": "database/factories/",
|
||||
"Database\\Seeders\\": "database/seeders/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"post-autoload-dump": [
|
||||
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
|
||||
"@php artisan package:discover --ansi"
|
||||
],
|
||||
"post-update-cmd": [
|
||||
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
|
||||
],
|
||||
"post-root-package-install": [
|
||||
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
|
||||
],
|
||||
"post-create-project-cmd": [
|
||||
"@php artisan key:generate --ansi"
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"dont-discover": []
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
"preferred-install": "dist",
|
||||
"sort-packages": true,
|
||||
"allow-plugins": {
|
||||
"pestphp/pest-plugin": true,
|
||||
"php-http/discovery": true
|
||||
}
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
"prefer-stable": true
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,189 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value is the name of your application. This value is used when the
|
||||
| framework needs to place the application's name in a notification or
|
||||
| any other location as required by the application or its packages.
|
||||
|
|
||||
*/
|
||||
|
||||
'name' => env('APP_NAME', 'Laravel'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Environment
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value determines the "environment" your application is currently
|
||||
| running in. This may determine how you prefer to configure various
|
||||
| services the application utilizes. Set this in your ".env" file.
|
||||
|
|
||||
*/
|
||||
|
||||
'env' => env('APP_ENV', 'production'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Debug Mode
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When your application is in debug mode, detailed error messages with
|
||||
| stack traces will be shown on every error that occurs within your
|
||||
| application. If disabled, a simple generic error page is shown.
|
||||
|
|
||||
*/
|
||||
|
||||
'debug' => (bool) env('APP_DEBUG', false),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application URL
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This URL is used by the console to properly generate URLs when using
|
||||
| the Artisan command line tool. You should set this to the root of
|
||||
| your application so that it is used when running Artisan tasks.
|
||||
|
|
||||
*/
|
||||
|
||||
'url' => env('APP_URL', 'http://localhost'),
|
||||
|
||||
'asset_url' => env('ASSET_URL'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Timezone
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the default timezone for your application, which
|
||||
| will be used by the PHP date and date-time functions. We have gone
|
||||
| ahead and set this to a sensible default for you out of the box.
|
||||
|
|
||||
*/
|
||||
|
||||
'timezone' => 'Asia/Jakarta',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Locale Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The application locale determines the default locale that will be used
|
||||
| by the translation service provider. You are free to set this value
|
||||
| to any of the locales which will be supported by the application.
|
||||
|
|
||||
*/
|
||||
|
||||
'locale' => 'en',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Fallback Locale
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The fallback locale determines the locale to use when the current one
|
||||
| is not available. You may change the value to correspond to any of
|
||||
| the language folders that are provided through your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'fallback_locale' => 'en',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Faker Locale
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This locale will be used by the Faker PHP library when generating fake
|
||||
| data for your database seeds. For example, this will be used to get
|
||||
| localized telephone numbers, street address information and more.
|
||||
|
|
||||
*/
|
||||
|
||||
'faker_locale' => 'en_US',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Encryption Key
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This key is used by the Illuminate encrypter service and should be set
|
||||
| to a random, 32 character string, otherwise these encrypted strings
|
||||
| will not be safe. Please do this before deploying an application!
|
||||
|
|
||||
*/
|
||||
|
||||
'key' => env('APP_KEY'),
|
||||
|
||||
'cipher' => 'AES-256-CBC',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Maintenance Mode Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These configuration options determine the driver used to determine and
|
||||
| manage Laravel's "maintenance mode" status. The "cache" driver will
|
||||
| allow maintenance mode to be controlled across multiple machines.
|
||||
|
|
||||
| Supported drivers: "file", "cache"
|
||||
|
|
||||
*/
|
||||
|
||||
'maintenance' => [
|
||||
'driver' => 'file',
|
||||
// 'store' => 'redis',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Autoloaded Service Providers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The service providers listed here will be automatically loaded on the
|
||||
| request to your application. Feel free to add your own services to
|
||||
| this array to grant expanded functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
'providers' => ServiceProvider::defaultProviders()->merge([
|
||||
/*
|
||||
* Package Service Providers...
|
||||
*/
|
||||
|
||||
/*
|
||||
* Application Service Providers...
|
||||
*/
|
||||
App\Providers\AppServiceProvider::class,
|
||||
App\Providers\AuthServiceProvider::class,
|
||||
// App\Providers\BroadcastServiceProvider::class,
|
||||
App\Providers\EventServiceProvider::class,
|
||||
App\Providers\RouteServiceProvider::class,
|
||||
App\Providers\ViewServiceProvider::class,
|
||||
])->toArray(),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Class Aliases
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This array of class aliases will be registered when this application
|
||||
| is started. However, feel free to register as many as you wish as
|
||||
| the aliases are "lazy" loaded so they don't hinder performance.
|
||||
|
|
||||
*/
|
||||
|
||||
'aliases' => Facade::defaultAliases()->merge([
|
||||
// 'Example' => App\Facades\Example::class,
|
||||
])->toArray(),
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Defaults
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default authentication "guard" and password
|
||||
| reset options for your application. You may change these defaults
|
||||
| as required, but they're a perfect start for most applications.
|
||||
|
|
||||
*/
|
||||
|
||||
'defaults' => [
|
||||
'guard' => 'web',
|
||||
'passwords' => 'users',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Guards
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Next, you may define every authentication guard for your application.
|
||||
| Of course, a great default configuration has been defined for you
|
||||
| here which uses session storage and the Eloquent user provider.
|
||||
|
|
||||
| All authentication drivers have a user provider. This defines how the
|
||||
| users are actually retrieved out of your database or other storage
|
||||
| mechanisms used by this application to persist your user's data.
|
||||
|
|
||||
| Supported: "session"
|
||||
|
|
||||
*/
|
||||
|
||||
'guards' => [
|
||||
'web' => [
|
||||
'driver' => 'session',
|
||||
'provider' => 'users',
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| User Providers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| All authentication drivers have a user provider. This defines how the
|
||||
| users are actually retrieved out of your database or other storage
|
||||
| mechanisms used by this application to persist your user's data.
|
||||
|
|
||||
| If you have multiple user tables or models you may configure multiple
|
||||
| sources which represent each model / table. These sources may then
|
||||
| be assigned to any extra authentication guards you have defined.
|
||||
|
|
||||
| Supported: "database", "eloquent"
|
||||
|
|
||||
*/
|
||||
|
||||
'providers' => [
|
||||
'users' => [
|
||||
'driver' => 'eloquent',
|
||||
'model' => App\Models\User::class,
|
||||
],
|
||||
|
||||
// 'users' => [
|
||||
// 'driver' => 'database',
|
||||
// 'table' => 'users',
|
||||
// ],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Resetting Passwords
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| You may specify multiple password reset configurations if you have more
|
||||
| than one user table or model in the application and you want to have
|
||||
| separate password reset settings based on the specific user types.
|
||||
|
|
||||
| The expiry time is the number of minutes that each reset token will be
|
||||
| considered valid. This security feature keeps tokens short-lived so
|
||||
| they have less time to be guessed. You may change this as needed.
|
||||
|
|
||||
| The throttle setting is the number of seconds a user must wait before
|
||||
| generating more password reset tokens. This prevents the user from
|
||||
| quickly generating a very large amount of password reset tokens.
|
||||
|
|
||||
*/
|
||||
|
||||
'passwords' => [
|
||||
'users' => [
|
||||
'provider' => 'users',
|
||||
'table' => 'password_reset_tokens',
|
||||
'expire' => 60,
|
||||
'throttle' => 60,
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Confirmation Timeout
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define the amount of seconds before a password confirmation
|
||||
| times out and the user is prompted to re-enter their password via the
|
||||
| confirmation screen. By default, the timeout lasts for three hours.
|
||||
|
|
||||
*/
|
||||
|
||||
'password_timeout' => 10800,
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Broadcaster
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default broadcaster that will be used by the
|
||||
| framework when an event needs to be broadcast. You may set this to
|
||||
| any of the connections defined in the "connections" array below.
|
||||
|
|
||||
| Supported: "pusher", "ably", "redis", "log", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('BROADCAST_DRIVER', 'null'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Broadcast Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define all of the broadcast connections that will be used
|
||||
| to broadcast events to other systems or over websockets. Samples of
|
||||
| each available type of connection are provided inside this array.
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'pusher' => [
|
||||
'driver' => 'pusher',
|
||||
'key' => env('PUSHER_APP_KEY'),
|
||||
'secret' => env('PUSHER_APP_SECRET'),
|
||||
'app_id' => env('PUSHER_APP_ID'),
|
||||
'options' => [
|
||||
'cluster' => env('PUSHER_APP_CLUSTER'),
|
||||
'host' => env('PUSHER_HOST') ?: 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com',
|
||||
'port' => env('PUSHER_PORT', 443),
|
||||
'scheme' => env('PUSHER_SCHEME', 'https'),
|
||||
'encrypted' => true,
|
||||
'useTLS' => env('PUSHER_SCHEME', 'https') === 'https',
|
||||
],
|
||||
'client_options' => [
|
||||
// Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
|
||||
],
|
||||
],
|
||||
|
||||
'ably' => [
|
||||
'driver' => 'ably',
|
||||
'key' => env('ABLY_KEY'),
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => 'default',
|
||||
],
|
||||
|
||||
'log' => [
|
||||
'driver' => 'log',
|
||||
],
|
||||
|
||||
'null' => [
|
||||
'driver' => 'null',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Cache Store
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default cache connection that gets used while
|
||||
| using this caching library. This connection is used when another is
|
||||
| not explicitly specified when executing a given caching function.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('CACHE_DRIVER', 'file'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Stores
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define all of the cache "stores" for your application as
|
||||
| well as their drivers. You may even define multiple stores for the
|
||||
| same cache driver to group types of items stored in your caches.
|
||||
|
|
||||
| Supported drivers: "apc", "array", "database", "file",
|
||||
| "memcached", "redis", "dynamodb", "octane", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'stores' => [
|
||||
|
||||
'apc' => [
|
||||
'driver' => 'apc',
|
||||
],
|
||||
|
||||
'array' => [
|
||||
'driver' => 'array',
|
||||
'serialize' => false,
|
||||
],
|
||||
|
||||
'database' => [
|
||||
'driver' => 'database',
|
||||
'table' => 'cache',
|
||||
'connection' => null,
|
||||
'lock_connection' => null,
|
||||
],
|
||||
|
||||
'file' => [
|
||||
'driver' => 'file',
|
||||
'path' => storage_path('framework/cache/data'),
|
||||
'lock_path' => storage_path('framework/cache/data'),
|
||||
],
|
||||
|
||||
'memcached' => [
|
||||
'driver' => 'memcached',
|
||||
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
|
||||
'sasl' => [
|
||||
env('MEMCACHED_USERNAME'),
|
||||
env('MEMCACHED_PASSWORD'),
|
||||
],
|
||||
'options' => [
|
||||
// Memcached::OPT_CONNECT_TIMEOUT => 2000,
|
||||
],
|
||||
'servers' => [
|
||||
[
|
||||
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
|
||||
'port' => env('MEMCACHED_PORT', 11211),
|
||||
'weight' => 100,
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => 'cache',
|
||||
'lock_connection' => 'default',
|
||||
],
|
||||
|
||||
'dynamodb' => [
|
||||
'driver' => 'dynamodb',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
'table' => env('DYNAMODB_CACHE_TABLE', 'cache'),
|
||||
'endpoint' => env('DYNAMODB_ENDPOINT'),
|
||||
],
|
||||
|
||||
'octane' => [
|
||||
'driver' => 'octane',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Key Prefix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When utilizing the APC, database, memcached, Redis, or DynamoDB cache
|
||||
| stores there might be other applications using the same cache. For
|
||||
| that reason, you may prefix every cache key to avoid collisions.
|
||||
|
|
||||
*/
|
||||
|
||||
'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'),
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cross-Origin Resource Sharing (CORS) Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure your settings for cross-origin resource sharing
|
||||
| or "CORS". This determines what cross-origin operations may execute
|
||||
| in web browsers. You are free to adjust these settings as needed.
|
||||
|
|
||||
| To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
||||
|
|
||||
*/
|
||||
|
||||
'paths' => ['api/*', 'sanctum/csrf-cookie'],
|
||||
|
||||
'allowed_methods' => ['*'],
|
||||
|
||||
'allowed_origins' => ['*'],
|
||||
|
||||
'allowed_origins_patterns' => [],
|
||||
|
||||
'allowed_headers' => ['*'],
|
||||
|
||||
'exposed_headers' => [],
|
||||
|
||||
'max_age' => 0,
|
||||
|
||||
'supports_credentials' => false,
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Database Connection Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify which of the database connections below you wish
|
||||
| to use as your default connection for all database work. Of course
|
||||
| you may use many connections at once using the Database library.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('DB_CONNECTION', 'mysql'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Database Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here are each of the database connections setup for your application.
|
||||
| Of course, examples of configuring each database platform that is
|
||||
| supported by Laravel is shown below to make development simple.
|
||||
|
|
||||
|
|
||||
| All database work in Laravel is done through the PHP PDO facilities
|
||||
| so make sure you have the driver for your particular database of
|
||||
| choice installed on your machine before you begin development.
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'sqlite' => [
|
||||
'driver' => 'sqlite',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'database' => env('DB_DATABASE', database_path('database.sqlite')),
|
||||
'prefix' => '',
|
||||
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
|
||||
],
|
||||
|
||||
'mysql' => [
|
||||
'driver' => 'mysql',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', '3306'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'unix_socket' => env('DB_SOCKET', ''),
|
||||
'charset' => 'utf8mb4',
|
||||
'collation' => 'utf8mb4_unicode_ci',
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
|
||||
]) : [],
|
||||
],
|
||||
|
||||
'pgsql' => [
|
||||
'driver' => 'pgsql',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', '5432'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => 'utf8',
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'search_path' => 'public',
|
||||
'sslmode' => 'prefer',
|
||||
],
|
||||
|
||||
'sqlsrv' => [
|
||||
'driver' => 'sqlsrv',
|
||||
'url' => env('DATABASE_URL'),
|
||||
'host' => env('DB_HOST', 'localhost'),
|
||||
'port' => env('DB_PORT', '1433'),
|
||||
'database' => env('DB_DATABASE', 'forge'),
|
||||
'username' => env('DB_USERNAME', 'forge'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => 'utf8',
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
// 'encrypt' => env('DB_ENCRYPT', 'yes'),
|
||||
// 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'),
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Migration Repository Table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This table keeps track of all the migrations that have already run for
|
||||
| your application. Using this information, we can determine which of
|
||||
| the migrations on disk haven't actually been run in the database.
|
||||
|
|
||||
*/
|
||||
|
||||
'migrations' => 'migrations',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Redis Databases
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Redis is an open source, fast, and advanced key-value store that also
|
||||
| provides a richer body of commands than a typical key-value system
|
||||
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
||||
|
|
||||
*/
|
||||
|
||||
'redis' => [
|
||||
|
||||
'client' => env('REDIS_CLIENT', 'phpredis'),
|
||||
|
||||
'options' => [
|
||||
'cluster' => env('REDIS_CLUSTER', 'redis'),
|
||||
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
|
||||
],
|
||||
|
||||
'default' => [
|
||||
'url' => env('REDIS_URL'),
|
||||
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||
'username' => env('REDIS_USERNAME'),
|
||||
'password' => env('REDIS_PASSWORD'),
|
||||
'port' => env('REDIS_PORT', '6379'),
|
||||
'database' => env('REDIS_DB', '0'),
|
||||
],
|
||||
|
||||
'cache' => [
|
||||
'url' => env('REDIS_URL'),
|
||||
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||
'username' => env('REDIS_USERNAME'),
|
||||
'password' => env('REDIS_PASSWORD'),
|
||||
'port' => env('REDIS_PORT', '6379'),
|
||||
'database' => env('REDIS_CACHE_DB', '1'),
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Filesystem Disk
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the default filesystem disk that should be used
|
||||
| by the framework. The "local" disk, as well as a variety of cloud
|
||||
| based disks are available to your application. Just store away!
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('FILESYSTEM_DISK', 'local'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Filesystem Disks
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure as many filesystem "disks" as you wish, and you
|
||||
| may even configure multiple disks of the same driver. Defaults have
|
||||
| been set up for each driver as an example of the required values.
|
||||
|
|
||||
| Supported Drivers: "local", "ftp", "sftp", "s3"
|
||||
|
|
||||
*/
|
||||
|
||||
'disks' => [
|
||||
|
||||
'local' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app'),
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
'public' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/public'),
|
||||
'url' => env('APP_URL').'/storage',
|
||||
'visibility' => 'public',
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
's3' => [
|
||||
'driver' => 's3',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION'),
|
||||
'bucket' => env('AWS_BUCKET'),
|
||||
'url' => env('AWS_URL'),
|
||||
'endpoint' => env('AWS_ENDPOINT'),
|
||||
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Symbolic Links
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the symbolic links that will be created when the
|
||||
| `storage:link` Artisan command is executed. The array keys should be
|
||||
| the locations of the links and the values should be their targets.
|
||||
|
|
||||
*/
|
||||
|
||||
'links' => [
|
||||
public_path('storage') => storage_path('app/public'),
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Hash Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default hash driver that will be used to hash
|
||||
| passwords for your application. By default, the bcrypt algorithm is
|
||||
| used; however, you remain free to modify this option if you wish.
|
||||
|
|
||||
| Supported: "bcrypt", "argon", "argon2id"
|
||||
|
|
||||
*/
|
||||
|
||||
'driver' => 'bcrypt',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Bcrypt Options
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the configuration options that should be used when
|
||||
| passwords are hashed using the Bcrypt algorithm. This will allow you
|
||||
| to control the amount of time it takes to hash the given password.
|
||||
|
|
||||
*/
|
||||
|
||||
'bcrypt' => [
|
||||
'rounds' => env('BCRYPT_ROUNDS', 12),
|
||||
'verify' => true,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Argon Options
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the configuration options that should be used when
|
||||
| passwords are hashed using the Argon algorithm. These will allow you
|
||||
| to control the amount of time it takes to hash the given password.
|
||||
|
|
||||
*/
|
||||
|
||||
'argon' => [
|
||||
'memory' => 65536,
|
||||
'threads' => 1,
|
||||
'time' => 4,
|
||||
'verify' => true,
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
|
||||
use Monolog\Handler\NullHandler;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Handler\SyslogUdpHandler;
|
||||
use Monolog\Processor\PsrLogMessageProcessor;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Log Channel
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines the default log channel that gets used when writing
|
||||
| messages to the logs. The name specified in this option should match
|
||||
| one of the channels defined in the "channels" configuration array.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('LOG_CHANNEL', 'stack'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Deprecations Log Channel
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the log channel that should be used to log warnings
|
||||
| regarding deprecated PHP and library features. This allows you to get
|
||||
| your application ready for upcoming major versions of dependencies.
|
||||
|
|
||||
*/
|
||||
|
||||
'deprecations' => [
|
||||
'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
|
||||
'trace' => false,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Log Channels
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the log channels for your application. Out of
|
||||
| the box, Laravel uses the Monolog PHP logging library. This gives
|
||||
| you a variety of powerful log handlers / formatters to utilize.
|
||||
|
|
||||
| Available Drivers: "single", "daily", "slack", "syslog",
|
||||
| "errorlog", "monolog",
|
||||
| "custom", "stack"
|
||||
|
|
||||
*/
|
||||
|
||||
'channels' => [
|
||||
'stack' => [
|
||||
'driver' => 'stack',
|
||||
'channels' => ['single'],
|
||||
'ignore_exceptions' => false,
|
||||
],
|
||||
|
||||
'single' => [
|
||||
'driver' => 'single',
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'daily' => [
|
||||
'driver' => 'daily',
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'days' => 14,
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'slack' => [
|
||||
'driver' => 'slack',
|
||||
'url' => env('LOG_SLACK_WEBHOOK_URL'),
|
||||
'username' => 'Laravel Log',
|
||||
'emoji' => ':boom:',
|
||||
'level' => env('LOG_LEVEL', 'critical'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'papertrail' => [
|
||||
'driver' => 'monolog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class),
|
||||
'handler_with' => [
|
||||
'host' => env('PAPERTRAIL_URL'),
|
||||
'port' => env('PAPERTRAIL_PORT'),
|
||||
'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
|
||||
],
|
||||
'processors' => [PsrLogMessageProcessor::class],
|
||||
],
|
||||
|
||||
'stderr' => [
|
||||
'driver' => 'monolog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'handler' => StreamHandler::class,
|
||||
'formatter' => env('LOG_STDERR_FORMATTER'),
|
||||
'with' => [
|
||||
'stream' => 'php://stderr',
|
||||
],
|
||||
'processors' => [PsrLogMessageProcessor::class],
|
||||
],
|
||||
|
||||
'syslog' => [
|
||||
'driver' => 'syslog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'facility' => LOG_USER,
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'errorlog' => [
|
||||
'driver' => 'errorlog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'null' => [
|
||||
'driver' => 'monolog',
|
||||
'handler' => NullHandler::class,
|
||||
],
|
||||
|
||||
'emergency' => [
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Mailer
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default mailer that is used to send any email
|
||||
| messages sent by your application. Alternative mailers may be setup
|
||||
| and used as needed; however, this mailer will be used by default.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('MAIL_MAILER', 'smtp'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Mailer Configurations
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure all of the mailers used by your application plus
|
||||
| their respective settings. Several examples have been configured for
|
||||
| you and you are free to add your own as your application requires.
|
||||
|
|
||||
| Laravel supports a variety of mail "transport" drivers to be used while
|
||||
| sending an e-mail. You will specify which one you are using for your
|
||||
| mailers below. You are free to add additional mailers as required.
|
||||
|
|
||||
| Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2",
|
||||
| "postmark", "log", "array", "failover", "roundrobin"
|
||||
|
|
||||
*/
|
||||
|
||||
'mailers' => [
|
||||
'smtp' => [
|
||||
'transport' => 'smtp',
|
||||
'url' => env('MAIL_URL'),
|
||||
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
|
||||
'port' => env('MAIL_PORT', 587),
|
||||
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
|
||||
'username' => env('MAIL_USERNAME'),
|
||||
'password' => env('MAIL_PASSWORD'),
|
||||
'timeout' => null,
|
||||
'local_domain' => env('MAIL_EHLO_DOMAIN'),
|
||||
],
|
||||
|
||||
'ses' => [
|
||||
'transport' => 'ses',
|
||||
],
|
||||
|
||||
'postmark' => [
|
||||
'transport' => 'postmark',
|
||||
// 'message_stream_id' => null,
|
||||
// 'client' => [
|
||||
// 'timeout' => 5,
|
||||
// ],
|
||||
],
|
||||
|
||||
'mailgun' => [
|
||||
'transport' => 'mailgun',
|
||||
// 'client' => [
|
||||
// 'timeout' => 5,
|
||||
// ],
|
||||
],
|
||||
|
||||
'sendmail' => [
|
||||
'transport' => 'sendmail',
|
||||
'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'),
|
||||
],
|
||||
|
||||
'log' => [
|
||||
'transport' => 'log',
|
||||
'channel' => env('MAIL_LOG_CHANNEL'),
|
||||
],
|
||||
|
||||
'array' => [
|
||||
'transport' => 'array',
|
||||
],
|
||||
|
||||
'failover' => [
|
||||
'transport' => 'failover',
|
||||
'mailers' => [
|
||||
'smtp',
|
||||
'log',
|
||||
],
|
||||
],
|
||||
|
||||
'roundrobin' => [
|
||||
'transport' => 'roundrobin',
|
||||
'mailers' => [
|
||||
'ses',
|
||||
'postmark',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Global "From" Address
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| You may wish for all e-mails sent by your application to be sent from
|
||||
| the same address. Here, you may specify a name and address that is
|
||||
| used globally for all e-mails that are sent by your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'from' => [
|
||||
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
|
||||
'name' => env('MAIL_FROM_NAME', 'Example'),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Markdown Mail Settings
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If you are using Markdown based email rendering, you may configure your
|
||||
| theme and component paths here, allowing you to customize the design
|
||||
| of the emails. Or, you may simply stick with the Laravel defaults!
|
||||
|
|
||||
*/
|
||||
|
||||
'markdown' => [
|
||||
'theme' => 'default',
|
||||
|
||||
'paths' => [
|
||||
resource_path('views/vendor/mail'),
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Queue Connection Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Laravel's queue API supports an assortment of back-ends via a single
|
||||
| API, giving you convenient access to each back-end using the same
|
||||
| syntax for every one. Here you may define a default connection.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('QUEUE_CONNECTION', 'sync'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Queue Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the connection information for each server that
|
||||
| is used by your application. A default configuration has been added
|
||||
| for each back-end shipped with Laravel. You are free to add more.
|
||||
|
|
||||
| Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'sync' => [
|
||||
'driver' => 'sync',
|
||||
],
|
||||
|
||||
'database' => [
|
||||
'driver' => 'database',
|
||||
'table' => 'jobs',
|
||||
'queue' => 'default',
|
||||
'retry_after' => 90,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'beanstalkd' => [
|
||||
'driver' => 'beanstalkd',
|
||||
'host' => 'localhost',
|
||||
'queue' => 'default',
|
||||
'retry_after' => 90,
|
||||
'block_for' => 0,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'sqs' => [
|
||||
'driver' => 'sqs',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
|
||||
'queue' => env('SQS_QUEUE', 'default'),
|
||||
'suffix' => env('SQS_SUFFIX'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => 'default',
|
||||
'queue' => env('REDIS_QUEUE', 'default'),
|
||||
'retry_after' => 90,
|
||||
'block_for' => null,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Job Batching
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following options configure the database and table that store job
|
||||
| batching information. These options can be updated to any database
|
||||
| connection and table which has been defined by your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'batching' => [
|
||||
'database' => env('DB_CONNECTION', 'mysql'),
|
||||
'table' => 'job_batches',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Failed Queue Jobs
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These options configure the behavior of failed queue job logging so you
|
||||
| can control which database and table are used to store the jobs that
|
||||
| have failed. You may change them to any database / table you wish.
|
||||
|
|
||||
*/
|
||||
|
||||
'failed' => [
|
||||
'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
|
||||
'database' => env('DB_CONNECTION', 'mysql'),
|
||||
'table' => 'failed_jobs',
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Stateful Domains
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Requests from the following domains / hosts will receive stateful API
|
||||
| authentication cookies. Typically, these should include your local
|
||||
| and production domains which access your API via a frontend SPA.
|
||||
|
|
||||
*/
|
||||
|
||||
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf(
|
||||
'%s%s',
|
||||
'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1',
|
||||
Sanctum::currentApplicationUrlWithPort()
|
||||
))),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Sanctum Guards
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This array contains the authentication guards that will be checked when
|
||||
| Sanctum is trying to authenticate a request. If none of these guards
|
||||
| are able to authenticate the request, Sanctum will use the bearer
|
||||
| token that's present on an incoming request for authentication.
|
||||
|
|
||||
*/
|
||||
|
||||
'guard' => ['web'],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Expiration Minutes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value controls the number of minutes until an issued token will be
|
||||
| considered expired. This will override any values set in the token's
|
||||
| "expires_at" attribute, but first-party sessions are not affected.
|
||||
|
|
||||
*/
|
||||
|
||||
'expiration' => null,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Token Prefix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Sanctum can prefix new tokens in order to take advantage of numerous
|
||||
| security scanning initiatives maintained by open source platforms
|
||||
| that notify developers if they commit tokens into repositories.
|
||||
|
|
||||
| See: https://docs.github.com/en/code-security/secret-scanning/about-secret-scanning
|
||||
|
|
||||
*/
|
||||
|
||||
'token_prefix' => env('SANCTUM_TOKEN_PREFIX', ''),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Sanctum Middleware
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When authenticating your first-party SPA with Sanctum you may need to
|
||||
| customize some of the middleware Sanctum uses while processing the
|
||||
| request. You may change the middleware listed below as required.
|
||||
|
|
||||
*/
|
||||
|
||||
'middleware' => [
|
||||
'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class,
|
||||
'encrypt_cookies' => App\Http\Middleware\EncryptCookies::class,
|
||||
'verify_csrf_token' => App\Http\Middleware\VerifyCsrfToken::class,
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Third Party Services
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This file is for storing the credentials for third party services such
|
||||
| as Mailgun, Postmark, AWS and more. This file provides the de facto
|
||||
| location for this type of information, allowing packages to have
|
||||
| a conventional file to locate the various service credentials.
|
||||
|
|
||||
*/
|
||||
|
||||
'mailgun' => [
|
||||
'domain' => env('MAILGUN_DOMAIN'),
|
||||
'secret' => env('MAILGUN_SECRET'),
|
||||
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
|
||||
'scheme' => 'https',
|
||||
],
|
||||
|
||||
'postmark' => [
|
||||
'token' => env('POSTMARK_TOKEN'),
|
||||
],
|
||||
|
||||
'ses' => [
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,214 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Session Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default session "driver" that will be used on
|
||||
| requests. By default, we will use the lightweight native driver but
|
||||
| you may specify any of the other wonderful drivers provided here.
|
||||
|
|
||||
| Supported: "file", "cookie", "database", "apc",
|
||||
| "memcached", "redis", "dynamodb", "array"
|
||||
|
|
||||
*/
|
||||
|
||||
'driver' => env('SESSION_DRIVER', 'file'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Lifetime
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the number of minutes that you wish the session
|
||||
| to be allowed to remain idle before it expires. If you want them
|
||||
| to immediately expire on the browser closing, set that option.
|
||||
|
|
||||
*/
|
||||
|
||||
'lifetime' => env('SESSION_LIFETIME', 120),
|
||||
|
||||
'expire_on_close' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Encryption
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option allows you to easily specify that all of your session data
|
||||
| should be encrypted before it is stored. All encryption will be run
|
||||
| automatically by Laravel and you can use the Session like normal.
|
||||
|
|
||||
*/
|
||||
|
||||
'encrypt' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session File Location
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the native session driver, we need a location where session
|
||||
| files may be stored. A default has been set for you but a different
|
||||
| location may be specified. This is only needed for file sessions.
|
||||
|
|
||||
*/
|
||||
|
||||
'files' => storage_path('framework/sessions'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Database Connection
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the "database" or "redis" session drivers, you may specify a
|
||||
| connection that should be used to manage these sessions. This should
|
||||
| correspond to a connection in your database configuration options.
|
||||
|
|
||||
*/
|
||||
|
||||
'connection' => env('SESSION_CONNECTION'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Database Table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the "database" session driver, you may specify the table we
|
||||
| should use to manage the sessions. Of course, a sensible default is
|
||||
| provided for you; however, you are free to change this as needed.
|
||||
|
|
||||
*/
|
||||
|
||||
'table' => 'sessions',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cache Store
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| While using one of the framework's cache driven session backends you may
|
||||
| list a cache store that should be used for these sessions. This value
|
||||
| must match with one of the application's configured cache "stores".
|
||||
|
|
||||
| Affects: "apc", "dynamodb", "memcached", "redis"
|
||||
|
|
||||
*/
|
||||
|
||||
'store' => env('SESSION_STORE'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Sweeping Lottery
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Some session drivers must manually sweep their storage location to get
|
||||
| rid of old sessions from storage. Here are the chances that it will
|
||||
| happen on a given request. By default, the odds are 2 out of 100.
|
||||
|
|
||||
*/
|
||||
|
||||
'lottery' => [2, 100],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may change the name of the cookie used to identify a session
|
||||
| instance by ID. The name specified here will get used every time a
|
||||
| new session cookie is created by the framework for every driver.
|
||||
|
|
||||
*/
|
||||
|
||||
'cookie' => env(
|
||||
'SESSION_COOKIE',
|
||||
Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
|
||||
),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The session cookie path determines the path for which the cookie will
|
||||
| be regarded as available. Typically, this will be the root path of
|
||||
| your application but you are free to change this when necessary.
|
||||
|
|
||||
*/
|
||||
|
||||
'path' => '/',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Domain
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may change the domain of the cookie used to identify a session
|
||||
| in your application. This will determine which domains the cookie is
|
||||
| available to in your application. A sensible default has been set.
|
||||
|
|
||||
*/
|
||||
|
||||
'domain' => env('SESSION_DOMAIN'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| HTTPS Only Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By setting this option to true, session cookies will only be sent back
|
||||
| to the server if the browser has a HTTPS connection. This will keep
|
||||
| the cookie from being sent to you when it can't be done securely.
|
||||
|
|
||||
*/
|
||||
|
||||
'secure' => env('SESSION_SECURE_COOKIE'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| HTTP Access Only
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Setting this value to true will prevent JavaScript from accessing the
|
||||
| value of the cookie and the cookie will only be accessible through
|
||||
| the HTTP protocol. You are free to modify this option if needed.
|
||||
|
|
||||
*/
|
||||
|
||||
'http_only' => true,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Same-Site Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option determines how your cookies behave when cross-site requests
|
||||
| take place, and can be used to mitigate CSRF attacks. By default, we
|
||||
| will set this value to "lax" since this is a secure default value.
|
||||
|
|
||||
| Supported: "lax", "strict", "none", null
|
||||
|
|
||||
*/
|
||||
|
||||
'same_site' => 'lax',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Partitioned Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Setting this value to true will tie the cookie to the top-level site for
|
||||
| a cross-site context. Partitioned cookies are accepted by the browser
|
||||
| when flagged "secure" and the Same-Site attribute is set to "none".
|
||||
|
|
||||
*/
|
||||
|
||||
'partitioned' => false,
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| View Storage Paths
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Most templating systems load templates from disk. Here you may specify
|
||||
| an array of paths that should be checked for your views. Of course
|
||||
| the usual Laravel view path has already been registered for you.
|
||||
|
|
||||
*/
|
||||
|
||||
'paths' => [
|
||||
resource_path('views'),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Compiled View Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option determines where all the compiled Blade templates will be
|
||||
| stored for your application. Typically, this is within the storage
|
||||
| directory. However, as usual, you are free to change this value.
|
||||
|
|
||||
*/
|
||||
|
||||
'compiled' => env(
|
||||
'VIEW_COMPILED_PATH',
|
||||
realpath(storage_path('framework/views'))
|
||||
),
|
||||
|
||||
];
|
||||
|
|
@ -0,0 +1 @@
|
|||
*.sqlite*
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('nama_lengkap');
|
||||
$table->string('username')->unique();
|
||||
$table->string('password');
|
||||
$table->string('alamat');
|
||||
$table->enum('role', ['admin', 'verifikator']);
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('personal_access_tokens', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->morphs('tokenable');
|
||||
$table->string('name');
|
||||
$table->string('token', 64)->unique();
|
||||
$table->text('abilities')->nullable();
|
||||
$table->timestamp('last_used_at')->nullable();
|
||||
$table->timestamp('expires_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('personal_access_tokens');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('pengaturans', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('nama_pengaturan')->unique();
|
||||
$table->string('nilai_pengaturan');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('pengaturans');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('kriterias', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('kode', 5)->unique(); // C1, C2, dst
|
||||
$table->string('nama');
|
||||
// $table->double('bobot_global')->default(0); aslinya double, tapi ganti ke decimal untuk presisi lebih baik
|
||||
$table->decimal('bobot_global', 8, 4)->default(0); // Bobot global dengan presisi 4 angka di belakang koma
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('kriterias');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('sub_kriterias', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('kriteria_id')->constrained('kriterias')->onDelete('cascade');
|
||||
$table->string('nama_sub');
|
||||
// $table->double('bobot_lokal')->default(0); // Hasil hitung F-AHP tingkat sub
|
||||
$table->decimal('bobot_lokal', 8, 4)->default(0); // Hasil hitung F-AHP tingkat sub dengan presisi 4 angka di belakang koma
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('sub_kriterias');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('perbandingans', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('pakar_ke')->default(1);
|
||||
$table->foreignId('kriteria_kiri_id')->references('id')->on('kriterias')->onDelete('cascade');
|
||||
$table->foreignId('kriteria_kanan_id')->references('id')->on('kriterias')->onDelete('cascade');
|
||||
$table->double('nilai_skala'); // Skala 1-9
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('perbandingans');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('perbandingan_subs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('pakar_ke')->default(1);
|
||||
$table->foreignId('kriteria_id')->constrained('kriterias')->onDelete('cascade');
|
||||
$table->foreignId('sub_kiri_id')->references('id')->on('sub_kriterias')->onDelete('cascade');
|
||||
$table->foreignId('sub_kanan_id')->references('id')->on('sub_kriterias')->onDelete('cascade');
|
||||
$table->double('nilai_skala');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('perbandingan_subs');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('wargas', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('nama');
|
||||
$table->text('alamat');
|
||||
$table->string('rt', 3);
|
||||
$table->string('rw', 3);
|
||||
$table->text('dokumen_pendukung')->nullable();
|
||||
$table->enum('status_verifikasi', ['pending', 'setuju', 'tolak'])->default('pending');
|
||||
$table->text('catatan')->nullable();
|
||||
$table->foreignId('verified_by')->nullable()->constrained('users')->onDelete('set null');
|
||||
$table->string('status_bansos_riil')->nullable(); // Data asli desa untuk pembanding TA
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('wargas');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('warga_details', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('warga_id')->constrained('wargas')->onDelete('cascade');
|
||||
$table->foreignId('kriteria_id')->constrained('kriterias')->onDelete('cascade');
|
||||
$table->foreignId('sub_kriteria_id')->constrained('sub_kriterias')->onDelete('cascade');
|
||||
$table->double('nilai_asli')->nullable(); // Misal menyimpan angka Rp 850.000
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('warga_details');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('periodes', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('nama_periode'); // Contoh: "Bansos Sembako Maret 2026"
|
||||
$table->integer('kuota'); // Batas jumlah penerima yang layak
|
||||
$table->boolean('is_aktif')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('periodes');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('hasil_seleksis', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('periode_id')->constrained('periodes')->onDelete('cascade');
|
||||
$table->foreignId('warga_id')->constrained('wargas')->onDelete('cascade');
|
||||
$table->double('skor_akhir');
|
||||
$table->integer('ranking');
|
||||
$table->enum('status_keputusan', ['layak', 'tidak_layak']);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('hasil_seleksis');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('sub_kriterias', function (Blueprint $table) {
|
||||
$table->string('kode')->after('kriteria_id')->unique()->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('sub_kriterias', function (Blueprint $table) {
|
||||
$table->dropColumn('kode');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('sub_kriterias', function (Blueprint $table) {
|
||||
$table->double('nilai_acuan')->default(0)->after('nama_sub');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('sub_kriterias', function (Blueprint $table) {
|
||||
$table->dropColumn('nilai_acuan');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('wargas', function (Blueprint $table) {
|
||||
$table->string('nik', 16)->unique()->after('id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('wargas', function (Blueprint $table) {
|
||||
$table->dropColumn('nik');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('warga_details', function (Blueprint $table) {
|
||||
$table->string('nilai_asli')->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('warga_details', function (Blueprint $table) {
|
||||
$table->integer('nilai_asli')->change();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// Kita paksa database mengubah enum-nya lewat SQL mentah
|
||||
// Ini tetap menghasilkan tipe data ENUM di database
|
||||
DB::statement("ALTER TABLE hasil_seleksis MODIFY COLUMN status_keputusan ENUM(
|
||||
'Layak Prioritas Utama',
|
||||
'Layak Cadangan',
|
||||
'Tidak Layak'
|
||||
)");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
// Balikkan ke enum awal jika di-rollback
|
||||
DB::statement("ALTER TABLE hasil_seleksis MODIFY COLUMN status_keputusan ENUM('layak', 'tidak_layak')");
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('profil_desas', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->text('sejarah_singkat')->nullable();
|
||||
$table->text('visi')->nullable();
|
||||
$table->text('misi')->nullable();
|
||||
$table->string('nama_kepala_desa')->nullable();
|
||||
$table->string('foto_kepala_desa')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('profil_desas');
|
||||
}
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue