Skip to content

Commit

Permalink
qualche fix in inoltro email documenti ordini
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Aug 13, 2024
1 parent a3381a3 commit 89494e8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
11 changes: 10 additions & 1 deletion code/app/Http/Controllers/OrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,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;
}
}
}
16 changes: 8 additions & 8 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 @@ -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
34 changes: 23 additions & 11 deletions code/app/Printers/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private function sendDocumentMail($request, $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 Down Expand Up @@ -80,7 +80,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 @@ -96,7 +96,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 @@ -108,9 +108,12 @@ 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)
Expand Down Expand Up @@ -143,7 +146,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 @@ -154,7 +157,7 @@ protected function handleSummary($obj, $request)
if ($subtype == 'gdxp') {
$contents = view('gdxp.json.supplier', ['obj' => $obj->supplier, 'order' => $obj, 'bookings' => true])->render();

if ($send_mail) {
if (in_array($action, ['save', 'email'])) {
file_put_contents($temp_file_path, $contents);
}
else {
Expand Down Expand Up @@ -187,14 +190,18 @@ protected function handleSummary($obj, $request)

$document = $this->formatSummary($obj, $document, $required_fields, $status, $shipping_place, $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 @@ -223,7 +230,7 @@ private function formatTableRows($order, $shipping_place, $status, $fields, &$al

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';
$shipping_place = $request['shipping_place'] ?? 0;
Expand Down Expand Up @@ -266,13 +273,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;
}
}
}
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

0 comments on commit 89494e8

Please sign in to comment.