Removed redundant functions from Service::class

This commit is contained in:
Deon George 2022-04-22 10:36:41 +10:00
parent d53643ef55
commit 8ed9e38290
29 changed files with 307 additions and 514 deletions

View File

@ -35,70 +35,73 @@ class SearchController extends Controller
->orderBy('firstname')
->limit(10)->get() as $o)
{
$result->push(['name'=>sprintf('%s %s',$o->sid,$o->name),'value'=>'/u/home/'.$o->id,'category'=>'Users']);
$result->push(['name'=>sprintf('%s (%s)',$o->lid,$o->name),'value'=>'/u/home/'.$o->id,'category'=>'Users']);
}
# Look for Account
foreach (Account::Search($request->input('term'))
->whereIN('user_id',$user_ids)
->orderBy('company')
->limit(10)->get() as $o)
->whereIN('user_id',$user_ids)
->orderBy('company')
->limit(10)->get() as $o)
{
$result->push(['name'=>sprintf('%s %s',$o->sid,$o->company),'value'=>'/u/home/'.$o->user_id,'category'=>'Accounts']);
$result->push(['name'=>sprintf('%s (%s)',$o->lid,$o->company),'value'=>'/u/home/'.$o->user_id,'category'=>'Accounts']);
}
# Look for a Service
foreach (Service::Search($request->input('term'))
->whereIN('account_id',$account_ids)
->orderBy('id')
->limit(10)->get() as $o)
->whereIN('account_id',$account_ids)
->orderBy('id')
->limit(10)->get() as $o)
{
$result->push(['name'=>sprintf('%s (%s)',$o->name,$o->sid),'value'=>'/u/service/'.$o->id,'category'=>'Services']);
$result->push(['name'=>sprintf('%s (%s)',$o->name,$o->lid),'value'=>'/u/service/'.$o->id,'category'=>'Services']);
}
# Look for an Invoice
foreach (Invoice::Search($request->input('term'))
->whereIN('account_id',$account_ids)
->orderBy('id')
->limit(10)->get() as $o)
->whereIN('account_id',$account_ids)
->orderBy('id')
->limit(10)->get() as $o)
{
$result->push(['name'=>sprintf('%s: %s',$o->sid,$o->account->name),'value'=>'/u/invoice/'.$o->id,'category'=>'Invoices']);
$result->push(['name'=>sprintf('%s: %s',$o->lid,$o->account->name),'value'=>'/u/invoice/'.$o->id,'category'=>'Invoices']);
}
# Look for an Broadband Service
# Look for a Broadband Service
foreach (Broadband::Search($request->input('term'))
->whereIN('account_id',$account_ids)
->orderBy('service_number')
->limit(10)->get() as $o)
->whereIN('account_id',$account_ids)
->orderBy('service_number')
->with(['service'])
->limit(10)->get() as $o)
{
$result->push(['name'=>sprintf('%s (%s)',$o->service_name,$o->service->sid),'value'=>'/u/service/'.$o->id,'category'=>'Broadband']);
$result->push(['name'=>sprintf('%s (%s)',$o->service->name,$o->service->lid),'value'=>'/u/service/'.$o->service_id,'category'=>'Broadband']);
}
# Look for an Phone Service
# Look for a Phone Service
foreach (Phone::Search($request->input('term'))
->whereIN('account_id',$account_ids)
->orderBy('service_number')
->limit(10)->get() as $o)
->whereIN('account_id',$account_ids)
->orderBy('service_number')
->with(['service'])
->limit(10)->get() as $o)
{
$result->push(['name'=>sprintf('%s (%s)',$o->service_name,$o->service->sid),'value'=>'/u/service/'.$o->id,'category'=>'Phone']);
$result->push(['name'=>sprintf('%s (%s)',$o->service->name,$o->service->lid),'value'=>'/u/service/'.$o->service_id,'category'=>'Phone']);
}
# Look for Domain Name
foreach (Service\Domain::Search($request->input('term'))
->whereIN('account_id',$account_ids)
->orderBy('domain_name')
->limit(10)->get() as $o)
->whereIN('account_id',$account_ids)
->orderBy('domain_name')
->with(['service'])
->limit(10)->get() as $o)
{
$result->push(['name'=>sprintf('%s (%s)',$o->service_name,$o->service->sid),'value'=>'/u/service/'.$o->id,'category'=>'Domains']);
$result->push(['name'=>sprintf('%s (%s)',$o->service->name,$o->service->lid),'value'=>'/u/service/'.$o->service_id,'category'=>'Domains']);
}
if (Gate::any(['wholesaler'],new Payment)) {
# Look for Payments
foreach (Payment::Search($request->input('term'))
->whereIN('account_id',$account_ids)
->limit(10)->get() as $o)
->whereIN('account_id',$account_ids)
->limit(10)->get() as $o)
{
$result->push(['name'=>sprintf('%s ($%s)',$o->id,number_format($o->total,2)),'value'=>'/a/payment/addedit/'.$o->id,'category'=>'Payments']);
$result->push(['name'=>sprintf('%s: %s $%s',$o->lid,$o->account->name,number_format($o->total,2)),'value'=>'/a/payment/addedit/'.$o->id,'category'=>'Payments']);
}
}

View File

