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.

AccountCategory.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace App\Enums\Accounting;
  3. use Filament\Support\Contracts\HasLabel;
  4. enum AccountCategory: string implements HasLabel
  5. {
  6. case Asset = 'asset';
  7. case Liability = 'liability';
  8. case Equity = 'equity';
  9. case Revenue = 'revenue';
  10. case Expense = 'expense';
  11. public function getLabel(): ?string
  12. {
  13. return $this->name;
  14. }
  15. public function getPluralLabel(): ?string
  16. {
  17. return match ($this) {
  18. self::Asset => 'Assets',
  19. self::Liability => 'Liabilities',
  20. self::Equity => 'Equity',
  21. self::Revenue => 'Revenue',
  22. self::Expense => 'Expenses',
  23. };
  24. }
  25. public static function fromPluralLabel(string $label): ?self
  26. {
  27. foreach (self::cases() as $case) {
  28. if ($case->getPluralLabel() === $label) {
  29. return $case;
  30. }
  31. }
  32. return null;
  33. }
  34. /**
  35. * Determines if the account typically has a normal debit balance.
  36. *
  37. * In accounting, assets and expenses typically have a normal debit balance.
  38. * A debit increases the balance of these accounts, while a credit decreases it.
  39. */
  40. public function isNormalDebitBalance(): bool
  41. {
  42. return in_array($this, [self::Asset, self::Expense], true);
  43. }
  44. /**
  45. * Determines if the account typically has a normal credit balance.
  46. *
  47. * In accounting, liabilities, equity, and revenue typically have a normal credit balance.
  48. * A credit increases the balance of these accounts, while a debit decreases it.
  49. */
  50. public function isNormalCreditBalance(): bool
  51. {
  52. return ! $this->isNormalDebitBalance();
  53. }
  54. /**
  55. * Determines if the account is a nominal account.
  56. *
  57. * In accounting, nominal accounts are temporary accounts that are closed at the end of each accounting period,
  58. * with their net balances transferred to Retained Earnings (a real account).
  59. */
  60. public function isNominal(): bool
  61. {
  62. return in_array($this, [self::Revenue, self::Expense], true);
  63. }
  64. /**
  65. * Determines if the account is a real account.
  66. *
  67. * In accounting, real accounts are permanent accounts that retain their balances across accounting periods.
  68. * They are not closed at the end of each accounting period.
  69. */
  70. public function isReal(): bool
  71. {
  72. return ! $this->isNominal();
  73. }
  74. public function getRelevantBalanceFields(): array
  75. {
  76. $commonFields = ['debit_balance', 'credit_balance', 'net_movement'];
  77. return match ($this->isReal()) {
  78. true => [...$commonFields, 'starting_balance', 'ending_balance'],
  79. false => $commonFields,
  80. };
  81. }
  82. public static function getOrderedCategories(): array
  83. {
  84. return [
  85. self::Asset,
  86. self::Liability,
  87. self::Equity,
  88. self::Revenue,
  89. self::Expense,
  90. ];
  91. }
  92. }