Changed account search to user search, show connection charges on invoice for pending services

This commit is contained in:
Deon George
2020-02-07 07:11:02 +09:00
parent ebd4367975
commit b61e00d80f
17 changed files with 314 additions and 145 deletions

View File

@@ -522,6 +522,12 @@ class Service extends Model
return $this->product->name($this->account->language);
}
public function getRecurScheduleAttribute($value): int
{
// If recur_schedule not set, default to 2
return $value ?? 2;
}
/**
* @deprecated see getSIDAttribute()
*/
@@ -568,7 +574,7 @@ class Service extends Model
*/
public function getSDescAttribute(): string
{
return $this->type->service_description;
return $this->type->service_description ?: 'Service Description NOT Defined for :'.$this->type->type;
}
/**
@@ -583,7 +589,7 @@ class Service extends Model
*/
public function getSNameAttribute(): string
{
return $this->type->service_name;
return $this->type->service_name ?: 'Service Name NOT Defined for :'.$this->type->type;
}
/**
@@ -596,7 +602,7 @@ class Service extends Model
{
switch($this->product->model) {
case 'App\Models\Product\Adsl': return 'broadband';
default: abort(500,'Product type not configured',['product'=>$this->product]);
default: return $this->type->type;
}
}
@@ -770,6 +776,23 @@ class Service extends Model
$result->push($o);
}
// If pending, add any connection charges
if ($this->isPending()) {
$o = new InvoiceItem;
$o->active = TRUE;
$o->service_id = $this->id;
$o->product_id = $this->product_id;
$o->item_type = 4;
$o->price_base = $this->price ?: $this->product->price($this->recur_schedule,'price_setup'); // @todo change to a method in this class
//$o->recurring_schedule = $this->recur_schedule;
$o->date_start = $this->invoice_next;
$o->date_stop = $this->invoice_next;
$o->quantity = 1;
$o->addTaxes();
$result->push($o);
}
// Add additional charges
foreach ($this->charges->filter(function($item) { return ! $item->processed; }) as $oo) {
$o = new InvoiceItem;