belongsTo(Account::class); } public function items() { return $this->hasMany(InvoiceItem::class); } public function paymentitems() { return $this->hasMany(PaymentItem::class); } public function getDueAttribute() { return sprintf('%3.'.$this->currency()->rounding.'f',$this->total - $this->paid); } public function getDateDueAttribute() { return $this->due_date->format('Y-m-d'); } public function getInvoiceIdAttribute() { return sprintf('%02s-%04s-%04s',$this->site_id,$this->account_id,$this->id); } public function getInvoiceIdUrlAttribute() { return sprintf('%s',$this->id,$this->invoice_id); } public function getPaidAttribute() { return $this->currency()->round($this->paymentitems->sum('alloc_amt')); } public function getTotalAttribute() { if (! $this->_total) { foreach ($this->items as $o) { if ($o->active) $this->_total += $this->currency()->round($o->total); } } return sprintf('%3.'.$this->currency()->rounding.'f',$this->_total); } public function currency() { return $this->account->country->currency; } }