Skip to content

Commit

Permalink
fix minori
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Aug 13, 2024
1 parent 89494e8 commit 4b43f2a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 40 deletions.
49 changes: 28 additions & 21 deletions code/app/Http/Controllers/OrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion code/app/Jobs/NotifyClosedOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
42 changes: 24 additions & 18 deletions code/app/Printers/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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';
Expand All @@ -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'];
Expand Down

0 comments on commit 4b43f2a

Please sign in to comment.