Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Account.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace App\Models\Accounting;
  3. use App\Casts\MoneyCast;
  4. use App\Models\Setting\Category;
  5. use App\Models\Setting\Currency;
  6. use App\Traits\Blamable;
  7. use App\Traits\CompanyOwned;
  8. use Database\Factories\Accounting\AccountFactory;
  9. use Illuminate\Database\Eloquent\Factories\Factory;
  10. use Illuminate\Database\Eloquent\Factories\HasFactory;
  11. use Illuminate\Database\Eloquent\Model;
  12. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  13. use Illuminate\Database\Eloquent\Relations\HasMany;
  14. use Illuminate\Database\Eloquent\Relations\HasManyThrough;
  15. use Illuminate\Database\Eloquent\Relations\MorphTo;
  16. use Wallo\FilamentCompanies\FilamentCompanies;
  17. class Account extends Model
  18. {
  19. use Blamable;
  20. use CompanyOwned;
  21. use HasFactory;
  22. protected $table = 'accounts';
  23. protected $fillable = [
  24. 'company_id',
  25. 'subtype_id',
  26. 'parent_id',
  27. 'category',
  28. 'type',
  29. 'code',
  30. 'name',
  31. 'currency_code',
  32. 'starting_balance',
  33. 'debit_balance',
  34. 'credit_balance',
  35. 'ending_balance',
  36. 'description',
  37. 'active',
  38. 'default',
  39. 'accountable_id',
  40. 'accountable_type',
  41. 'created_by',
  42. 'updated_by',
  43. ];
  44. protected $casts = [
  45. 'starting_balance' => MoneyCast::class,
  46. 'debit_balance' => MoneyCast::class,
  47. 'credit_balance' => MoneyCast::class,
  48. 'ending_balance' => MoneyCast::class,
  49. 'active' => 'boolean',
  50. 'default' => 'boolean',
  51. ];
  52. public function company(): BelongsTo
  53. {
  54. return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
  55. }
  56. public function categories(): HasMany
  57. {
  58. return $this->hasMany(Category::class, 'account_id');
  59. }
  60. public function subtype(): BelongsTo
  61. {
  62. return $this->belongsTo(AccountSubtype::class, 'subtype_id');
  63. }
  64. public function parent(): BelongsTo
  65. {
  66. return $this->belongsTo(__CLASS__, 'parent_id')
  67. ->whereKeyNot($this->getKey());
  68. }
  69. public function children(): HasMany
  70. {
  71. return $this->hasMany(__CLASS__, 'parent_id');
  72. }
  73. public function currency(): BelongsTo
  74. {
  75. return $this->belongsTo(Currency::class, 'currency_code', 'code');
  76. }
  77. public function createdBy(): BelongsTo
  78. {
  79. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  80. }
  81. public function updatedBy(): BelongsTo
  82. {
  83. return $this->belongsTo(FilamentCompanies::userModel(), 'updated_by');
  84. }
  85. public function accountable(): MorphTo
  86. {
  87. return $this->morphTo();
  88. }
  89. public function transactions(): HasManyThrough
  90. {
  91. return $this->hasManyThrough(
  92. Transaction::class,
  93. JournalEntry::class,
  94. 'account_id',
  95. 'id',
  96. 'id',
  97. 'transaction_id',
  98. );
  99. }
  100. public function journalEntries(): HasMany
  101. {
  102. return $this->hasMany(JournalEntry::class, 'account_id');
  103. }
  104. protected static function newFactory(): Factory
  105. {
  106. return AccountFactory::new();
  107. }
  108. }