Fix services with no model, showing future invoice items

This commit is contained in:
Deon George 2020-04-02 12:03:26 +11:00
parent 57f24c9315
commit 10c8e43f7c
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254

View File

@ -493,7 +493,7 @@ class Service extends Model
*/
public function getNameShortAttribute()
{
return $this->type->service_name;
return $this->type ? $this->type->service_name : $this->id;
}
/**
@ -831,7 +831,7 @@ class Service extends Model
// If the service is active, there will be service charges
if ((! $this->invoice_items->filter(function($item) { return $item->item_type==0 AND ! $item->exists; })->count())
AND ($this->active OR $this->isPending())
AND ($future == FALSE AND ($this->invoice_to < Carbon::now()->addDays(30))))
AND ($future == TRUE OR ($future == FALSE AND ($this->invoice_to < Carbon::now()->addDays(30)))))
{
do {
$o = new InvoiceItem;
@ -854,7 +854,9 @@ class Service extends Model
}
// Add additional charges
if (! $this->invoice_items->filter(function($item) { return $item->module_id == 30 AND ! $item->exists; })->count())
if (($future = TRUE OR ($future == FALSE AND ($this->invoice_to < Carbon::now()->addDays(30))))
AND ! $this->invoice_items->filter(function($item) { return $item->module_id == 30 AND ! $item->exists; })->count())
{
foreach ($this->charges->filter(function($item) { return ! $item->processed; }) as $oo) {
$o = new InvoiceItem;
$o->active = TRUE;
@ -872,6 +874,7 @@ class Service extends Model
$o->addTaxes($this->account->country->taxes);
$this->invoice_items->push($o);
}
}
return $this->invoice_items->filter(function($item) { return ! $item->exists; });
}