Fix usage_broadband, since our usage data is a float
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 31s
Create Docker Image / Final Docker Image Manifest (push) Successful in 9s

This commit is contained in:
2024-07-26 14:45:43 +10:00
parent 667109150d
commit 1c4cb6f38c
5 changed files with 73 additions and 24 deletions

View File

@@ -5,24 +5,22 @@ 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\Supplier;
use App\Models\{Rtm,Supplier};
use App\Models\Service\Broadband as ServiceBroadband;
use App\Models\Usage\Broadband as UsageBroadband;
/**
* Class BroadbandTraffic
* Read and update the traffic for an Broadband supplier
* Read and update the traffic for a Broadband supplier
*
* @package App\Jobs
*/
@@ -32,15 +30,11 @@ 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(int $sid)
{
$this->sid = $sid;
}
public function __construct(private string $supplier) {}
/**
* Execute the job.
@@ -50,12 +44,19 @@ final class BroadbandTraffic implements ShouldQueue
*/
public function handle()
{
$so = Supplier::findOrFail($this->sid);
$so = Supplier::active()
->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));
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
@@ -95,15 +96,16 @@ 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(DB::raw('service_broadband.*'))
->join('services','services.id','=','service_id')
->select('service_broadband.*')
->join('services',['service_broadband.service_id'=>'services.id'])
->where('services.start_at','<=',$date)
->where(function($query) use ($date) {
->where(fn($query)=>
$query->whereNULL('services.stop_at')
->orWhere('services.stop_at','<=',$date);
})
->orWhere('services.stop_at','>=',$date)
)
->single();
$to = new UsageBroadband;
@@ -149,7 +151,7 @@ final class BroadbandTraffic implements ShouldQueue
if ($u) {
if ($so->trafficMismatch($date)->count())
Mail::to('deon@graytech.net.au') // @todo To change
Mail::to($ro->owner->email)
->send(new TrafficMismatch($so,$date));
}
}