var showMessage = function (msg) { $("#msg-id").removeClass("d-none"); $("#msg-text").text(msg); } var hiddenMessage = function () { $("#msg-id").addClass("d-none"); $("#msg-text").text(""); } var validInfo = function (tag) { var patron; hiddenMessage(); if (tag.getAttribute("data-type") == "number") { patron = /^[0-9]+$/; } if (tag.getAttribute("data-type") == "rfc") { patron = new RegExp("^[A-Z,Ñ,&]{3,4}[0-9]{2}[0-1][0-9][0-3][0-9][A-Z,0-9][A-Z,0-9][0-9,A-Z]$"); } if (tag.getAttribute("data-type") == "email") { patron = new RegExp("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$"); } if (tag.getAttribute("data-type") == "alfanumerico") { patron = new RegExp("^[a-zA-Z0-9]+$"); } if (tag.getAttribute("data-type") == "alfaConGuion") { patron = new RegExp("^[a-zA-Z]+(?:-[0-9]+$"); } if (tag.getAttribute("data-type") == "password") { patron = new RegExp("^[a-zA-Z0-9]+$"); if ($(tag).val().length < 8 || $(tag).val().length > 10) { $(tag).addClass("error"); showMessage("El tamaño de la contraseña debe ser compuesto con letras y numeros entre 8 y 10 caracteres"); } } $(tag).removeClass("error"); if (!$(tag).val().match(patron)) { $(tag).addClass("error"); showMessage("Error en " + $(tag).attr("data-label")); return false; } else { return true; } } var onChanged = function () { $("#frmDeclaracion").attr('action', "goCalcular"); var params = $("#registroEstatal").val() + "/" + parseInt($("#idTipoIngreso").val()) + "/" + $("#ejercicio").val() + "/" + $("#tipoDeclaracion").val(); $("#params").val(params); $("#frmDeclaracion").submit(); } var getBancos = function () { try { var strJson = $("#bancosList").html(); return JSON.parse(strJson); } catch (error) { } }; var getPeriodos = function () { try { var strJson = $("#periodosList").html(); return JSON.parse(strJson); } catch (error) { } }; var goTo = function (page) { window.location = "./" + page; } var back = function () { history.back(); } var goPagar = function (e) { $("#idBanco").val(e.getAttribute("data-idbanco")); $("#idServicio").val(e.getAttribute("data-idservicio")); $("#formatoPago").val(e.getAttribute("data-idbanco") < "-1"); $("#accion").val("pagar"); $('#frmDeclaracion').attr('action', '/impuestos/goPagar'); $('#frmDeclaracion').submit(); } var clearForm = function () { $('#baseGravada').val("0"); $('#baseExcenta').val("0"); $('#impuestoRetenido').val("0"); $('#impuestoRecaudado').val("0"); $('#saldoAplicado').val("0"); $('#extra').val("0"); } var disabled = function (tag) { $("#" + tag).prop('disabled', true); } var enabled = function (tag) { $("#" + tag).prop('disabled', false); } $(document).ready(function () { $("input[type=submit]").click(function () { if ($(".error").length > 0) { showMessage("Favor de corregir los errores"); return false; } }); $("input").keyup(function () { return validInfo(this); }); $("#rfc").keyup(function () { $("#rfc").val($("#rfc").val().toUpperCase()); }); $("#total").click(function () { deleteDeclaracion(0); }) $("input[name=pagar]").click(function () { var total = 0; $("input:checkbox[name=pagar]:checked").each(function () { total += $(this).attr('data-subtotal') * 1; }); $("#granTotal").val(total); setTotalPagar(total); }); $(".custom-file-input").on("change", function () { var fileName = $(this).val().split("\\").pop(); $(".custom-file-label").html(fileName); }); $("#lkRegistrarUsuario").click(function () { window.location = "./registrarUsuario"; }) $("#lkRecuperarPassword").click(function () { window.location = "./recuperarPassword"; }) $("#lkRestablecerUsuario").click(function () { window.location = "./restablecerUsuario"; }) $("#btnRegresar").click(function () { window.history.back(); }) }); var app = angular.module('impuestos', []); app.config(['$qProvider', function ($qProvider) { $qProvider.errorOnUnhandledRejections(false); }]); app.controller('myCtrl', function ($scope, $http) { $scope.url_ws = $("#url_ws").val(); $scope.url_base = $("#url_base").val(); $scope.idTipoIngreso = $("#idTipoIngreso").val(); $scope.declaraciones = []; $scope.idx = -9; $scope.tipoContribuyente = "X"; $scope.bancosList = getBancos(); $scope.periodosList = getPeriodos(); $scope.tipoContribuyente = $scope.periodosList[1].esRetenedor === 'S' ? 'RTNDR' : $scope.periodosList[1].esRecaudador === 'S' ? 'RCDDR' : 'NORMAL'; $("#tipoContribuyente").val($scope.tipoContribuyente); $scope.tipoFormaPago=" "; let bancos=$scope.bancosList; let distinct = (bancos) => { let unique_values = bancos .map((bco) => bco.javaclassspel) .filter( (value, index, current_value) => current_value.indexOf(value) === index ); return unique_values; }; $scope.formasPago=distinct(bancos); console.log($scope.bancosList); $scope.getData = function (ws) { var url_ws = $("#url_base").val(); switch (ws) { case "guardarUsuario": url_ws += "/usuario/IMPUESTOS/registrar/" + $("#registroEstatal").val() + "/" + $("#rfc").val() + "/" + $("#correoElectronico").val() + "/" + $("#password").val(); // console.log("controller: " + url_ws); $http.get(url_ws).then(function (rs) { }); break; case "getPeriodos": url_ws += "/declaracion/IMPUESTOS/estatus/" + $("#registroEstatal").val() + "/" + parseInt($("#idTipoIngreso").val()) + "/" + $("#ejercicio").val() + "/" + $("#tipoDeclaracion").val(); // console.log("controller: " + url_ws); try { $http.get(url_ws) .then(function (rs) { $scope.periodos = rs.data.data; if ($scope.periodos.length == 0) { $("#msg-id").removeClass("d-none"); $("#msg-text").text(rs.data.mensaje); } else { $("#msg-id").addClass("d-none"); $scope.tipoContribuyente = $scope.periodos[1].esRetenedor == 'S' ? 'R' : $scope.periodos[1].esRetenido == 'S' ? 'P' : 'X'; } }) .error(function () { }); } catch (err) { // $("#msg-id").removeClass("d-none"); // $("#msg-text").text("Se presentó un problema inesperado (1)"); return false; } break; case "agregarDeclaracion": if ($(".error").length > 0) { showMessage("Favor de corregir los errores"); return false; } if ($("#archivo").text().length > 0) { var data = $("#archivo").text().replaceAll("\n", "R").replaceAll("|", "C"); url_ws += "/impuestos/rest/IMPUESTOS/calculaDeclaracion/" + $("#registroEstatal").val() + "/" + parseInt($("#idTipoIngreso").val()) + "/" + $scope.tipoContribuyente + "/" + $("#tipoDeclaracion").val() + "/" + $("#ejercicio").val() + "/" + $("#periodo").val(); $http.post(url_ws, data) .then(function (rs) { enabled("btnAgregar"); if (rs.data.estatus.toUpperCase() == "ERROR") { $("#msg-id").removeClass("d-none"); $("#msg-text").text(rs.data.mensaje); return false; } $scope.declaracion = rs.data.data; $scope.declaraciones.push(rs.data.data); }); return false; } else { // if ($("#archivo").text().length > 0) { // url_ws += "/impuestos/rest/IMPUESTOS/calculaDeclaracion/" + // $("#registroEstatal").val() + "/" + // parseInt($("#idTipoIngreso").val()) + "/" + // $scope.tipoContribuyente + "/" + // $("#tipoDeclaracion").val() + "/" + // $("#ejercicio").val() + "/" + // $("#periodo").val() + "/" + // $("#archivo").text().replaceAll("\n","R").replaceAll("|","C"); // } else { baseExcenta = $("#baseExcenta").val() == undefined ? 0 : $("#baseExcenta").val(); extra = $("#extra").val() == undefined ? 0 : $("#extra").val(); impuestoRetenido = $("#impuestoRetenido").val() == undefined ? 0 : $("#impuestoRetenido").val(); impuestoRecaudado = $("#impuestoRecaudado").val() == undefined ? 0 : $("#impuestoRecaudado").val(); url_ws += "/impuestos/rest/IMPUESTOS/calculaDeclaracion/" + $("#registroEstatal").val() + "/" + parseInt($("#idTipoIngreso").val()) + "/" + $scope.tipoContribuyente + "/" + $("#tipoDeclaracion").val() + "/" + $("#ejercicio").val() + "/" + $("#periodo").val() + "/" + $("#baseGravada").val() + "/" + baseExcenta + "/" + impuestoRetenido + "/" + impuestoRecaudado + "/" + $("#saldoAplicado").val() + "/" + extra; } $http.get(url_ws) .then(function (rs) { enabled("btnAgregar"); if (rs.data.estatus.toUpperCase() == "ERROR") { $("#msg-id").removeClass("d-none"); $("#msg-text").text(rs.data.mensaje); return false; } $scope.declaracion = rs.data.data; $scope.declaraciones.push(rs.data.data); }); break; } } $scope.getTotal = function () { var total = 0; for (var i = 0; i < $scope.declaraciones.length; i++) { var declaracion = $scope.declaraciones[i]; for (var j = 0; j < declaracion.conceptos.length; j++) { var concepto = declaracion.conceptos[j]; total += (concepto.total); } } return total; } $scope.deleteDeclaracion = function (id) { $scope.declaraciones.splice(id, 1); } //--- Carga periodos --- //$scope.getData("getPeriodos"); $scope.guardarUsuario = function () { $scope.getData("guardarUsuario"); } $scope.addDeclaracion = function () { if (!($("#ejercicio").val() > 0)) { $("#msg-id").removeClass("d-none"); $("#msg-text").text("Seleccione un ejercicio"); return false; } if ($scope.existDeclaracion($("#ejercicio").val(), $("#periodo").val())) { $("#msg-id").removeClass("d-none"); $("#msg-text").text("El periodo ya existe en declaraciones"); return false; } $("#msg-id").addClass("d-none"); disabled("btnAgregar"); $scope.getData("agregarDeclaracion"); } $scope.presentarDeclaraciones = function (idBanco) { $("#declaracionList").val(JSON.stringify($scope.declaraciones)); $("#frmDeclaracion").attr("action", "presentarDeclaraciones"); $("#frmDeclaracion").attr("target", "_blank"); $("#idBanco").val(idBanco); $("#frmDeclaracion").submit(); $scope.getData("getPeriodos"); $scope.declaraciones = []; $('#mdlFormaPago').modal("hide"); clearForm(); } $scope.changeParametros = function () { if ($("#ejercicio").val() > 0) { $scope.getData("getPeriodos"); } } $scope.changePeriodo = function () { } $scope.getDeclaracion = function () { } $scope.goOrigen = function () { window.history.back(); }; $scope.existDeclaracion = function (year, month) { for (var i = 0; i < $scope.declaraciones.length; i++) { var d = $scope.declaraciones[i]; if (d.ejercicio == year && d.periodo == month) { return true; } } return false; } $scope.selectedType =function(id){ $scope.tipoFormaPago=$scope.formasPago[id]; } try { document.getElementById('file').addEventListener('change', handleFileSelect, false); } catch (e) { } function handleFileSelect(event) { const reader = new FileReader() reader.onload = handleFileLoad; reader.readAsText(event.target.files[0]) } function handleFileLoad(event) { document.getElementById('archivo').textContent = event.target.result; } if ($("#idTipoIngreso").val() == "54" && $("#tipoContribuyente").val() == "RTNDR") { console.log($scope.tipoContribuyente + " " + $scope.idTipoIngreso); $("#dvArchivo").removeClass("d-none"); $("#baseGravada").addClass("d-none"); } if ($("#frmDeclaracion").val() != undefined && $("#idTipoIngreso").val() == "86") { $("#mdlAviso").modal("show"); } });