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.

Account.php 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace App\Models\Banking;
  3. use App\Casts\MoneyCast;
  4. use App\Models\Setting\Currency;
  5. use App\Traits\Blamable;
  6. use App\Traits\CompanyOwned;
  7. use Database\Factories\Banking\AccountFactory;
  8. use Illuminate\Database\Eloquent\Factories\Factory;
  9. use Illuminate\Database\Eloquent\Factories\HasFactory;
  10. use Illuminate\Database\Eloquent\Model;
  11. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  12. use Spatie\Tags\HasTags;
  13. use Wallo\FilamentCompanies\FilamentCompanies;
  14. class Account extends Model
  15. {
  16. use Blamable, CompanyOwned, HasTags, HasFactory;
  17. protected $table = 'accounts';
  18. protected $fillable = [
  19. 'company_id',
  20. 'type',
  21. 'name',
  22. 'number',
  23. 'currency_code',
  24. 'opening_balance',
  25. 'description',
  26. 'notes',
  27. 'status',
  28. 'bank_name',
  29. 'bank_phone',
  30. 'bank_address',
  31. 'bank_website',
  32. 'bic_swift_code',
  33. 'iban',
  34. 'aba_routing_number',
  35. 'ach_routing_number',
  36. 'enabled',
  37. 'created_by',
  38. 'updated_by',
  39. ];
  40. protected $casts = [
  41. 'enabled' => 'boolean',
  42. 'opening_balance' => MoneyCast::class,
  43. ];
  44. public function company(): BelongsTo
  45. {
  46. return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
  47. }
  48. public function currency(): BelongsTo
  49. {
  50. return $this->belongsTo(Currency::class, 'currency_code', 'code');
  51. }
  52. public function createdBy(): BelongsTo
  53. {
  54. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  55. }
  56. public function updatedBy(): BelongsTo
  57. {
  58. return $this->belongsTo(FilamentCompanies::userModel(), 'updated_by');
  59. }
  60. public static function getAccountTypes(): array
  61. {
  62. return [
  63. 'checking' => 'Checking',
  64. 'savings' => 'Savings',
  65. 'money_market' => 'Money Market',
  66. 'certificate_of_deposit' => 'Certificate of Deposit',
  67. 'credit_card' => 'Credit Card',
  68. ];
  69. }
  70. public static function getAccountStatuses(): array
  71. {
  72. return [
  73. 'open' => 'Open',
  74. 'active' => 'Active',
  75. 'dormant' => 'Dormant',
  76. 'restricted' => 'Restricted',
  77. 'closed' => 'Closed',
  78. ];
  79. }
  80. protected static function newFactory(): Factory
  81. {
  82. return AccountFactory::new();
  83. }
  84. }