Compare commits

..

1 Commits

Author SHA1 Message Date
73baa2f153 Added API stub configuration
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 33s
Create Docker Image / Final Docker Image Manifest (push) Successful in 10s
2024-07-26 12:34:35 +10:00
6 changed files with 25 additions and 74 deletions

View File

@ -3,7 +3,6 @@
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use App\Jobs\BroadbandTraffic as Job;
use App\Models\Supplier;
@ -16,7 +15,7 @@ class BroadbandTraffic extends Command
* @var string
*/
protected $signature = 'broadband:traffic:import'.
' {supplier? : Supplier Name}';
' {--s|supplier= : Supplier Name}';
/**
* The console command description.
@ -32,26 +31,14 @@ class BroadbandTraffic extends Command
*/
public function handle()
{
if ($this->argument('supplier')) {
try {
$o = Supplier::active()
->where('name','ilike',$this->argument('supplier'))
->sole();
if ($this->option('supplier')) {
$o = Supplier::where('name','ilike',$this->option('supplier'))->singleOrFail();
} catch (ModelNotFoundException $e) {
$this->error(sprintf('Supplier [%s] not found',$this->argument('supplier')));
return self::FAILURE;
}
Job::dispatchSync($o->name);
return self::SUCCESS;
Job::dispatchSync($o->id);
return;
}
foreach (Supplier::active()->get() as $o)
Job::dispatchSync($o->name);
return self::SUCCESS;
Job::dispatchSync($o->id);
}
}

View File

@ -5,22 +5,24 @@ namespace App\Jobs;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use App\Classes\External\Supplier as ExternalSupplier;
use App\Mail\TrafficMismatch;
use App\Models\{Rtm,Supplier};
use App\Models\Supplier;
use App\Models\Service\Broadband as ServiceBroadband;
use App\Models\Usage\Broadband as UsageBroadband;
/**
* Class BroadbandTraffic
* Read and update the traffic for a Broadband supplier
* Read and update the traffic for an Broadband supplier
*
* @package App\Jobs
*/
@ -30,11 +32,15 @@ final class BroadbandTraffic implements ShouldQueue
private const LOGKEY = 'JBT';
protected int $sid; // The supplier we are updating from
private const class_prefix = 'App\Classes\External\Supplier\\';
private const traffic = 'broadband';
public function __construct(private string $supplier) {}
public function __construct(int $sid)
{
$this->sid = $sid;
}
/**
* Execute the job.
@ -44,19 +50,12 @@ final class BroadbandTraffic implements ShouldQueue
*/
public function handle()
{
$so = Supplier::active()
->where('name','ilike',$this->supplier)
->sole();
// Wholesaler email
$ro = Rtm::where('parent_id',NULL)->sole();
$so = Supplier::findOrFail($this->sid);
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))
throw new \Exception('No or missing connection details for:'.self::traffic);
// Count of updated records
$u = 0;
// Load our class for this supplier
@ -96,16 +95,15 @@ final class BroadbandTraffic implements ShouldQueue
try {
$date = Carbon::createFromFormat('Y-m-d',$row[$o->getColumnKey('Date')]);
// Find the right service dependent on the dates we supplied the service
$oo = ServiceBroadband::where('service_username',$row[$o->getColumnKey('Login')])
->select('service_broadband.*')
->join('services',['service_broadband.service_id'=>'services.id'])
->select(DB::raw('service_broadband.*'))
->join('services','services.id','=','service_id')
->where('services.start_at','<=',$date)
->where(fn($query)=>
->where(function($query) use ($date) {
$query->whereNULL('services.stop_at')
->orWhere('services.stop_at','>=',$date)
)
->orWhere('services.stop_at','<=',$date);
})
->single();
$to = new UsageBroadband;
@ -151,7 +149,7 @@ final class BroadbandTraffic implements ShouldQueue
if ($u) {
if ($so->trafficMismatch($date)->count())
Mail::to($ro->owner->email)
Mail::to('deon@graytech.net.au') // @todo To change
->send(new TrafficMismatch($so,$date));
}
}

View File

@ -25,13 +25,6 @@ class Rtm extends Model
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
*

View File

@ -10,7 +10,7 @@ use App\Http\Middleware\{Role,SetSite};
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php',
//api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)

View File

@ -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
}
};

View File

@ -4,6 +4,6 @@ use Illuminate\Support\Facades\Schedule;
use App\Jobs\BroadbandTraffic;
Schedule::job(new BroadbandTraffic('exetelvisp'))
Schedule::job(new BroadbandTraffic(1))
->timezone('Australia/Melbourne')
->dailyAt('10:00');