Add flag to print quantities as well

This commit is contained in:
Marc Ole Bulling 2021-01-15 13:20:32 +01:00
parent 039bdb58fd
commit f007b92911
No known key found for this signature in database
GPG Key ID: C126AFC2A47B06FF
2 changed files with 14 additions and 9 deletions

View File

@ -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

View File

@ -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;
}