From dc78f8ba32b871e8e7e3046d513d550739a2996e Mon Sep 17 00:00:00 2001 From: myuqinurrohman Date: Tue, 22 Apr 2025 11:02:02 +0700 Subject: [PATCH] feat: filter data feat: export data chore: change button in hero section landing page --- app/Exports/IssueManagementExport.php | 176 ++++++++++++ app/Exports/MediaMonitoringExport.php | 2 +- .../Dashboard/DatatableController.php | 105 +++++-- .../Dashboard/IssueManagementController.php | 44 +++ .../issue-managements/index.blade.php | 266 +++++++++++++++++- resources/views/homepage/index.blade.php | 15 +- .../views/partials/app/datatable.blade.php | 18 +- routes/web.php | 7 +- 8 files changed, 584 insertions(+), 49 deletions(-) create mode 100644 app/Exports/IssueManagementExport.php diff --git a/app/Exports/IssueManagementExport.php b/app/Exports/IssueManagementExport.php new file mode 100644 index 0000000..36303bb --- /dev/null +++ b/app/Exports/IssueManagementExport.php @@ -0,0 +1,176 @@ +classification = $classification; + $this->sub_classification = $sub_classification; + $this->location = $location; + $this->sub_location = $sub_location; + $this->government_agency = $government_agency; + $this->issue = $issue; + $this->response = $response; + $this->year = $year; + $this->month = $month; + $this->date = $date; + } + + public function collection() + { + $query = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies']); + + if ($this->classification) { + $query->where('classification_id', decrypt_id($this->classification)); + } + + if ($this->sub_classification) { + $query->where('sub_classification_id', decrypt_id($this->sub_classification)); + } + + if ($this->location) { + $query->where('location_id', decrypt_id($this->location)); + } + + if ($this->sub_location) { + $query->where('sub_location_id', decrypt_id($this->sub_location)); + } + + if ($this->government_agency) { + $query->whereHas('governmentAgencies', function ($query) { + $query->where('issue_managements_government_agencies.government_agency_id', decrypt_id($this->government_agency)); + }); + } + + if ($this->issue) { + switch($this->issue){ + case 'positive': + $query->where('issue', 'positif'); + break; + case 'negative': + $query->where('issue', 'negatif'); + break; + case 'neutral': + $query->where('issue', 'netral'); + break; + case 'crisis': + $query->where('issue', 'krisis'); + break; + } + } + + if ($this->response) { + switch($this->response){ + case 'positive': + $query->where('response', 'positif'); + break; + case 'negative': + $query->where('response', 'negatif'); + break; + case 'neutral': + $query->where('response', 'netral'); + break; + case 'crisis': + $query->where('response', 'krisis'); + break; + } + } + + if ($this->year) { + $query->whereYear('created_at', $this->year); + } + + if ($this->month) { + $monthYear = Carbon::parse($this->month); + $query->whereYear('created_at', $monthYear->year) + ->whereMonth('created_at', $monthYear->month); + } + + if ($this->date) { + $query->whereDate('created_at', $this->date); + } + + return $query->get(); + } + + public function map($issueManagement): array + { + return [ + $this->no++, + $issueManagement->mediaMonitoring->code, + $issueManagement->mediaMonitoring->title, + $issueManagement->classification->name, + $issueManagement->subClassification->name, + $issueManagement->location->name, + $issueManagement->subLocation->name, + ucfirst($issueManagement->issue), + ucfirst($issueManagement->response), + $issueManagement->governmentAgencies->map(function($agency) { + return Str::ucfirst($agency->name); + })->implode(', '), + $issueManagement->enhancer->name ?? 'Admin', + Carbon::parse($issueManagement->created_at)->locale('id')->translatedFormat('l, d F Y'), + ]; + } + + public function headings(): array + { + return [ + ['Data Managemen Isu', '', '', '', '', '', '', '', '', '', '', ''], + ['NO', 'Kode', 'Monitoring Media', 'Klasifikasi', 'Sub Klasifikasi', 'Lokus', 'Sub Lokus', 'Isu', 'Tanggapan', 'Dinas', 'Oleh', 'Dibuat Pada'] + ]; + } + + public function styles(Worksheet $sheet) + { + $sheet->mergeCells('A1:L1'); // A1 sampai D1 digabung + + // Set alignment untuk pusat horizontal dan vertikal + $sheet->getStyle('A1:L1')->getAlignment()->setHorizontal('center'); + $sheet->getStyle('A1:L1')->getAlignment()->setVertical('center'); + + $sheet->getColumnDimension('A')->setWidth(7); // Set column A width + $sheet->getColumnDimension('B')->setAutoSize(true); + $sheet->getColumnDimension('C')->setAutoSize(true); + $sheet->getColumnDimension('D')->setAutoSize(true); + $sheet->getColumnDimension('E')->setAutoSize(true); + $sheet->getColumnDimension('F')->setAutoSize(true); + $sheet->getColumnDimension('G')->setAutoSize(true); + $sheet->getColumnDimension('H')->setAutoSize(true); + $sheet->getColumnDimension('I')->setAutoSize(true); + $sheet->getColumnDimension('J')->setAutoSize(true); + $sheet->getColumnDimension('K')->setAutoSize(true); + $sheet->getColumnDimension('L')->setAutoSize(true); + + // Menambahkan gaya lain jika diperlukan + $sheet->getStyle('A1:L1')->getFont()->setBold(true); + $sheet->getStyle('A1:L1')->getFont()->setSize(14); + } +} diff --git a/app/Exports/MediaMonitoringExport.php b/app/Exports/MediaMonitoringExport.php index ce55c31..4d78790 100644 --- a/app/Exports/MediaMonitoringExport.php +++ b/app/Exports/MediaMonitoringExport.php @@ -115,7 +115,7 @@ public function map($mediaMonitoring): array public function headings(): array { return [ - ['Data Rekap Konten', '', '', '', '', '', '', '', '', '', '', '', '', ''], + ['Data Monitoring Media', '', '', '', '', '', '', '', '', '', '', '', '', ''], ['NO', 'Kode', 'Judul Berita', 'Media', 'Tema', 'Penulis', 'Channel', 'Kata Kunci', 'Influencer', 'Link', 'Halaman Berita', 'Tanggal Rilis', 'Status Isu', 'Oleh', 'Tanggal Input'] ]; diff --git a/app/Http/Controllers/Dashboard/DatatableController.php b/app/Http/Controllers/Dashboard/DatatableController.php index f32f7f2..8d91600 100644 --- a/app/Http/Controllers/Dashboard/DatatableController.php +++ b/app/Http/Controllers/Dashboard/DatatableController.php @@ -2331,34 +2331,91 @@ public function mediaMonitoring(Request $request){ public function issueManagement(Request $request){ if ($request->ajax()) { - $classificationParam = $request->input('classification', null); - $subClassificationParam = $request->input('sub_classification', null); - $locationParam = $request->input('location', null); - $subLocationParam = $request->input('sub_location', null); - $governmentAgencyParam = $request->input('government_agency', null); + $classification = $request->input('classification', null); + $sub_classification = $request->input('sub_classification', null); + $location = $request->input('location', null); + $sub_location = $request->input('sub_location', null); + $government_agency = $request->input('government_agency', null); + $issue = $request->input('issue', null); + $response = $request->input('response', null); + $year = $request->input('year', null); + $month = $request->input('month', null); + $date = $request->input('date', null); - if($classificationParam){ - $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies'])->where('classification_id', decrypt_id($classificationParam))->get(); + $query = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies']); - }else if($subClassificationParam){ - $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies'])->where('sub_classification_id', decrypt_id($subClassificationParam))->get(); - - }else if($locationParam){ - $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies'])->where('location_id', decrypt_id($locationParam))->get(); - - }else if($subLocationParam){ - $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies'])->where('sub_location_id', decrypt_id($subLocationParam))->get(); - - }else if($governmentAgencyParam){ - $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies']) - ->whereHas('governmentAgencies', function ($query) use ($governmentAgencyParam) { - $query->where('issue_managements_government_agencies.government_agency_id', decrypt_id($governmentAgencyParam)); - }) - ->get(); - }else{ - $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies'])->get(); + if ($classification) { + $query->where('classification_id', decrypt_id($classification)); } + if ($sub_classification) { + $query->where('sub_classification_id', decrypt_id($sub_classification)); + } + + if ($location) { + $query->where('location_id', decrypt_id($location)); + } + + if ($sub_location) { + $query->where('sub_location_id', decrypt_id($sub_location)); + } + + if ($government_agency) { + $query->whereHas('governmentAgencies', function ($query) use ($government_agency) { + $query->where('issue_managements_government_agencies.government_agency_id', decrypt_id($government_agency)); + }); + } + + if ($issue) { + switch($issue){ + case 'positive': + $query->where('issue', 'positif'); + break; + case 'negative': + $query->where('issue', 'negatif'); + break; + case 'neutral': + $query->where('issue', 'netral'); + break; + case 'crisis': + $query->where('issue', 'krisis'); + break; + } + } + + if ($response) { + switch($response){ + case 'positive': + $query->where('response', 'positif'); + break; + case 'negative': + $query->where('response', 'negatif'); + break; + case 'neutral': + $query->where('response', 'netral'); + break; + case 'crisis': + $query->where('response', 'krisis'); + break; + } + } + + if ($year) { + $query->whereYear('created_at', $year); + } + + if ($month) { + $monthYear = Carbon::parse($month); + $query->whereYear('created_at', $monthYear->year) + ->whereMonth('created_at', $monthYear->month); + } + + if ($date) { + $query->whereDate('created_at', $date); + } + + $data = $query->get(); + return DataTables::of($data) ->addIndexColumn() diff --git a/app/Http/Controllers/Dashboard/IssueManagementController.php b/app/Http/Controllers/Dashboard/IssueManagementController.php index b9dbce1..1f1e9aa 100644 --- a/app/Http/Controllers/Dashboard/IssueManagementController.php +++ b/app/Http/Controllers/Dashboard/IssueManagementController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Dashboard; +use App\Exports\IssueManagementExport; use App\Http\Controllers\Controller; use App\Http\Requests\IssueManagementRequest; use App\Models\Classification; @@ -11,8 +12,10 @@ use App\Models\MediaMonitoring; use App\Models\SubClassification; use App\Models\SubLocation; +use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Maatwebsite\Excel\Facades\Excel; class IssueManagementController extends Controller { @@ -24,6 +27,18 @@ public function index(Request $request){ 'location' => $request->input('location', null), 'sub_location' => $request->input('sub_location', null), 'government_agency' => $request->input('government_agency', null), + 'media_monitoring' => $request->input('media_monitoring', null), + 'issue' => $request->input('issue', null), + 'response' => $request->input('response', null), + 'year' => $request->input('year', null), + 'month' => $request->input('month', null), + 'date' => $request->input('date', null), + + 'locations' => Location::all(), + 'sub_locations' => SubLocation::all(), + 'classifications' => Classification::all(), + 'sub_classifications' => SubClassification::all(), + 'government_agencies' => GovernmentAgency::all(), ]); } @@ -131,4 +146,33 @@ public function getSubClassifications($location_id) return response()->json(['sub_classifications' => $subLocations]); } + + public function filter(Request $request){ + + $filteredRequest = $request->except('_token'); + + $filterField = array_filter($filteredRequest, function ($value) { + return filled($value); + }); + + return redirect()->route('dashboard.issue.managements.index', $filterField); + } + + public function export(Request $request) + { + $classification = $request->input('classification', null); + $sub_classification = $request->input('sub_classification', null); + $location = $request->input('location', null); + $sub_location = $request->input('sub_location', null); + $government_agency = $request->input('government_agency', null); + $issue = $request->input('issue', null); + $response = $request->input('response', null); + $year = $request->input('year', null); + $month = $request->input('month', null); + $date = $request->input('date', null); + + $formattedNow = Carbon::parse(now())->locale('id')->translatedFormat('d-m-Y'); + + return Excel::download(new IssueManagementExport($classification, $sub_classification, $location, $sub_location, $government_agency, $issue, $response, $year, $month, $date), 'issue-managements-'.$formattedNow.'.xlsx'); + } } diff --git a/resources/views/dashboard/issue-managements/index.blade.php b/resources/views/dashboard/issue-managements/index.blade.php index bd32549..bbb70ce 100644 --- a/resources/views/dashboard/issue-managements/index.blade.php +++ b/resources/views/dashboard/issue-managements/index.blade.php @@ -11,28 +11,32 @@

