@@ -8,6 +8,7 @@ use Illuminate\View\View;
|
|||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
use App\Models\Ekosistem\PetaniCPM;
|
use App\Models\Ekosistem\PetaniCPM;
|
||||||
use App\Models\Wilayah\Provinsi;
|
use App\Models\Wilayah\Provinsi;
|
||||||
@@ -184,4 +185,96 @@ class PetaniCPMController extends Controller
|
|||||||
|
|
||||||
return redirect()->route('petani-cpm.index')->with('success', 'Data petani CPM berhasil dihapus.');
|
return redirect()->route('petani-cpm.index')->with('success', 'Data petani CPM berhasil dihapus.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function summary(string $tipe): JsonResponse
|
||||||
|
{
|
||||||
|
switch ($tipe) {
|
||||||
|
case 'jenis_kelamin':
|
||||||
|
return $this->calculateJenisKelamin();
|
||||||
|
case 'usia':
|
||||||
|
return $this->calculateUsia();
|
||||||
|
case 'pendidikan':
|
||||||
|
return $this->calculatePendidikan();
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'petani' => PetaniCPM::count(),
|
||||||
|
'pengumpul' => PetaniCPM::where('petani_pengumpul', 'pengumpul')->count(),
|
||||||
|
'petani' => PetaniCPM::where('petani_pengumpul', 'petani')->count(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function calculateJenisKelamin()
|
||||||
|
{
|
||||||
|
$petaniBase = PetaniCPM::query();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'total' => (clone $petaniBase)->count(),
|
||||||
|
'laki_laki' => (clone $petaniBase)->where('jenis_kelamin', 1)->count(),
|
||||||
|
'perempuan' => (clone $petaniBase)->where('jenis_kelamin', 0)->count(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function calculateUsia()
|
||||||
|
{
|
||||||
|
$petaniBase = PetaniCPM::query();
|
||||||
|
|
||||||
|
$usiaRataRata = (clone $petaniBase)
|
||||||
|
->selectRaw('AVG(EXTRACT(YEAR FROM AGE(CURRENT_DATE, tanggal_lahir))) as avg')
|
||||||
|
->value('avg');
|
||||||
|
$usiaMayoritas = (clone $petaniBase)
|
||||||
|
->selectRaw("
|
||||||
|
CASE
|
||||||
|
WHEN EXTRACT(YEAR FROM AGE(CURRENT_DATE, tanggal_lahir)) BETWEEN 0 AND 4 THEN '0-4'
|
||||||
|
WHEN EXTRACT(YEAR FROM AGE(CURRENT_DATE, tanggal_lahir)) BETWEEN 5 AND 9 THEN '5-9'
|
||||||
|
WHEN EXTRACT(YEAR FROM AGE(CURRENT_DATE, tanggal_lahir)) BETWEEN 10 AND 14 THEN '10-14'
|
||||||
|
WHEN EXTRACT(YEAR FROM AGE(CURRENT_DATE, tanggal_lahir)) BETWEEN 15 AND 19 THEN '15-19'
|
||||||
|
WHEN EXTRACT(YEAR FROM AGE(CURRENT_DATE, tanggal_lahir)) BETWEEN 20 AND 24 THEN '20-24'
|
||||||
|
WHEN EXTRACT(YEAR FROM AGE(CURRENT_DATE, tanggal_lahir)) BETWEEN 25 AND 29 THEN '25-29'
|
||||||
|
WHEN EXTRACT(YEAR FROM AGE(CURRENT_DATE, tanggal_lahir)) BETWEEN 30 AND 34 THEN '30-34'
|
||||||
|
WHEN EXTRACT(YEAR FROM AGE(CURRENT_DATE, tanggal_lahir)) BETWEEN 35 AND 39 THEN '35-39'
|
||||||
|
WHEN EXTRACT(YEAR FROM AGE(CURRENT_DATE, tanggal_lahir)) BETWEEN 40 AND 44 THEN '40-44'
|
||||||
|
WHEN EXTRACT(YEAR FROM AGE(CURRENT_DATE, tanggal_lahir)) BETWEEN 45 AND 49 THEN '45-49'
|
||||||
|
WHEN EXTRACT(YEAR FROM AGE(CURRENT_DATE, tanggal_lahir)) BETWEEN 50 AND 54 THEN '50-54'
|
||||||
|
WHEN EXTRACT(YEAR FROM AGE(CURRENT_DATE, tanggal_lahir)) BETWEEN 55 AND 59 THEN '55-59'
|
||||||
|
WHEN EXTRACT(YEAR FROM AGE(CURRENT_DATE, tanggal_lahir)) BETWEEN 60 AND 64 THEN '60-64'
|
||||||
|
WHEN EXTRACT(YEAR FROM AGE(CURRENT_DATE, tanggal_lahir)) BETWEEN 65 AND 69 THEN '65-69'
|
||||||
|
WHEN EXTRACT(YEAR FROM AGE(CURRENT_DATE, tanggal_lahir)) BETWEEN 70 AND 74 THEN '70-74'
|
||||||
|
ELSE '75+'
|
||||||
|
END as kelompok_usia
|
||||||
|
")
|
||||||
|
->groupBy('kelompok_usia')
|
||||||
|
->orderByRaw('COUNT(*) DESC')
|
||||||
|
->value('kelompok_usia');
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'usia_rata_rata' => $usiaRataRata ? round($usiaRataRata, 1) : 0,
|
||||||
|
'usia_mayoritas' => $usiaMayoritas ?? '-',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function calculatePendidikan()
|
||||||
|
{
|
||||||
|
$petaniBase = PetaniCPM::query();
|
||||||
|
|
||||||
|
$mayoritasValue = (clone $petaniBase)
|
||||||
|
->selectRaw('pendidikan_terakhir, COUNT(*) as total')
|
||||||
|
->groupBy('pendidikan_terakhir')
|
||||||
|
->orderByDesc('total')
|
||||||
|
->orderByDesc('pendidikan_terakhir')
|
||||||
|
->value('pendidikan_terakhir');
|
||||||
|
|
||||||
|
$tertinggiValue = (clone $petaniBase)
|
||||||
|
->whereNotNull('pendidikan_terakhir')
|
||||||
|
->orderByDesc('pendidikan_terakhir') // karena ada prefix angka
|
||||||
|
->value('pendidikan_terakhir');
|
||||||
|
|
||||||
|
$mayoritasLabel = $mayoritasValue?->label() ?? '-';
|
||||||
|
$tertinggiLabel = $tertinggiValue?->label() ?? '-';
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'pendidikan_mayoritas' => $mayoritasLabel,
|
||||||
|
'pendidikan_tertinggi' => $tertinggiLabel,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "AgroMonev",
|
||||||
|
"short_name": "AgroMonev",
|
||||||
|
"start_url": "/",
|
||||||
|
"display": "standalone",
|
||||||
|
"background_color": "#ffffff",
|
||||||
|
"theme_color": "#0d6efd",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "/icons/agromonev_192.png",
|
||||||
|
"sizes": "192x192",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "/icons/agromonev_512.png",
|
||||||
|
"sizes": "512x512",
|
||||||
|
"type": "image/png"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
const CACHE_NAME = 'agromonev-v1';
|
||||||
|
|
||||||
|
// asset statis saja
|
||||||
|
const STATIC_ASSETS = [
|
||||||
|
'/',
|
||||||
|
'/offline',
|
||||||
|
];
|
||||||
|
|
||||||
|
// install
|
||||||
|
self.addEventListener('install', event => {
|
||||||
|
self.skipWaiting();
|
||||||
|
event.waitUntil(
|
||||||
|
caches.open(CACHE_NAME)
|
||||||
|
.then(cache => cache.addAll(STATIC_ASSETS))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// activate (hapus cache lama)
|
||||||
|
self.addEventListener('activate', event => {
|
||||||
|
event.waitUntil(
|
||||||
|
caches.keys().then(keys => {
|
||||||
|
return Promise.all(
|
||||||
|
keys.map(key => {
|
||||||
|
if (key !== CACHE_NAME) {
|
||||||
|
return caches.delete(key);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
self.clients.claim();
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener('fetch', event => {
|
||||||
|
const request = event.request;
|
||||||
|
|
||||||
|
if (!request.url.startsWith('http')) return;
|
||||||
|
if (request.method !== 'GET') return;
|
||||||
|
|
||||||
|
const url = new URL(request.url);
|
||||||
|
|
||||||
|
// ❗ SKIP halaman auth & dashboard
|
||||||
|
if (
|
||||||
|
url.pathname.startsWith('/login') ||
|
||||||
|
url.pathname.startsWith('/logout') ||
|
||||||
|
url.pathname.startsWith('/register') ||
|
||||||
|
url.pathname.startsWith('/dashboard') ||
|
||||||
|
url.pathname.startsWith('/admin')
|
||||||
|
) {
|
||||||
|
event.respondWith(fetch(request));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ❗ SKIP API
|
||||||
|
if (url.pathname.startsWith('/api')) {
|
||||||
|
event.respondWith(fetch(request));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 HTML → network first
|
||||||
|
if (request.headers.get('accept')?.includes('text/html')) {
|
||||||
|
event.respondWith(
|
||||||
|
fetch(request)
|
||||||
|
.catch(() => caches.match('/offline'))
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 asset → cache
|
||||||
|
event.respondWith(
|
||||||
|
caches.match(request).then(res => res || fetch(request))
|
||||||
|
);
|
||||||
|
});
|
||||||
@@ -15,10 +15,17 @@
|
|||||||
name="viewport"
|
name="viewport"
|
||||||
content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
|
content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
|
||||||
<meta name="robots" content="noindex, nofollow" />
|
<meta name="robots" content="noindex, nofollow" />
|
||||||
<title>Admin | {{ $title ?? 'Database Petani' }}</title>
|
<title>AgroMonev | {{ $title ?? 'Database Petani' }}</title>
|
||||||
|
|
||||||
<meta name="description" content="" />
|
<meta name="description" content="" />
|
||||||
|
|
||||||
|
<link rel="manifest" href="/manifest.json">
|
||||||
|
<meta name="theme-color" content="#0d6efd">
|
||||||
|
|
||||||
|
<link rel="apple-touch-icon" href="/icons/icon-192.png">
|
||||||
|
<meta name="mobile-web-app-capable" content="yes">
|
||||||
|
<meta name="apple-mobile-web-app-status-bar-style" content="default">
|
||||||
|
|
||||||
<link rel="icon" type="image/x-icon" href="../../assets/img/favicon/favicon.ico" />
|
<link rel="icon" type="image/x-icon" href="../../assets/img/favicon/favicon.ico" />
|
||||||
|
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||||
|
|||||||
@@ -112,5 +112,15 @@
|
|||||||
}
|
}
|
||||||
</style> -->
|
</style> -->
|
||||||
@stack('scripts')
|
@stack('scripts')
|
||||||
|
|
||||||
|
<script>
|
||||||
|
if ('serviceWorker' in navigator) {
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
navigator.serviceWorker.register('/service-worker.js')
|
||||||
|
.then(reg => console.log('SW registered:', reg.scope))
|
||||||
|
.catch(err => console.error('SW failed:', err));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Offline</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Koneksi terputus</h1>
|
||||||
|
<p>Silakan cek internet Anda.</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -9,6 +9,8 @@ Route::post('/create-account', [App\Http\Controllers\Web\Konfigurasi\AuthControl
|
|||||||
Route::post('/authenticate', [App\Http\Controllers\Web\Konfigurasi\AuthController::class, 'authenticate'])->name('auth.authenticate');
|
Route::post('/authenticate', [App\Http\Controllers\Web\Konfigurasi\AuthController::class, 'authenticate'])->name('auth.authenticate');
|
||||||
Route::post('/logout', [App\Http\Controllers\Web\Konfigurasi\AuthController::class, 'logout'])->name('logout');
|
Route::post('/logout', [App\Http\Controllers\Web\Konfigurasi\AuthController::class, 'logout'])->name('logout');
|
||||||
|
|
||||||
|
Route::view('/offline', 'offline')->name('offline');
|
||||||
|
|
||||||
Route::middleware('auth')
|
Route::middleware('auth')
|
||||||
->group(function () {
|
->group(function () {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user