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.

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