update task uum bycaw
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
class DataPelangganBycawDetailExport implements
|
||||
FromCollection,
|
||||
WithHeadings,
|
||||
WithMapping,
|
||||
WithStyles,
|
||||
WithCustomStartCell
|
||||
{
|
||||
protected $pelanggan;
|
||||
protected $year;
|
||||
protected $no = 0;
|
||||
|
||||
public function __construct($pelanggan, $year)
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user