From f448257980e778b9a85dedefc7b47d706f4b9dc8 Mon Sep 17 00:00:00 2001 From: Irwan Cahyono Date: Mon, 6 Jul 2026 16:07:20 +0700 Subject: [PATCH] header summary --- .../Produktivitas/PetaniLahanController.php | 42 +++++++- .../produktivitas/petani/header.blade.php | 97 ++++++++++++------- routes/web.php | 1 + 3 files changed, 102 insertions(+), 38 deletions(-) diff --git a/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php b/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php index 6a2000f..1cfa8b5 100644 --- a/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php +++ b/app/Http/Controllers/Web/Produktivitas/PetaniLahanController.php @@ -253,11 +253,47 @@ class PetaniLahanController extends Controller } } - /** - * Remove the specified resource from storage. - */ public function destroy(string $id) { // } + + public function summary(string $petaniId) + { + if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) { + abort(403); + } + + $petani = Petani::findOrFail($petaniId); + + $lahan = Lahan::where('petani_id', $petaniId) + ->sum('luas_lahan'); + + $tanaman = Tanaman::whereHas('lahan', function ($query) use ($petaniId) { + $query->where('petani_id', $petaniId); + })->count(); + + $komoditas = Lahan::where('petani_id', $petaniId) + ->join('master_komoditas', 'map_lahan.komoditas_id', '=', 'master_komoditas.id') + ->select('master_komoditas.nama', DB::raw('count(*) as total')) + ->groupBy('master_komoditas.nama') + ->orderBy('total', 'desc') + ->first(); + + $kondisiLahan = Lahan::where('petani_id', $petaniId) + ->select('kondisi_tanaman', DB::raw('count(*) as total')) + ->groupBy('kondisi_tanaman') + ->orderBy('total', 'desc') + ->first(); + + return response()->json([ + 'status' => 'success', + 'data' => [ + 'lahan' => $lahan, + 'tanaman' => $tanaman, + 'komoditas' => $komoditas ? $komoditas->nama : null, + 'kondisi_lahan' => $kondisiLahan ? $kondisiLahan->kondisi_tanaman : null, + ], + ]); + } } diff --git a/resources/views/produktivitas/petani/header.blade.php b/resources/views/produktivitas/petani/header.blade.php index d8761d2..05a0152 100644 --- a/resources/views/produktivitas/petani/header.blade.php +++ b/resources/views/produktivitas/petani/header.blade.php @@ -29,15 +29,15 @@
-

In-store Sales

-

$5,345.43

+

Segmentasi

+

Penggerak

- 5k orders+5.7% + Pemerhati Teknis

- +
@@ -46,32 +46,33 @@
-

In-store Sales

-

$5,345.43

-

- 5k orders+5.7% +

Lahan

+

15600 m2

+

+ 100 tanaman kopiSehat

- +

+
-

In-store Sales

-

$5,345.43

+

Praktik Budidaya

+

2 kali

- 5k orders+5.7% + 2 sertifikasi+5.7%

- +
@@ -89,15 +90,32 @@
-

In-store Sales

-

$5,345.43

+

Pendidikan

+

3 kali

- 5k orders+5.7% + 2 sertifikasi+5.7%

- + + + +
+
+
+
+
+
+

Pendidikan

+

3 kali

+

+ 2 sertifikasi+5.7% +

+
+ + +
@@ -114,24 +132,7 @@
- - - -
-
-
-
-
-
-

In-store Sales

-

$5,345.43

-

- 5k orders+5.7% -

-
- - - +
@@ -213,3 +214,29 @@ @endif
+ + @push('scripts') + +@endpush \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 551bbe1..96380c8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -190,6 +190,7 @@ Route::middleware('auth') Route::resource('petani', App\Http\Controllers\Web\Produktivitas\PetaniController::class); Route::get('petani/show-image/{id}/{field}', [App\Http\Controllers\Web\Produktivitas\PetaniController::class, 'showImage'])->name('petani.show-image'); Route::get('petani/{petani}/akses-pasar', [App\Http\Controllers\Web\Produktivitas\AksesPasarController::class, 'editByPetani'])->name('petani.akses-pasar.edit'); + Route::get('petani/{petani}/lahan-tanaman/summary', [App\Http\Controllers\Web\Produktivitas\PetaniLahanController::class, 'summary'])->name('petani.lahan-tanaman.summary'); Route::resource('petani.lahan-tanaman', App\Http\Controllers\Web\Produktivitas\PetaniLahanController::class); Route::resource('petani.lahan-tanaman.tanaman', App\Http\Controllers\Web\Produktivitas\PetaniLahanTanamanController::class)->only(['show', 'update', 'destroy']); Route::resource('petani.praktik-budidaya', App\Http\Controllers\Web\Produktivitas\PraktikBudidayaController::class);