diff --git a/app/Exports/ReportTourismExport.php b/app/Exports/ReportTourismExport.php new file mode 100644 index 0000000..10ccce5 --- /dev/null +++ b/app/Exports/ReportTourismExport.php @@ -0,0 +1,25 @@ +get(); + } + + public function headings(): array{ + return [ + 'Jenis Bisnis Pariwisata', + 'Jumlah Total' + ]; + } +} diff --git a/app/Http/Controllers/Api/ReportTourismsController.php b/app/Http/Controllers/Api/ReportTourismsController.php new file mode 100644 index 0000000..ec4b5d6 --- /dev/null +++ b/app/Http/Controllers/Api/ReportTourismsController.php @@ -0,0 +1,15 @@ + [item.kbli_title, item.total_records]), // Mengubah data untuk Grid.js - search: true, // Menambahkan fitur pencarian - pagination: true, // Menambahkan fitur pagination - sort: true, // Menambahkan fitur sorting + columns: ["Jenis Bisnis Pariwisata", "Jumlah Total"], // Nama kolom + data: businessTypeCounts.map((item) => [ + item.kbli_title, + item.total_records, + ]), // Mengubah data untuk Grid.js + search: true, // Menambahkan fitur pencarian + pagination: true, // Menambahkan fitur pagination + sort: true, // Menambahkan fitur sorting }).render(document.getElementById("tourisms-report-data-table")); + +class TourismReport { + constructor() {} + init() { + this.handleExportToExcel(); + } + + async handleExportToExcel() { + const button = document.getElementById("btn-export-excel"); + if (!button) { + console.error("Button not found: #btn-export-excel"); + return; + } + + let exportUrl = button.getAttribute("data-url"); + + button.addEventListener("click", async () => { + button.disabled = true; + try { + const response = await fetch(`${exportUrl}`, { + method: "GET", + credentials: "include", + headers: { + Authorization: `Bearer ${document + .querySelector('meta[name="api-token"]') + .getAttribute("content")}`, + }, + }); + if (!response.ok) { + console.error("Error fetching data:", response.statusText); + button.disabled = false; + return; + } + + // Convert response to Blob and trigger download + const blob = await response.blob(); + const url = window.URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = url; + a.download = "laporan-pariwisata.xlsx"; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + window.URL.revokeObjectURL(url); + } catch (error) { + console.error("Error fetching data:", error); + button.disabled = false; + return; + } finally { + button.disabled = false; + } + }); + } +} + +document.addEventListener("DOMContentLoaded", function () { + new TourismReport().init(); +}); diff --git a/resources/views/report/tourisms/index.blade.php b/resources/views/report/tourisms/index.blade.php index 3831122..f96b566 100644 --- a/resources/views/report/tourisms/index.blade.php +++ b/resources/views/report/tourisms/index.blade.php @@ -9,8 +9,18 @@