diff --git a/app/Exports/SAExport.php b/app/Exports/SAExport.php index 0fb5748..2ab6d98 100644 --- a/app/Exports/SAExport.php +++ b/app/Exports/SAExport.php @@ -16,11 +16,15 @@ class SAExport implements FromCollection, WithHeadings, WithTitle, WithMapping, { protected $stokaudit; protected $jenisLaporan; // ✅ Define the missing property + protected $tebus_date; + protected $namacaw; - public function __construct($stokaudit, $jenisLaporan = 'LAPORAN') // ✅ Allow a custom report title + public function __construct($stokaudit, $jenisLaporan = 'LAPORAN',$tebus_date,$namacaw) // ✅ Allow a custom report title { $this->stokaudit = $stokaudit; $this->jenisLaporan = strtoupper($jenisLaporan); // ✅ Convert to uppercase for consistency + $this->tebus_date = $tebus_date; + $this->namacaw = $namacaw; } public function collection() @@ -56,6 +60,9 @@ class SAExport implements FromCollection, WithHeadings, WithTitle, WithMapping, { return [ ['LAPORAN STOK AUDIT'], // ✅ Ensure proper title format + ["Cawangan:", $this->namacaw], + ["Tarikh:", $this->tebus_date], // ✅ Include tebus_date in Excel + [], [ 'Bil', 'Norujukan', 'JBG', 'No. KP', 'Berat', 'Nilai Marhun (RM)', 'Marhun', 'Pembiayaan Asal (RM)', 'Baki Pembiayaan (RM)', @@ -73,6 +80,10 @@ class SAExport implements FromCollection, WithHeadings, WithTitle, WithMapping, public function map($row): array { + // ✅ Ensure $row is an array before accessing keys + if (!is_array($row)) { + return []; // Skip invalid rows + } static $counter = 1; if ($row['norujukan'] === 'TOTAL KESELURUHAN') { diff --git a/app/Exports/SAcombineExport.php b/app/Exports/SAcombineExport.php new file mode 100644 index 0000000..5f05a2a --- /dev/null +++ b/app/Exports/SAcombineExport.php @@ -0,0 +1,63 @@ +aktifData = $aktifData; + $this->takaktifData = $takaktifData; + $this->tebus_date = $tebus_date; + $this->namacaw = $namacaw; + + } + + public function sheets(): array + { + return [ + new SAExport($this->aktifData, 'Stok Audit Aktif', $this->tebus_date,$this->namacaw), + new SAExport($this->takaktifData, 'Stok Audit Tidak Aktif', $this->tebus_date,$this->namacaw), + ]; + } + + public function map($row): array +{ + static $counter = 1; + + // ✅ Ensure $row is an array before accessing keys + if (!is_array($row)) { + dd($row); + return []; // Skip invalid rows + } + + return [ + $counter++, + $row['norujukan'] ?? '', // ✅ Prevent Undefined Index + $row['tempoh'] ?? '', + $row['nokp'] ?? '', + is_numeric($row['berat']) ? (float) $row['berat'] : 0, + is_numeric($row['nilaimarhun']) ? (float) $row['nilaimarhun'] : 0, + $row['marhun'] ?? '', + is_numeric($row['pinjaman']) ? (float) $row['pinjaman'] : 0, + is_numeric($row['bakipjm']) ? (float) $row['bakipjm'] : 0, + $row['kadarupah'] ?? '', + (is_numeric($row['tempoh']) && is_numeric($row['tempohbayar'])) ? + ($row['tempoh'] - $row['tempohbayar']) : 0, + is_numeric($row['tunggakan']) ? (float) $row['tunggakan'] : 0, + is_numeric($row['tunggakanujrah']) ? (float) $row['tunggakanujrah'] : 0, + is_numeric($row['tunggakanonepercent']) ? (float) $row['tunggakanonepercent'] : 0, + $row['lelong_tawarruq'] ?? '', + ]; +} + +} + diff --git a/app/Http/Controllers/AkaunController.php b/app/Http/Controllers/AkaunController.php index 6d9a184..eb99340 100644 --- a/app/Http/Controllers/AkaunController.php +++ b/app/Http/Controllers/AkaunController.php @@ -21,6 +21,7 @@ use App\Exports\Laporan\StokAuditBackdateExport; use Maatwebsite\Excel\Facades\Excel; use App\Exports\PendSerExport; use App\Exports\SAExport; +use App\Exports\SAcombineExport; class AkaunController extends Controller { @@ -1560,6 +1561,25 @@ class AkaunController extends Controller $pdf = PDF::loadView('akaun.laporan_stokaudit_combine', compact('stokaudit_aktif','stokaudit_takaktif','cawangan_detail','tarikh_cetak','tebus_date','api_url'))->setPaper('a4', 'potrait'); return $pdf->download('laporan_stokaudit_' . $request->kodcaw .'_'. $tebus_date . '.pdf'); } + elseif ($request->jenis == 'excel') { + $stokaudit_aktif = Http::get($api_url . '/api/stokaudit/aktif/' . $request->kodcaw, ['tarikh' => $tebus_date])->json(); + $stokaudit_takaktif = Http::get($api_url . '/api/stokaudit/takaktifcombine/' . $request->kodcaw, ['tarikh' => $tebus_date])->json(); + + // ✅ Extract 'rekod' arrays correctly + $aktifData = $stokaudit_aktif['rekod'] ?? []; + $takaktifData = $stokaudit_takaktif['rekod'] ?? []; + + // ✅ Ensure at least one dataset is not empty + if (empty($aktifData) && empty($takaktifData)) { + return back()->with('error', 'No records found to export.'); + } + + return Excel::download( + new SAcombineExport($aktifData, $takaktifData, $tebus_date,$cawangan_detail['namacaw']), + 'laporan_stokauditcombine_' . $request->kodcaw . '_' . $tebus_date . '.xlsx' + ); + + } else{ $stokaudit_aktif = Http::get($api_url. '/api/stokaudit/aktif/'. $request->kodcaw,['tarikh' => $tebus_date])->json(); diff --git a/resources/js/Akaun/StokAuditCombine.vue b/resources/js/Akaun/StokAuditCombine.vue index 32cd92c..7323c11 100644 --- a/resources/js/Akaun/StokAuditCombine.vue +++ b/resources/js/Akaun/StokAuditCombine.vue @@ -49,19 +49,17 @@
- - -
+ + + + + @@ -112,6 +110,18 @@ export default { }); document.getElementById("formstokaudit").submit(); }, + async generateexcel(){ + await this.setJenis('excel'); + Vue.swal({ + title: 'Memuatkan...', + allowEscapeKey : false, + allowOutsideClick: false, + showCancelButton: false, + showConfirmButton: false, + timer: 8000, + }); + document.getElementById("formstokaudit").submit(); + }, Urlredirect: function () { return window.route("cetak.stokauditCombine"); }, @@ -121,3 +131,4 @@ export default { }, }; +