Commit 6a61bf16 authored by Malcolm Blaney's avatar Malcolm Blaney

Added a supplier input field to the Stock module import options.

parent 43252b26
Pipeline #38154314 passed with stage
in 1 minute and 16 seconds
......@@ -229,6 +229,7 @@ class Stock extends Base {
'<input id="stock-show-import" type="checkbox">' .
'<span id="stock-import-wrapper"><select id="stock-import-supplier">' .
$this->SupplierSelect() . '</select>' .
'<input type="text" id="stock-import-input">' .
'<input id="stock-import-file" type="file"></span>' .
'</div>' .
'<input type="checkbox" id="stock-show-columns">' .
......@@ -726,6 +727,7 @@ class Stock extends Base {
'"","#stock-import-help","float","right"',
'"","#stock-import-wrapper","display","inline-block"',
'"","#stock-import-supplier-button","width","150px"',
'"","#stock-import-input","width","170px"',
'"","#stock-import-file","max-width","240px"',
'"","#stock-download","float","right"',
'"","#stock-profiles-button","float","right"',
......@@ -3178,7 +3180,7 @@ class Stock extends Base {
foreach ($detail->SupplierOnly() as $supplier => $name) {
$options .= '<option value="' . $supplier . '">' . $name . '</option>';
}
return $options;
return $options . '<option value="other">other...</option>';
}
private function TrackQuantity() {
......
This diff is collapsed.
......@@ -102,7 +102,7 @@ if (!this.dobrado.stock) {
$('#stock-group-select').selectmenu({ change: changeGroup });
$('#stock-import-file').val('').change(loadImportData);
$('#stock-import-supplier').selectmenu();
$('#stock-import-supplier').selectmenu({ select: checkOtherSupplier });
$('#stock-open-product-form').button().click(function() {
if (mobile) {
$('#stock-form').toggle();
......@@ -134,8 +134,7 @@ if (!this.dobrado.stock) {
$('#stock-columns').controlgroup().click(updateColumns);
$('#stock-import-wrapper').hide();
$('#stock-show-import').prop('checked', false).
checkboxradio({ icon: false }).click(function() {
$('#stock-import-wrapper').toggle(); });
checkboxradio({ icon: false }).click(showImportOptions);
$('#stock-show-columns').prop('checked', false).
checkboxradio({ icon: false }).click(function() {
dobrado.grid.showColumns('stock', 'options'); });
......@@ -279,6 +278,23 @@ if (!this.dobrado.stock) {
return /\d+\s*(each|g|kg|kilo|l)/i.test(name);
}
function checkOtherSupplier(event, ui) {
if (ui.item.value === 'other') {
// Refresh the selectmenu so that the default option is displayed next
// time the menu is displayed.
$('#stock-import-supplier').val('').selectmenu('refresh');
$('#stock-import-supplier-button').hide();
$('#stock-import-input').val('').show();
let usernames = [];
$.each(stock.users, function(index, item) {
usernames.push(item);
});
$('#stock-import-input').autocomplete({ minLength: 1,
search: dobrado.fixAutoCompleteMemoryLeak,
source: usernames });
}
}
function download() {
// If columns isn't set in local storage create a default.
var columns = JSON.stringify(['product', 'supplier', 'price', 'unit',
......@@ -1102,6 +1118,15 @@ if (!this.dobrado.stock) {
}
}
function showImportOptions() {
$('#stock-import-wrapper').toggle();
if ($('#stock-import-wrapper').is(':visible')) {
// When the import options are shown reset to show select menu by default.
$('#stock-import-supplier-button').show();
$('#stock-import-input').val('').hide();
}
}
function updateColumns() {
// When updating columns always add the product column first.
var columns = [allColumns[0]];
......@@ -2028,7 +2053,13 @@ if (!this.dobrado.stock) {
var headerFound = false;
var headerCheck = 0;
var emptyLineCount = 0;
importSupplier = $('#stock-import-supplier').val();
importSupplier = '';
if ($('#stock-import-input').val() !== '') {
importSupplier = $('#stock-import-input').val();
}
else {
importSupplier = $('#stock-import-supplier').val();
}
$.each(data, function(i, item) {
// Before checking the line format, need to check for any quotes, remove
......@@ -2191,7 +2222,13 @@ if (!this.dobrado.stock) {
var headerFound = false;
var headerCheck = 0;
var emptyLineCount = 0;
importSupplier = $('#stock-import-supplier').val();
importSupplier = '';
if ($('#stock-import-input').val() !== '') {
importSupplier = $('#stock-import-input').val();
}
else {
importSupplier = $('#stock-import-supplier').val();
}
$.each(data, function(i, item) {
// Before checking the line format, need to check for any quotes, remove
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment