From 8d190cb10d5927076c647f4e0c3f3d6d5e84d39c Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Mon, 19 May 2025 09:08:33 +0700 Subject: [PATCH] feat(currency): tambahkan fitur filter pada ekspor data mata uang - Modifikasi `CurrencyController`: - Tambahkan parameter `Request` pada method `export` untuk menerima input filter `search`. - Perbarui logika ekspor agar mendukung pencarian berbasis parameter `search`. - Perubahan pada `CurrencyExport`: - Tambahkan konstruktor untuk menerima dan menyimpan parameter pencarian (`search`). - Modifikasi query pada method `collection` untuk menambahkan filter berdasarkan `code`, `name`, atau `decimal_places` yang sesuai dengan parameter `search`. - Hapus kolom `updated_at` dan `deleted_at` dari output ekspor. - Perbaikan format data pada method `columnFormats`. - Update pada view `currency/index.blade.php`: - Tambahkan elemen JavaScript untuk mengatur URL parameter `search` pada tombol ekspor. - Ganti event `change` pada input pencarian dengan `input` untuk meningkatkan respon pencarian secara real-time. - Pastikan URL ekspor diperbarui setiap kali pengguna mengetik dalam kolom pencarian. - Penyesuaian minor pada `branch/index.blade.php`: - Hapus log yang tidak relevan sebelum proses ekspor. Fitur ini memastikan proses ekspor data mata uang dapat disaring berdasarkan pencarian spesifik, memberikan fleksibilitas lebih kepada pengguna. Signed-off-by: Daeng Deni Mardaeni --- app/Exports/CurrencyExport.php | 27 +++++++++++++++++---- app/Http/Controllers/CurrencyController.php | 7 ++++-- resources/views/branch/index.blade.php | 1 - resources/views/currency/index.blade.php | 22 +++++++++++++++-- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/app/Exports/CurrencyExport.php b/app/Exports/CurrencyExport.php index fa79a92..34d238c 100644 --- a/app/Exports/CurrencyExport.php +++ b/app/Exports/CurrencyExport.php @@ -9,11 +9,30 @@ use Modules\Basicdata\Models\Currency; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; - class CurrencyExport implements WithColumnFormatting, WithHeadings, FromCollection, withMapping + class CurrencyExport implements WithColumnFormatting, WithHeadings, FromCollection, WithMapping { + protected $search; + + public function __construct($search = null) + { + $this->search = $search; + } + public function collection() { - return Currency::all(); + $query = Currency::query(); + + if (!empty($this->search)) { + $search = $this->search; + + $query->where(function ($q) use ($search) { + $q->whereRaw('LOWER(code) LIKE ?', ['%' . strtolower($search) . '%']) + ->orWhereRaw('LOWER(name) LIKE ?', ['%' . strtolower($search) . '%']) + ->orWhereRaw('CAST(decimal_places AS TEXT) LIKE ?', ['%' . $search . '%']); + }); + } + + return $query->get(); } public function map($row) @@ -24,8 +43,6 @@ $row->code, $row->name, $row->decimal_places, - $row->updated_at, - $row->deleted_at, $row->created_at ]; } @@ -47,7 +64,7 @@ { return [ 'A' => NumberFormat::FORMAT_NUMBER, - 'B' => NumberFormat::FORMAT_NUMBER, + 'D' => NumberFormat::FORMAT_NUMBER, 'E' => NumberFormat::FORMAT_DATE_DATETIME ]; } diff --git a/app/Http/Controllers/CurrencyController.php b/app/Http/Controllers/CurrencyController.php index 6fc6212..4074920 100644 --- a/app/Http/Controllers/CurrencyController.php +++ b/app/Http/Controllers/CurrencyController.php @@ -191,13 +191,16 @@ ]); } - public function export() + public function export(Request $request) { // Check if the authenticated user has the required permission to export currencies if (is_null($this->user) || !$this->user->can('basic-data.export')) { abort(403, 'Sorry! You are not allowed to export currencies.'); } - return Excel::download(new CurrencyExport, 'currency.xlsx'); + // Get search parameter from request + $search = $request->get('search'); + + return Excel::download(new CurrencyExport($search), 'currency.xlsx'); } } diff --git a/resources/views/branch/index.blade.php b/resources/views/branch/index.blade.php index c429c4b..ce1ba6f 100644 --- a/resources/views/branch/index.blade.php +++ b/resources/views/branch/index.blade.php @@ -259,7 +259,6 @@ }); exportBtn.addEventListener('click', function() { - console.log('Exporting data...'); updateExportUrl(); applyFilters(); }) diff --git a/resources/views/currency/index.blade.php b/resources/views/currency/index.blade.php index debadd8..8390845 100644 --- a/resources/views/currency/index.blade.php +++ b/resources/views/currency/index.blade.php @@ -20,7 +20,7 @@
@can('basic-data.export') - Export to Excel + Export to Excel @endcan @can('basic-data.create') Tambah Mata Uang @@ -152,6 +152,7 @@