From fb9ccd927dd94ab71f70c9d075a573592b48db51 Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 31 Mar 2020 14:39:39 +1100 Subject: [PATCH] Fix rendering of future charge items --- app/Models/InvoiceItem.php | 2 +- app/Models/Service.php | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/app/Models/InvoiceItem.php b/app/Models/InvoiceItem.php index 027f2c6..2785535 100644 --- a/app/Models/InvoiceItem.php +++ b/app/Models/InvoiceItem.php @@ -107,7 +107,7 @@ class InvoiceItem extends Model ); default: - return Arr::get($types,$this->item_type,'Unknown'); + return ($this->module_id == 30 ? 'Additional Charge: ' : '').Arr::get($types,$this->item_type,'Unknown'); } } diff --git a/app/Models/Service.php b/app/Models/Service.php index 315038c..a02472a 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -840,22 +840,23 @@ class Service extends Model } // Add additional charges - foreach ($this->charges->filter(function($item) { return ! $item->processed; }) as $oo) { - $o = new InvoiceItem; - $o->active = TRUE; - $o->service_id = $oo->service_id; - $o->product_id = $this->product_id; - $o->quantity = $oo->quantity; - $o->item_type = $oo->type; - $o->price_base = $oo->amount; - $o->date_start = $oo->date_charge; - $o->date_stop = $oo->date_charge; - $o->module_id = 30; // @todo This shouldnt be hard coded - $o->module_ref = $oo->id; + if (! $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; + $o->service_id = $oo->service_id; + $o->product_id = $this->product_id; + $o->quantity = $oo->quantity; + $o->item_type = $oo->type; + $o->price_base = $oo->amount; + $o->date_start = $oo->date_charge; + $o->date_stop = $oo->date_charge; + $o->module_id = 30; // @todo This shouldnt be hard coded + $o->module_ref = $oo->id; - $o->addTaxes($this->account->country->taxes); - $this->invoice_items->push($o); - } + $o->addTaxes($this->account->country->taxes); + $this->invoice_items->push($o); + } return $this->invoice_items->filter(function($item) { return ! $item->exists; }); }