Skip to content

Commit

Permalink
Merge branch 'master' into aggregations
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Aug 31, 2024
2 parents 6b3a210 + 1d862d1 commit 6109ebc
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 69 deletions.
60 changes: 38 additions & 22 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 Expand Up @@ -288,6 +295,15 @@ public function document(Request $request, $id, $type)
{
$printer = new Printer();
$order = Order::findOrFail($id);
return $printer->document($order, $type, $request->all());
$params = $request->all();
$ret = $printer->document($order, $type, $params);

$action = $params['action'] ?? 'download';
if ($action == 'email') {
return redirect()->route('orders.index');
}
else {
return $ret;
}
}
}
18 changes: 9 additions & 9 deletions code/app/Jobs/NotifyClosedOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ private function filesForSupplier($order)

$files = [];
foreach($types as $type) {
$files[] = $printer->document($order, $type, ['format' => 'pdf', 'status' => 'pending', 'extra_modifiers' => 0, 'send_mail' => true]);
$files[] = $printer->document($order, $type, ['format' => 'csv', 'status' => 'pending', 'extra_modifiers' => 0, 'send_mail' => true]);
foreach(['pdf', 'csv'] as $format) {
$f = $printer->document($order, $type, ['format' => $format, 'status' => 'pending', 'extra_modifiers' => 0, 'action' => 'save']);
if ($f) {
$files[] = $f;
}
}
}

return $files;
Expand Down Expand Up @@ -69,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 Expand Up @@ -116,12 +120,8 @@ public function handle()
$hub->enable(true);
$hub->setGas($gas->id);

/*
Nota: il flag send_mail serve solo a farsi restituire il
path del file generato. Cfr. il TODO in Order::document()
*/
$pdf_file_path = $printer->document($order, 'summary', ['format' => 'pdf', 'status' => 'pending', 'send_mail' => true]);
$csv_file_path = $printer->document($order, 'summary', ['format' => 'csv', 'status' => 'pending', 'send_mail' => true]);
$pdf_file_path = $printer->document($order, 'summary', ['format' => 'pdf', 'status' => 'pending', 'action' => 'save']);
$csv_file_path = $printer->document($order, 'summary', ['format' => 'csv', 'status' => 'pending', 'action' => 'save']);

$all_files[] = $pdf_file_path;
$all_files[] = $csv_file_path;
Expand Down
74 changes: 46 additions & 28 deletions code/app/Printers/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ 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);
}

