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

Company.php 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. namespace App\Models;
  3. use App\Enums\Accounting\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 documentDefaults(): HasMany
  108. {
  109. return $this->hasMany(DocumentDefault::class, 'company_id');
  110. }
  111. public function defaultBill(): HasOne
  112. {
  113. return $this->hasOne(DocumentDefault::class, 'company_id')
  114. ->where('type', DocumentType::Bill);
  115. }
  116. public function defaultEstimate(): HasOne
  117. {
  118. return $this->hasOne(DocumentDefault::class, 'company_id')
  119. ->where('type', DocumentType::Estimate);
  120. }
  121. public function defaultInvoice(): HasOne
  122. {
  123. return $this->hasOne(DocumentDefault::class, 'company_id')
  124. ->where('type', DocumentType::Invoice);
  125. }
  126. public function defaultRecurringInvoice(): HasOne
  127. {
  128. return $this->hasOne(DocumentDefault::class, 'company_id')
  129. ->where('type', DocumentType::RecurringInvoice);
  130. }
  131. public function departments(): HasMany
  132. {
  133. return $this->hasMany(Department::class, 'company_id');
  134. }
  135. public function estimates(): HasMany
  136. {
  137. return $this->hasMany(Accounting\Estimate::class, 'company_id');
  138. }
  139. public function invoices(): HasMany
  140. {
  141. return $this->hasMany(Accounting\Invoice::class, 'company_id');
  142. }
  143. public function recurringInvoices(): HasMany
  144. {
  145. return $this->hasMany(Accounting\RecurringInvoice::class, 'company_id');
  146. }
  147. public function locale(): HasOne
  148. {
  149. return $this->hasOne(Localization::class, 'company_id');
  150. }
  151. public function profile(): HasOne
  152. {
  153. return $this->hasOne(CompanyProfile::class, 'company_id');
  154. }
  155. public function transactions(): HasMany
  156. {
  157. return $this->hasMany(Accounting\Transaction::class, 'company_id');
  158. }
  159. public function offerings(): HasMany
  160. {
  161. return $this->hasMany(Offering::class, 'company_id');
  162. }
  163. public function vendors(): HasMany
  164. {
  165. return $this->hasMany(Common\Vendor::class, 'company_id');
  166. }
  167. }