From e897c2af65383c48119019ac8c2d3db352cd91b7 Mon Sep 17 00:00:00 2001 From: ahmad afandi Date: Wed, 12 Jun 2024 14:45:40 +0700 Subject: [PATCH] tambahkan filter dan data summary --- .../WebsiteDashboardController.php | 69 ++++++++++++++++++- app/Models/Desa.php | 17 +++++ app/Providers/AppServiceProvider.php | 4 +- resources/views/website/dashboard.blade.php | 59 +++++++++++++++- .../views/website/partial/chart.blade.php | 24 ++----- .../views/website/partial/summary.blade.php | 38 +++++----- routes/api.php | 1 + 7 files changed, 170 insertions(+), 42 deletions(-) diff --git a/app/Http/Controllers/WebsiteDashboardController.php b/app/Http/Controllers/WebsiteDashboardController.php index af504884..b78fef29 100644 --- a/app/Http/Controllers/WebsiteDashboardController.php +++ b/app/Http/Controllers/WebsiteDashboardController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Models\Desa; +use Carbon\Carbon; use Illuminate\Http\Request; class WebsiteDashboardController extends Controller @@ -27,13 +28,77 @@ public function index(Request $request) ]); } + public function summary(Request $request){ + $period = $request->get('period') ?? Carbon::now()->format('Y-m-d').' - '.Carbon::now()->format('Y-m-d'); + $provinsi = $request->get('provinsi'); + $kabupaten = $request->get('kabupaten'); + $kecamatan = $request->get('kecamatan'); + $summary = Desa::selectRaw('count(distinct kode_desa) as desa, count(distinct kode_kecamatan) as kecamatan, count(distinct kode_kabupaten) as kabupaten, count(distinct kode_provinsi) as provinsi'); + $summarySebelumnya = Desa::selectRaw('count(distinct kode_desa) as desa, count(distinct kode_kecamatan) as kecamatan, count(distinct kode_kabupaten) as kabupaten, count(distinct kode_provinsi) as provinsi'); + + if($period){ + $tanggalAkhir = explode(' - ', $period)[1]; + $summary->where('created_at', '<=', $tanggalAkhir); + $summarySebelumnya->where('created_at', '<=', Carbon::parse($tanggalAkhir)->subMonth()->format('Y-m-d')); + $desaAktif = Desa::aktif($tanggalAkhir); + $desaAktifOnline = Desa::aktifOnline($tanggalAkhir); + } + if($provinsi){ + $summary->where('kode_provinsi', $provinsi); + $summarySebelumnya->where('kode_provinsi', $provinsi); + $desaAktif->where('kode_provinsi', $provinsi); + $desaAktifOnline->where('kode_provinsi', $provinsi); + } + if($kabupaten){ + $summary->where('kode_kabupaten', $kabupaten); + $summarySebelumnya->where('kode_kabupaten', $kabupaten); + $desaAktif->where('kode_kabupaten', $kabupaten); + $desaAktifOnline->where('kode_kabupaten', $kabupaten); + } + if($kecamatan){ + $summary->where('kode_kecamatan', $kecamatan); + $summarySebelumnya->where('kode_kecamatan', $kecamatan); + $desaAktif->where('kode_kecamatan', $kecamatan); + $desaAktifOnline->where('kode_kecamatan', $kecamatan); + } + $summareResult = $summary->first(); + $summarySebelumnyaResult = $summarySebelumnya->first(); + return response()->json([ + 'total' => [ + 'provinsi' => ['total' => $summareResult->provinsi,'pertumbuhan' => $summareResult->provinsi - $summarySebelumnyaResult->provinsi], + 'kabupaten' => ['total' => $summareResult->kabupaten,'pertumbuhan' => $summareResult->kabupaten - $summarySebelumnyaResult->kabupaten], + 'kecamatan' => ['total' => $summareResult->kecamatan,'pertumbuhan' => $summareResult->kecamatan - $summarySebelumnyaResult->kecamatan], + 'desa' => ['total' => $summareResult->desa,'pertumbuhan' => $summareResult->desa - $summarySebelumnyaResult->desa], + 'desa_aktif' => ['total' => $desaAktif->count()], + 'desa_aktif_online' => ['total' => $desaAktifOnline->count()], + ], + 'detail' => [ + 'openkab' => [], + 'opendk' => [], + 'opensid' => [], + 'layanan_desa' => [], + 'kelola_desa' => [], + ] + ] + ); + + } public function chartUsage(Request $request){ $period = $request->get('period'); + $provinsi = $request->get('provinsi'); + $kabupaten = $request->get('kabupaten'); + $kecamatan = $request->get('kecamatan'); $period = explode(' - ','2024-06-10 - 2024-06-30'); $result = [ - 'labels' => ['1','2'], - 'datasets' => [['label' => 'fda', 'data' => [9,14]],['label' => 'f', 'data' => [9,14]]], + 'labels' => [1,2,3,4,5], + 'datasets' => [ + ['label' => 'OpenKab', 'data' => [9,14,2,6]], + ['label' => 'OpenDK', 'data' => [19,24]], + ['label' => 'OpenSID', 'data' => [9,4]], + ['label' => 'LayananDesa', 'data' => [9,1,4]], + ['label' => 'KelolaDesa', 'data' => [19,4, 5]], + ], ]; return response()->json($result); diff --git a/app/Models/Desa.php b/app/Models/Desa.php index 2a9d9a54..6fd7ef32 100644 --- a/app/Models/Desa.php +++ b/app/Models/Desa.php @@ -2,6 +2,7 @@ namespace App\Models; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\DB; @@ -364,4 +365,20 @@ public function scopeWilayahKhusus($query) $r->where('kode_provinsi', $provinsi); }); } + + public function scopeOnline($query) + { + return $query->where('versi_hosting', '!=', ''); + } + + public function scopeAktif($query, $batasTgl) + { + $maksimalTanggal = Carbon::parse($batasTgl)->subDays(7)->format('Y-m-d'); + return $query->whereRaw(DB::raw("greatest(coalesce(tgl_akses_lokal, 0), coalesce(tgl_akses_hosting, 0)) >= '{$maksimalTanggal}'")); + } + + public function scopeAktifOnline($query, $batasTgl) + { + return $query->online()->aktif($batasTgl); + } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index bec6f13b..fb92a6d5 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -31,7 +31,7 @@ public function boot() protected function bootLogQuery() { - if ($this->app->environment('local')) { + //if ($this->app->environment('local')) { Event::listen(QueryExecuted::class, function ($query) { $bindings = collect($query->bindings)->map(function ($param) { if (is_numeric($param)) { @@ -43,6 +43,6 @@ protected function bootLogQuery() $this->app->log->debug(Str::replaceArray('?', $bindings->toArray(), $query->sql)); }); - } + //} } } diff --git a/resources/views/website/dashboard.blade.php b/resources/views/website/dashboard.blade.php index 841c67f9..687fb895 100644 --- a/resources/views/website/dashboard.blade.php +++ b/resources/views/website/dashboard.blade.php @@ -69,6 +69,63 @@ class="btn btn-sm btn-block btn-primary"> $('.datepicker').each(function () { const _options = $(this).data('option') $(this).daterangepicker(_options) - }) + }) + + function updateData(){ + const params = {period : $('input[name=periods]').val(), provinsi : $('select[name=provinsi]').val(), kabupaten : $('select[name=kabupaten]').val(), kecamatan : $('select[name=kecamatan]').val()} + $.ajax({ + url: 'api/web/chart-usage', + data: params, + type: "GET", + success: function(data) { + myChart.data = data; + myChart.update(); + } + }, 'json') + + $.ajax({ + url: 'api/web/summary', + data: params, + type: "GET", + success: function(data) { + const total = data.total + const detail = data.detail + $('#box-provinsi>.total').text(total.provinsi.total) + $('#box-provinsi span.pertumbuhan').html(` + ${total.provinsi.pertumbuhan}`) + $('#box-kabupaten>.total').text(total.kabupaten.total) + $('#box-kabupaten span.pertumbuhan').html(` + ${total.kabupaten.pertumbuhan}`) + $('#box-kecamatan>.total').text(total.kecamatan.total) + $('#box-kecamatan span.pertumbuhan').html(` + ${total.kecamatan.pertumbuhan}`) + $('#box-desa>.total').text(total.desa.total) + $('#box-desa span.pertumbuhan').html(` + ${total.desa.pertumbuhan}`) + + $('#desa_aktif>.total').text(total.desa_aktif.total) + $('#desa_aktif_online>.total').text(total.desa_aktif_online.total) + + } + }, 'json') + } + + $(document).ready(function() { + $('#filter').click(function(){ + updateData() + }) + $('input[name=periods]').change(function(){ + updateData() + }) + $('#reset').click(function(){ + $('#collapse-filter select').val('') + }) + + updateData() + }) @endpush diff --git a/resources/views/website/partial/chart.blade.php b/resources/views/website/partial/chart.blade.php index 7e91c0b3..ed1ef574 100644 --- a/resources/views/website/partial/chart.blade.php +++ b/resources/views/website/partial/chart.blade.php @@ -12,23 +12,11 @@ @push('js') - @endpush \ No newline at end of file diff --git a/resources/views/website/partial/summary.blade.php b/resources/views/website/partial/summary.blade.php index 761d747c..73c18ca5 100644 --- a/resources/views/website/partial/summary.blade.php +++ b/resources/views/website/partial/summary.blade.php @@ -2,32 +2,32 @@
-
-
0
-
-
-
0
-
-
-
0
-
Kecamatan - 2
+
+
0
+
Kecamatan + 0
-
-
0
- @@ -36,14 +36,14 @@ class="fa fa-arrow-down">
-
-
0
+
+
0
Desa Aktif
-
-
0
+
+
0
Desa Aktif Online
diff --git a/routes/api.php b/routes/api.php index 84e96ced..7071e89a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -45,4 +45,5 @@ Route::prefix('web') ->group(function () { Route::get('chart-usage', [WebsiteDashboardController::class, 'chartUsage']); + Route::get('summary', [WebsiteDashboardController::class, 'summary']); });