123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
-
- namespace App\Models;
-
- use App\Models\Document\Document;
- use App\Models\Setting\Currency;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- use Wallo\FilamentCompanies\FilamentCompanies;
-
- class Contact extends Model
- {
- use HasFactory;
-
- protected $table = 'contacts';
-
- protected $fillable = [
- 'company_id',
- 'entity',
- 'type',
- 'name',
- 'email',
- 'tax_number',
- 'phone',
- 'address',
- 'city',
- 'zip_code',
- 'state',
- 'country',
- 'website',
- 'currency_code',
- 'reference',
- 'created_by',
- ];
-
- protected $casts = [
- 'enabled' => 'boolean',
- ];
-
- public function company(): BelongsTo
- {
- return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
- }
-
- public function createdBy(): BelongsTo
- {
- return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
- }
-
- public function currency(): BelongsTo
- {
- return $this->belongsTo(Currency::class, 'currency_code', 'code');
- }
-
- public function documents(): HasMany
- {
- return $this->hasMany(Document::class);
- }
-
- public function bills(): HasMany
- {
- return $this->documents()->where('type', 'bill');
- }
-
- public function invoices(): HasMany
- {
- return $this->documents()->where('type', 'invoice');
- }
-
- public function scopeVendor($query)
- {
- return $query->where('type', 'vendor');
- }
-
- public function scopeCustomer($query)
- {
- return $query->where('type', 'customer');
- }
-
- public function scopeEmployee($query)
- {
- return $query->where('type', 'employee');
- }
-
- public function scopeCompany($query)
- {
- return $query->where('entity', 'company');
- }
-
- public function scopeIndividual($query)
- {
- return $query->where('entity', 'individual');
- }
- }
|