diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index 1593482..38c6237 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -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 diff --git a/app/Models/InvoiceItem.php b/app/Models/InvoiceItem.php index 43c87b3..0425c0c 100644 --- a/app/Models/InvoiceItem.php +++ b/app/Models/InvoiceItem.php @@ -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 diff --git a/app/Models/Product/Broadband.php b/app/Models/Product/Broadband.php index 0b359d6..46e444b 100644 --- a/app/Models/Product/Broadband.php +++ b/app/Models/Product/Broadband.php @@ -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; diff --git a/app/Models/ProductType.php b/app/Models/ProductType.php deleted file mode 100644 index cbc77eb..0000000 --- a/app/Models/ProductType.php +++ /dev/null @@ -1,10 +0,0 @@ -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 * diff --git a/app/Models/Service/Broadband.php b/app/Models/Service/Broadband.php index facf731..883105f 100644 --- a/app/Models/Service/Broadband.php +++ b/app/Models/Service/Broadband.php @@ -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) diff --git a/app/Models/Service/Domain.php b/app/Models/Service/Domain.php index cf52f36..58526f5 100644 --- a/app/Models/Service/Domain.php +++ b/app/Models/Service/Domain.php @@ -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; diff --git a/app/Models/Service/Email.php b/app/Models/Service/Email.php index a61dacb..cc88325 100644 --- a/app/Models/Service/Email.php +++ b/app/Models/Service/Email.php @@ -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; diff --git a/app/Models/Service/Generic.php b/app/Models/Service/Generic.php index 9a76a76..9a9b9e5 100644 --- a/app/Models/Service/Generic.php +++ b/app/Models/Service/Generic.php @@ -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; diff --git a/app/Models/Service/Host.php b/app/Models/Service/Host.php index 017196a..6af41c0 100644 --- a/app/Models/Service/Host.php +++ b/app/Models/Service/Host.php @@ -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; diff --git a/app/Models/Service/Phone.php b/app/Models/Service/Phone.php index ace0256..985b619 100644 --- a/app/Models/Service/Phone.php +++ b/app/Models/Service/Phone.php @@ -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', diff --git a/app/Models/Service/SSL.php b/app/Models/Service/SSL.php index f9434dc..bd1e622 100644 --- a/app/Models/Service/SSL.php +++ b/app/Models/Service/SSL.php @@ -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'; diff --git a/app/Models/Base/ServiceType.php b/app/Models/Service/Type.php similarity index 90% rename from app/Models/Base/ServiceType.php rename to app/Models/Service/Type.php index 19a46cc..070e1d6 100644 --- a/app/Models/Base/ServiceType.php +++ b/app/Models/Service/Type.php @@ -1,16 +1,16 @@ service->product->type->supplied; } diff --git a/app/Models/Supplier/Broadband.php b/app/Models/Supplier/Broadband.php index e30c0f8..ab00b91 100644 --- a/app/Models/Supplier/Broadband.php +++ b/app/Models/Supplier/Broadband.php @@ -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 = [ diff --git a/app/Models/Usage/Broadband.php b/app/Models/Usage/Broadband.php index 7386b56..62b7fc6 100644 --- a/app/Models/Usage/Broadband.php +++ b/app/Models/Usage/Broadband.php @@ -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; diff --git a/app/Models/User.php b/app/Models/User.php index 6142ca4..b2e54f8 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -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 */ /** diff --git a/resources/views/theme/backend/adminlte/r/service/domain/list.blade.php b/resources/views/theme/backend/adminlte/r/service/domain/list.blade.php index 850a6c2..f9ff98f 100644 --- a/resources/views/theme/backend/adminlte/r/service/domain/list.blade.php +++ b/resources/views/theme/backend/adminlte/r/service/domain/list.blade.php @@ -45,7 +45,7 @@