function formatAMPM(date) { var hours = date.getHours(); var minutes = date.getMinutes(); var ampm = hours >= 12 ? 'PM' : 'AM'; hours = hours % 12; hours = hours ? hours : 12; // the hour '0' should be '12' minutes = minutes < 10 ? '0'+minutes : minutes; var strTime = hours + ':' + minutes + ' ' + ampm; return strTime; } function addDays(startDate, numberOfDays) { return new Date(startDate.getTime() + (numberOfDays * 24 *60 * 60 * 1000)); } jQuery.fn.priceShort = function(){ var _t = jQuery(this); var texto = _t.html(); if(_t[0].nodeName=='INPUT') texto = _t.val(); if (texto.length > 3){ texto = (texto + '').replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); if(texto[texto.length-3] == '0') texto = texto.substr(0, texto.length-4); else texto = texto.substr(0, texto.length-2); } else{ texto = ',' + texto; } if(_t[0].nodeName=='INPUT') _t.val(texto); else _t.html(texto) return texto; }; function VerInfoCampo(campo){ var str = 'tag: ' + campo.prop("tagName") + ', class: ' + campo.attr('class') + ', id: ' + campo.attr('id') + ', name: ' + campo.attr('name') + ', val: ' + campo.val() + ', text: ' + campo.text(); alert(str); } function addNumber(e){ //return; //document.getElementById('PINbox').value = document.getElementById('PINbox').value+element.value; var v = $( "#PINbox" ).val(); if ($( "#PINbox" ).val().length <= 3) $( "#PINbox" ).val( v + e.value ); else $( "#PINbox" ).val(''); $("#PINcode .enter").hide(); if ($( "#PINbox" ).val().length == 4) $("#PINcode .enter").fadeIn(); } function clearForm(e){ //document.getElementById('PINbox').value = ""; $( "#PINbox" ).val( "" ); $("#PINcode .enter").hide(); } function submitFormPin(e) { if (e.value == "") { alert("Enter a PIN"); } else { //alert( "Your PIN has been sent! - " + e.value ); var obj = {}; obj['pin'] = e.value; var dS = {}; dS['array'] = obj; dS['accion']= 'autenticar-usuario'; dS['json']= true; p =({'data': dS}); if (f9450182465036c1e6c451dbd65016efe(p)){ //console.log(j); $( "#PINbox" ).val(''); $("#PINcode .enter").hide(); oData = jQuery.parseJSON(j); if (oData['OK'] != undefined){ //console.log($(location).attr('href')); $(location).attr('href',$(location).attr('href')) //div.hide(); //ocultarDivGrid({'tbody': 'ingreso_mp'}); } } //document.getElementById('PINbox').value = ""; $( "#PINbox" ).val( "" ); }; }; var urlAsignar = 'https://lp.kibbesfusion.com/aMaestros.php'; var jSonData = {}; function f9450182465036c1e6c451dbd65016efe(p){ p['url']= urlAsignar; if (typeof p['data']['accion'] == 'undefined') p['data']['accion']= 'insertar-categoria-tipo'; //p['data']['object_name']='comanda'; if (AMaestrosSub(p)){ //$( "#result" ).load("https://lp.kibbesfusion.com/testMaestros.php" ); return true; } return false; } function AMaestrosSub(p) { var t_ini = Date.now(); var fixedurl = p['url']; $('#div_cargando_info').show(); $.ajax({url: fixedurl, type: 'POST', async: false, data: p['data'], success: function (data) {j = data; ocultar = true; if(typeof ocultar_div_cargando_info != 'undefined'){ ocultar = ocultar_div_cargando_info}; if(ocultar) $('#div_cargando_info').fadeOut();}, complete: function (){}, error: function (request, status, error) { console.log(request.responseText); } }) return true; } function pad (pPad) { if (pPad['letra'] == undefined) pPad['letra'] = " "; if (pPad['side'] == undefined) pPad['side'] = "R"; // o L pPad['str'] = pPad['str'].toString(); var str = pPad['str']; if (pPad['side'] == 'L'){ pPad['str'] = pPad['letra'] + pPad['str']; } else{ pPad['str'] = pPad['str'] + pPad['letra']; } return str.length < pPad['max'] ? pad(pPad) : str; } function FormatoMiles(pTN){ if (pTN['str'] == undefined) return ""; return pTN['str'].toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,') } function timeToSeconds(time) { time = time.split(/:/); return time[0] * 3600 + time[1] * 60 + time[2]; } function CampoEstaVacio(pCEV){ var retorno = true; if (pCEV['campo'] != undefined){ if (pCEV['campo'].prop('tagName') == 'INPUT') if (pCEV['campo'].val() != '') retorno = false; if (pCEV['campo'].prop('tagName') == 'TEXTAREA') if (pCEV['campo'].val() != '') retorno = false; if (pCEV['campo'].prop('tagName') == 'SELECT') if (pCEV['campo'].val() != '') retorno = false; } return retorno; } (function($){ $.fn.extend({ addTemporaryClass: function(className, duration) { var elements = this; setTimeout(function() { elements.removeClass(className); }, duration); return this.each(function() { $(this).addClass(className); }); } }); })(jQuery); ////////////////////////////////////////////////////////////////////////////// // BUSQUEDA DE AUTOCOMPLETE // var instanciasMaterialize ={}; var oVarAutocomplete = {}; class BuscarAutoComplete { constructor(oParams) { this.url = "https://lp.kibbesfusion.com/includes/searchJSON.php?auth=true&s="+oParams.campo.val()+"&c=" + oParams.search; //console.log(this.url); if (instanciasMaterialize[oParams['nombreInstancia']] == undefined){ //console.log('crear instancia ' + oParams['nombreInstancia']); instanciasMaterialize[oParams['nombreInstancia']] = M.Autocomplete.init(document.querySelector(oParams['nombreInstancia'] + ' [name="' + oParams['campo'].attr('name') + '"]')); this.update = false; }else this.update = true; //console.log(this.update); //this.autoComplete({'url': this.url}); this.ejecutarse(oParams) this.update = false; this.response = {}; this.dataRender = {}; this.dataRenderFull = {}; this.campo = oParams['campo']; this.oParams = oParams; //console.log(me.oParams.funcion) } ejecutarse(oParams){ this.url = "https://lp.kibbesfusion.com/includes/searchJSON.php?auth=true&s="+oParams.campo.val()+"&c=" + oParams.search; this.update = true; //console.log(this.url) this.autoComplete({'url': this.url}); } autoCompleteSuccess() { var me = this; let aIds = {}; //console.log(me) /* $('[row="'+this.oParams['row']+'"]').find('[name="ID"]').each(function(){ let e = $(this); if (e.val().length > 0) aIds[e.val()] = e.val(); }) */ //console.log(this.response) for (var i = 0; i < this.response.length; i++) { if (aIds[this.response[i]['ID']] == undefined){ this.dataRender[this.response[i].NOMBRE] = null; this.dataRenderFull[this.response[i].NOMBRE] = this.response[i]; } } //console.log(this.dataRenderFull) if(this.update) { //console.log('if'); var instancia = M.Autocomplete.getInstance(me.campo.get(0)); instancia.updateData(me.dataRender) } else { //console.log('else'); this.campo.autocomplete({ data: me.dataRender, onAutocomplete: function(response){ //console.log(me) /* me.campo.closest('[grupo]').find('[name]').each(function(){ var e = $(this); //console.log(me.dataRenderFull) //if (me.dataRenderFull[response] == undefined){ me.update = true; return;} //console.log('response: ' + response); //console.log(me.dataRenderFull[response]); if (me.dataRenderFull[response][e.attr('name')] != undefined){ e.val(me.dataRenderFull[response][e.attr('name')]); e.closest('div').find('label:not(.label-icon)').css({'transform': 'translateY(0px) scale(0.8)'}); } }) */ //console.log(me.dataRenderFull) if (me.dataRenderFull[response][me.campo.attr('name')] != undefined){ me.campo.val(me.dataRenderFull[response][me.campo.attr('name')]); //console.log('response: '); //console.log(me.dataRenderFull[response]) me.campo.attr('id_encontrado', me.dataRenderFull[response]['ID']); //console.log(me.campo) //e.closest('div').find('label:not(.label-icon)').css({'transform': 'translateY(0px) scale(0.8)'}); } //me.campo.closest('[grupo]').find('[check]').hide(); if (me.campo.attr('bloquear') != undefined) me.campo.attr('disabled', true); if (me.oParams['funcion'] != undefined) this.funcion = me.oParams['funcion']({'campo': me.campo, 'resultado': me.dataRenderFull[response]}); //console.log(me.dataRenderFull[response].id); //e.closest().val(dataRenderFullPT[response].id_producto); //console.log(dataRenderFullPT[response]); //CargarRecetaActivaItems({'ID_PRODUCTO': dataRenderFullPT[response].id_producto}); } //limit: 5 The max amount of results that can be shown at once. Default: Infinity. }); } } autoComplete() { var me = this; $.ajax({ type: "GET", //GET or POST or PUT or DELETE verb url: this.url, // Location of the service data: "", //Data sent to server contentType: "", // content type sent to server dataType: "json", //Expected data format from server processdata: true, //True or False success: function (json) {//On Successful service call //console.log(json); me.response = json; me.autoCompleteSuccess(); } }); } } // // ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // LLENAR INPUTS DE UN DIV CON DATOS DE UN OBJETO // function GeneralLlenarDivDesdeObjeto(pDDO){ if(pDDO['obj'] == undefined || pDDO['div'] == undefined) return; $.each(pDDO['obj'], function(k, v){ if (pDDO['convertir'] != undefined){ if (pDDO['convertir'][k] != undefined) k = pDDO['convertir'][k]; } var field = pDDO['div'].find('[name="'+k+'"]'); //console.log(k + ' -> ' + v + ': ' + field.prop('tagName')); if ($.inArray(field.prop('tagName'), ['INPUT', 'TEXTAREA', 'SELECT']) != -1 ){ if(field.prop('type') == "checkbox"){ if (v == 1) field.prop('checked', true); else field.prop('checked', false); }else field.val(v); }else if (field.prop('tagName') == 'SPAN') field.text(v); if ($.inArray(field.prop('tagName'), ['SELECT']) != -1){ //console.log(k + ' -> ' + v + ': ' + field.prop('tagName')); field.formSelect(); } if(field.closest('div').find('label').prop('tagName') != undefined && v != '' && v != null){ //console.log(field.attr('name') + ' "'+v+'"'); field.closest('div').find('label').addClass('active'); } }) } // // ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // LIMPIAR INPUTS DE UN DIV // function GeneralLimpiarDivHTML(pGLD){ if(pGLD['div'] == undefined) return; pGLD['div'].find('[name]').each(function(){ var field = $(this); //console.log(k + ' -> ' + v + ': ' + field.prop('tagName')); if ($.inArray(field.prop('tagName'), ['INPUT', 'TEXTAREA', 'SELECT']) != -1 ){ if(field.prop('type') == "checkbox"){ field.prop('checked', false); }else field.val(''); }else if (field.prop('tagName') == 'SPAN') field.text(''); if ($.inArray(field.prop('tagName'), ['SELECT']) != -1){ //console.log(k + ' -> ' + v + ': ' + field.prop('tagName')); field.formSelect(); } if(field.closest('div').find('label').prop('tagName') != undefined){ //console.log(field.attr('name') + ' "'+v+'"'); field.closest('div').find('label').addClass('active'); } }) } // // ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // COMPROBAR SI EL ELEMENTO ES VISIBLE // function esVisible(elemento) { var esVisible = false; if ($(elemento).is(':visible') && $(elemento).css("visibility") != "hidden" && $(elemento).css("opacity") > 0) { esVisible = true; } return esVisible; } // // ////////////////////////////////////////////////////////////////////////////// function random_rgba() { var o = Math.round, r = Math.random, s = 255; return 'rgba(' + o(r()*s) + ',' + o(r()*s) + ',' + o(r()*s) + ',' + r().toFixed(1) + ')'; } function VerificarSesionAbierta(pVSA){ var dS = {}; dS['array'] = {}; dS['accion']= 'verificar-sesion-abierta'; dS['json']= true; p =({'data': dS}); if (f9450182465036c1e6c451dbd65016efe(p)){ //console.log(j); //return; oGetData = jQuery.parseJSON(j); //console.log(oGetData); //console.log(oGetData); if (oGetData['OK'] != undefined){ var tmp = new Date(); //M.toast({html: oGetData['MSG'] + ' ' + tmp, displayLength: 3000}); //console.log("") if(!oGetData['OK']){ $('body').css({'background-color': 'orange'}); setTimeout(function() { window.location.href = ""; clearInterval(setInterval_VerifSesionAbierta); }, 800) } } return true; } }