Files
admin-erahn/app/Exports/GadaianExport.php
T
2023-12-03 10:14:43 +08:00

54 lines
1.4 KiB
PHP

<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
class GadaianExport implements WithMultipleSheets
{
public $cawangan_detail;
public $query;
public $gadaian;
public $summary_gadaian;
public function __construct($data)
{
$this->cawangan_detail = $data['cawangan_detail'];
$this->query = $data['query'];
$this->gadaian = $data['gadaian'];
$this->summary_gadaian = $data['summary_gadaian'];
}
public function sheets(): array
{
$sheets = [];
// Use array_reduce to calculate the sum of values
$data = $this->gadaian;
$teller_with_gadaian_summary_data = array_reduce(array_keys($data), function ($accumulator, $key) use ($data) {
$accumulator[] = [
'teller' => $key,
'summary_gadaian_teller' => $data[$key]['summary_gadaian_teller'],
];
return $accumulator;
}, []);
$sheets[] = new GadaianSummaryExport($this->cawangan_detail, $this->query, $teller_with_gadaian_summary_data, $this->summary_gadaian);
foreach ($this->gadaian as $teller => $data) {
$teller_with_gadaian_data = [
'teller' => $teller,
'data' => $data,
];
$sheets[] = new GadaianPerTellerExport($this->cawangan_detail, $this->query, $teller_with_gadaian_data);
}
return $sheets;
}
}