Enabled console invoice generation
This commit is contained in:
@@ -468,7 +468,15 @@ class Service extends Model
|
||||
*/
|
||||
public function getInvoiceToAttribute()
|
||||
{
|
||||
return ($x=$this->invoice_items->filter(function($item) { return $item->item_type === 0;}))->count() ? $x->last()->date_stop : NULL;
|
||||
$result = ($x=$this->invoice_items->filter(function($item) { return $item->item_type === 0;}))->count()
|
||||
? $x->last()->date_stop
|
||||
: NULL;
|
||||
|
||||
// For SSL Certificates, the invoice_to date is the expiry date of the Cert
|
||||
if (is_null($result) AND $this->type->type == 'ssl' AND $this->type->valid_to)
|
||||
return $this->type->valid_to;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getNameAttribute(): string
|
||||
@@ -480,13 +488,12 @@ class Service extends Model
|
||||
* Return the short name for the service.
|
||||
*
|
||||
* EG:
|
||||
* For ADSL, this would be the phone number,
|
||||
* For Hosting, this would be the domain name, etc
|
||||
* @deprecated
|
||||
* + For ADSL, this would be the phone number,
|
||||
* + For Hosting, this would be the domain name, etc
|
||||
*/
|
||||
public function getNameShortAttribute()
|
||||
{
|
||||
return $this->model ? $this->type->name : 'NAME UNKNOWN';
|
||||
return $this->type->service_name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -599,10 +606,10 @@ class Service extends Model
|
||||
/**
|
||||
* Return the service description.
|
||||
* For:
|
||||
* + Broadband, this is the service address
|
||||
* + Domains, blank
|
||||
* + Hosting, blank
|
||||
* + SSL, blank
|
||||
* + Broadband, this is the service address
|
||||
* + Domains, blank
|
||||
* + Hosting, blank
|
||||
* + SSL, blank
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -616,10 +623,10 @@ class Service extends Model
|
||||
/**
|
||||
* Return the service name.
|
||||
* For:
|
||||
* + Broadband, this is the service number
|
||||
* + Domains, this is the full domain name
|
||||
* + Hosting, this is the full domain name
|
||||
* + SSL, this is the DN
|
||||
* + Broadband, this is the service number
|
||||
* + Domains, this is the full domain name
|
||||
* + Hosting, this is the full domain name
|
||||
* + SSL, this is the DN
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -789,30 +796,33 @@ class Service extends Model
|
||||
/**
|
||||
* Generate a collection of invoice_item objects that will be billed for the next invoice
|
||||
*
|
||||
* @param bool $future Next item to be billed (not in the next x days)
|
||||
* @return Collection
|
||||
* @throws Exception
|
||||
*/
|
||||
public function next_invoice_items(bool $future): Collection
|
||||
{
|
||||
if ($this->wasCancelled())
|
||||
if ($this->wasCancelled() OR $this->suspend_billing OR ! $this->active)
|
||||
return collect();
|
||||
|
||||
// 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'))
|
||||
AND ($this->isPending() OR is_null($this->invoice_to)))
|
||||
AND ($this->isPending() OR is_null($this->invoice_to))
|
||||
AND $this->product->price($this->recur_schedule,'price_setup'))
|
||||
{
|
||||
$o = new InvoiceItem;
|
||||
|
||||
$o->active = TRUE;
|
||||
$o->service_id = $this->id;
|
||||
$o->product_id = $this->product_id;
|
||||
$o->item_type = 4; // @todo change to const or something
|
||||
$o->price_base = $this->price ?: $this->product->price($this->recur_schedule,'price_setup'); // @todo change to a method in this class
|
||||
$o->item_type = 4; // @todo change to const or something
|
||||
$o->price_base = $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->site_id = 1; // @todo
|
||||
|
||||
$o->addTaxes($this->account->country->taxes);
|
||||
$this->invoice_items->push($o);
|
||||
@@ -820,7 +830,8 @@ 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 ($this->active OR $this->isPending())
|
||||
AND ($future == FALSE AND ($this->invoice_to < Carbon::now()->addDays(30))))
|
||||
{
|
||||
do {
|
||||
$o = new InvoiceItem;
|
||||
@@ -828,35 +839,39 @@ class Service extends Model
|
||||
$o->service_id = $this->id;
|
||||
$o->product_id = $this->product_id;
|
||||
$o->item_type = 0;
|
||||
$o->price_base = $this->price ?: $this->product->price($this->recur_schedule); // @todo change to a method in this class
|
||||
$o->price_base = is_null($this->price)
|
||||
? (is_null($this->price_override) ? $this->product->price($this->recur_schedule) : $this->price_override)
|
||||
: $this->price; // @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_end;
|
||||
$o->quantity = $this->invoice_next_quantity;
|
||||
$o->site_id = 1; // @todo
|
||||
|
||||
$o->addTaxes($this->account->country->taxes);
|
||||
$this->invoice_items->push($o);
|
||||
} while ($future == FALSE AND ($this->invoice_to < Carbon::now()->addDays(30)));
|
||||
}
|
||||
|
||||
// Add additional charges
|
||||
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;
|
||||
// Add additional charges
|
||||
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->site_id = 1; // @todo
|
||||
|
||||
$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; });
|
||||
}
|
||||
|
Reference in New Issue
Block a user