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; } }