diff --git a/code/app/Formatters/GenericProductFormat.php b/code/app/Formatters/GenericProductFormat.php index f847c56b..020bfc91 100644 --- a/code/app/Formatters/GenericProductFormat.php +++ b/code/app/Formatters/GenericProductFormat.php @@ -32,6 +32,7 @@ protected static function genericColumns() $ret = []; $checked_by_default = ['name', 'price']; + foreach($attributes as $attr => $label) { $ret[$attr] = (object) [ 'name' => $label, diff --git a/code/app/Formatters/Order.php b/code/app/Formatters/Order.php index bf2744b6..291477e7 100644 --- a/code/app/Formatters/Order.php +++ b/code/app/Formatters/Order.php @@ -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 = [ @@ -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, @@ -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') { diff --git a/code/app/Http/Controllers/MovementsController.php b/code/app/Http/Controllers/MovementsController.php index 098ee857..079a8a86 100644 --- a/code/app/Http/Controllers/MovementsController.php +++ b/code/app/Http/Controllers/MovementsController.php @@ -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) { @@ -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; diff --git a/code/app/Printers/Concerns/Summary.php b/code/app/Printers/Concerns/Summary.php index dc18f022..571b8ac9 100644 --- a/code/app/Printers/Concerns/Summary.php +++ b/code/app/Printers/Concerns/Summary.php @@ -34,7 +34,7 @@ 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; } @@ -42,7 +42,7 @@ private function addModifiers($order, $summary, $status, $total, $fields, $extra 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; } @@ -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); diff --git a/code/app/Printers/Concerns/Table.php b/code/app/Printers/Concerns/Table.php index b05af380..1fca2b29 100644 --- a/code/app/Printers/Concerns/Table.php +++ b/code/app/Printers/Concerns/Table.php @@ -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()); } } }