"use strict";
var usr,
l,
k,
ln,
uid,
deletedItem,
cats,
menus,
products,
people,
options,
staff,
office,
shop,
tOrder,
ono = 0,
to,
tables,
snacktime,
dollar,
euro,
cmbI = 0,
lastItem,
timeEdit,
timeNote,
tAdd,
online = 1;
shop = 0;
//function setData() {
//console.log('data set');
function setData() {
cats = localStorage.getItem('cats') ? JSON.parse(localStorage.cats) : '[]';
menus = localStorage.getItem('menus') ? JSON.parse(localStorage.menus) : '[]';
products = localStorage.getItem('products') ? JSON.parse(localStorage.products) : '[]';
office = localStorage.getItem('office') ? JSON.parse(localStorage.office) : '[1,1]';
dollar = office[0];
euro = office[1];
options = localStorage.getItem('options') ? JSON.parse(localStorage.options) : '[]';
tables = localStorage.getItem('tables') ? JSON.parse(localStorage.tables) : '[]';
// people = localStorage.getItem('people') ? JSON.parse(localStorage.tables) : '[]';
}
var $ = function (id) {
return document.getElementById(id);
}
//function showHistory(x) {
// var img = new Image(),
// foto = $('foto');
// img.className = 'foto';
// foto.className = 'fotoWrap';
// foto.innerHTML = svgLoad();
// img.onload = function () {
// foto.innerHTML = '';
// foto.appendChild(img);
// }
// img.src = 'https://storage.googleapis.com/negocompa01/' + x;
//}
function showHistory(x) {
// if ($('trash').className == 'disN') {
// $('trash').removeAttribute('class');
var i, j, k, hist, item, id, note, invDate, note, product, dPrice, pid, ckd, oclass, oMeta, istat, opsD, opA, o,
ict1 = 0,
ladd = 'disN',
align = 'aL',
trash = '',
tItems = '',
total = 0,
totalprice = 0,
foto = $('foto');
// console.log('show history');
foto.addEventListener("click", function () {
closeFoto(x);
});
foto.className = 'fotoWrap';
o = orders[x];
invDate = o[0]['updated'].toLocaleString();
hist = '
';
}
if (oj[8] == 0) {
ckd = 'checked';
}
grpCk = tGrp;
// tType = oj[8];
}
if (oj[8] == 0) {
type = 'radio';
} else {
type = 'checkbox';
}
name = grpCk;
p$ = '';
oprice = '';
if (oj[7] > 0) {
p$ = '$';
oprice = oj[7];
}
oname = oj[ln].replace("//", "");
// op0 += '---' + x + '---';
// oid = 'op0' + j + x;
op0 += '
';
// op0 += '
';
// op0 += '';
// op0 += oname + ' ' + p$ + oprice;
// op0 += ' ';
// op0 += '';
}
}
// op0 += '
';
if (op0 != '') {
op0 = '
' + op0 + '
';
}
return op0;
}
function hideLineP() {
document.querySelectorAll(".linep").forEach(function (item) {
item.className = 'disN';
});
document.querySelectorAll(".addlp").forEach(function (item) {
item.className = 'disN';
});
document.querySelectorAll(".boxp").forEach(function (item) {
item.className = '';
});
}
function showLineP(x) {
hideLineP();
$('linep' + x).className = 'linep';
$('addp' + x).className = 'addlp';
$('boxp' + x).className = 'boxp';
}
function loadInfo(x, y) {
$('econtent').className = 'disN';
$('staffedit').className = 'blueLink ml20';
$('editinfo').className = 'greyLink';
if (x != '') {
loadPhoto(x);
}
if (y > 0) {
$('eplate').className = 'aL p10';
}
}
function showPhoto(x) {
var img = new Image(),
foto = $('foto');
img.className = 'foto';
foto.className = 'fotoWrap';
foto.innerHTML = svgLoad();
img.onload = function () {
foto.innerHTML = '';
foto.appendChild(img);
}
img.src = 'https://storage.googleapis.com/img-dirtymenu/' + x;
foto.addEventListener("click", function () {
closeFoto(x);
});
}
function showCC() {
var img = new Image(),
scc = $('scc');
// img.className = 'foto';
scc.className = 'mt20';
scc.innerHTML = svgLoad();
img.onload = function () {
scc.innerHTML = '';
scc.appendChild(img);
}
img.src = 'https://storage.googleapis.com/img-dirtymenu/cc.png';
}
function showEdit(x) {
$('econtent').className = '';
$('ephoto').className = 'disN';
$('eplate').className = 'disN';
$('staffedit').className = 'greyLink ml20';
if (x > 0) {
$('editinfo').className = 'blueLink';
}
}
function addValueM(x, y) {
var i, pid, update, iid, z, qty,
pr,
ino,
// tOrder,
// tItem,
// lqty = $('lqty' + x).innerHTMLH,
dataL = $('line' + x),
ops = $('opsE' + x).getElementsByClassName('ops'),
total = Number(dataL.dataset.oprice),
opsN = [];
for (i = 0; i < ops.length; i++) {
if (ops[i].checked == true) {
if (ops[i].value > 0) {
if (y == 15) {
total += Number(ops[i].value);
} else {
total = Number(ops[i].value);
}
}
opsN.push(ops[i].id.substr(3));
}
}
$('price' + x).innerHTML = ' $' + total;
dataL.dataset.price = total;
dataL.dataset.ops = opsN;
console.log(total);
// showSnack('snackG', 'updated', 1000);
strO();
}
function addValueO(x, y) { //x=line number y = cat CHECK-Y, CHECK d-1 for multiple rows of options
var i, pid, update, iid, ino, total,
tOrder = orders[ono],
tItem = tOrder[x],
oprice = tItem['oprice'],
ops = $('div1').getElementsByClassName('ops'),
opsN = [];
console.log(ops);
for (i = 0; i < ops.length; i++) {
if (ops[i].checked == true) {
// if (ops[i].value > 0) {
if (y == 15) {
total = Number(oprice);
total += Number(ops[i].value);
// console.log('15');
} else {
total = Number(ops[i].value);
console.log(i);
console.log(ops[i].value);
}
// }
opsN.push(ops[i].id.substring(ops[i].id.indexOf('-') + 1));
}
}
console.log(total);
tItem['price'] = total;
tItem['ops'] = opsN;
$('price' + x).innerHTML = ' $' + total;
updateItem(x, 'ops');
updateItem(x, 'price');
showSnack('snackG', 'updated', 1000);
strO();
}
//function addValueO(x) {
// var i, ops, pid, update, iid, z, //opsA,
// tOrder = orders[ono],
// tItem = tOrder[x],
// total = Number(tItem['oprice']),
// iid = tItem['iid'],
// ops = $('opsEz' + x).getElementsByClassName('opt'),
// opsN = [];
// if (ops != '') {
// for (i = 0; i < ops.length; i++) {
// if (ops[i].checked == true) {
// total += Number(ops[i].value);
// opsN.push(ops[i].id.substr(3));
// }
// }
// tItem['price'] = total;
// // tItem['ops'] = opsN;
// $('price' + x).innerHTML = ' $' + total;
// }
//
// if (iid > 0) {
// updateItem(x, 'price');
// updateItem(x, 'ops');
// }
// showSnack('snackG', 'updated', 1000);
// strO();
//}
function unSub(ino) {
var tOrder = orders[ono],
tMeta = tOrder[0],
tItem = tOrder[ino],
status = tItem['status'];;
if (tMeta['status'] == 3) {
tItem['status'] = 2;
} else {
tItem['status'] = 1;
}
// updateItem(ino, 'status');
strO();
showSnack('snackG', 'not canceled', 1000);
showItems();
}
//function unSub(ino) {
// var tOrder = orders[ono],
// tItem = tOrder[ino],
// ostatus = $('edititem' + ino).getAttribute('data-status');
// // $('product' + ino).className = 'fll';
// // $('ladd0' + ino).className = 'ladd0';
// tItem['status'] = ostatus;
// if (tItem['iid'] > 0) {
// updateItem(ino, 'status');
// }
// strO();
// showSnack('snackG', 'not canceled', 1000);
// showItems();
//}
function addOne(x) {
var n, i;
tOrder = orders[ono];
sessionStorage.setItem('addone', JSON.stringify(tOrder[x]));
n = JSON.parse(sessionStorage.getItem('addone'));
n['status'] = 0;
n['iid'] = 0;
tOrder.splice(1, 0, n);
sessionStorage.setItem('dupe', 1);
showSnack('snackG', 'added', 1000);
sessionStorage.setItem('addone', x);
strO();
showItems(0);
scrollTo(0, 0);
}
function showDetailsM(i) {
var d = $('details' + i);
if (d.className == 'ldetails0') {
$('details' + i).className = 'ldetails1';
$('blurb' + i).className = 'blurb';
$('plate' + i).className = 'plating';
$('noteE' + i).className = 'disN';
$('opsE' + i).className = 'disN';
} else {
$('details' + i).className = 'ldetails0';
$('blurb' + i).className = 'disN';
$('plate' + i).className = 'disN';
$('opsE' + i).removeAttribute('class');
$('noteE' + i).className = 'aC';
}
}
function showDetailsC(i) {
var d = $('details' + i).className;
document.querySelectorAll('.blurb').forEach(function (item) {
item.className = 'disN';
});
document.querySelectorAll('.plate').forEach(function (item) {
item.className = 'disN';
});
document.querySelectorAll('.ldetails1').forEach(function (item) {
item.className = 'ldetails0';
});
if (d == 'ldetails0') {
$('details' + i).className = 'ldetails1';
$('blurb' + i).className = 'blurb';
$('plate' + i).className = 'plating';
} else {
$('details' + i).className = 'ldetails0';
}
}
// document.querySelectorAll('.ldetails1').forEach(function (item) {
// item.className = 'ldetails0';
// });
function showDetailsO(i) {
var d = $('details' + i),
opsE = $('opsE' + i),
eTD = opsE.getElementsByTagName("td")[0];
if (d.className == 'ldetails0') {
$('details' + i).className = 'ldetails1';
$('blurb' + i).className = 'blurb';
$('plate' + i).className = 'plating';
$('noteE' + i).className = 'disN';
opsE.className = 'disN';
} else {
$('details' + i).className = 'ldetails0';
$('blurb' + i).className = 'disN';
$('plate' + i).className = 'disN';
$('noteE' + i).className = 'sC';
eTD.innerHTML == '' ? '' : opsE.removeAttribute('class');
// $('opsE' + i).className = 'opsE';
}
}
function addItem(pid, line) {
var i, y, k, oi, oid, opid, newItems, nqt, n, lqty, note, price, oprice, ops, status, opA, op0,
date = 0,
product = getProduct(pid),
item = product[1],
food = product[16],
tOrder = orders[ono],
tMeta = tOrder[0];
tMeta['status'] = 1;
// addValueM(line);
note = $('note' + line) ? $('note' + line).innerHTML : '';
price = $('line' + line).getAttribute('data-price');
oprice = $('line' + line).getAttribute('data-oprice');
lqty = $('lqty' + line).innerHTML;
ops = $('line' + line).getAttribute('data-ops');
if (ops != '') {
ops = ops.split(',');
} else {
opA = $('opsE' + line).getElementsByClassName('ops');
if (opA.length > 0) {
op0 = opA[0].id;
ops = [Number(op0.substr(3))];
// ops = $('edititem' + line).getAttribute('data-0');
// console.log(ops);
// console.log(ops[0]);
// console.log(op0);
// console.log(op00);
// alert("ops!");
}
}
lqty = isNaN(lqty) ? 1 : Number(lqty) + 1;
$('lqty' + line).innerHTML = lqty;
n = {
iid: 0,
pid: pid,
oid: tMeta['oid'],
status: staff,
wstat: 0,
date: 0,
item: item,
qty: 1,
price: price,
oprice: oprice,
ops: ops,
note: note.trim(),
food: food,
update: [],
deleted: 0
};
tOrder.splice(1, 0, n);
showSnack('snackG', 'added', 1000);
strO();
}
function closeSnack() {
$('snackbar').className = 'disN';
}
function showSnack(style, snack, time) {
var x = $('snackbar');
clearTimeout(snacktime);
x.className = style;
x.innerHTML = snack;
if (time > 0) {
snacktime = setTimeout(function () {
x.className = 'disN';
}, time);
}
}
//function showSnack(id, snack, time) {
// time = time || 1000;
// var x = document.getElementById(id);
// x.className = "show";
// x.innerHTML = snack;
// clearTimeout(snacktime);
// snacktime = setTimeout(function () {
// x.className = x.className.replace("show", "");
// }, time);
//}
function hrM(z) {
var d = new Date(z);
var h2 = d.getHours();
if (h2 < 10) h2 = '0' + h2;
var m2 = d.getMinutes();
if (m2 < 10) m2 = '0' + m2;
var hr = h2 + ':' + m2;
return hr;
}
function dM(z) {
var d = new Date(z);
var dy = d.getDate();
if (dy < 10) dy = '0' + dy;
var mo;
if (ln == '1') mo = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
else mo = ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'];
var day = dy + ' ' + mo[d.getMonth()];
return day;
}
function dMY(z) {
var d = new Date(z);
var dy = d.getDate();
if (dy < 10) dy = '0' + dy;
var mo;
if (ln == '1') mo = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
else mo = ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'];
var day = dy + ' ' + mo[d.getMonth()] + ', ' + d.getFullYear();
return day;
}
function dHM(x) {
// var y = (x) ? x.substr(x.indexOf(' '), 6) : 0,
// z = y.replace(':', '-');
return (x) ? x.substr(x.indexOf(' '), 6) : 0; // minutes
// return z;
}
function dateMin(z) {
var today = new Date(),
order_date = new Date(z),
Ms = (today.getTime() - order_date.getTime()),
Mns = Math.round(Ms / (1000 * 60));
// Mns = Mns < 1 ? '' : Mns;
return Mns; // minutes
}
function safeText(val) {
val = val.replace(/>/gi, ">");
val = val.replace(/"/gi, """);
val = val.replace(/'/gi, "'");
val = val.replace(/
';
//}
function svgNE() {
return '