diff --git a/app/Exports/ReportDirectorExport.php b/app/Exports/ReportDirectorExport.php new file mode 100644 index 0000000..1dc403c --- /dev/null +++ b/app/Exports/ReportDirectorExport.php @@ -0,0 +1,90 @@ +orderBy('id', 'desc')->get(); + } + public function headings(): array{ + return [ + "Jumlah Potensi" , + "Total Potensi" , + "Jumlah Berkas Belum Terverifikasi" , + "Total Berkas Belum Terverifikasi" , + "Jumlah Berkas Terverifikasi" , + "Total Berkas Terverifikasi" , + "Jumlah Usaha" , + "Total Usaha" , + "Jumlah Non Usaha" , + "Total Non Usaha" , + "Jumlah Tata Ruang" , + "Total Tata Ruang" , + "Jumlah Menunggu Klik DPMPTSP" , + "Total Menunggu Klik DPMPTSP" , + "Jumlah Realisasi Terbit PBG" , + "Total Realisasi Terbit PBG" , + "Jumlah Proses Dinas Teknis" , + "Total Proses Dinas Teknis", + "Tahun", + "Created" + ]; + } + + public function map($row): array + { + return [ + $row->potention_count, + $row->potention_sum, + $row->non_verified_count, + $row->non_verified_sum, + $row->verified_count, + $row->verified_sum, + $row->business_count, + $row->business_sum, + $row->non_business_count, + $row->non_business_sum, + $row->spatial_count, + $row->spatial_sum, + $row->waiting_click_dpmptsp_count, + $row->waiting_click_dpmptsp_sum, + $row->issuance_realization_pbg_count, + $row->issuance_realization_pbg_sum, + $row->process_in_technical_office_count, + $row->process_in_technical_office_sum, + $row->year, + $row->created_at ? $row->created_at->format('Y-m-d H:i:s') : null, // Format created_at as Y-m-d + ]; + } +} diff --git a/app/Http/Controllers/Api/BigDataResumeController.php b/app/Http/Controllers/Api/BigDataResumeController.php index 72446df..ff08b4a 100644 --- a/app/Http/Controllers/Api/BigDataResumeController.php +++ b/app/Http/Controllers/Api/BigDataResumeController.php @@ -2,12 +2,15 @@ namespace App\Http\Controllers\Api; +use App\Exports\ReportDirectorExport; use App\Http\Controllers\Controller; use App\Http\Resources\BigdataResumeResource; use App\Models\BigdataResume; use App\Models\DataSetting; +use Barryvdh\DomPDF\Facade\Pdf; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; +use Maatwebsite\Excel\Facades\Excel; class BigDataResumeController extends Controller { @@ -219,7 +222,36 @@ class BigDataResumeController extends Controller } } + public function export_excel_report_director(){ + return Excel::download(new ReportDirectorExport, 'laporan-pimpinan.xlsx'); + } + public function export_pdf_report_director(){ + $data = BigdataResume::select( + 'potention_count', + 'potention_sum', + 'non_verified_count', + 'non_verified_sum', + 'verified_count', + 'verified_sum', + 'business_count', + 'business_sum', + 'non_business_count', + 'non_business_sum', + 'spatial_count', + 'spatial_sum', + 'waiting_click_dpmptsp_count', + 'waiting_click_dpmptsp_sum', + 'issuance_realization_pbg_count', + 'issuance_realization_pbg_sum', + 'process_in_technical_office_count', + 'process_in_technical_office_sum', + 'year', + 'created_at' + )->orderBy('id', 'desc')->get(); + $pdf = Pdf::loadView('exports.report_director', compact('data'))->setPaper('a4', 'landscape'); + return $pdf->download('laporan-pimpinan.pdf'); + } private function response_empty_resume(){ $result = [ 'target_pad' => [ diff --git a/resources/js/bigdata-resumes/index.js b/resources/js/bigdata-resumes/index.js index 424b787..12a2374 100644 --- a/resources/js/bigdata-resumes/index.js +++ b/resources/js/bigdata-resumes/index.js @@ -17,6 +17,8 @@ class BigdataResume { async initEvents() { await this.initBigdataResumeTable(); // this.handleSearch(); + await this.handleExportPDF(); + await this.handleExportToExcel(); } async initBigdataResumeTable() { @@ -114,6 +116,100 @@ class BigdataResume { }); } + 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-pimpinan.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; + } + }); + } + + async handleExportPDF() { + const button = document.getElementById("btn-export-pdf"); + if (!button) { + console.error("Button not found: #btn-export-pdf"); + 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-pimpinan.pdf"; + 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; + } + }); + } + handleSearch() { document.getElementById("search-btn").addEventListener("click", () => { let searchValue = document.getElementById("search-box").value; diff --git a/resources/views/bigdata-resumes/index.blade.php b/resources/views/bigdata-resumes/index.blade.php index ec8e657..d104143 100644 --- a/resources/views/bigdata-resumes/index.blade.php +++ b/resources/views/bigdata-resumes/index.blade.php @@ -13,6 +13,19 @@
| Jumlah Potensi | +Total Potensi | +Jumlah Berkas Belum Terverifikasi | +Total Berkas Belum Terverifikasi | +Jumlah Berkas Terverifikasi | +Total Berkas Terverifikasi | +Jumlah Usaha | +Total Usaha | +Jumlah Non Usaha | +Total Non Usaha | +Jumlah Tata Ruang | +Total Tata Ruang | +Jumlah Menunggu Klik DPMPTSP | +Total Menunggu Klik DPMPTSP | +Jumlah Realisasi Terbit PBG | +Total Realisasi Terbit PBG | +Jumlah Proses Dinas Teknis | +Total Proses Dinas Teknis | +Tahun | +Created | +
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {{ $item->potention_count }} | +{{ $item->potention_sum }} | +{{ $item->non_verified_count }} | +{{ $item->non_verified_sum }} | +{{ $item->verified_count }} | +{{ $item->verified_sum }} | +{{ $item->business_count }} | +{{ $item->business_sum }} | +{{ $item->non_business_count }} | +{{ $item->non_business_sum }} | +{{ $item->spatial_count }} | +{{ $item->spatial_sum }} | +{{ $item->waiting_click_dpmptsp_count }} | +{{ $item->waiting_click_dpmptsp_sum }} | +{{ $item->issuance_realization_pbg_count }} | +{{ $item->issuance_realization_pbg_sum }} | +{{ $item->process_in_technical_office_count }} | +{{ $item->process_in_technical_office_sum }} | +{{ $item->year }} | +{{ $item->created_at->format('Y-m-d') }} | +