Added Ezypayment next payment check

This commit is contained in:
Deon George
2019-06-11 12:36:58 +10:00
parent c45f5136fe
commit eb254def7a
4 changed files with 107 additions and 11 deletions

View File

@@ -4,11 +4,9 @@ namespace App\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
use App\Classes\Payments\Ezypay;
use App\Models\{Account,AccoutBilling,Checkout,Payment};
use App\Models\{Account,Checkout,Payment};
class EzypayImport extends Command
{
@@ -43,12 +41,6 @@ class EzypayImport extends Command
*/
public function handle()
{
/*
DB::listen(function($query) {
$this->warn('- SQL:'.json_encode(['sql'=>$query->sql,'binding'=>$query->bindings]));
});
*/
$poo = new Ezypay();
// Get our checkout IDs for this plugin
@@ -110,7 +102,6 @@ class EzypayImport extends Command
$this->info(sprintf('Recorded: Payment for [%s] %s %s (%s) on %s',$c->EzypayReferenceNumber,$c->Firstname,$c->Surname,$po->id,$pd));
}
}
}
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Classes\Payments\Ezypay;
use App\Models\Account;
class EzypayPayments extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'next:ezypay';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Load next payments, and ensure they cover the next invoice';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$poo = new Ezypay();
foreach ($poo->getCustomers() as $c)
{
if ($c->BillingStatus == 'Inactive')
{
$this->info(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))
->first();
if (! $ao)
{
$this->warn(sprintf('Missing: [%s] %s %s (%s)',$c->EzypayReferenceNumber,$c->Firstname,$c->Surname,$c->ReferenceId));
continue;
}
// Get Due Invoices
$account_due = $ao->dueInvoices()->sum('due');
$next_pay = $poo->getDebits([
'customerId'=>$c->Id,
'dateFrom'=>now()->format('Y-m-d'),
'dateTo'=>now()->addQuarter()->format('Y-m-d'),
])->reverse()->first();
if ($next_pay->Amount < $account_due)
$this->warn(sprintf('Next payment for (%s) [%s] not sufficient for outstanding balance [%s]',$ao->name,number_format($next_pay->Amount,2),number_format($account_due,2)));
elseif ($next_pay->Amount > $account_due)
$this->warn(sprintf('Next payment for (%s) [%s] is too much for outstanding balance [%s]',$ao->name,number_format($next_pay->Amount,2),number_format($account_due,2)));
else
$this->info(sprintf('Next payment for (%s) [%s] will cover outstanding balance [%s]',$ao->name,number_format($next_pay->Amount,2),number_format($account_due,2)));
}
}
}