mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 01:32:38 +00:00
Added price field on inventory page (for added products) (references #225)
This commit is contained in:
parent
8138dd43ac
commit
bcae9f9292
@ -177,7 +177,13 @@ class StockApiController extends BaseApiController
|
||||
$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));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
@ -1351,6 +1351,11 @@
|
||||
"type": "number",
|
||||
"format": "integer",
|
||||
"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,
|
||||
function(productDetails)
|
||||
{
|
||||
var price = "";
|
||||
if (!jsonForm.price.toString().isEmpty())
|
||||
{
|
||||
price = parseFloat(jsonForm.price).toFixed(2);
|
||||
}
|
||||
|
||||
var jsonData = { };
|
||||
jsonData.new_amount = jsonForm.new_amount;
|
||||
jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue();
|
||||
jsonData.location_id = Grocy.Components.LocationPicker.GetValue();
|
||||
jsonData.price = price;
|
||||
|
||||
Grocy.Api.Post('stock/products/' + jsonForm.product_id + '/inventory', jsonData,
|
||||
function(result)
|
||||
@ -53,6 +60,7 @@
|
||||
$("#new_amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', '0'));
|
||||
$('#new_amount').val('');
|
||||
$('#new_amount_qu_unit').text("");
|
||||
$('#price').val('');
|
||||
Grocy.Components.DateTimePicker.Clear();
|
||||
Grocy.Components.ProductPicker.SetValue('');
|
||||
Grocy.Components.ProductPicker.GetInputElement().focus();
|
||||
@ -111,6 +119,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
$("#tare-weight-handling-info").addClass("d-none");
|
||||
}
|
||||
|
||||
$('#price').val(productDetails.last_price);
|
||||
Grocy.Components.LocationPicker.SetId(productDetails.location.id);
|
||||
$('#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))
|
||||
{
|
||||
@ -312,6 +312,11 @@ class StockService extends BaseService
|
||||
|
||||
$productDetails = (object)$this->GetProductDetails($productId);
|
||||
|
||||
if ($price === null)
|
||||
{
|
||||
$price = $productDetails->last_price;
|
||||
}
|
||||
|
||||
// Tare weight handling
|
||||
// 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
|
||||
@ -333,7 +338,7 @@ class StockService extends BaseService
|
||||
$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)
|
||||
{
|
||||
|
@ -45,6 +45,18 @@
|
||||
'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(
|
||||
'locations' => $locations,
|
||||
'hint' => 'This will apply to added products'
|
||||
|
Loading…
x
Reference in New Issue
Block a user