52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Exports\Penebusan;
|
|
|
|
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
|
|
|
class PenebusanExport implements WithMultipleSheets
|
|
{
|
|
public $cawangan_detail;
|
|
public $query;
|
|
public $penebusan;
|
|
public $summary_penebusan;
|
|
|
|
public function __construct($data)
|
|
{
|
|
$this->cawangan_detail = $data['cawangan_detail'];
|
|
$this->query = $data['query'];
|
|
$this->penebusan = $data['penebusan'];
|
|
$this->summary_penebusan = $data['summary_penebusan'];
|
|
}
|
|
|
|
public function sheets(): array
|
|
{
|
|
$sheets = [];
|
|
|
|
// Use array_reduce to calculate the sum of values
|
|
$data = $this->penebusan;
|
|
$teller_with_gadaian_summary_data = array_reduce(array_keys($data), function ($accumulator, $key) use ($data) {
|
|
$accumulator[] = [
|
|
'teller' => $key,
|
|
'summary_penebusan_teller' => $data[$key]['summary_penebusan_teller'],
|
|
];
|
|
return $accumulator;
|
|
}, []);
|
|
|
|
|
|
$sheets[] = new PenebusanSummaryExport($this->cawangan_detail, $this->query, $teller_with_gadaian_summary_data, $this->summary_penebusan);
|
|
|
|
foreach ($this->penebusan as $teller => $data) {
|
|
|
|
$teller_with_gadaian_data = [
|
|
'teller' => $teller,
|
|
'data' => $data,
|
|
];
|
|
|
|
$sheets[] = new PenebusanPerTellerExport($this->cawangan_detail, $this->query, $teller_with_gadaian_data);
|
|
}
|
|
|
|
return $sheets;
|
|
}
|
|
}
|