Files
onboard/app/Exports/StatisticsExport.php

58 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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