Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Company.php 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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\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 addresses(): HasMany
  67. {
  68. return $this->hasMany(Common\Address::class, 'company_id');
  69. }
  70. public function adjustments(): HasMany
  71. {
  72. return $this->hasMany(Accounting\Adjustment::class, 'company_id');
  73. }
  74. public function bankAccounts(): HasMany
  75. {
  76. return $this->hasMany(BankAccount::class, 'company_id');
  77. }
  78. public function bills(): HasMany
  79. {
  80. return $this->hasMany(Accounting\Bill::class, 'company_id');
  81. }
  82. public function budgets(): HasMany
  83. {
  84. return $this->hasMany(Accounting\Budget::class, 'company_id');
  85. }
  86. public function budgetItems(): HasMany
  87. {
  88. return $this->hasMany(Accounting\BudgetItem::class, 'company_id');
  89. }
  90. public function budgetAllocations(): HasMany
  91. {
  92. return $this->hasMany(Accounting\BudgetAllocation::class, 'company_id');
  93. }
  94. public function accountSubtypes(): HasMany
  95. {
  96. return $this->hasMany(AccountSubtype::class, 'company_id');
  97. }
  98. public function clients(): HasMany
  99. {
  100. return $this->hasMany(Client::class, 'company_id');
  101. }
  102. public function contacts(): HasMany
  103. {
  104. return $this->hasMany(Contact::class, 'company_id');
  105. }
  106. public function currencies(): HasMany
  107. {
  108. return $this->hasMany(Currency::class, 'company_id');
  109. }
  110. public function default(): HasOne
  111. {
  112. return $this->hasOne(CompanyDefault::class, 'company_id');
  113. }
  114. public function documentDefaults(): HasMany
  115. {
  116. return $this->hasMany(DocumentDefault::class, 'company_id');
  117. }
  118. public function defaultBill(): HasOne
  119. {
  120. return $this->hasOne(DocumentDefault::class, 'company_id')
  121. ->where('type', DocumentType::Bill);
  122. }
  123. public function defaultEstimate(): HasOne
  124. {
  125. return $this->hasOne(DocumentDefault::class, 'company_id')
  126. ->where('type', DocumentType::Estimate);
  127. }
  128. public function defaultInvoice(): HasOne
  129. {
  130. return $this->hasOne(DocumentDefault::class, 'company_id')
  131. ->where('type', DocumentType::Invoice);
  132. }
  133. public function defaultRecurringInvoice(): HasOne
  134. {
  135. return $this->hasOne(DocumentDefault::class, 'company_id')
  136. ->where('type', DocumentType::RecurringInvoice);
  137. }
  138. public function departments(): HasMany
  139. {
  140. return $this->hasMany(Department::class, 'company_id');
  141. }
  142. public function estimates(): HasMany
  143. {
  144. return $this->hasMany(Accounting\Estimate::class, 'company_id');
  145. }
  146. public function invoices(): HasMany
  147. {
  148. return $this->hasMany(Accounting\Invoice::class, 'company_id');
  149. }
  150. public function recurringInvoices(): HasMany
  151. {
  152. return $this->hasMany(Accounting\RecurringInvoice::class, 'company_id');
  153. }
  154. public function locale(): HasOne
  155. {
  156. return $this->hasOne(Localization::class, 'company_id');
  157. }
  158. public function profile(): HasOne
  159. {
  160. return $this->hasOne(CompanyProfile::class, 'company_id');
  161. }
  162. public function transactions(): HasMany
  163. {
  164. return $this->hasMany(Accounting\Transaction::class, 'company_id');
  165. }
  166. public function offerings(): HasMany
  167. {
  168. return $this->hasMany(Offering::class, 'company_id');
  169. }
  170. public function vendors(): HasMany
  171. {
  172. return $this->hasMany(Common\Vendor::class, 'company_id');
  173. }
  174. }