'decimal:2', 'price' => 'decimal:4', 'total' => 'decimal:4', ]; public function company(): BelongsTo { return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id'); } public function createdBy(): BelongsTo { return $this->belongsTo(FilamentCompanies::userModel(), 'created_by'); } public function document(): BelongsTo { return $this->belongsTo(Document::class); } public function item(): BelongsTo { return $this->belongsTo(Item::class); } public function tax(): BelongsTo { return $this->belongsTo(Tax::class); } public function discount(): BelongsTo { return $this->belongsTo(Discount::class); } public function scopeBill($query) { return $query->where('type', 'bill'); } public function scopeInvoice($query) { return $query->where('type', 'invoice'); } /** * Calculate and return the net price (price - discount + tax) */ public function getNetPriceAttribute() { $discountAmount = $this->discount ? ($this->price * $this->discount->rate / 100) : 0; $taxAmount = $this->tax ? ($this->price * $this->tax->rate / 100) : 0; return $this->price - $discountAmount + $taxAmount; } protected static function newFactory(): Factory { return DocumentItemFactory::new(); } }