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 3.6KB

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