update task uum bycaw

This commit is contained in:
Nur Izzati
2026-02-10 10:43:03 +08:00
parent c2093121bf
commit 39605d8bb7
6 changed files with 691 additions and 0 deletions
@@ -12,6 +12,7 @@ use Illuminate\Support\Facades\Auth;
use App\Exports\LaporanKeseluruhan\PelangganbaruAllExportExcel;
use App\Exports\LaporanKeseluruhan\PelangganaktifAllExportExcel;
use App\Exports\DataPelangganDetailExport;
use App\Exports\DataPelangganBycawDetailExport;
class AnalisaController extends Controller
{
@@ -136,6 +137,68 @@ class AnalisaController extends Controller
}
public function dataPelangganBycaw(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-bycaw.index', compact('month', 'year'));
}
public function dataPelangganBycawShow(Request $request)
{
$validated = $request->validate([
'year' => 'required|digits:4',
'cawangan' => 'required|array|min:1'
]);
$year = $validated['year'];
$cawangan = $validated['cawangan']; // array kod cawangan
$tarikh_cetak = now()->format('d/m/Y');
$tebus_date = 'Tahun ' . $year;
$request->hostname = config('api.url');
// 🔑 Forward ke API
$response = Http::get(
$request->hostname . '/api/reports/data-pelanggan-bycaw',
[
'year' => $year,
'cawangan' => $cawangan, // array terus
]
)->json();
if (!isset($response['summary'], $response['pelanggan'])) {
abort(500, 'Data API tidak sah');
}
$summary = $response['summary'];
$pelanggan = $response['pelanggan'];
if ($request->generateType === 'pdf') {
return view(
'reports.data-pelanggan-bycaw.show',
compact('summary','pelanggan','tarikh_cetak','tebus_date','year','cawangan')
);
}
if ($request->generateType === 'excel') {
return Excel::download(
new DataPelangganBycawDetailExport($pelanggan, $year, $cawangan),
"Laporan-Data-Pelanggan-Bycaw-{$year}.xlsx"
);
}
abort(400, 'Jenis laporan tidak sah');
}