You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InvoiceStatus.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Enums\Accounting;
  3. use Filament\Support\Contracts\HasColor;
  4. use Filament\Support\Contracts\HasLabel;
  5. enum InvoiceStatus: string implements HasColor, HasLabel
  6. {
  7. case Draft = 'draft';
  8. case Unsent = 'unsent';
  9. case Sent = 'sent';
  10. case Viewed = 'viewed';
  11. case Partial = 'partial';
  12. case Paid = 'paid';
  13. case Overdue = 'overdue';
  14. case Overpaid = 'overpaid';
  15. case Void = 'void';
  16. public function getLabel(): ?string
  17. {
  18. return $this->name;
  19. }
  20. public function getColor(): string | array | null
  21. {
  22. return match ($this) {
  23. self::Draft, self::Unsent, self::Void => 'gray',
  24. self::Sent, self::Viewed => 'primary',
  25. self::Partial => 'warning',
  26. self::Paid, self::Overpaid => 'success',
  27. self::Overdue => 'danger',
  28. };
  29. }
  30. public static function canBeOverdue(): array
  31. {
  32. return [
  33. self::Partial,
  34. self::Sent,
  35. self::Unsent,
  36. ];
  37. }
  38. public static function unpaidStatuses(): array
  39. {
  40. return [
  41. self::Unsent,
  42. self::Sent,
  43. self::Viewed,
  44. self::Partial,
  45. self::Overdue,
  46. ];
  47. }
  48. public static function getUnpaidOptions(): array
  49. {
  50. return collect(self::unpaidStatuses())
  51. ->mapWithKeys(fn (self $case) => [$case->value => $case->getLabel()])
  52. ->toArray();
  53. }
  54. }