diff --git a/app/Models/Service.php b/app/Models/Service.php index 6c5f8d4..1c51a84 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -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; }); }