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 @@