Fix broadband traffic import, when new services cannot be found. Fix broadband update so that start_at = connect_at

This commit is contained in:
Deon George 2022-09-29 11:22:16 +10:00
parent 5b4aa5c73e
commit 1667b8c1df
2 changed files with 14 additions and 3 deletions

View File

@ -12,6 +12,7 @@ use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
use Illuminate\View\View;
use Symfony\Component\HttpKernel\Exception\HttpException;
@ -391,6 +392,7 @@ class ServiceController extends Controller
* @param Request $request
* @param Service $o
* @return RedirectResponse
* @throws ValidationException
*/
public function update(Request $request,Service $o)
{
@ -418,8 +420,17 @@ class ServiceController extends Controller
$o->invoice_next_at = $request->invoice_next_at;
// Also update our service start_at date.
// @todo We may want to make start_at/stop_at dynamic values calculated by the type records
if ($request->post('start_at'))
$o->start_at = $request->start_at;
else {
// For broadband, start_at is connect_at in the type record
switch ($o->category) {
case 'broadband':
$o->start_at = $o->type->connect_at;
break;
}
}
$o->save();

View File

@ -106,7 +106,6 @@ final class BroadbandTraffic implements ShouldQueue
->single();
$to = new UsageBroadband;
$to->site_id = $oo->site_id;
$to->date = $last_update;
$to->supplier_id = $this->o->id;
$to->up_peak = $row[$o->getColumnKey('Peak upload')];
@ -122,8 +121,10 @@ final class BroadbandTraffic implements ShouldQueue
Log::error(sprintf('%s:Too many services return for [%s]',self::LOGKEY,$row[$o->getColumnKey('Login')]),['date'=>$date,'count'=>$oo->count()]);
$to->service = $row[$o->getColumnKey('Login')];
$to->site_id = 1; // @todo This needs to be worked out a better way
} else {
$to->site_id = $oo->site_id;
$to->service_item_id = $oo->id;
}
@ -131,9 +132,8 @@ final class BroadbandTraffic implements ShouldQueue
$u++;
} catch (\Exception $e) {
dump($to);
Log::error(sprintf('%s:Exception occurred when storing traffic record for [%s].',self::LOGKEY,$row[$o->getColumnKey('Login')]),['row'=>$row,'line'=>$line]);
throw new \Exception('Error while storing traffic date');
throw new \Exception('Error while storing traffic data: '.$e->getMessage());
}
}
Log::info(sprintf('%s: Records Imported [%d] for [%s]',self::LOGKEY,$u,$last_update->format('Y-m-d')));