mirror of
https://github.com/grocy/grocy.git
synced 2025-04-30 10:05:45 +00:00
Added flow to directly add articles and barcodes form purchase and inventory view
This commit is contained in:
parent
c4a22c18f7
commit
bd16b8c851
15
grocy.js
15
grocy.js
@ -80,3 +80,18 @@ String.prototype.contains = function(search)
|
|||||||
{
|
{
|
||||||
return this.toLowerCase().indexOf(search.toLowerCase()) !== -1;
|
return this.toLowerCase().indexOf(search.toLowerCase()) !== -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Grocy.GetUriParam = function(key)
|
||||||
|
{
|
||||||
|
var currentUri = decodeURIComponent(window.location.search.substring(1));
|
||||||
|
var vars = currentUri.split('&');
|
||||||
|
|
||||||
|
for (i = 0; i < vars.length; i++) {
|
||||||
|
var currentParam = vars[i].split('=');
|
||||||
|
|
||||||
|
if (currentParam[0] === key)
|
||||||
|
{
|
||||||
|
return currentParam[1] === undefined ? true : currentParam[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -1 +1 @@
|
|||||||
1.0.0
|
1.0.1
|
@ -56,6 +56,7 @@ $('#product_id').on('change', function(e)
|
|||||||
$('#selected-product-last-used').text((productDetails.last_used || 'never').substring(0, 10));
|
$('#selected-product-last-used').text((productDetails.last_used || 'never').substring(0, 10));
|
||||||
$('#selected-product-last-used-timeago').text($.timeago(productDetails.last_used || ''));
|
$('#selected-product-last-used-timeago').text($.timeago(productDetails.last_used || ''));
|
||||||
$('#amount').attr('max', productDetails.stock_amount);
|
$('#amount').attr('max', productDetails.stock_amount);
|
||||||
|
$('#consumption-form').validator('update');
|
||||||
|
|
||||||
Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
|
Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago');
|
||||||
Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
|
Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago');
|
||||||
|
@ -8,18 +8,50 @@
|
|||||||
function (productDetails)
|
function (productDetails)
|
||||||
{
|
{
|
||||||
Grocy.FetchJson('/api/stock/inventory-product/' + jsonForm.product_id + '/' + jsonForm.new_amount + '?bestbeforedate=' + $('#best_before_date').val(),
|
Grocy.FetchJson('/api/stock/inventory-product/' + jsonForm.product_id + '/' + jsonForm.new_amount + '?bestbeforedate=' + $('#best_before_date').val(),
|
||||||
function (result) {
|
function(result)
|
||||||
|
{
|
||||||
|
var addBarcode = Grocy.GetUriParam('addbarcodetoselection');
|
||||||
|
if (addBarcode !== undefined)
|
||||||
|
{
|
||||||
|
var existingBarcodes = productDetails.product.barcode || '';
|
||||||
|
if (existingBarcodes.length === 0)
|
||||||
|
{
|
||||||
|
productDetails.product.barcode = addBarcode;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
productDetails.product.barcode += ',' + addBarcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
Grocy.PostJson('/api/edit-object/products/' + productDetails.product.id, productDetails.product,
|
||||||
|
function (result) { },
|
||||||
|
function(xhr)
|
||||||
|
{
|
||||||
|
console.error(xhr);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
toastr.success('Stock amount of ' + productDetails.product.name + ' is now ' + jsonForm.new_amount.toString() + ' ' + productDetails.quantity_unit_stock.name);
|
toastr.success('Stock amount of ' + productDetails.product.name + ' is now ' + jsonForm.new_amount.toString() + ' ' + productDetails.quantity_unit_stock.name);
|
||||||
|
|
||||||
$('#new_amount').val('');
|
if (addBarcode !== undefined)
|
||||||
$('#best_before_date').val('');
|
{
|
||||||
$('#product_id').val('');
|
window.location.href = '/inventory';
|
||||||
$('#product_id_text_input').focus();
|
}
|
||||||
$('#product_id_text_input').val('');
|
else
|
||||||
$('#product_id_text_input').trigger('change');
|
{
|
||||||
$('#inventory-form').validator('validate');
|
$('#inventory-change-info').hide();
|
||||||
|
$('#new_amount').val('');
|
||||||
|
$('#best_before_date').val('');
|
||||||
|
$('#product_id').val('');
|
||||||
|
$('#product_id_text_input').focus();
|
||||||
|
$('#product_id_text_input').val('');
|
||||||
|
$('#product_id_text_input').trigger('change');
|
||||||
|
$('#inventory-form').validator('validate');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
function (xhr) {
|
function(xhr)
|
||||||
|
{
|
||||||
console.error(xhr);
|
console.error(xhr);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -86,12 +118,47 @@ $(function()
|
|||||||
var input = $('#product_id_text_input').val().toString();
|
var input = $('#product_id_text_input').val().toString();
|
||||||
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
|
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
|
||||||
|
|
||||||
if (possibleOptionElement.length > 0)
|
if (Grocy.GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0)
|
||||||
{
|
{
|
||||||
$('#product_id').val(possibleOptionElement.val());
|
$('#product_id').val(possibleOptionElement.val());
|
||||||
$('#product_id').data('combobox').refresh();
|
$('#product_id').data('combobox').refresh();
|
||||||
$('#product_id').trigger('change');
|
$('#product_id').trigger('change');
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var optionElement = $("#product_id option:contains('" + input + "')").first();
|
||||||
|
if (input.length > 0 && optionElement.length === 0 && Grocy.GetUriParam('addbarcodetoselection') === undefined )
|
||||||
|
{
|
||||||
|
bootbox.dialog({
|
||||||
|
message: '<strong>' + input + '</strong> could not be resolved to a product, how do you want to proceed?',
|
||||||
|
title: 'Create or assign product',
|
||||||
|
onEscape: function() { },
|
||||||
|
buttons: {
|
||||||
|
cancel: {
|
||||||
|
label: 'Cancel',
|
||||||
|
className: 'btn-default',
|
||||||
|
callback: function() { }
|
||||||
|
},
|
||||||
|
addnewproduct: {
|
||||||
|
label: 'Add as new product',
|
||||||
|
className: 'btn-success',
|
||||||
|
callback: function()
|
||||||
|
{
|
||||||
|
window.location.href = '/product/new?prefillname=' + encodeURIComponent(input) + '&returnto=' + encodeURIComponent(window.location.pathname);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
addbarcode: {
|
||||||
|
label: 'Add as barcode to existing product',
|
||||||
|
className: 'btn-info',
|
||||||
|
callback: function()
|
||||||
|
{
|
||||||
|
window.location.href = '/inventory?addbarcodetoselection=' + encodeURIComponent(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#new_amount').val('');
|
$('#new_amount').val('');
|
||||||
@ -140,6 +207,31 @@ $(function()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var prefillProduct = Grocy.GetUriParam('createdproduct');
|
||||||
|
if (prefillProduct !== undefined)
|
||||||
|
{
|
||||||
|
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + prefillProduct + "']").first();
|
||||||
|
if (possibleOptionElement.length === 0)
|
||||||
|
{
|
||||||
|
possibleOptionElement = $("#product_id option:contains('" + prefillProduct + "')").first();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (possibleOptionElement.length > 0)
|
||||||
|
{
|
||||||
|
$('#product_id').val(possibleOptionElement.val());
|
||||||
|
$('#product_id').data('combobox').refresh();
|
||||||
|
$('#product_id').trigger('change');
|
||||||
|
$('#new_amount').focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var addBarcode = Grocy.GetUriParam('addbarcodetoselection');
|
||||||
|
if (addBarcode !== undefined)
|
||||||
|
{
|
||||||
|
$('#addbarcodetoselection').text(addBarcode);
|
||||||
|
$('#flow-info-addbarcodetoselection').removeClass('hide');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#best_before_date-datepicker-button').on('click', function(e)
|
$('#best_before_date-datepicker-button').on('click', function(e)
|
||||||
@ -215,18 +307,23 @@ $('#new_amount').on('change', function(e)
|
|||||||
{
|
{
|
||||||
var amountToAdd = newAmount - productDetails.stock_amount;
|
var amountToAdd = newAmount - productDetails.stock_amount;
|
||||||
$('#inventory-change-info').text('This means ' + amountToAdd.toString() + ' ' + productDetails.quantity_unit_stock.name + ' will be added to stock');
|
$('#inventory-change-info').text('This means ' + amountToAdd.toString() + ' ' + productDetails.quantity_unit_stock.name + ' will be added to stock');
|
||||||
$('#inventory-change-infoo').show();
|
$('#inventory-change-info').show();
|
||||||
|
$('#best_before_date').attr('required', 'required');
|
||||||
}
|
}
|
||||||
else if (newAmount < productStockAmount)
|
else if (newAmount < productStockAmount)
|
||||||
{
|
{
|
||||||
var amountToRemove = productStockAmount - newAmount;
|
var amountToRemove = productStockAmount - newAmount;
|
||||||
$('#inventory-change-info').text('This means ' + amountToRemove.toString() + ' ' + productDetails.quantity_unit_stock.name + ' will be removed from stock');
|
$('#inventory-change-info').text('This means ' + amountToRemove.toString() + ' ' + productDetails.quantity_unit_stock.name + ' will be removed from stock');
|
||||||
$('#inventory-change-info').show();
|
$('#inventory-change-info').show();
|
||||||
|
$('#best_before_date').removeAttr('required');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$('#inventory-change-info').hide();
|
$('#inventory-change-info').hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('#inventory-form').validator('update');
|
||||||
|
$('#inventory-form').validator('validate');
|
||||||
},
|
},
|
||||||
function(xhr)
|
function(xhr)
|
||||||
{
|
{
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
<div class="help-block with-errors"></div>
|
<div class="help-block with-errors"></div>
|
||||||
|
<div id="flow-info-addbarcodetoselection" class="text-muted small hide"><strong><span id="addbarcodetoselection"></span></strong> will be added to the list of barcodes for the selected product on submit.</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
},
|
},
|
||||||
callback: function(result)
|
callback: function(result)
|
||||||
{
|
{
|
||||||
if (result == true)
|
if (result === true)
|
||||||
{
|
{
|
||||||
Grocy.FetchJson('/api/delete-object/locations/' + $(e.target).attr('data-location-id'),
|
Grocy.FetchJson('/api/delete-object/locations/' + $(e.target).attr('data-location-id'),
|
||||||
function(result)
|
function(result)
|
||||||
|
@ -2,12 +2,19 @@
|
|||||||
{
|
{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
var redirectDestination = '/products';
|
||||||
|
var returnTo = Grocy.GetUriParam('returnto');
|
||||||
|
if (returnTo !== undefined)
|
||||||
|
{
|
||||||
|
redirectDestination = returnTo + '?createdproduct=' + encodeURIComponent($('#name').val());
|
||||||
|
}
|
||||||
|
|
||||||
if (Grocy.EditMode === 'create')
|
if (Grocy.EditMode === 'create')
|
||||||
{
|
{
|
||||||
Grocy.PostJson('/api/add-object/products', $('#product-form').serializeJSON(),
|
Grocy.PostJson('/api/add-object/products', $('#product-form').serializeJSON(),
|
||||||
function(result)
|
function(result)
|
||||||
{
|
{
|
||||||
window.location.href = '/products';
|
window.location.href = redirectDestination;
|
||||||
},
|
},
|
||||||
function(xhr)
|
function(xhr)
|
||||||
{
|
{
|
||||||
@ -20,7 +27,7 @@
|
|||||||
Grocy.PostJson('/api/edit-object/products/' + Grocy.EditObjectId, $('#product-form').serializeJSON(),
|
Grocy.PostJson('/api/edit-object/products/' + Grocy.EditObjectId, $('#product-form').serializeJSON(),
|
||||||
function(result)
|
function(result)
|
||||||
{
|
{
|
||||||
window.location.href = '/products';
|
window.location.href = redirectDestination;
|
||||||
},
|
},
|
||||||
function(xhr)
|
function(xhr)
|
||||||
{
|
{
|
||||||
@ -61,6 +68,13 @@ $(function()
|
|||||||
$('#name').focus();
|
$('#name').focus();
|
||||||
$('#product-form').validator();
|
$('#product-form').validator();
|
||||||
$('#product-form').validator('validate');
|
$('#product-form').validator('validate');
|
||||||
|
|
||||||
|
var prefillName = Grocy.GetUriParam('prefillname');
|
||||||
|
if (prefillName !== undefined)
|
||||||
|
{
|
||||||
|
$('#name').val(prefillName);
|
||||||
|
$('#name').focus();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.input-group-qu').on('change', function(e)
|
$('.input-group-qu').on('change', function(e)
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
},
|
},
|
||||||
callback: function(result)
|
callback: function(result)
|
||||||
{
|
{
|
||||||
if (result == true)
|
if (result === true)
|
||||||
{
|
{
|
||||||
Grocy.FetchJson('/api/delete-object/products/' + $(e.target).attr('data-product-id'),
|
Grocy.FetchJson('/api/delete-object/products/' + $(e.target).attr('data-product-id'),
|
||||||
function(result)
|
function(result)
|
||||||
|
@ -10,18 +10,49 @@
|
|||||||
var amount = jsonForm.amount * productDetails.product.qu_factor_purchase_to_stock;
|
var amount = jsonForm.amount * productDetails.product.qu_factor_purchase_to_stock;
|
||||||
|
|
||||||
Grocy.FetchJson('/api/stock/add-product/' + jsonForm.product_id + '/' + amount + '?bestbeforedate=' + $('#best_before_date').val(),
|
Grocy.FetchJson('/api/stock/add-product/' + jsonForm.product_id + '/' + amount + '?bestbeforedate=' + $('#best_before_date').val(),
|
||||||
function (result) {
|
function(result)
|
||||||
|
{
|
||||||
|
var addBarcode = Grocy.GetUriParam('addbarcodetoselection');
|
||||||
|
if (addBarcode !== undefined)
|
||||||
|
{
|
||||||
|
var existingBarcodes = productDetails.product.barcode || '';
|
||||||
|
if (existingBarcodes.length === 0)
|
||||||
|
{
|
||||||
|
productDetails.product.barcode = addBarcode;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
productDetails.product.barcode += ',' + addBarcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
Grocy.PostJson('/api/edit-object/products/' + productDetails.product.id, productDetails.product,
|
||||||
|
function (result) { },
|
||||||
|
function(xhr)
|
||||||
|
{
|
||||||
|
console.error(xhr);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
toastr.success('Added ' + amount + ' ' + productDetails.quantity_unit_stock.name + ' of ' + productDetails.product.name + ' to stock');
|
toastr.success('Added ' + amount + ' ' + productDetails.quantity_unit_stock.name + ' of ' + productDetails.product.name + ' to stock');
|
||||||
|
|
||||||
$('#amount').val(1);
|
if (addBarcode !== undefined)
|
||||||
$('#best_before_date').val('');
|
{
|
||||||
$('#product_id').val('');
|
window.location.href = '/purchase';
|
||||||
$('#product_id_text_input').focus();
|
}
|
||||||
$('#product_id_text_input').val('');
|
else
|
||||||
$('#product_id_text_input').trigger('change');
|
{
|
||||||
$('#purchase-form').validator('validate');
|
$('#amount').val(1);
|
||||||
|
$('#best_before_date').val('');
|
||||||
|
$('#product_id').val('');
|
||||||
|
$('#product_id_text_input').focus();
|
||||||
|
$('#product_id_text_input').val('');
|
||||||
|
$('#product_id_text_input').trigger('change');
|
||||||
|
$('#purchase-form').validator('validate');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
function (xhr) {
|
function(xhr)
|
||||||
|
{
|
||||||
console.error(xhr);
|
console.error(xhr);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -92,12 +123,47 @@ $(function()
|
|||||||
var input = $('#product_id_text_input').val().toString();
|
var input = $('#product_id_text_input').val().toString();
|
||||||
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
|
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
|
||||||
|
|
||||||
if (possibleOptionElement.length > 0)
|
if (Grocy.GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0)
|
||||||
{
|
{
|
||||||
$('#product_id').val(possibleOptionElement.val());
|
$('#product_id').val(possibleOptionElement.val());
|
||||||
$('#product_id').data('combobox').refresh();
|
$('#product_id').data('combobox').refresh();
|
||||||
$('#product_id').trigger('change');
|
$('#product_id').trigger('change');
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var optionElement = $("#product_id option:contains('" + input + "')").first();
|
||||||
|
if (input.length > 0 && optionElement.length === 0 && Grocy.GetUriParam('addbarcodetoselection') === undefined )
|
||||||
|
{
|
||||||
|
bootbox.dialog({
|
||||||
|
message: '<strong>' + input + '</strong> could not be resolved to a product, how do you want to proceed?',
|
||||||
|
title: 'Create or assign product',
|
||||||
|
onEscape: function() { },
|
||||||
|
buttons: {
|
||||||
|
cancel: {
|
||||||
|
label: 'Cancel',
|
||||||
|
className: 'btn-default',
|
||||||
|
callback: function() { }
|
||||||
|
},
|
||||||
|
addnewproduct: {
|
||||||
|
label: 'Add as new product',
|
||||||
|
className: 'btn-success',
|
||||||
|
callback: function()
|
||||||
|
{
|
||||||
|
window.location.href = '/product/new?prefillname=' + encodeURIComponent(input) + '&returnto=' + encodeURIComponent(window.location.pathname);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
addbarcode: {
|
||||||
|
label: 'Add as barcode to existing product',
|
||||||
|
className: 'btn-info',
|
||||||
|
callback: function()
|
||||||
|
{
|
||||||
|
window.location.href = '/purchase?addbarcodetoselection=' + encodeURIComponent(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#amount').val(1);
|
$('#amount').val(1);
|
||||||
@ -139,6 +205,31 @@ $(function()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var prefillProduct = Grocy.GetUriParam('createdproduct');
|
||||||
|
if (prefillProduct !== undefined)
|
||||||
|
{
|
||||||
|
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + prefillProduct + "']").first();
|
||||||
|
if (possibleOptionElement.length === 0)
|
||||||
|
{
|
||||||
|
possibleOptionElement = $("#product_id option:contains('" + prefillProduct + "')").first();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (possibleOptionElement.length > 0)
|
||||||
|
{
|
||||||
|
$('#product_id').val(possibleOptionElement.val());
|
||||||
|
$('#product_id').data('combobox').refresh();
|
||||||
|
$('#product_id').trigger('change');
|
||||||
|
$('#best_before_date').focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var addBarcode = Grocy.GetUriParam('addbarcodetoselection');
|
||||||
|
if (addBarcode !== undefined)
|
||||||
|
{
|
||||||
|
$('#addbarcodetoselection').text(addBarcode);
|
||||||
|
$('#flow-info-addbarcodetoselection').removeClass('hide');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#best_before_date-datepicker-button').on('click', function(e)
|
$('#best_before_date-datepicker-button').on('click', function(e)
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
<div class="help-block with-errors"></div>
|
<div class="help-block with-errors"></div>
|
||||||
|
<div id="flow-info-addbarcodetoselection" class="text-muted small hide"><strong><span id="addbarcodetoselection"></span></strong> will be added to the list of barcodes for the selected product on submit.</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
},
|
},
|
||||||
callback: function(result)
|
callback: function(result)
|
||||||
{
|
{
|
||||||
if (result == true)
|
if (result === true)
|
||||||
{
|
{
|
||||||
Grocy.FetchJson('/api/delete-object/quantity_units/' + $(e.target).attr('data-quantityunit-id'),
|
Grocy.FetchJson('/api/delete-object/quantity_units/' + $(e.target).attr('data-quantityunit-id'),
|
||||||
function(result)
|
function(result)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user