Fixed missing shopping_location_id on stock transfer actions (fixes #1408)

This commit is contained in:
Bernd Bestel 2021-06-27 20:55:38 +02:00
parent 5153818b4e
commit acb81187d9
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 15 additions and 10 deletions

View File

@ -31,6 +31,7 @@
- Fixed that the transfer page was not fully populated when opening it from the stock entries page - Fixed that the transfer page was not fully populated when opening it from the stock entries page
- Fixed that undoing a consume/open action from the success notification on the stock entries page was not possible - Fixed that undoing a consume/open action from the success notification on the stock entries page was not possible
- Fixed that adding a barcode to a product didn't save the selected quantity unit when the product only has a single one - Fixed that adding a barcode to a product didn't save the selected quantity unit when the product only has a single one
- Fixed that the store information on a stock entry was lost when transferring a partial amount to a different location
### Shopping list improvements/fixes ### Shopping list improvements/fixes
- The amount now defaults to `1` for adding items quicker - The amount now defaults to `1` for adding items quicker

View File

@ -983,26 +983,27 @@ class StockService extends BaseService
throw new \Exception('Shopping list does not exist'); throw new \Exception('Shopping list does not exist');
} }
$result_product = array(); $result_product = [];
$result_quantity = array(); $result_quantity = [];
$rowsShoppingListProducts = $this->getDatabase()->uihelper_shopping_list()->where('shopping_list_id = :1', $listId)->fetchAll(); $rowsShoppingListProducts = $this->getDatabase()->uihelper_shopping_list()->where('shopping_list_id = :1', $listId)->fetchAll();
foreach ($rowsShoppingListProducts as $row) foreach ($rowsShoppingListProducts as $row)
{ {
$isValidProduct = ($row->product_id != null && $row->product_id != ""); $isValidProduct = ($row->product_id != null && $row->product_id != '');
if ($isValidProduct) if ($isValidProduct)
{ {
$product = $this->getDatabase()->products()->where('id = :1', $row->product_id)->fetch(); $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(); $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; $factor = 1.0;
if ($conversion != null) if ($conversion != null)
{ {
$factor = floatval($conversion->factor); $factor = floatval($conversion->factor);
} }
$amount = round($row->amount * $factor); $amount = round($row->amount * $factor);
$note = ""; $note = '';
if (GROCY_TPRINTER_PRINT_NOTES) if (GROCY_TPRINTER_PRINT_NOTES)
{ {
if ($row->note != "") { if ($row->note != '')
{
$note = ' (' . $row->note . ')'; $note = ' (' . $row->note . ')';
} }
} }
@ -1029,7 +1030,6 @@ class StockService extends BaseService
array_push($result_quantity, round($row->amount)); array_push($result_quantity, round($row->amount));
array_push($result_product, $row->note); array_push($result_product, $row->note);
} }
} }
} }
//Add padding to look nicer //Add padding to look nicer
@ -1041,7 +1041,7 @@ class StockService extends BaseService
$maxlength = strlen($quantity); $maxlength = strlen($quantity);
} }
} }
$result = array(); $result = [];
$length = count($result_quantity); $length = count($result_quantity);
for ($i = 0; $i < $length; $i++) for ($i = 0; $i < $length; $i++)
{ {
@ -1051,7 +1051,6 @@ class StockService extends BaseService
return $result; return $result;
} }
public function TransferProduct(int $productId, float $amount, int $locationIdFrom, int $locationIdTo, $specificStockEntryId = 'default', &$transactionId = null) public function TransferProduct(int $productId, float $amount, int $locationIdFrom, int $locationIdTo, $specificStockEntryId = 'default', &$transactionId = null)
{ {
if (!$this->ProductExists($productId)) if (!$this->ProductExists($productId))
@ -1152,6 +1151,7 @@ class StockService extends BaseService
'price' => $stockEntry->price, 'price' => $stockEntry->price,
'opened_date' => $stockEntry->opened_date, 'opened_date' => $stockEntry->opened_date,
'location_id' => $stockEntry->location_id, 'location_id' => $stockEntry->location_id,
'shopping_location_id' => $stockEntry->shopping_location_id,
'correlation_id' => $correlationId, 'correlation_id' => $correlationId,
'transaction_Id' => $transactionId, 'transaction_Id' => $transactionId,
'user_id' => GROCY_USER_ID 'user_id' => GROCY_USER_ID
@ -1168,6 +1168,7 @@ class StockService extends BaseService
'price' => $stockEntry->price, 'price' => $stockEntry->price,
'opened_date' => $stockEntry->opened_date, 'opened_date' => $stockEntry->opened_date,
'location_id' => $locationIdTo, 'location_id' => $locationIdTo,
'shopping_location_id' => $stockEntry->shopping_location_id,
'correlation_id' => $correlationId, 'correlation_id' => $correlationId,
'transaction_Id' => $transactionId, 'transaction_Id' => $transactionId,
'user_id' => GROCY_USER_ID 'user_id' => GROCY_USER_ID
@ -1195,6 +1196,7 @@ class StockService extends BaseService
'price' => $stockEntry->price, 'price' => $stockEntry->price,
'opened_date' => $stockEntry->opened_date, 'opened_date' => $stockEntry->opened_date,
'location_id' => $stockEntry->location_id, 'location_id' => $stockEntry->location_id,
'shopping_location_id' => $stockEntry->shopping_location_id,
'correlation_id' => $correlationId, 'correlation_id' => $correlationId,
'transaction_Id' => $transactionId, 'transaction_Id' => $transactionId,
'user_id' => GROCY_USER_ID 'user_id' => GROCY_USER_ID
@ -1211,6 +1213,7 @@ class StockService extends BaseService
'price' => $stockEntry->price, 'price' => $stockEntry->price,
'opened_date' => $stockEntry->opened_date, 'opened_date' => $stockEntry->opened_date,
'location_id' => $locationIdTo, 'location_id' => $locationIdTo,
'shopping_location_id' => $stockEntry->shopping_location_id,
'correlation_id' => $correlationId, 'correlation_id' => $correlationId,
'transaction_Id' => $transactionId, 'transaction_Id' => $transactionId,
'user_id' => GROCY_USER_ID 'user_id' => GROCY_USER_ID
@ -1231,6 +1234,7 @@ class StockService extends BaseService
'stock_id' => $stockEntry->stock_id, 'stock_id' => $stockEntry->stock_id,
'price' => $stockEntry->price, 'price' => $stockEntry->price,
'location_id' => $locationIdTo, 'location_id' => $locationIdTo,
'shopping_location_id' => $stockEntry->shopping_location_id,
'open' => $stockEntry->open, 'open' => $stockEntry->open,
'opened_date' => $stockEntry->opened_date 'opened_date' => $stockEntry->opened_date
]); ]);