58 lines
1.6 KiB
PHP
58 lines
1.6 KiB
PHP
<?php
|
||
|
||
namespace App\Exports;
|
||
|
||
use App\Exports\Sheets\StatisticsEconomistData;
|
||
use App\Exports\Sheets\StatisticsMainDataExport;
|
||
use App\Models\User;
|
||
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
|
||
|
||
class StatisticsExport implements WithMultipleSheets
|
||
{
|
||
protected array $data;
|
||
|
||
protected array $dateRange;
|
||
|
||
protected User $user;
|
||
|
||
protected array $profitTypeData;
|
||
|
||
protected string $reportName;
|
||
|
||
public function __construct(
|
||
array $data,
|
||
array $dateRange,
|
||
User $user,
|
||
array $profitTypeData = [],
|
||
string $reportName = 'Статистика по отделениям'
|
||
) {
|
||
$this->data = $data;
|
||
$this->dateRange = $dateRange;
|
||
$this->user = $user;
|
||
$this->profitTypeData = $profitTypeData;
|
||
$this->reportName = $reportName;
|
||
}
|
||
|
||
public function sheets(): array
|
||
{
|
||
$sheets = [
|
||
new StatisticsMainDataExport('Сводка', $this->reportName, $this->data, $this->dateRange, $this->user),
|
||
];
|
||
|
||
// Лист с разбивкой по типам оплаты — только для роли "Экономист"
|
||
if ($this->user->isEconomist()) {
|
||
$sheets[] = new StatisticsEconomistData(
|
||
'По источникам доходов',
|
||
$this->reportName,
|
||
$this->profitTypeData['data'] ?? [],
|
||
$this->dateRange,
|
||
$this->user,
|
||
$this->profitTypeData['grandTotals'] ?? [],
|
||
$this->profitTypeData['profitTypes'] ?? [],
|
||
);
|
||
}
|
||
|
||
return $sheets;
|
||
}
|
||
}
|