Using datatables to render home dashboard
This commit is contained in:
@@ -8,7 +8,22 @@ class Invoice extends Model
|
||||
{
|
||||
protected $table = 'ab_invoice';
|
||||
protected $dates = ['due_date'];
|
||||
protected $with = ['invoiceitems.taxes','account.country.currency','paymentitems'];
|
||||
protected $with = ['items.taxes','account.country.currency','paymentitems'];
|
||||
|
||||
protected $appends = [
|
||||
'date_due',
|
||||
'due',
|
||||
'invoice_id_url',
|
||||
'total',
|
||||
];
|
||||
|
||||
protected $visible = [
|
||||
'date_due',
|
||||
'due',
|
||||
'id',
|
||||
'invoice_id_url',
|
||||
'total',
|
||||
];
|
||||
|
||||
private $_total = 0;
|
||||
|
||||
@@ -17,7 +32,7 @@ class Invoice extends Model
|
||||
return $this->belongsTo(\App\User::class);
|
||||
}
|
||||
|
||||
public function invoiceitems()
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany(InvoiceItem::class);
|
||||
}
|
||||
@@ -29,7 +44,7 @@ class Invoice extends Model
|
||||
|
||||
public function getDueAttribute()
|
||||
{
|
||||
return $this->currency()->round($this->total - $this->paid);
|
||||
return sprintf('%3.'.$this->currency()->rounding.'f',$this->total - $this->paid);
|
||||
}
|
||||
|
||||
public function getDateDueAttribute()
|
||||
@@ -37,11 +52,16 @@ class Invoice extends Model
|
||||
return $this->due_date->format('Y-m-d');
|
||||
}
|
||||
|
||||
public function getInvoiceNumberAttribute()
|
||||
public function getInvoiceIdAttribute()
|
||||
{
|
||||
return sprintf('%02s-%04s-%04s',$this->site_id,$this->account_id,$this->id);
|
||||
}
|
||||
|
||||
public function getInvoiceIdUrlAttribute()
|
||||
{
|
||||
return sprintf('<a href="/u/invoice/view/%s">%s</a>',$this->id,$this->invoice_id);
|
||||
}
|
||||
|
||||
public function getPaidAttribute()
|
||||
{
|
||||
return $this->currency()->round($this->paymentitems->sum('alloc_amt'));
|
||||
@@ -51,14 +71,14 @@ class Invoice extends Model
|
||||
{
|
||||
if (! $this->_total)
|
||||
{
|
||||
foreach ($this->invoiceitems as $o)
|
||||
foreach ($this->items as $o)
|
||||
{
|
||||
//if ($o->active)
|
||||
if ($o->active)
|
||||
$this->_total += $this->currency()->round($o->total);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_total;
|
||||
return sprintf('%3.'.$this->currency()->rounding.'f',$this->_total);
|
||||
}
|
||||
|
||||
public function currency()
|
||||
|
Reference in New Issue
Block a user