solve jumlah lahan dan tanaman

This commit is contained in:
2026-09-23 14:37:08 +07:00
parent 94d3f2a582
commit 02eed6da34
2 changed files with 5 additions and 10 deletions
@@ -111,15 +111,9 @@ class PetaniController extends Controller
$desaOptions = $request->filled('kecamatan_id') $desaOptions = $request->filled('kecamatan_id')
? DesaKelurahan::select('id', 'nama')->where('kecamatan_id', $request->kecamatan_id)->orderBy('nama')->get() ? DesaKelurahan::select('id', 'nama')->where('kecamatan_id', $request->kecamatan_id)->orderBy('nama')->get()
: collect(); : collect();
$lahanQuery = Lahan::whereIn('petani_id', $summaryPetaniIds) $totalLahan = Lahan::count();
->when( $totalLuasLahan = Lahan::sum('luas_lahan');
$request->filled('komoditas_id'), $totalTanaman = Tanaman::count();
fn ($query) => $query->where('komoditas_id', $request->komoditas_id),
fn ($query) => $query->whereIn('komoditas_id', $komoditas->pluck('id'))
);
$lahanIds = (clone $lahanQuery)->pluck('id');
$totalLuasLahan = (clone $lahanQuery)->sum('luas_lahan');
$totalTanaman = Tanaman::whereIn('lahan_id', $lahanIds)->count();
$case = " $case = "
CASE CASE
@@ -146,6 +140,7 @@ class PetaniController extends Controller
'desaOptions', 'desaOptions',
'filters', 'filters',
'skor', 'skor',
'totalLahan',
'totalLuasLahan', 'totalLuasLahan',
'totalTanaman', 'totalTanaman',
'showFasilitatorColumn' 'showFasilitatorColumn'
@@ -98,7 +98,7 @@
<x-summary-card <x-summary-card
title="Lahan & Tanaman" title="Lahan & Tanaman"
count="{{ number_format(($totalLuasLahan ?? 0) / 10000, 2, ',', '.') }} ha" count="{{ number_format(($totalLuasLahan ?? 0) / 10000, 2, ',', '.') }} ha"
subtitle="{{ $totalTanaman ?? 0 }} tanaman dari {{ $komoditas?->count() }} komoditas utama" subtitle="{{ number_format($totalLahan ?? 0, 0, ',', '.') }} lahan, {{ number_format($totalTanaman ?? 0, 0, ',', '.') }} tanaman"
icon="trees" icon="trees"
color="success" color="success"
/> />