add excel dalam stokaudit combine

This commit is contained in:
BTMS2
2025-03-24 10:45:30 +08:00
parent 9c3c865106
commit fc33bb662c
4 changed files with 119 additions and 14 deletions
+20
View File
@@ -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();