Commit 001ce457 authored by Malcolm Blaney's avatar Malcolm Blaney

Cart->UpdateItem now takes extra tracking parameter so that Stock

module can explicitly turn off cart sync. Cart module no longer
changes tracking based on stock availability. Stock module now
also updates wholesale and retail markup prices when the base
price is changed in the grid. Grid module now responds to browser
resize events when in wide grid mode. A few small improvements to
Sell module to make sure data isn't getting loaded twice due to
different browser events firing. Fixed a bug in session_expired
where reload wasn't set in some cases.
parent c674c107
Pipeline #39289589 passed with stage
in 1 minute and 8 seconds
This diff is collapsed.
This diff is collapsed.
......@@ -31,12 +31,12 @@ function showColumnsLeft(module){var columns='#'+module+'-columns';var left=pars
$('#'+module+'-column-right').button({disabled:false});$(columns).css('margin-left',left+'px');}
function showColumnsRight(module){var columns='#'+module+'-columns';var left=parseInt($(columns).css('margin-left'),10)-scrollAmount;if(left<=columnDisplayWidth-totalColumnWidth-buttonWidth){left=columnDisplayWidth-totalColumnWidth-buttonWidth;$('#'+module+'-column-right').button({disabled:true});}
$('#'+module+'-column-left').button({disabled:false});$(columns).css('margin-left',left+'px');}
function toggleWideGrid(module,grid){if(initialWidth===0){initialWidth=$('.'+module).parents('.middle').width();}
function toggleWideGrid(module,grid){function resizeGrid(){if(grid){grid.resizeCanvas();}}
if(initialWidth===0){initialWidth=$('.'+module).parents('.middle').width();}
if(initialWidth){wideGrid=!wideGrid;if(dobrado.localStorage){localStorage[module+'WideGrid']=JSON.stringify(wideGrid);}
if(wideGrid){$('.middle').width('99%');}
else{$('.middle').width(initialWidth);}
if(grid){grid.resizeCanvas();}
var display='#'+module+'-column-display';var wrapper='#'+module+'-column-wrapper';columnDisplayWidth=$(display).width();$(wrapper).width(columnDisplayWidth-buttonWidth);scrollAmount=columnDisplayWidth-150;if(wideGrid){showColumnsLeft(module);}}}
if(wideGrid){$('.middle').width('99%');$(window).on('resize',resizeGrid);}
else{$('.middle').width(initialWidth);$(window).off('resize',resizeGrid);}
resizeGrid();var display='#'+module+'-column-display';var wrapper='#'+module+'-column-wrapper';columnDisplayWidth=$(display).width();$(wrapper).width(columnDisplayWidth-buttonWidth);scrollAmount=columnDisplayWidth-150;if(wideGrid){showColumnsLeft(module);}}}
return function(module,fn,grid){if(fn==='options'){showColumnOptions(module);}
else if(fn==='left'){showColumnsLeft(module);}
else if(fn==='right'){showColumnsRight(module);}
......
......@@ -96,6 +96,13 @@ if (!this.dobrado.grid) {
}
function toggleWideGrid(module, grid) {
function resizeGrid() {
if (grid) {
grid.resizeCanvas();
}
}
// Make sure the module is in the middle section of the layout,
// and then store the initial width so that it can be toggled.
if (initialWidth === 0) {
......@@ -108,13 +115,14 @@ if (!this.dobrado.grid) {
}
if (wideGrid) {
$('.middle').width('99%');
// Track browser resize events in wideGrid mode.
$(window).on('resize', resizeGrid);
}
else {
$('.middle').width(initialWidth);
$(window).off('resize', resizeGrid);
}
if (grid) {
grid.resizeCanvas();
}
resizeGrid();
// Also re-calculate the column options display width.
var display = '#' + module + '-column-display';
var wrapper = '#' + module + '-column-wrapper';
......
......@@ -25,7 +25,7 @@
// for the JavaScript code in this page.
if(!this.dobrado.sell){dobrado.sell={};}
(function(){'use strict';var sell=null;var purchaseGrid=null;var purchaseGridId='';var allAvailableGrid=null;var allAvailableGridId='';var allAvailableData=[];var currentProduct=null;var currentWeight='';var leavePageWarning=true;var user=0;var sparkID=null;var sparkAddress=null;var updateQuantity=false;var saving=false;var viewPurchases=true;$(function(){if($('.sell').length===0){return;}
(function(){'use strict';var sell=null;var purchaseGrid=null;var purchaseGridId='';var allAvailableGrid=null;var allAvailableGridId='';var allAvailableData=[];var currentProduct=null;var currentUser='';var currentWeight='';var leavePageWarning=true;var user=0;var sparkID=null;var sparkAddress=null;var updateQuantity=false;var saving=false;var viewPurchases=true;$(function(){if($('.sell').length===0){return;}
var currentPage=$('#page-select').val();window.addEventListener('beforeunload',function(event){if(sell&&sell.processed&&sell.processed.length!==0&&leavePageWarning){$('.control .info').hide();$('#page-select').val(currentPage).selectmenu('refresh');var message='Please save your orders before leaving the page.';event.returnValue=message;return message;}});if($('.sell-payment-message').html()!==''){$('.sell-payment-message button').button().click(paymentDone);$('.sell-payment-message').dialog({show:true,modal:true,width:400,height:200,position:{my:'top',at:'top+50',of:window},title:'Payment',close:paymentDone,create:dobrado.fixedDialog});}
$('.sell-finished').dialog({show:true,autoOpen:false,modal:true,width:500,height:250,position:{my:'top',at:'top+50',of:window},title:'Payment Method',create:dobrado.fixedDialog});$('#customer-detail-submit').button().click(customerDetail);$('#sell-checkout-dialog').dialog({show:true,autoOpen:false,modal:true,width:500,height:500,position:{my:'top',at:'top+50',of:window},title:'Checkout',create:dobrado.fixedDialog});$('#purchase-form .view-all').button().click(viewAll);$('.sell .save').button().click(save);$('.sell .done').button({disabled:true}).click(finishSale);$('.sell .reset').button().click(resetSaleForUser);$('#purchase-form .remove').button().click(remove);$('#purchase-form .add').button().click(add);$('#purchase-form').keypress(addFromEnter);$('#purchase-name-input').val('').change(function(){setTimeout(function(){showUser();},10);});$('#purchase-product-input').val('').change(function(){setTimeout(function(){showProduct();},10);});$('#purchase-price-input').val('');$('#purchase-quantity-input').val('');$('#purchase-quantity-input').spinner({disabled:true,min:0,spin:setQuantity,change:setQuantity});$('.sell-finished-back').button().click(function(){$('.sell-finished').dialog('close');});$('.sell-finished-done').button().click(newSale);$('#sell-auto-save').prop('checked',true).change(function(){$('.sell .save').toggle();$('.sell .warning').toggle();});$('.sell-describe-auto-save').click(function(){$('.sell-auto-save-description').toggle();});if($('.grid').length!==0){gridSetup();}
if($('#purchase-connect').length===1){$('#purchase-connect').controlgroup();$('#purchase-update-quantity').checkboxradio({icon:false}).click(toggleUpdate);$('#purchase-connect-settings').button({icon:'ui-icon-gear',showLabel:false}).click(connectSettings);}
......@@ -73,7 +73,8 @@ break;}}
return value;}
function showUser(event,ui){var username=$('#purchase-name-input').val();if(ui){username=ui.item.value;}
if(username!==''&&$.inArray(username,sell.users)===-1){alert('If an account was just created for '+username+' please reload the page.');$('#purchase-name-input').val('');username='';}
if(username===''||$.inArray(username,sell.userIndex)!==-1){sell.userIndex[user]=username;if(dobrado.localStorage){localStorage.sell=JSON.stringify(sell);}}
if(username!==''&&currentUser===username){return;}
currentUser=username;if(username===''||$.inArray(username,sell.userIndex)!==-1){sell.userIndex[user]=username;if(dobrado.localStorage){localStorage.sell=JSON.stringify(sell);}}
else{var message='Changing username will remove unsaved data, continue?';if(sell.data[user]&&sell.data[user].length!==0&&!confirm(message)){$('#purchase-name-input').val('');return;}
dobrado.log('Loading purchases for user...','info');$.post('/php/request.php',{request:'sell',action:'listUser',username:username,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,'sell showUser')){return;}
var quantity=1;var price=sell.buyerGroup[username];sell.userIndex[user]=username;sell.data[user]=JSON.parse(response);if(sell.data[user]){if(dobrado.localStorage){localStorage.sell=JSON.stringify(sell);}
......@@ -88,6 +89,7 @@ else{$('#purchase-grower-info').html('');}
return false;}});}
function showProduct(event,ui){var username=$('#purchase-name-input').val();var price='retail';if(username!==''){price=sell.buyerGroup[username];}
var productFound=false;var product=$('#purchase-product-input').val();if(ui){product=ui.item.value;}
if(currentProduct&&currentProduct.name===product){return;}
$.each(sell.products,function(index,item){if(item.name===product){productFound=true;currentProduct=item;if(currentProduct.unit==='variable'){$('#purchase-quantity-input').val('1').spinner('disable');$('#purchase-price-input').val(decimalString(item[price]));$('#purchase-price-input').attr('readonly',false);}
else{$('#purchase-price-input').val('($'+decimalString(item[price])+'/'+item.unit+')');$('#purchase-price-input').attr('readonly',true);if(currentProduct.unit==='kg'&&currentWeight!==''){$('#purchase-quantity-input').val(currentWeight).spinner('enable');setQuantity();}
else{$('#purchase-quantity-input').val('').spinner('enable');}}
......
......@@ -39,8 +39,9 @@ if (!this.dobrado.sell) {
var allAvailableGrid = null;
var allAvailableGridId = '';
var allAvailableData = [];
// The currently selected product.
// Track the currently selected user and product.
var currentProduct = null;
var currentUser = '';
// The current weight read from the server.
var currentWeight = '';
// Show a warning if the user tries to leave the page without saving, unless
......@@ -499,6 +500,11 @@ if (!this.dobrado.sell) {
$('#purchase-name-input').val('');
username = '';
}
if (username !== '' && currentUser === username) {
return;
}
currentUser = username;
// If a username is selected want to match it with the index when saving.
// (Also don't fetch the data for a user again until the current data has
// been saved.)
......@@ -615,6 +621,10 @@ if (!this.dobrado.sell) {
if (ui) {
product = ui.item.value;
}
if (currentProduct && currentProduct.name === product) {
return;
}
$.each(sell.products, function(index, item) {
if (item.name === product) {
productFound = true;
......
......@@ -137,7 +137,10 @@ var columns=stockGrid.getColumns();var field=columns[args.cell].field;var value=
if((field==='available'||field==='purchaseAvailable')&&value){args.item.supplierAvailable=1;stockGridView.updateItem(args.item.id,args.item);}
else if(field==='supplierAvailable'&&!value){args.item.available=0;args.item.purchaseAvailable=0;stockGridView.updateItem(args.item.id,args.item);}
dobrado.log('Updating product.','info');var product=currentName;$.post('/php/request.php',{request:'stock',action:'save',field:field,value:value,product:product,supplier:currentSupplier,composite:args.item.composite,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,'stock updateStock')){return;}
var save=JSON.parse(response);if(save.other&&save.other!==''){alert(product+' from '+save.other+' is now unavailable');var id=product+'-'+save.other;var other=stockGridView.getItemById(id);other.available=0;other.purchaseAvailable=0;stockGridView.updateItem(id,other);}});}
var save=JSON.parse(response);if(save.other){alert(product+' from '+save.other+' is now unavailable');let id=product+'-'+save.other;let other=stockGridView.getItemById(id);other.available=0;other.purchaseAvailable=0;stockGridView.updateItem(id,other);}
if(save.wholesale||save.retail){let id=product+'-'+currentSupplier;let update=stockGridView.getItemById(id);if(save.wholesale){update.wholesale=save.wholesale;}
if(save.retail){update.retail=save.retail;}
stockGridView.updateItem(id,update);}});}
function remove(){function removeProduct(){if(selected.length>1){if(!confirmRemoveMultiple){if(confirm('Remove '+selected.length+' products?')){confirmRemoveMultiple=true;currentRemove=0;}
else{return false;}}
if(currentRemove===selected.length){confirmRemoveMultiple=false;resetForm(false);showAll(false);return false;}
......
......@@ -1357,15 +1357,26 @@ if (!this.dobrado.stock) {
return;
}
var save = JSON.parse(response);
if (save.other && save.other !== '') {
if (save.other) {
alert(product + ' from ' + save.other + ' is now unavailable');
// Update the grid for the other supplier.
var id = product + '-' + save.other;
var other = stockGridView.getItemById(id);
let id = product + '-' + save.other;
let other = stockGridView.getItemById(id);
other.available = 0;
other.purchaseAvailable = 0;
stockGridView.updateItem(id, other);
}
if (save.wholesale || save.retail) {
let id = product + '-' + currentSupplier;
let update = stockGridView.getItemById(id);
if (save.wholesale) {
update.wholesale = save.wholesale;
}
if (save.retail) {
update.retail = save.retail;
}
stockGridView.updateItem(id, update);
}
});
}
......
......@@ -99,6 +99,15 @@ function dobrado_mail($email, $subject, $message, $headers,
return mail($email, $subject, $message, $headers, '-f ' . $sender);
}
function price_string($value) {
// The built in number_format() function is used to format floats as strings
// representing a price, ie with two decimal places. This is just a helper
// function to avoid writing out all the parameters. Note that the built in
// round() function cannot be used because it doesn't always return two
// decimal places, and number_format does the rounding internally.
return number_format($value, 2, '.', '');
}
function substitute($label, $group = '', $patterns = '', $replacements = '') {
$content = '';
$mysqli = connect_db();
......
......@@ -19,15 +19,14 @@ session_start();
function session_expired() {
// All javascript xhr should be able to log errors.
if (!isset($_SESSION['token'])) {
// May have an expired session because page.php does 'not modified' checks
// on feed pages. When this happens reload is used to skip the check.
$_SESSION['reload'] = true;
echo json_encode(['error' => 'Session expired: reloading page.']);
return true;
if (isset($_SESSION['token']) &&
isset($_POST['token']) && $_SESSION['token'] === $_POST['token']) {
return false;
}
if (!isset($_POST['token'])) return true;
return $_SESSION['token'] !== $_POST['token'];
// May have an expired session because page.php does 'not modified' checks
// on feed pages. When this happens reload is used to skip the check.
$_SESSION['reload'] = true;
echo json_encode(['error' => 'Session expired: reloading page.']);
return true;
}
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