items as $item) { if ($item->pivot->sign == "-") { $subtotal = $subtotal - (int) ($item->pivot->subtotal ?? 0); } else { $subtotal = $subtotal + (int) ($item->pivot->subtotal ?? 0); } } if ((int) $subtotal < 0) { return (int) $subtotal + (int) $this->discount - (int) $this->postal_fee_price; } else { return (int) $subtotal - (int) $this->discount + (int) $this->postal_fee_price; } // return $this->items->sum('pivot.subtotal') - (int) $this->discount + (int) $this->postal_fee_price; } public function getAmountDueAttribute() { return $this->amount - $this->paymentAmount; } public function scopeSearch($q, $keyword) { return $q->where(function ($q) use ($keyword) { $q->where('name', 'like', "%$keyword%") ->orWhere('unit', 'like', "%$keyword%"); }); } public function purchaseRequest() { return $this->belongsTo(PurchaseRequest::class); } public function purchaseOrderManualDetails() { return $this->hasMany(PurchaseOrderManualDetail::class); } }