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 <ddeni05@gmail.com>
This commit is contained in:
@@ -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
|
||||
];
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user