Home screen improvements, testing for role, work on user/account models

This commit is contained in:
Deon George
2022-04-21 14:41:26 +10:00
parent 40d12b906b
commit 796c72dd09
18 changed files with 528 additions and 241 deletions

View File

@@ -18,6 +18,7 @@ use Leenooks\Carbon;
use Symfony\Component\HttpKernel\Exception\HttpException;
use App\Interfaces\IDs;
use App\Traits\ScopeServiceUserAuthorised;
/**
* Class Service
@@ -46,7 +47,7 @@ use App\Interfaces\IDs;
// @todo All the methods/attributes in this file need to be checked.
class Service extends Model implements IDs
{
use HasFactory;
use HasFactory,ScopeServiceUserAuthorised;
protected $appends = [
'account_name',
@@ -86,15 +87,11 @@ class Service extends Model implements IDs
'status',
];
/*
protected $with = [
'account.language',
'charges',
'invoice_items',
'product',
'product.type.supplied',
'type',
];
*/
// @todo Change to self::INACTIVE_STATUS
private $inactive_status = [
@@ -413,15 +410,6 @@ class Service extends Model implements IDs
});
}
/**
* Only query records that the user is authorised to see
*/
public function scopeAuthorised($query,User $uo)
{
return $query
->whereIN($this->getTable().'.account_id',$uo->all_accounts()->pluck('id')->unique()->toArray());
}
/**
* Find inactive services.
*
@@ -1345,6 +1333,7 @@ class Service extends Model implements IDs
* @return Collection
* @throws Exception
* @todo Use self::isBilled();
* @todo This query is expensive.
*/
public function next_invoice_items(bool $future,Carbon $billdate=NULL): Collection
{