@ -125,12 +125,6 @@ class Account extends Model implements IDs
/* ATTRIBUTES */
public function getActiveDisplayAttribute($value)
{
abort(500,'deprecated');
return sprintf('<span class="btn-sm btn-block btn-%s text-center">%s</span>',$this->active ? 'success' : 'danger',$this->active ? 'Active' : 'Inactive');
}
/**
* Get the address for the account
*
@ -160,31 +154,7 @@ class Account extends Model implements IDs
return $this->company ? 'Business' : 'Private';
}
/**
* Return the Admin URL to manage the account
*
* @return string
* @deprecated
*/
public function getUrlAdminAttribute(): string
{
abort(500,'deprecated');
return sprintf('<a href="/r/account/view/%s">%s</a>',$this->id,$this->account_id);
}
/**
* Return the User URL to manage the account
*
* @return string
* @deprecated
*/
public function getUrlUserAttribute(): string
{
abort(500,'deprecated');
return sprintf('<a href="/u/account/view/%s">%s</a>',$this->id,$this->account_id);
}
/* GENERAL METHODS */
/* METHODS */
/**
* Get the due invoices on an account
@ -197,19 +167,4 @@ class Account extends Model implements IDs
return $item->active AND $item->due > 0;
});
}
/**
* Get the external account ID for a specific integration
*
* @param External\Integrations $o
* @return mixed
*/
public function ExternalAccounting(External\Integrations $o)
{
return $this
->external()
->where('id','=',$o->id)
->where('site_id','=',$this->site_id)
->first();
}
}

View File

