Files
2025-05-27 14:26:46 +08:00

57 lines
1.7 KiB
PHP

<?php
namespace App\Exports\Ansuran;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
class AnsuranExport implements WithMultipleSheets
{
public $cawangan_detail;
public $query;
public $ansuran;
public $ansuranall;
public $summary_ansuran;
public function __construct($data)
{
$this->cawangan_detail = $data['cawangan_detail'];
$this->query = $data['query'];
$this->ansuran = $data['total_ansuran'];
$this->ansuranall = $data['total_ansuran_keseluruhan'];
$this->summary_ansuran = $data['summary_ansuran'];
}
public function sheets(): array
{
$sheets = [];
// Use array_reduce to calculate the sum of values
$data = $this->ansuran;
$teller_with_gadaian_summary_data = array_reduce(array_keys($data), function ($accumulator, $key) use ($data) {
$accumulator[] = [
'teller' => $key,
'summary_ansuran_teller' => $data[$key]['summary_ansuran_teller'],
];
return $accumulator;
}, []);
$sheets[] = new AnsuranSummaryExport($this->cawangan_detail, $this->query, $teller_with_gadaian_summary_data, $this->summary_ansuran);
foreach ($this->ansuran as $teller => $data) {
$teller_with_gadaian_data = [
'teller' => $teller,
'data' => $data,
];
$sheets[] = new AnsuranPerTellerExport($this->cawangan_detail, $this->query, $teller_with_gadaian_data);
}
// Sheet Terakhir: Keseluruhan (tanpa teller)
$sheets[] = new AnsuranKeseluruhanExport($this->cawangan_detail, $this->query, $this->ansuranall);
return $sheets;
}
}