544 lines
18 KiB
JavaScript
544 lines
18 KiB
JavaScript
$("#formCatalogo").EnableValidationToolTip();
|
|
var DataCatalogo;
|
|
var id_columnCodigoComite = 0;
|
|
var id_comlumIdEstructuraOrgChart = 1;
|
|
var CatalogoItem = {};
|
|
|
|
var LllavesCompuestas = [];
|
|
|
|
var codComite = 0;
|
|
var codEstructura = 0;
|
|
|
|
|
|
//#region READY
|
|
|
|
jQuery(document).ready(function () {
|
|
|
|
GetControlsSettings("Cathay_MiembrosComiteCredito", "Cathay_MiembrosComiteCredito", "formCatalogo");
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
|
|
obtenerItems();
|
|
|
|
$('#btnLimpiar').click(function () {
|
|
limpiar();
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
});
|
|
|
|
$('#btnGuardar').click(function () {
|
|
ActualizarItem();
|
|
});
|
|
|
|
$('#btnInsertar').click(function () {
|
|
LeerExistente();
|
|
});
|
|
|
|
|
|
$('#chkEsVoto').change(function () {
|
|
toggleOnChangeVotoPositivoActivaRegClienteSAP();
|
|
toggleOnChangeVotoPositivoActivaValidarCondicionesCliente();
|
|
});
|
|
|
|
});
|
|
|
|
//#endregion
|
|
|
|
this.toggleOnChangeVotoPositivoActivaRegClienteSAP = function () {
|
|
|
|
if ($('#chkEsVoto').is(":checked")) {
|
|
$('#chkVotoPositivoActivaRegClienteSAP').enable();
|
|
}
|
|
else {
|
|
$('#chkVotoPositivoActivaRegClienteSAP').disable();
|
|
$('#chkVotoPositivoActivaRegClienteSAP').prop("checked", false);
|
|
}
|
|
}
|
|
|
|
|
|
this.toggleOnChangeVotoPositivoActivaValidarCondicionesCliente = function () {
|
|
|
|
if ($('#chkEsVoto').is(":checked")) {
|
|
$('#chkVotoPositivoActivaValidarCondicionesCliente').enable();
|
|
}
|
|
else {
|
|
$('#chkVotoPositivoActivaValidarCondicionesCliente').disable();
|
|
$('#chkVotoPositivoActivaValidarCondicionesCliente').prop("checked", false);
|
|
}
|
|
}
|
|
|
|
this.toggleOnChangeVotoPositivoActivaExcepciones = function () {
|
|
|
|
if ($('#chkEsVoto').is(":checked")) {
|
|
$('#chkVotoPositivoActivaExcepciones').enable();
|
|
}
|
|
else {
|
|
$('#chkVotoPositivoActivaExcepciones').disable();
|
|
$('#chkVotoPositivoActivaExcepciones').prop("checked", false);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
this.obtenerItems = function () {
|
|
|
|
var uri = 'api/MiembrosComiteCreditoAPI/ObtenerItems/';
|
|
|
|
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: server + uri,
|
|
cache: false,
|
|
contentType: 'application/json; charset=utf-8',
|
|
dataType: 'json',
|
|
async: true,
|
|
success: function (data) {
|
|
CatalogoItem = data;
|
|
$('#TableItems').TableInit(0, false, true, true, false, null, null);
|
|
var TableItems = $('#TableItems').DataTable();
|
|
$.each(data, function (key, item) {
|
|
|
|
LllavesCompuestas.push({
|
|
comite: item.CodigoComite,
|
|
estructorg: item.IdEstructuraOrgChart,
|
|
});
|
|
|
|
|
|
var option = $("#ucItemsCatalogo").html();
|
|
var esvoto = $("#ucIEsVoto").html();
|
|
var esVotoPositivoActivaRegClienteSAP = $("#ucIEsVotoPositivoActivaRegClienteSAP").html();
|
|
var esVotoPositivoActivaValidarCondicionesCliente = $("#ucIEsVotoPositivoActivaValidarCondicionesCliente").html();
|
|
var EsVotoPositivoActivaExcepciones = $("#ucIEsVotoPositivoActivaExcepciones").html();
|
|
|
|
|
|
option = replaceAll("[$CodItem]", item.CodigoComite, option); //prueba
|
|
|
|
option = replaceAll("[$CodigoComite]", item.CodigoComite, option);
|
|
option = replaceAll("[$CodEstructuraOrgChart]", item.IdEstructuraOrgChart, option);
|
|
|
|
var stateIcon = $("#ucItemsIcon").html();
|
|
|
|
if (item.EsVoto == true)
|
|
{
|
|
esvoto = replaceAll("[$icon]", "fa-check-circle", esvoto);
|
|
esvoto = replaceAll("[$state_color]", "success", esvoto);
|
|
option = replaceAll("[$valueEsVoto]", "1", option);
|
|
}
|
|
else
|
|
{
|
|
esvoto = replaceAll("[$icon]", "fa-check-circle", esvoto);
|
|
esvoto = replaceAll("[$state_color]", "muted", esvoto);
|
|
option = replaceAll("[$valueEsVoto]", "0", option);
|
|
}
|
|
|
|
|
|
if (item.VotoPositivoActivaRegClienteSAP == true)
|
|
{
|
|
esVotoPositivoActivaRegClienteSAP = replaceAll("[$icon]", "fa-check-circle", esVotoPositivoActivaRegClienteSAP);
|
|
esVotoPositivoActivaRegClienteSAP = replaceAll("[$state_color]", "success", esVotoPositivoActivaRegClienteSAP);
|
|
option = replaceAll("[$valueEsVotoPositivoActivaRegClienteSAP]", "1", option);
|
|
}
|
|
else
|
|
{
|
|
esVotoPositivoActivaRegClienteSAP = replaceAll("[$icon]", "fa-check-circle", esVotoPositivoActivaRegClienteSAP);
|
|
esVotoPositivoActivaRegClienteSAP = replaceAll("[$state_color]", "muted", esVotoPositivoActivaRegClienteSAP);
|
|
option = replaceAll("[$valueEsVotoPositivoActivaRegClienteSAP]", "0", option);
|
|
}
|
|
|
|
|
|
|
|
if (item.VotoPositivoActivaExcepciones == true)
|
|
{
|
|
EsVotoPositivoActivaExcepciones = replaceAll("[$icon]", "fa-check-circle", EsVotoPositivoActivaExcepciones);
|
|
EsVotoPositivoActivaExcepciones = replaceAll("[$state_color]", "success", EsVotoPositivoActivaExcepciones);
|
|
option = replaceAll("[$valueEsVotoPositivoActivaExcepciones]", "1", option);
|
|
|
|
} else {
|
|
EsVotoPositivoActivaExcepciones = replaceAll("[$icon]", "fa-check-circle", EsVotoPositivoActivaExcepciones);
|
|
EsVotoPositivoActivaExcepciones = replaceAll("[$state_color]", "muted", EsVotoPositivoActivaExcepciones);
|
|
option = replaceAll("[$valueEsVotoPositivoActivaExcepciones]", "0", option);
|
|
}
|
|
|
|
|
|
if (item.VotoPositivoActivaValidarCondicionesCliente == true) {
|
|
esVotoPositivoActivaValidarCondicionesCliente = replaceAll("[$icon]", "fa-check-circle", esVotoPositivoActivaValidarCondicionesCliente);
|
|
esVotoPositivoActivaValidarCondicionesCliente = replaceAll("[$state_color]", "success", esVotoPositivoActivaValidarCondicionesCliente);
|
|
option = replaceAll("[$valueEsVotoPositivoActivaValidarCondicionesCliente]", "1", option);
|
|
}
|
|
else {
|
|
esVotoPositivoActivaValidarCondicionesCliente = replaceAll("[$icon]", "fa-check-circle", esVotoPositivoActivaValidarCondicionesCliente);
|
|
esVotoPositivoActivaValidarCondicionesCliente = replaceAll("[$state_color]", "muted", esVotoPositivoActivaValidarCondicionesCliente);
|
|
option = replaceAll("[$valueEsVotoPositivoActivaValidarCondicionesCliente]", "0", option);
|
|
}
|
|
|
|
|
|
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.ComiteCredito.NombreComite, item.EstructuraOrgChart.Name, item.Orden, esvoto, esVotoPositivoActivaRegClienteSAP, esVotoPositivoActivaValidarCondicionesCliente, EsVotoPositivoActivaExcepciones, option]).draw();
|
|
|
|
});
|
|
|
|
ENDREQUEST();
|
|
}
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
if (typeof AjaxFailEvent !== 'undefined' && $.isFunction(AjaxFailEvent) && !AjaxFailEvent(jqxhr, textStatus, error))
|
|
return;
|
|
toastr.error("Ha ocurrido un error inesperado. Vuelva a intentarlo mas tarde", Message_Error);
|
|
HabilitarMenu();
|
|
ENDREQUEST();
|
|
|
|
}).then(function (value) {
|
|
ENDREQUEST();
|
|
});
|
|
}
|
|
|
|
|
|
this.EditarItem = function (CodigoComite, CodEstructuraOrgChart, esvoto) {
|
|
|
|
var esVotoPositivoActivaRegClienteSAP = false;
|
|
var esVotoPositivoActivaValidarCondicionesCliente = false;
|
|
var esVotoPositivoActivaExcepciones = false;
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
limpiar();
|
|
|
|
if (CatalogoItem != null) {
|
|
|
|
$('#hiddenComiteCredito').val(CodigoComite)
|
|
codComite = CodigoComite
|
|
|
|
$('#hiddenEstructuraOrgChart').val(CodEstructuraOrgChart)
|
|
codEstructura = CodEstructuraOrgChart
|
|
|
|
$.each(CatalogoItem, function (key, item) {
|
|
if (item.CodigoComite == CodigoComite && item.IdEstructuraOrgChart == CodEstructuraOrgChart) {
|
|
$('#txtComiteCredito').val(item.ComiteCredito.NombreComite);
|
|
$('#txtEstructuraOrgChart').val(item.EstructuraOrgChart.Name);
|
|
$('#txtOrden').val(item.Orden);
|
|
|
|
if (item.EsVoto != true) { esvoto = "0"; } else { esvoto = "1"; }
|
|
if (item.VotoPositivoActivaRegClienteSAP != true) { esVotoPositivoActivaRegClienteSAP = "0"; } else { esVotoPositivoActivaRegClienteSAP = "1"; }
|
|
if (item.VotoPositivoActivaValidarCondicionesCliente != true) { esVotoPositivoActivaValidarCondicionesCliente = "0"; } else { esVotoPositivoActivaValidarCondicionesCliente = "1"; }
|
|
if (item.VotoPositivoActivaExcepciones != true) { esVotoPositivoActivaExcepciones = "0"; } else { esVotoPositivoActivaExcepciones = "1"; }
|
|
}
|
|
});
|
|
|
|
if (esvoto == "1")
|
|
{
|
|
$("#chkEsVoto").prop("checked", true);
|
|
} else {
|
|
$("#chkEsVoto").prop("checked", false);
|
|
}
|
|
|
|
|
|
|
|
if (esVotoPositivoActivaRegClienteSAP == "1") {
|
|
$('#chkVotoPositivoActivaRegClienteSAP').prop("checked", true);
|
|
} else {
|
|
$('#chkVotoPositivoActivaRegClienteSAP').prop("checked", false);
|
|
}
|
|
|
|
|
|
if (esVotoPositivoActivaValidarCondicionesCliente == "1") {
|
|
$('#chkVotoPositivoActivaValidarCondicionesCliente').prop("checked", true);
|
|
} else {
|
|
$('#chkVotoPositivoActivaValidarCondicionesCliente').prop("checked", false);
|
|
}
|
|
|
|
if (esVotoPositivoActivaExcepciones == "1")
|
|
{
|
|
$('#chkVotoPositivoActivaExcepciones').prop("checked", true);
|
|
} else {
|
|
$('#chkVotoPositivoActivaExcepciones').prop("checked", false);
|
|
}
|
|
|
|
|
|
toggleOnChangeVotoPositivoActivaRegClienteSAP();
|
|
toggleOnChangeVotoPositivoActivaValidarCondicionesCliente();
|
|
toggleOnChangeVotoPositivoActivaExcepciones();
|
|
|
|
$("#formCatalogo").validateElement("#txtComiteCredito");
|
|
$("#formCatalogo").validateElement("#txtEstructuraOrgChart");
|
|
$("#formCatalogo").validateElement("#txtOrden");
|
|
|
|
$('#lbTituloAccion').empty();
|
|
$('#lbTituloAccion').append('Editar Valores de Miembro Comité Crédito');
|
|
|
|
$('#btnInsertar').hide();
|
|
$('#btnGuardar').show();
|
|
|
|
$('#btnComiteCredito').hide();
|
|
$('#btnEstructuraOrgChart').hide();
|
|
|
|
$('#btn_eliminarComiteCredito').hide();
|
|
$('#btn_eliminarEstructuraOrgChart').hide();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
this.toggleEnabledItem = function (CodigoComite, CodEstructuraOrgChart, value) {
|
|
|
|
var msg = 'Está seguro que desea habilitar el Miembro Comité Crédito?';
|
|
|
|
if (value == 0) {
|
|
msg = 'Está seguro que desea deshabilitar el Miembro Comité Crédito?';
|
|
}
|
|
|
|
if (CodigoComite == null && CodEstructuraOrgChart == null || value == null) {
|
|
toastr.warning("No se pudo obtener el ID del Miembro Comité Crédito seleccionado.");
|
|
return;
|
|
}
|
|
|
|
if (!confirm(msg))
|
|
{ return; }
|
|
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
|
|
|
|
Item = {
|
|
CodigoComite: CodigoComite,
|
|
IdEstructuraOrgChart: CodEstructuraOrgChart,
|
|
Estado: value,
|
|
UsuarioModificado: $("#hiddenUserID").val()
|
|
}
|
|
|
|
var uri = 'api/MiembrosComiteCreditoAPI/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();
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').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.InsertarItem = function () {
|
|
|
|
|
|
if (!$("#formCatalogo").valid()) {
|
|
toastr.warning("Ingresar todos los campos que son requeridos.");
|
|
return false;
|
|
}
|
|
|
|
if (!confirm("Va a ingresar un Nuevo Miembro Comite Crédito.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
MiembrosComiteCredito = {
|
|
CodigoComite: $("#hiddenComiteCredito").val(),
|
|
IdEstructuraOrgChart: $("#hiddenEstructuraOrgChart").val(),
|
|
Orden: $("#txtOrden").val(),
|
|
EsVoto: $('#chkEsVoto').is(":checked"),
|
|
UsuarioCreador: $("#hiddenUserID").val(),
|
|
VotoPositivoActivaRegClienteSAP: $('#chkVotoPositivoActivaRegClienteSAP').is(":checked"),
|
|
VotoPositivoActivaValidarCondicionesCliente: $('#chkVotoPositivoActivaValidarCondicionesCliente').is(":checked"),
|
|
VotoPositivoActivaExcepciones: $('#chkVotoPositivoActivaExcepciones').is(":checked")
|
|
}
|
|
|
|
var uri = 'api/MiembrosComiteCreditoAPI/InsertarItem/';
|
|
var DTO = JSON.stringify(MiembrosComiteCredito);
|
|
|
|
$.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 éxito', 'Completado');
|
|
limpiar();
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').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.ActualizarItem = function () {
|
|
|
|
if (!$("#formCatalogo").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 = {
|
|
CodigoComite: $("#hiddenComiteCredito").val(),
|
|
IdEstructuraOrgChart: $("#hiddenEstructuraOrgChart").val(),
|
|
Orden: $("#txtOrden").val(),
|
|
EsVoto: $('#chkEsVoto').is(":checked"),
|
|
UsuarioModificado: $("#hiddenUserID").val(),
|
|
VotoPositivoActivaRegClienteSAP: $('#chkVotoPositivoActivaRegClienteSAP').is(":checked"),
|
|
VotoPositivoActivaValidarCondicionesCliente: $('#chkVotoPositivoActivaValidarCondicionesCliente').is(":checked"),
|
|
VotoPositivoActivaExcepciones: $('#chkVotoPositivoActivaExcepciones').is(":checked")
|
|
}
|
|
|
|
var uri = 'api/MiembrosComiteCreditoAPI/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();
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
|
|
$('#lbTituloAccion').empty();
|
|
$('#lbTituloAccion').append('Ingresar Nuevo Miembro Comite Crédito');
|
|
|
|
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 Miembro Comite Crédito');
|
|
|
|
|
|
$('#txtComiteCredito').val('');
|
|
$("#formCatalogo").validateElement("#txtComiteCredito");
|
|
|
|
$('#txtEstructuraOrgChart').val('');
|
|
$("#formCatalogo").validateElement("#txtEstructuraOrgChart");
|
|
|
|
$('#txtOrden').val('');
|
|
$("#formCatalogo").validateElement("#txtOrden");
|
|
|
|
$('#btnComiteCredito').show();
|
|
$('#btnEstructuraOrgChart').show();
|
|
$('#btn_eliminarComiteCredito').show();
|
|
$('#btn_eliminarEstructuraOrgChart').show();
|
|
|
|
$('#chkEsVoto').prop("checked", false);
|
|
$('#chkVotoPositivoActivaRegClienteSAP').prop("checked", false);
|
|
$('#chkVotoPositivoActivaValidarCondicionesCliente').prop("checked", false);
|
|
$('#chkVotoPositivoActivaExcepciones').prop("checked", false);
|
|
}
|
|
|
|
|
|
this.LeerExistente = function () {
|
|
|
|
var Comite = 0;
|
|
var Estructura = 0;
|
|
var Existe = false;
|
|
Comite = $("#hiddenComiteCredito").val();
|
|
Estructura = $("#hiddenEstructuraOrgChart").val();
|
|
|
|
for (var i = 0; i < LllavesCompuestas.length; i++) {
|
|
if ( Comite == LllavesCompuestas[i].comite && Estructura == LllavesCompuestas[i].estructorg) {
|
|
Existe = true;
|
|
}
|
|
}
|
|
|
|
if (Existe == true) {
|
|
toastr.error("Este Comité Crédito y esta Estructura OrgChart ya están registrados.");
|
|
}
|
|
else {
|
|
InsertarItem();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|