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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. namespace App\Models;
  3. use App\Enums\DocumentType;
  4. use App\Models\Accounting\AccountSubtype;
  5. use App\Models\Banking\BankAccount;
  6. use App\Models\Banking\ConnectedBankAccount;
  7. use App\Models\Common\Contact;
  8. use App\Models\Core\Department;
  9. use App\Models\History\AccountHistory;
  10. use App\Models\Setting\Appearance;
  11. use App\Models\Setting\Category;
  12. use App\Models\Setting\CompanyDefault;
  13. use App\Models\Setting\CompanyProfile;
  14. use App\Models\Setting\Currency;
  15. use App\Models\Setting\Discount;
  16. use App\Models\Setting\DocumentDefault;
  17. use App\Models\Setting\Localization;
  18. use App\Models\Setting\Tax;
  19. use Filament\Models\Contracts\HasAvatar;
  20. use Illuminate\Database\Eloquent\Factories\HasFactory;
  21. use Illuminate\Database\Eloquent\Relations\HasMany;
  22. use Illuminate\Database\Eloquent\Relations\HasOne;
  23. use Wallo\FilamentCompanies\Company as FilamentCompaniesCompany;
  24. use Wallo\FilamentCompanies\Events\CompanyCreated;
  25. use Wallo\FilamentCompanies\Events\CompanyDeleted;
  26. use Wallo\FilamentCompanies\Events\CompanyUpdated;
  27. class Company extends FilamentCompaniesCompany implements HasAvatar
  28. {
  29. use HasFactory;
  30. /**
  31. * The attributes that should be cast.
  32. *
  33. * @var array<string, string>
  34. */
  35. protected $casts = [
  36. 'personal_company' => 'boolean',
  37. ];
  38. /**
  39. * The attributes that are mass assignable.
  40. *
  41. * @var array<int, string>
  42. */
  43. protected $fillable = [
  44. 'name',
  45. 'personal_company',
  46. ];
  47. /**
  48. * The event map for the model.
  49. *
  50. * @var array<string, class-string>
  51. */
  52. protected $dispatchesEvents = [
  53. 'created' => CompanyCreated::class,
  54. 'updated' => CompanyUpdated::class,
  55. 'deleted' => CompanyDeleted::class,
  56. ];
  57. public function getFilamentAvatarUrl(): ?string
  58. {
  59. return $this->profile->logo_url ?? $this->owner->profile_photo_url;
  60. }
  61. public function connectedBankAccounts(): HasMany
  62. {
  63. return $this->hasMany(ConnectedBankAccount::class, 'company_id');
  64. }
  65. public function accounts(): HasMany
  66. {
  67. return $this->hasMany(Accounting\Account::class, 'company_id');
  68. }
  69. public function accountHistories(): HasMany
  70. {
  71. return $this->hasMany(AccountHistory::class, 'company_id');
  72. }
  73. public function bankAccounts(): HasMany
  74. {
  75. return $this->hasMany(BankAccount::class, 'company_id');
  76. }
  77. public function appearance(): HasOne
  78. {
  79. return $this->hasOne(Appearance::class, 'company_id');
  80. }
  81. public function categories(): HasMany
  82. {
  83. return $this->hasMany(Category::class, 'company_id');
  84. }
  85. public function accountSubtypes(): HasMany
  86. {
  87. return $this->hasMany(AccountSubtype::class, 'company_id');
  88. }
  89. public function contacts(): HasMany
  90. {
  91. return $this->hasMany(Contact::class, 'company_id');
  92. }
  93. public function currencies(): HasMany
  94. {
  95. return $this->hasMany(Currency::class, 'company_id');
  96. }
  97. public function default(): HasOne
  98. {
  99. return $this->hasOne(CompanyDefault::class, 'company_id');
  100. }
  101. public function defaultBill(): HasOne
  102. {
  103. return $this->hasOne(DocumentDefault::class, 'company_id')
  104. ->where('type', DocumentType::Bill);
  105. }
  106. public function defaultInvoice(): HasOne
  107. {
  108. return $this->hasOne(DocumentDefault::class, 'company_id')
  109. ->where('type', DocumentType::Invoice);
  110. }
  111. public function departments(): HasMany
  112. {
  113. return $this->hasMany(Department::class, 'company_id');
  114. }
  115. public function discounts(): HasMany
  116. {
  117. return $this->hasMany(Discount::class, 'company_id');
  118. }
  119. public function locale(): HasOne
  120. {
  121. return $this->hasOne(Localization::class, 'company_id');
  122. }
  123. public function profile(): HasOne
  124. {
  125. return $this->hasOne(CompanyProfile::class, 'company_id');
  126. }
  127. public function taxes(): HasMany
  128. {
  129. return $this->hasMany(Tax::class, 'company_id');
  130. }
  131. }