您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Company.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. namespace App\Models;
  3. use App\Models\Banking\Account;
  4. use App\Models\Document\Document;
  5. use App\Models\Document\DocumentItem;
  6. use App\Models\Document\DocumentTotal;
  7. use App\Models\Setting\Currency;
  8. use App\Models\Setting\Category;
  9. use App\Models\Setting\Discount;
  10. use App\Models\Setting\DocumentDefault;
  11. use App\Models\Setting\Tax;
  12. use Illuminate\Database\Eloquent\Factories\HasFactory;
  13. use Illuminate\Database\Eloquent\Relations\HasMany;
  14. use Illuminate\Database\Eloquent\Relations\HasOne;
  15. use Squire\Models\Country;
  16. use Squire\Models\Region;
  17. use Wallo\FilamentCompanies\Company as FilamentCompaniesCompany;
  18. use Wallo\FilamentCompanies\Events\CompanyCreated;
  19. use Wallo\FilamentCompanies\Events\CompanyDeleted;
  20. use Wallo\FilamentCompanies\Events\CompanyUpdated;
  21. class Company extends FilamentCompaniesCompany
  22. {
  23. use HasFactory;
  24. /**
  25. * The attributes that should be cast.
  26. *
  27. * @var array<string, string>
  28. */
  29. protected $casts = [
  30. 'personal_company' => 'boolean',
  31. ];
  32. /**
  33. * The attributes that are mass assignable.
  34. *
  35. * @var array<int, string>
  36. */
  37. protected $fillable = [
  38. 'name',
  39. 'personal_company',
  40. 'logo',
  41. 'address',
  42. 'city',
  43. 'zip_code',
  44. 'state',
  45. 'country',
  46. 'phone',
  47. 'email',
  48. ];
  49. /**
  50. * The event map for the model.
  51. *
  52. * @var array<string, class-string>
  53. */
  54. protected $dispatchesEvents = [
  55. 'created' => CompanyCreated::class,
  56. 'updated' => CompanyUpdated::class,
  57. 'deleted' => CompanyDeleted::class,
  58. ];
  59. public function accounts(): HasMany
  60. {
  61. return $this->hasMany(Account::class);
  62. }
  63. public function currencies(): HasMany
  64. {
  65. return $this->hasMany(Currency::class);
  66. }
  67. public function categories(): HasMany
  68. {
  69. return $this->hasMany(Category::class);
  70. }
  71. public function taxes(): HasMany
  72. {
  73. return $this->hasMany(Tax::class);
  74. }
  75. public function discounts(): HasMany
  76. {
  77. return $this->hasMany(Discount::class);
  78. }
  79. public function contacts(): HasMany
  80. {
  81. return $this->hasMany(Contact::class);
  82. }
  83. public function customers(): HasMany
  84. {
  85. return $this->contacts()->where('type', 'customer');
  86. }
  87. public function company_customers(): HasMany
  88. {
  89. return $this->contacts()->where('type', 'customer')
  90. ->where('entity', 'company');
  91. }
  92. public function individual_customers(): HasMany
  93. {
  94. return $this->contacts()->where('type', 'customer')
  95. ->where('entity', 'individual');
  96. }
  97. public function vendors(): HasMany
  98. {
  99. return $this->contacts()->where('type', 'vendor');
  100. }
  101. public function company_vendors(): HasMany
  102. {
  103. return $this->contacts()->where('type', 'vendor')
  104. ->where('entity', 'company');
  105. }
  106. public function individual_vendors(): HasMany
  107. {
  108. return $this->contacts()->where('type', 'vendor')
  109. ->where('entity', 'individual');
  110. }
  111. public function document_defaults(): HasOne
  112. {
  113. return $this->hasOne(DocumentDefault::class);
  114. }
  115. public function items(): HasMany
  116. {
  117. return $this->hasMany(Item::class);
  118. }
  119. public function documents(): HasMany
  120. {
  121. return $this->hasMany(Document::class);
  122. }
  123. public function document_items(): HasMany
  124. {
  125. return $this->hasMany(DocumentItem::class);
  126. }
  127. public function document_totals(): HasMany
  128. {
  129. return $this->hasMany(DocumentTotal::class);
  130. }
  131. public function bills(): HasMany
  132. {
  133. return $this->documents()->where('type', 'bill');
  134. }
  135. public function invoices(): HasMany
  136. {
  137. return $this->documents()->where('type', 'invoice');
  138. }
  139. public function bill_items(): HasMany
  140. {
  141. return $this->document_items()->where('type', 'bill');
  142. }
  143. public function bill_totals(): HasMany
  144. {
  145. return $this->document_totals()->where('type', 'bill');
  146. }
  147. public function invoice_items(): HasMany
  148. {
  149. return $this->document_items()->where('type', 'invoice');
  150. }
  151. public function invoice_totals(): HasMany
  152. {
  153. return $this->document_totals()->where('type', 'invoice');
  154. }
  155. }