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.

Company.php 4.5KB

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