update analisa controller

This commit is contained in:
Nur Izzati
2026-01-14 09:40:03 +08:00
parent ee8bf400b5
commit 6c781051ad
@@ -11,6 +11,7 @@ use Maatwebsite\Excel\Facades\Excel;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use App\Exports\LaporanKeseluruhan\PelangganbaruAllExportExcel; use App\Exports\LaporanKeseluruhan\PelangganbaruAllExportExcel;
use App\Exports\LaporanKeseluruhan\PelangganaktifAllExportExcel; use App\Exports\LaporanKeseluruhan\PelangganaktifAllExportExcel;
use App\Exports\DataPelangganDetailExport;
class AnalisaController extends Controller class AnalisaController extends Controller
{ {
@@ -90,5 +91,52 @@ class AnalisaController extends Controller
return view('reports.pelangganaktif.index', compact('pelangganaktif', 'startDate', 'endDate')); return view('reports.pelangganaktif.index', compact('pelangganaktif', 'startDate', 'endDate'));
} }
public function dataPelanggan(Request $request)
{
$request->hostname = config('api.url');
$current = new Carbon();
$month = $request->filled('month') ? $request->month : $current->month;
$year = $request->filled('year') ? $request->year : $current->year;
return view('reports.data-pelanggan.index', compact('month', 'year'));
}
public function dataPelangganShow(Request $request)
{
$validated = $request->validate([
'year' => 'required|digits:4'
]);
$year = $validated['year'];
$tarikh_cetak = now()->format('d/m/Y');
$tebus_date = 'Tahun ' . $year;
$request->hostname = config('api.url');
$response = Http::get($request->hostname . '/api/reports/data-pelanggan', [
'year' => $year,
])->json();
$summary = $response['summary'];
$pelanggan = $response['pelanggan'];
if ($request->generateType === 'pdf') {
return view(
'reports.data-pelanggan.show',
compact('summary','pelanggan','tarikh_cetak','tebus_date','year')
);
}
elseif ($request->generateType === 'excel') {
return Excel::download(
new DataPelangganDetailExport($pelanggan, $year),
"Laporan-Data-Pelanggan-{$year}.xlsx"
);
}
}
} }