TK.registerNS("TK.club");
TK.club = new function(){
var rid = "";
var DEFAULTPXPERFOOT = 16;
var PXPERFOOT = DEFAULTPXPERFOOT;
var SCALE = 1;
var room = null;
var curtable = null;
var curinv = null;
var curiteminv = null;
var categories = null;
var subcategories = new Array();
var inventory = new Array();
var selectedSubCat = null;
var selectedCat = null;
var emps = null;
var timer = null;
this.custid = null;
var visible = false;
var visiblewait = false;
var waitCustId = null;
var curwait = null;
var notes = [];
this.init = function(arg){
rid = arg;
$("#gs-room-additemtotable-guest").buttonset();
$("#gs-room-additemtotable-qty").buttonset();
$("#gs-room-additemtotable-status").buttonset();
$("#gs-wait-numofguests").buttonset();
$("#gs-room-dlgTable").dialog({ autoOpen: false, modal:true,resizable:false, width: 800});
$("#gs-room-name-ac").autocomplete({
source:TK.club.queryCustomer,
minLength: 1,
focus: function( event, ui ) {return false;},
search: function( event, ui ) {
custid = null;
},
select: function( event, ui ) {
$("#gs-room-name-ac" ).val( ui.item.labelraw );
custid = ui.item.value;
return false;
},
position: { my: "left bottom", at: "left top", collision: "flip" }
})
.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
return $( "
" )
.append( "" + item.label +" |
" + item.desc + " |
" )
.appendTo( ul );
};
TKClub.getRoom(rid, TK.club.getRoomInitReturn);
TKClub.getQuickNotes(TK.club.getNotesReturn);
$("#gs-room-scale").html(SCALE.toFixed(1));
$("#gs-room-dlgTable").dialog().bind( "dialogopen", function(event, ui) {
var adjw = $(window).width() * .1;
var adjh = $(window).height() * .025;
var width = $(window).width() - adjw;
var height = $(window).height() - adjh;
$('#gs-room-dlgTable').parent().css({
'width': width,
'height': height,
'left': adjw/2,
'top': $(window).scrollTop()
});
$('#gs-room-bottomdiv').css({
'height': height - 200,
});
});
$(window).resize(function () {
var adjw = $(window).width() * .1;
var adjh = $(window).height() * .025;
var width = $(window).width() - adjw;
var height = $(window).height() - adjh;
$('#gs-room-dlgTable').parent().css({
'width': width,
'height': height,
'left': adjw/2,
'top': $(window).scrollTop()
});
$('#gs-room-bottomdiv').css({
'height': height - 200,
});
}).resize();
$("#gs-wait-txtName").autocomplete({
source:TK.club.queryCustomer,
minLength: 1,
focus: function( event, ui ) {return false;},
search: function( event, ui ) {
waitCustId = null;
},
select: function( event, ui ) {
$("#gs-wait-txtName" ).val("");
waitCustId = ui.item.value;
$("#gs-wait-custac-name1").html(ui.item.labelraw);
$("#gs-wait-txtName").hide();
$("#gs-wait-custDiv").show();
return false;
},
position: { my: "left bottom", at: "left top", collision: "flip" }
})
.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
return $( "" )
.append( "" + item.label +" |
" + item.desc + " |
" )
.appendTo( ul );
};
$("#gs-wait-txtName").keydown(function(event){
if(event.keyCode == 13) {
event.preventDefault();
$("#gs-wait-txtPhone").focus();
return false;
}
});
};
this.getNotesReturn = function(data){
notes = data;
};
this.queryCustomer = function(request, response){
var callMetaData = {
callback: TK.club.queryCustomerReturn,
callbackArg: response
};
TKClub.getACQueryForCustomer(request.term, 10, callMetaData);
};
this.queryCustomerReturn = function(data, response){
response(data);
};
this.reduceScale = function(){
if(SCALE > .4){
$("#gs-room-canvas").hide();
$("#gs-room-loading").show();
SCALE -= .2;
$("#gs-room-scale").html(SCALE.toFixed(1));
TK.club.loadTable();
$("#gs-room-loading").hide();
$("#gs-room-canvas").show();
}
};
this.addScale = function(){
$("#gs-room-canvas").hide();
$("#gs-room-loading").show();
SCALE += .2;
$("#gs-room-scale").html(SCALE.toFixed(1));
TK.club.loadTable();
$("#gs-room-loading").hide();
$("#gs-room-canvas").show();
};
this.fitToScreen = function(){
$("#gs-room-canvas").hide();
$("#gs-room-loading").show();
var width = $(window).width() - 50;
var height = $(window).height() - 50;
var scale = width/height;
if((room.width/room.height) < scale){
height = (height/room.height)/DEFAULTPXPERFOOT;
SCALE = height;
}
else{
width = (width/room.width)/DEFAULTPXPERFOOT;
SCALE = width;
}
$("#gs-room-scale").html(SCALE.toFixed(1));
TK.club.loadTable();
$("#gs-room-loading").hide();
$("#gs-room-canvas").show();
$('html, body').animate({scrollTop: $("#gs-room-canvas").offset().top}, 1000);
};
this.defaultScale = function(){
$("#gs-room-canvas").hide();
$("#gs-room-loading").show();
SCALE = 1;
$("#gs-room-scale").html(SCALE.toFixed(1));
TK.club.loadTable();
$("#gs-room-loading").hide();
$("#gs-room-canvas").show();
};
this.getRoomInitReturn = function(data){
$("#gs-room-loading").hide();
$("#gs-room-canvas").show();
if(data != null){
room = data;
$("#gs-room-name").html(room.name);
TK.club.loadTable();
}
timer = setTimeout("TK.club.getRoom();", 10000);
};
this.getRoom = function(){
TKClub.getRoom(rid, TK.club.getRoomReturn);
};
this.getRoomReturn = function(data){
if(data != null){
room = data;
if(curtable != null){
for(var i = 0; i < room.tables.length; ++i){
var table = room.tables[i];
if(table.encryptedId == curtable.encryptedId){
curtable = table;
break;
}
}
}
TK.club.loadTable();
if($("#gs-room-gotoseat1").is(":visible")) TK.club.showSeating();
}
timer = setTimeout("TK.club.getRoom();", 10000);
};
this.loadTable = function(){
//Add items to canvas
var width = room.width * PXPERFOOT * SCALE;
var height = room.height * PXPERFOOT * SCALE;
var fontsize = Math.round(((PXPERFOOT * SCALE) * 2)/3);
width = Math.round(width);
height = Math.round(height);
var msg = "";
msg += "
";
$("#gs-room-canvas").html(msg);
var foodmsg = "";
var tablewaitmsg = "";
tablewaitmsg += "Table | | Status |
";
for(var i = 0; i < room.tables.length; ++i){
var table = room.tables[i];
var itemmsg = "";
var style = "";
if(table.tableTypeCode == 2){
style = " round";
}
tablewaitmsg += "" + table.name + " | " + table.seats + " | ";
if(table.tableStatusTypeCode == 2){
style += " gs-room-item-seated";
tablewaitmsg += "SEATED";
}
else if(table.tableStatusTypeCode == 3){
style += " gs-room-item-clean";
tablewaitmsg += "CLEANING";
}
else if(table.tableStatusTypeCode == 4){
style += " gs-room-item-reserved";
tablewaitmsg += "RESERVED";
}
else{
tablewaitmsg += "READY";
}
tablewaitmsg += " |
";
itemmsg = "";
itemmsg += table.name + "[" + table.seats + "]
";
itemmsg += table.tableStatusTypeName + "
";
if(TK.actions.isNotBlank(table.encryptedClubUserId)){
itemmsg += "" + table.clubUserName + "";
}
itemmsg += "
";
$("#gs-room-floor").append(itemmsg);
$( "#gs-item-" + table.encryptedId ).css({width: table.width * PXPERFOOT * SCALE, height: table.height * PXPERFOOT * SCALE, 'top': table.y * PXPERFOOT * SCALE, 'left' : table.x * PXPERFOOT * SCALE});
//LOAD FOOD TABLE
if(table.item != null){
for(var j = 0;j < table.item.inv.length; ++j){
var inv = table.item.inv[j];
if(inv.statusCode == 2){
foodmsg += "" + table.name + ": " + inv.invDTO.nameDisplay + "
";
}
}
}
}
tablewaitmsg += "
";
if(TK.actions.isBlank(foodmsg)){
foodmsg += "There is no order to be served
";
$("#gs-food-icon").hide();
}
else{
$("#gs-food-icon").show();
}
$("#gs-food-msg").html(foodmsg);
$("#gs-wait-tables").html(tablewaitmsg);
TK.club.loadWait();
};
this.loadWait = function(){
if(room.waits.length > 0){
room.waits.sort(TK.club.waitSort);
var msg = "";
msg += "Time | Name | Phone | #Guests | Res | |
";
for(var i = 0; i < room.waits.length; ++i){
var wait = room.waits[i];
msg += "";
var date = new Date(wait.timeInEpoch);
msg += "";
msg += date.format("shortTime");
msg += " | ";
msg += "";
msg += wait.name;
msg += " | ";
msg += "";
msg += wait.phone;
msg += " | ";
msg += "";
msg += wait.numberInParty;
msg += " | ";
msg += "";
if(wait.reservationFlag){
msg += "";
}
msg += " | ";
msg += "
";
}
msg += "
";
$("#gs-wait-waiting").html(msg);
$("#gs-wait-icon").show();
}
else{
var msg ="No parties waiting.
";
$("#gs-wait-waiting").html(msg);
$("#gs-wait-icon").hide();
}
};
this.openTable = function(itemId){
curtable = null;
for(var i = 0; i < room.tables.length; ++i){
if(room.tables[i].encryptedId == itemId){
curtable = room.tables[i];
break;
}
}
if(curtable != null){
TK.club.renderDialog();
}
else{
TK.actions.alert("Could not find table.");
location.reload();
}
};
this.renderDialog = function(){
$("[name='gs-room-status']").hide();
if(curtable.tableStatusTypeCode == 1){
$("#gs-room-statusReady").show();
TK.club.loadEmps();
}
else if(curtable.tableStatusTypeCode == 2){
$("#gs-room-statusSeated").show();
$("#gs-room-gotoseat").show();
TK.club.showSeating();
}
else if(curtable.tableStatusTypeCode == 3){
$("#gs-room-statusClean").show();
}
else{
$("#gs-room-statusReserve").show();
}
if(TK.actions.isBlank(curtable.encryptedClubUserId)){
$("#gs-room-dlgTable").dialog("option", "title", "Table " + curtable.name + " Server: None");
}
else{
$("#gs-room-dlgTable").dialog("option", "title", "Table " + curtable.name + " Server: " + curtable.clubUserName);
}
$("#gs-room-dlgTable").dialog("open");
};
this.loadEmps = function(){
if(emps != null){
TK.club.renderEmps();
}
else{
if(TK.actions.getLock()){
TKClub.getClubUsers(TK.club.loadEmpsReturn);
}
}
};
this.loadEmpsReturn = function(data){
TK.actions.releaseLock();
emps = data;
TK.club.renderEmps();
};
this.renderEmps = function(){
$("#gs-room-gotoready").html("");
var msg = "";
if(emps == null || emps.length == 0){
msg += "You have no employees ready for dining. Click
HERE to add some.
";
}
else{
if(TK.actions.isNotBlank(curtable.encryptedClubUserId)){
msg += "";
msg += "Remove " + curtable.clubUserName + " From Table";
msg += "
";
}
for(var i = 0; i < emps.length; ++i){
var emp = emps[i];
var style = "gs-pos-itemdiv";
if(curtable.encryptedClubUserId == emp.encryptedId) style="gs-pos-catdiv";
msg += "";
msg += emp.alias;
msg += "
";
}
msg += "";
}
$("#gs-room-gotoready").html(msg);
$("#gs-room-gotoready").show();
};
this.addServerToTable = function(uid){
if(TK.actions.getLock()){
TKClub.addServerToTable(curtable.encryptedId, uid, TK.club.addServerToTableReturn);
}
};
this.addServerToTableReturn = function(data){
TK.club.changeStatusReturn(data);
};
this.removeServerFromTable = function(){
if(TK.actions.getLock()){
TKClub.removeServerFromTable(curtable.encryptedId, TK.club.removeServerFromTableReturn);
}
};
this.removeServerFromTableReturn = function(data){
TK.club.changeStatusReturn(data);
};
this.editItemReturn = function(data){
TK.actions.releaseLock();
$("#gs-room-dlgAdd").dialog("close");
if(data != null){
if(data.error == TK.constants.SUCCESS){
for(var i = 0; i < room.tables.length; ++i){
if(room.tables[i].encryptedId == data.encryptedId){
room.tables[i] = data;
break;
}
}
curtable = data;
TK.club.loadTable();
}
else{
location.reload();
}
}
};
this.changeStatus = function(code){
if(curtable != null){
if(code == 3 || code == 1){
var confirm = false;
if(curtable.item != null){
for(var i = 0; i < curtable.item.inv.length; ++i){
var inv = curtable.item.inv[i];
if(TK.actions.isNotBlank(inv.encryptedInvoiceId)){
if(!inv.invoiceFinished){
confirm = true;
break;
}
}
else{
confirm = true;
break;
}
}
}
if(confirm){
TK.actions.showConfirm("Unfinished Invoices", "There are order items not paid for, continue?", function(){TKClub.changeRoomTableStatus(curtable.encryptedId, code, TK.club.changeStatusReturn);}, "Yes", "No");
}
else{
if(TK.actions.getLock()){
TKClub.changeRoomTableStatus(curtable.encryptedId, code, TK.club.changeStatusReturn);
}
}
}
else{
if(TK.actions.getLock()){
TKClub.changeRoomTableStatus(curtable.encryptedId, code, TK.club.changeStatusReturn);
}
}
}
};
this.changeStatusReturn = function(data){
TK.actions.releaseLock();
if(data != null){
if(data.error == TK.constants.SUCCESS){
for(var i = 0; i < room.tables.length; ++i){
if(room.tables[i].encryptedId == data.encryptedId){
room.tables[i] = data;
break;
}
}
TK.club.loadTable();
curtable = data;
TK.club.renderDialog();
}
else{
location.reload();
}
}
};
this.sortRoomItemInv = function(var1, var2){
if(var1.guest < var2.guest) return -1;
if(var1.guest > var2.guest) return 1;
return 0;
};
this.showAddToOrder = function(){
curiteminv = null;
$("#gs-room-gotoseat3").hide();
$("#gs-room-gotoseat1").hide();
$("#gs-room-gotoseat2").show();
TK.club.loadCats();
};
this.showSeating = function(){
$("#gs-room-gotoseat3").hide();
$("#gs-room-gotoseat2").hide();
$("#gs-room-gotoseat1").show();
$("#gs-room-tableorder").html("");
//RENDER THE ORDERS
if(curtable.item != null && curtable.item.inv != null){
curtable.item.inv.sort(TK.club.sortRoomItemInv);
var msg = "";
msg += " | Guest | Status | table | Qty | Invoice | Cost Each |
";
for(var i = 0; i < curtable.item.inv.length; ++i){
var inv = curtable.item.inv[i];
msg += "";
msg += " | ";
msg += "" + inv.guest + " | ";
msg += "" + inv.statusName + " | ";
msg += "" + inv.invDTO.nameDisplay;
if(TK.actions.isNotBlank(inv.notes)){
msg += " " + inv.notesDisplay + "";
}
msg += " | ";
msg += "" + inv.quantity + " | ";
msg += "";
if(TK.actions.isNotBlank(inv.encryptedInvoiceId)){
msg += "";
msg += " ";
var style = "redText";
if(inv.invoiceFinished) style = "greenText";
msg += "" + inv.encryptedInvoiceId + " ";
msg += " ";
msg += "";
msg += " ";
}
msg += " | ";
msg += "" + TK.constants.CURRENCY + inv.invDTO.salePrice.toFixed(2) + " | ";
msg += "
";
}
msg += "
";
$("#gs-room-tableorder").html(msg);
}
};
this.showAddInventory = function(){
$("#gs-room-gotoseat1").hide();
$("#gs-room-gotoseat2").hide();
$("#gs-room-gotoseat3").show();
if(curiteminv == null){
$("#gs-room-additemtotable-buttons2").hide();
$("#gs-room-additemtotable-buttons1").show();
}
else{
$("#gs-room-additemtotable-buttons1").hide();
$("#gs-room-additemtotable-buttons2").show();
}
};
this.loadCats = function(){
if(categories != null){
TK.club.renderCats();
}
else{
if(TK.actions.getLock()){
TKClub.getClubCategoriesForFB(TK.club.loadCatsReturn);
}
}
};
this.loadCatsReturn = function(data){
TK.actions.releaseLock();
categories = data;
TK.club.renderCats();
};
this.renderCats = function(){
selectedCat = null;
$("#gs-room-gotoseat2").html("");
var msg = "";
if(categories == null || categories.length == 0){
msg += "You have no inventory categories
";
msg += "";
msg += "«Return To Seating";
msg += "
";
msg += "";
}
else{
msg += "";
msg += "«Return To Seating";
msg += "
";
for(var i = 0; i < categories.length; ++i){
var cat = categories[i];
msg += "";
msg += cat;
msg += "
";
}
msg += "";
}
$("#gs-room-gotoseat2").html(msg);
};
this.loadSubCats = function(cat){
selectedCat = cat;
if(subcategories[cat] == null){
if(TK.actions.getLock()){
TKClub.getClubSubCategoriesForFB(cat, TK.club.loadSubCatsReturn);
}
}
else{
TK.club.renderSubCats(cat);
}
};
this.loadSubCatsReturn = function(data){
TK.actions.releaseLock();
subcategories[selectedCat] = data;
TK.club.renderSubCats();
};
this.renderSubCats = function(){
selectedSubCat = null;
$("#gs-room-gotoseat2").html("");
var sub = subcategories[selectedCat];
var msg = "";
if((sub.subcats == null || sub.subcats.length == 0) && (sub.items == null || sub.items.length == 0)){
msg += "You have no inventory categories Go Back
";
}
else{
msg += "";
msg += "«GO BACK"
msg += "
";
for(var i = 0; i < sub.subcats.length; ++i){
var subcat = sub.subcats[i];
msg += "";
msg += subcat;
msg += "
";
}
for(var i = 0; i < sub.items.length; ++i){
var inv = sub.items[i];
msg += "";
msg += inv.name + "" + TK.constants.CURRENCY + inv.salePrice.toFixed(2);
msg += "
";
}
msg += "";
}
$("#gs-room-gotoseat2").html(msg);
};
this.loadSubCatInv = function(subcat){
selectedSubCat = subcat;
var invs = inventory[selectedSubCat + "-" + selectedCat];
if(invs == null || invs.length == 0){
if(TK.actions.getLock()){
TKClub.getClubSubcategoryInventoryForFB(selectedCat, selectedSubCat, TK.club.loadSubCatInvReturn);
}
}
else{
TK.club.renderSubCatInv();
}
};
this.loadSubCatInvReturn = function(data){
TK.actions.releaseLock();
inventory[selectedSubCat + "-" + selectedCat] = data;
TK.club.renderSubCatInv();
};
this.renderSubCatInv = function(){
$("#gs-room-gotoseat2").html("");
var invs = inventory[selectedSubCat + "-" + selectedCat];
var msg = "";
if(invs == null || invs.length == 0){
msg += "You have no inventory categories Go Back
";
}
else{
msg += "";
msg += "«GO BACK"
msg += "
";
for(var i = 0; i < invs.length; ++i){
var inv = invs[i];
msg += "";
msg += inv.name + "" + TK.constants.CURRENCY + inv.salePrice.toFixed(2);
msg += "
";
}
msg += "";
}
$("#gs-room-gotoseat2").html(msg);
};
this.addItemToTable = function(invId){
curinvitem = null;
TK.club.showAddInventory();
if(selectedSubCat != null){
invlist = inventory[selectedSubCat + "-" + selectedCat];
}
else{
invlist = subcategories[selectedCat].items
}
for(var i = 0; i < invlist.length; ++i){
if(invlist[i].encryptedId == invId){
curinv = invlist[i];
break;
}
}
$('#gs-room-additemtotable-guest-1').prop('checked', true).buttonset('refresh');
$('#gs-room-additemtotable-qty-1').prop('checked', true).buttonset('refresh');
$('#gs-room-additemtotable-status-1').prop('checked', true).buttonset('refresh');
$("#gs-room-additemtotable-notes").val("");
var msg = curinv.nameDisplay + " " + TK.constants.CURRENCY + curinv.cost.toFixed(2);
TK.club.loadQuickNotes(selectedCat, selectedSubCat);
$("#gs-room-additemtotable-div").html(msg);
//alert(JSON.stringify(curinv, null, 4));
//if(TK.actions.getLock()) TKClub.addItemToTable(curtable.encryptedId, invId, TK.club.addItemToTableReturn);
};
this.loadQuickNotes = function(cat, subcat){
var list = [];
for(var i = 0; i < notes.length; ++i){
var note = notes[i];
if(note.category == ""){
list[list.length] = note;
}
else if (cat != null && cat == note.category){
if(note.subcategory == "" || subcat == null || subcat == "") list[list.length] = note;
else if(subcat == note.subcategory) list[list.length] = note;
}
}
if(list.length > 0){
var msg = "";
for(var i = 0; i < list.length; ++i){
msg += "" + list[i].notesText + "
"
}
$("#gs-room-additemtotable-quicknotes").html(msg);
}
else{
$("#gs-room-additemtotable-quicknotes").html("No Quick Notes
");
}
//return list;
}
this.addQuickNote = function(id){
for(var i = 0; i < notes.length; ++i){
if(notes[i].encryptedId == id){
$('#gs-room-additemtotable-notes').val($('#gs-room-additemtotable-notes').val() + notes[i].notesText + "\n");
}
}
};
this.addItemToTableSubmit = function(){
var guest = $('input[name=gs-room-additemtotable-guest]:checked').val();
var qty = $('input[name=gs-room-additemtotable-qty]:checked').val();
var status = $('input[name=gs-room-additemtotable-status]:checked').val();
var notes = $("#gs-room-additemtotable-notes").val();
if(TK.actions.getLock()){
TKClub.createRoomItemInventory(curtable.encryptedId , curinv.encryptedId, guest, qty, notes, status, TK.club.addItemToTableReturn);
}
};
this.addItemToTableReturn = function(data){
TK.actions.releaseLock();
if(data != null){
if(data.error == TK.constants.SUCCESS){
for(var i = 0; i < room.tables.length; ++i){
if(room.tables[i].encryptedId == data.encryptedId){
room.tables[i] = data;
break;
}
}
curtable = data;
TK.club.showSeating();
TK.club.loadTable();
}
else{
TK.actions.alert(data.misc);
}
}
else{
location.reload();
}
};
this.removeItemFromTable = function(invId){
if(TK.actions.getLock()){
TKClub.deleteRoomItemInventory(invId, TK.club.removeItemFromTableReturn);
}
};
this.removeItemFromTableReturn = function(data){
TK.actions.releaseLock();
if(data != null){
if(data.error == TK.constants.SUCCESS){
for(var i = 0; i < curtable.item.inv.length; ++i){
var item = curtable.item.inv[i];
if(item.encryptedId == data.encryptedId){
curtable.item.inv.splice(i, 1);
break;
}
}
TK.club.showSeating();
TK.club.loadTable();
}
else{
location.reload();
}
}
};
this.editItemFromTable = function(invId){
for(var i = 0; i < curtable.item.inv.length; ++i){
var item = curtable.item.inv[i];
if(item.encryptedId == invId){
curiteminv = item;
break;
}
}
$('input[name=gs-room-additemtotable-guest]').val([curiteminv.guest]);
$('input[name=gs-room-additemtotable-qty]').val([curiteminv.quantity]);
$('input[name=gs-room-additemtotable-status]').val([curiteminv.statusCode]);
$("#gs-room-additemtotable-guest").buttonset("refresh");
$("#gs-room-additemtotable-qty").buttonset("refresh");
$("#gs-room-additemtotable-status").buttonset("refresh");
$("#gs-room-additemtotable-notes").val(curiteminv.notes);
var msg = curiteminv.invDTO.nameDisplay + " " + TK.constants.CURRENCY + curiteminv.invDTO.cost.toFixed(2);
$("#gs-room-additemtotable-div").html(msg);
TK.club.loadQuickNotes(curiteminv.category, curiteminv.subcategory);
TK.club.showAddInventory();
};
this.editItemFromTableSubmit = function(){
var guest = $('input[name=gs-room-additemtotable-guest]:checked').val();
var qty = $('input[name=gs-room-additemtotable-qty]:checked').val();
var status = $('input[name=gs-room-additemtotable-status]:checked').val();
var notes = $("#gs-room-additemtotable-notes").val();
if(TK.actions.getLock()){
TKClub.updateRoomItemInventory(curiteminv.encryptedId, guest, qty, notes, status, TK.club.editItemFromTableReturn);
}
};
this.editItemFromTableReturn = function(data){
TK.actions.releaseLock();
if(data != null){
if(data.error == TK.constants.SUCCESS){
for(var i = 0; i < curtable.item.inv.length; ++i){
var item = curtable.item.inv[i];
if(curtable.item.inv[i].encryptedId == data.encryptedId){
curtable.item.inv[i] = data;
break;
}
}
TK.club.loadTable();
TK.club.showSeating();
}
else{
TK.actions.alert(data.misc);
}
}
else{
location.reload();
}
};
this.serveTable = function(){
if(curtable != null){
if(TK.actions.getLock()) TKClub.serveTable(curtable.encryptedId, TK.club.createInvoiceForTableReturn);
}
}
this.createInvoiceForTable = function(){
if(curtable.item != null){
if(TK.actions.getLock()) TKClub.createInvoiceForRoomItem(curtable.item.encryptedId, TK.club.createInvoiceForTableReturn);
}
};
this.createInvoiceForTableReturn = function(data){
TK.actions.releaseLock();
if(data != null){
if(data.error == TK.constants.SUCCESS){
for(var i = 0; i < room.tables.length; ++i){
if(room.tables[i].encryptedId == data.encryptedId){
room.tables[i] = data;
break;
}
}
curtable = data;
TK.club.showSeating();
TK.club.loadTable();
}
else{
TK.actions.alert(data.misc);
}
}
else{
location.reload();
}
};
this.removeInvoiceFromItemInv = function(rinvId){
if(TK.actions.getLock()) TKClub.removeInvoiceFromRoomItemInventory(rinvId, TK.club.removeInvoiceFromItemInvReturn);
};
this.removeInvoiceFromItemInvReturn = function(data){
TK.club.editItemFromTableReturn(data);
};
this.createInvoiceForTablePerGuest = function(){
if(curtable.item != null){
if(TK.actions.getLock()) TKClub.createInvoiceForRoomItemPerGuest(curtable.item.encryptedId, TK.club.createInvoiceForTablePerGuestReturn);
}
};
this.createInvoiceForTablePerGuestReturn = function(data){
TK.club.createInvoiceForTableReturn(data);
};
this.clearTable = function(){
var clear = true;
for(var i = 0; i < curtable.item.inv.length; ++i){
var inv = curtable.item.inv[i];
if(TK.actions.isNotBlank(inv.encryptedInvoiceId)){
if(!inv.invoiceFinished){
clear = false;
break;
}
}
else{
clear = false;
break;
}
}
if(!clear){
TK.actions.alert("You cannot clear the table with order items unpaid for. Please finish invoicing the table.");
}
else{
if(TK.actions.getLock()) TKClub.clearTable(curtable.encryptedId, TK.club.clearTableReturn);
}
};
this.clearTableReturn = function(data){
TK.club.changeStatusReturn(data);
TK.actions.alert("Table has been cleared, proceed to Cleaning.");
};
this.openPOS = function(invoiceId){
TK.clubCheckOut.setCloseCallBack(TK.club.closePOS);
TK.clubCheckOut.showInvoiceDetailView(invoiceId);
};
this.closePOS = function(){
TK.clubCheckOut.setCloseCallBack(null);
if(TK.actions.getLock()) TKClub.getRoomTable(curtable.encryptedId, TK.club.createInvoiceForTableReturn);
};
this.toggleFood = function(){
if(visible){
$('#gs-food').transition({right: '-406px' });
}
else{
$('#gs-food').transition({right: '0px' });
}
visible = !visible;
};
this.toggleWait = function(){
if(visiblewait){
$('#gs-wait').transition({left: '-806px' });
}
else{
$('#gs-wait').transition({left: '0px' });
$("#gs-wait-waiting2").hide();
$("#gs-wait-waiting3").hide();
$("#gs-wait-waiting4").hide();
$("#gs-wait-waiting1").show();
}
visiblewait = !visiblewait;
};
this.getRoomWaitObj = function(){
var item = new Object();
item.encryptedRoomId = "";
item.encryptedClubId = "";
item.encryptedCustomerId = "";
item.name = "";
item.phone = "";
item.timeInEpoch = 0;
item.numberInParty = 0;
item.reservationFlag = false;
return item;
};
this.addPartyToWaitlist = function(){
curwait = null;
TK.club.clearWaitCustomer();
$("#gs-wait-txtName").val("");
$("#gs-wait-txtPhone").val("");
$('#gs-wait-numofguests-1').prop('checked', true).buttonset('refresh');
$("#gs-wait-waiting1").hide();
$("#gs-wait-waiting3").hide();
$("#gs-wait-waiting4").hide();
$("#gs-wait-waiting2").show();
$("#gs-wait-txtName").focus();
};
this.backToWaitlist = function(){
$("#gs-wait-waiting2").hide();
$("#gs-wait-waiting3").hide();
$("#gs-wait-waiting4").hide();
$("#gs-wait-waiting1").show();
};
this.modifyWait = function(wid){
curwait = null;
for(var i = 0; i < room.waits.length; ++i){
if(wid == room.waits[i].encryptedId){
curwait = room.waits[i];
break;
}
}
if(curwait != null){
var date = new Date(curwait.timeInEpoch);
var msg = "";
msg += "Party: " + curwait.name + "
";
msg += "Phone: " + curwait.phone + "
";
msg += "# Guests: " + curwait.numberInParty + "
";
msg += "Time In: " + date.format("shortTime") + "
";
msg += "
";
$("#gs-wait-modifyWait").html(msg);
$("#gs-wait-waiting1").hide();
$("#gs-wait-waiting2").hide();
$("#gs-wait-waiting3").show();
}
};
this.waitSort = function (var1, var2){
if(var1.timeInEpoch < var2.timeInEpoch) return -1;
if(var1.timeInEpoch > var2.timeInEpoch) return 1;
return 0;
};
this.addToWaitlist = function(){
if(TK.actions.getLock()){
var name = $("#gs-wait-txtName").val();
var phone = $("#gs-wait-txtPhone").val();
var num = $('input[name=gs-wait-numofguests]:checked').val();
var wait = TK.club.getRoomWaitObj();
wait.name = name;
wait.phone = phone;
wait.numberInParty = num;
if(waitCustId != null){
wait.encryptedCustomerId = waitCustId;
}
else{
wait.encryptedCustomerId = null;
}
if(curwait == null){
TKClub.createRoomWait(wait, room.encryptedId, TK.club.addToWaitReturn);
}
else{
wait.encryptedId = curwait.encryptedId;
TKClub.updateRoomWait(wait, TK.club.updateRoomWaitReturn);
}
}
};
this.addToWaitReturn = function(data){
TK.actions.releaseLock();
if(data != null){
if(data.error == TK.constants.SUCCESS){
room.waits[room.waits.length] = data;
TK.club.loadWait();
TK.club.backToWaitlist();
}
else{
TK.actions.alert(data.misc);
}
}
else{
location.reload();
}
};
this.updateRoomWaitReturn = function(data){
TK.actions.releaseLock();
if(data != null){
if(data.error == TK.constants.SUCCESS){
for(var i = 0;i < room.waits.length; ++i){
if(room.waits[i].encryptedId == data.encryptedId){
room.waits[i] = data;
curwait = data;
break;
}
}
TK.club.loadWait();
TK.club.backToWaitlist();
}
else{
TK.actions.alert(data.misc);
}
}
else{
location.reload();
}
};
this.clearWaitCustomer = function(){
waitCustId = null;
$("#gs-wait-txtName").show();
$("#gs-wait-custDiv").hide();
$("#gs-wait-custac-name1").html("");
$("#gs-wait-txtName").focus();
};
this.waitSeat = function(){
$("#gs-wait-waitTable").html("");
$("#gs-wait-waiting1").hide();
$("#gs-wait-waiting2").hide();
$("#gs-wait-waiting3").hide();
$("#gs-wait-waiting4").show();
var msg = "";
for(var i = 0; i < room.tables.length; ++i){
var table = room.tables[i];
if(table.tableStatusTypeCode != 2 && (table.item == null || table.item.inv.length == 0)){
msg += "";
msg += table.name + "[" + table.seats + "]
";
msg += table.tableStatusTypeName + "
";
if(TK.actions.isNotBlank(table.encryptedClubUserId)){
msg += "" + table.clubUserName + "
";
}
msg += "
";
}
}
msg += "";
$("#gs-wait-waitTable").html(msg);
};
this.waitSeatSubmit = function(itemId){
if(TK.actions.getLock()){
TKClub.waitSeat(curwait.encryptedId, itemId, TK.club.waitSeatSubmitReturn);
}
};
this.waitSeatSubmitReturn = function(data){
TK.actions.releaseLock();
if(data != null){
for(var i = 0; i < room.tables.length; ++i){
var item = room.tables[i];
if(item.encryptedId == data.encryptedId){
room.tables[i] = data;
break;
}
}
for(var i = 0;i < room.waits.length; ++i){
if(room.waits[i].encryptedId == curwait.encryptedId){
room.waits.splice(i, 1);
break;
}
}
TK.club.loadTable();
TK.club.backToWaitlist();
}
};
this.waitEdit = function(){
if(TK.actions.isNotBlank(curwait.encryptedCustomerId)){
$("#gs-wait-txtName" ).val("");
waitCustId = curwait.encryptedCustomerId;
$("#gs-wait-custac-name1").html(curwait.name);
$("#gs-wait-txtName").hide();
$("#gs-wait-custDiv").show();
}
else{
TK.club.clearWaitCustomer();
$("#gs-wait-txtName").val(curwait.name);
}
$("#gs-wait-txtPhone").val(curwait.phone);
$('input[name=gs-wait-numofguests]').val([curwait.numberInParty]);
$("#gs-wait-numofguests").buttonset("refresh");
$("#gs-wait-waiting1").hide();
$("#gs-wait-waiting3").hide();
$("#gs-wait-waiting4").hide();
$("#gs-wait-waiting2").show();
$("#gs-wait-txtName").focus();
};
this.waitDelete = function(){
TK.actions.showConfirm("Confirm", "Are you sure you want to delete?", this.deleteWait, "Yes", "No");
};
this.deleteWait = function() {
if(TK.actions.getLock()){
TKClub.deleteRoomWait(curwait, TK.club.deleteRoomWaitReturn);
}
};
this.deleteRoomWaitReturn = function(data){
TK.actions.releaseLock();
if(data != null){
if(data.error == TK.constants.SUCCESS){
for(var i = 0;i < room.waits.length; ++i){
if(room.waits[i].encryptedId == data.encryptedId){
room.waits.splice(i, 1);
break;
}
}
TK.club.loadWait();
TK.club.backToWaitlist();
}
else{
TK.actions.alert(data.misc);
}
}
else{
location.reload();
}
};
this.waitNotify = function(itemId){
if(TK.actions.getLock()){
TKClub.sendWaitNotification(curwait.encryptedId, TK.club.waitNotifyReturn);
}
};
this.waitNotifyReturn = function(data){
TK.actions.releaseLock();
if(data != null){
if(data.error == TK.constants.SUCCESS){
TK.actions.alert("Notifications sent.");
}
else{
TK.actions.alert(data.misc);
}
}
else{
location.reload();
}
};
};