From 1c1adc5f8917291b9e418cc98b4d587288a32fd8 Mon Sep 17 00:00:00 2001 From: Marc Ole Bulling Date: Fri, 15 Jan 2021 14:32:52 +0100 Subject: [PATCH] Formatting --- services/StockService.php | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/services/StockService.php b/services/StockService.php index 5eed7595..f1f53618 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -941,8 +941,10 @@ class StockService extends BaseService * @return string[] Returns an array in the format "[amount] [name of product]" * @throws \Exception */ - public function GetShoppinglistInPrintableStrings($listId = 1): array { - if (!$this->ShoppingListExists($listId)) { + public function GetShoppinglistInPrintableStrings($listId = 1): array + { + if (!$this->ShoppingListExists($listId)) + { throw new \Exception('Shopping list does not exist'); } @@ -953,39 +955,50 @@ class StockService extends BaseService $product = $this->getDatabase()->products()->where('id = :1', $row->product_id)->fetch(); $conversion = $this->getDatabase()->quantity_unit_conversions_resolved()->where('product_id = :1 AND from_qu_id = :2 AND to_qu_id = :3', $product->id, $product->qu_id_stock, $row->qu_id)->fetch(); $factor = 1.0; - if ($conversion != null) { + if ($conversion != null) + { $factor = floatval($conversion->factor); } $amount = round($row->amount * $factor); $note = ""; - if (GROCY_TPRINTER_PRINT_NOTES) { - if ($row->note != "") { + if (GROCY_TPRINTER_PRINT_NOTES) + { + if ($row->note != "") + { $note = ' (' . $row->note . ')'; } } - if (GROCY_TPRINTER_PRINT_QUANTITY_NAME) { + if (GROCY_TPRINTER_PRINT_QUANTITY_NAME) + { $quantityname = $row->qu_name; - if ($amount > 1) { + if ($amount > 1) + { $quantityname = $row->qu_name_plural; } array_push($result_quantity, $amount . ' ' . $quantityname); array_push($result_product, $row->product_name . $note); - } else { + } + else + { array_push($result_quantity, $amount); array_push($result_product, $row->product_name . $note); } } //Add padding to look nicer $maxlength = 1; - foreach ($result_quantity as $quantity) { + foreach ($result_quantity as $quantity) + { if (strlen($quantity) > $maxlength) + { $maxlength = strlen($quantity); + } } $result = array(); $length = count($result_quantity); - for ($i = 0; $i < $length; $i++) { + for ($i = 0; $i < $length; $i++) + { $quantity = str_pad($result_quantity[$i], $maxlength); - array_push($result, $quantity . ' ' . $result_product[$i]); + array_push($result, $quantity . ' ' . $result_product[$i]); } return $result; }