123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
-
- namespace App\Models\Document;
-
- use App\Models\Contact;
- use App\Models\Setting\Category;
- use App\Models\Setting\Currency;
- use App\Models\Setting\Discount;
- use App\Models\Setting\Tax;
- use Database\Factories\DocumentFactory;
- use Illuminate\Database\Eloquent\Factories\Factory;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- use Illuminate\Database\Eloquent\Relations\HasOne;
- use Wallo\FilamentCompanies\FilamentCompanies;
-
- class Document extends Model
- {
- use HasFactory;
-
- protected $table = 'documents';
-
- protected $fillable = [
- 'company_id',
- 'type',
- 'document_number',
- 'order_number',
- 'status',
- 'document_date',
- 'due_date',
- 'paid_date',
- 'amount',
- 'tax_id',
- 'discount_id',
- 'reference',
- 'currency_code',
- 'category_id',
- 'contact_id',
- 'notes',
- 'created_by',
- ];
-
- protected $casts = [
- 'document_date' => 'datetime',
- 'due_date' => 'datetime',
- 'paid_date' => 'datetime',
- ];
-
- public function company(): BelongsTo
- {
- return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
- }
-
- public function createdBy(): BelongsTo
- {
- return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
- }
-
- public function tax(): BelongsTo
- {
- return $this->belongsTo(Tax::class);
- }
-
- public function discount(): BelongsTo
- {
- return $this->belongsTo(Discount::class);
- }
-
- public function currency(): BelongsTo
- {
- return $this->belongsTo(Currency::class, 'currency_code', 'code');
- }
-
- public function category(): BelongsTo
- {
- return $this->belongsTo(Category::class);
- }
-
- public function contact(): BelongsTo
- {
- return $this->belongsTo(Contact::class);
- }
-
- public function items(): HasMany
- {
- return $this->hasMany(DocumentItem::class);
- }
-
- public function total(): HasOne
- {
- return $this->hasOne(DocumentTotal::class);
- }
-
- protected static function newFactory(): Factory
- {
- return DocumentFactory::new();
- }
- }
|