Remove Interface ID and implement the lid/sid methods in __get()
This commit is contained in:
parent
a988720340
commit
1e496a2863
@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Interfaces;
|
|
||||||
|
|
||||||
interface IDs
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Return the local ID of the item
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getLIDAttribute(): string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the system ID of the item
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getSIDAttribute(): string;
|
|
||||||
}
|
|
@ -22,10 +22,20 @@ use App\Interfaces\IDs;
|
|||||||
* + name : Account Name
|
* + name : Account Name
|
||||||
* + taxes : Taxes Applicable to this account
|
* + taxes : Taxes Applicable to this account
|
||||||
*/
|
*/
|
||||||
class Account extends Model implements IDs
|
class Account extends Model
|
||||||
{
|
{
|
||||||
use HasFactory,ScopeActive;
|
use HasFactory,ScopeActive;
|
||||||
|
|
||||||
|
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),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/* STATIC */
|
/* STATIC */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,18 +64,6 @@ class Account extends Model implements IDs
|
|||||||
->get();
|
->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 */
|
/* RELATIONS */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,7 +36,7 @@ use App\Traits\{PushNew,SiteID};
|
|||||||
*
|
*
|
||||||
* @package App\Models
|
* @package App\Models
|
||||||
*/
|
*/
|
||||||
class Invoice extends Model implements IDs
|
class Invoice extends Model
|
||||||
{
|
{
|
||||||
use PushNew,ScopeActive,SiteID;
|
use PushNew,ScopeActive,SiteID;
|
||||||
|
|
||||||
@ -109,6 +109,16 @@ class Invoice extends Model implements IDs
|
|||||||
'payment_items_active.payment:id,paid_at',
|
'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 */
|
/* STATIC METHODS */
|
||||||
|
|
||||||
public static function boot()
|
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);
|
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 */
|
/* RELATIONS */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,7 +22,7 @@ use App\Traits\{ProviderRef,PushNew,ScopeAccountUserAuthorised,SiteID};
|
|||||||
*
|
*
|
||||||
* @package App\Models
|
* @package App\Models
|
||||||
*/
|
*/
|
||||||
class Payment extends Model implements IDs
|
class Payment extends Model
|
||||||
{
|
{
|
||||||
use ProviderRef,PushNew,ScopeActive,ScopeAccountUserAuthorised,SiteID;
|
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.
|
// Any balance below this we'll assume its all used.
|
||||||
private const threshold = 0.05;
|
private const threshold = 0.05;
|
||||||
|
|
||||||
/* INTERFACES */
|
public function __get($key): mixed
|
||||||
|
|
||||||
/**
|
|
||||||
* Payment Local ID
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getLIDattribute(): string
|
|
||||||
{
|
{
|
||||||
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),
|
||||||
|
|
||||||
/**
|
default => parent::__get($key),
|
||||||
* Payment System ID
|
};
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getSIDAttribute(): string
|
|
||||||
{
|
|
||||||
return sprintf('%02s-%04s#%s',$this->site_id,$this->account_id,$this->getLIDattribute());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* RELATIONS */
|
/* RELATIONS */
|
||||||
|
@ -74,7 +74,7 @@ use App\Traits\ProviderRef;
|
|||||||
* ]
|
* ]
|
||||||
* ]
|
* ]
|
||||||
*/
|
*/
|
||||||
class Product extends Model implements IDs
|
class Product extends Model
|
||||||
{
|
{
|
||||||
use HasFactory,ScopeActive,ProviderRef,ProviderTokenTrait;
|
use HasFactory,ScopeActive,ProviderRef,ProviderTokenTrait;
|
||||||
|
|
||||||
@ -104,7 +104,9 @@ class Product extends Model implements IDs
|
|||||||
|
|
||||||
'name' => $this->translate->name_detail,
|
'name' => $this->translate->name_detail,
|
||||||
|
|
||||||
|
'lid' => sprintf('%04s',$this->id),
|
||||||
'pid' => $this->translate->name_short,
|
'pid' => $this->translate->name_short,
|
||||||
|
'sid' => sprintf('%02s-%s',$this->site_id,$this->lid),
|
||||||
|
|
||||||
'setup_cost' => $this->supplied->setup_cost ?: 0,
|
'setup_cost' => $this->supplied->setup_cost ?: 0,
|
||||||
|
|
||||||
@ -187,18 +189,6 @@ class Product extends Model implements IDs
|
|||||||
return $this->morphTo(null,'model','model_id');
|
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 */
|
/* ATTRIBUTES */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,7 +65,7 @@ use App\Traits\{ScopeAccountUserAuthorised,ScopeServiceActive,SiteID};
|
|||||||
* + sid : System ID for service
|
* + sid : System ID for service
|
||||||
* + supplied : The model of the supplier's product used for this 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;
|
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_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']),
|
'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
|
'status' => $this->active
|
||||||
? strtolower($this->order_status)
|
? strtolower($this->order_status)
|
||||||
: ((strtolower($this->order_status) === 'cancelled') ? 'cancelled' : 'inactive'),
|
: ((strtolower($this->order_status) === 'cancelled') ? 'cancelled' : 'inactive'),
|
||||||
@ -341,28 +344,6 @@ class Service extends Model implements IDs
|
|||||||
->get();
|
->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 */
|
/* RELATIONS */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,7 +20,7 @@ use App\Traits\SiteID;
|
|||||||
* Attributes for users:
|
* Attributes for users:
|
||||||
* + role : User's role
|
* + role : User's role
|
||||||
*/
|
*/
|
||||||
class User extends Authenticatable implements IDs
|
class User extends Authenticatable
|
||||||
{
|
{
|
||||||
use HasFactory,HasApiTokens,Notifiable,UserSwitch,ScopeActive,SiteID;
|
use HasFactory,HasApiTokens,Notifiable,UserSwitch,ScopeActive,SiteID;
|
||||||
|
|
||||||
@ -63,6 +63,16 @@ class User extends Authenticatable implements IDs
|
|||||||
'customer',
|
'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 */
|
/* OVERRIDES */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,18 +86,6 @@ class User extends Authenticatable implements IDs
|
|||||||
->onQueue('user'));
|
->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 */
|
/* RELATIONS */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user