Cleanup usage of Leenooks\Carbon, change ServiceType to be consistent with Products/ Suppliers/
This commit is contained in:
parent
8ed9e38290
commit
a16277d9bb
@ -35,7 +35,7 @@ class SearchController extends Controller
|
||||
->orderBy('firstname')
|
||||
->limit(10)->get() as $o)
|
||||
{
|
||||
$result->push(['name'=>sprintf('%s (%s)',$o->lid,$o->name),'value'=>'/u/home/'.$o->id,'category'=>'Users']);
|
||||
$result->push(['name'=>sprintf('%s (%s)',$o->name,$o->lid),'value'=>'/u/home/'.$o->id,'category'=>'Users']);
|
||||
}
|
||||
|
||||
# Look for Account
|
||||
@ -44,7 +44,7 @@ class SearchController extends Controller
|
||||
->orderBy('company')
|
||||
->limit(10)->get() as $o)
|
||||
{
|
||||
$result->push(['name'=>sprintf('%s (%s)',$o->lid,$o->company),'value'=>'/u/home/'.$o->user_id,'category'=>'Accounts']);
|
||||
$result->push(['name'=>sprintf('%s (%s)',$o->company,$o->lid),'value'=>'/u/home/'.$o->user_id,'category'=>'Accounts']);
|
||||
}
|
||||
|
||||
# Look for a Service
|
||||
|
@ -5,10 +5,10 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use Leenooks\Carbon;
|
||||
|
||||
use App\Traits\NextKey;
|
||||
use App\Traits\PushNew;
|
||||
use Leenooks\Carbon;
|
||||
|
||||
/**
|
||||
* Class Invoice Items
|
||||
@ -85,8 +85,6 @@ class InvoiceItem extends Model
|
||||
/**
|
||||
* Start date for the invoice item line
|
||||
*
|
||||
* We need cast this value to a Leenooks\Carbon for access to startOfHalf() endOfHalf() methods
|
||||
*
|
||||
* @param $value
|
||||
* @return Carbon
|
||||
* @throws \Exception
|
||||
@ -100,8 +98,6 @@ class InvoiceItem extends Model
|
||||
/**
|
||||
* End date for the invoice item line
|
||||
*
|
||||
* We need cast this value to a Leenooks\Carbon for access to startOfHalf() endOfHalf() methods
|
||||
*
|
||||
* @param $value
|
||||
* @return Carbon
|
||||
* @throws \Exception
|
||||
|
@ -6,11 +6,9 @@ use Illuminate\Support\Collection;
|
||||
use Leenooks\Traits\ScopeActive;
|
||||
|
||||
use App\Interfaces\ProductItem;
|
||||
use App\Models\Supplier;
|
||||
use App\Models\Service\Broadband as ServiceBroadband;
|
||||
use App\Models\Supplier\Broadband as SupplierBroadband;
|
||||
|
||||
// @todo does this need to extend Type? Perhaps have a ProductType consistent with ServiceType.
|
||||
final class Broadband extends Type implements ProductItem
|
||||
{
|
||||
use ScopeActive;
|
||||
@ -61,7 +59,7 @@ final class Broadband extends Type implements ProductItem
|
||||
{
|
||||
$config = collect();
|
||||
|
||||
foreach (array_keys(Supplier\Broadband::traffic_map) as $k => $v) {
|
||||
foreach (array_keys(SupplierBroadband::traffic_map) as $k => $v) {
|
||||
// Base Config
|
||||
$config->put($k,$this->{$k});
|
||||
// Excess Config
|
||||
@ -90,7 +88,7 @@ final class Broadband extends Type implements ProductItem
|
||||
{
|
||||
$result = 0;
|
||||
foreach ($this->supplied->allowance(NULL,$this->allowance([])->toArray()) as $k=>$v) {
|
||||
$result += -$v*$this->supplied->{Supplier\Broadband::traffic_map[$k]};
|
||||
$result += -$v*$this->supplied->{SupplierBroadband::traffic_map[$k]};
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ProductType extends Model
|
||||
{
|
||||
//
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Casts\AsCollection;
|
||||
use Illuminate\Database\Eloquent\Collection as DatabaseCollection;
|
||||
@ -14,8 +15,8 @@ use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Leenooks\Carbon;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Leenooks\Carbon as LeenooksCarbon;
|
||||
|
||||
use App\Interfaces\IDs;
|
||||
use App\Traits\ScopeServiceUserAuthorised;
|
||||
@ -539,7 +540,7 @@ class Service extends Model implements IDs
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getContractEndAttribute(): ?\Carbon\Carbon
|
||||
public function getContractEndAttribute(): ?Carbon
|
||||
{
|
||||
// If we have no start date or expire date, then NULL;
|
||||
if (! $this->start_at && ! $this->type->expire_at)
|
||||
@ -585,15 +586,14 @@ class Service extends Model implements IDs
|
||||
/**
|
||||
* Return the date for the next invoice
|
||||
*
|
||||
* @return Carbon|string
|
||||
* @return LeenooksCarbon
|
||||
*/
|
||||
public function getInvoiceNextAttribute(): \Carbon\Carbon
|
||||
public function getInvoiceNextAttribute(): LeenooksCarbon
|
||||
{
|
||||
$last = $this->getInvoiceToAttribute();
|
||||
return $last
|
||||
? $last->addDay()
|
||||
: ($this->date_next_invoice ? $this->date_next_invoice->clone()
|
||||
: ($this->start_at ?: Carbon::now()));
|
||||
: ($this->date_next_invoice ? $this->date_next_invoice->clone() : ($this->start_at ?: LeenooksCarbon::now()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -733,8 +733,10 @@ class Service extends Model implements IDs
|
||||
|
||||
/**
|
||||
* Get the date that the service has been invoiced to
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
public function getInvoiceToAttribute(): ?\Carbon\Carbon
|
||||
public function getInvoiceToAttribute(): ?Carbon
|
||||
{
|
||||
$result = ($x=$this->invoice_items->filter(function($item) { return $item->item_type === 0;}))->count()
|
||||
? $x->last()->date_stop
|
||||
@ -807,6 +809,8 @@ class Service extends Model implements IDs
|
||||
|
||||
/**
|
||||
* Work out when this service has been paid to.
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getPaidToAttribute(): Carbon
|
||||
{
|
||||
@ -834,6 +838,17 @@ class Service extends Model implements IDs
|
||||
return $value ?? Invoice::BILL_QUARTERLY;
|
||||
}
|
||||
|
||||
/**
|
||||
* We need to cast some dates to LeenooksCarbon to get access to startOfHalf()/endOfHalf() methods
|
||||
*
|
||||
* @param $value
|
||||
* @return LeenooksCarbon
|
||||
*/
|
||||
public function getStartAtAttribute($value): LeenooksCarbon
|
||||
{
|
||||
return LeenooksCarbon::create($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Service Status
|
||||
*
|
||||
|
@ -2,21 +2,20 @@
|
||||
|
||||
namespace App\Models\Service;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Leenooks\Carbon;
|
||||
|
||||
use App\Interfaces\ServiceUsage;
|
||||
use App\Models\Base\ServiceType;
|
||||
use App\Models\Supplier\Broadband as SupplierBroadband;
|
||||
use App\Models\Supplier\Type;
|
||||
use App\Models\Supplier\Type as SupplierType;
|
||||
use App\Models\Usage\Broadband as UsageBroadband;
|
||||
|
||||
/**
|
||||
* Class Broadband (Service)
|
||||
* Services that are Internet Broadband
|
||||
*/
|
||||
class Broadband extends ServiceType implements ServiceUsage
|
||||
class Broadband extends Type implements ServiceUsage
|
||||
{
|
||||
private const LOGKEY = 'MSB';
|
||||
|
||||
@ -105,9 +104,9 @@ class Broadband extends ServiceType implements ServiceUsage
|
||||
/**
|
||||
* Return the suppliers offering that this service is providing
|
||||
*
|
||||
* @return Type
|
||||
* @return SupplierType
|
||||
*/
|
||||
public function supplied(): Type
|
||||
public function supplied(): SupplierType
|
||||
{
|
||||
return $this->provided_adsl_plan_id
|
||||
? SupplierBroadband::findOrFail($this->provided_adsl_plan_id)
|
||||
|
@ -2,15 +2,14 @@
|
||||
|
||||
namespace App\Models\Service;
|
||||
|
||||
use App\Models\Base\ServiceType;
|
||||
use App\Traits\ServiceDomains;
|
||||
use App\Models\DomainRegistrar;
|
||||
use App\Traits\ServiceDomains;
|
||||
|
||||
/**
|
||||
* Class Domain (Service)
|
||||
* Services that are managed Domain Names
|
||||
*/
|
||||
class Domain extends ServiceType
|
||||
class Domain extends Type
|
||||
{
|
||||
use ServiceDomains;
|
||||
|
||||
|
@ -2,14 +2,13 @@
|
||||
|
||||
namespace App\Models\Service;
|
||||
|
||||
use App\Models\Base\ServiceType;
|
||||
use App\Traits\ServiceDomains;
|
||||
|
||||
/**
|
||||
* Class Email (Service)
|
||||
* Services that are Email Hosting
|
||||
*/
|
||||
class Email extends ServiceType
|
||||
class Email extends Type
|
||||
{
|
||||
use ServiceDomains;
|
||||
|
||||
|
@ -2,10 +2,8 @@
|
||||
|
||||
namespace App\Models\Service;
|
||||
|
||||
use App\Models\Base\ServiceType;
|
||||
|
||||
// @todo Document how this is used.
|
||||
class Generic extends ServiceType
|
||||
class Generic extends Type
|
||||
{
|
||||
protected $table = 'service__generic';
|
||||
public $timestamps = FALSE;
|
||||
|
@ -2,15 +2,14 @@
|
||||
|
||||
namespace App\Models\Service;
|
||||
|
||||
use App\Models\Base\ServiceType;
|
||||
use App\Traits\ServiceDomains;
|
||||
use App\Models\HostServer;
|
||||
use App\Traits\ServiceDomains;
|
||||
|
||||
/**
|
||||
* Class Host (Service)
|
||||
* Services that are Web Hosting
|
||||
*/
|
||||
class Host extends ServiceType
|
||||
class Host extends Type
|
||||
{
|
||||
use ServiceDomains;
|
||||
|
||||
|
@ -2,13 +2,11 @@
|
||||
|
||||
namespace App\Models\Service;
|
||||
|
||||
use App\Models\Base\ServiceType;
|
||||
|
||||
/**
|
||||
* Class Phone (Service)
|
||||
* Services that are Voice Telephony
|
||||
*/
|
||||
class Phone extends ServiceType
|
||||
class Phone extends Type
|
||||
{
|
||||
protected $dates = [
|
||||
'connect_at',
|
||||
|
@ -2,16 +2,14 @@
|
||||
|
||||
namespace App\Models\Service;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Carbon\Carbon;
|
||||
|
||||
use App\Models\Base\ServiceType;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
/**
|
||||
* Class SSL (Service)
|
||||
* Services that are provide an SSL Certificate
|
||||
*/
|
||||
class SSL extends ServiceType
|
||||
class SSL extends Type
|
||||
{
|
||||
protected $table = 'service_ssl';
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Base;
|
||||
namespace App\Models\Service;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use App\Interfaces\ServiceItem;
|
||||
use App\Models\{Account,Service};
|
||||
use App\Models\Supplier\Type;
|
||||
use App\Models\Supplier\Type as SupplierType;
|
||||
use App\Traits\{ScopeServiceActive,ScopeServiceUserAuthorised};
|
||||
|
||||
abstract class ServiceType extends Model implements ServiceItem
|
||||
abstract class Type extends Model implements ServiceItem
|
||||
{
|
||||
use ScopeServiceActive,ScopeServiceUserAuthorised;
|
||||
|
||||
@ -90,9 +90,9 @@ abstract class ServiceType extends Model implements ServiceItem
|
||||
/**
|
||||
* The supplier's service that we provide
|
||||
*
|
||||
* @return Type
|
||||
* @return SupplierType
|
||||
*/
|
||||
public function supplied(): Type
|
||||
public function supplied(): SupplierType
|
||||
{
|
||||
return $this->service->product->type->supplied;
|
||||
}
|
@ -8,7 +8,6 @@ use Illuminate\Support\Collection;
|
||||
use App\Interfaces\SupplierItem;
|
||||
use App\Models\Product\Broadband as ProductBroadband;
|
||||
|
||||
// @todo does this need to extend Type? Perhaps have a SupplierType consistent with ServiceType.
|
||||
class Broadband extends Type implements SupplierItem
|
||||
{
|
||||
protected $casts = [
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Models\Usage;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Leenooks\Carbon;
|
||||
|
||||
use App\Models\Service\Broadband as ServiceBroadband;
|
||||
|
||||
|
@ -14,6 +14,7 @@ use Laravel\Passport\HasApiTokens;
|
||||
use Leenooks\Traits\ScopeActive;
|
||||
use Leenooks\Traits\UserSwitch;
|
||||
|
||||
use App\Interfaces\IDs;
|
||||
use App\Notifications\ResetPassword as ResetPasswordNotification;
|
||||
use App\Traits\{QueryCacheableConfig,SiteID};
|
||||
|
||||
@ -23,7 +24,7 @@ use App\Traits\{QueryCacheableConfig,SiteID};
|
||||
* Attributes for users:
|
||||
* + role : User's role
|
||||
*/
|
||||
class User extends Authenticatable
|
||||
class User extends Authenticatable implements IDs
|
||||
{
|
||||
use HasFactory,HasApiTokens,Notifiable,UserSwitch,QueryCacheableConfig,SiteID,ScopeActive;
|
||||
|
||||
@ -79,6 +80,18 @@ class User extends Authenticatable
|
||||
$this->notify((new ResetPasswordNotification($token))->onQueue('high'));
|
||||
}
|
||||
|
||||
/* INTERFACES */
|
||||
|
||||
public function getLIDAttribute(): string
|
||||
{
|
||||
return sprintf('#%04s',$this->id);
|
||||
}
|
||||
|
||||
public function getSIDAttribute(): string
|
||||
{
|
||||
return sprintf('%02s-%s',$this->site_id,$this->getLIDAttribute());
|
||||
}
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
/**
|
||||
|
@ -45,7 +45,7 @@
|
||||
<td>{{ $oo->service_expire ? $oo->service_expire->format('Y-m-d') : '-' }}</td>
|
||||
<td>{{ $oo->registrar->name }}</td>
|
||||
<td>{{ $oo->registrar_ns }}</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>
|
||||
<td>@if ($oo->service->isBilled()) {{ $oo->service->invoice_next->format('Y-m-d') }}@else - @endif</td>
|
||||
<td>@if (! $oo->service->external_billing)${{ number_format($oo->service->next_invoice_items(TRUE)->sum('total'),2) }}@else - @endif</td>
|
||||
<td>{{ $oo->service->billing_interval_string }}</td>
|
||||
</tr>
|
||||
|
@ -48,8 +48,8 @@
|
||||
<td>{{ $oo->service->product->supplier->name }}</td>
|
||||
<td>{{ $oo->admin_url }}</td>
|
||||
<td>@if($oo->admin_user){{ $oo->admin_user }}/{{ $oo->admin_pass }}@else @endif</td>
|
||||
<td class="text-right">{{ number_format($oo->accounts ?: 0,0) }}</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>
|
||||
<td class="text-right">{{ number_format($oo->accounts ?: 0) }}</td>
|
||||
<td>@if ($oo->service->isBilled()) {{ $oo->service->invoice_next->format('Y-m-d') }} @else - @endif</td>
|
||||
<td>@if (! $oo->service->external_billing)${{ number_format($oo->service->next_invoice_items(TRUE)->sum('total'),2) }}@else - @endif</td>
|
||||
<td>{{ $oo->service->billing_interval_string }}</td>
|
||||
</tr>
|
||||
|
@ -43,7 +43,7 @@
|
||||
<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>
|
||||
<td>@if ($oo->service->isBilled()) {{ $oo->service->invoice_next->format('Y-m-d') }}@else - @endif</td>
|
||||
<td>@if (! $oo->service->external_billing)${{ number_format($oo->service->next_invoice_items(TRUE)->sum('total'),2) }}@else - @endif</td>
|
||||
<td>{{ $oo->service->billing_interval_string }}</td>
|
||||
</tr>
|
||||
|
Loading…
Reference in New Issue
Block a user