belongsTo(\App\User::class); } public function invoiceitems() { return $this->hasMany(InvoiceItem::class); } public function paymentitems() { return $this->hasMany(PaymentItem::class); } public function getDueAttribute() { return $this->currency()->round($this->total - $this->paid); } public function getDateDueAttribute() { return $this->due_date->format('Y-m-d'); } public function getInvoiceNumberAttribute() { return sprintf('%02s-%04s-%04s',$this->site_id,$this->account_id,$this->id); } public function getPaidAttribute() { return $this->currency()->round($this->paymentitems->sum('alloc_amt')); } public function getTotalAttribute() { if (! $this->_total) { foreach ($this->invoiceitems as $o) { //if ($o->active) $this->_total += $this->currency()->round($o->total); } } return $this->_total; } public function currency() { return $this->account->country->currency; } }