mirror of
https://github.com/grocy/grocy.git
synced 2025-08-17 11:06:36 +00:00
Added price field on inventory page (for added products) (references #225)
This commit is contained in:
@@ -177,7 +177,13 @@ class StockApiController extends BaseApiController
|
|||||||
$locationId = $requestBody['location_id'];
|
$locationId = $requestBody['location_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$bookingId = $this->StockService->InventoryProduct($args['productId'], $requestBody['new_amount'], $bestBeforeDate, $locationId);
|
$price = null;
|
||||||
|
if (array_key_exists('price', $requestBody) && is_numeric($requestBody['price']))
|
||||||
|
{
|
||||||
|
$price = $requestBody['price'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$bookingId = $this->StockService->InventoryProduct($args['productId'], $requestBody['new_amount'], $bestBeforeDate, $locationId, $price);
|
||||||
return $this->ApiResponse($this->Database->stock_log($bookingId));
|
return $this->ApiResponse($this->Database->stock_log($bookingId));
|
||||||
}
|
}
|
||||||
catch (\Exception $ex)
|
catch (\Exception $ex)
|
||||||
|
@@ -1351,6 +1351,11 @@
|
|||||||
"type": "number",
|
"type": "number",
|
||||||
"format": "integer",
|
"format": "integer",
|
||||||
"description": "If omitted, the default location of the product is used (only applies to added products)"
|
"description": "If omitted, the default location of the product is used (only applies to added products)"
|
||||||
|
},
|
||||||
|
"price": {
|
||||||
|
"type": "number",
|
||||||
|
"format": "double",
|
||||||
|
"description": "If omitted, the last price of the product is used (only applies to added products)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,10 +8,17 @@
|
|||||||
Grocy.Api.Get('stock/products/' + jsonForm.product_id,
|
Grocy.Api.Get('stock/products/' + jsonForm.product_id,
|
||||||
function(productDetails)
|
function(productDetails)
|
||||||
{
|
{
|
||||||
|
var price = "";
|
||||||
|
if (!jsonForm.price.toString().isEmpty())
|
||||||
|
{
|
||||||
|
price = parseFloat(jsonForm.price).toFixed(2);
|
||||||
|
}
|
||||||
|
|
||||||
var jsonData = { };
|
var jsonData = { };
|
||||||
jsonData.new_amount = jsonForm.new_amount;
|
jsonData.new_amount = jsonForm.new_amount;
|
||||||
jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue();
|
jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue();
|
||||||
jsonData.location_id = Grocy.Components.LocationPicker.GetValue();
|
jsonData.location_id = Grocy.Components.LocationPicker.GetValue();
|
||||||
|
jsonData.price = price;
|
||||||
|
|
||||||
Grocy.Api.Post('stock/products/' + jsonForm.product_id + '/inventory', jsonData,
|
Grocy.Api.Post('stock/products/' + jsonForm.product_id + '/inventory', jsonData,
|
||||||
function(result)
|
function(result)
|
||||||
@@ -53,6 +60,7 @@
|
|||||||
$("#new_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', '0'));
|
$("#new_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', '0'));
|
||||||
$('#new_amount').val('');
|
$('#new_amount').val('');
|
||||||
$('#new_amount_qu_unit').text("");
|
$('#new_amount_qu_unit').text("");
|
||||||
|
$('#price').val('');
|
||||||
Grocy.Components.DateTimePicker.Clear();
|
Grocy.Components.DateTimePicker.Clear();
|
||||||
Grocy.Components.ProductPicker.SetValue('');
|
Grocy.Components.ProductPicker.SetValue('');
|
||||||
Grocy.Components.ProductPicker.GetInputElement().focus();
|
Grocy.Components.ProductPicker.GetInputElement().focus();
|
||||||
@@ -111,6 +119,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
|||||||
$("#tare-weight-handling-info").addClass("d-none");
|
$("#tare-weight-handling-info").addClass("d-none");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('#price').val(productDetails.last_price);
|
||||||
Grocy.Components.LocationPicker.SetId(productDetails.location.id);
|
Grocy.Components.LocationPicker.SetId(productDetails.location.id);
|
||||||
$('#new_amount').focus();
|
$('#new_amount').focus();
|
||||||
},
|
},
|
||||||
|
@@ -303,7 +303,7 @@ class StockService extends BaseService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function InventoryProduct(int $productId, int $newAmount, string $bestBeforeDate, $locationId = null)
|
public function InventoryProduct(int $productId, int $newAmount, string $bestBeforeDate, $locationId = null, $price = null)
|
||||||
{
|
{
|
||||||
if (!$this->ProductExists($productId))
|
if (!$this->ProductExists($productId))
|
||||||
{
|
{
|
||||||
@@ -312,6 +312,11 @@ class StockService extends BaseService
|
|||||||
|
|
||||||
$productDetails = (object)$this->GetProductDetails($productId);
|
$productDetails = (object)$this->GetProductDetails($productId);
|
||||||
|
|
||||||
|
if ($price === null)
|
||||||
|
{
|
||||||
|
$price = $productDetails->last_price;
|
||||||
|
}
|
||||||
|
|
||||||
// Tare weight handling
|
// Tare weight handling
|
||||||
// The given amount is the new total amount including the container weight (gross)
|
// The given amount is the new total amount including the container weight (gross)
|
||||||
// So assume that the amount in stock is the amount also including the container weight
|
// So assume that the amount in stock is the amount also including the container weight
|
||||||
@@ -333,7 +338,7 @@ class StockService extends BaseService
|
|||||||
$bookingAmount = $newAmount;
|
$bookingAmount = $newAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->AddProduct($productId, $bookingAmount, $bestBeforeDate, self::TRANSACTION_TYPE_INVENTORY_CORRECTION, date('Y-m-d'), $productDetails->last_price, $locationId);
|
$this->AddProduct($productId, $bookingAmount, $bestBeforeDate, self::TRANSACTION_TYPE_INVENTORY_CORRECTION, date('Y-m-d'), $price, $locationId);
|
||||||
}
|
}
|
||||||
else if ($newAmount < $productDetails->stock_amount + $containerWeight)
|
else if ($newAmount < $productDetails->stock_amount + $containerWeight)
|
||||||
{
|
{
|
||||||
|
@@ -45,6 +45,18 @@
|
|||||||
'earlierThanInfoText' => $__t('The given date is earlier than today, are you sure?')
|
'earlierThanInfoText' => $__t('The given date is earlier than today, are you sure?')
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@include('components.numberpicker', array(
|
||||||
|
'id' => 'price',
|
||||||
|
'label' => 'Price',
|
||||||
|
'min' => 0,
|
||||||
|
'step' => 0.01,
|
||||||
|
'value' => '',
|
||||||
|
'hint' => $__t('in %s per purchase quantity unit', GROCY_CURRENCY),
|
||||||
|
'additionalHtmlContextHelp' => '<br><span class="small text-muted">' . $__t('This will apply to added products') . '</span>',
|
||||||
|
'invalidFeedback' => $__t('The price cannot be lower than %s', '0'),
|
||||||
|
'isRequired' => false
|
||||||
|
))
|
||||||
|
|
||||||
@include('components.locationpicker', array(
|
@include('components.locationpicker', array(
|
||||||
'locations' => $locations,
|
'locations' => $locations,
|
||||||
'hint' => 'This will apply to added products'
|
'hint' => 'This will apply to added products'
|
||||||
|
Reference in New Issue
Block a user