| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace App\Exports;
- use App\Services\ReportService;
- use Maatwebsite\Excel\Concerns\FromCollection;
- use Maatwebsite\Excel\Concerns\WithHeadings;
- use Maatwebsite\Excel\Concerns\WithStyles;
- use Maatwebsite\Excel\Concerns\WithColumnWidths;
- use Maatwebsite\Excel\Concerns\WithTitle;
- use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
- use PhpOffice\PhpSpreadsheet\Style\Fill;
- use PhpOffice\PhpSpreadsheet\Style\Alignment;
- use Illuminate\Support\Collection;
- class UsosConvenioExport implements FromCollection, WithHeadings, WithStyles, WithColumnWidths, WithTitle
- {
- public function __construct(
- private readonly ReportService $service,
- private readonly ?string $search = null,
- ) {}
- public function collection(): Collection
- {
- $filters = $this->search ? ['search' => $this->search] : [];
- return $this->service->getAllUsosConvenio($filters)->map(function ($appointment) {
- $row = $this->service->formatUsoConvenio($appointment);
- return [
- $row['convenio'] ?? '',
- $this->service->usoConvenioTipoLabel($row['type']),
- $row['servico'] ?? '',
- $row['associado'] ?? '',
- $row['criado_em'] ?? '',
- $row['agendado_em'] ?? '',
- ];
- });
- }
- public function headings(): array
- {
- return ['Convênio', 'Tipo', 'Serviço', 'Associado', 'Criação do Agendamento', 'Data do Agendamento'];
- }
- public function title(): string
- {
- return 'Usos do Convênio';
- }
- public function columnWidths(): array
- {
- return ['A' => 35, 'B' => 20, 'C' => 35, 'D' => 35, 'E' => 24, 'F' => 24];
- }
- public function styles(Worksheet $sheet): array
- {
- return [
- 1 => [
- 'font' => ['bold' => true, 'color' => ['argb' => 'FFFFFFFF']],
- 'fill' => ['fillType' => Fill::FILL_SOLID, 'startColor' => ['argb' => 'FF661D75']],
- 'alignment' => ['horizontal' => Alignment::HORIZONTAL_CENTER],
- ],
- ];
- }
- }
|