add export excel and pdf district payment recaps
This commit is contained in:
31
app/Exports/DistrictPaymentRecapExport.php
Normal file
31
app/Exports/DistrictPaymentRecapExport.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\PbgTaskGoogleSheet;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
|
||||
class DistrictPaymentRecapExport implements FromCollection, WithHeadings
|
||||
{
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return PbgTaskGoogleSheet::select(
|
||||
'kecamatan',
|
||||
DB::raw('SUM(nilai_retribusi_keseluruhan_simbg) as total')
|
||||
)
|
||||
->groupBy('kecamatan')->get();
|
||||
}
|
||||
|
||||
public function headings(): array{
|
||||
return [
|
||||
'Kecamatan',
|
||||
'Total'
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -249,7 +249,7 @@ class BigDataResumeController extends Controller
|
||||
'year',
|
||||
'created_at'
|
||||
)->orderBy('id', 'desc')->get();
|
||||
$pdf = Pdf::loadView('exports.report_director', compact('data'))->setPaper('a4', 'landscape');
|
||||
$pdf = Pdf::loadView('exports.director_report', compact('data'))->setPaper('a4', 'landscape');
|
||||
return $pdf->download('laporan-pimpinan.pdf');
|
||||
}
|
||||
private function response_empty_resume(){
|
||||
|
||||
@@ -2,14 +2,17 @@
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Exports\DistrictPaymentRecapExport;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\RequestAssignmentResouce;
|
||||
use App\Models\PbgTask;
|
||||
use App\Models\PbgTaskGoogleSheet;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use DB;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class RequestAssignmentController extends Controller
|
||||
{
|
||||
@@ -49,6 +52,19 @@ class RequestAssignmentController extends Controller
|
||||
return response()->json(['message' => 'Terjadi kesalahan: ' . $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function export_excel_district_payment_recaps(){
|
||||
return Excel::download(new DistrictPaymentRecapExport, 'laporan-rekap-data-pembayaran.xlsx');
|
||||
}
|
||||
public function export_pdf_district_payment_recaps(){
|
||||
$data = PbgTaskGoogleSheet::select(
|
||||
'kecamatan',
|
||||
DB::raw('SUM(nilai_retribusi_keseluruhan_simbg) as total')
|
||||
)
|
||||
->groupBy('kecamatan')->get();
|
||||
$pdf = Pdf::loadView('exports.district_payment_report', compact('data'));
|
||||
return $pdf->download('laporan-rekap-data-pembayaran.pdf');
|
||||
}
|
||||
public function report_pbg_ptsp()
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -7,6 +7,8 @@ class ReportPaymentRecaps {
|
||||
constructor() {
|
||||
this.table = null;
|
||||
this.initTableReportPaymentRecaps();
|
||||
this.handleExportPDF();
|
||||
this.handleExportToExcel();
|
||||
}
|
||||
initTableReportPaymentRecaps() {
|
||||
let tableContainer = document.getElementById(
|
||||
@@ -63,6 +65,100 @@ class ReportPaymentRecaps {
|
||||
fixedHeader: true,
|
||||
}).render(tableContainer);
|
||||
}
|
||||
|
||||
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-rekap-data-pembayaran.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-rekap-data-pembayaran.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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
document.addEventListener("DOMContentLoaded", function (e) {
|
||||
new ReportPaymentRecaps();
|
||||
|
||||
33
resources/views/exports/district_payment_report.blade.php
Normal file
33
resources/views/exports/district_payment_report.blade.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Laporan Rekap Data Pembayaran</title>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; }
|
||||
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
|
||||
th, td { border: 1px solid black; padding: 8px; text-align: center; }
|
||||
th { background-color: #f2f2f2; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Laporan Rekap Data Pembayaran</h2>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Kecamatan</th>
|
||||
<th>Total</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($data as $item)
|
||||
<tr>
|
||||
<td>{{ $item->kecamatan }}</td>
|
||||
<td>{{ $item->total }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -13,6 +13,19 @@
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card w-100">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<h5 class="card-title mb-0">Laporan Rekap Data Pembayaran</h5>
|
||||
<div class="d-flex gap-2">
|
||||
<button class="btn btn-sm bg-black text-white d-flex align-items-center content-center gap-2" id="btn-export-excel" data-url="{{ route('api.district-payment-report.excel') }}">
|
||||
<span>.xlsx</span>
|
||||
<iconify-icon icon="mingcute:file-export-line" width="20" height="20" class="d-flex align-items-center"></iconify-icon>
|
||||
</button>
|
||||
<button class="btn btn-sm bg-black text-white d-flex align-items-center content-center gap-2" id="btn-export-pdf" data-url="{{ route('api.district-payment-report.pdf') }}">
|
||||
<span>.pdf</span>
|
||||
<iconify-icon icon="mingcute:file-export-line" width="20" height="20" class="d-flex align-items-center"></iconify-icon>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div id="table-report-payment-recaps"></div>
|
||||
</div>
|
||||
|
||||
@@ -56,6 +56,10 @@ Route::group(['middleware' => 'auth:sanctum'], function (){
|
||||
Route::apiResource('request-assignments',RequestAssignmentController::class);
|
||||
Route::get('/report-payment-recaps',[RequestAssignmentController::class, 'report_payment_recaps'])->name('report-payment-recaps');
|
||||
Route::get('/report-pbg-ptsp',[RequestAssignmentController::class, 'report_pbg_ptsp'])->name('report-pbg-ptsp');
|
||||
Route::controller(RequestAssignmentController::class)->group( function (){
|
||||
Route::get('/district-payment-report/excel', 'export_excel_district_payment_recaps')->name('api.district-payment-report.excel');
|
||||
Route::get('/district-payment-report/pdf', 'export_pdf_district_payment_recaps')->name('api.district-payment-report.pdf');
|
||||
});
|
||||
|
||||
// all dashboards
|
||||
Route::controller(DashboardController::class)->group(function(){
|
||||
|
||||
Reference in New Issue
Block a user