From c1d84232eaaae594c0f6257ca6ae8ad8649a5617 Mon Sep 17 00:00:00 2001 From: BTMS2 Date: Thu, 15 May 2025 13:12:44 +0800 Subject: [PATCH] tambah laporan keseluruhan pelanggan baru --- .../PelangganbaruAllExportExcel.php | 93 ++++++ .../Controllers/Reports/AnalisaController.php | 55 ++++ resources/views/indexOverallReport.blade.php | 6 + .../reports/pelangganbaru/index.blade.php | 266 ++++++++++++++++++ routes/reports.php | 2 + 5 files changed, 422 insertions(+) create mode 100644 app/Exports/LaporanKeseluruhan/PelangganbaruAllExportExcel.php create mode 100644 app/Http/Controllers/Reports/AnalisaController.php create mode 100644 resources/views/reports/pelangganbaru/index.blade.php diff --git a/app/Exports/LaporanKeseluruhan/PelangganbaruAllExportExcel.php b/app/Exports/LaporanKeseluruhan/PelangganbaruAllExportExcel.php new file mode 100644 index 0000000..bddf9e4 --- /dev/null +++ b/app/Exports/LaporanKeseluruhan/PelangganbaruAllExportExcel.php @@ -0,0 +1,93 @@ +pelangganbaruData = $pelangganbaruData; + $this->startDate = $startDate; + $this->endDate = $endDate; + } + + public function collection() + { + return collect($this->pelangganbaruData); + } + + public function headings(): array + { + return [ + 'No.', + 'Kod Caw', + 'Nama Cawangan', + 'Jumlah', + ]; + } + + public function map($row): array + { + $jumlah = is_numeric($row['total_pelanggan_baru'] ?? null) ? (float) $row['total_pelanggan_baru'] : 0; + $this->total += $jumlah; + + return [ + $this->counter++, + $row['kodcaw'] ?? '', + $row['details_caw'] ?? '', + number_format($jumlah, 2), + ]; + } + public function startCell(): string + { + return 'A3'; // Mulakan heading di baris 3 + } + + public function registerEvents(): array + { + return [ + AfterSheet::class => function (AfterSheet $event) { + + // Tajuk laporan di A1:D1 + $event->sheet->mergeCells('A1:D1'); + $event->sheet->setCellValue('A1', 'LAPORAN PELANGGAN BARU'); + $event->sheet->getStyle('A1')->getFont()->setSize(14)->setBold(true); + $event->sheet->getStyle('A1')->getAlignment()->setHorizontal('center'); + + // Tarikh di A2:D2 + $tarikhMula = $this->startDate ? date('d/m/Y', strtotime($this->startDate)) : '-'; + $tarikhTamat = $this->endDate ? date('d/m/Y', strtotime($this->endDate)) : '-'; + $event->sheet->mergeCells('A2:D2'); + $event->sheet->setCellValue('A2', "Tempoh: {$tarikhMula} hingga {$tarikhTamat}"); + $event->sheet->getStyle('A2')->getFont()->setItalic(true); + $event->sheet->getStyle('A2')->getAlignment()->setHorizontal('center'); + + // Kira baris terakhir untuk jumlah keseluruhan + $lastRow = count($this->pelangganbaruData) + 3 + 1; // +1 untuk heading + + $event->sheet->mergeCells("A{$lastRow}:C{$lastRow}"); + $event->sheet->setCellValue("A{$lastRow}", 'Jumlah Keseluruhan'); + $event->sheet->setCellValue("D{$lastRow}", number_format($this->total, 2)); + $event->sheet->getStyle("A{$lastRow}:D{$lastRow}")->getFont()->setBold(true); + $event->sheet->getStyle("A{$lastRow}:D{$lastRow}")->getAlignment()->setHorizontal('right'); + }, + ]; + } + + + + +} diff --git a/app/Http/Controllers/Reports/AnalisaController.php b/app/Http/Controllers/Reports/AnalisaController.php new file mode 100644 index 0000000..f508ca4 --- /dev/null +++ b/app/Http/Controllers/Reports/AnalisaController.php @@ -0,0 +1,55 @@ +hostname = config('api.url'); + // dd($request->hostname ); + $kod_cawangan = $request->kod_cawangan; + $action = $request->input('action', 'search'); + // dd($action); + + $getReportDate = function ($date_string) use ($current) { + if ($date_string == null) { + return $current->toDateString(); + } + + return $date_string; + }; + + $request->hostname = config('api.url'); + + $pelangganbaru = Http::get($request->hostname . '/api/reports/pelangganbaru', [ + 'startDate' => $getReportDate($request->startDate), + 'endDate' => $getReportDate($request->endDate), + ])->json(); + // dd($pelangganbaru); + + $startDate = $getReportDate($request->startDate); + $endDate = $getReportDate($request->endDate); + + if ($action === 'excel') { + $file_title = sprintf("LaporanPelangganBaru(%s).xlsx", $kod_cawangan, $request->startDate, $request->endDate); + return Excel::download(new PelangganbaruAllExportExcel($pelangganbaru,$startDate,$endDate), $file_title); + } + + $pelangganbaru = $pelangganbaru ?? []; + + return view('reports.pelangganbaru.index', compact('pelangganbaru', 'startDate', 'endDate')); + } + + +} diff --git a/resources/views/indexOverallReport.blade.php b/resources/views/indexOverallReport.blade.php index a387d62..138f3c7 100644 --- a/resources/views/indexOverallReport.blade.php +++ b/resources/views/indexOverallReport.blade.php @@ -68,6 +68,12 @@

Peti Besi Cawangan

+
+ +

Pelanggan Baru

+
+
diff --git a/resources/views/reports/pelangganbaru/index.blade.php b/resources/views/reports/pelangganbaru/index.blade.php new file mode 100644 index 0000000..6f864e0 --- /dev/null +++ b/resources/views/reports/pelangganbaru/index.blade.php @@ -0,0 +1,266 @@ +@extends('layouts.app') + +@section('content') + +
+
+ +
+ + + + +
+
+
+
+ + + + Laporan Pelanggan Baru
+
+ +
+
+
+
+ Mula + + + Hingga + + + + + +
+
+
+
+
+
+
+
+
+
+ + +
+
+ + +
+
+ + +
+ + + + + + + + + + + + + + @php + $totalbilgadai = 0; + $totalberat = 0; + $totalnm = 0; + $totalpinjaman = 0; + @endphp + + @forelse ($pelangganbaru as $gadai) + @php + $totalbilgadai += $gadai['total_pelanggan_baru']; + $totalberat += $gadai['sum_berat']; + $totalnm += $gadai['sum_nilai_marhun']; + $totalpinjaman += $gadai['sum_pinjaman']; + @endphp + + + + + + + + + + + + @empty + + + + @endforelse + + + + + + + + + + +
+ No + + Kod Cawangan + + Cawangan + + Bil Pembiayaan + + Berat (g) + + Nilai Marhun(RM) + + Pinjaman(RM) +
+
+
+

{{ $loop->iteration }}

+
+
+
+
+
+

{{ $gadai['kodcaw'] }}

+
+
+
+
+
+

{{ $gadai['details_caw'] }}

+
+
+
+
+
+

{{ $gadai['total_pelanggan_baru'] }} +

+
+
+
+
+
+

+ {{ number_format($gadai['sum_berat'], 2) }}

+
+
+
+
+
+

+ {{ number_format($gadai['sum_nilai_marhun'], 2) }}

+
+
+
+
+
+

+ {{ number_format($gadai['sum_pinjaman'], 2) }}

+
+
+
+
+
+

Data not available

+
+
+
+
+
+

Jumlah Keseluruhan

+
+
+
+
+
+

{{ $totalbilgadai}} +

+
+
+
+
+
+

+ {{ number_format($totalberat,2) }}

+
+
+
+
+
+

+ {{ number_format($totalnm,2) }}

+
+
+
+
+
+

+ {{ number_format($totalpinjaman,2) }}

+
+
+
+
+
+

+

+
+
+
+
+
+
+ @include('layouts.footer') + +
+@endsection + + + + \ No newline at end of file diff --git a/routes/reports.php b/routes/reports.php index 64755ae..47264dd 100644 --- a/routes/reports.php +++ b/routes/reports.php @@ -9,6 +9,7 @@ use App\Http\Controllers\Reports\LelonganController; use App\Http\Controllers\Reports\AgingController; use App\Http\Controllers\Reports\OutstandingController; use App\Http\Controllers\Reports\PetibesiController; +use App\Http\Controllers\Reports\AnalisaController; use Illuminate\Support\Facades\Route; Route::middleware(['roleChecker:admin,akaun,operasi,kpo, null'])->group(function () { @@ -31,4 +32,5 @@ Route::middleware(['roleChecker:admin,akaun,operasi,kpo, null'])->group(function Route::get('laporan-aging/view', [AgingController::class, 'show'])->name('reports.aging.show'); Route::get('outstanding/view', [OutstandingController::class, 'index'])->name('reports.outstanding.index'); Route::get('petibesi/view', [PetibesiController::class, 'index'])->name('reports.petibesi.index'); + Route::get('pelangganbaru/view', [AnalisaController::class, 'index'])->name('reports.pelangganbaru.index'); });