mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 12:20:22 +00:00
Qu factor purchase to stock & Product Barcode Details (#801)
* Puchase add qu_factor_to_stock * qu_factor_purchase_to_stock for stock edit * product barcodes with QU and Stores * remove product barcode tags * migrations/0103 add value and factor_puchase_amount to stock_current and stock_current_location_content * Remove unused method * StockService#GetProductDetails: include stock_value * productcard: include stock_value * Add Purchase Factor to Stock Overview * update demo data with stock qu_factor_purchase_to_stock * recipes_pos_resolved update * avg_price and oldest_price in product details * add average price to product card * hint for recipe costs not included if not in stock * Round value and factor_purchas_amount. Include currency for stock value * Add factor_purchase_amount to product card stock amount * Allow editing qu_factor_purchase_to_stock for stock entries * fix update qu_factor_purchase_to_stock for Transfers * Add barcode to existing product update to add to product_barcodes table * Add barcode to new product workflow update to add to product_barcodes table * *** Price now saved as 1 QU to stock in stock tables *** * remove column product barcode and use product_barcodes * Allow products to be deactivated instead of deleted * Embedded barcode and qu-conversion with page reload on change * Save current product barcode into new product_barcodes table * Embedded popup for product group add/edit * barcode scanner added to product barcodes input * Edit product qu_stock is unavailable after first purchase * StockOverview: Filters break when columns are reordered so for now just disable colReorder * view stockoverview.blade: display product_group column * Review Co-authored-by: Bernd Bestel <bernd@berrnd.de>
This commit is contained in:
@@ -6,11 +6,24 @@ Grocy.Components.ProductCard.Refresh = function(productId)
|
||||
function(productDetails)
|
||||
{
|
||||
var stockAmount = productDetails.stock_amount || '0';
|
||||
var stockFactorPurchaseAmount = productDetails.stock_factor_purchase_amount || '0';
|
||||
var stockValue = productDetails.stock_value || '0';
|
||||
var stockAmountOpened = productDetails.stock_amount_opened || '0';
|
||||
$('#productcard-product-name').text(productDetails.product.name);
|
||||
$('#productcard-product-description').html(productDetails.product.description);
|
||||
$('#productcard-product-stock-amount').text(stockAmount);
|
||||
$('#productcard-product-stock-qu-name').text(__n(stockAmount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural));
|
||||
if (productDetails.last_qu_factor_purchase_to_stock > 1)
|
||||
{
|
||||
$('#productcard-product-stock-factor-purchase-amount').text('(' + stockFactorPurchaseAmount);
|
||||
$('#productcard-product-stock-factor-purchase-qu-name').text(__n(stockFactorPurchaseAmount, productDetails.quantity_unit_purchase.name, productDetails.quantity_unit_purchase.name_plural) + ')');
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#productcard-product-stock-factor-purchase-amount').text('');
|
||||
$('#productcard-product-stock-factor-purchase-qu-name').text('');
|
||||
}
|
||||
$('#productcard-product-stock-value').text(stockValue + ' ' + Grocy.Currency);
|
||||
$('#productcard-product-last-purchased').text((productDetails.last_purchased || '2999-12-31').substring(0, 10));
|
||||
$('#productcard-product-last-purchased-timeago').attr("datetime", productDetails.last_purchased || '2999-12-31');
|
||||
$('#productcard-product-last-used').text((productDetails.last_used || '2999-12-31').substring(0, 10));
|
||||
@@ -80,13 +93,29 @@ Grocy.Components.ProductCard.Refresh = function(productId)
|
||||
|
||||
if (productDetails.last_price !== null)
|
||||
{
|
||||
$('#productcard-product-last-price').text(Number.parseFloat(productDetails.last_price).toLocaleString() + ' ' + Grocy.Currency + ' per ' + productDetails.quantity_unit_purchase.name);
|
||||
if (productDetails.last_qu_factor_purchase_to_stock > 1)
|
||||
{
|
||||
$('#productcard-product-last-price').text(Number.parseFloat(productDetails.last_price).toLocaleString() + ' ' + Grocy.Currency + ' per 1 ' + productDetails.quantity_unit_purchase.name + ' of ' + productDetails.last_qu_factor_purchase_to_stock + ' ' + productDetails.quantity_unit_stock.name_plural);
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#productcard-product-last-price').text(Number.parseFloat(productDetails.last_price).toLocaleString() + ' ' + Grocy.Currency + ' per ' + productDetails.quantity_unit_purchase.name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#productcard-product-last-price').text(__t('Unknown'));
|
||||
}
|
||||
|
||||
if (productDetails.avg_price !== null)
|
||||
{
|
||||
$('#productcard-product-average-price').text(Number.parseFloat(productDetails.avg_price).toLocaleString() + ' ' + Grocy.Currency);
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#productcard-product-average-price').text(__t('Unknown'));
|
||||
}
|
||||
|
||||
if (productDetails.product.picture_file_name !== null && !productDetails.product.picture_file_name.isEmpty())
|
||||
{
|
||||
$("#productcard-product-picture").removeClass("d-none");
|
||||
|
@@ -132,6 +132,7 @@ $('#product_id_text_input').on('blur', function(e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
$('#product_id').attr("barcode", "null");
|
||||
|
||||
var input = $('#product_id_text_input').val().toString();
|
||||
var possibleOptionElement = $("#product_id option[data-additional-searchdata*=\"" + input + ",\"]").first();
|
||||
@@ -139,6 +140,7 @@ $('#product_id_text_input').on('blur', function(e)
|
||||
if (GetUriParam('addbarcodetoselection') === undefined && input.length > 0 && possibleOptionElement.length > 0)
|
||||
{
|
||||
$('#product_id').val(possibleOptionElement.val());
|
||||
$('#product_id').attr("barcode", input);
|
||||
$('#product_id').data('combobox').refresh();
|
||||
$('#product_id').trigger('change');
|
||||
}
|
||||
|
@@ -44,17 +44,12 @@
|
||||
var addBarcode = GetUriParam('addbarcodetoselection');
|
||||
if (addBarcode !== undefined)
|
||||
{
|
||||
var existingBarcodes = productDetails.product.barcode || '';
|
||||
if (existingBarcodes.length === 0)
|
||||
{
|
||||
productDetails.product.barcode = addBarcode;
|
||||
}
|
||||
else
|
||||
{
|
||||
productDetails.product.barcode += ',' + addBarcode;
|
||||
}
|
||||
var jsonDataBarcode = {};
|
||||
jsonDataBarcode.barcode = addBarcode;
|
||||
jsonDataBarcode.product_id = jsonForm.product_id;
|
||||
jsonDataBarcode.qu_factor_purchase_to_stock = productDetails.product.qu_factor_purchase_to_stock;
|
||||
|
||||
Grocy.Api.Put('objects/products/' + productDetails.product.id, productDetails.product,
|
||||
Grocy.Api.Post('objects/product_barcodes', jsonDataBarcode,
|
||||
function(result)
|
||||
{
|
||||
$("#flow-info-addbarcodetoselection").addClass("d-none");
|
||||
@@ -63,7 +58,8 @@
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
Grocy.FrontendHelpers.EndUiBusy("consume-form");
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@@ -37,17 +37,13 @@
|
||||
var addBarcode = GetUriParam('addbarcodetoselection');
|
||||
if (addBarcode !== undefined)
|
||||
{
|
||||
var existingBarcodes = productDetails.product.barcode || '';
|
||||
if (existingBarcodes.length === 0)
|
||||
{
|
||||
productDetails.product.barcode = addBarcode;
|
||||
}
|
||||
else
|
||||
{
|
||||
productDetails.product.barcode += ',' + addBarcode;
|
||||
}
|
||||
var jsonDataBarcode = {};
|
||||
jsonDataBarcode.barcode = addBarcode;
|
||||
jsonDataBarcode.product_id = jsonForm.product_id;
|
||||
jsonDataBarcode.qu_factor_purchase_to_stock = productDetails.product.qu_factor_purchase_to_stock;
|
||||
jsonDataBarcode.shopping_location_id = jsonForm.shopping_location_id;
|
||||
|
||||
Grocy.Api.Put('objects/products/' + productDetails.product.id, productDetails.product,
|
||||
Grocy.Api.Post('objects/product_barcodes', jsonDataBarcode,
|
||||
function(result)
|
||||
{
|
||||
$("#flow-info-addbarcodetoselection").addClass("d-none");
|
||||
@@ -56,7 +52,8 @@
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
Grocy.FrontendHelpers.EndUiBusy("inventory-form");
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@@ -180,6 +180,11 @@ var calendar = $("#calendar").fullCalendar({
|
||||
productDetails.last_price = 0;
|
||||
}
|
||||
|
||||
if (productDetails.last_qu_factor_purchase_to_stock === null)
|
||||
{
|
||||
productDetails.last_qu_factor_purchase_to_stock = 1;
|
||||
}
|
||||
|
||||
element.attr("data-product-details", event.productDetails);
|
||||
|
||||
var productOrderMissingButtonDisabledClasses = "disabled";
|
||||
@@ -205,7 +210,7 @@ var calendar = $("#calendar").fullCalendar({
|
||||
var costsAndCaloriesPerServing = ""
|
||||
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
|
||||
{
|
||||
costsAndCaloriesPerServing = '<h5 class="small text-truncate"><span class="locale-number locale-number-currency">' + productDetails.last_price / productDetails.product.qu_factor_purchase_to_stock * mealPlanEntry.product_amount + '</span> / <span class="locale-number locale-number-generic">' + productDetails.product.calories * mealPlanEntry.product_amount + '</span> kcal ' + '<h5>';
|
||||
costsAndCaloriesPerServing = '<h5 class="small text-truncate"><span class="locale-number locale-number-currency">' + productDetails.last_price / productDetails.last_qu_factor_purchase_to_stock * mealPlanEntry.product_amount + '</span> / <span class="locale-number locale-number-generic">' + productDetails.product.calories * mealPlanEntry.product_amount + '</span> kcal ' + '<h5>';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
65
public/viewjs/productbarcodesform.js
Normal file
65
public/viewjs/productbarcodesform.js
Normal file
@@ -0,0 +1,65 @@
|
||||
$('#save-barcode-button').on('click', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
var jsonData = $('#barcode-form').serializeJSON();
|
||||
Grocy.FrontendHelpers.BeginUiBusy("barcode-form");
|
||||
|
||||
if (Grocy.EditMode === 'create')
|
||||
{
|
||||
Grocy.Api.Post('objects/product_barcodes', jsonData,
|
||||
function(result)
|
||||
{
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy("barcode-form");
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response);
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Grocy.Api.Put('objects/product_barcodes/' + Grocy.EditObjectId, jsonData,
|
||||
function(result)
|
||||
{
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy("barcode-form");
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
window.parent.postMessage(WindowMessageBag("ProductBarcodesChanged"), U("/product/" + GetUriParam("product")));
|
||||
window.parent.postMessage(WindowMessageBag("CloseAllModals"), U("/product/" + GetUriParam("product")));
|
||||
});
|
||||
|
||||
$('#barcode').on('change', function(e)
|
||||
{
|
||||
Grocy.FrontendHelpers.ValidateForm('barcode-form');
|
||||
});
|
||||
|
||||
$('#qu_factor_purchase_to_stock').on('change', function(e)
|
||||
{
|
||||
Grocy.FrontendHelpers.ValidateForm('barcode-form');
|
||||
});
|
||||
|
||||
$('#barcode-form input').keydown(function(event)
|
||||
{
|
||||
if (event.keyCode === 13) //Enter
|
||||
{
|
||||
event.preventDefault();
|
||||
|
||||
if (document.getElementById('barcode-form').checkValidity() === false) //There is at least one validation error
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#save-barcode-button').click();
|
||||
}
|
||||
}
|
||||
});
|
||||
Grocy.FrontendHelpers.ValidateForm('barcode-form');
|
@@ -42,6 +42,26 @@
|
||||
function(result)
|
||||
{
|
||||
Grocy.EditObjectId = result.created_object_id;
|
||||
|
||||
if (prefillBarcode !== undefined)
|
||||
{
|
||||
var jsonDataBarcode = {};
|
||||
jsonDataBarcode.barcode = prefillBarcode;
|
||||
jsonDataBarcode.product_id = result.created_object_id;
|
||||
jsonDataBarcode.qu_factor_purchase_to_stock = jsonData.qu_factor_purchase_to_stock;
|
||||
jsonDataBarcode.shopping_location_id = jsonData.shopping_location_id;
|
||||
|
||||
Grocy.Api.Post('objects/product_barcodes', jsonDataBarcode,
|
||||
function(result)
|
||||
{
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy("barcode-form");
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response);
|
||||
}
|
||||
);
|
||||
}
|
||||
Grocy.Components.UserfieldsForm.Save(function()
|
||||
{
|
||||
if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteProductPictureOnSave)
|
||||
@@ -166,32 +186,19 @@
|
||||
}
|
||||
});
|
||||
|
||||
$('#barcode-taginput').tagsManager({
|
||||
'hiddenTagListName': 'barcode',
|
||||
'tagsContainer': '#barcode-taginput-container',
|
||||
'tagClass': 'badge badge-secondary',
|
||||
'delimiters': [13, 44]
|
||||
});
|
||||
|
||||
if (Grocy.EditMode === 'edit')
|
||||
{
|
||||
Grocy.Api.Get('objects/products/' + Grocy.EditObjectId,
|
||||
function (product)
|
||||
Grocy.Api.Get('stock/products/' + Grocy.EditObjectId,
|
||||
function(productDetails)
|
||||
{
|
||||
if (productDetails.last_purchased == null)
|
||||
{
|
||||
if (product.barcode !== null && product.barcode.length > 0)
|
||||
{
|
||||
product.barcode.split(',').forEach(function(item)
|
||||
{
|
||||
$('#barcode-taginput').tagsManager('pushTag', item);
|
||||
});
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
$('#qu_id_stock').removeAttr("disabled");
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
|
||||
var prefillName = GetUriParam('prefillname');
|
||||
if (prefillName !== undefined)
|
||||
@@ -201,16 +208,6 @@ if (prefillName !== undefined)
|
||||
}
|
||||
|
||||
var prefillBarcode = GetUriParam('prefillbarcode');
|
||||
if (prefillBarcode !== undefined)
|
||||
{
|
||||
$('#barcode-taginput').tagsManager('pushTag', prefillBarcode);
|
||||
$('#name').focus();
|
||||
}
|
||||
|
||||
$("#barcode-taginput").on("blur", function(e)
|
||||
{
|
||||
$("#barcode-taginput").tagsManager("pushTag", $("#barcode-taginput").val());
|
||||
});
|
||||
|
||||
$('.input-group-qu').on('change', function(e)
|
||||
{
|
||||
@@ -249,12 +246,34 @@ $('#product-form input').keyup(function(event)
|
||||
{
|
||||
$("#qu-conversion-add-button").removeClass("disabled");
|
||||
}
|
||||
if (document.getElementById('product-form').checkValidity() === false) //There is at least one validation error
|
||||
{
|
||||
$("#barcode-add-button").addClass("disabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (prefillBarcode === undefined)
|
||||
{
|
||||
$("#barcode-add-button").removeClass("disabled");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#product-form select').change(function(event)
|
||||
{
|
||||
Grocy.FrontendHelpers.ValidateForm('product-form');
|
||||
|
||||
if (document.getElementById('product-form').checkValidity() === false) //There is at least one validation error
|
||||
{
|
||||
$("#barcode-add-button").addClass("disabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (prefillBarcode === undefined)
|
||||
{
|
||||
$("#barcode-add-button").removeClass("disabled");
|
||||
}
|
||||
}
|
||||
if (document.getElementById('product-form').checkValidity() === false) //There is at least one validation error
|
||||
{
|
||||
$("#qu-conversion-add-button").addClass("disabled");
|
||||
@@ -365,6 +384,17 @@ var quConversionsTable = $('#qu-conversions-table').DataTable({
|
||||
$('#qu-conversions-table tbody').removeClass("d-none");
|
||||
quConversionsTable.columns.adjust().draw();
|
||||
|
||||
var barcodeTable = $('#barcode-table').DataTable({
|
||||
'order': [[1, 'asc']],
|
||||
"orderFixed": [[1, 'asc']],
|
||||
'columnDefs': [
|
||||
{ 'orderable': false, 'targets': 0 },
|
||||
{ 'searchable': false, "targets": 0 }
|
||||
]
|
||||
});
|
||||
$('#barcode-table tbody').removeClass("d-none");
|
||||
barcodeTable.columns.adjust().draw();
|
||||
|
||||
Grocy.Components.UserfieldsForm.Load();
|
||||
$("#name").trigger("keyup");
|
||||
$('#name').focus();
|
||||
@@ -412,17 +442,44 @@ $(document).on('click', '.qu-conversion-delete-button', function(e)
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '.qu-conversion-edit-button', function (e)
|
||||
$(document).on('click', '.barcode-delete-button', function(e)
|
||||
{
|
||||
var id = $(e.currentTarget).attr('data-qu-conversion-id');
|
||||
Grocy.ProductEditFormRedirectUri = U("/quantityunitconversion/" + id.toString() + "?product=editobjectid");
|
||||
$('#save-product-button').click();
|
||||
});
|
||||
var objectId = $(e.currentTarget).attr('data-barcode-id');
|
||||
var productId = $(e.currentTarget).attr('data-product-id');
|
||||
var barcode = $(e.currentTarget).attr('data-barcode');
|
||||
var productBarcode = $(e.currentTarget).attr('data-product-barcode');
|
||||
|
||||
$("#qu-conversion-add-button").on("click", function(e)
|
||||
{
|
||||
Grocy.ProductEditFormRedirectUri = U("/quantityunitconversion/new?product=editobjectid");
|
||||
$('#save-product-button').click();
|
||||
bootbox.confirm({
|
||||
message: __t('Are you sure to remove this barcode?'),
|
||||
closeButton: false,
|
||||
buttons: {
|
||||
confirm: {
|
||||
label: __t('Yes'),
|
||||
className: 'btn-success'
|
||||
},
|
||||
cancel: {
|
||||
label: __t('No'),
|
||||
className: 'btn-danger'
|
||||
}
|
||||
},
|
||||
callback: function(result)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.Api.Delete('objects/product_barcodes/' + objectId, { },
|
||||
function(result)
|
||||
{
|
||||
Grocy.ProductEditFormRedirectUri = "reload";
|
||||
$('#save-product-button').click();
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#qu_id_purchase').blur(function(e)
|
||||
@@ -436,12 +493,12 @@ $('#qu_id_purchase').blur(function(e)
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on("Grocy.BarcodeScanned", function(e, barcode, target)
|
||||
$(window).on("message", function(e)
|
||||
{
|
||||
if (target != "#barcode-taginput")
|
||||
var data = e.originalEvent.data;
|
||||
|
||||
if (data.Message === "ProductBarcodesChanged" || data.Message === "ProductQUConversionChanged")
|
||||
{
|
||||
return;
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
$("#barcode-taginput").tagsManager("pushTag", barcode);
|
||||
});
|
||||
|
@@ -13,7 +13,7 @@
|
||||
Grocy.EditObjectId = result.created_object_id;
|
||||
Grocy.Components.UserfieldsForm.Save(function()
|
||||
{
|
||||
window.location.href = U('/productgroups');
|
||||
window.parent.postMessage(WindowMessageBag("CloseAllModals"), U("/productgroups"));
|
||||
});
|
||||
},
|
||||
function(xhr)
|
||||
@@ -30,7 +30,7 @@
|
||||
{
|
||||
Grocy.Components.UserfieldsForm.Save(function()
|
||||
{
|
||||
window.location.href = U('/productgroups');
|
||||
window.parent.postMessage(WindowMessageBag("CloseAllModals"), U("/productgroups"));
|
||||
});
|
||||
},
|
||||
function(xhr)
|
||||
|
@@ -55,3 +55,12 @@ $(document).on('click', '.product-group-delete-button', function(e)
|
||||
}
|
||||
});
|
||||
});
|
||||
$(window).on("message", function(e)
|
||||
{
|
||||
var data = e.originalEvent.data;
|
||||
|
||||
if (data.Message === "CloseAllModals")
|
||||
{
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
|
@@ -49,7 +49,7 @@ $(document).on('click', '.product-delete-button', function (e)
|
||||
if (stockAmount.toString() == "0")
|
||||
{
|
||||
bootbox.confirm({
|
||||
message: __t('Are you sure to delete product "%s"?', objectName),
|
||||
message: __t('Are you sure you want to deactivate this product "%s"?', objectName),
|
||||
closeButton: false,
|
||||
buttons: {
|
||||
confirm: {
|
||||
@@ -65,7 +65,9 @@ $(document).on('click', '.product-delete-button', function (e)
|
||||
{
|
||||
if (result === true)
|
||||
{
|
||||
Grocy.Api.Delete('objects/products/' + objectId, {},
|
||||
jsonData = {};
|
||||
jsonData.active = 0;
|
||||
Grocy.Api.Put('objects/products/' + objectId, jsonData,
|
||||
function (result)
|
||||
{
|
||||
window.location.href = U('/products');
|
||||
@@ -82,8 +84,8 @@ $(document).on('click', '.product-delete-button', function (e)
|
||||
else
|
||||
{
|
||||
bootbox.alert({
|
||||
title: __t('Delete not possible'),
|
||||
message: __t('This product cannot be deleted because it is in stock, please remove the stock amount first.') + '<br><br>' + __t('Stock amount') + ': ' + stockAmount + ' ' + __n(stockAmount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural),
|
||||
title: __t('Deactivation not possible'),
|
||||
message: __t('This product cannot be deactivated because it is in stock, please remove the stock amount first.') + '<br><br>' + __t('Stock amount') + ': ' + stockAmount + ' ' + __n(stockAmount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural),
|
||||
closeButton: false
|
||||
});
|
||||
}
|
||||
|
@@ -8,12 +8,13 @@
|
||||
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())
|
||||
{
|
||||
price = parseFloat(jsonForm.price).toFixed(2);
|
||||
// price is saved as 1 QU to stock
|
||||
price = parseFloat(jsonForm.price / amount).toFixed(2);
|
||||
|
||||
if ($("input[name='price-type']:checked").val() == "total-price")
|
||||
{
|
||||
@@ -37,6 +38,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)
|
||||
@@ -49,17 +51,13 @@
|
||||
var addBarcode = GetUriParam('addbarcodetoselection');
|
||||
if (addBarcode !== undefined)
|
||||
{
|
||||
var existingBarcodes = productDetails.product.barcode || '';
|
||||
if (existingBarcodes.length === 0)
|
||||
{
|
||||
productDetails.product.barcode = addBarcode;
|
||||
}
|
||||
else
|
||||
{
|
||||
productDetails.product.barcode += ',' + addBarcode;
|
||||
}
|
||||
var jsonDataBarcode = {};
|
||||
jsonDataBarcode.barcode = addBarcode;
|
||||
jsonDataBarcode.product_id = jsonForm.product_id;
|
||||
jsonDataBarcode.qu_factor_purchase_to_stock = jsonForm.qu_factor_purchase_to_stock;
|
||||
jsonDataBarcode.shopping_location_id = jsonForm.shopping_location_id;
|
||||
|
||||
Grocy.Api.Put('objects/products/' + productDetails.product.id, productDetails.product,
|
||||
Grocy.Api.Post('objects/product_barcodes', jsonDataBarcode,
|
||||
function(result)
|
||||
{
|
||||
$("#flow-info-addbarcodetoselection").addClass("d-none");
|
||||
@@ -69,7 +67,7 @@
|
||||
function(xhr)
|
||||
{
|
||||
Grocy.FrontendHelpers.EndUiBusy("purchase-form");
|
||||
console.error(xhr);
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response);
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -140,13 +138,66 @@ if (Grocy.Components.ProductPicker !== undefined)
|
||||
{
|
||||
Grocy.Components.ProductCard.Refresh(productId);
|
||||
|
||||
if (document.getElementById("product_id").getAttribute("barcode") != "null")
|
||||
{
|
||||
Grocy.Api.Get('productbarcodedetails/' + document.getElementById("product_id").getAttribute("barcode"),
|
||||
function(resultBarcode)
|
||||
{
|
||||
if (resultBarcode != null)
|
||||
{
|
||||
$('#product_id').attr("barcode-qu-factor-purchase-to-stock", resultBarcode.qu_factor_purchase_to_stock);
|
||||
$('#product_id').attr("barcode-shopping-location-id", resultBarcode.shopping_location_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#product_id').attr("barcode-qu-factor-purchase-to-stock", "null");
|
||||
$('#product_id').attr("barcode-shopping-location-id", "null");
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#product_id').attr("barcode-qu-factor-purchase-to-stock", "null");
|
||||
$('#product_id').attr("barcode-shopping-location-id", "null");
|
||||
}
|
||||
|
||||
Grocy.Api.Get('stock/products/' + productId,
|
||||
function(productDetails)
|
||||
{
|
||||
$('#price').val(parseFloat(productDetails.last_price).toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: 2 }));
|
||||
|
||||
$('#price').val(parseFloat(productDetails.last_price).toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: 2 }));
|
||||
|
||||
var qu_factor_purchase_to_stock = null;
|
||||
var barcode_shopping_location_id = null;
|
||||
|
||||
if (document.getElementById("product_id").getAttribute("barcode") != "null" && document.getElementById("product_id").getAttribute("barcode-qu-factor-purchase-to-stock") != "null")
|
||||
{
|
||||
qu_factor_purchase_to_stock = document.getElementById("product_id").getAttribute("barcode-qu-factor-purchase-to-stock");
|
||||
barcode_shopping_location_id = document.getElementById("product_id").getAttribute("barcode-shopping-location-id");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (productDetails.last_qu_factor_purchase_to_stock != null)
|
||||
{
|
||||
qu_factor_purchase_to_stock = productDetails.last_qu_factor_purchase_to_stock;
|
||||
}
|
||||
else
|
||||
{
|
||||
qu_factor_purchase_to_stock = productDetails.product.qu_factor_purchase_to_stock;
|
||||
}
|
||||
}
|
||||
|
||||
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) {
|
||||
if (productDetails.last_shopping_location_id != null)
|
||||
if (barcode_shopping_location_id != null)
|
||||
{
|
||||
Grocy.Components.ShoppingLocationPicker.SetId(barcode_shopping_location_id);
|
||||
}
|
||||
else if (productDetails.last_shopping_location_id != null)
|
||||
{
|
||||
Grocy.Components.ShoppingLocationPicker.SetId(productDetails.last_shopping_location_id);
|
||||
}
|
||||
@@ -161,15 +212,22 @@ if (Grocy.Components.ProductPicker !== undefined)
|
||||
Grocy.Components.LocationPicker.SetId(productDetails.location.id);
|
||||
}
|
||||
|
||||
$('#amount_qu_unit').attr("qu-factor-purchase-to-stock", productDetails.product.qu_factor_purchase_to_stock);
|
||||
$('#amount_qu_unit').attr("qu-factor-purchase-to-stock", 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);
|
||||
if (productDetails.product.qu_id_purchase === productDetails.product.qu_id_stock)
|
||||
$('#amount_qu_unit').attr("quantity-unit-stock-name-plural", productDetails.quantity_unit_stock.name_plural);
|
||||
$('#qu_factor_purchase_to_stock').val(qu_factor_purchase_to_stock);
|
||||
|
||||
|
||||
if (qu_factor_purchase_to_stock == 1)
|
||||
{
|
||||
$('#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)) + ")");
|
||||
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name + " (" + __t("will be multiplied by a factor of %1$s to get %2$s", parseFloat(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");
|
||||
@@ -193,7 +251,7 @@ if (Grocy.Components.ProductPicker !== undefined)
|
||||
|
||||
if (productDetails.product.enable_tare_weight_handling == 1)
|
||||
{
|
||||
var minAmount = parseFloat(productDetails.product.tare_weight) / productDetails.product.qu_factor_purchase_to_stock + parseFloat(productDetails.stock_amount);
|
||||
var minAmount = parseFloat(productDetails.product.tare_weight) / qu_factor_purchase_to_stock + parseFloat(productDetails.stock_amount);
|
||||
$("#amount").attr("min", minAmount);
|
||||
$("#amount").attr("step", "0.0001");
|
||||
$("#amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', minAmount.toLocaleString()));
|
||||
@@ -339,6 +397,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 }));
|
||||
|
@@ -25,7 +25,8 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
window.location.href = U("/product/" + GetUriParam("product"));
|
||||
window.parent.postMessage(WindowMessageBag("ProductQUConversionChanged"), U("/product/" + GetUriParam("product")));
|
||||
window.parent.postMessage(WindowMessageBag("CloseAllModals"), U("/product/" + GetUriParam("product")));
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -54,7 +55,8 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
window.location.href = U("/product/" + GetUriParam("product"));
|
||||
window.parent.postMessage(WindowMessageBag("ProductQUConversionChanged"), U("/product/" + GetUriParam("product")));
|
||||
window.parent.postMessage(WindowMessageBag("CloseAllModals"), U("/product/" + GetUriParam("product")));
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -79,7 +81,8 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
window.location.href = U("/product/" + GetUriParam("product"));
|
||||
window.parent.postMessage(WindowMessageBag("ProductQUConversionChanged"), U("/product/" + GetUriParam("product")));
|
||||
window.parent.postMessage(WindowMessageBag("CloseAllModals"), U("/product/" + GetUriParam("product")));
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@@ -177,6 +177,7 @@ function RefreshStockEntryRow(stockRowId)
|
||||
);
|
||||
|
||||
$('#stock-' + stockRowId + '-price').text(result.price);
|
||||
$('#stock-' + stockRowId + '-qu-factor-purchase-to-stock').text(result.qu_factor_purchase_to_stock);
|
||||
$('#stock-' + stockRowId + '-purchased-date').text(result.purchased_date);
|
||||
$('#stock-' + stockRowId + '-purchased-date-timeago').attr('datetime', result.purchased_date + ' 23:59:59');
|
||||
|
||||
|
@@ -26,6 +26,9 @@
|
||||
jsonData.location_id = 1;
|
||||
}
|
||||
jsonData.price = price;
|
||||
jsonData.qu_factor_purchase_to_stock = jsonForm.qu_factor_purchase_to_stock;
|
||||
console.log(jsonForm);
|
||||
console.log(jsonData);
|
||||
|
||||
jsonData.open = $("#open").is(":checked");
|
||||
|
||||
|
@@ -1,9 +1,10 @@
|
||||
var stockOverviewTable = $('#stock-overview-table').DataTable({
|
||||
'order': [[3, 'asc']],
|
||||
'order': [[4, 'asc']],
|
||||
'colReorder': false,
|
||||
'columnDefs': [
|
||||
{ 'orderable': false, 'targets': 0 },
|
||||
{ 'searchable': false, "targets": 0 },
|
||||
{ 'visible': false, 'targets': 4 },
|
||||
{ 'searchable': false, "targets": 0 },
|
||||
{ 'visible': false, 'targets': 5 },
|
||||
{ 'visible': false, 'targets': 6 }
|
||||
],
|
||||
@@ -19,7 +20,7 @@ $("#location-filter").on("change", function()
|
||||
value = "";
|
||||
}
|
||||
|
||||
stockOverviewTable.column(4).search(value).draw();
|
||||
stockOverviewTable.column(5).search(value).draw();
|
||||
});
|
||||
|
||||
$("#product-group-filter").on("change", function()
|
||||
@@ -30,7 +31,7 @@ $("#product-group-filter").on("change", function()
|
||||
value = "";
|
||||
}
|
||||
|
||||
stockOverviewTable.column(6).search(value).draw();
|
||||
stockOverviewTable.column(2).search(value).draw();
|
||||
});
|
||||
|
||||
$("#status-filter").on("change", function()
|
||||
@@ -44,7 +45,7 @@ $("#status-filter").on("change", function()
|
||||
// Transfer CSS classes of selected element to dropdown element (for background)
|
||||
$(this).attr("class", $("#" + $(this).attr("id") + " option[value='" + value + "']").attr("class") + " form-control");
|
||||
|
||||
stockOverviewTable.column(5).search(value).draw();
|
||||
stockOverviewTable.column(6).search(value).draw();
|
||||
});
|
||||
|
||||
$(".status-filter-message").on("click", function()
|
||||
@@ -252,7 +253,7 @@ function RefreshProductRow(productId)
|
||||
$('#product-' + productId + '-qu-name').text(__n(result.stock_amount, result.quantity_unit_stock.name, result.quantity_unit_stock.name_plural));
|
||||
$('#product-' + productId + '-amount').text(result.stock_amount);
|
||||
$('#product-' + productId + '-consume-all-button').attr('data-consume-amount', result.stock_amount);
|
||||
|
||||
$('#product-' + productId + '-factor-purchase-amount').text(__t('( %s', result.stock_factor_purchase_amount));
|
||||
$('#product-' + productId + '-next-best-before-date').text(result.next_best_before_date);
|
||||
$('#product-' + productId + '-next-best-before-date-timeago').attr('datetime', result.next_best_before_date);
|
||||
|
||||
|
@@ -30,17 +30,12 @@
|
||||
|
||||
if (addBarcode !== undefined)
|
||||
{
|
||||
var existingBarcodes = productDetails.product.barcode || '';
|
||||
if (existingBarcodes.length === 0)
|
||||
{
|
||||
productDetails.product.barcode = addBarcode;
|
||||
}
|
||||
else
|
||||
{
|
||||
productDetails.product.barcode += ',' + addBarcode;
|
||||
}
|
||||
var jsonDataBarcode = {};
|
||||
jsonDataBarcode.barcode = addBarcode;
|
||||
jsonDataBarcode.product_id = jsonForm.product_id;
|
||||
jsonDataBarcode.qu_factor_purchase_to_stock = productDetails.product.qu_factor_purchase_to_stock;
|
||||
|
||||
Grocy.Api.Put('objects/products/' + productDetails.product.id, productDetails.product,
|
||||
Grocy.Api.Post('objects/product_barcodes', jsonDataBarcode,
|
||||
function(result)
|
||||
{
|
||||
$("#flow-info-addbarcodetoselection").addClass("d-none");
|
||||
@@ -49,7 +44,8 @@
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
console.error(xhr);
|
||||
Grocy.FrontendHelpers.EndUiBusy("transfer-form");
|
||||
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user