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
+12 -1
View File
@@ -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') {
+63
View File
@@ -0,0 +1,63 @@
<?php
namespace App\Exports;
use App\Exports\SAExport;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
class SAcombineExport implements WithMultipleSheets
{
protected $aktifData;
protected $takaktifData;
protected $tebus_date;
protected $namacaw;
public function __construct($aktifData, $takaktifData,$tebus_date,$namacaw)
{
$this->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'] ?? '',
];
}
}
+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();
+24 -13
View File
@@ -49,19 +49,17 @@
</div>
<div class="flex justify-end mt-10">
<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"
>
<i class="fas fa-file-pdf mr-2"></i>PDF
</button>
<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
</button>
</div>
<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">
<i class="fas fa-file-pdf mr-2"></i>PDF
</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">
<i class="fas fa-eye mr-2"></i>View
</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">
<i class="fas fa-file-excel mr-2"></i>Excel
</button>
</div>
</div>
</form>
</div>
@@ -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 {
},
};
</script>