protected function handleShipping($obj, $request)
{
$send_mail = isset($request['send_mail']);
$action = $request['action'] ?? 'download';
$subtype = $request['format'] ?? 'pdf';
$status = $request['status'] ?? 'pending';
$extra_modifiers = $request['extra_modifiers'] ?? 0;
Expand All @@ -63,7 +69,7 @@ protected function handleShipping($obj, $request)

enablePdfPagesNumbers($pdf);

if ($send_mail) {
if (in_array($action, ['save', 'email'])) {
$pdf->save($temp_file_path);
}
else {
Expand All @@ -79,7 +85,7 @@ protected function handleShipping($obj, $request)
}
}

if ($send_mail) {
if (in_array($action, ['save', 'email'])) {
output_csv($filename, $data->headers, $flat_contents, function($row) {
return $row;
}, $temp_file_path);
Expand All @@ -91,30 +97,27 @@ protected function handleShipping($obj, $request)
}
}

if ($send_mail) {
if ($action == 'email') {
$this->sendDocumentMail($request, $temp_file_path);
}
else if ($action == 'save') {
return $temp_file_path;
}
}

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 @@ -126,7 +129,7 @@ private function autoGuessFields($order)

protected function handleSummary($obj, $request)
{
$send_mail = isset($request['send_mail']);
$action = $request['action'] ?? 'download';
$subtype = $request['format'] ?? 'pdf';
$extra_modifiers = $request['extra_modifiers'] ?? 0;

Expand All @@ -137,13 +140,19 @@ protected function handleSummary($obj, $request)
if ($subtype == 'gdxp') {
$contents = view('gdxp.json.supplier', ['obj' => $obj->supplier, 'order' => $obj, 'bookings' => true])->render();

if ($send_mail) {
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 All @@ -167,14 +176,18 @@ protected function handleSummary($obj, $request)

$document = $this->formatSummary($obj, $document, $required_fields, $status, $circles, $extra_modifiers);

if ($send_mail) {
if ($action == 'email') {
$document->save($temp_file_path);
$this->sendDocumentMail($request, $temp_file_path);
return $temp_file_path;
}
else {
else if ($action == 'download') {
return $document->download($filename);
}
else if ($action == 'save') {
$document->save($temp_file_path);
return $temp_file_path;
}
}
}

Expand Down Expand Up @@ -205,7 +218,7 @@ private function formatTableRows($order, $circles, $status, $fields, &$all_produ

protected function handleTable($obj, $request)
{
$send_mail = isset($request['send_mail']);
$action = $request['action'] ?? 'download';
$status = $request['status'] ?? 'pending';
$include_missing = $request['include_missing'] ?? 'no';
$circles = new CirclesFilter($obj->aggregate, $request);
Expand Down Expand Up @@ -248,13 +261,18 @@ protected function handleTable($obj, $request)

$filename = sanitizeFilename(_i('Tabella Ordine %s presso %s.csv', [$obj->internal_number, $obj->supplier->name]));

if ($send_mail) {
if ($action == 'email') {
$temp_file_path = sprintf('%s/%s', sys_get_temp_dir(), $filename);
output_csv($filename, $headers, $data, null, $temp_file_path);
$this->sendDocumentMail($request, $temp_file_path);
}
else {
else if ($action == 'download') {
return output_csv($filename, $headers, $data, null);
}
else if ($action == 'save') {
$temp_file_path = sprintf('%s/%s', sys_get_temp_dir(), $filename);
output_csv($filename, $headers, $data, null, $temp_file_path);
return $temp_file_path;
}
}
}
6 changes: 4 additions & 2 deletions code/app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ protected function enforceInstance($event)
{
$payload = $this->getEventPayload($event);

\Log::debug('Inizializzazione job: ' . ($payload['env_file'] ?? '[no env]') . ' / ' . ($payload['gas_id'] ?? '[no gas]'));

$env_file = $payload['env_file'] ?? null;
if ($env_file) {
/*
Expand Down Expand Up @@ -104,6 +102,10 @@ private function initQueues()
'gas_id' => app()->make('GlobalScopeHub')->getGas(),
];

if (empty($ret['gas_id'])) {
\Log::debug(print_r(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 20), true));
}

if (global_multi_installation()) {
$ret['env_file'] = env_file();
}
Expand Down
8 changes: 5 additions & 3 deletions code/app/Receipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ public function getUserAttribute()
public function getNameAttribute()
{
$user = $this->user;
if ($user)
if ($user) {
$user_name = $user->printableName();
else
}
else {
$user_name = '???';
}

return sprintf('%s - %s', $user_name, $this->number);
return sprintf('%s - %s - %s', $user_name, printableDate($this->date), $this->number);
}

private function calculateTotal()
Expand Down
2 changes: 1 addition & 1 deletion code/public/js/gasdotto.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion code/public/js/gasdotto.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion code/public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/js/gasdotto.js": "/js/gasdotto.js?id=ce33186d70212962ea2c5d6eb5fe8d6f",
"/js/gasdotto.js": "/js/gasdotto.js?id=e57fec6faec265b43940d890548bdda5",
"/css/gasdotto.css": "/css/gasdotto.css?id=944fde138a68e0877df0d9da8e03d933"
}
2 changes: 1 addition & 1 deletion code/resources/assets/js/callables.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Callables {
*/
static collectFilteredUsers(form) {
form.find('input:hidden[name^="users"]').remove();
let table = $('#user-list');
let table = $(form.find('input:hidden[name=collectFilteredUsers]').val());

if (table.is('table')) {
$('tbody tr:visible', table).each(function() {
Expand Down
2 changes: 2 additions & 0 deletions code/resources/views/movement/credits.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<div class="modal-footer">
<form class="form-inline iblock inner-form" action="{{ url('movements/document/credits/csv?dummy=1') }}" method="GET">
<input type="hidden" name="pre-saved-function" value="collectFilteredUsers">
<input type="hidden" name="collectFilteredUsers" value="#creditsTable">
<input type="hidden" name="pre-saved-function" value="formToDownload">
<button type="submit" class="btn btn-success">{{ _i('Esporta CSV') }} <i class="bi-download"></i></button>
</form>
Expand Down Expand Up @@ -129,6 +130,7 @@
<form class="form-horizontal inner-form" method="POST" action="{{ route('notifications.store') }}">
<input type="hidden" name="close-modal" value="1">
<input type="hidden" name="pre-saved-function" value="collectFilteredUsers">
<input type="hidden" name="collectFilteredUsers" value="#creditsTable">
<input type="hidden" name="type" value="notification">

@include('notification.base-edit', [
Expand Down
2 changes: 1 addition & 1 deletion code/resources/views/order/filesmail.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<hr/>

<x-larastrap::check name="send_mail" :label="_i('Inoltra Mail')" triggers_collapse="send_mail" />
<x-larastrap::check name="action" value="email" :label="_i('Inoltra Mail')" triggers_collapse="send_mail" />

<x-larastrap::collapse id="send_mail">
<x-larastrap::field :label="_i('Destinatari')">
Expand Down
1 change: 1 addition & 0 deletions code/resources/views/pages/users.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<x-larastrap::modal id="exportCSVusers" :title="_i('Esporta CSV')" classes="close-on-submit">
<x-larastrap::iform method="GET" :action="url('users/export')" :buttons="[['label' => _i('Download'), 'type' => 'submit']]">
<input type="hidden" name="pre-saved-function" value="collectFilteredUsers">
<input type="hidden" name="collectFilteredUsers" value="#user-list">
<input type="hidden" name="pre-saved-function" value="formToDownload">

<p>
Expand Down

0 comments on commit 6109ebc

Please sign in to comment.