Fix catch matching in typeahead, dont bill services past their end date

This commit is contained in:
Deon George 2020-12-01 21:23:07 +11:00
parent 1242dffa20
commit 4718bf3057
2 changed files with 9 additions and 6 deletions

View File

@ -1171,11 +1171,14 @@ class Service extends Model
* @return Collection * @return Collection
* @throws Exception * @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)) if ($this->wasCancelled() OR $this->suspend_billing OR $this->external_billing OR (! $future AND ! $this->active))
return collect(); return collect();
if (is_null($billdate))
$billdate = Carbon::now()->addDays(30);
// If pending, add any connection charges // If pending, add any connection charges
// Connection charges are only charged once // Connection charges are only charged once
if ((! $this->invoice_items->filter(function($item) { return $item->item_type==4; })->sum('total')) 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()) if ((! $this->invoice_items->filter(function($item) { return $item->item_type==0 AND ! $item->exists; })->count())
AND ($this->active OR $this->isPending()) AND ($this->active OR $this->isPending())
AND ( AND (
($future == TRUE AND $this->invoice_next < $this->invoice_next_end) OR (($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 == FALSE) AND ($this->invoice_to < ($this->date_end ?: $billdate)))
)) ))
{ {
do { do {
@ -1224,11 +1227,11 @@ class Service extends Model
$o->addTaxes($this->account->country->taxes); $o->addTaxes($this->account->country->taxes);
$this->invoice_items->push($o); $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 // 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()) 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) { foreach ($this->charges->filter(function($item) { return ! $item->processed; }) as $oo) {

View File

@ -313,7 +313,7 @@
text = text.replace((/[\(\)\/\.\*\+\?\[\]]/g), function (mat) { text = text.replace((/[\(\)\/\.\*\+\?\[\]]/g), function (mat) {
return '\\' + mat; return '\\' + mat;
}); });
var reg = new RegExp(text, 'g'); var reg = new RegExp(text, 'ig');
var m; var m;
for (i = 0; i < first.length; ++i) { for (i = 0; i < first.length; ++i) {
m = first[i].match(reg); m = first[i].match(reg);