diff --git a/code/app/Console/Commands/CloseOrders.php b/code/app/Console/Commands/CloseOrders.php index 7e558b30..a8b57e39 100644 --- a/code/app/Console/Commands/CloseOrders.php +++ b/code/app/Console/Commands/CloseOrders.php @@ -17,21 +17,31 @@ public function handle() { $today = Carbon::today()->format('Y-m-d'); $orders = Order::withoutGlobalScopes()->where('status', 'open')->where('end', '<', $today)->get(); - $closed = []; + $notifications = []; foreach($orders as $order) { try { $order->status = 'closed'; $order->save(); - $closed[] = $order->id; + + foreach($order->aggregate->gas as $gas) { + if (isset($notifications[$gas->id]) == false) { + $notifications[$gas->id] = []; + } + + $notifications[$gas->id][] = $order->id; + } } catch(\Exception $e) { \Log::error('Errore in chiusura automatica ordine: ' . $e->getMessage()); } } - if (empty($closed) == false) { - NotifyClosedOrder::dispatch($closed); + $hub = app()->make('GlobalScopeHub'); + + foreach($notifications as $gas_id => $orders) { + $hub->setGas($gas_id); + NotifyClosedOrder::dispatch($orders); } } } diff --git a/code/app/Providers/AppServiceProvider.php b/code/app/Providers/AppServiceProvider.php index 140168df..24e130a4 100644 --- a/code/app/Providers/AppServiceProvider.php +++ b/code/app/Providers/AppServiceProvider.php @@ -71,7 +71,7 @@ protected function enforceInstance($event) URL::forceRootUrl(env('APP_URL')); } else { - \Log::error('Job senza env file definito!'); + \Log::error('Job ' . get_class($event) . ' senza env file definito!'); } $gas_id = $payload['gas_id'] ?? null; @@ -79,7 +79,7 @@ protected function enforceInstance($event) app()->make('GlobalScopeHub')->setGas($gas_id); } else { - \Log::error('Job senza GAS definito!'); + \Log::error('Job ' . get_class($event) . ' senza GAS definito!'); } /*