update stok audit audit

This commit is contained in:
Nur Izzati
2026-03-11 13:30:26 +08:00
parent b22436854c
commit 2ba1d47d33
3 changed files with 237 additions and 3 deletions
+44
View File
@@ -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();