diff --git a/app/Exports/SAExportAudit.php b/app/Exports/SAExportAudit.php new file mode 100644 index 0000000..757f3d9 --- /dev/null +++ b/app/Exports/SAExportAudit.php @@ -0,0 +1,172 @@ +stokaudit = $stokaudit; + $this->jenisLaporan = strtoupper($jenisLaporan); + $this->tebus_date = $tebus_date; + $this->namacaw = $namacaw; + } + + public function collection() + { + $data = collect($this->stokaudit); + + $totals = [ + 'No Rujukan' => 'TOTAL', + 'No KP' => '', + 'Marhun' => '', + 'Tempoh' => '', + 'Berat (g)' => $data->sum('Berat (g)'), + 'Nilai Marhun' => $data->sum('Nilai Marhun'), + 'Pinjaman' => $data->sum('Pinjaman'), + 'Baki Pinjaman' => $data->sum('Baki Pinjaman'), + ]; + + $data->push($totals); + + return $data; + } + + public function headings(): array + { + return [ + ['LAPORAN STOK AUDIT'], + ["CAWANGAN:", $this->namacaw], + ["TARIKH:", $this->tebus_date], + [], + [ + 'BIL', + 'NORUJUKAN', + 'NO KP', + 'MARHUN', + 'BERAT (G)', + 'BERAT AUDIT', + 'NILAI MARHUN (RM)', + 'PINJAMAN (RM)', + 'BAKI PINJAMAN (RM)', + 'TEMPOH', + 'CATATAN' + ] + ]; + } + + public function startCell(): string + { + return 'A1'; + } + + public function map($row): array + { + static $counter = 1; + + if (($row['No Rujukan'] ?? '') === 'TOTAL') { + return [ + '', + 'JUMLAH', + '', + '', + $row['Berat (g)'] ?? 0, + '', + $row['Nilai Marhun'] ?? 0, + $row['Pinjaman'] ?? 0, + $row['Baki Pinjaman'] ?? 0, + '', + '', + ]; + } + + return [ + $row['Bil'] ?? $counter++, + $row['No Rujukan'] ?? '', + isset($row['No KP']) ? "'" . $row['No KP'] : '', + $row['Marhun'] ?? '', + $row['Berat (g)'] ?? 0, + '', + $row['Nilai Marhun'] ?? 0, + $row['Pinjaman'] ?? 0, + $row['Baki Pinjaman'] ?? 0, + $row['Tempoh'] ?? '', + '', + ]; + } + + public function title(): string + { + return $this->jenisLaporan; + } + + public function styles(Worksheet $sheet) + { + $sheet->mergeCells('A1:K1'); + $sheet->getStyle('A1')->getFont()->setBold(true)->setSize(16); + $sheet->getStyle('A1')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); + + $sheet->getStyle('A5:K5')->getFont()->setBold(true); + + // Border untuk semua data + $lastRow = $sheet->getHighestRow(); + $lastCol = 'K'; + $sheet->getStyle("A5:{$lastCol}{$lastRow}")->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN); + + // Bold TOTAL row + $sheet->getStyle("A{$lastRow}:{$lastCol}{$lastRow}")->getFont()->setBold(true); + + // Align center for some columns + $sheet->getStyle("A5:A{$lastRow}")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); + $sheet->getStyle("B5:B{$lastRow}")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); + $sheet->getStyle("C5:C{$lastRow}")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); + $sheet->getStyle("D5:D{$lastRow}")->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER); + + return []; + } + + public function columnWidths(): array + { + return [ + 'A' => 5, + 'B' => 20, + 'C' => 18, + 'D' => 18, + 'E' => 12, + 'F' => 15, + 'G' => 18, + 'H' => 18, + 'I' => 18, + 'J' => 12, + 'K' => 15, + ]; + } + + public function columnFormats(): array + { + return [ + 'E' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, + 'F' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, + 'G' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, + 'H' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, + 'I' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, + ]; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/AkaunController.php b/app/Http/Controllers/AkaunController.php index 25fa38d..bdaae3e 100644 --- a/app/Http/Controllers/AkaunController.php +++ b/app/Http/Controllers/AkaunController.php @@ -23,6 +23,7 @@ use Maatwebsite\Excel\Facades\Excel; use App\Exports\PendSerExport; use App\Exports\SAExport; use App\Exports\SAcombineExport; +use App\Exports\SAExportAudit; class AkaunController extends Controller { @@ -768,6 +769,49 @@ class AkaunController extends Controller $cawangan_detail['namacaw']// ✅ Use the correct branch name from API ), 'laporan_stokaudit_' . $request->kodcaw . '_' . $tebus_date . '.xlsx'); } + elseif ($request->jenis == 'excelaudit') { + + if ($request->radaktif === 'aktif') { + $stokaudit = Http::get($api_url . '/api/stokaudit/aktif/' . $request->kodcaw, [ + 'tarikh' => $tebus_date + ])->json(); + } else { + $stokaudit = Http::get($api_url . '/api/stokaudit/takaktif/' . $request->kodcaw, [ + 'tarikh' => $tebus_date + ])->json(); + } + + $stokauditRecords = $stokaudit['rekod'] ?? []; + + if (empty($stokauditRecords)) { + return back()->with('error', 'No records found to export.'); + } + + // pilih column untuk audit sahaja + $auditRecords = collect($stokauditRecords)->values()->map(function ($item, $index) { + return [ + 'Bil' => $index + 1, + 'No Rujukan' => $item['norujukan'] ?? '', + 'No KP' => $item['nokp'] ?? '', + 'Marhun' => $item['marhun'] ?? '', + 'Berat (g)' => $item['berat'] ?? '', + 'Nilai Marhun' => $item['nilaimarhun'] ?? '', + 'Pinjaman' => $item['pinjaman'] ?? '', + 'Baki Pinjaman' => $item['bakipjm'] ?? '', + 'Tempoh' => $item['tempoh'] ?? '', + ]; + }); + + return Excel::download( + new SAExportAudit( + $auditRecords, + 'Laporan Stok Audit', + $tebus_date, + $cawangan_detail['namacaw'] + ), + 'laporan_stokaudit_audit_' . $request->kodcaw . '_' . $tebus_date . '.xlsx' + ); + } else { if ($request->radaktif === 'aktif') { $stokaudit = Http::get($api_url . '/api/stokaudit/aktif/' . $request->kodcaw, ['tarikh' => $tebus_date])->json(); diff --git a/resources/js/Akaun/StokAudit.vue b/resources/js/Akaun/StokAudit.vue index 493dc9e..0269a48 100644 --- a/resources/js/Akaun/StokAudit.vue +++ b/resources/js/Akaun/StokAudit.vue @@ -35,16 +35,22 @@ -