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