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')
? DesaKelurahan::select('id', 'nama')->where('kecamatan_id', $request->kecamatan_id)->orderBy('nama')->get()
: collect();
$lahanQuery = Lahan::whereIn('petani_id', $summaryPetaniIds)
->when(
$request->filled('komoditas_id'),
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();
$totalLahan = Lahan::count();
$totalLuasLahan = Lahan::sum('luas_lahan');
$totalTanaman = Tanaman::count();
$case = "
CASE
@@ -146,6 +140,7 @@ class PetaniController extends Controller
'desaOptions',
'filters',
'skor',
'totalLahan',
'totalLuasLahan',
'totalTanaman',
'showFasilitatorColumn'