ordersprinter/webapp/elements/customers.js

1 line
24 KiB
JavaScript

var allgroups=[];var customers=[];var decpoint=".";var currency="";var payments=[];function getGeneralConfigItemsCus(){$("#customersearch").val("");$("#groupsearch").val("");clearNewCustomerFields();clearNewGroupFields();doAjax("GET","php/contenthandler.php?module=admin&command=getGeneralConfigItems",null,insertConfigDoRest,"Fehler Konfigurationsdaten");doAjax("GET","php/contenthandler.php?module=customers&command=getPaymentsForGuest",null,insertPayments,"Fehler Zahlungswege",true);customizeDatePicker("#newcustomercheckin",null);customizeDatePicker("#newcustomercheckout",null);customizeDatePicker("#customerdate","")}function insertConfigDoRest(b){if(b.status==="OK"){var a=b.msg;$("#customersearch").val("");setLanguage(a.userlanguage);decpoint=a.decpoint;currency=a.currency;bindGroupsOrCustomerBtns();showCustomersArea();startSearch()}else{setTimeout(function(){document.location.href="index.html"},250)}}function insertPayments(d){if(d.status=="OK"){var c=d.msg;payments=[];for(var b=0;b<c.length;b++){var a=c[b];payments[payments.length]={id:a.id,name:a.name}}setPaymentsInAllGuestActions()}}function setPaymentsInAllGuestActions(){var a="";a+="<br><b>"+CUS_DECLARE_ALL_PAY[l]+"</b>:<br>";for(var b=0;b<payments.length;b++){var c=payments[b];a+=createApplyButton("paymentallguests_"+c.id,c.name,"e","paymentpayallguests")}$("#payalldiv").html(a);$("#payalldiv").trigger("create")}function createPaymentsArea(b,e,f){var a=createCollapsibleStartGeneral("paymentsarea_"+b,f,"f","paymentsarea",true);for(var c=0;c<payments.length;c++){var d=payments[c];a+=createApplyButton("payment_"+b+"_"+d.id+"_"+e,d.name,"e","paymentpay")}a+="</div>";return a}function showCustomersArea(){$("#customersarea").show();$("#groupsarea").hide();$("#customersbtn").buttonMarkup({theme:"f"});$("#customersbtn").buttonMarkup({icon:"arrow-d"});$("#groupsbtn").buttonMarkup({theme:"c"});$("#groupsbtn").buttonMarkup({icon:"arrow-r"})}function showGroupsArea(){$("#customersarea").hide();$("#groupsarea").show();$("#customersbtn").buttonMarkup({theme:"c"});$("#customersbtn").buttonMarkup({icon:"arrow-r"});$("#groupsbtn").buttonMarkup({theme:"f"});$("#groupsbtn").buttonMarkup({icon:"arrow-d"})}function bindGroupsOrCustomerBtns(){$("#customersbtn").off("click").on("click",function(a){a.stopImmediatePropagation();a.preventDefault();showCustomersArea()});$("#groupsbtn").off("click").on("click",function(a){a.stopImmediatePropagation();a.preventDefault();showGroupsArea()});$("#newcustomerbtn").off("click").on("click",function(i){i.stopImmediatePropagation();i.preventDefault();var b=$("#newcustomername").val().trim();var m=$("#newcustomeremail").val().trim();var o=$("#newcustomeraddress").val().trim();var g=$("#newcustomerremark").val().trim();var j=$("#newcustomerphone").val().trim();var k=$("#newcustomermobil").val().trim();var c=$("#newcustomerwww").val().trim();var n=$("#newcustomerhello").val().trim();var h=$("#newcustomerregards").val().trim();var a=$("#newcustomerroom").val().trim();if(b===""){alert(CUS_EMPTY_NAME[l])}else{var f=getCheckinouts("#newcustomercheckin","#newcustomercheckout");if(!f.valid){alert(CUS_CHECKIN_AFTER_OUT[l]);return}var d={name:b,email:m,addr:o,remark:g,phone:j,mobil:k,www:c,hello:n,regards:h,checkin:f.checkin,checkout:f.checkout,room:a};if(!cusCheckTextLengths(d)){return}doAjax("POST","php/contenthandler.php?module=customers&command=createNewCustomer",d,handleCreateCustomerResult,"Gast anlegen unmöglich",true)}});$("#customersearch").off("keyup").on("keyup",function(a){startSearch()});$("#groupsearch").off("keyup").on("keyup",function(a){startSearch()});$("#newgroupbtn").off("click").on("click",function(c){c.stopImmediatePropagation();c.preventDefault();var a=$("#newgroupname").val().trim();var d=$("#newgroupremark").val().trim();if(a===""){alert(GROUP_EMPTY_NAME[l])}else{var b={name:a,remark:d};doAjax("POST","php/contenthandler.php?module=customers&command=createNewGroup",b,handleCreateGroupResult,"Gruppe anlegen unmöglich",true)}});$("#customerlog").off("click").on("click",function(a){a.stopImmediatePropagation();a.preventDefault();window.open("php/contenthandler.php?module=customers&command=exportLog","_blank")});$("#reportbills").off("click").on("click",function(a){a.stopImmediatePropagation();a.preventDefault();window.open("php/contenthandler.php?module=customers&command=reportbills","_blank")})}function bindOnDynamicCustomersBtn(){$(".applycustomer").off("click").on("click",function(g){g.stopImmediatePropagation();g.preventDefault();var j=this.id.split("_")[1];var a=[];for(var b=0;b<allgroups.length;b++){var f=allgroups[b];var c="#grplistitem_"+j+"_"+f.id;if($(c).hasClass("ingroup")){a[a.length]=f.id}}var h=getCheckinouts("#cusfield_checkin_"+j,"#cusfield_checkout_"+j);if(!h.valid){alert(CUS_CHECKIN_AFTER_OUT[l]);return}if(a.length===0){a=""}var d={id:j,name:$("#cusfield_name_"+j).val().trim(),email:$("#cusfield_email_"+j).val().trim(),addr:$("#cusfield_address_"+j).val().trim(),remark:$("#cusfield_remark_"+j).val().trim(),phone:$("#cusfield_phone_"+j).val().trim(),mobil:$("#cusfield_mobil_"+j).val().trim(),www:$("#cusfield_www_"+j).val().trim(),hello:$("#cusfield_hello_"+j).val().trim(),regards:$("#cusfield_regards_"+j).val().trim(),groups:a};if(!cusCheckTextLengths(d)){return}doAjax("POST","php/contenthandler.php?module=customers&command=changeCustomer",d,handleChangeCustomerResult,"Gast ändern unmöglich",true)});$(".deletecustomer").off("click").on("click",function(a){a.stopImmediatePropagation();a.preventDefault();var b=this.id.split("_")[1];areYouSureCus("Gast löschen",CUS_DEL_TEXT[l],CUS_DEL[l],function(){deleteCustomerCore(b)})});$(".applygroup").off("click").on("click",function(b){b.stopImmediatePropagation();b.preventDefault();var c=this.id.split("_")[1];var a={id:c,name:$("#grpfield_name_"+c).val().trim(),remark:$("#grpfield_remark_"+c).val().trim()};doAjax("POST","php/contenthandler.php?module=customers&command=changeGroup",a,handleChangeGroupResult,"Gruppe ändern unmöglich",true)});$(".deletegroup").off("click").on("click",function(a){a.stopImmediatePropagation();a.preventDefault();var b=this.id.split("_")[1];areYouSureCus("Gruppe löschen",GRP_DEL_TEXT[l],GRP_DEL[l],function(){deleteGroupCore(b)})});$(".grpsel").off("click").on("click",function(c){c.stopImmediatePropagation();c.preventDefault();var b=this.id.split("_")[1];var a=this.id.split("_")[2];var d="#grplistitem_"+b+"_"+a;if($(d).hasClass("ingroup")){$(d).removeClass("ingroup");$(d).addClass("notingroup");$(d+" a").removeClass("ui-btn-f");$(d+" a").addClass("ui-btn-c");$(d+" a").removeClass("ui-icon-check");$(d+" a").addClass("ui-icon-delete")}else{$(d).removeClass("notingroup");$(d).addClass("ingroup");$(d+" a").removeClass("ui-btn-c");$(d+" a").addClass("ui-btn-f");$(d+" a").removeClass("ui-icon-delete");$(d+" a").addClass("ui-icon-check")}});$(".groupsendemail").off("click").on("click",function(f){f.stopImmediatePropagation();f.preventDefault();var b=this.id.split("_")[1];var c=$("#grpemailsubjectfield_grpemailsubject_"+b).val();var a=$("#grpemailbccfield_grpemailbcc_"+b).val();var g=$("#grpemailtextfield_grpemailtext_"+b).val();var d={groupid:b,subject:c,bcc:a,text:g};doAjax("POST","php/contenthandler.php?module=customers&command=emailGroup",d,handleEmailResult,"Emailen unmöglich",true)});$(".vacationcollapsible").off("collapsibleexpand").on("collapsibleexpand",function(c){var a=this.id.split("_");if(a[0]=="allvacations"){var b=a[1];updateVacationsOfCustomer(b)}});$(".billscollapsible").off("collapsibleexpand").on("collapsibleexpand",function(c){var a=this.id.split("_");if(a[0]=="allbills"){var b=a[1];updateBillsOfCustomer(b)}});$("#customerdate").off("change").on("change",function(a){startCustomerSearch()});$("#customeropenbills").off("change").on("change",function(a){startCustomerSearch()});$(".paymentpayallguests").off("click").on("click",function(a){a.stopImmediatePropagation();a.preventDefault();var b=this.id.split("_")[2];doAjax("POST","php/contenthandler.php?module=customers&command=payallguests",{paymentid:b},handlePayAllResult,"Deklaration alle Gäste als bezahlt unmöglich",true)})}function bindVacations(){$(".vacationentry").off("collapsibleexpand").on("collapsibleexpand",function(a){a.stopImmediatePropagation();a.preventDefault()});$(".billentry").off("collapsibleexpand").on("collapsibleexpand",function(a){a.stopImmediatePropagation();a.preventDefault()});$(".newvacationscollapsible").off("collapsibleexpand").on("collapsibleexpand",function(a){a.stopImmediatePropagation();a.preventDefault()});$(".newvacation").off("click").on("click",function(d){d.stopImmediatePropagation();d.preventDefault();var a=this.id.split("_")[1];var g=getCheckinouts("#cusfield_newcheckin_"+a,"#cusfield_newcheckout_"+a);if(!g.valid){alert(CUS_CHECKIN_AFTER_OUT[l]);return}var f=$("#cusfield_vacremark_"+a).val();if(f.length>200){cusAlertTextLength("Bemerkung");return false}var c=$("#cusfield_cusfield_newroom_"+a).val();if(c.length>50){cusAlertTextLength("Zimmer");return false}var b={id:a,checkin:g.checkin,checkout:g.checkout,room:c,remark:f};doAjax("POST","php/contenthandler.php?module=customers&command=newVacation",b,handleChangeVacationResult,"Aufenthalt anlegen unmöglich",true)});$(".delvacation").off("click").on("click",function(a){a.stopImmediatePropagation();a.preventDefault();var b=this.id.split("_")[1];doAjax("POST","php/contenthandler.php?module=customers&command=delVacation",{id:b},handleChangeVacationResult,"Aufenthalt löschen unmöglich",true)});$(".unpaybill").off("click").on("click",function(b){b.stopImmediatePropagation();b.preventDefault();var a=this.id.split("_")[1];$("#stornocode").val("");$("#stornoreason").val("");areYouSureCancel(CUS_STORNO_QUEST_TITLE[l],CUS_STORNO_QUEST_TEXT[l],CUS_YES[l],function(){var c={id:a,code:$("#stornocode").val(),remark:$("#stornoreason").val()};doAjax("POST","php/contenthandler.php?module=customers&command=unpay",c,handleChangeBillResult,"Deklaration als unbezahlt unmöglich",true)})});$(".paymentpay").off("click").on("click",function(d){d.stopImmediatePropagation();d.preventDefault();var g=this.id;var c=g.split("_");var a=c[2];var f=c[3];var b=c[4];if(b!="all"){doAjax("POST","php/contenthandler.php?module=customers&command=pay",{id:b,paymentid:f},handleChangeBillResult,"Deklaration als bezahlt unmöglich",true)}else{doAjax("POST","php/contenthandler.php?module=customers&command=payallbills",{id:a,paymentid:f},handleChangeBillResult,"Deklaration alle unmöglich",true)}});$(".printbill").off("click").on("click",function(b){b.stopImmediatePropagation();b.preventDefault();var a=this.id.split("_")[1];doAjax("POST","php/contenthandler.php?module=customers&command=printbill",{id:a},null,"Drucken unmöglich",true)});$(".printallbills").off("click").on("click",function(b){b.stopImmediatePropagation();b.preventDefault();var a=this.id.split("_")[1];doAjax("POST","php/contenthandler.php?module=customers&command=printallbills",{id:a},null,"Drucken alle unmöglich",true)});$(".reportallbillsofsinglecus").off("click").on("click",function(b){b.stopImmediatePropagation();b.preventDefault();var a=this.id.split("_")[1];window.open("php/contenthandler.php?module=customers&command=reportcustomerbills&cusid="+a,"_blank")})}function updateVacationsOfCustomer(a){doAjax("GET","php/contenthandler.php?module=customers&command=getVacations",{cusid:a},handleVacationsResult,null,true)}function updateBillsOfCustomer(a){doAjax("GET","php/contenthandler.php?module=customers&command=getBills",{cusid:a},handleBillsResult,null,true)}function handleVacationsResult(e){if(e.status==="OK"){var f=e.msg.vacations;var b=e.msg.cusid;var a="";for(var d=0;d<f.length;d++){var c=f[d];a+=renderAVacation(b,c.id,c.checkin,c.checkout,c.room,c.remark)}$("#vacationsarea_"+b).html(a);$("#vacationsarea_"+b).trigger("create");bindVacations()}}function handleBillsResult(h){if(h.status==="OK"){var g=h.msg.bills;var b=h.msg.cusid;var d=false;var a="";for(var c=0;c<g.length;c++){var e=g[c];if(e.paid==0){d=true}a+=renderABill(b,e.id,e.billdate,e.brutto,e.guestinfo,e.paid)}if(g.length>0){if(d){a+="<br><b>"+CUS_DECLARE_ALL_PAY[l]+"</b>:<br>";for(var c=0;c<payments.length;c++){var f=payments[c];a+=createApplyButton("payment_"+b+"_"+f.id+"_all",f.name,"e","paymentpay")}}a+=createApplyButton(b+"_printallbills",CUS_PRINT_ALL[l],"f","printallbills");a+=createApplyButton(b+"_reportallbillsofsinglecus",CUS_REPORT[l],"f","reportallbillsofsinglecus")}$("#billsarea_"+b).html(a);$("#billsarea_"+b).trigger("create");bindVacations()}}function renderAVacation(b,h,d,c,f,g){var e=d+" - "+c;var a=createCollapsibleStartGeneral("vacationentry_"+b,e,"c","vacationentry",true);a+="<p>Check-in: "+d;a+="<p>Check-out: "+c;a+="<p>"+CUS_ROOM_LABEL[l]+": "+f;a+="<p>"+CUS_REMARK_LABEL[l]+g;a+=createDeleteButton(h+"_delvacation",CUS_DEL[l],"d","delvacation");a+="</div>";return a}function renderABill(h,b,c,f,g,i){var a=f.replace(".",decpoint)+" "+currency;var e="c";if(i==1){e="f"}var d=createCollapsibleStartGeneral("billentry_"+h,c+" - "+a,e,"billentry",true);d+="<p>"+CUS_BILLID[l]+": "+b;d+="<p>"+CUS_BILLDATE[l]+": "+c;d+="<p>"+CUS_BILLBRUTTO[l]+": "+c;if(i==0){d+=createPaymentsArea(h,b,CUS_DECLAREPAY[l])}else{d+=createApplyButton(b+"_unpaybill",CUS_DECLAREUNPAY[l],"d","unpaybill")}d+=createApplyButton(b+"_printbill",CUS_PRINTBILL[l],"f","printbill");d+="</div>";return d}function handleEmailResult(a){if(a.status==="OK"){alert("Aktion abgeschlossen")}else{alert("Error: "+a.msg)}}function handleChangeVacationResult(b){if(b.status==="OK"){var a=b.cusid;$("#cusfield_newcheckin_"+a).val("");$("#cusfield_newcheckout_"+a).val("");$("#cusfield_cusfield_newroom_"+a).val("");$("#cusfield_vacremark_"+a).val("");updateVacationsOfCustomer(a)}else{alert("Error: "+b.msg)}}function handleChangeBillResult(b){if(b.status==="OK"){var a=b.cusid;updateBillsOfCustomer(a)}else{alert("Error: "+b.msg)}}function handlePayAllResult(a){if(a.status==="OK"){startCustomerSearch()}else{alert("Error: "+a.msg)}}function deleteCustomerCore(b){var a={id:b};doAjax("POST","php/contenthandler.php?module=customers&command=deleteCustomer",a,handleDeleteCustomerResult,"Gast löschen unmöglich",true)}function deleteGroupCore(b){var a={id:b};doAjax("POST","php/contenthandler.php?module=customers&command=deleteGroup",a,handleDeleteGroupResult,"Gruppe löschen unmöglich",true)}function areYouSureCus(c,b,a,d){$("#sure .sure-1").text(c);$("#sure .sure-2").text(b);$("#sure .sure-do").text(a).off("click.sure").on("click.sure",function(){d()});$(this).off("click.sure");$.mobile.changePage("#sure")}function startSearch(){var a={search:$("#groupsearch").val().trim()};doAjax("POST","php/contenthandler.php?module=customers&command=getGroups",a,handleGetGroupsResult,"Gästeabfrage unmöglich",true)}function startCustomerSearch(){var c=$("#customersearch").val().trim();var a=getDate("#customerdate");var d="";if((a!=null)&&(a!="")){d=a.year+"-"+a.month+"-"+a.day}var b=0;if($("#customeropenbills").is(":checked")){b=1}var e={search:c,date:d,onlyopenbills:b};doAjax("POST","php/contenthandler.php?module=customers&command=getCustomers",e,handleGetCustomerResult,"Gästeabfrage unmöglich",true)}function clearNewCustomerFields(){$("#newcustomername").val("");$("#newcustomeremail").val("");$("#newcustomeraddress").val("");$("#newcustomerremark").val("");$("#newcustomerphone").val("");$("#newcustomermobil").val("");$("#newcustomerwww").val("");$("#newcustomerhello").val("");$("#newcustomerregards").val("");$("#newcustomercheckin").val("");$("#newcustomercheckout").val("");$("#newcustomerroom").val("")}function handleCreateCustomerResult(a){if(a.status==="OK"){clearNewCustomerFields();if(a.code==1){var b=CUS_ALREADY_CUS_NAME[l];b=b.replace("%number%",a.value);alert(b)}startSearch()}else{alert(CUS_ACTION_FAILED[l]+": "+a.msg)}}function clearNewGroupFields(){$("#newgroupname").val("");$("#newgroupremark").val("")}function handleCreateGroupResult(a){if(a.status==="OK"){clearNewGroupFields();startSearch()}else{if(a.code==1){alert(CUS_GROUP_EXISTS[l])}else{alert(CUS_ACTION_FAILED[l]+": "+a.msg)}}}function handleChangeCustomerResult(a){if(a.status==="OK"){startSearch()}else{alert(CUS_ACTION_FAILED[l]+": "+a.msg)}}function handleDeleteCustomerResult(a){if(a.status==="OK"){startSearch()}else{alert(CUS_ACTION_FAILED[l]+": "+a.msg)}}function handleDeleteGroupResult(a){if(a.status==="OK"){startSearch()}else{alert(CUS_ACTION_FAILED[l]+": "+a.msg)}}function handleChangeGroupResult(a){if(a.status==="OK"){startSearch()}else{alert(CUS_ACTION_FAILED[l]+": "+a.msg)}}function createInputTextField(f,d,e,b,c){var a='<div class="ui-field-contain">';a+=' <label id="label_'+e+"_"+f+'" for="'+d+"field_"+e+"_"+f+'">'+b+":</label>";a+=' <input id="'+d+"field_"+e+"_"+f+'" type="text" data-mini="true" class="whiteinput" value="'+toHtml(c)+'" />';a+="</div>";return a}function createTextAreaField(f,d,e,b,c){var a='<div class="ui-field-contain">';a+=' <label id="label_'+e+"_"+f+'" for="'+d+"field_"+e+"_"+f+'">'+b+"</label>";a+=' <textarea cols="40" rows="8" name="'+d+"field_"+e+"_"+f+'" id="'+d+"field_"+e+"_"+f+'" data-theme="a">';a+=toHtml(c);a+="</textarea>";a+="</div>";return a}function createDateTimePicker(d,b,c){var a='<div data-role="fieldcontain" id="datepickerarea">';a+=' <label for="'+d+'"><span id=datetxt>'+b+"</span>: </label>";a+=' <input data-role="date" data-inline="true" type="text" id="'+d+'" data-theme="'+c+'">';a+="</div>";return a}function createCollapsibleStartNew(d,b,c){var a='<div data-role="collapsible" id="newcustomerdiv_'+d+'" data-theme="'+c+'" data-content-theme="'+c+'">';a+="<h3>"+toHtml(b)+"</h3>";return a}function createCollapsibleStartGeneral(g,c,e,f,b){var d=" ";if(b===false){d=' style="display:none;" '}var a='<div data-role="collapsible" id="'+g+'" data-theme="'+e+'" data-content-theme="'+e+'" class="'+f+'" '+d+">";a+="<h3>"+toHtml(c)+"</h3>";return a}function createApplyButton(e,b,d,c){var a='<button type="submit" data-theme="'+d+'" class="'+c+'" data-icon="check" id="applycustomer_'+e+'">'+b+"</button>";return a}function createDeleteButton(e,b,d,c){var a='<button type="submit" data-theme="'+d+'" class="'+c+'" data-icon="delete" id="deletecustomer_'+e+'">'+b+"</button>";return a}function createApplyDeleteButtons(d,c,b){var a='<div class="ui-grid-a" class="noprint">';a+='<div class="ui-block-a">'+createApplyButton(d,CUS_APPLY[l],"f",c)+"</div>";a+='<div class="ui-block-b">'+createDeleteButton(d,CUS_DEL[l],"d",b)+"</div>";a+="</div>";return a}function renderACustomer(d){var b=d.id;var c="";if((d.openbillsum!=null)&&(d.openbillsum!="")){c=" ("+d.openbillsum;c=c.replace(".",decpoint)+" "+currency+")"}var a=createCollapsibleStartNew(b,d.name+c,"c");a+="<p><form>";a+=createInputTextField(b,"cus","name","Name",d.name);a+=createTextAreaField(b,"cus","address",CUS_ADR_LABEL[l],d.address);a+=createInputTextField(b,"cus","phone",CUS_PHONE_LABEL[l],d.phone);a+=createInputTextField(b,"cus","mobil",CUS_MOBIL_LABEL[l],d.mobil);a+=createInputTextField(b,"cus","email","E-Mail",d.email);a+=createInputTextField(b,"cus","www",CUS_WWW_LABEL[l],d.www);a+=createInputTextField(b,"cus","hello",CUS_HELLO_LABEL[l],d.hello);a+=createTextAreaField(b,"cus","regards",CUS_REGARDS_LABEL[l],d.regards);a+=createTextAreaField(b,"cus","remark",CUS_REMARK_LABEL[l],d.remark);a+=createGroupList(d);a+="<p><i>";a+=CUS_CREATED[l]+": "+d.created+"<br>";a+=CUS_LAST_MODIFIED[l]+": "+d.lastmodified;a+="</i>";a+=createApplyDeleteButtons(b,"applycustomer","deletecustomer");a+="</form>";a+=createCollapsibleStartGeneral("allbills_"+b,CUS_BILLS[l],"e","billscollapsible",true);a+='<p><div id="billsarea_'+b+'"><img src="php/3rdparty/images/ajax-loader.gif"/></div>';a+="</div>";a+=createCollapsibleStartGeneral("allvacations_"+b,CUS_VACATIONS[l],"e","vacationcollapsible",true);a+='<p><div id="vacationsarea_'+b+'"><img src="php/3rdparty/images/ajax-loader.gif"/></div>';a+=createCollapsibleStartGeneral("newvacations_"+b,CUS_NEWVACATIONS[l],"c","newvacationscollapsible",true);a+=createDateTimePicker("cusfield_newcheckin_"+b,"Check-in","a");a+=createDateTimePicker("cusfield_newcheckout_"+b,"Check-out","a");a+=createInputTextField(b,"cus","cusfield_newroom",CUS_ROOM_LABEL[l],"");a+=createInputTextField(b,"cus","vacremark",CUS_REMARK_LABEL[l],"");a+=createApplyButton(b+"_newvacation",CUS_APPLY[l],"f","newvacation");a+="</div></div>";a+="</div>";return a}function renderCustomers(b){var a="";for(var c=0;c<b.length;c++){a+=renderACustomer(b[c])}$("#customersearchresult").html(a);$("#customersearchresult").trigger("create");for(var c=0;c<b.length;c++){customizeDatePicker("#cusfield_newcheckin_"+b[c].id,"");customizeDatePicker("#cusfield_newcheckout_"+b[c].id,"")}}function handleGetCustomerResult(a){if(a.status==="OK"){customers=a.msg;renderCustomers(a.msg);bindOnDynamicCustomersBtn()}else{alert(CUS_ACTION_FAILED[l]+": "+a.msg)}}function handleGetGroupsResult(a){if(a.status==="OK"){renderGroups(a.msg.filtered);allgroups=a.msg.all;startCustomerSearch()}else{alert(CUS_ACTION_FAILED[l]+": "+a.msg)}}function renderAGroup(e){var b=e.id;var a=createCollapsibleStartNew(b,e.name,"c");a+="<p><form>";a+=createInputTextField(b,"grp","name","Name",e.name);a+=createTextAreaField(b,"grp","remark",CUS_REMARK_LABEL[l],e.remark);var c=e.customers;if(c.length>0){a+="<p><div class='customerlistbox'>";a+=CUS_CONTAINED_IN_GRP[l]+":<br>";for(var d=0;d<c.length;d++){a+="- "+c[d].name+"<br>"}a+="</div>"}a+="<p><i>";a+=CUS_CREATED[l]+": "+e.created+"<br>";a+="</i>";a+=createApplyDeleteButtons(b,"applygroup","deletegroup");a+=createCollapsibleStartGeneral("groupemail_"+b,"Email","e","groupemailentry",true);a+=createInputTextField(b,"grpemailsubject","grpemailsubject","Subject","");a+=createInputTextField(b,"grpemailbcc","grpemailbcc","BCC","");a+=createTextAreaField(b,"grpemailtext","grpemailtext","Text","");a+="<p>"+CUS_PLACEHOLDER_HINT[l]+" <i>"+CUS_EMAIL_WARNING[l]+"</i>";a+="<p>"+createApplyButton(b+"_groupsendemail",CUS_SEND_EMAIL[l],"f","groupsendemail");a+="</div>";a+="</form>";a+="</div>";return a}function renderGroups(b){var a="";for(var c=0;c<b.length;c++){a+=renderAGroup(b[c])}$("#groupsearchresult").html(a);$("#groupsearchresult").trigger("create")}function isCustomerInGroup(a,b){for(var c=0;c<a.length;c++){if(a[c].groupid==b){return true}}return false}function createGroupList(f){var k=f.id;var b=f.groups;var e='<ul data-role="listview" id="grouplist_'+k+'" data-divider-theme="a" data-inset="true">';e+='<li data-role="list-divider" data-theme="b" data-role="heading">'+CUS_GRP_ASS_LIST[l]+"</li>";for(var d=0;d<allgroups.length;d++){var c=allgroups[d];var h=c.id;var a="c";var g="delete";var j="notingroup";if(isCustomerInGroup(b,h)){a="f";g="check";j="ingroup"}e+='<li id="grplistitem_'+k+"_"+h+'" data-theme="'+a+'" data-icon="'+g+'" class="'+j+'"><a href="#" id="grpass_'+k+"_"+h+'" class="grpsel">'+toHtml(c.name)+"</a></li>"}e+="</ul>";return e}function cusAlertTextLength(a){alert(CUS_ALERT_TEXT_LEN[l]+a)}function cusCheckTextLengths(a){if(a.name.length>50){cusAlertTextLength("Name");return false}if(a.addr.length>200){cusAlertTextLength(CUS_ADR_LABEL[l]);return false}if(a.phone.length>30){cusAlertTextLength(CUS_PHONE_LABEL[l]);return false}if(a.mobil.length>30){cusAlertTextLength(CUS_MOBIL_LABEL[l]);return false}if(a.email.length>50){cusAlertTextLength("Email");return false}if(a.www.length>50){cusAlertTextLength(CUS_WWW_LABEL[l]);return false}if(a.remark.length>500){cusAlertTextLength(CUS_REMARK_LABEL[l]);return false}return true}function customizeDatePicker(e,b){var d="de";if(l==1){d="en"}else{if(l==2){d="es"}}var a=new Date().getFullYear();var c=(a-10)+":"+(a+3);$(e).datepicker($.datepicker.regional[d]).datepicker("option",{changeMonth:true,changeYear:true,yearRange:c});if((b!=null)&&(b!="")){$(e).datepicker("setDate",new Date(b))}else{$(e).val("")}}function getDate(d){var c=$(d).val();if((c==undefined)||(c.trim()=="")){return null}var a=$(d).datepicker("getDate");var b={day:("0"+a.getDate()).slice(-2),month:("0"+(a.getMonth()+1)).slice(-2),year:a.getFullYear(),date:a};return b}function getCheckinouts(b,h){var d=getDate(b);var c=getDate(h);var a="";if((d!=null)&&(d!="")){a=d.year+"-"+d.month+"-"+d.day}var f="";if((c!=null)&&(c!="")){f=c.year+"-"+c.month+"-"+c.day}var e=true;if((d!=null)&&(d!="")&&(c!=null)&&(c!="")){if(d.date>c.date){e=false}}var g={checkin:a,checkout:f,valid:e};return g}function areYouSureCancel(c,b,a,d){$("#cancelsure .sure-1").text(c);$("#cancelsure .sure-2").text(b);$("#cancelsure .sure-do").text(a).off("click.cancelsure").on("click.cancelsure",function(f){f.stopImmediatePropagation();f.preventDefault();$("#nocancelbtn").off("click");$("#cancelsure").dialog("close");$.mobile.changePage("#info-page");d();$(this).off("click.cancelsure")});$("#nocancelbtn").off("click").on("click",function(f){f.stopImmediatePropagation();f.preventDefault();$("#cancelsure .sure-do").text(a).off("click.cancelsure");$("#cancelsure").dialog("close");$.mobile.changePage("#info-page")});$.mobile.changePage("#cancelsure");setTimeout(function(){$("#stornocode").val("");$("#stornoreason").val("")},1000)};