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); } // 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 LelonganFullExport( $this->cawangan_detail, $this->query, $full_lelongan_data ); return $sheets; } }