/* */ let AMBIENTE_PRODUCAO = true; class Engine { constructor () { this.comunicar = async (classe, acao, dados)=>{ // Default options are marked with * console.log("Engine.comunicar"); console.log(classe); console.log(acao); console.log(dados); let _dados = dados || {}; _dados.SID = sessionStorage.SID || null; let url = (AMBIENTE_PRODUCAO?"/ws/":"/ws_dev/") + classe + "/" + acao; const response = await fetch(url, { method: 'POST', // *GET, POST, PUT, DELETE, etc. mode: 'cors', // no-cors, *cors, same-origin cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached credentials: 'same-origin', // include, *same-origin, omit headers: { Accept: "application/json", "Content-Type": "application/json; charset=UTF-8", // 'Content-Type': 'application/x-www-form-urlencoded', }, redirect: 'follow', // manual, *follow, error referrerPolicy: 'no-referrer', // no-referrer, *client body: JSON.stringify(_dados) // body data type must match "Content-Type" header }); let resultado = await response.text(); // parses JSON response into native JavaScript objects console.log(resultado); return JSON.parse(resultado); } this.iniciar = async (token, doc)=>{ let dados = {} if ((token || null) != null) dados.TOKEN = token; if ((doc || null) != null) dados.DOC = doc; let resultado = await engine.comunicar("login", "iniciar", dados) return resultado } this.validar = async (dados, sucesso, falha)=>{ this.exibeAguarde(); let resultado = await this.comunicar("login", "validar", dados) this.ocultaAguarde(); if (resultado.ERRO == 0) { sessionStorage.setItem("SID", resultado.SID); sessionStorage.setItem("DADOS", JSON.stringify(resultado)); if (sucesso || null) sucesso(resultado); } else { if (falha || null) falha(resultado); } return resultado; }; this.logout = async ()=>{ let resultado = await this.comunicar("login", "logout", null); if (resultado.ERRO == 0) { sessionStorage.clear(); window.location.href = "index.html"; } return resultado; }; this.debitos = async ()=>{ this.exibeAguarde(); let resultado = await this.comunicar("debitos", "listar", null); this.ocultaAguarde(); return resultado; } this.informar_nao_reconhece = async (telefone, msg)=>{ this.exibeAguarde() let resultado = await this.comunicar("debitos", "nao_reconheco", {TELEFONE: telefone, MSG: msg }) this.ocultaAguarde() return resultado } this.pagar_cartao = async (dados)=>{ this.exibeAguarde() let resultado = await this.comunicar("pagamento", "cartao", {DADOS_CARTAO: dados}) this.ocultaAguarde() return resultado } this.gerar_boleto = async (n_parcelas, valor, forma_aviso, valor_aviso)=>{ this.exibeAguarde() let resultado = await this.comunicar("pagamento", "boleto", {QTD_PARCELAS : n_parcelas, VALOR: valor, FORMA_AVISO: forma_aviso, VALOR_AVISO: valor_aviso }) this.ocultaAguarde() return resultado } this.enviar_lead = async (telefone)=>{ this.exibeAguarde() let resultado = await this.comunicar("leads", "adicionar", {telefone}) this.ocultaAguarde() return resultado } this.dados_pix = async (txid)=>{ this.exibeAguarde() let resultado = await this.comunicar("pix", "ler", {txid}) this.ocultaAguarde() return resultado } this.exibeAguarde = ()=>{ var $aguarde = $("
").css({"background-color":"black", "position":"absolute", "opacity":"0.4", "left":"0px", "right":"0px", "top":"0px", "height":$("body").height() + "px", "z-index":2147483648 }).addClass("blockout"); var $gif = $("").attr("src","/img/loader.gif") .css({"position":"absolute", "top":$(document).scrollTop() + ($(window).height() / 2) + "px", "left": ($(window).width() / 2 - 16) + "px", "width":"32px", "height":"32px"}) .addClass("blockout"); $aguarde.append($gif); $("body").append($aguarde); this.$aguarde = $aguarde; } this.ocultaAguarde = ()=>{ if (!(this.$aguarde || null)) return; this.$aguarde.remove(); this.$aguarde = null; } //função de para fetch de um arquvo para o endpoint https://websocket.romancemoda.com.br/RMC_PB/v2/recibos/enviar ultilizando como parametro o arquivo e o cpf this.enviar_recibo = async (arquivo, cpf)=>{ let formData = new FormData(); formData.append("file", arquivo); formData.append("documento", cpf); let resultado = await fetch(`https://websocket.romancemoda.com.br/RMC_PB${AMBIENTE_PRODUCAO ? "" : "_HMG"}/v2/recibos/enviar`, { method: "POST", body: formData }); return resultado; } } } let engine = new Engine(); Number.prototype.formatMoney = function(c, d, t){ var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "." : d, t = t == undefined ? "," : t, s = n < 0 ? "-" : "", i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c))), j = (j = i.length) > 3 ? j % 3 : 0; return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); }; Number.prototype.formataReal = function(){ return "R$" + this.formatMoney(2, ",", "."); }; let nomeVendedora = ()=>{ let dadosStr = sessionStorage.DADOS || '{NOME: "--"}' let dados = JSON.parse(dadosStr) return dados.NOME } let primeiroNomeVendedora = ()=>{ let nome = nomeVendedora() return nome.split(" ")[0] }