Skip to content

Commit

Permalink
Various minor patches
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
micwallace committed Feb 25, 2017
1 parent fa07f6e commit 093e744
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 25 deletions.
4 changes: 2 additions & 2 deletions admin/assets/wpos/wpos.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ $(function(){
// init
WPOS.isLogged();
// dev/demo quick login
if (document.location.host=="alpha.wallacepos.com"){
$("#logindiv").append('<button class="btn btn-primary btn-sm" onclick="$(\'#loguser\').val(\'admin\');$(\'#logpass\').val(\'admin\'); WPOS.login();">Dev Login</button>');
if (document.location.host=="demo.wallacepos.com" || document.location.host=="alpha.wallacepos.com"){
$("#logindiv").append('<button class="btn btn-primary btn-sm" onclick="$(\'#loguser\').val(\'admin\');$(\'#logpass\').val(\'admin\'); WPOS.login();">Demo Login</button>');
}
});
function WPOSAdmin(){
Expand Down
10 changes: 5 additions & 5 deletions admin/content/generalsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
<option value="₣">₣ Franc</option>
<option value="₤">₤ Lira</option>
<option value="﷼">﷼ Saudi Riyal</option>
<!--<option value="₧">₧ Peseta</option> ! Encoding issues -->
<!--<option value="₹">₹ Indian Rupee</option> ! Encoding issues -->
<!--<option value="₨">₨ Rupee</option> ! Encoding issues -->
<!--<option value="₩">₩ Won</option> ! Encoding issues -->
<option value="₧">₧ Peseta</option>
<option value="₹">₹ Indian Rupee</option>
<option value="₨">₨ Rupee</option>
<option value="₩">₩ Won</option>
<option value="₴">₴ Hryvnia</option>
<option value="₯">₯ Drachma</option>
<option value="₮">₮ Tugrik</option>
Expand All @@ -66,7 +66,7 @@
<option value="₭">₭ Kip</option>
<option value="₪">₪ New Sheqel</option>
<option value="₫">₫ Dong</option>
<!--<option value="៛">៛ Riel</option> ! Encoding issues -->
<option value="៛">៛ Riel</option>
<option value="Rp">Rp Rupiah</option>
<option value="kr">kr Krone/Kroon/Krona</option>
<option value="Kč">Kč Koruna</option>
Expand Down
15 changes: 12 additions & 3 deletions admin/content/realtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,26 @@ function populateOnlineDevices(devices) {
devtable.html('');
devselect.html('');
devselect.append("<option value='all' selected>All</option>");
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("<tr><td><i class='icon-lightbulb green icon-large'></i>&nbsp;&nbsp;" + devices[i].username + " / " + WPOS.devices[i].name + " / " + WPOS.devices[i].locationname + "</td></tr>");
devselect.append("<option value='" + i + "'>" + devices[i].username + " / " + WPOS.devices[i].name + " / " + WPOS.devices[i].locationname + "</option>");
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("<tr><td><i class='icon-lightbulb green icon-large'></i>&nbsp;&nbsp;" + devices[i].username + " / " + devname + " / " + locname + "</td></tr>");
devselect.append("<option value='" + i + "'>" + devices[i].username + " / " + devname + " / " + locname + "</option>");
}
}
} else {
devtable.append("<tr><td>There are no online devices.</td></tr>");
}
devselect.append("<option value='all' selected>All</option>");
}
function processIncomingSale(saleobj) {
Expand Down
11 changes: 7 additions & 4 deletions assets/js/wpos/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
Expand Down Expand Up @@ -1741,8 +1741,11 @@ $(function () {
});

// dev/demo quick login
if (document.location.host=="alpha.wallacepos.com"){
$("#logindiv").append('<button class="btn btn-primary btn-sm" onclick="$(\'#username\').val(\'admin\');$(\'#password\').val(\'admin\'); WPOS.userLogin();">Dev Login</button><button class="btn btn-primary btn-sm" onclick="$(\'#loginmodal\').hide();">Hide Login</button>');
if (document.location.host=="demo.wallacepos.com" || document.location.host=="alpha.wallacepos.com"){
var login = $("#logindiv");
login.append('<button class="btn btn-primary btn-sm" onclick="$(\'#username\').val(\'admin\');$(\'#password\').val(\'admin\'); WPOS.userLogin();">Demo Login</button>');
if (document.location.host=="alpha.wallacepos.com")
login.append('<button class="btn btn-primary btn-sm" onclick="$(\'#loginmodal\').hide();">Hide Login</button>');
}

// window size
Expand Down
4 changes: 3 additions & 1 deletion assets/js/wpos/sales.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions kitchen/kitchen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
Expand Down Expand Up @@ -1388,7 +1388,7 @@ $(function () {
});

// dev/demo quick login
if (document.location.host=="alpha.wallacepos.com"){
$("#logindiv").append('<button class="btn btn-primary btn-sm" onclick="$(\'#username\').val(\'admin\');$(\'#password\').val(\'admin\'); WPOS.userLogin();">Dev Login</button>');
if (document.location.host=="demo.wallacepos.com" || document.location.host=="alpha.wallacepos.com"){
$("#logindiv").append('<button class="btn btn-primary btn-sm" onclick="$(\'#username\').val(\'admin\');$(\'#password\').val(\'admin\'); WPOS.userLogin();">Demo Login</button>');
}
});
12 changes: 9 additions & 3 deletions library/wpos/models/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions library/wpos/models/WposPosSale.php
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion library/wpos/models/db/StockModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 093e744

Please sign in to comment.