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.9KB

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