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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user