336 lines
8.3 KiB
JavaScript
336 lines
8.3 KiB
JavaScript
$("#formDivisionCIIU").EnableValidationToolTip();
|
|
var DataCatalogo;
|
|
var id_column = 1;
|
|
var Item = {};
|
|
var IdSeccionCIIU = getUrlParameter('IdSeccionCIIU');
|
|
var IdDiv;
|
|
|
|
|
|
jQuery(document).ready(function () {
|
|
$('#txtDescripcionDivisionCIIU').attr('size', 50);
|
|
|
|
|
|
GetControlsSettings("Cathay_DivisionCIIU", "Cathay_DivisionCIIU", "formDivisionCIIU");
|
|
|
|
$('#btnGuardarDivisionCIIU').hide();
|
|
$('#btnInsertarDivisionCIIU').show();
|
|
|
|
obtenerItems();
|
|
|
|
$('#btnLimpiarDivisionCIIU').click(function () {
|
|
limpiar();
|
|
|
|
$('#btnGuardarDivisionCIIU').hide();
|
|
$('#btnInsertarDivisionCIIU').show();
|
|
});
|
|
|
|
$('#btnGuardarDivisionCIIU').click(function () {
|
|
ActualizarItem();
|
|
});
|
|
|
|
$('#btnInsertarDivisionCIIU').click(function () {
|
|
InsertarItem();
|
|
});
|
|
});
|
|
|
|
this.obtenerItems = function () {
|
|
|
|
Item =
|
|
{
|
|
IdSeccionCIIU: IdSeccionCIIU,
|
|
}
|
|
|
|
var uri = 'api/DivisionCIIUAPI/ObtenerItems?IDSeccionCIIU=' + (IdSeccionCIIU);
|
|
|
|
|
|
$.getJSON(server + uri).done(function (data) {
|
|
|
|
|
|
var TableItems = $('#TableItems').DataTable();
|
|
$('#TableItems').TableInit(0, false, true, true, false, null, null);
|
|
|
|
$.each(data, function (key, item) {
|
|
|
|
var option = $("#ucItemsCatalogo").html();
|
|
|
|
option = replaceAll("[$CodItem]", item.IdDivisionCIIU, option);
|
|
option = replaceAll("[$CodSeccion]", item.IdSeccionCIIU, option);
|
|
|
|
var stateIcon = $("#ucItemsIcon").html();
|
|
|
|
if (item.Estado == false) {
|
|
stateIcon = replaceAll("[$icon]", "fa-check-circle", stateIcon);
|
|
stateIcon = replaceAll("[$state_color]", "muted", stateIcon);
|
|
|
|
option = replaceAll("[$opcion]", "Habilitar", option);
|
|
option = replaceAll("[$icon]", "fa-check", option);
|
|
option = replaceAll("[$value]", "1", option);
|
|
}
|
|
else {
|
|
stateIcon = replaceAll("[$icon]", "fa-check-circle", stateIcon);
|
|
stateIcon = replaceAll("[$state_color]", "success", stateIcon);
|
|
|
|
option = replaceAll("[$opcion]", "Deshabilitar", option);
|
|
option = replaceAll("[$icon]", "fa-times", option);
|
|
option = replaceAll("[$value]", "0", option);
|
|
}
|
|
|
|
TableItems.row.add([stateIcon, item.IdDivisionCIIU, item.IdSeccionCIIU, item.Descripcion, option]).draw();
|
|
|
|
});
|
|
|
|
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo mas tarde");
|
|
|
|
}).then(function (value) {
|
|
|
|
ENDREQUEST();
|
|
});
|
|
|
|
}
|
|
|
|
this.EditarItem = function (id) {
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
limpiar();
|
|
var indexes = getRowIndex(TableItems, id_column, id);
|
|
|
|
|
|
if (indexes != null) {
|
|
|
|
$('#hiddenId').val(id)
|
|
IdDiv = id
|
|
$('#txtCodigoDivisionCIIU').val(id);
|
|
$('#txtDescripcionDivisionCIIU').val(TableItems.cell(indexes, 3).data());
|
|
|
|
$("#formDivisionCIIU").validateElement("#txtDescripcionDivisionCIIU");
|
|
|
|
$('#lbTituloAccion').empty();
|
|
$('#lbTituloAccion').append('Editar Valor de Campo ID: ' + id);
|
|
|
|
$('#lblCodigoDivisionCIIU').hide();
|
|
$('#txtCodigoDivisionCIIU').hide();
|
|
|
|
$('#btnInsertarDivisionCIIU').hide();
|
|
$('#btnGuardarDivisionCIIU').show();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
this.toggleEnabledItem = function (id, value) {
|
|
|
|
var msg = 'Está seguro que desea habilitar el SUGEF Resumen?';
|
|
|
|
if (value == 0) {
|
|
msg = 'Está seguro que desea deshabilitar el SUGEF Resumen?';
|
|
}
|
|
|
|
if (id == null || value == null) {
|
|
toastr.warning("No se pudo obtener el ID de el SUGEF Resumen seleccionado.");
|
|
return;
|
|
}
|
|
|
|
if (!confirm(msg))
|
|
{ return; }
|
|
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
|
|
|
|
Item = {
|
|
IdDivisionCIIU: id,
|
|
IdSeccionCIIU: IdSeccionCIIU,
|
|
Estado: value,
|
|
UsuarioModificado: $("#hiddenUserID").val()
|
|
|
|
}
|
|
|
|
var uri = 'api/DivisionCIIUAPI/toggleStateItem/';
|
|
var DTO = JSON.stringify(Item);
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: server + uri,
|
|
cache: false,
|
|
data: DTO,
|
|
contentType: 'application/json; charset=utf-8',
|
|
dataType: 'json',
|
|
success: function (data) {
|
|
|
|
|
|
|
|
if (data == "EXITOSO") {
|
|
toastr.info('Información actualizada con exito', 'Completado');
|
|
limpiar();
|
|
|
|
$('#btnGuardarDivisionCIIU').hide();
|
|
$('#btnInsertarDivisionCIIU').show();
|
|
|
|
TableItems.clear().draw();
|
|
obtenerItems();
|
|
|
|
}
|
|
else {
|
|
toastr.error("Ha ocurrido un error.");
|
|
}
|
|
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo.");
|
|
|
|
}).then(function (value) {
|
|
|
|
ENDREQUEST();
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
this.ActualizarItem = function () {
|
|
|
|
if (!$("#formDivisionCIIU").valid()) {
|
|
toastr.warning("Ingresar todos los campos que son requeridos.");
|
|
return false;
|
|
}
|
|
|
|
if (!confirm("Se guardarán los cambios.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
|
|
Item = {
|
|
IdDivisionCIIU: IdDiv,
|
|
IdSeccionCIIU: IdSeccionCIIU,
|
|
Descripcion: $('#txtDescripcionDivisionCIIU').val(),
|
|
UsuarioModificado: $("#hiddenUserID").val()
|
|
|
|
}
|
|
|
|
var uri = 'api/DivisionCIIUAPI/ModificarItem/';
|
|
var DTO = JSON.stringify(Item);
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: server + uri,
|
|
cache: false,
|
|
data: DTO,
|
|
contentType: 'application/json; charset=utf-8',
|
|
dataType: 'json',
|
|
success: function (data) {
|
|
|
|
|
|
|
|
if (data == "EXITOSO") {
|
|
toastr.info('Información guardada con exito', 'Completado');
|
|
limpiar();
|
|
|
|
$('#btnGuardarDivisionCIIU').hide();
|
|
$('#btnInsertarDivisionCIIU').show();
|
|
|
|
$('#lbTituloAccion').empty();
|
|
$('#lbTituloAccion').append('Ingresar Nuev SUGEF Resumen');
|
|
|
|
TableItems.clear().draw();
|
|
obtenerItems();
|
|
|
|
}
|
|
else {
|
|
toastr.error("Ha ocurrido un error.");
|
|
}
|
|
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo.");
|
|
|
|
}).then(function (value) {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
this.InsertarItem = function () {
|
|
|
|
|
|
if (!$("#formDivisionCIIU").valid()) {
|
|
toastr.warning("Ingresar todos los campos que son requeridos.");
|
|
return false;
|
|
}
|
|
|
|
if (!confirm("Va a ingresar una nuevo SUGEF Resumen.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
|
|
|
|
DivisionCIIU = {
|
|
IdDivisionCIIU: $('#txtCodigoDivisionCIIU').val(),
|
|
IdSeccionCIIU: IdSeccionCIIU,
|
|
Descripcion: $('#txtDescripcionDivisionCIIU').val(),
|
|
UsuarioCreador: $("#hiddenUserID").val()
|
|
|
|
}
|
|
|
|
var uri = 'api/DivisionCIIUAPI/InsertarItem/';
|
|
var DTO = JSON.stringify(DivisionCIIU);
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: server + uri,
|
|
cache: false,
|
|
data: DTO,
|
|
contentType: 'application/json; charset=utf-8',
|
|
dataType: 'json',
|
|
success: function (data) {
|
|
|
|
|
|
|
|
if (data == "EXITOSO") {
|
|
toastr.info('Información guardada con exito', 'Completado');
|
|
limpiar();
|
|
$('#btnGuardarDivisionCIIU').hide();
|
|
$('#btnInsertarDivisionCIIU').show();
|
|
|
|
TableItems.clear().draw();
|
|
obtenerItems();
|
|
|
|
}
|
|
else {
|
|
toastr.error("Ha ocurrido un error.");
|
|
}
|
|
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo.");
|
|
|
|
}).then(function (value) {
|
|
|
|
});
|
|
}
|
|
|
|
this.limpiar = function () {
|
|
$('#lbTituloAccion').empty();
|
|
$('#lbTituloAccion').append('Ingresar Nuevo SUGEF Resumen');
|
|
$('#lblCodigoDivisionCIIU').show();
|
|
|
|
$('#txtCodigoDivisionCIIU').val('');
|
|
$('#txtCodigoDivisionCIIU').show();
|
|
|
|
$('#txtDescripcionDivisionCIIU').val('');
|
|
$("#formDivisionCIIU").validateElement("#txtDescripcionDivisionCIIU");
|
|
$("#formDivisionCIIU").validateElement("#txtCodigoDivisionCIIU");
|
|
|
|
}
|