Skip to content

Commit

Permalink
altro fix in notifiche chiusura ordini
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed May 21, 2024
1 parent 9622bb1 commit 16c4150
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
18 changes: 14 additions & 4 deletions code/app/Console/Commands/CloseOrders.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
4 changes: 2 additions & 2 deletions code/app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ 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;
if ($gas_id) {
app()->make('GlobalScopeHub')->setGas($gas_id);
}
else {
\Log::error('Job senza GAS definito!');
\Log::error('Job ' . get_class($event) . ' senza GAS definito!');
}

/*
Expand Down

0 comments on commit 16c4150

Please sign in to comment.