Compare commits
1 Commits
1c4cb6f38c
...
73baa2f153
Author | SHA1 | Date | |
---|---|---|---|
73baa2f153 |
@ -3,7 +3,6 @@
|
|||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
||||||
|
|
||||||
use App\Jobs\BroadbandTraffic as Job;
|
use App\Jobs\BroadbandTraffic as Job;
|
||||||
use App\Models\Supplier;
|
use App\Models\Supplier;
|
||||||
@ -16,7 +15,7 @@ class BroadbandTraffic extends Command
|
|||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'broadband:traffic:import'.
|
protected $signature = 'broadband:traffic:import'.
|
||||||
' {supplier? : Supplier Name}';
|
' {--s|supplier= : Supplier Name}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@ -32,26 +31,14 @@ class BroadbandTraffic extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
if ($this->argument('supplier')) {
|
if ($this->option('supplier')) {
|
||||||
try {
|
$o = Supplier::where('name','ilike',$this->option('supplier'))->singleOrFail();
|
||||||
$o = Supplier::active()
|
|
||||||
->where('name','ilike',$this->argument('supplier'))
|
|
||||||
->sole();
|
|
||||||
|
|
||||||
} catch (ModelNotFoundException $e) {
|
Job::dispatchSync($o->id);
|
||||||
$this->error(sprintf('Supplier [%s] not found',$this->argument('supplier')));
|
return;
|
||||||
|
|
||||||
return self::FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Job::dispatchSync($o->name);
|
|
||||||
|
|
||||||
return self::SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Supplier::active()->get() as $o)
|
foreach (Supplier::active()->get() as $o)
|
||||||
Job::dispatchSync($o->name);
|
Job::dispatchSync($o->id);
|
||||||
|
|
||||||
return self::SUCCESS;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,22 +5,24 @@ namespace App\Jobs;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
use App\Classes\External\Supplier as ExternalSupplier;
|
use App\Classes\External\Supplier as ExternalSupplier;
|
||||||
use App\Mail\TrafficMismatch;
|
use App\Mail\TrafficMismatch;
|
||||||
use App\Models\{Rtm,Supplier};
|
use App\Models\Supplier;
|
||||||
use App\Models\Service\Broadband as ServiceBroadband;
|
use App\Models\Service\Broadband as ServiceBroadband;
|
||||||
use App\Models\Usage\Broadband as UsageBroadband;
|
use App\Models\Usage\Broadband as UsageBroadband;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BroadbandTraffic
|
* Class BroadbandTraffic
|
||||||
* Read and update the traffic for a Broadband supplier
|
* Read and update the traffic for an Broadband supplier
|
||||||
*
|
*
|
||||||
* @package App\Jobs
|
* @package App\Jobs
|
||||||
*/
|
*/
|
||||||
@ -30,11 +32,15 @@ final class BroadbandTraffic implements ShouldQueue
|
|||||||
|
|
||||||
private const LOGKEY = 'JBT';
|
private const LOGKEY = 'JBT';
|
||||||
|
|
||||||
|
protected int $sid; // The supplier we are updating from
|
||||||
private const class_prefix = 'App\Classes\External\Supplier\\';
|
private const class_prefix = 'App\Classes\External\Supplier\\';
|
||||||
|
|
||||||
private const traffic = 'broadband';
|
private const traffic = 'broadband';
|
||||||
|
|
||||||
public function __construct(private string $supplier) {}
|
public function __construct(int $sid)
|
||||||
|
{
|
||||||
|
$this->sid = $sid;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the job.
|
* Execute the job.
|
||||||
@ -44,19 +50,12 @@ final class BroadbandTraffic implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$so = Supplier::active()
|
$so = Supplier::findOrFail($this->sid);
|
||||||
->where('name','ilike',$this->supplier)
|
|
||||||
->sole();
|
|
||||||
|
|
||||||
// Wholesaler email
|
|
||||||
$ro = Rtm::where('parent_id',NULL)->sole();
|
|
||||||
|
|
||||||
Log::info(sprintf('%s:Importing Broadband Traffic from [%s]',self::LOGKEY,$so->name));
|
Log::info(sprintf('%s:Importing Broadband Traffic from [%s]',self::LOGKEY,$so->name));
|
||||||
|
|
||||||
if ((! $connection=$so->detail->connections->get('broadband')) || (count(array_intersect(array_keys($connection),ExternalSupplier::traffic_connection_keys)) !== 3))
|
if ((! $connection=$so->detail->connections->get('broadband')) || (count(array_intersect(array_keys($connection),ExternalSupplier::traffic_connection_keys)) !== 3))
|
||||||
throw new \Exception('No or missing connection details for:'.self::traffic);
|
throw new \Exception('No or missing connection details for:'.self::traffic);
|
||||||
|
|
||||||
// Count of updated records
|
|
||||||
$u = 0;
|
$u = 0;
|
||||||
|
|
||||||
// Load our class for this supplier
|
// Load our class for this supplier
|
||||||
@ -96,16 +95,15 @@ final class BroadbandTraffic implements ShouldQueue
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$date = Carbon::createFromFormat('Y-m-d',$row[$o->getColumnKey('Date')]);
|
$date = Carbon::createFromFormat('Y-m-d',$row[$o->getColumnKey('Date')]);
|
||||||
|
|
||||||
// Find the right service dependent on the dates we supplied the service
|
// Find the right service dependent on the dates we supplied the service
|
||||||
$oo = ServiceBroadband::where('service_username',$row[$o->getColumnKey('Login')])
|
$oo = ServiceBroadband::where('service_username',$row[$o->getColumnKey('Login')])
|
||||||
->select('service_broadband.*')
|
->select(DB::raw('service_broadband.*'))
|
||||||
->join('services',['service_broadband.service_id'=>'services.id'])
|
->join('services','services.id','=','service_id')
|
||||||
->where('services.start_at','<=',$date)
|
->where('services.start_at','<=',$date)
|
||||||
->where(fn($query)=>
|
->where(function($query) use ($date) {
|
||||||
$query->whereNULL('services.stop_at')
|
$query->whereNULL('services.stop_at')
|
||||||
->orWhere('services.stop_at','>=',$date)
|
->orWhere('services.stop_at','<=',$date);
|
||||||
)
|
})
|
||||||
->single();
|
->single();
|
||||||
|
|
||||||
$to = new UsageBroadband;
|
$to = new UsageBroadband;
|
||||||
@ -151,7 +149,7 @@ final class BroadbandTraffic implements ShouldQueue
|
|||||||
|
|
||||||
if ($u) {
|
if ($u) {
|
||||||
if ($so->trafficMismatch($date)->count())
|
if ($so->trafficMismatch($date)->count())
|
||||||
Mail::to($ro->owner->email)
|
Mail::to('deon@graytech.net.au') // @todo To change
|
||||||
->send(new TrafficMismatch($so,$date));
|
->send(new TrafficMismatch($so,$date));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,13 +25,6 @@ class Rtm extends Model
|
|||||||
return $this->hasMany(self::class,'parent_id');
|
return $this->hasMany(self::class,'parent_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function owner()
|
|
||||||
{
|
|
||||||
return $this->hasOneThrough(User::class,Account::class,'id','id','account_id','user_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/* METHODS */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all the children RTM records that this record is parent of
|
* Return all the children RTM records that this record is parent of
|
||||||
*
|
*
|
||||||
|
@ -10,7 +10,7 @@ use App\Http\Middleware\{Role,SetSite};
|
|||||||
return Application::configure(basePath: dirname(__DIR__))
|
return Application::configure(basePath: dirname(__DIR__))
|
||||||
->withRouting(
|
->withRouting(
|
||||||
web: __DIR__.'/../routes/web.php',
|
web: __DIR__.'/../routes/web.php',
|
||||||
api: __DIR__.'/../routes/api.php',
|
//api: __DIR__.'/../routes/api.php',
|
||||||
commands: __DIR__.'/../routes/console.php',
|
commands: __DIR__.'/../routes/console.php',
|
||||||
health: '/up',
|
health: '/up',
|
||||||
)
|
)
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*/
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
DB::update('ALTER TABLE usage_broadband ALTER COLUMN up_peak TYPE REAL');
|
|
||||||
DB::update('ALTER TABLE usage_broadband ALTER COLUMN down_peak TYPE REAL');
|
|
||||||
DB::update('ALTER TABLE usage_broadband ALTER COLUMN up_offpeak TYPE REAL');
|
|
||||||
DB::update('ALTER TABLE usage_broadband ALTER COLUMN down_offpeak TYPE REAL');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
// NOOP
|
|
||||||
}
|
|
||||||
};
|
|
@ -4,6 +4,6 @@ use Illuminate\Support\Facades\Schedule;
|
|||||||
|
|
||||||
use App\Jobs\BroadbandTraffic;
|
use App\Jobs\BroadbandTraffic;
|
||||||
|
|
||||||
Schedule::job(new BroadbandTraffic('exetelvisp'))
|
Schedule::job(new BroadbandTraffic(1))
|
||||||
->timezone('Australia/Melbourne')
|
->timezone('Australia/Melbourne')
|
||||||
->dailyAt('10:00');
|
->dailyAt('10:00');
|
Loading…
Reference in New Issue
Block a user