From f007b92911bb805accf3d35e302ee916494826fa Mon Sep 17 00:00:00 2001 From: Marc Ole Bulling Date: Fri, 15 Jan 2021 13:20:32 +0100 Subject: [PATCH] Add flag to print quantities as well --- config-dist.php | 1 + services/StockService.php | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/config-dist.php b/config-dist.php index 181ce782..9b9d7847 100644 --- a/config-dist.php +++ b/config-dist.php @@ -98,6 +98,7 @@ Setting('DEFAULT_PERMISSIONS', ['ADMIN']); // When using a thermal printer (thermal printers are receipt printers, not regular printers) // The printer must support the ESC/POS protocol, see https://github.com/mike42/escpos-php Setting('TPRINTER_IS_NETWORK_PRINTER', false); // Set to true if it is a network printer +Setting('TPRINTER_PRINT_QUANTITY_NAME', true); // Set to true if you want to print the quantity name as well //Configuration below for network printers. If you are using a USB/serial printer, skip to next section Setting('TPRINTER_IP', '127.0.0.1'); // IP of the network printer Setting('TPRINTER_PORT', 9100); // Port of printer, eg. 9100 diff --git a/services/StockService.php b/services/StockService.php index ce5b2fa0..e375360a 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -941,19 +941,23 @@ 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'); } $result = array(); - $rowsShoppingListProducts = $this->getDatabase()->shopping_list()->where('shopping_list_id = :1', $listId)->fetchAll(); - foreach ($rowsShoppingListProducts as $row) - { - $product = $this->getDatabase()->products()->where('id = :1', $row['product_id'])->fetch(); - array_push($result, $row["amount"] . " " . $product["name"]); + $rowsShoppingListProducts = $this->getDatabase()->uihelper_shopping_list()->where('shopping_list_id = :1', $listId)->fetchAll(); + foreach ($rowsShoppingListProducts as $row) { + if (GROCY_TPRINTER_PRINT_QUANTITY_NAME) { + $quantityname = $row["qu_name"]; + if ($row["amount"] > 1) { + $quantityname = $row["qu_name_plural"]; + } + array_push($result, $row["amount"] . ' ' . $quantityname . ' ' . $row["product_name"]); + } else { + array_push($result, $row["amount"] . ' ' . $row["product_name"]); + } } return $result; }