Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Client.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Models\Common;
  3. use App\Concerns\Blamable;
  4. use App\Concerns\CompanyOwned;
  5. use App\Enums\Common\AddressType;
  6. use App\Models\Accounting\Estimate;
  7. use App\Models\Accounting\Invoice;
  8. use App\Models\Accounting\RecurringInvoice;
  9. use App\Models\Setting\Currency;
  10. use Illuminate\Database\Eloquent\Factories\HasFactory;
  11. use Illuminate\Database\Eloquent\Model;
  12. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  13. use Illuminate\Database\Eloquent\Relations\HasMany;
  14. use Illuminate\Database\Eloquent\Relations\MorphMany;
  15. use Illuminate\Database\Eloquent\Relations\MorphOne;
  16. class Client extends Model
  17. {
  18. use Blamable;
  19. use CompanyOwned;
  20. use HasFactory;
  21. protected $table = 'clients';
  22. protected $fillable = [
  23. 'company_id',
  24. 'name',
  25. 'currency_code',
  26. 'account_number',
  27. 'website',
  28. 'notes',
  29. 'created_by',
  30. 'updated_by',
  31. ];
  32. public function contacts(): MorphMany
  33. {
  34. return $this->morphMany(Contact::class, 'contactable');
  35. }
  36. public function primaryContact(): MorphOne
  37. {
  38. return $this->morphOne(Contact::class, 'contactable')
  39. ->where('is_primary', true);
  40. }
  41. public function secondaryContacts(): MorphMany
  42. {
  43. return $this->morphMany(Contact::class, 'contactable')
  44. ->where('is_primary', false);
  45. }
  46. public function currency(): BelongsTo
  47. {
  48. return $this->belongsTo(Currency::class, 'currency_code', 'code');
  49. }
  50. public function addresses(): MorphMany
  51. {
  52. return $this->morphMany(Address::class, 'addressable');
  53. }
  54. public function billingAddress(): MorphOne
  55. {
  56. return $this->morphOne(Address::class, 'addressable')
  57. ->where('type', AddressType::Billing);
  58. }
  59. public function shippingAddress(): MorphOne
  60. {
  61. return $this->morphOne(Address::class, 'addressable')
  62. ->where('type', AddressType::Shipping);
  63. }
  64. public function estimates(): HasMany
  65. {
  66. return $this->hasMany(Estimate::class);
  67. }
  68. public function invoices(): HasMany
  69. {
  70. return $this->hasMany(Invoice::class);
  71. }
  72. public function recurringInvoices(): HasMany
  73. {
  74. return $this->hasMany(RecurringInvoice::class);
  75. }
  76. }