Merged in izzati-feat-stokaudit-excel (pull request #87)
update stokaudit excel
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
<?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;
|
||||
|
||||
class SAExport implements FromCollection, WithHeadings, WithTitle, WithMapping, WithStyles, WithCustomStartCell, WithColumnFormatting
|
||||
{
|
||||
protected $stokaudit;
|
||||
protected $jenisLaporan; // ✅ Define the missing property
|
||||
|
||||
public function __construct($stokaudit, $jenisLaporan = 'LAPORAN') // ✅ Allow a custom report title
|
||||
{
|
||||
$this->stokaudit = $stokaudit;
|
||||
$this->jenisLaporan = strtoupper($jenisLaporan); // ✅ Convert to uppercase for consistency
|
||||
}
|
||||
|
||||
public function collection()
|
||||
{
|
||||
$data = collect($this->stokaudit);
|
||||
|
||||
// ✅ Compute Totals
|
||||
$totals = [
|
||||
'norujukan' => 'TOTAL KESELURUHAN', // Label for total row
|
||||
'tempoh' => '',
|
||||
'nokp' => '',
|
||||
'berat' => $data->sum('berat'),
|
||||
'nilaimarhun' => $data->sum('nilaimarhun'),
|
||||
'marhun' => '',
|
||||
'pinjaman' => $data->sum('pinjaman'),
|
||||
'bakipjm' => $data->sum('bakipjm'),
|
||||
'kadarupah' => '',
|
||||
'tempohbayar' => '',
|
||||
'tunggakan' => $data->sum('tunggakan'),
|
||||
'tunggakanujrah' => $data->sum('tunggakanujrah'),
|
||||
'tunggakanonepercent' => $data->sum('tunggakanonepercent'),
|
||||
'lelong_tawarruq' => '',
|
||||
];
|
||||
|
||||
// ✅ Append Total Row to the Data Collection
|
||||
$data->push($totals);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
['LAPORAN STOK AUDIT'], // ✅ Ensure proper title format
|
||||
[
|
||||
'Bil', 'Norujukan', 'JBG', 'No. KP', 'Berat',
|
||||
'Nilai Marhun (RM)', 'Marhun', 'Pembiayaan Asal (RM)', 'Baki Pembiayaan (RM)',
|
||||
'Kadar Keuntungan', 'Tempoh Belum Bayar', 'Keuntungan Belum Bayar (RM)',
|
||||
'Lain-Lain Caj (RM)', 'Keuntungan 1% (RM)', 'Lanjutan'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function startCell(): string
|
||||
{
|
||||
return 'A2';
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
static $counter = 1;
|
||||
|
||||
if ($row['norujukan'] === 'TOTAL KESELURUHAN') {
|
||||
return [
|
||||
'', // Empty for numbering
|
||||
'JUMLAH',
|
||||
'', '',
|
||||
$row['berat'], // Raw number
|
||||
$row['nilaimarhun'], // Raw number
|
||||
'',
|
||||
$row['pinjaman'], // Raw number
|
||||
$row['bakipjm'], // Raw number
|
||||
'',
|
||||
'',
|
||||
$row['tunggakan'], // Raw number
|
||||
$row['tunggakanujrah'], // Raw number
|
||||
$row['tunggakanonepercent'], // Raw number
|
||||
'',
|
||||
];
|
||||
}
|
||||
return [
|
||||
$counter++, // Bil
|
||||
$row['norujukan'],
|
||||
$row['tempoh'],
|
||||
$row['nokp'],
|
||||
$row['berat'], // Raw number
|
||||
$row['nilaimarhun'], // Raw number
|
||||
$row['marhun'],
|
||||
$row['pinjaman'], // Raw number
|
||||
$row['bakipjm'], // Raw number
|
||||
$row['kadarupah'], // Raw number
|
||||
$row['tempoh'] - $row['tempohbayar'], // Raw number
|
||||
$row['tunggakan'], // Raw number
|
||||
$row['tunggakanujrah'], // Raw number
|
||||
$row['tunggakanonepercent'], // Raw number
|
||||
$row['lelong_tawarruq'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return $this->jenisLaporan; // ✅ Now correctly uses the class property
|
||||
}
|
||||
|
||||
public function styles(Worksheet $sheet)
|
||||
{
|
||||
|
||||
// ✅ Merge and Style Title Row
|
||||
$sheet->mergeCells('A1:O1');
|
||||
$sheet->getStyle('A1')->getFont()->setBold(true)->setSize(16);
|
||||
$sheet->getStyle('A1')->getAlignment()->setHorizontal('center');
|
||||
|
||||
// ✅ Bold Headers
|
||||
$sheet->getStyle('A2:O2')->getFont()->setBold(true)->setSize(12);
|
||||
|
||||
// ✅ Bold Last Row (Total Row)
|
||||
$lastRow = $sheet->getHighestRow(); // Get last row number
|
||||
$sheet->getStyle("A{$lastRow}:O{$lastRow}")->getFont()->setBold(true)->setSize(12);
|
||||
$sheet->getStyle("A{$lastRow}:O{$lastRow}")->getAlignment()->setHorizontal('right'); // Align text properly
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public function columnWidths(): array
|
||||
{
|
||||
return [
|
||||
'A' => 5,
|
||||
'B' => 25,
|
||||
'C' => 5,
|
||||
'D' => 18,
|
||||
'E' => 10,
|
||||
'F' => 10,
|
||||
'G' => 10,
|
||||
];
|
||||
}
|
||||
|
||||
public function columnFormats(): array
|
||||
{
|
||||
return [
|
||||
'E' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
||||
'F' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
||||
'H' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
||||
'I' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
||||
'L' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
||||
'M' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
||||
'N' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ use App\Services\RingkasanHarianServices;
|
||||
use App\Exports\Laporan\StokAuditBackdateExport;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Exports\PendSerExport;
|
||||
use App\Exports\SAExport;
|
||||
|
||||
class AkaunController extends Controller
|
||||
{
|
||||
@@ -714,54 +715,56 @@ class AkaunController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function cetaklaporan_stokaudit(Request $request){
|
||||
|
||||
public function cetaklaporan_stokaudit(Request $request)
|
||||
{
|
||||
$api_url = $request->hostname;
|
||||
$auth_user = Auth::user();
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
$tarikh_cetak = $current->toDateString();
|
||||
if($request->datetimepicker1 == null){
|
||||
$tebus_date = $current->toDateString();
|
||||
}else{
|
||||
$tebus_date = $request->datetimepicker1;
|
||||
}
|
||||
|
||||
$cawangan=Http::get($api_url.'/api/cawangan/detail/'.$request->kodcaw)->json();
|
||||
$cawangan_detail=$cawangan[0];
|
||||
|
||||
if(isset($request->jenis))
|
||||
{
|
||||
if($request->jenis == 'pdf')
|
||||
{
|
||||
|
||||
if($request->radaktif === 'aktif')
|
||||
{
|
||||
$stokaudit = Http::get($api_url. '/api/stokaudit/aktif/'. $request->kodcaw,['tarikh' => $tebus_date])->json();
|
||||
$pdf = PDF::loadView('akaun.laporan_stokaudit', compact('stokaudit','cawangan_detail','tarikh_cetak','tebus_date','api_url'))->setPaper('a4', 'potrait');
|
||||
return $pdf->download('laporan_stokaudit_' . $request->kodcaw .'_'. $tebus_date . '.pdf');
|
||||
|
||||
}else{
|
||||
$stokaudit = Http::get($api_url. '/api/stokaudit/takaktif/'. $request->kodcaw,['tarikh' => $tebus_date])->json();
|
||||
$pdf = PDF::loadView('akaun.laporan_stokauditbelumaktif',compact('stokaudit','cawangan_detail','tarikh_cetak','tebus_date','api_url'))->setPaper('a4', 'potrait');
|
||||
return $pdf->download('laporan_stokauditbelumaktif_' . $request->kodcaw .'_'. $tebus_date . '.pdf');
|
||||
$tebus_date = $request->datetimepicker1 ?? $tarikh_cetak;
|
||||
|
||||
$cawangan = Http::get($api_url . '/api/cawangan/detail/' . $request->kodcaw)->json();
|
||||
$cawangan_detail = $cawangan[0];
|
||||
|
||||
if (isset($request->jenis)) {
|
||||
if ($request->jenis == 'pdf') {
|
||||
if ($request->radaktif === 'aktif') {
|
||||
$stokaudit = Http::get($api_url . '/api/stokaudit/aktif/' . $request->kodcaw, ['tarikh' => $tebus_date])->json();
|
||||
$pdf = PDF::loadView('akaun.laporan_stokaudit', compact('stokaudit', 'cawangan_detail', 'tarikh_cetak', 'tebus_date', 'api_url'))->setPaper('a4', 'portrait');
|
||||
return $pdf->download('laporan_stokaudit_' . $request->kodcaw . '_' . $tebus_date . '.pdf');
|
||||
} else {
|
||||
$stokaudit = Http::get($api_url . '/api/stokaudit/takaktif/' . $request->kodcaw, ['tarikh' => $tebus_date])->json();
|
||||
$pdf = PDF::loadView('akaun.laporan_stokauditbelumaktif', compact('stokaudit', 'cawangan_detail', 'tarikh_cetak', 'tebus_date', 'api_url'))->setPaper('a4', 'portrait');
|
||||
return $pdf->download('laporan_stokauditbelumaktif_' . $request->kodcaw . '_' . $tebus_date . '.pdf');
|
||||
}
|
||||
}
|
||||
elseif ($request->jenis == 'excel') {
|
||||
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.');
|
||||
}
|
||||
return Excel::download(new SAExport($stokauditRecords, 'Laporan Stok Audit'), 'laporan_stokaudit_' . $request->kodcaw . '_' . $tebus_date . '.xlsx');
|
||||
}
|
||||
else {
|
||||
if ($request->radaktif === 'aktif') {
|
||||
$stokaudit = Http::get($api_url . '/api/stokaudit/aktif/' . $request->kodcaw, ['tarikh' => $tebus_date])->json();
|
||||
return view('akaun.laporan_stokaudit', compact('stokaudit', 'cawangan_detail', 'tarikh_cetak', 'tebus_date', 'api_url'));
|
||||
} else {
|
||||
$stokaudit = Http::get($api_url . '/api/stokaudit/takaktif/' . $request->kodcaw, ['tarikh' => $tebus_date])->json();
|
||||
return view('akaun.laporan_stokauditbelumaktif', compact('stokaudit', 'cawangan_detail', 'tarikh_cetak', 'tebus_date', 'api_url'));
|
||||
}
|
||||
}
|
||||
else{
|
||||
if($request->radaktif === 'aktif')
|
||||
{
|
||||
$stokaudit = Http::get($api_url. '/api/stokaudit/aktif/'. $request->kodcaw,['tarikh' => $tebus_date])->json();
|
||||
return view('akaun.laporan_stokaudit', compact('stokaudit','cawangan_detail','tarikh_cetak','tebus_date','api_url'));
|
||||
|
||||
}else{
|
||||
|
||||
$stokaudit = Http::get($api_url. '/api/stokaudit/takaktif/'. $request->kodcaw,['tarikh' => $tebus_date])->json();
|
||||
return view('akaun.laporan_stokauditbelumaktif', compact('stokaudit','cawangan_detail','tarikh_cetak','tebus_date','api_url'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function cetaklaporan_kawalanstok(Request $request){
|
||||
$api_url = $request->hostname;
|
||||
|
||||
Reference in New Issue
Block a user