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.8KB

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