Commit 836036c5 authored by Malcolm Blaney's avatar Malcolm Blaney

Add 'available' to default column list in Stock module. Return the

other supplier when an inline availability change updates another
supplier, and then update that row in the grid.
parent 63c6c54b
Pipeline #11610969 (#) passed with stage
in 1 minute and 47 seconds
......@@ -628,10 +628,10 @@ class Stock extends Base {
'<p>The second import format is also csv, however since it contains '.
'the usernames of your suppliers, you don\'t need to select one when '.
'importing. The header row for this format is:<br>Name,User,Description,'.
'Quantity,Price,Wholesale,Retail,Size,Unit,Taxable,Grower,Category,'.
'Available,PurchaseAvailable,SupplierAvailable<br>These formats can '.
'Quantity,Price,Wholesale,Retail,Size,Unit,Taxable,Grower,Category,<br>'.
'Available,PurchaseAvailable,SupplierAvailable</p><p>These formats can '.
'also be exported by switching to one of the two default profiles and '.
'then clicking <b>download</b>.</p>';
'then clicking <b>Download</b>.</p>';
$template = ['"stock-taxable","","Attracts GST"',
'"stock-not-taxable","","Exempt from GST"',
......@@ -1597,7 +1597,7 @@ class Stock extends Base {
'sort' => [['columnId' => 'supplier', 'sortAsc' => true],
['columnId' => 'product', 'sortAsc' => true]]];
}
return ['columns' => ['product', 'supplier', 'price', 'unit'],
return ['columns' => ['product', 'supplier', 'price', 'unit', 'available'],
'sort' => [['columnId' => 'product', 'sortAsc' => true]]];
}
......@@ -2147,6 +2147,7 @@ class Stock extends Base {
$this->SetPurchaseGroup();
$error = '';
$other = '';
$available_query = '';
// Check if the user is choosing to change the product name. All previous
// purchases also need to be updated in this case.
......@@ -2207,8 +2208,9 @@ class Stock extends Base {
'AND stock.user != "'.$supplier.'" AND '.$organiser->GroupQuery();
if ($result = $mysqli->query($query)) {
if ($stock = $result->fetch_assoc()) {
$other = $stock['user'];
$query = 'UPDATE stock SET order_available = 0, '.
'purchase_available = 0 WHERE user = "'.$stock['user'].'" AND '.
'purchase_available = 0 WHERE user = "'.$other.'" AND '.
'name = "'.$product.'"';
if (!$mysqli->query($query)) {
$this->Log('Stock->Save 3: '.$mysqli->error);
......@@ -2259,6 +2261,7 @@ class Stock extends Base {
$this->Log('Stock->Save 6: '.$mysqli->error);
}
}
if ($other !== '') $result['other'] = $other;
$result['done'] = true;
}
else {
......
This diff is collapsed.
......@@ -165,7 +165,8 @@ if (!this.dobrado.stock) {
resetForm();
// If columns isn't set in local storage create a default.
var columns = JSON.stringify(['product', 'supplier', 'price', 'unit']);
var columns = JSON.stringify(['product', 'supplier', 'price', 'unit',
'available']);
var sort = '';
var profile = '';
if (dobrado.localStorage) {
......@@ -241,7 +242,8 @@ if (!this.dobrado.stock) {
function download() {
// If columns isn't set in local storage create a default.
var columns = JSON.stringify(['product', 'supplier', 'price', 'unit']);
var columns = JSON.stringify(['product', 'supplier', 'price', 'unit',
'available']);
var sort = '';
var profile = '';
if (dobrado.localStorage) {
......@@ -350,7 +352,7 @@ if (!this.dobrado.stock) {
var columns = [];
// If columns isn't set in local storage create a default.
var columnIds = ['product', 'supplier', 'price','unit'];
var columnIds = ['product', 'supplier', 'price', 'unit', 'available'];
if (dobrado.localStorage) {
if (localStorage.stockColumns) {
columnIds = JSON.parse(localStorage.stockColumns);
......@@ -929,15 +931,33 @@ if (!this.dobrado.stock) {
}
dobrado.log('Updating product.', 'info');
// Need to save currentName as it will change before the callback returns.
var product = currentName;
$.post('/php/request.php',
{ request: 'stock', action: 'save', field: field, value: value,
product: currentName, supplier: currentSupplier,
product: product, supplier: currentSupplier,
composite: args.item.composite, url: location.href,
token: dobrado.token },
function(response) {
if (dobrado.checkResponseError(response, 'stock save')) {
return;
}
var save = JSON.parse(response);
if (save.other && save.other !== '') {
alert(product + ' from ' + save.other + ' is now unavailable');
// Update the grid for the other supplier.
$.each(stock.products, function(i, item) {
if (item.name === product && item.user === save.other) {
stock.products[i].available = 0;
stock.products[i].purchaseAvailable = 0;
return false;
}
});
if (stockGrid) {
stockGrid.setData(stock.products);
stockGrid.render();
}
}
});
}
......@@ -1020,7 +1040,8 @@ if (!this.dobrado.stock) {
var confirmRemoveMultiple = false;
var selected = stockGrid.getSelectedRows();
// If columns isn't set in local storage create a default.
var columns = JSON.stringify(['product', 'supplier', 'price', 'unit']);
var columns = JSON.stringify(['product', 'supplier', 'price', 'unit',
'available']);
var sort = '';
var profile = '';
if (dobrado.localStorage) {
......@@ -1309,7 +1330,7 @@ if (!this.dobrado.stock) {
var supplier = $('#stock-user-input').val();
if ($.inArray(supplier, stock.users) === -1) {
alert('Supplier account must be in the current buying group.');
alert('Please click Add Supplier to create a new account.');
$('#stock-user-input').val('');
return false;
}
......@@ -1458,7 +1479,7 @@ if (!this.dobrado.stock) {
function showAll(resetColumns) {
var columns = [];
// If columns isn't set in local storage create a default.
var columnIds = ['product', 'supplier', 'price', 'unit'];
var columnIds = ['product', 'supplier', 'price', 'unit', 'available'];
var sort = '';
var profile = '';
if (dobrado.localStorage) {
......@@ -1568,7 +1589,8 @@ if (!this.dobrado.stock) {
}
else {
// If columns isn't set in local storage create a default.
var columns = JSON.stringify(['product', 'supplier', 'price', 'unit']);
var columns = JSON.stringify(['product', 'supplier', 'price', 'unit',
'available']);
var sort = '';
if (dobrado.localStorage) {
if (localStorage.stockColumns) {
......
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