Added quantity conversion

This commit is contained in:
Marc Ole Bulling 2021-01-15 13:59:45 +01:00
parent a8142fed05
commit 983ab48945
No known key found for this signature in database
GPG Key ID: C126AFC2A47B06FF

View File

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