Skip to content

Commit

Permalink
possibilità di non includere i prodotti non prenotati nella tabella c…
Browse files Browse the repository at this point in the history
…omplessiva prodotti. closes #258
  • Loading branch information
madbob committed Feb 18, 2024
1 parent e56d6b0 commit 87162a6
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 6 deletions.
6 changes: 6 additions & 0 deletions code/app/Printers/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ private function formatTableRows($aggregate, $shipping_place, $status, $fields,
protected function handleTable($obj, $request)
{
$status = $request['status'] ?? 'pending';
$include_missing = $request['include_missing'] ?? 'no';
$shipping_place = $request['shipping_place'] ?? 0;

$required_fields = $request['fields'] ?? [];
Expand Down Expand Up @@ -283,6 +284,11 @@ protected function handleTable($obj, $request)
$data[] = $row;
$data[] = $headers;

if ($include_missing == 'no') {
$data = $this->compressTable($user_columns, $data);
$headers = $data[count($data) - 1];
}

/*
Genero documento
*/
Expand Down
47 changes: 41 additions & 6 deletions code/app/Printers/Concerns/Table.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php

/*
Classe per formattare la "Tabella Complessiva Prodotti" di ordini e
aggregati
*/

namespace App\Printers\Concerns;

trait Table
Expand Down Expand Up @@ -42,24 +47,22 @@ protected function formatBookingInTable($order, $booking, $status, &$all_product

foreach ($order->products as $product) {
if ($product->variants->isEmpty()) {
$quantity = 0;

if ($booking) {
$quantity = $booking->$get_function($product, false, true);
}
else {
$quantity = 0;
}

$all_products[$product->id] += $quantity;
$row[] = printableQuantity($quantity, $product->measure->discrete, 3, ',');
}
else {
foreach($product->variant_combos as $combo) {
$quantity = 0;

if ($booking) {
$quantity = $booking->$get_function($combo, false, true);
}
else {
$quantity = 0;
}

$all_products[$product->id . '-' . $combo->id] += $quantity;
$row[] = printableQuantity($quantity, $product->measure->discrete, 3, ',');
Expand Down Expand Up @@ -93,4 +96,36 @@ protected function formatTableFooter($orders, $user_columns, $all_products, $tot
$row[] = printablePrice($total_price);
return $row;
}

/*
Per eliminare, ove richiesto, le colonne dei prodotti non prenotati (con
prezzo totale = 0)
*/
protected function compressTable($user_columns, $data)
{
$compressed = [];

$user_columns_count = count($user_columns);
foreach($data as $index => $row) {
$compressed[] = array_slice($row, 0, $user_columns_count);
}

/*
Qui si assume che la riga coi totali sia la penultima, perché
l'ultima contiene una ripetizione della riga di intestazione coi
nomi dei prodotti
*/
$reference_row = $data[count($data) - 2];
$len = count($reference_row);

for ($i = count($user_columns); $i < $len; $i++) {
if (translateNumberFormat($reference_row[$i]) != 0) {
foreach($data as $index => $row) {
$compressed[$index][] = $row[$i];
}
}
}

return $compressed;
}
}
6 changes: 6 additions & 0 deletions code/app/Printers/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ protected function handleTable($obj, $request)
{
$send_mail = isset($request['send_mail']);
$status = $request['status'] ?? 'pending';
$include_missing = $request['include_missing'] ?? 'no';
$shipping_place = $request['shipping_place'] ?? 0;

$required_fields = $request['fields'] ?? [];
Expand Down Expand Up @@ -255,6 +256,11 @@ protected function handleTable($obj, $request)
$data[] = $row;
$data[] = $headers;

if ($include_missing == 'no') {
$data = $this->compressTable($user_columns, $data);
$headers = $data[count($data) - 1];
}

/*
Genero documento
*/
Expand Down
1 change: 1 addition & 0 deletions code/resources/views/aggregate/exporttable.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<x-larastrap::checks name="fields" :label="_i('Dati Utenti')" :options="$options" :value="$currentgas->orders_shipping_user_columns" />

<x-larastrap::radios name="status" :label="_i('Stato Prenotazioni')" :options="['pending' => _i('Prenotate'), 'shipped' => _i('Consegnate'), 'saved' => _i('Salvate')]" value="pending" />
<x-larastrap::radios name="include_missing" :label="_i('Includi Prodotti non Prenotati')" :options="['yes' => _i('Sì'), 'no' => _i('No')]" value="no" />
</x-larastrap::form>
</x-larastrap::modal>
1 change: 1 addition & 0 deletions code/resources/views/order/exporttable.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<x-larastrap::checks name="fields" :label="_i('Dati Utenti')" :options="$options" :value="$currentgas->orders_shipping_user_columns" />

<x-larastrap::radios name="status" :label="_i('Stato Prenotazioni')" :options="['pending' => _i('Prenotate'), 'shipped' => _i('Consegnate'), 'saved' => _i('Salvate')]" value="pending" />
<x-larastrap::radios name="include_missing" :label="_i('Includi Prodotti non Prenotati')" :options="['yes' => _i('Sì'), 'no' => _i('No')]" value="no" />

@include('order.filesmail', ['contacts' => $order->supplier->involvedEmails()])
</x-larastrap::form>
Expand Down

0 comments on commit 87162a6

Please sign in to comment.