update: sanity check
This commit is contained in:
@@ -4,13 +4,8 @@ namespace App\Http\Controllers\Web\Dashboard;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Profile;
|
||||
use App\Models\Wilayah\Provinsi;
|
||||
use App\Models\wilayah\KabupatenKota;
|
||||
use App\Models\Wilayah\Kecamatan;
|
||||
use App\Models\Wilayah\DesaKelurahan;
|
||||
use App\Models\Pertanian\Lahan;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class SummaryController extends Controller
|
||||
{
|
||||
public function index()
|
||||
@@ -21,128 +16,4 @@ class SummaryController extends Controller
|
||||
$title = 'Summary Dashboard';
|
||||
return view('dashboard.summary', compact('title'));
|
||||
}
|
||||
|
||||
public function produktivitasBackup(Request $request)
|
||||
{
|
||||
if (!Gate::allows('super_admin') && !Gate::allows('admin')) {
|
||||
abort(403);
|
||||
}
|
||||
$title = 'Produktivitas Dashboard';
|
||||
$luasTotal = Lahan::whereNotNull('path')->sum('luas_lahan');
|
||||
$totalpetani = Profile::where('role', 'petani')->count();
|
||||
$totallahan = Lahan::whereNotNull('path')->count();
|
||||
|
||||
$petaniList = Profile::where('role', 'petani')
|
||||
->with(['lahan.tanaman.komoditas', 'desaKelurahan'])
|
||||
->paginate(20);
|
||||
|
||||
$allLahan = Lahan::whereNotNull('path')
|
||||
->with(['profile', 'tanaman.komoditas', 'desaKelurahan.kecamatan.kabupatenKota.provinsi'])
|
||||
->get()
|
||||
->map(function($lahan) {
|
||||
return [
|
||||
'id' => $lahan->id,
|
||||
'polygon' => $lahan->path,
|
||||
'nama_petani' => $lahan->profile->nama ?? 'N/A',
|
||||
'luas' => $lahan->luas_lahan,
|
||||
'tanaman' => $lahan->tanaman->map(fn($t) => $t->komoditas->nama ?? null)->filter()->unique()->values()
|
||||
];
|
||||
});
|
||||
|
||||
return view('dashboard.produktivitas', compact('title', 'petaniList', 'allLahan', 'totalpetani', 'totallahan', 'luasTotal'));
|
||||
}
|
||||
|
||||
public function produktivitas(Request $request)
|
||||
{
|
||||
if (!Gate::allows('super_admin') && !Gate::allows('admin')) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$title = 'Produktivitas Dashboard';
|
||||
$luasTotal = Lahan::whereNotNull('path')->sum('luas_lahan');
|
||||
$totalpetani = Profile::where('role', 'petani')->count();
|
||||
$totallahan = Lahan::whereNotNull('path')->count();
|
||||
|
||||
$petaniList = Profile::where('role', 'petani')
|
||||
->with(['lahan.tanaman.komoditas', 'desaKelurahan'])
|
||||
->paginate(20);
|
||||
|
||||
$allLahan = Lahan::whereNotNull('path')
|
||||
->with(['profile', 'tanaman.komoditas', 'desaKelurahan.kecamatan.kabupatenKota.provinsi'])
|
||||
->get();
|
||||
|
||||
// Penampung data per level (menggunakan ID sebagai key agar unique)
|
||||
$geoProvinsi = [];
|
||||
$geoKabupaten = [];
|
||||
$geoKecamatan = [];
|
||||
$geoDesa = [];
|
||||
$geoLahan = [];
|
||||
|
||||
foreach ($allLahan as $lahan) {
|
||||
$desa = $lahan->desaKelurahan;
|
||||
$kec = $desa ? $desa->kecamatan : null;
|
||||
$kab = $kec ? $kec->kabupatenKota : null;
|
||||
$prov = $kab ? $kab->provinsi : null;
|
||||
|
||||
// --- Akumulasi Provinsi ---
|
||||
if ($prov && $prov->path) {
|
||||
if (!isset($geoProvinsi[$prov->id])) {
|
||||
$geoProvinsi[$prov->id] = ['id' => $prov->id, 'nama' => $prov->nama, 'polygon' => $prov->path, 'total_lahan' => 0, 'total_luas' => 0];
|
||||
}
|
||||
$geoProvinsi[$prov->id]['total_lahan']++;
|
||||
$geoProvinsi[$prov->id]['total_luas'] += $lahan->luas_lahan;
|
||||
}
|
||||
|
||||
// --- Akumulasi Kabupaten ---
|
||||
if ($kab && $kab->path) {
|
||||
if (!isset($geoKabupaten[$kab->id])) {
|
||||
$geoKabupaten[$kab->id] = ['id' => $kab->id, 'parent_id' => $prov->id ?? null, 'nama' => $kab->nama, 'polygon' => $kab->path, 'total_lahan' => 0, 'total_luas' => 0];
|
||||
}
|
||||
$geoKabupaten[$kab->id]['total_lahan']++;
|
||||
$geoKabupaten[$kab->id]['total_luas'] += $lahan->luas_lahan;
|
||||
}
|
||||
|
||||
// --- Akumulasi Kecamatan ---
|
||||
if ($kec && $kec->path) {
|
||||
if (!isset($geoKecamatan[$kec->id])) {
|
||||
$geoKecamatan[$kec->id] = ['id' => $kec->id, 'parent_id' => $kab->id ?? null, 'nama' => $kec->nama, 'polygon' => $kec->path, 'total_lahan' => 0, 'total_luas' => 0];
|
||||
}
|
||||
$geoKecamatan[$kec->id]['total_lahan']++;
|
||||
$geoKecamatan[$kec->id]['total_luas'] += $lahan->luas_lahan;
|
||||
}
|
||||
|
||||
// --- Akumulasi Desa ---
|
||||
if ($desa && $desa->path) {
|
||||
if (!isset($geoDesa[$desa->id])) {
|
||||
$geoDesa[$desa->id] = ['id' => $desa->id, 'parent_id' => $kec->id ?? null, 'nama' => $desa->nama, 'polygon' => $desa->path, 'total_lahan' => 0, 'total_luas' => 0];
|
||||
}
|
||||
$geoDesa[$desa->id]['total_lahan']++;
|
||||
$geoDesa[$desa->id]['total_luas'] += $lahan->luas_lahan;
|
||||
}
|
||||
|
||||
// Data Lahan Tetap
|
||||
$geoLahan[] = [
|
||||
'id' => $lahan->id,
|
||||
'parent_id' => $desa->id ?? null,
|
||||
'polygon' => $lahan->path,
|
||||
'nama_petani' => $lahan->profile->nama ?? 'N/A',
|
||||
'luas' => $lahan->luas_lahan,
|
||||
'tanaman' => $lahan->tanaman->map(fn($t) => $t->komoditas->nama ?? null)->filter()->unique()->values()
|
||||
];
|
||||
}
|
||||
|
||||
return view('dashboard.produktivitas', [
|
||||
'title' => $title,
|
||||
'petaniList' => $petaniList,
|
||||
'totalpetani' => $totalpetani,
|
||||
'totallahan' => $totallahan,
|
||||
'luasTotal' => $luasTotal,
|
||||
// Reset key array agar menjadi format list normal untuk JSON
|
||||
'geoProvinsi' => array_values($geoProvinsi),
|
||||
'geoKabupaten' => array_values($geoKabupaten),
|
||||
'geoKecamatan' => array_values($geoKecamatan),
|
||||
'geoDesa' => array_values($geoDesa),
|
||||
'geoLahan' => $geoLahan
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@ class AuthController extends Controller
|
||||
public function login()
|
||||
{
|
||||
$title = 'Login';
|
||||
return view('konfigurasi.auth.login', compact('title'));
|
||||
return view('auth.login', compact('title'));
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
$title = 'Register';
|
||||
return view('konfigurasi.auth.register', compact('title'));
|
||||
return view('auth.register', compact('title'));
|
||||
}
|
||||
|
||||
public function createAccount(Request $request)
|
||||
@@ -42,7 +42,7 @@ class AuthController extends Controller
|
||||
'deleted_by' => null,
|
||||
]);
|
||||
|
||||
return redirect()->route('konfigurasi.auth.login')->with('success', 'Account created successfully. Please login.');
|
||||
return redirect()->route('auth.login')->with('success', 'Account created successfully. Please login.');
|
||||
}
|
||||
|
||||
public function verify(User $user)
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web\Konfigurasi;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\Profile;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$userid = auth()->user()->id;
|
||||
$profile = Profile::where('user_id', $userid)->first();
|
||||
$title = 'Profile';
|
||||
return view('konfigurasi.profile.index', compact('title', 'profile'));
|
||||
}
|
||||
}
|
||||
@@ -38,22 +38,22 @@ class Lahan extends Model
|
||||
'path' => 'array',
|
||||
];
|
||||
|
||||
public function profile()
|
||||
public function profile(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Profile::class, 'profile_id');
|
||||
}
|
||||
|
||||
public function desaKelurahan()
|
||||
public function desaKelurahan(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DesaKelurahan::class, 'desa_kelurahan_id');
|
||||
}
|
||||
|
||||
public function adat()
|
||||
public function adat(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Adat::class, 'adat_pemilik_id');
|
||||
}
|
||||
|
||||
public function tanaman()
|
||||
public function tanaman(): HasMany
|
||||
{
|
||||
return $this->hasMany(Tanaman::class, 'lahan_id');
|
||||
}
|
||||
|
||||
@@ -7,9 +7,6 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Models\Pertanian\Komoditas;
|
||||
use App\Models\Pertanian\Lahan;
|
||||
use App\Models\Profile;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
|
||||
class Tanaman extends Model
|
||||
{
|
||||
|
||||
@@ -4,11 +4,9 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Pertanian\Lahan;
|
||||
use App\Models\Wilayah\DesaKelurahan;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Profile extends Model
|
||||
{
|
||||
@@ -45,9 +43,4 @@ class Profile extends Model
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function lahan(): HasMany
|
||||
{
|
||||
return $this->hasMany(Lahan::class, 'profile_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
use App\Models\Wilayah\Provinsi;
|
||||
use App\Models\Wilayah\KabupatenKota;
|
||||
use App\Models\Wilayah\Kecamatan;
|
||||
use App\Models\Wilayah\DesaKelurahan;
|
||||
|
||||
class WilayahDashboard extends Component
|
||||
{
|
||||
public function render(): View|Closure|string
|
||||
{
|
||||
$kodeJawa = ['31', '32', '33', '34', '35', '36'];
|
||||
|
||||
$totalProvinsi = Provinsi::count();
|
||||
$totalKabKota = KabupatenKota::count();
|
||||
$totalKecamatan = Kecamatan::count();
|
||||
$totalDesaKelurahan = DesaKelurahan::count();
|
||||
|
||||
|
||||
$provinsiAktif = Provinsi::has('kabupatenKota')->count();
|
||||
|
||||
$provinsiKosong = $totalProvinsi - $provinsiAktif;
|
||||
|
||||
$totalKabupaten = KabupatenKota::whereRaw("SUBSTRING(kode, 3, 2) < '70'")->count();
|
||||
$totalKota = KabupatenKota::whereRaw("SUBSTRING(kode, 3, 2) >= '70'")->count();
|
||||
|
||||
if ($totalKabupaten == 0 && $totalKota == 0 && $totalKabKota > 0) {
|
||||
$totalKabupaten = $totalKabKota;
|
||||
}
|
||||
|
||||
$kecamatanPerdesaan = Kecamatan::whereHas('kabupatenKota', function($query) {
|
||||
$query->whereRaw("SUBSTRING(kode, 3, 2) < '70'");
|
||||
})->count();
|
||||
|
||||
$kecamatanPerkotaan = max(0, $totalKecamatan - $kecamatanPerdesaan);
|
||||
|
||||
$terpetakan = DesaKelurahan::whereNotNull('path')->count();
|
||||
$belumTerpetakan = max(0, $totalDesaKelurahan - $terpetakan);
|
||||
|
||||
$totalDesa = DesaKelurahan::where('nama', 'like', 'DESA%')->count() ?: $totalDesaKelurahan;
|
||||
$totalKelurahan = DesaKelurahan::where('nama', 'like', 'KEL%')->count();
|
||||
|
||||
$data = [
|
||||
'totalProvinsi' => $totalProvinsi,
|
||||
'provinsiAktif' => $provinsiAktif,
|
||||
'provinsiKosong' => $provinsiKosong,
|
||||
|
||||
'totalKabKota' => $totalKabKota,
|
||||
'totalKabupaten' => $totalKabupaten,
|
||||
'totalKota' => $totalKota,
|
||||
|
||||
'totalKecamatan' => $totalKecamatan,
|
||||
'kecamatanPerdesaan' => $kecamatanPerdesaan,
|
||||
'kecamatanPerkotaan' => $kecamatanPerkotaan,
|
||||
|
||||
'totalDesaKelurahan' => $totalDesaKelurahan,
|
||||
'totalDesa' => $totalDesa,
|
||||
'totalKelurahan' => $totalKelurahan,
|
||||
'terpetakan' => $terpetakan,
|
||||
'belumTerpetakan' => $belumTerpetakan,
|
||||
];
|
||||
|
||||
return view('components.wilayah-dashboard', $data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user