From 4b43f2a0a718fa7e2618915a243e9b7cf7feb524 Mon Sep 17 00:00:00 2001 From: Roberto Guido Date: Tue, 13 Aug 2024 12:02:41 +0200 Subject: [PATCH] fix minori --- .../app/Http/Controllers/OrdersController.php | 49 +++++++++++-------- code/app/Jobs/NotifyClosedOrder.php | 2 +- code/app/Printers/Order.php | 42 +++++++++------- 3 files changed, 53 insertions(+), 40 deletions(-) diff --git a/code/app/Http/Controllers/OrdersController.php b/code/app/Http/Controllers/OrdersController.php index 30ef3c64..efe1360a 100644 --- a/code/app/Http/Controllers/OrdersController.php +++ b/code/app/Http/Controllers/OrdersController.php @@ -44,6 +44,33 @@ public function __construct(OrdersService $service) ]); } + private function rssItem($feed, $aggregate) + { + $summary = ''; + + foreach($aggregate->orders as $order) { + $summary .= $order->printableName() . "\n"; + + foreach($order->products as $product) { + $summary .= $product->printableName() . "\n"; + } + + $summary .= "\n"; + } + + $author = new Author(); + $author->setName($aggregate->gas->first()->printableName()); + + $item = $feed->newItem(); + $item->setTitle($aggregate->printableName()); + $item->setAuthor($author); + $item->setLink($aggregate->getBookingURL()); + $item->setLastModified($aggregate->updated_at); + $item->setContent($summary); + + return $item; + } + public function rss(Request $request) { $aggregates = getOrdersByStatus(null, 'open'); @@ -62,27 +89,7 @@ public function rss(Request $request) continue; } - $summary = ''; - - foreach($aggregate->orders as $order) { - $summary .= $order->printableName() . "\n"; - - foreach($order->products as $product) { - $summary .= $product->printableName() . "\n"; - } - - $summary .= "\n"; - } - - $author = new Author(); - $author->setName($aggregate->gas->first()->printableName()); - - $item = $feed->newItem(); - $item->setTitle($aggregate->printableName()); - $item->setAuthor($author); - $item->setLink($aggregate->getBookingURL()); - $item->setLastModified($aggregate->updated_at); - $item->setContent($summary); + $item = $this->rssItem($feed, $aggregate); $feed->add($item); } diff --git a/code/app/Jobs/NotifyClosedOrder.php b/code/app/Jobs/NotifyClosedOrder.php index 2ff57c2a..9bd589e6 100644 --- a/code/app/Jobs/NotifyClosedOrder.php +++ b/code/app/Jobs/NotifyClosedOrder.php @@ -73,7 +73,7 @@ private function dispatchToSupplier($order) $hub->enable(true); } catch(\Exception $e) { - \Log::error('Errore in notifica chiusura ordine a fornitore: ' . $e->getMessage() . "\n" . $e->getTraceAsString()); + \Log::error('Errore in notifica chiusura ordine a fornitore: ' . $e->getMessage()); } break; diff --git a/code/app/Printers/Order.php b/code/app/Printers/Order.php index f227dc55..6a400b7f 100644 --- a/code/app/Printers/Order.php +++ b/code/app/Printers/Order.php @@ -38,7 +38,13 @@ private function sendDocumentMail($request, $temp_file_path) return; } - Mail::to($real_recipient_mails)->send(new GenericOrderShipping($temp_file_path, $request['subject_mail'], $request['body_mail'])); + try { + Mail::to($real_recipient_mails)->send(new GenericOrderShipping($temp_file_path, $request['subject_mail'], $request['body_mail'])); + } + catch(\Exception $e) { + \Log::error('Impossibile inoltrare documento ordine: ' . $e->getMessage()); + } + @unlink($temp_file_path); } @@ -120,21 +126,15 @@ private function autoGuessFields($order) { $guessed_fields = []; - foreach($order->products as $product) { - if (empty($product->code) == false) { - $guessed_fields[] = 'code'; - break; - } + if ($order->products->filter(fn($p) => empty($p->code) == false)->count() != 0) { + $guessed_fields[] = 'code'; } $guessed_fields[] = 'name'; $guessed_fields[] = 'quantity'; - foreach($order->products as $product) { - if ($product->package_size != 0) { - $guessed_fields[] = 'boxes'; - break; - } + if ($order->products->filter(fn($p) => $p->package_size != 0)->count() != 0) { + $guessed_fields[] = 'boxes'; } $guessed_fields[] = 'measure'; @@ -157,13 +157,19 @@ protected function handleSummary($obj, $request) if ($subtype == 'gdxp') { $contents = view('gdxp.json.supplier', ['obj' => $obj->supplier, 'order' => $obj, 'bookings' => true])->render(); - if (in_array($action, ['save', 'email'])) { - file_put_contents($temp_file_path, $contents); - } - else { - download_headers('application/json', $filename); - return $contents; - } + if ($action == 'email') { + file_put_contents($temp_file_path, $contents); + $this->sendDocumentMail($request, $temp_file_path); + return $temp_file_path; + } + else if ($action == 'download') { + download_headers('application/json', $filename); + return $contents; + } + else if ($action == 'save') { + file_put_contents($temp_file_path, $contents); + return $temp_file_path; + } } else { $status = $request['status'];