Move balance checks to the start of the javascript execution;

main
Bruno Carrión 1 year ago
parent 51f2838553
commit 70c899404d
  1. 1559
      index.php
  2. 90
      shop_and_order.php

File diff suppressed because it is too large Load Diff

@ -54,6 +54,53 @@
cache: false
});
/********************************************************
* My BALANCES
********************************************************/
// Check UF balances
var content = document.getElementById("stagewrap");
content.style.visibility = "hidden";
$.ajax({
type: "POST",
url: "php/ctrl/Account.php",
data: {
oper: "getUfBalance",
uf: <?= $_SESSION["userdata"]["uf_id"] ?>,
}
}).done(function(xmlDoc) {
var balance = xmlDoc.getElementsByTagName("balance")[0];
var lastUpdate = xmlDoc.getElementsByTagName("last_update")[0];
var result = NaN;
var timeDelta;
if (balance && lastUpdate) {
try {
var result = parseFloat(balance.textContent);
} catch (err) {};
if (!isNaN(result) && isFinite(result) && result < 0) {
timeDelta = new Date() - $.datepicker.parseDate(
"dd-mm-yy",
lastUpdate.textContent.split(" ")[0].trim()
);
if (timeDelta / (1000 * 60 ** 2 * 24) > 14) {
var newContent = document.createElement("div");
newContent.id = "noMoney";
newContent.innerHTML = `<img src="img/angry.jpeg">
<h1>Fa més de dues setmanes que estàs en números vermells!</h1>
<h2>Fins que no carreguis el moneder de CANPUJADES, l'aixada restara bloquejada</h2>`;
content.parentElement.insertBefore(newContent, content);
content.parentElement.removeChild(content);
content = void(0);
}
}
}
}).fail(function(err) {
console.error(err);
}).always(function() {
if (content) {
content.style.visibility = "visible";
}
});
//decide what to do in which section
var what = $.getUrlVar('what');
@ -566,49 +613,6 @@
$('.loadSpinner').attr('src', "img/ajax-loader-<?= $default_theme; ?>.gif");
$('#leftCol .loadSpinner').hide();
// Check UF balances
var content = document.getElementById("stagewrap");
content.style.visibility = "hidden";
$.ajax({
type: "POST",
url: "php/ctrl/Account.php",
data: {
oper: "getUfBalance",
uf: <?=$_SESSION["userdata"]["uf_id"]?>,
}
}).done(function(xmlDoc) {
var balance = xmlDoc.getElementsByTagName("balance")[0];
var lastUpdate = xmlDoc.getElementsByTagName("last_update")[0];
var result = NaN;
var timeDelta;
if (balance && lastUpdate) {
try {
var result = parseFloat(balance.textContent);
} catch (err) {};
if (!isNaN(result) && isFinite(result) && result < 0) {
timeDelta = new Date() - $.datepicker.parseDate(
"dd-mm-yy",
lastUpdate.textContent.split(" ")[0].trim()
);
if (timeDelta / (1000 * 60 ** 2 * 24) > 14) {
var newContent = document.createElement("div");
newContent.id = "noMoney";
newContent.innerHTML = `<img src="img/angry.jpeg">
<h1>Fa més de dues setmanes que estàs en números vermells!</h1>
<h2>Fins que no carreguis el moneder de CANPUJADES, l'aixada restara bloquejada</h2>`;
content.parentElement.insertBefore(newContent, content);
content.parentElement.removeChild(content);
content = void(0);
}
}
}
}).fail(function(err) {
console.error(err);
}).always(function() {
if (content) {
content.style.visibility = "visible";
}
});
}); //close document ready
</script>

Loading…
Cancel
Save