lahan skor has petani
This commit is contained in:
@@ -26,7 +26,7 @@ class IndeksPetaniController extends Controller
|
||||
$komoditas = Komoditas::where('is_utama', true)->get();
|
||||
|
||||
$petani = Petani::pluck('id');
|
||||
$lahan = Lahan::whereIn('petani_id', $petani)->get();
|
||||
$lahan = Lahan::has('petani')->get();
|
||||
|
||||
$case = "
|
||||
CASE
|
||||
@@ -38,14 +38,13 @@ class IndeksPetaniController extends Controller
|
||||
END
|
||||
";
|
||||
|
||||
$countPetani = Petani::whereIn('id', $petani)->count();
|
||||
$countKomoditas = Petani::whereIn('id', $petani)->whereIn('komoditas_id', $komoditas->pluck('id'))->distinct()->count('komoditas_id');
|
||||
$sumLahan = Lahan::whereIn('petani_id', $petani)->whereIn('komoditas_id', $komoditas->pluck('id'))->sum('luas_lahan');
|
||||
$avgLahan = Lahan::whereIn('petani_id', $petani)->whereIn('komoditas_id', $komoditas->pluck('id'))->avg('luas_lahan');
|
||||
$countPetani = Petani::count();
|
||||
$countKomoditas = Petani::whereIn('komoditas_id', $komoditas->pluck('id'))->distinct()->count('komoditas_id');
|
||||
$sumLahan = Lahan::has('petani')->whereIn('komoditas_id', $komoditas->pluck('id'))->sum('luas_lahan');
|
||||
$avgLahan = Lahan::has('petani')->whereIn('komoditas_id', $komoditas->pluck('id'))->avg('luas_lahan');
|
||||
|
||||
$avgSkor = SkorPetani::query()
|
||||
->join('petani', 'petani_skor.petani_id', '=', 'petani.id')
|
||||
->whereIn('petani_id', $petani)
|
||||
->whereIn('petani.komoditas_id', $komoditas->pluck('id'))
|
||||
->avg('skor_kesiapan_adopsi');
|
||||
|
||||
@@ -61,14 +60,13 @@ class IndeksPetaniController extends Controller
|
||||
$avgSegmen = 'Belum Lengkap';
|
||||
}
|
||||
|
||||
$countDesa = Petani::whereIn('id', $petani)->whereIn('komoditas_id', $komoditas->pluck('id'))->distinct()->count('desa_kelurahan_id');
|
||||
$countKecamatan = Petani::whereIn('petani.id', $petani)
|
||||
$countDesa = Petani::whereIn('komoditas_id', $komoditas->pluck('id'))->distinct()->count('desa_kelurahan_id');
|
||||
$countKecamatan = Petani::query()
|
||||
->join('master_desa_kelurahan', 'petani.desa_kelurahan_id', '=', 'master_desa_kelurahan.id')
|
||||
->join('master_kecamatan', 'master_desa_kelurahan.kecamatan_id', '=', 'master_kecamatan.id')
|
||||
->whereIn('komoditas_id', $komoditas->pluck('id'))->distinct()->count('master_kecamatan.id');
|
||||
|
||||
$countSegmentasi = SkorPetani::selectRaw("$case AS segmen, COUNT(*) AS total")
|
||||
->whereIn('petani_id', $petani)
|
||||
->groupByRaw($case)
|
||||
->get();
|
||||
|
||||
@@ -79,14 +77,12 @@ class IndeksPetaniController extends Controller
|
||||
$case AS segmen,
|
||||
COUNT(petani.id) AS total
|
||||
")
|
||||
->whereIn('petani_skor.petani_id', $petani)
|
||||
->groupBy('petani.komoditas_id')
|
||||
->groupByRaw($case)
|
||||
->get();
|
||||
|
||||
$avgDimensi = SkorPetani::query()
|
||||
->join('petani', 'petani_skor.petani_id', '=', 'petani.id')
|
||||
->whereIn('petani_id', $petani)
|
||||
->whereIn('petani.komoditas_id', $komoditas->pluck('id'))
|
||||
->selectRaw("
|
||||
avg(skor_d2_sistem_praktik_budidaya) as skor_d2_sistem_praktik_budidaya,
|
||||
@@ -96,7 +92,6 @@ class IndeksPetaniController extends Controller
|
||||
|
||||
$avgKomponen = SkorPetani::query()
|
||||
->join('petani', 'petani_skor.petani_id', '=', 'petani.id')
|
||||
->whereIn('petani_id', $petani)
|
||||
->whereIn('petani.komoditas_id', $komoditas->pluck('id'))
|
||||
->selectRaw("avg(skor_komp_1_d4_k3_motivasi_kapasitas_adopsi) as skor_komp_1_d4_k3_motivasi_kapasitas_adopsi,
|
||||
avg(skor_komp_2_d4_k2_ekonomi_rumah_tangga) as skor_komp_2_d4_k2_ekonomi_rumah_tangga,
|
||||
@@ -132,7 +127,6 @@ class IndeksPetaniController extends Controller
|
||||
$case AS segmen,
|
||||
COUNT(petani.id) AS total
|
||||
")
|
||||
->whereIn('petani_skor.petani_id', $petani)
|
||||
->groupBy('petani.desa_kelurahan_id')
|
||||
->groupByRaw($case)
|
||||
->get();
|
||||
@@ -150,12 +144,10 @@ class IndeksPetaniController extends Controller
|
||||
ELSE 'Belum Lengkap'
|
||||
END AS segmen
|
||||
")
|
||||
->whereIn('petani_skor.petani_id', $petani)
|
||||
->groupBy('petani.desa_kelurahan_id')
|
||||
->get();
|
||||
|
||||
$daftarPetani = Petani::query()
|
||||
->whereIn('id', $petani)
|
||||
->whereIn('komoditas_id', $komoditas->pluck('id'))
|
||||
->get();
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ use App\Enums\KondisiTanaman;
|
||||
use App\Enums\SeranganHama;
|
||||
use App\Enums\PenyakitTanaman;
|
||||
use App\Enums\KeparahanSerangan;
|
||||
use App\Models\Pertanian\Petani;
|
||||
|
||||
class Lahan extends Model
|
||||
{
|
||||
@@ -98,7 +99,7 @@ class Lahan extends Model
|
||||
|
||||
public function petani(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Profile::class, 'petani_id');
|
||||
return $this->belongsTo(Petani::class, 'petani_id');
|
||||
}
|
||||
|
||||
public function komoditas(): BelongsTo
|
||||
|
||||
@@ -4,6 +4,9 @@ namespace App\Models\Pertanian;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
use App\Models\Pertanian\Petani;
|
||||
|
||||
class SkorPetani extends Model
|
||||
{
|
||||
@@ -139,4 +142,9 @@ class SkorPetani extends Model
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public function petani(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Petani::class, 'petani_id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user