UsosConvenioExport.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Exports;
  3. use App\Services\ReportService;
  4. use Maatwebsite\Excel\Concerns\FromCollection;
  5. use Maatwebsite\Excel\Concerns\WithHeadings;
  6. use Maatwebsite\Excel\Concerns\WithStyles;
  7. use Maatwebsite\Excel\Concerns\WithColumnWidths;
  8. use Maatwebsite\Excel\Concerns\WithTitle;
  9. use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
  10. use PhpOffice\PhpSpreadsheet\Style\Fill;
  11. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  12. use Illuminate\Support\Collection;
  13. class UsosConvenioExport implements FromCollection, WithHeadings, WithStyles, WithColumnWidths, WithTitle
  14. {
  15. public function __construct(
  16. private readonly ReportService $service,
  17. private readonly ?string $search = null,
  18. ) {}
  19. public function collection(): Collection
  20. {
  21. $filters = $this->search ? ['search' => $this->search] : [];
  22. return $this->service->getAllUsosConvenio($filters)->map(function ($appointment) {
  23. $row = $this->service->formatUsoConvenio($appointment);
  24. return [
  25. $row['convenio'] ?? '',
  26. $this->service->usoConvenioTipoLabel($row['type']),
  27. $row['servico'] ?? '',
  28. $row['associado'] ?? '',
  29. $row['criado_em'] ?? '',
  30. $row['agendado_em'] ?? '',
  31. ];
  32. });
  33. }
  34. public function headings(): array
  35. {
  36. return ['Convênio', 'Tipo', 'Serviço', 'Associado', 'Criação do Agendamento', 'Data do Agendamento'];
  37. }
  38. public function title(): string
  39. {
  40. return 'Usos do Convênio';
  41. }
  42. public function columnWidths(): array
  43. {
  44. return ['A' => 35, 'B' => 20, 'C' => 35, 'D' => 35, 'E' => 24, 'F' => 24];
  45. }
  46. public function styles(Worksheet $sheet): array
  47. {
  48. return [
  49. 1 => [
  50. 'font' => ['bold' => true, 'color' => ['argb' => 'FFFFFFFF']],
  51. 'fill' => ['fillType' => Fill::FILL_SOLID, 'startColor' => ['argb' => 'FF661D75']],
  52. 'alignment' => ['horizontal' => Alignment::HORIZONTAL_CENTER],
  53. ],
  54. ];
  55. }
  56. }