URL_BASE = getCookie('URL_BASE'); const URL_ARQUIVOS = 'https://files.movetask.com.br?path='; const ESTADOS = { "AC": "Acre", "AL": "Alagoas", "AP": "Amap\u00e1", "AM": "Amazonas", "BA": "Bahia", "CE": "Cear\u00e1", "DF": "Distrito Federal", "ES": "Esp\u00edrito Santo", "GO": "Goi\u00e1s", "MA": "Maranh\u00e3o", "MT": "Mato Grosso", "MS": "Mato Grosso do Sul", "MG": "Minas Gerais", "PA": "Par\u00e1", "PB": "Para\u00edba", "PR": "Paran\u00e1", "PE": "Pernambuco", "PI": "Piau\u00ed", "RJ": "Rio de Janeiro", "RN": "Rio Grande do Norte", "RS": "Rio Grande do Sul", "RO": "Rond\u00f4nia", "RR": "Roraima", "SC": "Santa Catarina", "SP": "S\u00e3o Paulo", "SE": "Sergipe", "TO": "Tocantins" }; VERIFY_PASS = true; let aClickMenu = 1; let arquivosEmail = new DataTransfer(); const session = getDataSession(); // define usuários id_tipo_colaborador const USUARIO_CLIENTE = 4; const LIMITE_CARACTERES_ASSUNTO_CHAMADO = 120; // define origens const ORIGEM_USUARIO_CLIENTE = 1; const urlSplit = URL_BASE.split('/client'); const URL_API_SERPRO = window.location.href.includes('local') ? `http://localhost/${urlSplit[0]}/API/Serpro/api` : 'https://dots.app.br/API/Serpro/api'; const URL_API_AUTOTASK = window.location.href.includes('local') ? `http://localhost/${urlSplit[0]}/API/autotask` : 'https://dots.app.br/API/autotask'; function maskPhone(value) { value = value.replace(/\D/g, '') value = value.replace(/(\d{2})(\d)/, "($1) $2") value = value.replace(/(\d)(\d{4})$/, "$1-$2") return value; } function OpenPage(aLink) { window.open(aLink, "_self"); } /**LOCAL STORAGE */ 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, ''); } /**SESSION STORAGE */ function SetSS(nome, valor) { sessionStorage.setItem(nome, valor); } function GetSS(nome) { var SS; SS = sessionStorage.getItem(nome); if (SS == null) { return ""; } else { return SS; } } function ClearSS(nome) { sessionStorage.removeItem(nome); } /**COOKIES*/ function setCookie(aName, aValue) { document.cookie = aName + "=" + aValue; } 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)); } /**LOAD*/ function ShowLoad() { $('#aLoad').fadeIn(); } function HideLoad() { $('#aLoad').fadeOut(); } /*MODAL*/ function OpenModal(aText, aTitle = '') { let LocalModal = GetSS('modal'); if (LocalModal) { execModal(aText, aTitle); } else { $.ajax({ url: '/' + URL_BASE + 'App/View/Pages/Launcher/modal.php', contentType: "application/html; charset=utf-8", success: function (data) { SetSS('modal', data); execModal(aText, aTitle); }, error: function () { // } }); } return false; } function execModal(aText, aTitle = '') { $("body").append(GetSS('modal')); $("#aBodyModal").html(aText); if (aTitle) { $('#exampleModalLabel').html(aTitle) } } function ModalPropagarHorarios(id) { $.ajax({ url: '/' + URL_BASE + 'App/View/Pages/Colaboradores/include/modal_propagar_horarios.php', contentType: "application/html; charset=utf-8", success: function (data) { $("body").append(data); if (!id) $('#aCloseModal').attr('onclick', `selecionaDiaParaPropagarHoras()`); else $('#aCloseModal').attr('onclick', `selecionaDiaParaPropagarHoras('${id}')`); }, error: function () { // } }); return false; } function CloseModal() { $('#aModal').remove(); } function ClosePageModal() { const divs = $('.a_modal'); const lastDiv = divs.last(); lastDiv.remove(); } function CloseFileModal() { $('#aFileModal').remove(); } // TOAST ALERT WITH ACTION // type = info | success | error | warning function OpenToastV2(aTitle, aDescription, type = 'info', textButton, timeExpiration = 6000, callbackAction = null, id = null) { const toastId = (!id ? Math.floor(Math.random() * 99999) : id); let refToast = 'toastV2_' + toastId; let html = ''; html += ``; $("#toast-container-V2").append(html); $("#liveToastV2").attr('id', refToast); $('*[id=' + refToast + ']').slideDown(); $(`#btnCloseToastV2_${toastId}`).on('click', () => CloseToast(refToast)); if (typeof callbackAction === "function") { $(`#btnActionToastV2_${toastId}`).on('click', () => callbackAction()); } if (timeExpiration && timeExpiration > 0) { setTimeout(function () { $('*[id=' + refToast + ']').slideUp(); CloseToast(refToast); }, timeExpiration); } } /*TOAST*/ function OpenToast(aText, aError = false) { let html = ''; SetSS('toast', html); execToast(aText); } function execToast(aText) { let refToast = 'toast_' + Math.floor(Math.random() * 99999); $("#toast-container").append(GetSS('toast')); $("#liveToast").attr('id', refToast); $('*[id=' + refToast + ']').html(aText).slideDown(); setTimeout(function () { $('*[id=' + refToast + ']').slideUp(); setTimeout(function () { $('*[id=' + refToast + ']').slideUp(); CloseToast(refToast); }, 1000); }, 5000); } function CloseToast(refToast) { $('*[id=' + refToast + ']').remove(); } /**VALIDATE */ function ValidaForm(aForm) { var Campos = ''; // $("#" + aForm).find("input[valida='true']").each(function (index) { $("#" + aForm + " input[valida='true']").each(function (index) { if ($(this).closest('form').attr('id') == aForm) { if ($.trim($(this).val()) == '') { if (!$(this).attr("disabled") && !$(this).attr("readonly")) { $(this).addClass('invalid'); // Campos += '
* ' + $(this).attr("id"); Campos += '
' + $(this).closest('div').html().split('')[0].replace('form-label', 'form-label text-secondary').trim(); } else { $(this).removeClass('invalid'); } } else { $(this).removeClass('invalid'); } } }); $("#" + aForm + " select[valida='true']").each(function (index) { if ($(this).closest('form').attr('id') == aForm) { if (!$(this).val()) { if (!$(this).attr("disabled") && !$(this).attr("readonly")) { $(this).addClass('invalid'); // Campos += '
* ' + $(this).attr("id"); Campos += '
' + $(this).closest('div').html().split('')[0].replace('form-label', 'form-label text-secondary').trim(); } } else { $(this).removeClass('invalid'); } } }); $("#" + aForm + " input[doc='cpfcnpj']").each(function (index) { if ($(this).closest('form').attr('id') == aForm) { if ($(this).val()) { if (!$(this).attr("disabled") && !$(this).attr("readonly")) { if (!validaCpfCnpj(apenasNumeros($(this).val()))) { $(this).addClass('invalid'); Campos += '
* Informar CPF ou CNPJ Válido'; } else { $(this).removeClass('invalid'); } } else { $(this).removeClass('invalid'); } } else { $(this).addClass('invalid'); } } }); $("#" + aForm + " input[tp='mail']").each(function (index) { if ($(this).closest('form').attr('id') == aForm) { if ($.trim($(this).val()) !== '') { if (!$(this).attr("disabled") && !$(this).attr("readonly")) { if (!IsEmail($.trim($(this).val()))) { $(this).addClass('invalid'); Campos += '
* Informar E-mail Válido'; } } else { $(this).removeClass('invalid'); } } else { $(this).removeClass('invalid'); } } }); if (!VERIFY_PASS) { $('#msgSenhaFraca').css({ 'display': 'block' }); OpenToast('Informe uma senha forte', true); return; } else { $('#msgSenhaFraca').css({ 'display': 'none' }); } $("#" + aForm + " input[tp='data']").each(function (index) { if ($(this).closest('form').attr('id') == aForm) { if ($.trim($(this).val()) !== '') { if (!$(this).attr("disabled") && !$(this).attr("readonly")) { if ($.trim($(this).val()) !== '00/00/0000') { if (!validateDate($.trim($(this).val()))) { var legenda = $("label[for='" + $(this).attr('name') + "']").html(); if (legenda !== '') Campos += '
* Informe uma ' + legenda + ' válida'; else Campos += '
* Data Válida'; } } } } else { $(this).removeClass('invalid'); } } }); if (Campos !== '') { OpenToast(' Os campos abaixo devem ser preenchidos !!!' + Campos.replaceAll('form-label', 'm-0') + '', true); // OpenToast('Preencha os campos obrigatórios !!'); // OpenModal(' Os campos abaixo devem ser preenchidos !!!
' + Campos); return false; } else { return true; } } /**AJAX LOAD*/ // $(document).ajaxStart(function () { // ShowLoad(); // }); // $(document).ajaxComplete(function () { // HideLoad(); // }); // $(document).ajaxError(function () { // HideLoad(); // }); $(document).ready(function () { // Whenever the key is pressed, apply condition checks. $("input[tp='password']").keyup(function () { var m = $(this).val(); var n = m.length; // Function for checking check(n, m); }); $("input[tp='password']").blur(function () { var m = $(this).val(); var n = m.length; // Function for checking check(n, m); }) }); function check(n, m) { if (n == 0) { $('.progress-bar').attr('aria-valuenow', '33%') $('.progress').addClass('bg-danger'); VERIFY_PASS = false; } if (n < 8 && n > 0) { VERIFY_PASS = false; } if (n >= 8 && (m.match(/[a-z]/) != null) && (m.match(/[A-Z]/) != null) && (m.match(/0|1|2|3|4|5|6|7|8|9/) != null)) { VERIFY_PASS = false; } if (n >= 8 && (m.match(/\W/) != null) && (m.match(/[a-z]/) != null) && (m.match(/[A-Z]/) != null) && (m.match(/0|1|2|3|4|5|6|7|8|9/) != null) && (m.match(/\D/) != null)) { VERIFY_PASS = true; } // Check for the character-set constraints // and update percentage variable as needed. // Lowercase Words only // (m.match(/[a-z]/) != null)) // Uppercase Words only // m.match(/[A-Z]/) != null)) // Digits only // ((m.match(/0|1|2|3|4|5|6|7|8|9/) != null)) // Special characters // ((m.match(/\W/) != null) && (m.match(/\D/) != null)) } /**MISCELANEAS */ function isUndefined(aVal) { return (typeof aVal === "undefined"); } function SetTitle(NamePage) { if (NamePage.trim() !== '' || !isUndefined(NamePage)) document.title = NamePage + ' - ' + document.title; else document.title = 'Ares Dots'; } function apenasNumeros(string) { var numsStr = string.replace(/[^0-9]/g, ''); return numsStr; } function MoedaPrint(aValor) { aValor = aValor.toLocaleString('pt-br', { minimumFractionDigits: 2 }); return aValor; } function FormataValorMoeda(aValor) { if ((typeof aValor) === "number") { aValor = aValor.toString(); } aValor = aValor?.replaceAll(',', '.'); aValor = parseFloat(aValor); return aValor.toLocaleString('pt-br', { minimumFractionDigits: 2 }); } function MoedaCalculo(aValor) { aValor = aValor.replaceAll('.', ''); aValor = aValor.replace(',', '.'); return parseFloat(aValor); } 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(); } } // idChildren é utilizado quando vc tem uma tabela pai, mas precisa deletar um item da tabela filha tbm; // Exemplo: tabela de arquivos do projeto/tarefa oq precisa ser enviado para api é o idChildren, que é o id da tabela arquivos. function Deleta(table, id, id_usuario, idLine = '', idChildren = 0) { let message; if (table == "departamento_empresa") { message = "Atenção, ao excluir um departamento, os processos e obrigações ligados ao departamento também serão excluídos da empresa. Deseja prosseguir?"; } else if (table == "faturamento") { message = "Atenção, ao excluir um faturamento os serviços e contas a receber em aberto também serão excluídos. Deseja prosseguir ?"; } else if (table == "contrato") { message = "Atenção, ao excluir um contrato, os itens ligados a esse contrato também serão excluídos. Deseja prosseguir?"; } else if (table == "projetos") { message = "Atenção, a exclusão do projeto implica na exclusão de todas as suas dependências. (Tarefas, Comentários e Arquivos)" } else if (table == 'solicitacao_cliente') { message = "Deseja realmente excluir este chamado?"; } else message = "Deseja realmente excluir esta informação"; bootbox.confirm({ title: "Exclusão", message: message, closeButton: false, buttons: { cancel: { label: ' Cancelar' }, confirm: { label: ' Confirmar' } }, callback: result => { let form = ""; if (result) { /* cria formulário pra enviar no _EXEC */ form += `
`; form += ` `; form += ` `; form += ` `; form += "
"; /* adiciona form no html e envia */ $('body').append(form); _EXEC('formExclusao', 'Item removido com sucesso') .done(data => { /* remove form e atualiza tabela */ $('#formExclusao').remove(); setTimeout(() => { if (table == "tarefa_agenda") { reRender(); } if ((table != 'ponto_justificativa_falta') && (table != 'vencimentos') && (table != 'empresa_contato')) $('#btnList').click(); if (table == 'titulo_modelo_projeto_tarefas' || table == 'projeto_tarefas') { $(`#${idLine}`).remove(); } else { $(`#tr-${id}`).remove(); } if (table == "empresa_contato") atualizarListaContatos(); if (table == "departamento_empresa") { atualizaTabelaDepartamentoEmpresa(); } if (table == "faturamento") { removeItensDoFaturamento(id, id_usuario); removeContasReceber(id, id_usuario); removerIdFaturamentoDoProjeto(id); } if (table == "projetos") { removerTarefasDoProjeto(id); removerComentariosProjetoTarefas(id); removerArquivosProjetoTarefa(id); } if (table == "arquivos_projeto_tarefas") { deleteFiles(idChildren.toString()); } if (table == "documento_texto") { deleteFiles(idChildren); } if (table == "tarefas") { removerTarefasTituloProjeto(id); // remover a tarefa dos títulos de projeto. removerTarefasDoProjeto(0, id); // remover a tarefa dos projetos removerComentariosProjetoTarefas(0, id); // remover os comentário da tarefa. removerArquivosProjetoTarefa(0, id); // remover os arquivos da tarefa } if (table == "empresa") { removerProjeto(id); // deletar o projeto ao excluir a Cliente/cliente } if (table == "solicitacao_cliente") { ClosePageModalFull(); const session = getDataSession(); const msgLog = `O colaborador(a) ${(session.apelido) ? session.apelido : session.nome} excluiu o chamado.`; saveGeneralLog(id_usuario, table, id, msgLog, 0); } if (table == "contrato") removeItensDoContrato(id, id_usuario); if (table == 'conta_corrente_cobranca') $(`#row_cobranca_${id}`).remove(); else if (table == 'vencimentos') $(`#row_vencimento_${id}`).remove(); else if (table == 'nfse_itens') $(`#${idLine}`).remove(); }, 300); }); } } }); } function removeItensDoFaturamento(id, id_usuario) { // pega todos os processos _GET('App/Controller/Query/get.controller.php', { table_name: 'faturamento_itens', condition: `AND id_faturamento = ${id}` }) .done(data => { const itens = JSON.parse(data); itens.forEach((item, key) => { let form = ""; form += `
`; form += ``; form += ``; form += ``; form += "
"; $('body').append(form); _EXEC(`formItensFaturamento-${key}`, null, false) .done(data => { $(`#formItensFaturamento-${key}`).remove(); }) }); }) } function removeContasReceber(id, id_usuario) { // pega todos os processos _GET('App/Controller/Query/get.controller.php', { table_name: 'contas_receber', condition: `AND id_faturamento = ${id} AND data_pagamento IS NULL;` }) .done(data => { const obj = JSON.parse(data); obj.forEach((item, key) => { let form = ""; form += `
`; form += ``; form += ``; form += ``; form += "
"; $('body').append(form); _EXEC(`formContasReceber-${key}`, null, false) .done(data => { $(`#formContasReceber-${key}`).remove(); }) }); }) } // function removeNFSe(id, id_usuario) { // // pega todos os processos // _GET('App/Controller/Query/get.controller.php', { // table_name: 'nfse', // condition: `AND id_faturamento = ${id}` // }) // .done(data => { // const obj = JSON.parse(data); // obj.forEach((item, key) => { // let form = ""; // form += `
`; // form += ``; // form += ``; // form += ``; // form += "
"; // $('body').append(form); // _EXEC(`formNFSe-${key}`, null, false) // .done(data => { // $(`#formNFSe-${key}`).remove(); // }) // }); // }) // } function removeItensDoContrato(id, id_usuario) { // pega todos os processos _GET('App/Controller/Query/get.controller.php', { table_name: 'contrato_itens', condition: `AND id_contrato = ${id}` }) .done(data => { const itens = JSON.parse(data); itens.forEach((item, key) => { let form = ""; form += `
`; form += ``; form += ``; form += ``; form += "
"; $('body').append(form); _EXEC(`formItensContrato-${key}`, null, false) .done(data => { $(`#formItensContrato-${key}`).remove(); }) }); }) } function LimpaForm(aForm) { if (aForm == '') aForm = 'ajax_form'; $('#' + aForm).each(function () { this.reset(); }); } /**VALIDA SE É UM CPF/CNPJ VÁLIDO */ function validaCpfCnpj(val) { if (val.length == 11) { 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; } } else if (val.length == 14) { 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; } } else { return false; } } //para usar a closeFunction crie uma função e mande o nome dela; //para usar a aModalCustomWidth basta passar o valor que deseja (é porcentagem), ou seja 75% => 75 (inteiro) como parâmetro da função PageModal; // Caso queira adicionar um botão de "+" na modal no lugar no close (x), basta passar o parâmetro hasAddButton como true e informar a função a ser executada pelo addFunction function PageModal(aURL, aTitle, aModalLarger = true, closeFunction = null, aModalCustomWidth = null, paddingInterno = true, overflowHidden = true, hasAddButton = false, addFunction = null, btnNovoCadastroModal = 'btnNovoCadastroModal', bgColorHeader = null) { $('body').append('
'); let response = false; let md = ''; let randID = `aBodyPageModal_${Math.floor(Math.random() * 9999) + 1}`; $.ajax({ url: aURL, cache: false, async: false, success: function (data) { const key = (Math.random() + 1).toString(36).substring(2); md += `