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
+172
View File
@@ -0,0 +1,172 @@
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithStyles;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
class SAExportAudit implements FromCollection, WithHeadings, WithTitle, WithMapping, WithStyles, WithCustomStartCell, WithColumnFormatting
{
protected $stokaudit;
protected $jenisLaporan;
protected $tebus_date;
protected $namacaw;
public function __construct($stokaudit, $jenisLaporan = 'LAPORAN STOK AUDIT', $tebus_date, $namacaw)
{
$this->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,
];
}
}
+44
View File
@@ -23,6 +23,7 @@ use Maatwebsite\Excel\Facades\Excel;
use App\Exports\PendSerExport; use App\Exports\PendSerExport;
use App\Exports\SAExport; use App\Exports\SAExport;
use App\Exports\SAcombineExport; use App\Exports\SAcombineExport;
use App\Exports\SAExportAudit;
class AkaunController extends Controller class AkaunController extends Controller
{ {
@@ -768,6 +769,49 @@ class AkaunController extends Controller
$cawangan_detail['namacaw']// ✅ Use the correct branch name from API $cawangan_detail['namacaw']// ✅ Use the correct branch name from API
), 'laporan_stokaudit_' . $request->kodcaw . '_' . $tebus_date . '.xlsx'); ), '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 { else {
if ($request->radaktif === 'aktif') { if ($request->radaktif === 'aktif') {
$stokaudit = Http::get($api_url . '/api/stokaudit/aktif/' . $request->kodcaw, ['tarikh' => $tebus_date])->json(); $stokaudit = Http::get($api_url . '/api/stokaudit/aktif/' . $request->kodcaw, ['tarikh' => $tebus_date])->json();
+21 -3
View File
@@ -35,16 +35,22 @@
</div> </div>
</div> </div>
<div class="flex justify-end mt-10"> <div class="flex justify-end mt-10 gap-3">
<button @click.prevent="generatepdf" class="mr-2 border border-yellow-600 text-yellow-600 font-montserrat py-2 px-8 font-medium rounded-xl hover:bg-yellow-600 hover:text-white transition-all duration-300"> <button @click.prevent="generatepdf" class="border border-yellow-600 text-yellow-600 font-montserrat py-2 px-8 font-medium rounded-xl hover:bg-yellow-600 hover:text-white transition-all duration-300">
<i class="fas fa-file-pdf mr-2"></i>PDF <i class="fas fa-file-pdf mr-2"></i>PDF
</button> </button>
<button @click.prevent="generateview" class="mr-2 border border-yellow-600 text-yellow-600 font-montserrat py-2 px-8 font-medium rounded-xl hover:bg-yellow-600 hover:text-white transition-all duration-300">
<button @click.prevent="generateview" class="border border-yellow-600 text-yellow-600 font-montserrat py-2 px-8 font-medium rounded-xl hover:bg-yellow-600 hover:text-white transition-all duration-300">
<i class="fas fa-eye mr-2"></i>View <i class="fas fa-eye mr-2"></i>View
</button> </button>
<button @click.prevent="generateexcel" class="border border-green-600 text-green-600 font-montserrat py-2 px-8 font-medium rounded-xl hover:bg-green-600 hover:text-white transition-all duration-300"> <button @click.prevent="generateexcel" class="border border-green-600 text-green-600 font-montserrat py-2 px-8 font-medium rounded-xl hover:bg-green-600 hover:text-white transition-all duration-300">
<i class="fas fa-file-excel mr-2"></i>Excel <i class="fas fa-file-excel mr-2"></i>Excel
</button> </button>
<button @click.prevent="generateexcelaudit" class="border border-green-600 text-green-600 font-montserrat py-2 px-8 font-medium rounded-xl hover:bg-green-600 hover:text-white transition-all duration-300">
<i class="fas fa-file-excel mr-2"></i>Excel Audit
</button>
</div> </div>
@@ -111,6 +117,18 @@ export default {
}); });
document.getElementById("formstokaudit").submit(); document.getElementById("formstokaudit").submit();
}, },
async generateexcelaudit(){
await this.setJenis('excelaudit');
Vue.swal({
title: 'Memuatkan...',
allowEscapeKey : false,
allowOutsideClick: false,
showCancelButton: false,
showConfirmButton: false,
timer: 8000,
});
document.getElementById("formstokaudit").submit();
},
Urlredirect: function() { Urlredirect: function() {
return window.route('cetak.stokaudit'); return window.route('cetak.stokaudit');
}, },