{{$title}}

- {{--
+
  • -
    - Last 30 Days - + @if (filled(value: $media_monitoring) || filled(value: $classification) || filled(value: $sub_classification) || filled(value: $location) || filled(value: $sub_location) || filled($year) || filled(value: $government_agency) || filled(value: $issue) || filled($response) || filled($year) || filled($month) || filled($date)) + + + + + + @endif +
    + Filter +
    +
  • +
  • +
    + Export
  • -
  • Tambah
-
--}} +
@@ -61,6 +65,244 @@
+ + diff --git a/resources/views/homepage/index.blade.php b/resources/views/homepage/index.blade.php index 461f93f..8b42270 100644 --- a/resources/views/homepage/index.blade.php +++ b/resources/views/homepage/index.blade.php @@ -8,21 +8,16 @@
-
+
Simedkom
-
+
Sistem Media Komunikasi Kabupaten Purwakarta
-
@@ -42,7 +37,7 @@
- Tentang Kami + Tentang Kami

Simedkom

{{strip_tags($app->about_us)}}

diff --git a/resources/views/partials/app/datatable.blade.php b/resources/views/partials/app/datatable.blade.php index ab7dc21..8851692 100644 --- a/resources/views/partials/app/datatable.blade.php +++ b/resources/views/partials/app/datatable.blade.php @@ -1091,7 +1091,23 @@ $('#issueManagementsTable').DataTable({ processing: true, serverSide: true, - ajax: '{{ route('dashboard.issue.managements.data', ["classification" => $classification, "sub_classification" => $sub_classification, "location" => $location, "sub_location" => $sub_location, "government_agency" => $government_agency]) }}', + ajax: { + url: '{{ route('dashboard.issue.managements.data') }}', + type: 'GET', + data: function(d) { + d.classification = '{{ $classification }}'; + d.sub_classification = '{{ $sub_classification }}'; + d.location = '{{ $location }}'; + d.sub_location = '{{ $sub_location }}'; + d.government_agency = '{{ $government_agency }}'; + d.media_monitoring = '{{ $media_monitoring }}'; + d.issue = '{{ $issue }}'; + d.response = '{{ $response }}'; + d.year = '{{ $year }}'; + d.month = '{{ $month }}'; + d.date = '{{ $date }}'; + } + }, columns: [ { data: 'DT_RowIndex', name: 'DT_RowIndex', orderable: false, searchable: false }, { data: 'code', name: 'code' }, diff --git a/routes/web.php b/routes/web.php index bd38456..dab9166 100644 --- a/routes/web.php +++ b/routes/web.php @@ -530,7 +530,8 @@ Route::controller(IssueManagementController::class)->group(function(){ Route::get('/', 'index')->name('index'); Route::get('/create', 'create')->name('create'); - Route::post('/{media_monitoring_id}', 'store')->name('store'); + Route::post('/create/{media_monitoring_id}', 'store')->name('store'); + Route::get('/{id}/show', 'show')->name('show'); Route::get('/{id}/edit', 'edit')->name('edit'); Route::put('/{id}', 'update')->name('update'); @@ -539,6 +540,10 @@ // AJAX Route::get('/get-sub-locations/{location_id}', 'getSubLocations')->name('get.sub.locations'); Route::get('/get-sub-classifications/{classification_id}', 'getSubClassifications')->name('get.sub.classifications'); + // AJAX END + + Route::post('/filter', 'filter')->name('filter'); + Route::post('/export', 'export')->name('export'); }); Route::get('/data', [DatatableController::class, 'issueManagement'])->name('data');