Skip to content

Commit

Permalink
modificata formattazione prezzi in documenti csv degli ordini. closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Feb 7, 2024
1 parent f46db92 commit 74b5ead
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 74 deletions.
1 change: 1 addition & 0 deletions code/app/Formatters/GenericProductFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected static function genericColumns()

$ret = [];
$checked_by_default = ['name', 'price'];

foreach($attributes as $attr => $label) {
$ret[$attr] = (object) [
'name' => $label,
Expand Down
162 changes: 95 additions & 67 deletions code/app/Formatters/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,91 @@

class Order extends Formatter
{
private static function formatCode()
{
return (object) [
'name' => _i('Codice Fornitore'),
'format_product' => function($product, $summary) {
return $product->supplier_code;
},
'format_variant' => function($product, $summary) {
if (!empty($summary->variant->supplier_code)) {
return $summary->variant->supplier_code;
}
else {
return $summary->variant->product->product->supplier_code;
}
}
];
}

private static function formatQuantity()
{
return (object) [
'name' => _i('Quantità'),
'checked' => true,
'format_product' => function($product, $summary, $alternate = false) {
if ($alternate == false)
return printableQuantity($summary->quantity_pieces, $product->measure->discrete, 2, ',');
else
return printableQuantity($summary->delivered_pieces, $product->measure->discrete, 2, ',');
},
];
}

private static function formatBoxes()
{
return (object) [
'name' => _i('Numero Confezioni'),
'format_product' => function($product, $summary, $alternate = false) {
if ($product->package_size != 0) {
if ($alternate == false)
return $summary->quantity_pieces / $product->package_size;
else
return $summary->delivered_pieces / $product->package_size;
}
else {
return '';
}
},
];
}

private static function formatMeasure()
{
return (object) [
'name' => _i('Unità di Misura'),
'checked' => true,
'format_product' => function($product, $summary, $alternate = false) {
if ($alternate == false) {
return $product->printableMeasure(true);
}
else {
if ($product->portion_quantity != 0) {
return $product->measure->name;
}
else {
return $product->printableMeasure(true);
}
}
},
];
}

private static function formatPrice()
{
return (object) [
'name' => _i('Prezzo'),
'checked' => true,
'format_product' => function($product, $summary, $alternate = false) {
if ($alternate == false)
return printablePrice($summary->price);
else
return printablePrice($summary->price_delivered);
},
];
}

public static function formattableColumns($type = null)
{
$ret = [
Expand All @@ -30,61 +115,12 @@ public static function formattableColumns($type = null)
return $product->supplier->printableName();
},
],
'code' => (object) [
'name' => _i('Codice Fornitore'),
'format_product' => function($product, $summary) {
return $product->supplier_code;
},
'format_variant' => function($product, $summary) {
if (!empty($summary->variant->supplier_code)) {
return $summary->variant->supplier_code;
}
else {
return $summary->variant->product->product->supplier_code;
}
}
],
'quantity' => (object) [
'name' => _i('Quantità'),
'checked' => true,
'format_product' => function($product, $summary, $alternate = false) {
if ($alternate == false)
return printableQuantity($summary->quantity_pieces, $product->measure->discrete, 2, ',');
else
return printableQuantity($summary->delivered_pieces, $product->measure->discrete, 2, ',');
},
],
'boxes' => (object) [
'name' => _i('Numero Confezioni'),
'format_product' => function($product, $summary, $alternate = false) {
if ($product->package_size != 0) {
if ($alternate == false)
return $summary->quantity_pieces / $product->package_size;
else
return $summary->delivered_pieces / $product->package_size;
}
else {
return '';
}
},
],
'measure' => (object) [
'name' => _i('Unità di Misura'),
'checked' => true,
'format_product' => function($product, $summary, $alternate = false) {
if ($alternate == false) {
return $product->printableMeasure(true);
}
else {
if ($product->portion_quantity != 0) {
return $product->measure->name;
}
else {
return $product->printableMeasure(true);
}
}
},
],

'code' => static::formatCode(),
'quantity' => static::formatQuantity(),
'boxes' => static::formatBoxes(),
'measure' => static::formatMeasure(),

'category' => (object) [
'name' => _i('Categoria'),
'checked' => false,
Expand All @@ -96,22 +132,14 @@ public static function formattableColumns($type = null)
'name' => _i('Prezzo Unitario'),
'checked' => false,
'format_product' => function($product, $summary) {
return printablePrice($product->getPrice(), ',');
return printablePrice($product->getPrice());
},
'format_variant' => function($product, $summary) {
return printablePrice($summary->variant->unitPrice(), ',');
return printablePrice($summary->variant->unitPrice());
}
],
'price' => (object) [
'name' => _i('Prezzo'),
'checked' => true,
'format_product' => function($product, $summary, $alternate = false) {
if ($alternate == false)
return printablePrice($summary->price, ',');
else
return printablePrice($summary->price_delivered, ',');
},
],

'price' => static::formatPrice(),
];

if ($type == 'summary') {
Expand Down
4 changes: 2 additions & 2 deletions code/app/Http/Controllers/MovementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public function document(Request $request, $type, $subtype = 'none')
$row[] = $user->email;

foreach($currencies as $curr) {
$row[] = printablePrice($user->currentBalanceAmount($curr), ',');
$row[] = printablePrice($user->currentBalanceAmount($curr));
}

if ($has_fee) {
Expand Down Expand Up @@ -388,7 +388,7 @@ public function document(Request $request, $type, $subtype = 'none')
$row[] = $supplier->printableName();

foreach($currencies as $curr) {
$row[] = printablePrice($supplier->currentBalanceAmount($curr), ',');
$row[] = printablePrice($supplier->currentBalanceAmount($curr));
}

return $row;
Expand Down
6 changes: 3 additions & 3 deletions code/app/Printers/Concerns/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ private function addModifiers($order, $summary, $status, $total, $fields, $extra
foreach (ModifiedValue::aggregateByType($modifiers) as $am) {
$mod_row = array_fill(0, count($fields), '');
$mod_row[0] = $am->name;
$mod_row[$price_offset] = printablePrice($am->amount, ',');
$mod_row[$price_offset] = printablePrice($am->amount);
$rows[] = $mod_row;
$total += $am->amount;
}

if (empty($rows) == false) {
$last_row = array_fill(0, count($fields), '');
$last_row[0] = _i('Totale con Modificatori');
$last_row[$price_offset] = printablePrice($total, ',');
$last_row[$price_offset] = printablePrice($total);
$rows[] = $last_row;
}

Expand Down Expand Up @@ -75,7 +75,7 @@ private function formatSummaryShipping($order, $fields, $status, $shipping_place
if (is_null($price_offset) == false) {
$last_row = array_fill(0, count($fields), '');
$last_row[0] = _i('Totale');
$last_row[$price_offset] = printablePrice($total, ',');
$last_row[$price_offset] = printablePrice($total);
$rows[] = $last_row;

$modifiers_rows = $this->addModifiers($order, $summary, $status, $total, $fields, $extra_modifiers);
Expand Down
4 changes: 2 additions & 2 deletions code/app/Printers/Concerns/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ protected function formatTableHead($user_columns, $orders)
if ($product->variants->isEmpty()) {
$all_products[$product->id] = 0;
$headers[] = $product->printableName();
$prices_rows[] = printablePrice($product->getPrice(), ',');
$prices_rows[] = printablePrice($product->getPrice());
}
else {
foreach($product->variant_combos as $combo) {
$all_products[$product->id . '-' . $combo->id] = 0;
$headers[] = $combo->printableName();
$prices_rows[] = printablePrice($combo->getPrice(), ',');
$prices_rows[] = printablePrice($combo->getPrice());
}
}
}
Expand Down

0 comments on commit 74b5ead

Please sign in to comment.