Removed redundant functions in Account, Optimised User a little more, Moved Ezypay Commands to new Ezypay folder
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
namespace App\Console\Commands\Ezypay;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
@@ -8,14 +8,14 @@ use Illuminate\Console\Command;
|
||||
use App\Classes\External\Payments\Ezypay;
|
||||
use App\Models\Account;
|
||||
|
||||
class PaymentsEzypayNext extends Command
|
||||
class PaymentNext extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'payments:ezypay:next';
|
||||
protected $signature = 'ezypay:payment:next';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@@ -35,14 +35,12 @@ class PaymentsEzypayNext extends Command
|
||||
|
||||
foreach ($poo->getCustomers() as $c) {
|
||||
if ($c->BillingStatus == 'Inactive') {
|
||||
$this->info(sprintf('Ignoring INACTIVE: [%s] %s %s',$c->EzypayReferenceNumber,$c->Firstname,$c->Surname));
|
||||
$this->comment(sprintf('Ignoring INACTIVE: [%s] %s %s',$c->EzypayReferenceNumber,$c->Firstname,$c->Surname));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Load Account Details from ReferenceId
|
||||
$ao = Account::where('site_id',(int)substr($c->ReferenceId,0,2))
|
||||
->where('id',(int)substr($c->ReferenceId,2,4))
|
||||
->single();
|
||||
$ao = Account::find((int)substr($c->ReferenceId,2,4));
|
||||
|
||||
if (! $ao) {
|
||||
$this->warn(sprintf('Missing: [%s] %s %s (%s)',$c->EzypayReferenceNumber,$c->Firstname,$c->Surname,$c->ReferenceId));
|
||||
@@ -50,7 +48,14 @@ class PaymentsEzypayNext extends Command
|
||||
}
|
||||
|
||||
// Get Due Invoices
|
||||
$account_due = $ao->dueInvoices()->sum('due');
|
||||
$invoice_due = $ao->invoiceSummaryDue()->get();
|
||||
|
||||
$this->info(sprintf('Account [%s] (%s) has [%d] invoices due, totalling [%3.2f]',
|
||||
$ao->lid,
|
||||
$ao->name,
|
||||
$invoice_due->count(),
|
||||
($due=$invoice_due->sum('_balance')),
|
||||
));
|
||||
|
||||
$next_pay = $poo->getDebits([
|
||||
'customerId'=>$c->Id,
|
||||
@@ -59,32 +64,32 @@ class PaymentsEzypayNext extends Command
|
||||
])->reverse()->first();
|
||||
|
||||
if ($next_pay->Status !== 'Pending') {
|
||||
$this->warn(sprintf('Next payment is not pending for (%s)',$ao->name));
|
||||
$this->warn(sprintf('- Next payment is not pending for (%s)',$ao->name));
|
||||
continue;
|
||||
}
|
||||
|
||||
$next_paydate = Carbon::createFromTimeString($next_pay->Date);
|
||||
|
||||
if ($next_pay->Amount < $account_due)
|
||||
$this->warn(sprintf('Next payment on [%s] for (%s) [%s] not sufficient for outstanding balance [%s]',
|
||||
if ($next_pay->Amount < $due)
|
||||
$this->error(sprintf('- Next payment on [%s] for (%s) [%s] not sufficient for outstanding balance [%s]',
|
||||
$next_paydate->format('Y-m-d'),
|
||||
$ao->name,
|
||||
number_format($next_pay->Amount,2),
|
||||
number_format($account_due,2)));
|
||||
number_format($due,2)));
|
||||
|
||||
elseif ($next_pay->Amount > $account_due)
|
||||
$this->warn(sprintf('Next payment on [%s] for (%s) [%s] is too much for outstanding balance [%s]',
|
||||
elseif ($next_pay->Amount > $due)
|
||||
$this->warn(sprintf('- Next payment on [%s] for (%s) [%s] is too much for outstanding balance [%s]',
|
||||
$next_paydate->format('Y-m-d'),
|
||||
$ao->name,
|
||||
number_format($next_pay->Amount,2),
|
||||
number_format($account_due,2)));
|
||||
number_format($due,2)));
|
||||
|
||||
else
|
||||
$this->info(sprintf('Next payment on [%s] for (%s) [%s] will cover outstanding balance [%s]',
|
||||
$this->info(sprintf('- Next payment on [%s] for (%s) [%s] will cover outstanding balance [%s]',
|
||||
$next_paydate->format('Y-m-d'),
|
||||
$ao->name,
|
||||
number_format($next_pay->Amount,2),
|
||||
number_format($account_due,2)));
|
||||
number_format($due,2)));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,20 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
namespace App\Console\Commands\Ezypay;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
use App\Classes\External\Payments\Ezypay;
|
||||
use App\Jobs\PaymentsImport as Job;
|
||||
|
||||
class PaymentsEzypayImport extends Command
|
||||
class PaymentsImport extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'payments:ezypay:import';
|
||||
protected $signature = 'ezypay:payment:import';
|
||||
|
||||
/**
|
||||
* The console command description.
|
@@ -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