diff --git a/app/Interfaces/IDs.php b/app/Interfaces/IDs.php deleted file mode 100644 index dfdf138..0000000 --- a/app/Interfaces/IDs.php +++ /dev/null @@ -1,20 +0,0 @@ - sprintf('%04s',$this->id), + 'sid' => sprintf('%02s-%s',$this->site_id,$this->lid), + + default => parent::__get($key), + }; + } + /* STATIC */ /** @@ -54,18 +64,6 @@ class Account extends Model implements IDs ->get(); } - /* 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/app/Models/Invoice.php b/app/Models/Invoice.php index db499b5..2b21333 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -36,7 +36,7 @@ use App\Traits\{PushNew,SiteID}; * * @package App\Models */ -class Invoice extends Model implements IDs +class Invoice extends Model { use PushNew,ScopeActive,SiteID; @@ -109,6 +109,16 @@ class Invoice extends Model implements IDs 'payment_items_active.payment:id,paid_at', ]; + public function __get($key): mixed + { + return match ($key) { + 'lid' => sprintf('%06s',$this->id), + 'sid' => sprintf('%02s-%04s-%s',$this->site_id,$this->account_id,$this->lid), + + default => parent::__get($key), + }; + } + /* STATIC METHODS */ public static function boot() @@ -317,28 +327,6 @@ class Invoice extends Model implements IDs return round(($d-Arr::get($period,'start')->diffInDays($start)-$end->diffInDays(Arr::get($period,'end')))/$d,2); } - /* INTERFACES */ - - /** - * Invoice Local ID - * - * @return string - */ - public function getLIDAttribute(): string - { - return sprintf('%06s',$this->id); - } - - /** - * Invoice System ID - * - * @return string - */ - public function getSIDAttribute(): string - { - return sprintf('%02s-%04s-%s',$this->site_id,$this->account_id,$this->getLIDAttribute()); - } - /* RELATIONS */ /** diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 472f592..87e1038 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -22,7 +22,7 @@ use App\Traits\{ProviderRef,PushNew,ScopeAccountUserAuthorised,SiteID}; * * @package App\Models */ -class Payment extends Model implements IDs +class Payment extends Model { use ProviderRef,PushNew,ScopeActive,ScopeAccountUserAuthorised,SiteID; @@ -36,26 +36,14 @@ class Payment extends Model implements IDs // Any balance below this we'll assume its all used. private const threshold = 0.05; - /* INTERFACES */ - - /** - * Payment Local ID - * - * @return string - */ - public function getLIDattribute(): string + public function __get($key): mixed { - return sprintf('%06s',$this->id); - } + return match ($key) { + 'lid' => sprintf('%06s',$this->id), + 'sid' => sprintf('%02s-%04s#%s',$this->site_id,$this->account_id,$this->lid), - /** - * Payment System ID - * - * @return string - */ - public function getSIDAttribute(): string - { - return sprintf('%02s-%04s#%s',$this->site_id,$this->account_id,$this->getLIDattribute()); + default => parent::__get($key), + }; } /* RELATIONS */ diff --git a/app/Models/Product.php b/app/Models/Product.php index 69c6a0f..c971069 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -74,7 +74,7 @@ use App\Traits\ProviderRef; * ] * ] */ -class Product extends Model implements IDs +class Product extends Model { use HasFactory,ScopeActive,ProviderRef,ProviderTokenTrait; @@ -104,7 +104,9 @@ class Product extends Model implements IDs 'name' => $this->translate->name_detail, + 'lid' => sprintf('%04s',$this->id), 'pid' => $this->translate->name_short, + 'sid' => sprintf('%02s-%s',$this->site_id,$this->lid), 'setup_cost' => $this->supplied->setup_cost ?: 0, @@ -187,18 +189,6 @@ class Product extends Model implements IDs return $this->morphTo(null,'model','model_id'); } - /* INTERFACES */ - - public function getLIDAttribute(): string - { - return sprintf('%04s',$this->id); - } - - public function getSIDAttribute(): string - { - return sprintf('%02s-%s',$this->site_id,$this->getLIDattribute()); - } - /* ATTRIBUTES */ /** diff --git a/app/Models/Service.php b/app/Models/Service.php index d81791e..70bf2af 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -65,7 +65,7 @@ use App\Traits\{ScopeAccountUserAuthorised,ScopeServiceActive,SiteID}; * + sid : System ID for service * + supplied : The model of the supplier's product used for this service. */ -class Service extends Model implements IDs +class Service extends Model { use HasFactory,ScopeAccountUserAuthorised,ScopeServiceActive,SiteID; @@ -313,6 +313,9 @@ class Service extends Model implements IDs 'is_pending_change' => $this->active && $this->changes()->where('service__change.active',TRUE)->where('complete',FALSE)->count(), 'is_pending_cancel' => $this->active && in_array(strtolower($this->order_status),['cancel-request','cancel-pending']), + 'lid' => sprintf('%05s',$this->id), + 'sid' => sprintf('%02s-%04s.%s',$this->site_id,$this->account_id,$this->lid), + 'status' => $this->active ? strtolower($this->order_status) : ((strtolower($this->order_status) === 'cancelled') ? 'cancelled' : 'inactive'), @@ -341,28 +344,6 @@ class Service extends Model implements IDs ->get(); } - /* 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 */ /** diff --git a/app/Models/User.php b/app/Models/User.php index bb7a256..1a53f40 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -20,7 +20,7 @@ use App\Traits\SiteID; * Attributes for users: * + role : User's role */ -class User extends Authenticatable implements IDs +class User extends Authenticatable { use HasFactory,HasApiTokens,Notifiable,UserSwitch,ScopeActive,SiteID; @@ -63,6 +63,16 @@ class User extends Authenticatable implements IDs 'customer', ]; + public function __get($key): mixed + { + return match ($key) { + 'lid' => sprintf('#%04s',$this->id), + 'sid' => sprintf('%02s-%s',$this->site_id,$this->lid), + + default => parent::__get($key), + }; + } + /* OVERRIDES */ /** @@ -76,18 +86,6 @@ class User extends Authenticatable implements IDs ->onQueue('user')); } - /* INTERFACES */ - - public function getLIDAttribute(): string - { - return sprintf('#%04s',$this->id); - } - - public function getSIDAttribute(): string - { - return sprintf('%02s-%s',$this->site_id,$this->getLIDAttribute()); - } - /* RELATIONS */ /**