Files
admin-erahn/app/Exports/BakiLelongBelumTuntutExport.php
2025-06-11 12:31:24 +08:00

80 lines
2.2 KiB
PHP

<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
class BakiLelongBelumTuntutExport implements WithMultipleSheets
{
public $cawangan_detail;
public $query;
public $lelongan;
public $summary_lelongan;
protected $lelongan_full_data;
public function __construct($data)
{
$this->cawangan_detail = $data['cawangan_detail'];
$this->query = $data['query'];
$this->lelongan = $data['lelongan'];
$this->summary_lelongan = $data['summary_lelongan'];
}
public function sheets(): array
{
$sheets = [];
// Sheet summary (group by teller)
$data = $this->lelongan;
$teller_with_lelongan_summary_data = array_reduce(array_keys($data), function ($accumulator, $key) use ($data) {
$accumulator[] = [
'teller' => $key,
'summary_lelongan_teller' => $data[$key]['summary_lelongan_teller'],
];
return $accumulator;
}, []);
$sheets[] = new BakiLelongSummaryExport(
$this->cawangan_detail,
$this->query,
$teller_with_lelongan_summary_data,
$this->summary_lelongan
);
// Sheet untuk setiap teller
foreach ($this->lelongan as $teller => $data) {
$teller_with_lelongan_data = [
'teller' => $teller,
'data' => $data,
];
$sheets[] = new BakiLelongPerTellerExport(
$this->cawangan_detail,
$this->query,
$teller_with_lelongan_data
);
}
// Sheet untuk senarai penuh lelongan (gabung semua teller)
$full_lelongan_data = [];
foreach ($this->lelongan as $teller => $data) {
if (isset($data['lelongan']) && is_array($data['lelongan'])) {
foreach ($data['lelongan'] as $item) {
$item['teller'] = $teller; // optional: simpan info teller
$full_lelongan_data[] = $item;
}
}
}
$sheets[] = new BakiLelongFullExport(
$this->cawangan_detail,
$this->query,
$full_lelongan_data
);
return $sheets;
}
}