diff --git a/app/Exports/PendSerExport.php b/app/Exports/PendSerExport.php
new file mode 100644
index 0000000..cb03718
--- /dev/null
+++ b/app/Exports/PendSerExport.php
@@ -0,0 +1,143 @@
+pendser = $pendser;
+ $this->jenisLaporan = strtolower($jenisLaporan); // ✅ Convert to lowercase for array key matching
+ }
+
+ public function collection()
+ {
+ $data = collect($this->pendser);
+
+ // Calculate total amaun
+ $totalAmaun = $data->sum(function ($item) {
+ return $item['pendahuluan'] > 0 ? $item['pendahuluan'] : $item['serahan'];
+ });
+
+ // Append total row
+ $data->push([
+ 'tarikh' => '',
+ 'descpt' => '',
+ 'teller' => 'JUMLAH KESELURUHAN',
+ 'pendahuluan' => 0,
+ 'serahan' => $totalAmaun,
+ ]);
+
+ return $data;
+ }
+
+ // ✅ Set Title Row Above The Table
+ public function headings(): array
+ {
+ $reportTitles = [
+ 'serahan' => 'LAPORAN SERAHAN KEPADA HQ',
+ 'serahanv3' => 'LAPORAN SERAHAN KEPADA V3',
+ 'pendahuluan' => 'LAPORAN PENDAHULUAN DARIPADA HQ',
+ 'pendahuluanv3' => 'LAPORAN PENDAHULUAN DARIPADA V2',
+ 'online' => 'LAPORAN SERAHAN KEPADA HQ (arrahnPay)',
+ 'serahanlelong' => 'LAPORAN SERAHAN KEPADA HQ (arrahnBid)',
+ 'serahanonline' => 'LAPORAN SERAHAN KESELURUHAN',
+ 'all' => 'LAPORAN KESELURUHAN HQ'
+ ];
+
+ // ✅ Use lowercase key for better matching
+ $title = $reportTitles[$this->jenisLaporan] ?? 'LAPORAN TIDAK DIKETAHUI';
+
+ return [
+ [$title], // Report title in the first row
+ ['Bil', 'Tarikh', 'Keterangan', 'Nama', 'Amaun (RM)'], // Column headers
+ ];
+ }
+
+ // ✅ Move Table Start Position (Avoid Overlapping with Title)
+ public function startCell(): string
+ {
+ return 'A2'; // Start table from row 2 to leave space for the title
+ }
+
+ // ✅ Map Data to Match the Columns
+ public function map($item): array
+ {
+ static $counter = 1;
+ static $totalAmaun = 0;
+
+ // Get amount (either "pendahuluan" or "serahan")
+ $amount = $item['pendahuluan'] > 0 ? $item['pendahuluan'] : $item['serahan'];
+
+ // Accumulate total amount
+ $totalAmaun += $amount;
+
+ // If this is the total row (JUMLAH KESELURUHAN), remove numbering
+ if ($item['teller'] === 'JUMLAH KESELURUHAN') {
+ return [
+ '', // Empty Bil column
+ '', // Empty Tarikh column
+ '', // Empty Keterangan column
+ strtoupper($item['teller']), // "JUMLAH KESELURUHAN" (Uppercase)
+ number_format($amount, 2), // Total Amount
+ ];
+ }
+ return [
+ $counter++, // Bil
+ $item['tarikh'], // Date
+ $item['descpt'], // Description
+ $item['teller'], // Name
+ number_format($amount, 2), // Amount RM (Formatted)
+ ];
+ }
+
+ // ✅ Set Title for Excel Tab Name
+ public function title(): string
+ {
+ return strtoupper($this->jenisLaporan ?? 'LAPORAN'); // Capitalize for better readability
+ }
+
+ public function styles(Worksheet $sheet)
+ {
+ // Set title and headers bold
+ $sheet->getStyle('A1')->getFont()->setBold(true)->setSize(16);
+ $sheet->getStyle('A2:E2')->getFont()->setBold(true)->setSize(12);
+
+ // Auto-size columns A to E
+ foreach (range('A', 'E') as $column) {
+ $sheet->getColumnDimension($column)->setAutoSize(true);
+ }
+
+ // Get last row index (total row)
+ $lastRow = $sheet->getHighestRow();
+
+ // Bold total row
+ $sheet->getStyle("A{$lastRow}:E{$lastRow}")->getFont()->setBold(true);
+
+ return [];
+ }
+
+ // ✅ Format Column E (Amaun) as a Number with 2 Decimal Places
+ public function columnFormats(): array
+ {
+ return [
+ 'E' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, // ✅ Properly format numbers
+ ];
+ }
+
+
+}
diff --git a/app/Http/Controllers/AkaunController.php b/app/Http/Controllers/AkaunController.php
index 561712e..9e6a711 100644
--- a/app/Http/Controllers/AkaunController.php
+++ b/app/Http/Controllers/AkaunController.php
@@ -19,6 +19,7 @@ use App\Services\RingkasanHarianServices;
use App\Exports\Laporan\StokAuditBackdateExport;
use Maatwebsite\Excel\Facades\Excel;
+use App\Exports\PendSerExport;
class AkaunController extends Controller
{
@@ -495,59 +496,50 @@ class AkaunController extends Controller
$api_url = $request->hostname;
$auth_user = Auth::user();
- $current = Carbon::now();
- $current = new Carbon();
+ $current = now();
$tarikh_cetak = $current->toDateString();
- if($request->datemula == null){
- $mula_date = '2017-01-01';
- }else{
- $split_date = explode('-', $request->datemula);
- // $mula_date = $split_date[2] . '-' . $split_date[1] . '-' . $split_date[0];
- $mula_date = $request->datemula;
- }
+ $mula_date = $request->datemula ?? '2017-01-01';
+ $hingga_date = $request->datehingga ?? $current->toDateString();
- if($request->datehingga == null){
- $hingga_date = $current->toDateString();
- }else{
- $split_date = explode('-', $request->datehingga);
- // $hingga_date = $split_date[2] . '-' . $split_date[1] . '-' . $split_date[0];
- $hingga_date = $request->datehingga;
- }
+ $pendser = Http::get($request->hostname . '/api/SenaraiPendSer/range/' . $request->kodcaw, [
+ 'mula' => $mula_date,
+ 'hingga' => $hingga_date,
+ 'jenis' => $request->radpendser
+ ])->json();
- $pendser = Http::get($request->hostname. '/api/SenaraiPendSer/range/' . $request->kodcaw,['mula' => $mula_date,'hingga' => $hingga_date,'jenis' => $request->radpendser])->json();
+ $cawangan = Http::get($request->hostname . '/api/cawangan/detail/' . $request->kodcaw)->json();
+ $cawangan_detail = $cawangan[0];
- $cawangan = Http::get($request->hostname.'/api/cawangan/detail/'.$request->kodcaw)->json();
- $cawangan_detail=$cawangan[0];
+ // Define report title mappings
+ $reportTitles = [
+ 'serahan' => 'Laporan_Serahan_HQ',
+ 'pendahuluan' => 'Laporan_Pendahuluan_HQ',
+ 'online' => 'Laporan_Serahan_Online_HQ',
+ 'serahanlelong' => 'Laporan_Serahan_Lelong_HQ',
+ 'serahanonline' => 'Laporan_Serahan_Dan_Serahan_Online_HQ',
+ 'all' => 'Laporan_Keseluruhan_HQ'
+ ];
- if(isset($request->jenis))
- {
- $jenisLaporan = $request->radpendser; // Get report type
+ // Get the correct report title
+ $jenisLaporan = $request->radpendser;
+ $fileTitle = $reportTitles[$jenisLaporan] ?? 'Laporan_Tidak_Diketahui';
- if($request->jenis == 'pdf')
- {
+ if (isset($request->jenis)) {
+
+ if ($request->jenis == 'pdf') {
$pdf = PDF::loadView('akaun.laporan_pendahuluanserahan', compact(
- 'pendser',
- 'cawangan_detail',
- 'tarikh_cetak',
- 'mula_date',
- 'hingga_date',
- 'api_url',
- 'jenisLaporan' // Pass the report type
+ 'pendser', 'cawangan_detail', 'tarikh_cetak', 'mula_date', 'hingga_date', 'api_url', 'jenisLaporan'
))->setPaper('a4', 'portrait');
- return $pdf->download('laporan_HQ_' . $request->kodcaw . '_' . $mula_date . '_' . $jenisLaporan . '.pdf');
+ return $pdf->download($fileTitle . '_' . $request->kodcaw . '_' . $mula_date . '.pdf');
}
- else
- {
+ else if ($request->jenis == 'excel') {
+ return Excel::download(new PendSerExport($pendser, $jenisLaporan), $fileTitle . '_' . $request->kodcaw . '_' . $mula_date . '.xlsx');
+ }
+ else {
return view('akaun.laporan_pendahuluanserahan', compact(
- 'pendser',
- 'cawangan_detail',
- 'tarikh_cetak',
- 'mula_date',
- 'hingga_date',
- 'api_url',
- 'jenisLaporan' // Pass the report type to the view
+ 'pendser', 'cawangan_detail', 'tarikh_cetak', 'mula_date', 'hingga_date', 'api_url', 'jenisLaporan'
));
}
}
diff --git a/resources/js/Akaun/Pendahuluanserahan.vue b/resources/js/Akaun/Pendahuluanserahan.vue
index 3fa842f..957e96e 100644
--- a/resources/js/Akaun/Pendahuluanserahan.vue
+++ b/resources/js/Akaun/Pendahuluanserahan.vue
@@ -1,132 +1,124 @@
-