diff --git a/services/StockService.php b/services/StockService.php index 07e24d2b..88bb55d9 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -941,33 +941,48 @@ 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()->uihelper_shopping_list()->where('shopping_list_id = :1', $listId)->fetchAll(); foreach ($rowsShoppingListProducts as $row) { - $note = ""; - if (GROCY_TPRINTER_PRINT_NOTES) { - if (isset($row["note"])) { - $note = ' (' . $row["note"] . ')'; + $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) { + $factor = floatval($conversion->factor); + } + $amount = round($row->amount * $factor); + $note = ""; + if (GROCY_TPRINTER_PRINT_NOTES) + { + if ($row->note != "") { + $note = ' (' . $row->note . ')'; } } - if (GROCY_TPRINTER_PRINT_QUANTITY_NAME) { - $quantityname = $row["qu_name"]; - if ($row["amount"] > 1) { - $quantityname = $row["qu_name_plural"]; + if (GROCY_TPRINTER_PRINT_QUANTITY_NAME) + { + $quantityname = $row->qu_name; + if ($amount > 1) + { + $quantityname = $row->qu_name_plural; } - array_push($result, $row["amount"] . ' ' . $quantityname . ' ' . $row["product_name"] . $note); - } else { - array_push($result, $row["amount"] . ' ' . $row["product_name"] . $note); + array_push($result, $amount . ' ' . $quantityname . ' ' . $row->product_name . $note); + } + else + { + array_push($result, $amount . ' ' . $row->product_name . $note); } } return $result; } + public function TransferProduct(int $productId, float $amount, int $locationIdFrom, int $locationIdTo, $specificStockEntryId = 'default', &$transactionId = null) { if (!$this->ProductExists($productId))