diff --git a/app/Exports/DataPelangganBycawDetailExport.php b/app/Exports/DataPelangganBycawDetailExport.php new file mode 100644 index 0000000..efdae3c --- /dev/null +++ b/app/Exports/DataPelangganBycawDetailExport.php @@ -0,0 +1,130 @@ +pelanggan = collect($pelanggan); + $this->year = $year; + } + + /** + * Data source + */ + public function collection(): Collection + { + return $this->pelanggan; + } + + /** + * Start data from row 5 (sebab ada tajuk) + */ + public function startCell(): string + { + return 'A5'; + } + + /** + * Header column + */ + public function headings(): array + { + return [ + 'No', + 'Cawangan', + 'No.Pelanggan', + 'Umur', + 'Jantina', + 'Pekerjaan', + 'Lokasi', + 'Tempoh Pajakan', + 'Tarikh Mula', + 'Tarikh Tamat', + 'Hari Sejak Transaksi Terakhir', + 'Bil Transaksi', + 'Bil Outstanding', + 'Bil Tebus', + 'Jumlah Pinjaman (RM)', + 'Jumlah Ujrah (RM)', + 'Tujuan Gadaian', + 'Status Aktif', + 'Cara Bayaran', + 'Tarikh Lelong', + ]; + } + + /** + * Map setiap row + */ + public function map($row): array + { + return [ + ++$this->no, + $row['cawangan'], + $row['nopelanggan'], + $row['umur'], + $row['jantina'], + $row['pekerjaan'], + $row['daerah'], + $row['tempoh_pajakan'], + $row['tarikh_mula'], + $row['tarikh_tamat'], + $row['hari_sejak_transaksi'], + $row['bil_transaksi'], + $row['bil_outstanding'], + $row['bil_tebus'], + number_format($row['jumlah_pinjaman'], 2), + number_format($row['jumlah_ujrah'], 2), + $row['tujuan_gadai'], + $row['status_aktif'], + $row['cara_bayaran'], + $row['tarikh_lelong'] ?? '-', + ]; + } + + /** + * Styling Excel + */ + public function styles(Worksheet $sheet) + { + // Tajuk utama + $sheet->mergeCells('A1:R1'); + $sheet->setCellValue('A1', 'LAPORAN DATA PELANGGAN MENGIKUT CAWANGAN'); + $sheet->getStyle('A1')->getFont()->setBold(true)->setSize(14); + $sheet->getStyle('A1')->getAlignment()->setHorizontal('center'); + + // Tahun + $sheet->mergeCells('A2:R2'); + $sheet->setCellValue('A2', 'TAHUN : ' . $this->year); + $sheet->getStyle('A2')->getFont()->setBold(true); + $sheet->getStyle('A2')->getAlignment()->setHorizontal('center'); + + // Header table + $sheet->getStyle('A5:R5')->getFont()->setBold(true); + $sheet->getStyle('A5:R5')->getAlignment()->setHorizontal('center'); + + // Auto width + foreach (range('A', 'R') as $col) { + $sheet->getColumnDimension($col)->setAutoSize(true); + } + } +} diff --git a/app/Http/Controllers/Reports/AnalisaController.php b/app/Http/Controllers/Reports/AnalisaController.php index a3059b4..504adc8 100644 --- a/app/Http/Controllers/Reports/AnalisaController.php +++ b/app/Http/Controllers/Reports/AnalisaController.php @@ -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'); + } + + + + diff --git a/resources/views/indexOverallReport.blade.php b/resources/views/indexOverallReport.blade.php index 16fe820..19abb71 100644 --- a/resources/views/indexOverallReport.blade.php +++ b/resources/views/indexOverallReport.blade.php @@ -122,6 +122,12 @@

Data Pelanggan

+
+ +

Data Pelanggan By Cawangan

+
+
diff --git a/resources/views/reports/data-pelanggan-bycaw/index.blade.php b/resources/views/reports/data-pelanggan-bycaw/index.blade.php new file mode 100644 index 0000000..0455c5a --- /dev/null +++ b/resources/views/reports/data-pelanggan-bycaw/index.blade.php @@ -0,0 +1,241 @@ +@extends('layouts.app') + +@section('content') + + +
+
+
+ + {{-- Breadcrumb --}} + + + +
+ + {{-- Error Alert --}} + @if ($errors->any()) +
+ +
+ @endif + +
+
+ + {{-- Header --}} +
+ + + + + Laporan Data Pelanggan By Cawangan + +
+ + {{-- FORM --}} +
+ + + +
+ + {{-- Tahun --}} +
+ + +
+ + Tahun + + + + + {{-- Hidden generate type --}} + + + + {{-- Excel --}} + + + {{-- PDF --}} + +
+
+ + {{-- Pilih Cawangan --}} +
+ + + {{-- Select All --}} +
+ +
+ +
+ Memuatkan senarai cawangan... +
+
+ +
+
+ +
+
+
+
+
+ + @include('layouts.footer') +
+ +{{-- Loading Overlay --}} + +@endsection + +@push('additional_scripts') + +@endpush diff --git a/resources/views/reports/data-pelanggan-bycaw/show.blade.php b/resources/views/reports/data-pelanggan-bycaw/show.blade.php new file mode 100644 index 0000000..25473b1 --- /dev/null +++ b/resources/views/reports/data-pelanggan-bycaw/show.blade.php @@ -0,0 +1,247 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
Laporan Data Pelanggan + Tarikh Cetak: {{ $tarikh_cetak }} +
TAHUN LAPORAN{{ $tebus_date }}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @foreach($pelanggan as $index => $row) + + + + + + + + + + + + + + + + + + + + + + + + @endforeach + +
NoCawanganNo.PelangganUmurJantinaPekerjaanLokasiTempoh PajakanTarikh MulaTarikh TamatHari Sejak Transaksi TerakhirBil TransaksiBil OutstandingBil TebusJumlah Pinjaman (RM)Jumlah Ujrah (RM)Tujuan GadaianStatus AktifCara BayaranTarikh Lelong
{{ $index + 1 }}{{ $row['cawangan'] }}{{ $row['nopelanggan'] }}{{ $row['umur'] }}{{ $row['jantina'] }}{{ $row['pekerjaan'] }}{{ $row['daerah'] }}{{ $row['tempoh_pajakan'] }}{{ $row['tarikh_mula'] }}{{ $row['tarikh_tamat'] }}{{ $row['hari_sejak_transaksi'] }}{{ $row['bil_transaksi'] }}{{ $row['bil_outstanding'] }}{{ $row['bil_tebus'] }}{{ number_format($row['jumlah_pinjaman'], 2) }}{{ number_format($row['jumlah_ujrah'], 2) }}{{ $row['tujuan_gadai'] }}{{ $row['status_aktif'] }}{{ $row['cara_bayaran'] }}{{ $row['tarikh_lelong'] }}
+ +
+
+ + + + + + + + + + + + + + + +
.................................................................. ..................................................................
DI SEMAK DI SAHKAN
diff --git a/routes/reports.php b/routes/reports.php index e33ac7e..2276692 100644 --- a/routes/reports.php +++ b/routes/reports.php @@ -56,4 +56,8 @@ Route::middleware(['roleChecker:admin,akaun,operasi,kpo,callcenter, null'])->gro Route::get('data-pelanggan-index', [AnalisaController::class, 'dataPelanggan'])->name('reports.dataPelanggan.index'); Route::get('data-pelanggan-show', [AnalisaController::class, 'dataPelangganShow'])->name('reports.dataPelanggan.show'); + + Route::get('data-pelanggan-bycaw-index', [AnalisaController::class, 'dataPelangganBycaw'])->name('reports.dataPelangganBycaw.index'); + Route::get('data-pelanggan-bycaw-show', [AnalisaController::class, 'dataPelangganBycawShow'])->name('reports.dataPelangganBycaw.show'); + });