Work on Service rendering
This commit is contained in:
@@ -3,10 +3,11 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
use Barryvdh\Snappy\Facades\SnappyPdf as PDF;
|
||||
|
||||
use App\Models\{Invoice,Service};
|
||||
use App\User;
|
||||
use PDF;
|
||||
|
||||
class UserHomeController extends Controller
|
||||
{
|
||||
@@ -15,7 +16,12 @@ class UserHomeController extends Controller
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
public function home()
|
||||
/**
|
||||
* Logged in users home page
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function home(): View
|
||||
{
|
||||
switch (Auth::user()->role()) {
|
||||
case 'customer':
|
||||
@@ -32,11 +38,23 @@ class UserHomeController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function invoice(Invoice $o)
|
||||
/**
|
||||
* Render a specific invoice for the user
|
||||
*
|
||||
* @param Invoice $o
|
||||
* @return View
|
||||
*/
|
||||
public function invoice(Invoice $o): View
|
||||
{
|
||||
return View('u.invoice',['o'=>$o]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the invoice in PDF format, ready to download
|
||||
*
|
||||
* @param Invoice $o
|
||||
* @return mixed
|
||||
*/
|
||||
public function invoice_pdf(Invoice $o)
|
||||
{
|
||||
return PDF::loadView('u.invoice', ['o'=>$o])->stream(sprintf('%s.pdf',$o->invoice_account_id));
|
||||
@@ -56,8 +74,15 @@ class UserHomeController extends Controller
|
||||
abort(307,sprintf('http://www.graytech.net.au/u/%s/%s/%s',$type,$action,$id));
|
||||
}
|
||||
|
||||
public function service(Service $o)
|
||||
/**
|
||||
* Return details on the users service
|
||||
*
|
||||
* @param Service $o
|
||||
* @return View
|
||||
*/
|
||||
public function service(Service $o): View
|
||||
{
|
||||
return View('u.service',['o'=>$o]);
|
||||
foreach ([
|
||||
sprintf('u.service.%s.%s',$o->type->type,$o->status),
|
||||
sprintf('u.service.%s',$o->status),
|
||||
|
20
app/Interfaces/ServiceItem.php
Normal file
20
app/Interfaces/ServiceItem.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Interfaces;
|
||||
|
||||
interface ServiceItem
|
||||
{
|
||||
/**
|
||||
* Return the Service Description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceDescriptionAttribute():string;
|
||||
|
||||
/**
|
||||
* Return the Service Name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceNameAttribute():string;
|
||||
}
|
@@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use App\Traits\OrderServiceOptions;
|
||||
|
||||
class AccoutBilling extends Model
|
||||
class AccountBilling extends Model
|
||||
{
|
||||
protected $table = 'ab_account_billing';
|
||||
public $timestamps = FALSE;
|
@@ -4,6 +4,10 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
use App\Traits\NextKey;
|
||||
@@ -11,17 +15,18 @@ use App\Traits\NextKey;
|
||||
class Service extends Model
|
||||
{
|
||||
use NextKey;
|
||||
|
||||
const RECORD_ID = 'service';
|
||||
public $incrementing = FALSE;
|
||||
|
||||
const CREATED_AT = 'date_orig';
|
||||
const UPDATED_AT = 'date_last';
|
||||
public $incrementing = FALSE;
|
||||
|
||||
protected $table = 'ab_service';
|
||||
protected $dates = ['date_last_invoice','date_next_invoice'];
|
||||
protected $dates = [
|
||||
'date_last_invoice',
|
||||
'date_next_invoice'
|
||||
];
|
||||
public $dateFormat = 'U';
|
||||
protected $with = ['product.descriptions','account.language','type'];
|
||||
protected $table = 'ab_service';
|
||||
|
||||
protected $casts = [
|
||||
'order_info'=>'array',
|
||||
@@ -91,17 +96,27 @@ class Service extends Model
|
||||
/**
|
||||
* Account the service belongs to
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function account()
|
||||
{
|
||||
return $this->belongsTo(Account::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return automatic billing details
|
||||
*
|
||||
* @return HasOne
|
||||
*/
|
||||
public function billing()
|
||||
{
|
||||
return $this->hasOne(AccountBilling::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Charges associated with this Service
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
* @return HasMany
|
||||
*/
|
||||
public function charges()
|
||||
{
|
||||
@@ -146,10 +161,9 @@ class Service extends Model
|
||||
/**
|
||||
* Account that ordered the service
|
||||
*
|
||||
* @todo changed to orderedby
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function orderby()
|
||||
public function orderedby()
|
||||
{
|
||||
return $this->belongsTo(Account::class);
|
||||
}
|
||||
@@ -157,30 +171,23 @@ class Service extends Model
|
||||
/**
|
||||
* Product of the service
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tenant that the service belongs to
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function site()
|
||||
{
|
||||
return $this->belongsTo(Site::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a child model with details of the service
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
||||
* @return MorphTo
|
||||
*/
|
||||
public function type()
|
||||
{
|
||||
if (! $this->model)
|
||||
abort(500,'Missing Model in',['service'=>$this]);
|
||||
|
||||
return $this->morphTo(null,'model','id','service_id');
|
||||
}
|
||||
|
||||
@@ -192,7 +199,8 @@ class Service extends Model
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where(function () use ($query) {
|
||||
$query->where('active',TRUE)->orWhereNotIn('order_status',$this->inactive_status);
|
||||
$query->where('active',TRUE)
|
||||
->orWhereNotIn('order_status',$this->inactive_status);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -205,7 +213,8 @@ class Service extends Model
|
||||
public function scopeInActive($query)
|
||||
{
|
||||
return $query->where(function () use ($query) {
|
||||
$query->where('active',FALSE)->orWhereIn('order_status',$this->inactive_status);
|
||||
$query->where('active',FALSE)
|
||||
->orWhereIn('order_status',$this->inactive_status);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -251,6 +260,16 @@ class Service extends Model
|
||||
return $this->getUrlAdminAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the auto billing details
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAutoPayAttribute()
|
||||
{
|
||||
return $this->billing;
|
||||
}
|
||||
|
||||
public function getBillingPriceAttribute(): float
|
||||
{
|
||||
// @todo Temporary for services that dont have recur_schedule set.
|
||||
@@ -337,6 +356,7 @@ class Service extends Model
|
||||
* EG:
|
||||
* For ADSL, this would be the phone number,
|
||||
* For Hosting, this would be the domain name, etc
|
||||
* @deprecated
|
||||
*/
|
||||
public function getNameShortAttribute()
|
||||
{
|
||||
@@ -372,6 +392,25 @@ class Service extends Model
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out when this service has been paid to.
|
||||
*
|
||||
* @todo This might need to be optimised
|
||||
*/
|
||||
public function getPaidToAttribute()
|
||||
{
|
||||
foreach ($this->invoices->reverse() as $o) {
|
||||
if ($o->due == 0) {
|
||||
return $o->items
|
||||
->filter(function($item) {
|
||||
return $item->item_type === 0;
|
||||
})
|
||||
->last()
|
||||
->date_stop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Product's Category for this service
|
||||
*
|
||||
@@ -392,9 +431,9 @@ class Service extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated see getServiceIdAttribute()
|
||||
* @deprecated see getSIDAttribute()
|
||||
*/
|
||||
public function getServiceIdAttribute()
|
||||
public function getServiceIdAttribute(): string
|
||||
{
|
||||
return $this->getSIDAttribute();
|
||||
}
|
||||
@@ -425,6 +464,50 @@ class Service extends Model
|
||||
return sprintf('%02s-%04s.%05s',$this->site_id,$this->account_id,$this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->service_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->service_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the service product type
|
||||
* This is used for view specific details
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSTypeAttribute(): string
|
||||
{
|
||||
switch($this->product->model) {
|
||||
case 'App\Models\Product\Adsl': return 'broadband';
|
||||
default: abort(500,'Product type not configured',['product'=>$this->product]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Service Status
|
||||
*
|
||||
@@ -545,6 +628,16 @@ class Service extends Model
|
||||
return (! $this->external_billing) AND (! $this->suspend_billing) AND $this->getInvoiceNextAttribute()->lessThan(now()->addDays($days));
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify if a service is being ordered
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPending(): bool
|
||||
{
|
||||
return ! $this->active AND ! in_array($this->order_status,$this->inactive_status);
|
||||
}
|
||||
|
||||
public function next_invoice_items(): \Illuminate\Support\Collection
|
||||
{
|
||||
$result = collect();
|
||||
|
@@ -2,17 +2,35 @@
|
||||
|
||||
namespace App\Models\Service;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
|
||||
use App\Interfaces\ServiceItem;
|
||||
use App\Models\Base\ServiceType;
|
||||
use App\Models\Service;
|
||||
use App\Traits\NextKey;
|
||||
|
||||
class Adsl extends \App\Models\Base\ServiceType
|
||||
class Adsl extends ServiceType implements ServiceItem
|
||||
{
|
||||
use NextKey;
|
||||
|
||||
const RECORD_ID = 'service__adsl';
|
||||
|
||||
// @todo column service_id can be removed.
|
||||
protected $table = 'ab_service__adsl';
|
||||
protected $dates = ['service_connect_date','service_contract_date'];
|
||||
protected $dates = [
|
||||
'service_connect_date',
|
||||
'service_contract_date'
|
||||
];
|
||||
|
||||
/**
|
||||
* The service this belongs to
|
||||
*
|
||||
* @return BelongsTo|MorphOne
|
||||
*/
|
||||
public function service()
|
||||
{
|
||||
return $this->belongsTo(Service::class);
|
||||
}
|
||||
|
||||
/** SCOPES */
|
||||
|
||||
@@ -35,22 +53,41 @@ class Adsl extends \App\Models\Base\ServiceType
|
||||
/** ATTRIBUTES **/
|
||||
|
||||
/**
|
||||
* @deprecated use getNameFullAttribute()
|
||||
* @deprecated use $o->type()->service_name;
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function getFullNameAttribute()
|
||||
{
|
||||
return $this->getNameFullAttribute();
|
||||
}
|
||||
|
||||
public function getNameAttribute()
|
||||
{
|
||||
return $this->service_number ?: $this->service_address;
|
||||
}
|
||||
|
||||
public function getNameFullAttribute()
|
||||
/**
|
||||
* Return the service address
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceDescriptionAttribute(): string
|
||||
{
|
||||
return ($this->service_number AND $this->service_address)
|
||||
? sprintf('%s: %s',$this->service_number, $this->service_address)
|
||||
: $this->name;
|
||||
return $this->service_address ?: 'NO Service Address';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the service number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getServiceNameAttribute(): string
|
||||
{
|
||||
return $this->service_number ?: 'NO Service Number';
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this service currently in a contract
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function inContract(): bool
|
||||
{
|
||||
return $this->service_contract_date AND $this->service_contract_date->addMonths($this->contract_term)->isFuture();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user