From 4718bf3057492cdf4369eeedf7705179c611ecb5 Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 1 Dec 2020 21:23:07 +1100 Subject: [PATCH] Fix catch matching in typeahead, dont bill services past their end date --- app/Models/Service.php | 13 ++++++++----- resources/js/bootstrap3-typeahead.js | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/Models/Service.php b/app/Models/Service.php index 0dc014e..6e25e4a 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -1171,11 +1171,14 @@ class Service extends Model * @return Collection * @throws Exception */ - public function next_invoice_items(bool $future): Collection + public function next_invoice_items(bool $future,Carbon $billdate=NULL): Collection { if ($this->wasCancelled() OR $this->suspend_billing OR $this->external_billing OR (! $future AND ! $this->active)) return collect(); + if (is_null($billdate)) + $billdate = Carbon::now()->addDays(30); + // If pending, add any connection charges // Connection charges are only charged once if ((! $this->invoice_items->filter(function($item) { return $item->item_type==4; })->sum('total')) @@ -1203,8 +1206,8 @@ class Service extends Model if ((! $this->invoice_items->filter(function($item) { return $item->item_type==0 AND ! $item->exists; })->count()) AND ($this->active OR $this->isPending()) AND ( - ($future == TRUE AND $this->invoice_next < $this->invoice_next_end) OR - ($future == FALSE AND ($this->invoice_to < ($this->date_end ?: Carbon::now()->addDays(30)))) + (($future == TRUE) AND $this->invoice_next < $this->invoice_next_end) OR + (($future == FALSE) AND ($this->invoice_to < ($this->date_end ?: $billdate))) )) { do { @@ -1224,11 +1227,11 @@ class Service extends Model $o->addTaxes($this->account->country->taxes); $this->invoice_items->push($o); - } while ($future == FALSE AND ($this->invoice_to < ($this->date_end ?: Carbon::now()->addDays(30)))); + } while ($future == FALSE AND ($this->invoice_to < ($this->date_end ?: $billdate))); } // Add additional charges - if (($future == TRUE OR ($future == FALSE AND ($this->invoice_to >= Carbon::now()->addDays(30)))) + if ((($future == TRUE) OR (($future == FALSE) AND ($this->invoice_to >= $billdate))) 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) { diff --git a/resources/js/bootstrap3-typeahead.js b/resources/js/bootstrap3-typeahead.js index 95a7b8f..7556318 100644 --- a/resources/js/bootstrap3-typeahead.js +++ b/resources/js/bootstrap3-typeahead.js @@ -313,7 +313,7 @@ text = text.replace((/[\(\)\/\.\*\+\?\[\]]/g), function (mat) { return '\\' + mat; }); - var reg = new RegExp(text, 'g'); + var reg = new RegExp(text, 'ig'); var m; for (i = 0; i < first.length; ++i) { m = first[i].match(reg);