Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Contact.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Models;
  3. use App\Models\Document\Document;
  4. use App\Models\Setting\Currency;
  5. use Illuminate\Database\Eloquent\Factories\HasFactory;
  6. use Illuminate\Database\Eloquent\Model;
  7. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  8. use Illuminate\Database\Eloquent\Relations\HasMany;
  9. use Wallo\FilamentCompanies\FilamentCompanies;
  10. class Contact extends Model
  11. {
  12. use HasFactory;
  13. protected $table = 'contacts';
  14. protected $fillable = [
  15. 'company_id',
  16. 'entity',
  17. 'type',
  18. 'name',
  19. 'email',
  20. 'tax_number',
  21. 'phone',
  22. 'address',
  23. 'city',
  24. 'zip_code',
  25. 'state',
  26. 'country',
  27. 'website',
  28. 'currency_code',
  29. 'reference',
  30. 'created_by',
  31. ];
  32. protected $casts = [
  33. 'enabled' => 'boolean',
  34. ];
  35. public function company(): BelongsTo
  36. {
  37. return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
  38. }
  39. public function createdBy(): BelongsTo
  40. {
  41. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  42. }
  43. public function currency(): BelongsTo
  44. {
  45. return $this->belongsTo(Currency::class, 'currency_code', 'code');
  46. }
  47. public function documents(): HasMany
  48. {
  49. return $this->hasMany(Document::class);
  50. }
  51. public function bills(): HasMany
  52. {
  53. return $this->documents()->where('type', 'bill');
  54. }
  55. public function invoices(): HasMany
  56. {
  57. return $this->documents()->where('type', 'invoice');
  58. }
  59. public function scopeVendor($query)
  60. {
  61. return $query->where('type', 'vendor');
  62. }
  63. public function scopeCustomer($query)
  64. {
  65. return $query->where('type', 'customer');
  66. }
  67. public function scopeEmployee($query)
  68. {
  69. return $query->where('type', 'employee');
  70. }
  71. public function scopeCompany($query)
  72. {
  73. return $query->where('entity', 'company');
  74. }
  75. public function scopeIndividual($query)
  76. {
  77. return $query->where('entity', 'individual');
  78. }
  79. }