ExclusoesMesExport.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Exports;
  3. use App\Enums\UserTypeEnum;
  4. use App\Models\User;
  5. use Carbon\Carbon;
  6. use Maatwebsite\Excel\Concerns\FromCollection;
  7. use Maatwebsite\Excel\Concerns\WithHeadings;
  8. use Maatwebsite\Excel\Concerns\WithStyles;
  9. use Maatwebsite\Excel\Concerns\WithColumnWidths;
  10. use Maatwebsite\Excel\Concerns\WithTitle;
  11. use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
  12. use PhpOffice\PhpSpreadsheet\Style\Fill;
  13. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  14. use Illuminate\Support\Collection;
  15. class ExclusoesMesExport implements FromCollection, WithHeadings, WithStyles, WithColumnWidths, WithTitle
  16. {
  17. public function collection(): Collection
  18. {
  19. $now = Carbon::now();
  20. return User::where('type', UserTypeEnum::ASSOCIADO)
  21. ->whereNotNull('excluded_at')
  22. ->whereYear('excluded_at', $now->year)
  23. ->whereMonth('excluded_at', $now->month)
  24. ->orderBy('excluded_at', 'desc')
  25. ->get()
  26. ->map(fn($u) => [
  27. $u->name,
  28. $u->cpf ?? '',
  29. $u->excluded_at?->format('d/m/Y') ?? '',
  30. ]);
  31. }
  32. public function headings(): array
  33. {
  34. return ['Nome', 'CPF', 'Data de Exclusão'];
  35. }
  36. public function title(): string
  37. {
  38. return 'Exclusões do Mês';
  39. }
  40. public function columnWidths(): array
  41. {
  42. return ['A' => 40, 'B' => 20, 'C' => 20];
  43. }
  44. public function styles(Worksheet $sheet): array
  45. {
  46. return [
  47. 1 => [
  48. 'font' => ['bold' => true, 'color' => ['argb' => 'FFFFFFFF']],
  49. 'fill' => ['fillType' => Fill::FILL_SOLID, 'startColor' => ['argb' => 'FF661D75']],
  50. 'alignment' => ['horizontal' => Alignment::HORIZONTAL_CENTER],
  51. ],
  52. ];
  53. }
  54. }