diff --git a/app/Exports/CompanyExport.php b/app/Exports/CompanyExport.php index 4fe4518..80b7649 100644 --- a/app/Exports/CompanyExport.php +++ b/app/Exports/CompanyExport.php @@ -110,7 +110,7 @@ public function headings(): array public function styles(Worksheet $sheet) { - $sheet->mergeCells('A1:I1'); // A1 sampai D1 digabung + $sheet->mergeCells('A1:I1'); // A1 sampai I1 digabung // Set alignment untuk pusat horizontal dan vertikal $sheet->getStyle('A1:I1')->getAlignment()->setHorizontal('center'); diff --git a/app/Exports/ContentRecapExport.php b/app/Exports/ContentRecapExport.php new file mode 100644 index 0000000..ffc1abd --- /dev/null +++ b/app/Exports/ContentRecapExport.php @@ -0,0 +1,115 @@ +classification = $classification; + $this->channel = $channel; + $this->social_media = $social_media; + $this->posted_year = $posted_year; + $this->posted_month = $posted_month; + $this->posted_date = $posted_date; + } + + public function collection() + { + $query = ContentRecap::with(['enhancer', 'classification']); + + if($this->classification && $this->classification !== 'all'){ + $query->where('classification_id', decrypt_id($this->classification)); + } + + if($this->channel && $this->channel !== 'all'){ + $query->where('channel', $this->channel); + } + + if($this->social_media && $this->social_media !== 'all'){ + $query->where('social_media', $this->social_media); + } + + if ($this->posted_year) { + $query->whereYear('posted_date', $this->posted_year); + } + + if ($this->posted_month) { + $monthYear = Carbon::parse($this->posted_month); + $query->whereYear('posted_date', $monthYear->year) + ->whereMonth('posted_date', $monthYear->month); + } + + if ($this->posted_date) { + $query->whereDate('posted_date', $this->posted_date); + } + + return $query->get(); + } + + public function map($contentRecap): array + { + return [ + $this->no++, + $contentRecap->content_theme, + $contentRecap->link, + $contentRecap->classification->name, + $contentRecap->social_media, + Carbon::parse($contentRecap->posted_date)->locale('id')->translatedFormat('l, d F Y'), + $contentRecap->channel, + filled($contentRecap->description) ? strip_tags($contentRecap->description) : 'Tidak ada', + Carbon::parse($contentRecap->created_at)->locale('id')->translatedFormat('l, d F Y'), + ]; + } + + public function headings(): array + { + return [ + ['Data Rekap Konten', '', '', '', '', '', '', '', ''], + ['NO', 'Tema Konten', 'Link', 'Klasifikasi', 'Media Sosial', 'Tanggal Posting', 'Channel', 'Deskripsi', 'Dibuat Pada'] + ]; + } + + public function styles(Worksheet $sheet) + { + $sheet->mergeCells('A1:I1'); // A1 sampai D1 digabung + + // Set alignment untuk pusat horizontal dan vertikal + $sheet->getStyle('A1:I1')->getAlignment()->setHorizontal('center'); + $sheet->getStyle('A1:I1')->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); + + // Menambahkan gaya lain jika diperlukan + $sheet->getStyle('A1:I1')->getFont()->setBold(true); + $sheet->getStyle('A1:I1')->getFont()->setSize(14); + } +} diff --git a/app/Http/Controllers/Dashboard/ContentRecapController.php b/app/Http/Controllers/Dashboard/ContentRecapController.php index 2f6453e..11390dd 100644 --- a/app/Http/Controllers/Dashboard/ContentRecapController.php +++ b/app/Http/Controllers/Dashboard/ContentRecapController.php @@ -2,12 +2,15 @@ namespace App\Http\Controllers\Dashboard; +use App\Exports\ContentRecapExport; use App\Http\Controllers\Controller; use App\Http\Requests\ContentRecapRequest; use App\Models\ContentRecap; use App\Models\ContentRecapClassification; +use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Maatwebsite\Excel\Facades\Excel; class ContentRecapController extends Controller { @@ -15,8 +18,8 @@ public function index(Request $request){ return view('dashboard.content-recaps.index', [ 'title' => 'Rekap Konten', 'classifications' => ContentRecapClassification::all(), - 'classification' => $request->input('classification', null), 'channel' => $request->input('channel', null), + 'classification' => $request->input('classification', null), 'social_media' => $request->input('social_media', null), 'posted_year' => $request->input('posted_year', null), 'posted_month' => $request->input('posted_month', null), @@ -111,4 +114,29 @@ public function checkLink(Request $request) 'exists' => $linkExists ]); } + + public function filter(Request $request){ + + $filteredRequest = $request->except('_token'); + + $filterField = array_filter($filteredRequest, function ($value) { + return filled($value); + }); + + return redirect()->route('dashboard.content.recaps.index', $filterField); + } + + public function export(Request $request) + { + $classification = $request->input('classification', 'all'); + $channel = $request->input('channel', 'all'); + $social_media = $request->input('social_media', 'all'); + $posted_year = $request->input('posted_year', null); + $posted_month = $request->input('posted_month', null); + $posted_date = $request->input('posted_date', null); + + $formattedNow = Carbon::parse(now())->locale('id')->translatedFormat('d-m-Y'); + + return Excel::download(new ContentRecapExport($classification, $channel, $social_media, $posted_year, $posted_month, $posted_date), 'content-recaps-'.$formattedNow.'.xlsx'); + } } diff --git a/app/Http/Controllers/Dashboard/DatatableController.php b/app/Http/Controllers/Dashboard/DatatableController.php index ddaa22d..9330d5b 100644 --- a/app/Http/Controllers/Dashboard/DatatableController.php +++ b/app/Http/Controllers/Dashboard/DatatableController.php @@ -2095,14 +2095,49 @@ class="text-dark" public function contentRecap(Request $request){ if ($request->ajax()) { - $classificationParam = $request->input('classification', null); + $classification = $request->input('classification', null); + $channel = $request->input('channel', null); + $social_media = $request->input('social_media', null); + $posted_year = $request->input('posted_year', null); + $posted_month = $request->input('posted_month', null); + $posted_date = $request->input('posted_date', null); - if(filled($classificationParam)){ - $data = ContentRecap::where('classification_id', decrypt_id($classificationParam))->get(); - }else{ - $data = ContentRecap::all(); + $query = ContentRecap::query(); + + if($classification && $classification !== 'all'){ + $query->where('classification_id', decrypt_id($classification)); } + if($channel && $channel !== 'all'){ + $query->where('channel', $channel); + } + + if($social_media && $social_media !== 'all'){ + $query->where('social_media', $social_media); + } + + if ($posted_year) { + $query->whereYear('posted_date', $posted_year); + } + + if ($posted_month) { + $monthYear = Carbon::parse($posted_month); + $query->whereYear('posted_date', $monthYear->year) + ->whereMonth('posted_date', $monthYear->month); + } + + if ($posted_date) { + $query->whereDate('posted_date', $posted_date); + } + + $data = $query->get(); + + // if(filled($classification)){ + // $data = ContentRecap::where('classification_id', decrypt_id($classification))->get(); + // }else{ + // $data = ContentRecap::all(); + // } + return DataTables::of($data) ->addIndexColumn() diff --git a/resources/views/dashboard/content-recaps/create.blade.php b/resources/views/dashboard/content-recaps/create.blade.php index 73af02f..e946b59 100644 --- a/resources/views/dashboard/content-recaps/create.blade.php +++ b/resources/views/dashboard/content-recaps/create.blade.php @@ -18,7 +18,7 @@
@csrf
-
+
@@ -106,7 +106,7 @@
- +
diff --git a/resources/views/dashboard/content-recaps/edit.blade.php b/resources/views/dashboard/content-recaps/edit.blade.php index ab9da00..c955d85 100644 --- a/resources/views/dashboard/content-recaps/edit.blade.php +++ b/resources/views/dashboard/content-recaps/edit.blade.php @@ -19,7 +19,7 @@ @csrf @method('put')
-
+
@@ -150,7 +150,7 @@
diff --git a/resources/views/dashboard/content-recaps/index.blade.php b/resources/views/dashboard/content-recaps/index.blade.php index e4254ca..6a2ab41 100644 --- a/resources/views/dashboard/content-recaps/index.blade.php +++ b/resources/views/dashboard/content-recaps/index.blade.php @@ -17,9 +17,9 @@
  • - @if (filled(value: $channel) || filled(value: $social_media) || filled($posted_year) || filled($posted_month) || filled($posted_date)) + @if (filled(value: $channel) || filled($classification) || filled(value: $social_media) || filled($posted_year) || filled($posted_month) || filled($posted_date)) - + @@ -71,13 +71,13 @@
- + @csrf - + @csrf --}}
- -
+
- {!! display_file('news', $contentRecap->image) !!} + {!! display_file('content-recaps', $contentRecap->image) !!}
diff --git a/resources/views/partials/app/datatable.blade.php b/resources/views/partials/app/datatable.blade.php index fe7f9a3..ccbf53f 100644 --- a/resources/views/partials/app/datatable.blade.php +++ b/resources/views/partials/app/datatable.blade.php @@ -984,6 +984,11 @@ type: 'GET', data: function(d) { d.classification = '{{ $classification }}'; + d.channel = '{{ $channel }}'; + d.social_media = '{{ $social_media }}'; + d.posted_year = '{{ $posted_year }}'; + d.posted_month = '{{ $posted_month }}'; + d.posted_date = '{{ $posted_date }}'; } }, columns: [ diff --git a/routes/web.php b/routes/web.php index 70b975c..fd3cf7e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -496,6 +496,9 @@ Route::get('/{id}/edit', 'edit')->name('edit'); Route::put('/{id}', 'update')->name('update'); Route::delete('/{id}', 'destroy')->name('destroy'); + + Route::post('/export', 'export')->name('export'); + Route::post('/filter', 'filter')->name('filter'); }); Route::get('/data', [DatatableController::class, 'contentRecap'])->name('data');