Fixed /stockedit opened checkbox (references #506)

This commit is contained in:
Bernd Bestel 2020-01-21 20:04:33 +01:00
parent f543a3a472
commit c22496ca7c
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
5 changed files with 19 additions and 11 deletions

View File

@ -113,7 +113,7 @@ class StockApiController extends BaseApiController
} }
} }
public function EditStock(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) public function EditStockEntry(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{ {
$requestBody = $request->getParsedBody(); $requestBody = $request->getParsedBody();
@ -152,7 +152,7 @@ class StockApiController extends BaseApiController
$locationId = $requestBody['location_id']; $locationId = $requestBody['location_id'];
} }
$bookingId = $this->StockService->EditStock($requestBody['id'], $requestBody['amount'], $bestBeforeDate, $locationId, $price); $bookingId = $this->StockService->EditStockEntry($requestBody['id'], $requestBody['amount'], $bestBeforeDate, $locationId, $price, $requestBody['open']);
return $this->ApiResponse($this->Database->stock_log($bookingId)); return $this->ApiResponse($this->Database->stock_log($bookingId));
} }
catch (\Exception $ex) catch (\Exception $ex)

View File

@ -1087,6 +1087,10 @@
"type": "number", "type": "number",
"format": "number", "format": "number",
"description": "The price per purchase quantity unit in configured currency" "description": "The price per purchase quantity unit in configured currency"
},
"open": {
"type": "boolean",
"description": "If the stock entry was already opened or not"
} }
}, },
"example": { "example": {
@ -1094,7 +1098,8 @@
"amount": 1, "amount": 1,
"best_before_date": "2019-01-19", "best_before_date": "2019-01-19",
"location_id": 2, "location_id": 2,
"price": "1.99" "price": "1.99",
"open": false
} }
} }
} }

View File

@ -23,6 +23,8 @@
} }
jsonData.price = price; jsonData.price = price;
jsonData.open = $("#open").is(":checked");
var stockRowId = GetUriParam('stockRowId'); var stockRowId = GetUriParam('stockRowId');
jsonData.id = stockRowId; jsonData.id = stockRowId;
@ -88,6 +90,7 @@ Grocy.Api.Get("stock/" + stockRowId + "/entry",
Grocy.Components.LocationPicker.SetId(stockEntry.location_id); Grocy.Components.LocationPicker.SetId(stockEntry.location_id);
$('#amount').val(stockEntry.amount); $('#amount').val(stockEntry.amount);
$('#price').val(stockEntry.price); $('#price').val(stockEntry.price);
$("#open").prop('checked', BoolVal(stockEntry.open));
Grocy.Components.DateTimePicker.SetValue(stockEntry.best_before_date); Grocy.Components.DateTimePicker.SetValue(stockEntry.best_before_date);
Grocy.Api.Get('stock/products/' + stockEntry.product_id, Grocy.Api.Get('stock/products/' + stockEntry.product_id,

View File

@ -162,7 +162,7 @@ $app->group('/api', function()
{ {
$this->get('/stock', '\Grocy\Controllers\StockApiController:CurrentStock'); $this->get('/stock', '\Grocy\Controllers\StockApiController:CurrentStock');
$this->get('/stock/{entryId}/entry', '\Grocy\Controllers\StockApiController:StockEntry'); $this->get('/stock/{entryId}/entry', '\Grocy\Controllers\StockApiController:StockEntry');
$this->put('/stock', '\Grocy\Controllers\StockApiController:EditStock'); $this->put('/stock', '\Grocy\Controllers\StockApiController:EditStockEntry');
$this->get('/stock/volatile', '\Grocy\Controllers\StockApiController:CurrentVolatileStock'); $this->get('/stock/volatile', '\Grocy\Controllers\StockApiController:CurrentVolatileStock');
$this->get('/stock/products/{productId}', '\Grocy\Controllers\StockApiController:ProductDetails'); $this->get('/stock/products/{productId}', '\Grocy\Controllers\StockApiController:ProductDetails');
$this->get('/stock/products/{productId}/entries', '\Grocy\Controllers\StockApiController:ProductStockEntries'); $this->get('/stock/products/{productId}/entries', '\Grocy\Controllers\StockApiController:ProductStockEntries');

View File

@ -562,7 +562,7 @@ class StockService extends BaseService
return $this->Database->lastInsertId(); return $this->Database->lastInsertId();
} }
public function EditStock(int $stockRowId, int $amount, $bestBeforeDate, $locationId, $price) public function EditStockEntry(int $stockRowId, int $amount, $bestBeforeDate, $locationId, $price, $open)
{ {
$stockRow = $this->Database->stock()->where('id = :1', $stockRowId)->fetch(); $stockRow = $this->Database->stock()->where('id = :1', $stockRowId)->fetch();
@ -594,7 +594,8 @@ class StockService extends BaseService
'amount' => $amount, 'amount' => $amount,
'price' => $price, 'price' => $price,
'best_before_date' => $bestBeforeDate, 'best_before_date' => $bestBeforeDate,
'location_id' => $locationId 'location_id' => $locationId,
'open' => $open
)); ));
$logNewRowForStockUpdate = $this->Database->stock_log()->createRow(array( $logNewRowForStockUpdate = $this->Database->stock_log()->createRow(array(
@ -613,10 +614,9 @@ class StockService extends BaseService
)); ));
$logNewRowForStockUpdate->save(); $logNewRowForStockUpdate->save();
$returnValue = $this->Database->lastInsertId(); return $this->Database->lastInsertId();
return $returnValue;
} }
public function InventoryProduct(int $productId, float $newAmount, $bestBeforeDate, $locationId = null, $price = null) public function InventoryProduct(int $productId, float $newAmount, $bestBeforeDate, $locationId = null, $price = null)
{ {
if (!$this->ProductExists($productId)) if (!$this->ProductExists($productId))