Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Account.php 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Models\Banking;
  3. use App\Casts\MoneyCast;
  4. use App\Enums\AccountStatus;
  5. use App\Enums\AccountType;
  6. use App\Models\History\AccountHistory;
  7. use App\Models\Setting\Currency;
  8. use App\Traits\Blamable;
  9. use App\Traits\CompanyOwned;
  10. use App\Traits\HasDefault;
  11. use App\Traits\SyncsWithCompanyDefaults;
  12. use Database\Factories\Banking\AccountFactory;
  13. use Illuminate\Database\Eloquent\Factories\Factory;
  14. use Illuminate\Database\Eloquent\Factories\HasFactory;
  15. use Illuminate\Database\Eloquent\Model;
  16. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  17. use Illuminate\Database\Eloquent\Relations\HasMany;
  18. use Spatie\Tags\HasTags;
  19. use Wallo\FilamentCompanies\FilamentCompanies;
  20. class Account extends Model
  21. {
  22. use Blamable;
  23. use CompanyOwned;
  24. use HasDefault;
  25. use HasFactory;
  26. use HasTags;
  27. use SyncsWithCompanyDefaults;
  28. protected $table = 'accounts';
  29. protected $fillable = [
  30. 'company_id',
  31. 'type',
  32. 'name',
  33. 'number',
  34. 'currency_code',
  35. 'opening_balance',
  36. 'balance',
  37. 'description',
  38. 'notes',
  39. 'status',
  40. 'bank_name',
  41. 'bank_phone',
  42. 'bank_address',
  43. 'bank_website',
  44. 'bic_swift_code',
  45. 'iban',
  46. 'aba_routing_number',
  47. 'ach_routing_number',
  48. 'enabled',
  49. 'created_by',
  50. 'updated_by',
  51. ];
  52. protected $casts = [
  53. 'type' => AccountType::class,
  54. 'status' => AccountStatus::class,
  55. 'enabled' => 'boolean',
  56. 'opening_balance' => MoneyCast::class,
  57. 'balance' => MoneyCast::class,
  58. ];
  59. public function company(): BelongsTo
  60. {
  61. return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
  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 histories(): HasMany
  76. {
  77. return $this->hasMany(AccountHistory::class, 'account_id');
  78. }
  79. protected static function newFactory(): Factory
  80. {
  81. return AccountFactory::new();
  82. }
  83. }