dashboard profil petani

This commit is contained in:
2026-07-13 14:03:19 +07:00
parent 92e8efb247
commit 4755c8a482
4 changed files with 312 additions and 0 deletions
@@ -0,0 +1,87 @@
<?php
namespace App\Http\Controllers\Web\Dashboard;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\DB;
use App\Models\Pertanian\Petani;
use App\Models\Pertanian\Komoditas;
use App\Models\Pertanian\Lahan;
use App\Models\Pertanian\Tanaman;
use App\Models\Pertanian\SkorPetani;
class ProfilPetaniController extends Controller
{
public function index()
{
if (!Gate::allows('super_admin') && !Gate::allows('admin')) {
abort(403);
}
$title = 'Dashboard Profil Petani';
$komoditas = Komoditas::all();
$petani = Petani::pluck('id');
$lahan = Lahan::whereIn('petani_id', $petani)->get();
$petaniSummary = Petani::select(
'komoditas_id',
DB::raw('COUNT(*) as total')
)
->groupBy('komoditas_id')
->get();
$lahanSummary = Lahan::select(
'komoditas_id',
DB::raw('COUNT(*) as total',
DB::raw('SUM(luas_lahan) as luas_lahan'))
)
->whereIn('petani_id', $petani)
->groupBy('komoditas_id')
->get();
$tanamanSummary = Tanaman::select(
'komoditas_id',
DB::raw('COUNT(*) as total')
)
->whereIn('lahan_id', $lahan->pluck('id'))
->groupBy('komoditas_id')
->get();
$case = "
CASE
WHEN skor_kesiapan_adopsi >= 4.0 THEN 'Penggerak'
WHEN skor_kesiapan_adopsi >= 3.0 THEN 'Perintis'
WHEN skor_kesiapan_adopsi >= 2.0 THEN 'Pemerhati'
WHEN skor_kesiapan_adopsi >= 1.0 THEN 'Pemula'
ELSE 'Belum Lengkap'
END
";
$skorSummary = SkorPetani::selectRaw("$case AS segmen, COUNT(*) AS total")
->whereIn('petani_id', $petani)
->groupByRaw($case)
->get();
$skorKomoditasSummary = SkorPetani::query()
->join('petani', 'petani_skor.petani_id', '=', 'petani.id')
->selectRaw("
petani.komoditas_id,
$case AS segmen,
COUNT(petani.id) AS total
")
->whereIn('petani_skor.petani_id', $petani)
->groupBy('petani.komoditas_id')
->groupByRaw($case)
->get();
return view('dashboard.petani', compact('title',
'komoditas',
'petaniSummary',
'lahanSummary',
'tanamanSummary',
'skorSummary',
'skorKomoditasSummary'
));
}
}
+215
View File
@@ -0,0 +1,215 @@
@extends('layout.main')
@section('content')
<div class="container-xxl flex-grow-1 container-p-y">
<div class="row g-6">
<div class="col-lg-3 col-sm-6">
<div class="card card-border-shadow-primary h-100">
<div class="card-body">
<div class="d-flex align-items-center mb-2">
<div class="avatar me-4">
<span class="avatar-initial rounded bg-label-primary">
<i class="icon-base ti tabler-user-check icon-28px"></i>
</span>
</div>
<h4 class="mb-0">{{ $petaniSummary->sum('total') }}</h4>
</div>
<p class="mb-1">Petani</p>
<p class="mb-0">
<span class="text-heading fw-medium me-2">{{ $petaniSummary->count('total') }}</span>
<small class="text-body-secondary">komoditas utama</small>
</p>
</div>
</div>
</div>
<div class="col-lg-3 col-sm-6">
<div class="card card-border-shadow-warning h-100">
<div class="card-body">
<div class="d-flex align-items-center mb-2">
<div class="avatar me-4">
<span class="avatar-initial rounded bg-label-warning">
<i class="icon-base ti tabler-trees icon-28px"></i>
</span>
</div>
<h4 class="mb-0">{{ $lahanSummary->sum('luas_lahan') }}m<sup>2</sup></h4>
</div>
<p class="mb-1">Lahan</p>
<p class="mb-0">
<span class="text-heading fw-medium me-2">{{ $lahanSummary->count('total') }}</span>
<small class="text-body-warning">komoditas utama</small>
</p>
</div>
</div>
</div>
<div class="col-lg-6 col-sm-12">
<div class="card card-border-shadow-danger h-100">
<div class="card-body">
<div class="d-flex align-items-center mb-2">
<div class="avatar me-4">
<span class="avatar-initial rounded bg-label-danger">
<i class="icon-base ti tabler-seedling icon-28px"></i>
</span>
</div>
<h4 class="mb-0">{{ $tanamanSummary->sum('total') }}</h4>
</div>
<p class="mb-1">Tanaman Komoditas Utama</p>
<div class="d-flex justify-content-between mb-2">
@foreach($komoditas as $k)
<p class="mb-0">
<span class="text-heading fw-medium me-2">{{ $tanamanSummary->where('komoditas_id', $k->id)->sum('total') }}</span>
<small class="text-body-danger">tanaman {{ $k->nama }}</small>
</p>
@endforeach
</div>
</div>
</div>
</div>
</div>
<div class="row g-6 py-4">
<div class="col-lg-6 col-sm-12">
<div class="card h-100">
<div class="card-header d-flex justify-content-between align-items-center">
<div class="card-title mb-0">
<h5 class="m-0 me-2">Segmentasi Petani</h5>
<p class="card-subtitle">untuk semua komoditas</p>
</div>
</div>
<div class="card-body">
<table class="table card-table table-border-top-0 table-border-bottom-0">
<tbody>
<tr>
<td class="w-60 ps-0">
<div class="d-flex justify-content-start align-items-center">
<div class="me-2">
<i class="icon-base ti tabler-crown icon-lg text-heading"></i>
</div>
<div>
<h6 class="mb-0 fw-normal text-success">Penggerak (4.0 - 5.0)</h6>
<!-- <small class="text-body-secondary text-wrap">Siap menjadi peserta agrolab utama dan panutan bagi petani lain</small> -->
</div>
</div>
</td>
<td class="text-end pe-0">
<span>{{ $skorSummary->where('segmentasi', 'Penggerak')->sum('total') }} petani</span>
</td>
<td class="text-end pe-0">
<span>{{ number_format(($skorSummary->where('segmentasi', 'Penggerak')->sum('total') / $petaniSummary->sum('total')) * 100, 2) }}%</span>
</td>
</tr>
<tr>
<td class="w-60 ps-0">
<div class="d-flex justify-content-start align-items-center">
<div class="me-2">
<i class="icon-base ti tabler-flag icon-lg text-heading"></i>
</div>
<div>
<h6 class="mb-0 fw-normal text-info">Perintis (3.0 - 3.9)</h6>
<!-- <small class="text-body-secondary text-wrap">Berpotensi berkembang menjadi Penggerak dengan dukungan yang tepat</small> -->
</div>
</div>
</td>
<td class="text-end pe-0">
<span>{{ $skorSummary->where('segmentasi', 'Perintis')->sum('total') }} petani</span>
</td>
<td class="text-end pe-0">
<span>{{ number_format(($skorSummary->where('segmentasi', 'Perintis')->sum('total') / $petaniSummary->sum('total')) * 100, 2) }}%</span>
</td>
</tr>
<tr>
<td class="w-60 ps-0">
<div class="d-flex justify-content-start align-items-center">
<div class="me-2">
<i class="icon-base ti tabler-eye icon-lg text-heading text-success"></i>
</div>
<div>
<h6 class="mb-0 fw-normal text-warning">Pemerhati (2.0 - 2.9)</h6>
<!-- <small class="text-body-secondary text-wrap">Perlu melihat bukti hasil nyata dari Penggerak sebelum mau bergerak</small> -->
</div>
</div>
</td>
<td class="text-end pe-0">
<span>{{ $skorSummary->where('segmentasi', 'Pemerhati')->sum('total') }} petani</span>
</td>
<td class="text-end pe-0">
<span>{{ number_format(($skorSummary->where('segmentasi', 'Pemerhati')->sum('total') / $petaniSummary->sum('total')) * 100, 2) }}%</span>
</td>
</tr>
<tr>
<td class="w-60 ps-0">
<div class="d-flex justify-content-start align-items-center">
<div class="me-2">
<i class="icon-base ti tabler-seedling icon-lg text-heading"></i>
</div>
<div>
<h6 class="mb-0 fw-normal text-danger">Pemula (1.0 - 1.9)</h6>
<!-- <small class="text-body-secondary text-wrap">Butuh penanganan hambatan dasar terlebih dahulu sebelum intervensi langsung</small> -->
</div>
</div>
</td>
<td class="text-end pe-0">
<span>{{ $skorSummary->where('segmentasi', 'Pemula')->sum('total') }} petani</span>
</td>
<td class="text-end pe-0">
<span>{{ number_format(($skorSummary->where('segmentasi', 'Pemula')->sum('total') / $petaniSummary->sum('total')) * 100, 2) }}%</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-lg-6 col-sm-12">
<div class="card h-100">
<div class="card-header d-flex justify-content-between align-items-center">
<div class="card-title mb-0">
<h5 class="m-0 me-2">Segmentasi Petani Komoditas</h5>
<p class="card-subtitle">berdasarkan mayoritas segmentasi</p>
</div>
</div>
<div class="card-body">
<table class="table card-table table-border-top-0 table-border-bottom-0">
<tbody>
@foreach ($komoditas as $k)
<?php
$max = $skorKomoditasSummary->where('komoditas_id', $k->id)
->sortByDesc('total')
->first();
?>
<tr>
<td class="w-40 ps-0">
<h6 class="mb-0 fw-normal text-heading">{{ $k->nama }}</h6>
</td>
<td class="pe-0">
@if(isset($max))
@if($max->segmentasi == 'Penggerak')
<span class="text-success">Petani Penggerak</span>
@elseif($max->segmentasi == 'Perintis')
<span class="text-info">Petani Perintis</span>
@elseif($max->segmentasi == 'Pemerhati')
<span class="text-warning">Petani Pemerhati</span>
@elseif($max->segmentasi == 'Pemula')
<span class="text-danger">Petani Pemula</span>
@else
<span>Belum Lengkap</span>
@endif
@else
<span>Belum Ada</span>
@endif
</td>
<td class="text-end pe-0">
<span>{{ isset($max) ? $max->total : 0 }} Petani</span>
</td>
<td class="text-end pe-0">
<span>{{ isset($max) ? number_format(($max->total / $petaniSummary->sum('total')) * 100, 2) : 0 }}%</span>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
@endsection
+7
View File
@@ -56,6 +56,13 @@
</a> </a>
</li> </li>
</ul> </ul>
<ul class="menu-sub">
<li class="menu-item {{ request()->routeIs('dashboard.petani') ? 'active' : '' }}">
<a href="{{ route('dashboard.petani') }}" class="menu-link">
<div data-i18n="Profil Petani">Profil Petani</div>
</a>
</li>
</ul>
</li> </li>
@endif @endif
+3
View File
@@ -33,6 +33,9 @@ Route::middleware('auth')
Route::get('/dashboard/produktivitas', [App\Http\Controllers\Web\Dashboard\SummaryController::class, 'produktivitas'])->name('dashboard.produktivitas'); Route::get('/dashboard/produktivitas', [App\Http\Controllers\Web\Dashboard\SummaryController::class, 'produktivitas'])->name('dashboard.produktivitas');
// Dashboard
Route::get('/dashboard/petani', [App\Http\Controllers\Web\Dashboard\ProfilPetaniController::class, 'index'])->name('dashboard.petani');
Route::get('/UserProfile', [App\Http\Controllers\Web\Konfigurasi\ProfileController::class, 'index'])->name('userProfile.index'); Route::get('/UserProfile', [App\Http\Controllers\Web\Konfigurasi\ProfileController::class, 'index'])->name('userProfile.index');
Route::get('/UserProfile/security', [App\Http\Controllers\Web\Konfigurasi\ProfileController::class, 'security'])->name('userProfile.security'); Route::get('/UserProfile/security', [App\Http\Controllers\Web\Konfigurasi\ProfileController::class, 'security'])->name('userProfile.security');