From 093e7443caabac89f6edfb008bb41a5abc4430b2 Mon Sep 17 00:00:00 2001 From: micwallace Date: Sat, 25 Feb 2017 14:19:51 +1100 Subject: [PATCH] Various minor patches - Fixed firefox appcache issue where newly loaded appcache does not take affect. - Patch to prevent stored items added in previous versions (with undefined cost field) from causing transactions to fail. - UI fixes for demo buttons. - Re-enabled various currencies that were causing browser freezing in some older browser versions. - Allow stock count to become a minus qty. --- admin/assets/wpos/wpos.js | 4 ++-- admin/content/generalsettings.php | 10 +++++----- admin/content/realtime.php | 15 ++++++++++++--- assets/js/wpos/core.js | 11 +++++++---- assets/js/wpos/sales.js | 4 +++- kitchen/kitchen.js | 8 ++++---- library/wpos/models/Logger.php | 12 +++++++++--- library/wpos/models/WposPosSale.php | 12 ++++++++++-- library/wpos/models/db/StockModel.php | 2 +- 9 files changed, 53 insertions(+), 25 deletions(-) diff --git a/admin/assets/wpos/wpos.js b/admin/assets/wpos/wpos.js index 13aff366..fb06dc19 100644 --- a/admin/assets/wpos/wpos.js +++ b/admin/assets/wpos/wpos.js @@ -44,8 +44,8 @@ $(function(){ // init WPOS.isLogged(); // dev/demo quick login - if (document.location.host=="alpha.wallacepos.com"){ - $("#logindiv").append(''); + if (document.location.host=="demo.wallacepos.com" || document.location.host=="alpha.wallacepos.com"){ + $("#logindiv").append(''); } }); function WPOSAdmin(){ diff --git a/admin/content/generalsettings.php b/admin/content/generalsettings.php index 99ee1a70..f490f809 100644 --- a/admin/content/generalsettings.php +++ b/admin/content/generalsettings.php @@ -52,10 +52,10 @@ - - - - + + + + @@ -66,7 +66,7 @@ - + diff --git a/admin/content/realtime.php b/admin/content/realtime.php index 6ef5a797..67ff53a0 100644 --- a/admin/content/realtime.php +++ b/admin/content/realtime.php @@ -311,17 +311,26 @@ function populateOnlineDevices(devices) { devtable.html(''); devselect.html(''); + devselect.append(""); + if (Object.keys(devices).length > 1) { // devices will always have the admin dash for (var i in devices) { if (i != 0) { // do not include admin dash - devtable.append("  " + devices[i].username + " / " + WPOS.devices[i].name + " / " + WPOS.devices[i].locationname + ""); - devselect.append(""); + var devname, locname; + if (WPOS.devices.hasOwnProperty(i)){ + devname = WPOS.devices[i].name; + locname = WPOS.devices[i].locationname; + } else { + devname = "Unknown"; + locname = "Unknown"; + } + devtable.append("  " + devices[i].username + " / " + devname + " / " + locname + ""); + devselect.append(""); } } } else { devtable.append("There are no online devices."); } - devselect.append(""); } function processIncomingSale(saleobj) { diff --git a/assets/js/wpos/core.js b/assets/js/wpos/core.js index b5e1ba01..6a0b1a13 100644 --- a/assets/js/wpos/core.js +++ b/assets/js/wpos/core.js @@ -80,7 +80,7 @@ function WPOS() { console.log("Appcache update finished, reloading..."); setLoadingBar(100, "Loading..."); appCache.swapCache(); - location.reload(); + location.reload(true); }); appCache.addEventListener('noupdate', function(e) { console.log("No appcache update found"); @@ -100,7 +100,7 @@ function WPOS() { console.log("Appcache update finished, reloading..."); setLoadingBar(100, "Loading..."); appCache.swapCache(); - location.reload(); + location.reload(true); } }; // Check for device UUID & present Login, initial setup is triggered if the device UUID is not present @@ -1741,8 +1741,11 @@ $(function () { }); // dev/demo quick login - if (document.location.host=="alpha.wallacepos.com"){ - $("#logindiv").append(''); + if (document.location.host=="demo.wallacepos.com" || document.location.host=="alpha.wallacepos.com"){ + var login = $("#logindiv"); + login.append(''); + if (document.location.host=="alpha.wallacepos.com") + login.append(''); } // window size diff --git a/assets/js/wpos/sales.js b/assets/js/wpos/sales.js index d8b427e2..9b7317f5 100644 --- a/assets/js/wpos/sales.js +++ b/assets/js/wpos/sales.js @@ -201,7 +201,9 @@ function WPOSItems() { * @param {Object} item */ function addItem(item) { - // remove last row from table if its invalid. + // Item cost may be null if we're adding stored items that were created in a previous version, explicitly set the cost in this case. + if (!item.hasOwnProperty('cost')) item.cost = 0.00; + // TODO: remove last row from table if its invalid? // check if a priced item is already present in the sale and if so increment it's qty if (item.price==""){ // insert item into table diff --git a/kitchen/kitchen.js b/kitchen/kitchen.js index 55a200dd..847accce 100644 --- a/kitchen/kitchen.js +++ b/kitchen/kitchen.js @@ -56,7 +56,7 @@ function WPOSKitchen() { window.applicationCache.addEventListener('updateready', function(e) { console.log("Appcache update finished, reloading..."); setLoadingBar(100, "Loading..."); - location.reload(); + location.reload(true); }); window.applicationCache.addEventListener('noupdate', function(e) { console.log("No appcache update found"); @@ -75,7 +75,7 @@ function WPOSKitchen() { if (window.applicationCache.status == window.applicationCache.UPDATEREADY){ console.log("Appcache update finished, reloading..."); setLoadingBar(100, "Loading..."); - location.reload(); + location.reload(true); } }; // Check for device UUID & present Login, initial setup is triggered if the device UUID is not present @@ -1388,7 +1388,7 @@ $(function () { }); // dev/demo quick login - if (document.location.host=="alpha.wallacepos.com"){ - $("#logindiv").append(''); + if (document.location.host=="demo.wallacepos.com" || document.location.host=="alpha.wallacepos.com"){ + $("#logindiv").append(''); } }); diff --git a/library/wpos/models/Logger.php b/library/wpos/models/Logger.php index 7a14d34c..12cae882 100644 --- a/library/wpos/models/Logger.php +++ b/library/wpos/models/Logger.php @@ -37,9 +37,15 @@ class Logger { * @param null $data */ public static function write($msg, $type="Misc", $data=null, $showUser=true){ - $auth = new Auth(); - if ($showUser) - $user = $auth->isLoggedIn() ? $auth->getUserId().":".$auth->getUsername() : ($auth->isCustomerLoggedIn() ? $auth->getCustomerId().":".$auth->getCustomerUsername() : 'system'); + + if ($showUser) { + if (php_sapi_name() === 'cli'){ + $user = "system:cli"; + } else { + $auth = new Auth(); + $user = $auth->isLoggedIn() ? $auth->getUserId() . ":" . $auth->getUsername() : ($auth->isCustomerLoggedIn() ? $auth->getCustomerId() . ":" . $auth->getCustomerUsername() : 'system'); + } + } // open file $fd = fopen($_SERVER['DOCUMENT_ROOT'].$_SERVER['APP_ROOT'].self::$directory.DIRECTORY_SEPARATOR."wpos_log_".date("y-m-d").".txt", "a"); // write string diff --git a/library/wpos/models/WposPosSale.php b/library/wpos/models/WposPosSale.php index 38d1fbac..cc847afb 100644 --- a/library/wpos/models/WposPosSale.php +++ b/library/wpos/models/WposPosSale.php @@ -233,8 +233,13 @@ public function insertTransaction($result) { $jsonval = new JsonValidate($this->jsonobj, '{"ref":"", "userid":1, "devid":1, "locid":1, "items":"[", "payments":"[", "cost":1, "total":1, "processdt":1}'); if (($errors = $jsonval->validate())!==true){ - $result['error'] = $errors; - return $result; + // fix for offline sales not containing cost field and getting stuck + if (strpos($errors, "cost must be specified")!==false){ + $this->jsonobj->cost = 0.00; + } else { + $result['error'] = $errors; + return $result; + } } // check for existing record, if record exists (it's an order), we need to clear the old data to add the most current. if (($sale=$this->salesMdl->getByRef($this->ref))===false){ @@ -497,6 +502,9 @@ private function insertTransactionItems() //$stockMdl = new StockModel(); $wposStock = new WposAdminStock(); foreach ($this->jsonobj->items as $key=>$item) { + // fix for offline sales not containing cost field and getting stuck + if (!isset($item->cost)) $item->cost = 0.00; + if (!$res=$itemsMdl->create($this->id, $item->sitemid, $item->ref, $item->qty, $item->name, $item->desc, $item->taxid, $item->tax, $item->cost, $item->unit, $item->price)) { $this->itemErr = $itemsMdl->errorInfo; return false; diff --git a/library/wpos/models/db/StockModel.php b/library/wpos/models/db/StockModel.php index 27a40f9e..4731fcaf 100644 --- a/library/wpos/models/db/StockModel.php +++ b/library/wpos/models/db/StockModel.php @@ -82,7 +82,7 @@ public function setStockLevel($storeditemid, $locationid, $stocklevel){ * @return bool|int|string Returns false on failure, number of rows affected or a newly inserted id. */ public function incrementStockLevel($storeditemid, $locationid, $amount, $decrement = false){ - $sql = "UPDATE stock_levels SET `stocklevel`= GREATEST(`stocklevel` ".($decrement==true?'-':'+')." :stocklevel, 0) WHERE `storeditemid`=:storeditemid AND `locationid`=:locationid"; + $sql = "UPDATE stock_levels SET `stocklevel`= (`stocklevel` ".($decrement==true?'-':'+')." :stocklevel) WHERE `storeditemid`=:storeditemid AND `locationid`=:locationid"; $placeholders = [":storeditemid"=>$storeditemid, ":locationid"=>$locationid, ":stocklevel"=>$amount]; $result = $this->update($sql, $placeholders);