Added schedule:list, fixed traffic import service, fixed invoice generation with charges and credit amounts

This commit is contained in:
Deon George
2020-05-29 14:10:10 +10:00
parent 7f1681f0b7
commit 121aa5b31c
6 changed files with 67 additions and 7 deletions

View File

@@ -40,7 +40,7 @@ abstract class Supplier
'query'=>[
$this->login_user_field=>$this->o->stats_username,
$this->login_pass_field=>$this->o->stats_password,
$this->date_field=>$this->o->stats_lastupdate,
$this->date_field=>$this->o->stats_lastupdate->format('Y-m-d'),
],
/*
'headers' => [
@@ -52,7 +52,7 @@ abstract class Supplier
$api_remain = Arr::get($result->getHeader('X-RateLimit-Remaining'),0);
$api_reset = Arr::get($result->getHeader('X-RateLimit-Reset'),0);
if ($api_remain == 0) {
if ($api_remain === 0 AND $api_reset) {
Log::error('API Throttle.',['m'=>__METHOD__]);
Cache::put('api_throttle',$api_reset,now()->addSeconds($api_reset));
}
@@ -86,7 +86,7 @@ abstract class Supplier
$this->_columns = $expect;
if ($this->_columns->diff($fields)->count()) {
abort('500','Missing columns in data: '.join('|',$this->_columns->diff($fields)->toArray()));
abort('500','Missing columns in data: '.join('|',$this->_columns->diff($fields)->toArray()).' got: '.join('|',$fields));
}
return $fields->intersect($this->_columns);

View File

@@ -47,6 +47,7 @@ class InvoiceGenerate extends Command
foreach ($accounts as $o) {
$io = new Invoice;
$io->account_id = $o->id;
foreach ($o->services(TRUE)->get() as $so) {
foreach ($so->next_invoice_items(FALSE) as $ooo)
@@ -54,7 +55,7 @@ class InvoiceGenerate extends Command
}
// If there are no items, no reason to do anything
if (! $io->items->count())
if (! $io->items->count() OR $io->total < 0)
continue;
$io->account_id = $o->id;

View File

@@ -5,6 +5,7 @@ namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use App\Models\AdslSupplier;
use App\Jobs\BroadbandTraffic;
class Kernel extends ConsoleKernel
@@ -26,7 +27,9 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$schedule->job(new BroadbandTraffic())->dailyAt('10:00');
// @todo This needs to be more generic and dynamic
// Exetel Traffic
$schedule->job(new BroadbandTraffic(AdslSupplier::find(1)))->timezone('Australia/Melbourne')->dailyAt('10:00');
}
/**

View File

@@ -1231,7 +1231,7 @@ class Service extends Model
}
// Add additional charges
if (($future == TRUE OR ($future == FALSE AND ($this->invoice_to < Carbon::now()->addDays(30))))
if (($future == TRUE OR ($future == FALSE AND ($this->invoice_to >= Carbon::now()->addDays(30))))
AND ! $this->invoice_items->filter(function($item) { return $item->module_id == 30 AND ! $item->exists; })->count())
{
foreach ($this->charges->filter(function($item) { return ! $item->processed; }) as $oo) {