mirror of
https://github.com/grocy/grocy.git
synced 2026-04-07 05:16:15 +02:00
Puchase add qu_factor_to_stock
This commit is contained in:
parent
f6852e82b2
commit
3d54ec6dca
|
|
@ -88,13 +88,19 @@ class StockApiController extends BaseApiController
|
|||
$shoppingLocationId = $requestBody['shopping_location_id'];
|
||||
}
|
||||
|
||||
$quFactorPurchaseToStock = null;
|
||||
if (array_key_exists('qu_factor_purchase_to_stock', $requestBody) && is_numeric($requestBody['qu_factor_purchase_to_stock']))
|
||||
{
|
||||
$quFactorPurchaseToStock = $requestBody['qu_factor_purchase_to_stock'];
|
||||
}
|
||||
|
||||
$transactionType = StockService::TRANSACTION_TYPE_PURCHASE;
|
||||
if (array_key_exists('transaction_type', $requestBody) && !empty($requestBody['transactiontype']))
|
||||
{
|
||||
$transactionType = $requestBody['transactiontype'];
|
||||
}
|
||||
|
||||
$bookingId = $this->getStockService()->AddProduct($args['productId'], $requestBody['amount'], $bestBeforeDate, $transactionType, date('Y-m-d'), $price, $locationId, $shoppingLocationId);
|
||||
$bookingId = $this->getStockService()->AddProduct($args['productId'], $requestBody['amount'], $bestBeforeDate, $transactionType, date('Y-m-d'), $price, $quFactorPurchaseToStock, $locationId, $shoppingLocationId);
|
||||
return $this->ApiResponse($response, $this->getDatabase()->stock_log($bookingId));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
Grocy.Api.Get('stock/products/' + jsonForm.product_id,
|
||||
function(productDetails)
|
||||
{
|
||||
var amount = jsonForm.amount * productDetails.product.qu_factor_purchase_to_stock;
|
||||
var amount = jsonForm.amount * jsonForm.qu_factor_purchase_to_stock;
|
||||
|
||||
var price = "";
|
||||
if (!jsonForm.price.toString().isEmpty())
|
||||
|
|
@ -37,6 +37,7 @@
|
|||
{
|
||||
jsonData.location_id = Grocy.Components.LocationPicker.GetValue();
|
||||
}
|
||||
jsonData.qu_factor_purchase_to_stock = jsonForm.qu_factor_purchase_to_stock;
|
||||
|
||||
Grocy.Api.Post('stock/products/' + jsonForm.product_id + '/add', jsonData,
|
||||
function(result)
|
||||
|
|
@ -162,14 +163,20 @@ if (Grocy.Components.ProductPicker !== undefined)
|
|||
}
|
||||
|
||||
$('#amount_qu_unit').attr("qu-factor-purchase-to-stock", productDetails.product.qu_factor_purchase_to_stock);
|
||||
$('#amount_qu_unit').attr("quantity-unit-purchase-name", productDetails.quantity_unit_purchase.name);
|
||||
$('#amount_qu_unit').attr("quantity-unit-stock-name", productDetails.quantity_unit_stock.name);
|
||||
$('#amount_qu_unit').attr("quantity-unit-stock-name-plural", productDetails.quantity_unit_stock.name_plural);
|
||||
$('#qu_factor_purchase_to_stock').val(productDetails.product.qu_factor_purchase_to_stock);
|
||||
|
||||
if (productDetails.product.qu_id_purchase === productDetails.product.qu_id_stock)
|
||||
{
|
||||
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
|
||||
$('#group-qu_factor_purchase_to_stock').addClass('d-none');
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name + " (" + __t("will be multiplied by a factor of %1$s to get %2$s", parseFloat(productDetails.product.qu_factor_purchase_to_stock).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 2 }), __n(2, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural)) + ")");
|
||||
$('#group-qu_factor_purchase_to_stock').removeClass('d-none');
|
||||
}
|
||||
|
||||
var priceTypeUnitPrice = $("#price-type-unit-price");
|
||||
|
|
@ -339,6 +346,15 @@ $('#amount').on('change', function(e)
|
|||
Grocy.FrontendHelpers.ValidateForm('purchase-form');
|
||||
});
|
||||
|
||||
$('#qu_factor_purchase_to_stock').on('change', function(e)
|
||||
{
|
||||
var value = $(e.target).val();
|
||||
$('#amount_qu_unit').attr("qu-factor-purchase-to-stock", value);
|
||||
$('#amount_qu_unit').text(document.getElementById("amount_qu_unit").getAttribute("quantity-unit-purchase-name") + " (" + __t("will be multiplied by a factor of %1$s to get %2$s", parseFloat(value).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 2 }), __n(2, document.getElementById("amount_qu_unit").getAttribute("quantity-unit-stock-name"), document.getElementById("amount_qu_unit").getAttribute("quantity-unit-stock-name-plural")) + ")"));
|
||||
refreshPriceHint();
|
||||
Grocy.FrontendHelpers.ValidateForm('purchase-form');
|
||||
});
|
||||
|
||||
if (GetUriParam("flow") === "shoppinglistitemtostock")
|
||||
{
|
||||
$('#amount').val(parseFloat(GetUriParam("amount")).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 4 }));
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ class StockService extends BaseService
|
|||
return FindAllObjectsInArrayByPropertyValue($stockEntries, 'location_id', $locationId);
|
||||
}
|
||||
|
||||
public function AddProduct(int $productId, float $amount, $bestBeforeDate, $transactionType, $purchasedDate, $price, $locationId = null, $shoppingLocationId = null, &$transactionId = null)
|
||||
public function AddProduct(int $productId, float $amount, $bestBeforeDate, $transactionType, $purchasedDate, $price, $quFactorPurchaseToStock, $locationId = null, $shoppingLocationId = null, &$transactionId = null)
|
||||
{
|
||||
if (!$this->ProductExists($productId))
|
||||
{
|
||||
|
|
@ -275,6 +275,7 @@ class StockService extends BaseService
|
|||
'location_id' => $locationId,
|
||||
'transaction_id' => $transactionId,
|
||||
'shopping_location_id' => $shoppingLocationId,
|
||||
'qu_factor_purchase_to_stock' => $quFactorPurchaseToStock,
|
||||
));
|
||||
$logRow->save();
|
||||
|
||||
|
|
@ -289,6 +290,7 @@ class StockService extends BaseService
|
|||
'price' => $price,
|
||||
'location_id' => $locationId,
|
||||
'shopping_location_id' => $shoppingLocationId,
|
||||
'qu_factor_purchase_to_stock' => $quFactorPurchaseToStock,
|
||||
));
|
||||
$stockRow->save();
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
@php if(!isset($isRequired)) { $isRequired = true; } @endphp
|
||||
@php if(!isset($noNameAttribute)) { $noNameAttribute = false; } @endphp
|
||||
|
||||
<div class="form-group {{ $additionalGroupCssClasses }}">
|
||||
<div id="group-{{ $id }}" class="form-group {{ $additionalGroupCssClasses }}">
|
||||
<label for="{{ $id }}">
|
||||
{{ $__t($label) }}
|
||||
<i class="fas fa-question-circle" id="{{ $hintId }}" data-toggle="tooltip" title="{{ $hint }}"></i>{!! $additionalHtmlContextHelp !!}</label>
|
||||
|
|
|
|||
|
|
@ -96,6 +96,16 @@
|
|||
<input type="hidden" name="price" id="price" value="0">
|
||||
@endif
|
||||
|
||||
@include('components.numberpicker', array(
|
||||
'id' => 'qu_factor_purchase_to_stock',
|
||||
'label' => 'Factor purchase to stock quantity unit',
|
||||
'min' => 1,
|
||||
'additionalGroupCssClasses' => 'd-none',
|
||||
'invalidFeedback' => $__t('The amount cannot be lower than %s', '1'),
|
||||
'additionalCssClasses' => 'input-group-qu',
|
||||
'additionalHtmlElements' => '<p id="qu-conversion-info" class="form-text text-muted small d-none"></p>'
|
||||
))
|
||||
|
||||
@if(GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)
|
||||
@include('components.locationpicker', array(
|
||||
'locations' => $locations,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user