Removed redundant functions in Account, Optimised User a little more, Moved Ezypay Commands to new Ezypay folder

This commit is contained in:
2024-07-07 10:21:27 +10:00
parent 70e94bf6e6
commit b4f3db04fc
11 changed files with 91 additions and 85 deletions

View File

@@ -27,6 +27,12 @@ class Account extends Model implements IDs
/* STATIC */
/**
* A list of invoices that are in credit for all accounts
*
* @param Collection|NULL $invoices
* @return Collection
*/
public static function InvoicesCredit(Collection $invoices=NULL): Collection
{
return (new self)
@@ -34,6 +40,12 @@ class Account extends Model implements IDs
->get();
}
/**
* A list of invoices that are due for all accounts
*
* @param Collection|NULL $invoices
* @return Collection
*/
public static function InvoicesDue(Collection $invoices=NULL): Collection
{
return (new self)
@@ -73,11 +85,12 @@ class Account extends Model implements IDs
return $this->belongsTo(Country::class);
}
public function external()
{
return $this->belongsToMany(External\Integrations::class,'external_account',NULL,'external_integration_id');
}
/**
* Group this account is assigned to
* Groups are used for pricing control
*
* @return \Illuminate\Database\Eloquent\Relations\HasOneThrough
*/
public function group()
{
return $this->hasOneThrough(Group::class,AccountGroup::class,'account_id','id','id','group_id');
@@ -85,8 +98,6 @@ class Account extends Model implements IDs
/**
* Invoices created for this account
*
* @todo This needs to be optimised, to only return outstanding invoices and invoices for a specific age (eg: 2 years worth)
*/
public function invoices()
{
@@ -96,13 +107,11 @@ class Account extends Model implements IDs
/**
* Relation to only return active invoices
*
* @todo Only return active invoice_items
*/
public function invoices_active()
{
return $this->invoices()
->active();
->with('active',TRUE);;
}
/**
@@ -116,19 +125,19 @@ class Account extends Model implements IDs
/**
* Relation to only return active payments
*
* @todo Only return active payment_items
*/
public function payments_active()
{
return $this->payments()
->active();
->with('active',TRUE);
}
/**
* Return the link to a provider's info for this account
*/
public function providers()
{
return $this->belongsToMany(ProviderOauth::class,'account__provider')
->where('account__provider.site_id',$this->site_id)
->withPivot('ref','synctoken','created_at','updated_at');
}
@@ -150,6 +159,9 @@ class Account extends Model implements IDs
->active();
}
/**
* Taxes applicable for this account
*/
public function taxes()
{
return $this->hasMany(Tax::class,'country_id','country_id')
@@ -219,7 +231,7 @@ class Account extends Model implements IDs
*/
public function getNameAttribute(): string
{
return $this->company ?: ($this->user_id ? $this->user->getSurFirstNameAttribute() : 'LID:'.$this->id);
return $this->company ?: ($this->user_id ? $this->user->getNameSurFirstAttribute() : 'LID:'.$this->id);
}
/**
@@ -234,19 +246,6 @@ class Account extends Model implements IDs
/* METHODS */
/**
* Get the due invoices on an account
*
* @return mixed
* @deprecated use invoiceSummary->filter(_balance > 0)
*/
public function dueInvoices()
{
return $this->invoices->filter(function($item) {
return $item->active AND $item->due > 0;
});
}
/**
* List of invoices (summary) for this account
*