window.onload = function () { $(".loader").fadeOut("slow"); $("#body").fadeIn(1000); } //Função que carrega conteúdo sem refresh function Conteudo(url, div) { $('#' + div).html('
'); $.ajax({ url: url, success: function (data) { $('#' + div).animate({ opacity: '0' }); setTimeout(function () { $('#' + div).html(data); $('#' + div).animate({ opacity: '1' }); }, 500); }, error: function () { $('#' + div).html(''); } }); } function ShowToast(aTitle, aHeader) { $('#title_toast').html(aTitle); $('#body_toast').html(aHeader); $('#base_toast').removeClass('d-none').animate({ opacity: '1' }); //console.log(aHeader); $(".toast").addClass('show-toast'); setTimeout(function () { CloseToast(); }, 3500); } function CloseToast() { $("#base_toast").animate({ opacity: '0' }); setTimeout(function () { $(".toast").removeClass('show-toast'); $('#base_toast').addClass('d-none'); }, 500); } function ShowModal(titulo, texto) { $('#modal_titulo').html(titulo); $('#modal_texto').html(texto); CloseModal(); $('#modal').modal('show'); } function ShowModalPage(url) { CloseModal(); $('#modalPage').modal('show'); Conteudo(url, 'corpo-modal-page'); } function CloseModal() { $('#modal').modal('hide'); } function CloseModalEdit() { $('#modalEdit').modal('hide'); } function CloseModalPage() { $('#modalPage').modal('hide'); } function ShowLoader() { $("#progressbar").removeClass('invisible'); } function HideLoader() { $("#progressbar").addClass('invisible'); } function SelectOptionText(idcombo, valor) { $("#" + idcombo).val($('option:contains("' + valor + '")').val()); } function SelectOptionValue(idcombo, valor) { $('#' + idcombo + ' option[value="' + valor + '"]').attr({ selected: "selected" }); } function GetConfig() { //console.log('entrou get config'); var dados = $(this).serialize(); $.ajax({ url: "pages/ajax/get_config.php", cache: false, data: dados, success: function (data) { if (data == true) { //console.log('Configurado com sucesso !!!'); } else { //console.log('Ops config', data); } }, error: function (erro) { //console.log('Erro Config !!', 'Ocorreu um erro ao tentar gravar o cadastro. Erro: ' + erro); } }); } function DCript(aText, aInput = '') { $.ajax({ cache: false, url: "Source/App/Controller/Ajax/get_decrypt.php", type: 'POST', data: { text: aText }, success: function (data) { if (aInput !== '') { $(aInput).val(data); } else { return data; } }, error: function (erro) { return ''; } }); } function SetTitle(NamePage) { if (NamePage.trim() !== '') { document.title = NamePage + ' - ' + document.title; } } function SetLS(nome, valor) { localStorage.setItem(nome, valor); } function GetLS(nome) { var LS; LS = localStorage.getItem(nome); if (LS == null) { return ""; } else { return LS; } } function ClearLS(nome) { localStorage.setItem(nome, ''); } function SaveMenu(ItemMenu) { SetLS('open_menu', ItemMenu); } function OpenMenu() { var NomeMenu = GetLS('open_menu'); $('#' + NomeMenu).click(); } function OpenPage(link) { window.open(link, "_self"); } function UpperPrime(text) { if (text !== '') { var words = text.toLowerCase().split(" "); for (var a = 0; a < words.length; a++) { var w = words[a]; words[a] = w[0].toUpperCase() + w.slice(1); } return words.join(" "); } } function Deleta(id, ref, idrow) { var rConfirma; bootbox.confirm({ message: "Deseja mesmo prosseguir com a exclusão do cadastro ?", buttons: { confirm: { label: ' Confirmar', className: 'btn-success' }, cancel: { label: ' Cancelar', className: 'btn-danger' } }, callback: function (result) { if (result) { $.ajax({ cache: false, url: "Source/App/Config/Delete.php", type: 'POST', data: { "id": id, "referencia": ref }, success: function (data) { if (data == '') { ShowModal('Ops', 'Esta ação não teve o retorno esperado. Contate um administrador.'); } else { var obj = JSON.parse(data); if (obj.erro == 1) { ShowModal('Ops', obj.msg); } else { $('#' + idrow).remove(); ShowToast('', obj.msg); //Verifica a referencia e recarrega o combo do cadastro ao fechar o modal if (ref == 'unidade_medida') { GetComboUnidadeMedida('un'); } else if (ref == 'grupo_produto') { GetComboGrupo('id_grupo'); } else if (ref == 'area_atuacao') { GetComboGrupo('area_atuacao'); } } } }, error: function (erro) { ShowModal("Ops", 'Ocorreu um erro durante a exclusão do item. Erro: ' + erro); } }); } } }); } function formatReal(int) { var tmp = int + ''; tmp = tmp.replace(/([0-9]{2})$/g, ",$1"); if (tmp.length > 6) tmp = tmp.replace(/([0-9]{3}),([0-9]{2}$)/g, ".$1,$2"); return tmp; } function keypressed(obj, e) { var tecla = (window.event) ? e.keyCode : e.which; if (tecla == 8 || tecla == 0) return true; if (tecla != 44 && tecla < 48 || tecla > 57) return false; } function openCloseLeftMenu() { if (document.getElementById("mySidenav").style.width == "240px") { closeLeftMenu(); SetLS('openleftmenu', false); } else { openLeftMenu(); SetLS('openleftmenu', true); } } function openLeftMenu() { $('#mySidenav').width('240px'); $('#corpo').css('margin-left', '240px'); } function closeLeftMenu() { $('#mySidenav').width('54px'); $('#corpo').css('margin-left', '54px'); } function Tip(data) { $("#tip-text").text($(data).attr('data-tip')); } function NoTip() { $("#tip-text").text(''); } function ShowHideFilters() { var visivel = $('#nav-filter').is(':visible'); if (visivel) { SetLS('filter', 'none'); } else { SetLS('filter', 'block'); } $('#nav-filter').toggle('fast'); } function ChekUnchek(id) { $('#' + id).each(function () { if (this.checked) this.checked = false; else this.checked = true; }); } function marcarTodos(marcardesmarcar) { var dataTable = $('#rel-table').dataTable(); $(dataTable.fnGetNodes()).each(function () { // https://legacy.datatables.net/ref $(this).find('input[type="checkbox"]').each(function () { this.checked = marcardesmarcar; }); }); } function ValidaForm(aForm) { var Campos = ''; if (aForm == '' || isUndefined(aForm)) { aForm = 'ajax_form'; } $("#" + aForm + " input[valida='true']").each(function (index) { if ($.trim($(this).val()) == '') { if (!$(this).attr("disabled") && !$(this).attr("readonly")) { $(this).addClass('border-invalid'); Campos += '
* ' + $(this).attr("text-valid"); } else { $(this).removeClass('border-invalid'); } } }); $("#" + aForm + " select[valida='true']").each(function (index) { if (!$(this).val()) { if (!$(this).attr("disabled") && !$(this).attr("readonly")) { $(this).addClass('border-invalid'); Campos += '
* ' + $(this).attr("text-valid"); } } }); $("#" + aForm + " input[doc='cpfcnpj']").each(function (index) { if ($.trim($(this).val()) !== '') { if (!$(this).attr("disabled") && !$(this).attr("readonly")) { if (!validaCpfCnpj($.trim($(this).val()))) { $(this).addClass('border-invalid'); Campos += '
* Informar CPF ou CNPJ Válido'; } } else { $(this).removeClass('border-invalid'); } } }); $("#" + aForm + " input[doc='cnpj']").each(function (index) { if ($.trim($(this).val()) !== '') { if (!$(this).attr("disabled") && !$(this).attr("readonly")) { if (!ValidaCNPJ($.trim($(this).val()))) { $(this).addClass('border-invalid'); Campos += '
* Informar CNPJ Válido'; } } else { $(this).removeClass('border-invalid'); } } }); $("#" + aForm + " input[tp='data']").each(function (index) { if ($.trim($(this).val()) !== '') { if (!$(this).attr("disabled") && !$(this).attr("readonly")) { if ($.trim($(this).val()) !== '00/00/0000') { if (!validateDate($.trim($(this).val()))) { //$(this).addClass('border-invalid'); var legenda = $("label[for='" + $(this).attr('name') + "']").html(); if (legenda !== '') { Campos += '
* Informe uma ' + legenda + ' válida'; } else { Campos += '
* Data Válida'; } } } } } }); if (Campos !== '') { ShowModal(' Campos Obrigatórios', 'Os campos abaixo devem ser preenchidos !!!
' + Campos) return false; } } function LimpaForm(aForm) { if (aForm == '') { aForm = 'ajax_form'; } $('#' + aForm).each(function () { this.reset(); }); } function GetParam(aurlParams, aParam) { //coonsole.log('aaa'); // Verifica se o parâmetro existe aurlParams.has(aParam); // true // Imprime todos os parâmetros como na forma original, sem o "?" na frente return aurlParams.toString(); // page=1 } function GetParamURL(aParam) { // Exemplo: https://website.com/blog?page=1 var urlParams = new URLSearchParams(location.search); // Verifica se o parâmetro existe urlParams.has(aParam); // true // Imprime todos os parâmetros como na forma original, sem o "?" na frente return urlParams.toString(); // page=1 // Adiciona um parâmetro com chave e valor especificados //urlParams.append('key', 'val'); // Resultado: page=1&key=val // Remove um parâmetro //urlParams.delete('key'); // Resultado: page=1 } function GetParamsURL() { var query = location.search.slice(1); var partes = query.split('&'); var data = {}; partes.forEach(function (parte) { var chaveValor = parte.split('='); var chave = chaveValor[0]; var valor = chaveValor[1]; data[chave] = valor; }); return data; } function isUndefined(aVal) { return (typeof aVal === "undefined"); } function onlynumber(evt) { var theEvent = evt || window.event; var key = theEvent.keyCode || theEvent.which; key = String.fromCharCode(key); var regex = /^[0-9]+$/; if (!regex.test(key)) { theEvent.returnValue = false; if (theEvent.preventDefault) theEvent.preventDefault(); } } function ValidaCPF(val) { var cpf = val.trim(); cpf = cpf.replace(/\./g, ''); cpf = cpf.replace('-', ''); cpf = cpf.split(''); var v1 = 0; var v2 = 0; var aux = false; for (var i = 1; cpf.length > i; i++) { if (cpf[i - 1] != cpf[i]) { aux = true; } } if (aux == false) { return false; } for (var i = 0, p = 10; (cpf.length - 2) > i; i++, p--) { v1 += cpf[i] * p; } v1 = ((v1 * 10) % 11); if (v1 == 10) { v1 = 0; } if (v1 != cpf[9]) { return false; } for (var i = 0, p = 11; (cpf.length - 1) > i; i++, p--) { v2 += cpf[i] * p; } v2 = ((v2 * 10) % 11); if (v2 == 10) { v2 = 0; } if (v2 != cpf[10]) { return false; } else { return true; } } function ValidaCNPJ(val) { var cnpj = val.trim(); cnpj = cnpj.replace(/\./g, ''); cnpj = cnpj.replace('-', ''); cnpj = cnpj.replace('/', ''); cnpj = cnpj.split(''); var v1 = 0; var v2 = 0; var aux = false; for (var i = 1; cnpj.length > i; i++) { if (cnpj[i - 1] != cnpj[i]) { aux = true; } } if (aux == false) { return false; } for (var i = 0, p1 = 5, p2 = 13; (cnpj.length - 2) > i; i++, p1--, p2--) { if (p1 >= 2) { v1 += cnpj[i] * p1; } else { v1 += cnpj[i] * p2; } } v1 = (v1 % 11); if (v1 < 2) { v1 = 0; } else { v1 = (11 - v1); } if (v1 != cnpj[12]) { return false; } for (var i = 0, p1 = 6, p2 = 14; (cnpj.length - 1) > i; i++, p1--, p2--) { if (p1 >= 2) { v2 += cnpj[i] * p1; } else { v2 += cnpj[i] * p2; } } v2 = (v2 % 11); if (v2 < 2) { v2 = 0; } else { v2 = (11 - v2); } if (v2 != cnpj[13]) { return false; } else { return true; } } function validaCpfCnpj(val) { if (val.length == 11) { return ValidaCPF(val); } else if (val.length == 14) { ValidaCNPJ(val); } else { return false; } } function validateDate_old(aData) { var RegExPattern = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02]) [\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/; if (!((aData.match(RegExPattern)) && (aData.value != ''))) { return false; } else { return true; } } function validateDate(aData) { var date = aData; var ardt = new Array; var ExpReg = new RegExp("(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/[12][0-9]{3}"); ardt = date.split("/"); erro = false; if (date.search(ExpReg) == -1) { erro = true; } else if (((ardt[1] == 4) || (ardt[1] == 6) || (ardt[1] == 9) || (ardt[1] == 11)) && (ardt[0] > 30)) erro = true; else if (ardt[1] == 2) { if ((ardt[0] > 28) && ((ardt[2] % 4) != 0)) erro = true; if ((ardt[0] > 29) && ((ardt[2] % 4) == 0)) erro = true; } if (erro) { return false; } else { return true; } } function ValidaData(aData) { var dia = aData.split("/")[0]; var mes = aData.split("/")[1]; var ano = aData.split("/")[2]; var MyData = new Date(ano, mes - 1, dia); if ((MyData.getMonth() + 1 !== mes) || (MyData.getDate() !== dia) || (MyData.getFullYear() !== ano)) { return false; } else { return true; } } function RemoveParams() { var url_atual = window.location.href; //window.location.href = url_atual.substr(0, url_atual.indexOf('?')); //window.history.replaceState(data, title, url_atual.substr(0, url_atual.indexOf('?'))); window.history.replaceState('', '', url_atual.substr(0, url_atual.indexOf('?'))); //console.log(url_atual); } function apenasNumeros(string) { var numsStr = string.replace(/[^0-9]/g, ''); return numsStr; } function apenasMoeda(string) { //var numsStr = string.replaceAll(/[^0-9+,]/g, ''); //var numsStr = string.replaceAll(/\,|[^0-9]/g, ''); //var numsStr = string.replaceAll(/^\d+,\d{2}$/g, ''); var numsStr = string.replaceAll(/(?!-)[^0-9,]/g, ''); //numsStr = numsStr.replace(/\d|,/g, ''); return (numsStr); } function MoedaCalculo(aValor) { aValor = aValor.replaceAll('.', ''); aValor = aValor.replaceAll(',', '.'); return parseFloat(aValor); } function MoedaPrint(aValor) { /* aValor = aValor.toString().replaceAll('.', ''); aValor = aValor.toString().replaceAll(',', ''); aValor = formatReal(aValor); aValor = aValor.toString().replaceAll('.', ''); */ if (aValor !== null) { aValor = aValor.toString().replaceAll('.', ','); } else { aValor = '0,00'; } return aValor; } function FormataMoeda(aVal) { if (aVal == '') { return '0,00'; } else { return aVal.toLocaleString('pt-br', { minimumFractionDigits: 2 }); } } function OpenCloseMenu(aMenu) { var vs = $('#' + aMenu).is(':visible'); if (vs) { $('#' + aMenu).slideUp(); SetLS(aMenu, 'false'); } else { $('#' + aMenu).slideDown(); SetLS(aMenu, 'true'); } } function FormataCPFCNPJ(aDoc) { var NumCarac = aDoc.length; var Doc; if (NumCarac == 11) { Doc = aDoc.substring(0, 3) + '.' + aDoc.substring(3, 6) + '.' + aDoc.substring(6, 9) + '-' + aDoc.substring(9, 11); } else if (NumCarac == 14) { Doc = aDoc.substring(0, 2) + '.' + aDoc.substring(2, 5) + '.' + aDoc.substring(5, 8) + '/' + aDoc.substring(8, 12) + '-' + aDoc.substring(12, 14); } else { Doc = aDoc; } return Doc; } $(document).ajaxStart(function () { ShowLoader(); }); $(document).ajaxComplete(function () { HideLoader(); }); function CallBackValue(aCampoSemaforo, aCampoValue, aValue) { /* PARA QUE O CAMPO "aCampoValue" POSSA SER PREENCHIDO, O CAMPO "aCampoSemaforo" PRECISA ESTAR PREENCHIDO, BASICAMENETE É ISSO QUE A ROTINA FAZ... ELE CONSIDERA 120 CHECAGENS ANTES DE IGNORAR A AÇÃO */ if (aValue !== 0 && aValue !== '') { var i = 0; $(aCampoValue).addClass('input-load'); var Start = setInterval(function () { //console.log('CallBackValue: ' + i); if ($(aCampoSemaforo).val() || i == 120) { $(aCampoValue).val(aValue); if ($(aCampoValue).val() || i == 120) { $(aCampoValue).removeClass('input-load'); $(aCampoValue).change(); clearInterval(Start); } } i++; }, 50); } } function DataDia() { var dt = new Date(); var d = dt.getDate(); var m = dt.getMonth(); m++; var y = dt.getFullYear(); if (String(d).length == 1) { d = '0' + d; } if (String(m).length == 1) { m = '0' + (m); } return d + '/' + m + '/' + y; } function SalvaFiltro(aForm) { $("#" + aForm + " input[save='true']").each(function (index) { SetLS($(this).attr('name'), $(this).val()); }); $("#" + aForm + " select[save='true']").each(function (index) { SetLS($(this).attr('name'), $(this).val()); }); return true; } function LoadFiltro(aForm) { $("#" + aForm + " input[save='true']").each(function (index) { $(this).val(GetLS($(this).attr('name'))); }); $("#" + aForm + " select[save='true']").each(function (index) { $(this).val(GetLS($(this).attr('name'))); }); } function getTotalTable(aNameTable, aPosColumn) { let result = 0; let columns = $("#" + aNameTable + " tr td:nth-child(" + aPosColumn + ")"); columns.each(i => { result += parseFloat(MoedaCalculo($(columns[i]).html())); }); return result; } function convertToReal(number, options = {}) { const { moneySign = true } = options; if (Number.isNaN(number) || !number) return "need a number as the first parameter"; if (typeof number === "string") { // n1 number = Number(number); } let res; const config = moneySign ? { style: 'currency', currency: 'BRL' } : { minimumFractionDigits: 2 }; moneySign ? res = number.toLocaleString('pt-BR', config) : res = number.toLocaleString('pt-BR', config) const needComma = number => number <= 1000; if (needComma(number)) { res = res.toString().replace(".", ","); } return res; // n2 } function IsEmail(email) { var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/); if (!er.test(email)) { return false; } else { return true; } } function setCookie(aName, aValue) { document.cookie = aName + "=" + aValue; } /* function setCookie(name, exdays) { var expires; var date; var value; date = new Date(); // criando o COOKIE com a data atual date.setTime(date.getTime() + (exdays * 24 * 60 * 60 * 1000)); expires = date.toUTCString(); value = "TESTE123"; document.cookie = name + "=" + value + "; expires=" + expires + "; path=/"; } */ function getCookie(name) { var cookies = document.cookie; var prefix = name + "="; var begin = cookies.indexOf("; " + prefix); if (begin == -1) { begin = cookies.indexOf(prefix); if (begin != 0) { return null; } } else { begin += 2; } var end = cookies.indexOf(";", begin); if (end == -1) { end = cookies.length; } return unescape(cookies.substring(begin + prefix.length, end)); } /* function GetSession(aSession) { var Ret = ''; $.ajax({ cache: false, url: "Source/App/Controller/Acesso/get_sessions.php", type: 'POST', success: function (data) { var obj = JSON.parse(data); if (aSession == 'id_empresa') { Ret = obj.id_empresa; } else if (aSession == 'id') { Ret = obj.id; } else if (aSession == 'nome') { Ret = obj.nome; } else if (aSession == 'nivel') { Ret = obj.nivel; } else if (aSession == 'email') { Ret = obj.email; } else if (aSession == 'id_empresa') { Ret = obj.id_empresa; } else if (aSession == 'nome_empresa') { Ret = obj.nome_empresa; } else { Ret = '0'; } console.log('Ret:' + Ret + ' - aSession:' + aSession); return Ret; }, error: function (erro) { return '0'; } }); } */ function GetSession() { return $.ajax({ url: "Source/App/Controller/Acesso/get_sessions.php", cache: false, type: 'POST' }); /*COMO UTILIZAR GetSession() .done(function (data) { //done code }) .fail(function () { //fail code }) .always(function () { //some code }); */ } function ImportaDados() { Conteudo('Source/App/View/Importa/importa_dados.php', 'corpo_modal_edit'); $('#modalEdit').modal({ keyboard: false, backdrop: 'static' }); } function CopiarPlanoConta(EmpresaOrigem) { Conteudo('Source/App/View/PlanoConta/copia_plano_contas.php', 'corpo_modal_edit'); $('#modalEdit').addClass('bd-example-modal-lg').removeClass('bd-example-modal-xl'); $('#subModalEdit').addClass('modal-lg').removeClass('modal-xl'); $('#modalEdit').modal(); setTimeout(function () { $('#empresa_destino').val(EmpresaOrigem); $('#id_empresa').find('[value="'+EmpresaOrigem+'"]').remove(); $('#empresa_destino').attr('disabled', true); }, 1000); } function CadGrupo() { Conteudo('Source/App/View/GrupoProduto/cad_grupo.php', 'corpo_modal_edit'); $('#btnGravaGrupo').removeAttr('disabled'); $('#tip-text').html(''); $('#form_grupo_produto #id').val(''); $('#form_grupo_produto #codigo').val(''); $('#form_grupo_produto #descricao').val(''); $('#modalEdit').modal({ keyboard: false, backdrop: 'static' }); setTimeout(function () { $('#form_grupo_produto #descricao').focus(); }, 500); } function CadUnMedida() { Conteudo('Source/App/View/UnidadeMedida/cad_unidade_medida.php', 'corpo_modal_edit'); $('#btnGravaUnidadeMedida').removeAttr('disabled'); $('#tip-text').html(''); $('#form_unidade_medida #id').val(''); $('#form_unidade_medida #descricao').val(''); $('#modalEdit').modal({ keyboard: false, backdrop: 'static' }); setTimeout(function () { $('#form_unidade_medida #descricao').focus(); }, 500); } // Função criada pois o SHowModal fica por trás da tela na exibição de erros, então foi criada essa função para auxiliar em cadastros modal function ModalRejeicao(local, msg, botao) { $('#' + local).html(''); $('#tip-text').html(''); $('#' + botao).removeAttr('disabled'); } //Formata moeda enquanto usuário digita, ligar função ao evento onkeyup do input //Passar ID do input como parâmetro function FormatarMoedaInput(input) { var elemento = document.getElementById(input); var valor = elemento.value; valor = valor + ''; valor = parseInt(valor.replace(/[\D]+/g, '')); valor = valor + ''; valor = valor.replace(/([0-9]{2})$/g, ",$1"); if (valor.length > 6) { valor = valor.replace(/([0-9]{3}),([0-9]{2}$)/g, ".$1,$2"); } elemento.value = valor; if (valor == 'NaN') elemento.value = ''; } function modalRelatorio(caminhoConteudo) { $('#subModalEdit').addClass('modal-personalizado'); $('#corpo_modal_edit').addClass('modal-personalizado'); $('#modalEdit').modal({ keyboard: false, backdrop: 'static' }); Conteudo(caminhoConteudo, 'corpo_modal_edit'); } function FormataStringData(data) { var dia = data.split("/")[0]; var mes = data.split("/")[1]; var ano = data.split("/")[2]; return ano + '-' + ("0" + mes).slice(-2) + '-' + ("0" + dia).slice(-2); // Utilizo o .slice(-2) para garantir o formato com 2 digitos. } function OpenCloseMenu(aMenu) { var vs = $('#' + aMenu).is(':hidden'); if (!(vs)) { $('#' + aMenu).slideUp(); SetLS(aMenu, 'false'); } else { $('#' + aMenu).slideDown(); SetLS(aMenu, 'true'); } } function FiltrosVenda() { if (($('#data_inicial').val() == '') || ($('#data_final').val() == '')) { ShowModal('Ops !!', 'Para prosseguir é necessário preencher a data inicial e a data final !!'); } else if ($('#data_final').val() < $('#data_inicial').val()) { ShowModal('Ops !!', 'A data final não pode ser maior que a data inicial !!'); } else { url_atual = window.location.href; if ((window.location.href.indexOf("data_inicial") != -1) && (window.location.href.indexOf("data_final") != -1)) { var caracter = url_atual.indexOf("&"); url_atual = url_atual.substring(caracter, 0); } url_atual += '&data_inicial=' + $('#data_inicial').val() + '&data_final=' + $('#data_final').val(); window.location = url_atual.replace('#', ''); } } function GeraXLS() { location.href = excelExport("rel-table").parseToCSV().parseToXLS("excelexport sheet").getXLSDataURI(); setTimeout(function() { window.close(); }, 1000); } function Print() { window.print(); window.addEventListener("afterprint", function(event) { window.close(); }); window.onafterprint(); window.addEventListener("abort", function(event) { window.close(); }); }