Removed redundant functions in Account, Optimised User a little more, Moved Ezypay Commands to new Ezypay folder
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
27
app/Models/External/Integrations.php
vendored
27
app/Models/External/Integrations.php
vendored
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\External;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class Integrations extends Model
|
||||
{
|
||||
public $table = 'external_integrations';
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
function scopeActive()
|
||||
{
|
||||
return $this->where('active',TRUE);
|
||||
}
|
||||
|
||||
function scopeType($query,string $type)
|
||||
{
|
||||
return $query->where('type',$type);
|
||||
}
|
||||
}
|
@@ -7,6 +7,7 @@ use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Database\Eloquent\Collection as DatabaseCollection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Laravel\Passport\HasApiTokens;
|
||||
use Leenooks\Traits\ScopeActive;
|
||||
use Leenooks\Traits\UserSwitch;
|
||||
@@ -142,6 +143,18 @@ class User extends Authenticatable implements IDs
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
/**
|
||||
* Logged in user's full name
|
||||
*
|
||||
* @return string
|
||||
* @deprecated use getNameFullAttribute()
|
||||
*/
|
||||
public function getFullNameAttribute(): string
|
||||
{
|
||||
Log::alert('UMO:! Deprecated function getFullNameAttribute()');
|
||||
return $this->getNameFullAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is an alias method, as it is used by the framework
|
||||
*
|
||||
@@ -149,7 +162,7 @@ class User extends Authenticatable implements IDs
|
||||
*/
|
||||
public function getNameAttribute(): string
|
||||
{
|
||||
return $this->full_name;
|
||||
return $this->name_full;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,11 +170,21 @@ class User extends Authenticatable implements IDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFullNameAttribute(): string
|
||||
public function getNameFullAttribute(): string
|
||||
{
|
||||
return sprintf('%s %s',$this->firstname,$this->lastname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name, surname first
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNameSurFirstAttribute()
|
||||
{
|
||||
return sprintf('%s, %s',$this->lastname,$this->firstname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a friendly string of this persons role
|
||||
*
|
||||
@@ -172,9 +195,15 @@ class User extends Authenticatable implements IDs
|
||||
return ucfirst($this->role());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name, surname first
|
||||
* @return string
|
||||
* @deprecated use getNameSurFirstAttribute()
|
||||
*/
|
||||
public function getSurFirstNameAttribute()
|
||||
{
|
||||
return sprintf('%s, %s',$this->lastname,$this->firstname);
|
||||
Log::alert('UMO:! Deprecated function getSurFirstNameAttribute()');
|
||||
return $this->getNameSurFirstAttribute();
|
||||
}
|
||||
|
||||
/* SCOPES */
|
||||
|
Reference in New Issue
Block a user