mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 01:32:38 +00:00
Fixed /stockedit opened checkbox (references #506)
This commit is contained in:
parent
f543a3a472
commit
c22496ca7c
@ -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();
|
||||
|
||||
@ -152,7 +152,7 @@ class StockApiController extends BaseApiController
|
||||
$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));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
@ -1087,6 +1087,10 @@
|
||||
"type": "number",
|
||||
"format": "number",
|
||||
"description": "The price per purchase quantity unit in configured currency"
|
||||
},
|
||||
"open": {
|
||||
"type": "boolean",
|
||||
"description": "If the stock entry was already opened or not"
|
||||
}
|
||||
},
|
||||
"example": {
|
||||
@ -1094,7 +1098,8 @@
|
||||
"amount": 1,
|
||||
"best_before_date": "2019-01-19",
|
||||
"location_id": 2,
|
||||
"price": "1.99"
|
||||
"price": "1.99",
|
||||
"open": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,8 @@
|
||||
}
|
||||
jsonData.price = price;
|
||||
|
||||
jsonData.open = $("#open").is(":checked");
|
||||
|
||||
var stockRowId = GetUriParam('stockRowId');
|
||||
jsonData.id = stockRowId;
|
||||
|
||||
@ -88,6 +90,7 @@ Grocy.Api.Get("stock/" + stockRowId + "/entry",
|
||||
Grocy.Components.LocationPicker.SetId(stockEntry.location_id);
|
||||
$('#amount').val(stockEntry.amount);
|
||||
$('#price').val(stockEntry.price);
|
||||
$("#open").prop('checked', BoolVal(stockEntry.open));
|
||||
Grocy.Components.DateTimePicker.SetValue(stockEntry.best_before_date);
|
||||
|
||||
Grocy.Api.Get('stock/products/' + stockEntry.product_id,
|
||||
|
@ -162,7 +162,7 @@ $app->group('/api', function()
|
||||
{
|
||||
$this->get('/stock', '\Grocy\Controllers\StockApiController:CurrentStock');
|
||||
$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/products/{productId}', '\Grocy\Controllers\StockApiController:ProductDetails');
|
||||
$this->get('/stock/products/{productId}/entries', '\Grocy\Controllers\StockApiController:ProductStockEntries');
|
||||
|
@ -562,7 +562,7 @@ class StockService extends BaseService
|
||||
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();
|
||||
@ -572,8 +572,8 @@ class StockService extends BaseService
|
||||
throw new \Exception('Stock does not exist');
|
||||
}
|
||||
|
||||
$correlationId = uniqid();
|
||||
$transactionId = uniqid();
|
||||
$correlationId = uniqid();
|
||||
$transactionId = uniqid();
|
||||
$logOldRowForStockUpdate = $this->Database->stock_log()->createRow(array(
|
||||
'product_id' => $stockRow->product_id,
|
||||
'amount' => $stockRow->amount,
|
||||
@ -594,7 +594,8 @@ class StockService extends BaseService
|
||||
'amount' => $amount,
|
||||
'price' => $price,
|
||||
'best_before_date' => $bestBeforeDate,
|
||||
'location_id' => $locationId
|
||||
'location_id' => $locationId,
|
||||
'open' => $open
|
||||
));
|
||||
|
||||
$logNewRowForStockUpdate = $this->Database->stock_log()->createRow(array(
|
||||
@ -613,10 +614,9 @@ class StockService extends BaseService
|
||||
));
|
||||
$logNewRowForStockUpdate->save();
|
||||
|
||||
$returnValue = $this->Database->lastInsertId();
|
||||
|
||||
return $returnValue;
|
||||
return $this->Database->lastInsertId();
|
||||
}
|
||||
|
||||
public function InventoryProduct(int $productId, float $newAmount, $bestBeforeDate, $locationId = null, $price = null)
|
||||
{
|
||||
if (!$this->ProductExists($productId))
|
||||
|
Loading…
x
Reference in New Issue
Block a user