Changed home screen to use account models instead of user model. Home screen now shows multiple accounts
This commit is contained in:
@@ -64,9 +64,15 @@ class Account extends Model implements IDs
|
||||
return $this->hasOneThrough(Group::class,AccountGroup::class,'account_id','id','id','group_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @todo This needs to be optimised, to only return outstanding invoices and invoices for a specific age (eg: 2 years worth)
|
||||
*/
|
||||
public function invoices()
|
||||
{
|
||||
return $this->hasMany(Invoice::class);
|
||||
return $this->hasMany(Invoice::class)
|
||||
->active()
|
||||
->with(['items.taxes','paymentitems.payment']);
|
||||
}
|
||||
|
||||
public function language()
|
||||
@@ -76,7 +82,9 @@ class Account extends Model implements IDs
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany(Payment::class);
|
||||
return $this->hasMany(Payment::class)
|
||||
->active()
|
||||
->with(['items']);
|
||||
}
|
||||
|
||||
public function providers()
|
||||
@@ -89,7 +97,8 @@ class Account extends Model implements IDs
|
||||
public function services($active=FALSE)
|
||||
{
|
||||
$query = $this->hasMany(Service::class,['account_id','site_id'],['id','site_id'])
|
||||
->withoutGlobalScope(SiteScope::class);
|
||||
->withoutGlobalScope(SiteScope::class)
|
||||
->with(['product.translate','invoice_items']);
|
||||
|
||||
return $active ? $query->active() : $query;
|
||||
}
|
||||
|
@@ -97,7 +97,7 @@ class Service extends Model implements IDs
|
||||
protected $with = [
|
||||
//'invoice_items',
|
||||
//'product.type.supplied',
|
||||
//'type',
|
||||
'type',
|
||||
];
|
||||
|
||||
public const INACTIVE_STATUS = [
|
||||
|
@@ -105,14 +105,14 @@ class User extends Authenticatable implements IDs
|
||||
{
|
||||
return $this->hasMany(Account::class)
|
||||
->orWhereIn('id',$this->rtm_accounts()->pluck('id'))
|
||||
->active()
|
||||
->with(['services']);
|
||||
->active();
|
||||
}
|
||||
|
||||
/**
|
||||
* This users invoices
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||
* @deprecated Accounts have invoices, not users
|
||||
*/
|
||||
public function invoices()
|
||||
{
|
||||
@@ -130,16 +130,6 @@ class User extends Authenticatable implements IDs
|
||||
return $this->belongsTo(Language::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* The payments this user has made
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||
*/
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasManyThrough(Payment::class,Account::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the routes to market account for this user
|
||||
*
|
||||
@@ -151,9 +141,10 @@ class User extends Authenticatable implements IDs
|
||||
}
|
||||
|
||||
/**
|
||||
* THe services this user has
|
||||
* The services this user has
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||
* @deprecated Accounts have services, not users
|
||||
*/
|
||||
public function services()
|
||||
{
|
||||
@@ -162,6 +153,12 @@ class User extends Authenticatable implements IDs
|
||||
->active();
|
||||
}
|
||||
|
||||
/**
|
||||
* Supplier configuration for this user
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
* @deprecated Move to account->suppliers()
|
||||
*/
|
||||
public function suppliers()
|
||||
{
|
||||
return $this->belongsToMany(Supplier::class)
|
||||
@@ -178,7 +175,7 @@ class User extends Authenticatable implements IDs
|
||||
*/
|
||||
public function getNameAttribute(): string
|
||||
{
|
||||
return $this->getFullNameAttribute();
|
||||
return $this->full_name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,13 +189,20 @@ class User extends Authenticatable implements IDs
|
||||
}
|
||||
|
||||
/**
|
||||
* Return my accounts
|
||||
* Return my accounts, but only those accounts with the same group_id
|
||||
*
|
||||
* @note Users can only manage accounts with the same group ID, thereby ensuring they dont see different
|
||||
* pricing options - since prices can be controlled by groups
|
||||
* @return Collection
|
||||
*/
|
||||
public function getMyAccountsAttribute(): Collection
|
||||
{
|
||||
return $this->accounts->where('user_id',$this->id);
|
||||
$result = $this->accounts->where('user_id',$this->id);
|
||||
|
||||
if (! $result->count())
|
||||
return $result;
|
||||
|
||||
return $this->isReseller() ? $result : $result->groupBy('group.id')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user