@ -45,7 +45,18 @@ class Invoice extends Model implements IDs
protected $dates = ['date_orig','due_date'];
public $dateFormat = 'U';
public const BILL_WEEKLY = 0;
public const BILL_MONTHLY = 1;
public const BILL_QUARTERLY = 2;
public const BILL_SEMI_YEARLY = 3;
public const BILL_YEARLY = 4;
public const BILL_TWOYEARS = 5;
public const BILL_THREEYEARS = 6;
public const BILL_FOURYEARS = 7;
public const BILL_FIVEYEARS = 8;
/* Our available billing periods */
// @todo change this to a function - with billing_name()?
public const billing_periods = [
0 => [
'name' => 'Weekly',

View File

@ -28,7 +28,7 @@ use App\Traits\{ProductDetails,SiteID};
* + sid : System ID for product (part number)
* + supplied : Supplier product provided for this offering
* + supplier : Supplier for this offering
* + name : Brief Name for our product
* + name : Brief Name for our product // @todo we should change this to be consistent with service
* + name_short : Product ID for our Product
* + name_long : Long Name for our product
* + billing_interval : Default Billing Interval

View File

@ -9,7 +9,7 @@ use App\Traits\{OrderServiceOptions,SiteID};
/**
* @todo These tables have a base_cost/setup_cost/contract_term columns - how is that different to the supplier_tables?
* @todo Ensure our terminology is consistent - we have a "cost", we "charge" clients.
* @todo Ensure our terminology is consistent - we have a "cost", we "charge" clients, and we have a "price" which is not official charges nor a cost.
*/
abstract class Type extends Model
{

View File

@ -26,15 +26,18 @@ use App\Traits\ScopeServiceUserAuthorised;
*
* Attributes for services:
* + additional_cost : Pending additional charges for this service (excluding setup) //@todo check all these are still valid
* + billing_cost : Charge for this service each invoice period
* + billing_charge : Charge for this service each invoice period // @todo change to "charge"
* + billing_interval : The period that this service is billed for by default
* + billing_interval_string : The period that this service is billed for by default as a name
* + category : The type of service this is, eg: broadband, phone
* + contract_term : The term that this service must be active
* + contract_end : The date that the contract ends for this service
* + name : Service short name with service address
* + name_short : Service Product short name, eg: phone number, domain name, certificate CN
* + name_detail : Service Detail, eg: service_address
* + product : Our product that is providing this service
* + sid : System ID for service
* + supplied : The model of the supplier's product used for this service.
*
* = Terminology:
* - Offering, what product we supply (we make offerings from supplier's supplied products) - in the DB these are products/*
@ -44,7 +47,6 @@ use App\Traits\ScopeServiceUserAuthorised;
* @package App\Models
* @todo "Billing Start Date" = "connection date" for sub types??
*/
// @todo All the methods/attributes in this file need to be checked.
class Service extends Model implements IDs
{
use HasFactory,ScopeServiceUserAuthorised;
@ -254,6 +256,28 @@ class Service extends Model implements IDs
],
];
/* INTERFACES */
/**
* Service Local ID
*
* @return string
*/
public function getLIDattribute(): string
{
return sprintf('%05s',$this->id);
}
/**
* Services System ID
*
* @return string
*/
public function getSIDAttribute(): string
{
return sprintf('%02s-%04s.%s',$this->site_id,$this->account_id,$this->getLIDattribute());
}
/* RELATIONS */
/**
@ -304,7 +328,6 @@ class Service extends Model implements IDs
/**
* Invoices for this service
*
*/
public function invoices($active=TRUE)
{
@ -342,17 +365,6 @@ class Service extends Model implements IDs
return $this->belongsTo(Product::class);
}
/**
* The site this service is configured for
*
* @todo It may be more appropriate to get this from the account->user attribute (ie: for mail actions)
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function site()
{
return $this->belongsTo(Site::class);
}
/**
* Return a child model with details of the service
*
@ -405,7 +417,7 @@ class Service extends Model implements IDs
*
* @param $query
* @param string $term
* @return
* @return mixed
*/
public function scopeSearch($query,string $term)
{
@ -415,27 +427,11 @@ class Service extends Model implements IDs
/* ATTRIBUTES */
/**
* Name of the account for this service
* How much do we charge for this service, base on the current recur schedule
*
* @return mixed
* @deprecated use $this->>account->name directly
* @return float
*/
public function getAccountNameAttribute(): string
{
return $this->account->name;
}
/**
* Return the auto billing details
*
* @return mixed
*/
public function getAutoPayAttribute()
{
return $this->billing;
}
public function getBillingPriceAttribute(): float
public function getBillingChargeAttribute(): float
{
// @todo Temporary for services that dont have recur_schedule set.
if (is_null($this->recur_schedule) OR is_null($this->product->getBaseChargeAttribute($this->recur_schedule,$this->account->group)))
@ -444,22 +440,6 @@ class Service extends Model implements IDs
return $this->addTax(is_null($this->price) ? $this->product->getBaseChargeAttribute($this->recur_schedule,$this->account->group) : $this->price);
}
public function getBillingMonthlyPriceAttribute(): float
{
$d = 0;
switch ($this->recur_schedule) {
case 0: $d = 12/52; break;
case 1: $d = 1; break;
case 2: $d = 3; break;
case 3: $d = 6; break;
case 4: $d = 12; break;
case 5: $d = 24; break;
case 6: $d = 36; break;
}
return number_format($this->getBillingPriceAttribute()/$d,2);
}
/**
* Return the service billing period
*
@ -480,6 +460,78 @@ class Service extends Model implements IDs
return Invoice::billing_name($this->getBillingIntervalAttribute());
}
/**
* Determine a monthly price for a service, even if it is billed at a different frequency
*
* @return float
* @throws Exception
*/
public function getBillingMonthlyPriceAttribute(): float
{
$d = 1;
switch ($this->recur_schedule) {
case Invoice::BILL_WEEKLY:
$d = 12/52;
break;
case Invoice::BILL_MONTHLY:
$d = 1;
break;
case Invoice::BILL_QUARTERLY:
$d = 3;
break;
case Invoice::BILL_SEMI_YEARLY:
$d = 6;
break;
case Invoice::BILL_YEARLY:
$d = 12;
break;
case Invoice::BILL_TWOYEARS:
$d = 24;
break;
case Invoice::BILL_THREEYEARS:
$d = 36;
break;
case Invoice::BILL_FOURYEARS:
$d = 48;
break;
case Invoice::BILL_FIVEYEARS:
$d = 60;
break;
default:
throw new Exception('Unknown recur_schedule');
}
return number_format($this->getBillingChargeAttribute()/$d,2);
}
/**
* Return the type of service is provided. eg: Broadband, Phone.
*
* @return string
*/
public function getCategoryAttribute(): string
{
switch ($x=$this->type->getTypeAttribute()) {
case 'ssl':
$type = 'SSL';
break;
default:
$type = ucfirst($x);
}
return $type;
}
/**
* The date the contract ends
*
@ -509,13 +561,13 @@ class Service extends Model implements IDs
/**
* This function will determine the minimum contract term for a service, which is the maximum of
* this::type->contract_term, or the product->type->contract_term();
* supplier->type->contract_term, or the product->type->contract_term;
*
* @return int
*/
public function getContractTermAttribute(): int
{
return $this->product->type->supplied->contract_term ?: 0;
return $this->getSuppliedAttribute()->contract_term;
}
/**
@ -526,24 +578,22 @@ class Service extends Model implements IDs
*/
public function getExpiresAttribute(): string
{
abort(500,'Not implemented');
return 'TBA';
}
/**
* Return the date for the next invoice
*
* @todo Change date_next_invoice to connect_date/invoice_start_date
* @return Carbon|string
*/
public function getInvoiceNextAttribute()
public function getInvoiceNextAttribute(): \Carbon\Carbon
{
$last = $this->getInvoiceToAttribute();
$date = $last
return $last
? $last->addDay()
: ($this->date_next_invoice ? $this->date_next_invoice->clone()
: ($this->start_at ?: Carbon::now()));
return request()->wantsJson() ? $date->format('Y-m-d') : $date;
}
/**
@ -555,58 +605,65 @@ class Service extends Model implements IDs
public function getInvoiceNextEndAttribute()
{
switch ($this->recur_schedule) {
// Weekly
case 0: $date = $this->product->price_recur_strict
? $this->getInvoiceNextAttribute()->endOfWeek()
: $this->getInvoiceNextAttribute()->addWeek()->subDay();
case Invoice::BILL_WEEKLY:
$date = $this->product->price_recur_strict
? $this->getInvoiceNextAttribute()->endOfWeek()
: $this->getInvoiceNextAttribute()->addWeek()->subDay();
break;
// Monthly
case 1:
case Invoice::BILL_MONTHLY:
$date = $this->product->price_recur_strict
? $this->getInvoiceNextAttribute()->endOfMonth()
: $this->getInvoiceNextAttribute()->addMonth()->subDay();
break;
// Quarterly
case 2:
case Invoice::BILL_QUARTERLY:
$date = $this->product->price_recur_strict
? $this->getInvoiceNextAttribute()->endOfQuarter()
: $this->getInvoiceNextAttribute()->addQuarter()->subDay();
break;
// Half Yearly
case 3:
case Invoice::BILL_SEMI_YEARLY:
$date = $this->product->price_recur_strict
? $this->getInvoiceNextAttribute()->endOfHalf()
: $this->getInvoiceNextAttribute()->addQuarter(2)->subDay();
break;
// Yearly
case 4:
case Invoice::BILL_YEARLY:
$date = $this->product->price_recur_strict
? $this->getInvoiceNextAttribute()->endOfYear()
: $this->getInvoiceNextAttribute()->addYear()->subDay();
break;
// Two Yearly
case 5:
if (! $this->product->price_recur_strict)
case Invoice::BILL_TWOYEARS:
if (! $this->product->price_recur_strict) {
$date = $this->getInvoiceNextAttribute()->addYear(2)->subDay();
else {
} else {
$date = $this->getInvoiceNextAttribute()->addYear(2)->subDay()->endOfYear();
if ($date->clone()->addDay()->year % 2) {
if ($date->clone()->addDay()->year%2)
$date = $date->subYear();
}
}
break;
// Three Yearly
// NOTE: price_recur_strict ignored
case 6: $date = $this->getInvoiceNextAttribute()->addYear(3)->subDay(); break;
case Invoice::BILL_THREEYEARS:
$date = $this->getInvoiceNextAttribute()->addYear(3)->subDay();
break;
default: throw new Exception('Unknown recur_schedule');
// NOTE: price_recur_strict ignored
case Invoice::BILL_FOURYEARS:
$date = $this->getInvoiceNextAttribute()->addYear(4)->subDay();
break;
// NOTE: price_recur_strict ignored
case Invoice::BILL_FIVEYEARS:
$date = $this->getInvoiceNextAttribute()->addYear(5)->subDay();
break;
default:
throw new Exception('Unknown recur_schedule');
}
// If the invoice has an end date, our invoice period shouldnt be greater than that.
@ -616,7 +673,13 @@ class Service extends Model implements IDs
return $date;
}
public function getInvoiceNextQuantityAttribute()
/**
* Determine how much quantity (at the charge rate) is requite for the next invoice
*
* @return float
* @throws Exception
*/
public function getInvoiceNextQuantityAttribute(): float
{
// If we are not rounding to the first day of the cycle, then it is always a full cycle
if (! $this->product->price_recur_strict)
@ -625,42 +688,44 @@ class Service extends Model implements IDs
$n = $this->invoice_next->diff($this->invoice_next_end)->days+1;
switch ($this->recur_schedule) {
// Weekly
case 0:
case Invoice::BILL_WEEKLY:
$d = $this->invoice_next->addWeek()->startOfWeek()->diff($this->invoice_next_end->startOfWeek())->days;
break;
// Monthly
case 1:
case Invoice::BILL_MONTHLY:
$d = $this->invoice_next->addMonth()->startOfMonth()->diff($this->invoice_next_end->startOfMonth())->days;
break;
// Quarterly
case 2:
case Invoice::BILL_QUARTERLY:
$d = $this->invoice_next->addQuarter()->startOfQuarter()->diff($this->invoice_next_end->startOfQuarter())->days;
break;
// Half Yearly
case 3:
case Invoice::BILL_SEMI_YEARLY:
$d = $this->invoice_next->addQuarter(2)->startOfHalf()->diff($this->invoice_next_end->startOfHalf())->days;
break;
// Yearly
case 4:
case Invoice::BILL_YEARLY:
$d = $this->invoice_next->addYear()->startOfYear()->diff($this->invoice_next_end->startOfYear())->days;
break;
// Two Yearly
case 5:
case Invoice::BILL_TWOYEARS:
$d = $this->invoice_next->addYear(2)->startOfYear()->diff($this->invoice_next_end->subyear(2))->days-1;
break;
// Three Yearly
case 6:
case Invoice::BILL_THREEYEARS:
$d = $this->invoice_next->addYear(3)->startOfYear()->diff($this->invoice_next_end->subyear(3))->days-1;
break;
default: throw new Exception('Unknown recur_schedule');
case Invoice::BILL_FOURYEARS:
$d = $this->invoice_next->addYear(3)->startOfYear()->diff($this->invoice_next_end->subyear(4))->days-1;
break;
case Invoice::BILL_FIVEYEARS:
$d = $this->invoice_next->addYear(3)->startOfYear()->diff($this->invoice_next_end->subyear(5))->days-1;
break;
default:
throw new Exception('Unknown recur_schedule');
}
return round($n/$d,2);
@ -669,7 +734,7 @@ class Service extends Model implements IDs
/**
* Get the date that the service has been invoiced to
*/
public function getInvoiceToAttribute()
public function getInvoiceToAttribute(): ?\Carbon\Carbon
{
$result = ($x=$this->invoice_items->filter(function($item) { return $item->item_type === 0;}))->count()
? $x->last()->date_stop
@ -684,15 +749,10 @@ class Service extends Model implements IDs
}
/**
* Service Local ID
* The full name for a service, comprised of the short name and the description
*
* @return string
*/
public function getLIDattribute(): string
{
return sprintf('%05s',$this->id);
}
public function getNameAttribute(): string
{
return $this->getNameShortAttribute().(($x=$this->getNameDetailAttribute()) ? ': '.$x : '');
@ -707,27 +767,28 @@ class Service extends Model implements IDs
*/
public function getNameShortAttribute()
{
return $this->type ? $this->type->service_name : $this->id;
}
public function getNameDetailAttribute()
{
return $this->type ? $this->type->service_address : $this->id;
return $this->type->getServiceNameAttribute() ?: 'SID:'.$this->sid;
}
/**
* @deprecated see getInvoiceNextAttribute()
* Return the service description.
* For:
* + Broadband, this is the service address
* + Domains, blank
* + Hosting, blank
* + SSL, blank
*
* @return string
*/
public function getNextInvoiceAttribute()
public function getNameDetailAttribute()
{
return $this->getInvoiceNextAttribute();
return $this->type->getServiceDescriptionAttribute();
}
/**
* The product we supply for this service
*
* @return Model
* @todo Remove all references to product->type to use this method
*/
public function getOfferingAttribute(): Model
{
@ -746,130 +807,31 @@ class Service extends Model implements IDs
/**
* Work out when this service has been paid to.
*
* @todo This might need to be optimised
*/
public function getPaidToAttribute()
public function getPaidToAttribute(): Carbon
{
foreach ($this->invoices->reverse() as $o) {
if ($o->due == 0) {
return $o->items
->filter(function($item) {
return $item->item_type === 0;
})
->last()
->date_stop;
}
}
foreach ($this->invoices->reverse() as $o)
if ($o->due == 0)
break;
return $o->items
->filter(function($item) {
return $item->item_type === 0;
})
->last()
->date_stop;
}
/**
* Get the Product's Category for this service
* Return the billing recurring configuration for this service
*
* @deprecated use product->getProductTypeAttribute() directly
* @param $value
* @return int
*/
public function getProductCategoryAttribute(): string
{
return $this->product->getProductTypeAttribute();
}
/**
* Get the Product's Short Name for the service
*
* @return string
* @deprecated use product->name directly
*/
public function getProductNameAttribute(): string
{
return $this->product->getNameAttribute();
}
public function getRecurScheduleAttribute($value): int
{
// If recur_schedule not set, default to 2
return $value ?? 2;
}
/**
* @deprecated see getSIDAttribute()
*/
public function getServiceIdAttribute(): string
{
return $this->getSIDAttribute();
}
/**
* @deprecated see getUrlUserAttribute()
*/
public function getServiceIdUrlAttribute()
{
return $this->getUrlUserAttribute();
}
/**
* @deprecated see getServiceIdAttribute()
*/
public function getServiceNumberAttribute()
{
return $this->getSIDAttribute();
}
/**
* Services System ID
*
* @return string
*/
public function getSIDAttribute(): string
{
return sprintf('%02s-%04s.%s',$this->site_id,$this->account_id,$this->getLIDattribute());
}
/**
* Return the service description.
* For:
* + Broadband, this is the service address
* + Domains, blank
* + Hosting, blank
* + SSL, blank
*
* @return string
*/
public function getSDescAttribute(): string
{
return ($this->type AND $this->type->service_description)
? $this->type->service_description
: 'Service Description NOT Defined for :'.($this->type ? $this->type->type : $this->id);
}
/**
* 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
*
* @return string
*/
public function getSNameAttribute(): string
{
return ($this->type AND $this->type->service_name)
? $this->type->service_name
: 'Service Name NOT Defined for :'.($this->type ? $this->type->type : $this->id);
}
/**
* Return the service product type
* This is used for view specific details
*
* @return string
* @todo I think this can be removed - and dynamically determined
*/
public function getSTypeAttribute(): string
{
switch($this->product->model) {
default: return $this->type->type;
}
// If recur_schedule not set, default to quarterly
return $value ?? Invoice::BILL_QUARTERLY;
}
/**
@ -886,21 +848,10 @@ class Service extends Model implements IDs
}
/**
* Return the detailed order Status, with order reference numbers.
*
* @return string
*/
public function getStatusDetailAttribute(): string
{
return in_array($this->order_status,['ORDER-SENT','ORDER-HOLD','ORDERED'])
? sprintf('%s: <span class="white-space: nowrap"><small><b>#%s</b></small></span>',$this->order_status,Arr::get($this->order_info,'order_reference','Unknown'))
: '';
}
/**
* Return a HTML status box
* Return an HTML status box
*
* @return string
* @todo Add in the other status'
*/
public function getStatusHTMLAttribute(): string
{
@ -925,60 +876,15 @@ class Service extends Model implements IDs
: $this->status;
}
/**
* Return the type of service is provided.
* Return the product that supplies this service
* ie: product/*
*
* @return string
* @return Model
*/
public function getServiceTypeAttribute(): string
public function getSuppliedAttribute(): Model
{
// @todo This is temporary, while we clean the database.
return ($this->product->type && $this->product->type->supplied) ? $this->product->type->supplied->getTypeAttribute() : '** TBA **';
}
/**
* Get the service providers offering that we are providing for this service
*
* @return Model|null
*/
public function getSupplierProductAttribute(): ?Model
{
dd($this->product,$this->product->type,$this->product->type->supplied);
}
/**
* URL used by an admin to administer the record
*
* @return string
*/
public function getUrlAdminAttribute(): string
{
return sprintf('<a href="/a/service/%s">%s</a>',$this->id,$this->service_id);
}
/**
* URL used by an user to see the record
*
* @return string
*/
public function getUrlUserAttribute(): string
{
return sprintf('<a href="/u/service/%s">%s</a>',$this->id,$this->service_id);
}
/* SETTERS */
// @todo is this required?
public function setDateOrigAttribute($value)
{
$this->attributes['date_orig'] = $value->timestamp;
}
// @todo is this required?
public function setDateLastAttribute($value)
{
$this->attributes['date_last'] = $value->timestamp;
return $this->getOfferingAttribute()->supplied;
}
/* METHODS */
@ -1114,6 +1020,19 @@ class Service extends Model implements IDs
: collect();
}
/**
* Add applicable tax to the cost
*
* @todo This needs to be calculated, not fixed at 1.1
* @todo move all tax calculations into product
* @param float $value
* @return float
*/
private function addTax(float $value): float
{
return round($value*1.1,2);
}
private function getOrderInfoValue(string $key): ?string
{
return $this->order_info ? $this->order_info->get($key) : NULL;
@ -1160,27 +1079,6 @@ class Service extends Model implements IDs
return collect($result);
}
/**
* Add applicable tax to the cost
*
* @todo This needs to be calculated, not fixed at 1.1
* @param float $value
* @return float
*/
private function addTax(float $value): float
{
return round($value*1.1,2);
}
public function invoices_due(): DatabaseCollection
{
$this->load('invoice_items.invoice');
return $this->invoice_items->filter(function($item) {
return $item->invoice->due > 0;
});
}
/**
* Does this service have traffic data to be graphed
*
@ -1207,6 +1105,7 @@ class Service extends Model implements IDs
*
* @param string $role
* @return bool
* @todo Can we use the gates to achieve this?
*/
public function isAuthorised(string $role): bool
{
@ -1263,17 +1162,16 @@ class Service extends Model implements IDs
/**
* Should this service be invoiced soon
*
* @todo get the number of days from account setup
* @todo Use self::isBilled();
* @param int $days
* @return bool
*/
public function isInvoiceDueSoon($days=30): bool
{
return (! $this->external_billing) AND (! $this->suspend_billing) AND $this->getInvoiceNextAttribute()->lessThan(now()->addDays($days));
return $this->isBilled() AND $this->getInvoiceNextAttribute()->lessThan(now()->addDays($days));
}
/**
* Identify if a service is being ordered
* Identify if a service is being ordered, ie: not active yet nor cancelled
*
* @return bool
*/
@ -1288,14 +1186,14 @@ class Service extends Model implements IDs
* 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)
* @param Carbon|null $billdate
* @return Collection
* @throws Exception
* @todo Use self::isBilled();
* @todo This query is expensive.
*/
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->isBilled()) OR (! $future AND ! $this->active))
return collect();
if (is_null($billdate))
@ -1378,43 +1276,6 @@ class Service extends Model implements IDs
return $this->invoice_items->filter(function($item) { return ! $item->exists; });
}
/**
* This function will return the associated service model for the product type
* @deprecated use $this->type
*/
private function ServicePlugin()
{
abort(500,'deprecated');
// @todo: All services should be linked to a product. This might require data cleaning for old services not linked to a product.
if (! is_object($this->product))
return NULL;
switch ($this->product->prod_plugin_file)
{
case 'BROADBAND': return $this->service_broadband;
case 'DOMAIN': return $this->service_domain;
case 'HOST': return $this->service_host;
case 'SSL': return $this->service_ssl;
case 'PHONE': return $this->service_voip;
default: return NULL;
}
}
/**
* Store order info details
*
* @param string $key
* @param string $value
*/
public function setOrderInfo(string $key,?string $value): void
{
$x = is_null($this->order_info) ? collect() : $this->order_info;
$x->put($key,$value);
$this->order_info = $x;
}
/**
* Service that was cancelled or never provisioned
*

View File

@ -5,14 +5,14 @@ Please order the following...
| Service | Details |
| :---------- | :---------------- |
| Logged User | {{ Auth::user()->id }} |
| Account | {{ $service->account_name }} |
| Account | {{ $service->account->name }} |
| Service ID | {{ $service->sid }} |
| Product | {{ $service->product_name }} |
@switch($service->product_category)
@case('BROADBAND')
| Product | {{ $service->product->name }} |
@switch($service->category)
@case('Broadband')
| Address | {{ $service->type->service_address }} |
@break;
@case('PHONE')
@case('Phone')
| Number | {{ $service->type->service_number }} |
| Supplier Details | {{ $service->order_info->join(':') }} |
@break;

View File

@ -6,9 +6,9 @@
@component('mail::table')
| Service | Details |
| :---------- | :---------------- |
| Account | {{ $service->account_name }} |
| Account | {{ $service->account->name }} |
| Service ID | {{ $service->sid }} |
| Product | {{ $service->product_name }} |
| Product | {{ $service->product->name }} |
@switch($service->category)
@case('BROADBAND')
| Address | {{ is_object($service->type) ? $service->type->service_address : 'Not Supplied' }} |

View File

@ -5,14 +5,14 @@ Please cancel the following...
| Service | Details |
| :---------- | :---------------- |
| Logged User | {{ Auth::user()->id }} |
| Account | {{ $service->account_name }} |
| Account | {{ $service->account->name }} |
| Service ID | {{ $service->sid }} |
| Product | {{ $service->product_name }} |
@switch($service->product_category)
@case('BROADBAND')
| Product | {{ $service->product->name }} |
@switch($service->category)
@case('Broadband')
| Address | {{ $service->type->service_address }} |
@break;
@case('PHONE')
@case('Phone')
| Number | {{ $service->type->service_number }} |
| Supplier Details | {{ $service->order_info->join(':') }} |
@break;

View File

@ -5,14 +5,14 @@ Please change the following...
| Service | Details |
| :---------- | :---------------- |
| Logged User | {{ Auth::user()->id }}
| Account | {{ $service->account_name }} |
| Account | {{ $service->account->name }} |
| Service ID | {{ $service->sid }} |
| Product | {{ $service->product_name }} |
@switch($service->product_category)
@case('BROADBAND')
| Product | {{ $service->product->name }} |
@switch($service->category)
@case('Broadband')
| Address | {{ $service->type->service_address }} |
@break;
@case('PHONE')
@case('Phone')
| Number | {{ $service->type->service_number }} |
| Supplier Details | {{ $service->order_info->join(':') }} |
@break;

View File

@ -5,7 +5,7 @@
<form class="g-0 needs-validation" method="POST" action="{{ url('a/service/edit',[$o->id]) }}">
@csrf
@includeIf('a.service.widgets.'.$o->stype.'.update',['o'=>$o->type])
@includeIf('a.service.widgets.'.$o->type->type.'.update',['o'=>$o->type])
<div class="row">
<div class="col-12">

View File

@ -1,38 +0,0 @@
<div class="card card-primary card-outline">
<div class="card-header">
<strong>Service Information</strong>
</div>
<div class="card-body">
<table class="table table-borderless">
<tr>
<th>Account</th>
<td>{{ $o->account->name }}</td>
</tr>
<tr>
<th>Active</th>
<td>{!! $o->status_html !!}</td>
</tr>
<tr>
<th>Billing Period</th>
<td>{{ $o->billing_period }}</td>
</tr>
<tr>
<th>Billing Amount</th>
<td>${{ number_format($o->billing_price,2) }}</td>
</tr>
<tr>
<th>Invoiced To</th>
<td>{{ $o->invoice_to ? $o->invoice_to->format('Y-m-d') : '' }}</td>
</tr>
<tr>
<th>Next Invoice</th>
<td>{{ $o->invoice_next ? $o->invoice_next->format('Y-m-d') : '' }}</td>
</tr>
<tr>
<th>Current Invoices Due</th>
<td>${{ number_format($o->invoices_due()->sum('due'),2) }} <small>({{ $o->invoices_due()->count() }})</small></td>
</tr>
</table>
</div>
</div>

View File

@ -41,7 +41,7 @@
<td><a href="{{ url('u/service',[$oo->service_id]) }}">{{ $oo->service->sid }}</td>
<td>{{ $oo->service->account->name }}</td>
<td>{{ $oo->service->product->name }}</td>
<td>{{ $oo->service_name }}</td>
<td>{{ $oo->service->name }}</td>
<td>{{ $oo->service_expire ? $oo->service_expire->format('Y-m-d') : '-' }}</td>
<td>{{ $oo->registrar->name }}</td>
<td>{{ $oo->registrar_ns }}</td>

View File

@ -43,7 +43,7 @@
<td><a href="{{ url('u/service',[$oo->service_id]) }}">{{ $oo->service->sid }}</td>
<td>{{ $oo->service->account->name }}</td>
<td>{{ $oo->service->product->name }}</td>
<td>{{ $oo->service_name }}</td>
<td>{{ $oo->service->name }}</td>
<td>{{ $oo->service_expire ? $oo->service_expire->format('Y-m-d') : '-' }}</td>
<td>{{ $oo->service->product->supplier->name }}</td>
<td>{{ $oo->admin_url }}</td>

View File

@ -40,7 +40,7 @@
<td><a href="{{ url('u/service',[$oo->service_id]) }}">{{ $oo->service->sid }}</td>
<td>{{ $oo->service->account->name }}</td>
<td>{{ $oo->service->product->name }}</td>
<td>{{ $oo->service_name }}</td>
<td>{{ $oo->service->name }}</td>
<td>{{ $oo->service_expire ? $oo->service_expire->format('Y-m-d') : '-' }}</td>
<td>{{ $oo->service->product->supplier->name }}</td>
<td>@if ($oo->service->isBilled()) <span class="@if($oo->service->suspend_billing)strike @endif">{{ $oo->service->invoice_next->format('Y-m-d') }}</span> @else - @endif</td>

View File

@ -11,7 +11,7 @@
Service: {{ $o->sid }} <strong>{{ $o->product->name }}</strong>
@endsection
@section('contentheader_description')
{{ $o->sname }}: {{ $o->sdesc }}
{{ $o->name }}
@endsection
@section('main-content')
@ -38,7 +38,7 @@
</div>
</div>
@includeIf('u.service.widgets.'.$o->stype.'.order',['o'=>$o->type])
@includeIf('u.service.widgets.'.$o->type->type.'.order',['o'=>$o->type])
<div class="form-group row">
<label for="notes" class="col-sm-2 col-form-label text-right">Notes</label>

View File

@ -11,7 +11,7 @@
Service: {{ $o->sid }} <strong>{{ $o->product->name }}</strong>
@endsection
@section('contentheader_description')
{{ $o->sname }}: {{ $o->sdesc }}
{{ $o->name }}
@endsection
@section('main-content')
@ -38,7 +38,7 @@
</div>
</div>
@includeIf('u.service.widgets.'.$o->stype.'.order',['o'=>$o->type])
@includeIf('u.service.widgets.'.$o->type->type.'.order',['o'=>$o->type])
<div class="form-group row">
<label for="notes" class="col-sm-2 col-form-label text-right">Notes</label>

View File

@ -13,7 +13,7 @@
@foreach ($oo->groupBy('service_id') as $ooo)
<tr>
<td class="pt-0 pb-1" style="width: 12em;"><a href="{{ url('u/service',$ooo->first()->service_id) }}">{{ $ooo->first()->service->sid }}</a></td>
<td class="pt-0 pb-1" colspan="3">{{ $ooo->first()->service->sname }}: {{ $ooo->first()->service->sdesc }}</td>
<td class="pt-0 pb-1" colspan="3">{{ $ooo->first()->service->name }}</td>
</tr>
@foreach ($ooo as $io)

View File

@ -11,7 +11,7 @@
Service: {{ $o->sid }} <strong>{{ $o->product->name }}</strong>
@endsection
@section('contentheader_description')
{{ $o->sname }}: {{ $o->sdesc }}
{{ $o->name }}
@endsection
@section('main-content')
@ -44,7 +44,7 @@
</div>
{{--
@includeIf('u.service.widgets.'.$o->stype.'.order',['o'=>$o->type])
@includeIf('u.service.widgets.'.$o->type->type.'.order',['o'=>$o->type])
--}}
<div class="form-group row">

View File

@ -11,7 +11,7 @@
Service: {{ $o->sid }} <strong>{{ $o->product->name }}</strong>
@endsection
@section('contentheader_description')
{{ $o->sname }}: {{ $o->sdesc }}
{{ $o->name }}
@endsection
@section('main-content')
@ -43,7 +43,7 @@
</div>
</div>
@includeIf('u.service.widgets.'.$o->stype.'.change',['o'=>$o->type])
@includeIf('u.service.widgets.'.$o->type->type.'.change',['o'=>$o->type])
<div class="form-group row">
<label for="notes" class="col-2 col-form-label text-right">Notes</label>

View File

@ -11,14 +11,15 @@
Service: {{ $o->sid }} <strong>{{ $o->product->name }}</strong>
@endsection
@section('contentheader_description')
{{ $o->sname }}: {{ $o->sdesc }}
{{ $o->name }}
@endsection
@section('main-content')
<div class="row">
<!-- Service Details -->
<div class="col-5">
@includeIf('u.service.widgets.'.$o->stype.'.details',['o'=>$o->type])
@includeIf('u.service.widgets.'.$o->type->type.'.details',['o'=>$o->type])
@include('u.service.widgets.information')
</div>
@ -77,7 +78,7 @@
@if ($o->hasUsage())
<div class="tab-pane fade {{ (! $o->isBilled() && (! session()->has('service_update'))) ? 'active show' : '' }}" id="traffic" role="tabpanel">
@if ($o->type->usage(30)->count())
@include('u.service.widgets.'.$o->stype.'.usagegraph',['o'=>$o->type])
@include('u.service.widgets.'.$o->type->type.'.usagegraph',['o'=>$o->type])
@endif
</div>
@endif

View File

@ -22,10 +22,10 @@
@foreach ($o->services as $oo)
<tr>
<td><a href="{{ url('u/service',[$oo->id]) }}">{{ $oo->sid }}</a></td>
<td>{{ $oo->service_type }}</td>
<td>{{ $oo->category }}</td>
<td>{{ $oo->name_short }}</td>
<td>{{ $oo->product->name }}</td>
<td>{{ $oo->external_billing ? '-' : $oo->next_invoice->format('Y-m-d') }}</td>
<td>{{ $oo->external_billing ? '-' : $oo->invoice_next->format('Y-m-d') }}</td>
</tr>
@endforeach
</tbody>

View File

@ -16,11 +16,11 @@
<table class="table table-sm">
<tr>
<th>Address</th>
<td>{{ $o->service_description }}</td>
<td>{{ $o->service_address }}</td>
</tr>
<tr>
<th>Service Number</th>
<td>{{ $o->service_name }}</td>
<td>{{ $o->service_number }}</td>
</tr>
<tr>
<th>Service Username</th>

View File

@ -16,7 +16,7 @@
<table class="table table-sm">
<tr>
<th>Domain Name</th>
<td>{{ $o->service_name }}</td>
<td>{{ $o->service->name }}</td>
</tr>
<tr>
<th>Registrar URL</th>

View File

@ -16,7 +16,7 @@
<table class="table table-sm">
<tr>
<th>Domain Name</th>
<td>{{ $o->service_name }}</td>
<td>{{ $o->service->name }}</td>
</tr>
@if($o->service_connect_date)
<tr>

View File

@ -16,7 +16,7 @@
<table class="table table-sm">
<tr>
<th>Domain Name</th>
<td>{{ $o->service_name }}</td>
<td>{{ $o->service->name }}</td>
</tr>
@if($o->provider->whitelabel_url)
<tr>

View File

@ -67,7 +67,7 @@
</tr>
<tr>
<th>Payment Method</th>
<td>@if ($o->autopay)Direct Debit @else Invoice @endif</td>
<td>@if ($o->billing)Direct Debit @else Invoice @endif</td>
</tr>
@elseif($o->wasCancelled())

View File

@ -16,11 +16,11 @@
<table class="table table-sm">
<tr>
<th>Address</th>
<td>{{ $o->service_description }}</td>
<td>{{ $o->service_address }}</td>
</tr>
<tr>
<th>Service Number</th>
<td>{{ $o->service_name }}</td>
<td>{{ $o->service_number }}</td>
</tr>
<tr>
<th>Service Username</th>

View File

@ -15,7 +15,7 @@
<table class="table table-sm">
<tr>
<th>Cert</th>
<td>{{ $o->service_description }}</td>
<td>{{ $o->name_detail }}</td>
</tr>
<tr>
<th>Cancel Notice</th>