Files
admin-erahn/app/Exports/LelonganExport.php
T
2025-03-02 16:38:10 +08:00

54 lines
1.4 KiB
PHP

<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
class LelonganExport implements WithMultipleSheets
{
public $cawangan_detail;
public $query;
public $lelongan;
public $summary_lelongan;
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 = [];
// Use array_reduce to calculate the sum of values
$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 LelonganSummaryExport($this->cawangan_detail, $this->query, $teller_with_lelongan_summary_data, $this->summary_lelongan);
foreach ($this->lelongan as $teller => $data) {
$teller_with_lelongan_data = [
'teller' => $teller,
'data' => $data,
];
$sheets[] = new LelonganPerTellerExport($this->cawangan_detail, $this->query, $teller_with_lelongan_data);
}
return $sheets;
}
}