feat(basicdata): tambahkan pencarian pada fitur ekspor Holiday Calendar
- Menambahkan kemampuan pencarian pada fitur ekspor Holiday Calendar. - Mengubah konstruktor `HolidayCalendarExport` untuk menerima parameter `search` yang bersifat opsional. - Menyesuaikan query pengambilan data pada `HolidayCalendarExport` agar mendukung filter berdasarkan: - Deskripsi (`description`). - Tipe (`type`). - Tanggal (`date`). - Memperbaiki logika perhitungan halaman aktif pada pagination di `HolidayCalendarController`. - Menambahkan parameter `search` pada fungsi `export` di `HolidayCalendarController`. - Memperbarui URL export pada tampilan `index.blade.php` ketika input pencarian diubah. - Menambahkan fungsi JavaScript `updateExportUrl()` untuk menyisipkan filter pencarian pada URL ekspor. - Menjamin tidak ada perubahan URL ekspor jika pencarian kosong. Fitur ini memungkinkan pengguna untuk mengekspor data kalender libur berdasarkan hasil pencarian spesifik. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -11,9 +11,27 @@ use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
|||||||
|
|
||||||
class HolidayCalendarExport implements WithColumnFormatting, WithHeadings, FromCollection, WithMapping
|
class HolidayCalendarExport implements WithColumnFormatting, WithHeadings, FromCollection, WithMapping
|
||||||
{
|
{
|
||||||
|
protected $search;
|
||||||
|
|
||||||
|
public function __construct($search = null)
|
||||||
|
{
|
||||||
|
$this->search = $search;
|
||||||
|
}
|
||||||
|
|
||||||
public function collection()
|
public function collection()
|
||||||
{
|
{
|
||||||
return HolidayCalendar::all();
|
$query = HolidayCalendar::query();
|
||||||
|
|
||||||
|
if (!empty($this->search)) {
|
||||||
|
$search = $this->search;
|
||||||
|
$query->where(function ($q) use ($search) {
|
||||||
|
$q->whereRaw('LOWER(description) LIKE ?', ['%' . strtolower($search) . '%'])
|
||||||
|
->orWhereRaw('LOWER(type) LIKE ?', ['%' . strtolower($search) . '%'])
|
||||||
|
->orWhereRaw('CAST(date AS TEXT) LIKE ?', ['%' . $search . '%']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function map($row): array
|
public function map($row): array
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
use Modules\Basicdata\Exports\HolidayCalendarExport;
|
use Modules\Basicdata\Exports\HolidayCalendarExport;
|
||||||
use Modules\Basicdata\Http\Requests\HolidayCalendarRequest;
|
use Modules\Basicdata\Http\Requests\HolidayCalendarRequest;
|
||||||
@@ -191,7 +190,7 @@
|
|||||||
$pageCount = ceil($totalRecords / $request->get('size'));
|
$pageCount = ceil($totalRecords / $request->get('size'));
|
||||||
|
|
||||||
// Calculate the current page number
|
// Calculate the current page number
|
||||||
$currentPage = 0 + 1;
|
$currentPage = $request->get('page') ?: 1;
|
||||||
|
|
||||||
// Return the response data as a JSON object
|
// Return the response data as a JSON object
|
||||||
return response()->json([
|
return response()->json([
|
||||||
@@ -205,13 +204,16 @@
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function export()
|
public function export(Request $request)
|
||||||
{
|
{
|
||||||
// Check if the authenticated user has the required permission to export holiday calendars
|
// Check if the authenticated user has the required permission to export holiday calendars
|
||||||
if (is_null($this->user) || !$this->user->can('basic-data.export')) {
|
if (is_null($this->user) || !$this->user->can('basic-data.export')) {
|
||||||
abort(403, 'Sorry! You are not allowed to export holiday calendars.');
|
abort(403, 'Sorry! You are not allowed to export holiday calendars.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return Excel::download(new HolidayCalendarExport, 'holiday_calendar.xlsx');
|
// Get search parameter from request
|
||||||
|
$search = $request->get('search');
|
||||||
|
|
||||||
|
return Excel::download(new HolidayCalendarExport($search), 'holiday_calendar.xlsx');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<div class="flex flex-wrap gap-2.5">
|
<div class="flex flex-wrap gap-2.5">
|
||||||
<div class="h-[24px] border border-r-gray-200"></div>
|
<div class="h-[24px] border border-r-gray-200"></div>
|
||||||
@can('basic-data.export')
|
@can('basic-data.export')
|
||||||
<a class="btn btn-sm btn-light" href="{{ route('basicdata.holidaycalendar.export') }}"> Export to Excel </a>
|
<a id="export-btn" class="btn btn-sm btn-light" href="{{ route('basicdata.holidaycalendar.export') }}"> Export to Excel </a>
|
||||||
@endcan
|
@endcan
|
||||||
@can('basic-data.create')
|
@can('basic-data.create')
|
||||||
<a class="btn btn-sm btn-primary" href="{{ route('basicdata.holidaycalendar.create') }}"> Tambah Hari Libur </a>
|
<a class="btn btn-sm btn-primary" href="{{ route('basicdata.holidaycalendar.create') }}"> Tambah Hari Libur </a>
|
||||||
@@ -149,6 +149,7 @@
|
|||||||
const element = document.querySelector('#holiday-calendar-table');
|
const element = document.querySelector('#holiday-calendar-table');
|
||||||
const searchInput = document.getElementById('search');
|
const searchInput = document.getElementById('search');
|
||||||
const deleteSelectedButton = document.getElementById('deleteSelected');
|
const deleteSelectedButton = document.getElementById('deleteSelected');
|
||||||
|
const exportBtn = document.getElementById('export-btn');
|
||||||
|
|
||||||
const apiUrl = element.getAttribute('data-api-url');
|
const apiUrl = element.getAttribute('data-api-url');
|
||||||
const dataTableOptions = {
|
const dataTableOptions = {
|
||||||
@@ -205,10 +206,28 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
let dataTable = new KTDataTable(element, dataTableOptions);
|
let dataTable = new KTDataTable(element, dataTableOptions);
|
||||||
|
|
||||||
|
// Update export URL with filters
|
||||||
|
function updateExportUrl() {
|
||||||
|
let url = new URL(exportBtn.href);
|
||||||
|
|
||||||
|
if (searchInput.value) {
|
||||||
|
url.searchParams.set('search', searchInput.value);
|
||||||
|
} else {
|
||||||
|
url.searchParams.delete('search');
|
||||||
|
}
|
||||||
|
|
||||||
|
exportBtn.href = url.toString();
|
||||||
|
}
|
||||||
|
|
||||||
// Custom search functionality
|
// Custom search functionality
|
||||||
searchInput.addEventListener('input', function () {
|
searchInput.addEventListener('input', function () {
|
||||||
const searchValue = this.value.trim();
|
const searchValue = this.value.trim();
|
||||||
|
dataTable.goPage(1);
|
||||||
dataTable.search(searchValue, true);
|
dataTable.search(searchValue, true);
|
||||||
|
|
||||||
|
// Update export URL with search parameter
|
||||||
|
updateExportUrl();
|
||||||
});
|
});
|
||||||
|
|
||||||
function updateDeleteButtonVisibility() {
|
function updateDeleteButtonVisibility() {
|
||||||
|
|||||||
Reference in New Issue
Block a user