447 lines
14 KiB
JavaScript
447 lines
14 KiB
JavaScript
$("#formCatalogo").EnableValidationToolTip();
|
|
var DataCatalogo;
|
|
var id_column = 1;
|
|
var Item = {};
|
|
var CatalogoItem = {};
|
|
|
|
|
|
//#region READY
|
|
|
|
jQuery(document).ready(function () {
|
|
|
|
GetControlsSettings("Cathay_CondicionesFormalizacion", "Cathay_CondicionesFormalizacion", "formCatalogo");
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
|
|
obtenerItems();
|
|
|
|
$('#btnLimpiar').click(function () {
|
|
limpiar();
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
});
|
|
|
|
$('#btnGuardar').click(function () {
|
|
ActualizarItem();
|
|
});
|
|
|
|
$('#btnInsertar').click(function () {
|
|
InsertarItem();
|
|
});
|
|
});
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
this.obtenerItems = function () {
|
|
|
|
|
|
var uri = 'api/CondicionesFormalizacionAPI/ObtenerItems/';
|
|
|
|
$.getJSON(server + uri).done(function (data) {
|
|
CatalogoItem = data;
|
|
|
|
var TableItems = $('#TableItems').DataTable();
|
|
|
|
$.each(data, function (key, item) {
|
|
|
|
|
|
var condicion;
|
|
var tipocategoria;
|
|
var tipofacilidad;
|
|
var proceso;
|
|
|
|
|
|
if (item.CondicionesGeneralesCredito == null) { condicion = ""; } else { condicion = item.CondicionesGeneralesCredito.Descripcion; }
|
|
if (item.TipoCategoria == null) { tipocategoria = ""; } else { tipocategoria = item.TipoCategoria.Descripcion; }
|
|
if (item.TipoFacilidad == null) { tipofacilidad = ""; } else { tipofacilidad = item.TipoFacilidad.Descripcion; }
|
|
if (item.Procesos == null) { proceso = ""; } else { proceso = item.Procesos.NombreProceso; }
|
|
|
|
|
|
|
|
|
|
var linea = $("#ucILinea").html();
|
|
var especifico = $("#ucIEspecifico").html();
|
|
var Garantia = $("#ucIGarantia").html();
|
|
var option = $("#ucItemsCatalogo").html();
|
|
|
|
option = replaceAll("[$CodItem]", item.IdCondicionFormalizacion, option);
|
|
|
|
var stateIcon = $("#ucItemsIcon").html();
|
|
//----------------------------------------------------Estado--------------------------------------------
|
|
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);
|
|
}
|
|
//---------------------------------------------------- FIN Estado--------------------------------------------
|
|
|
|
//----------------------------------------------------Garantia--------------------------------------------
|
|
|
|
if (item.ConGarantiaReal == true) {
|
|
Garantia = replaceAll("[$icon]", "fa-check-circle", Garantia);
|
|
Garantia = replaceAll("[$state_color]", "success", Garantia);
|
|
option = replaceAll("[$valueGarantia]", "1", option);
|
|
}
|
|
else {
|
|
Garantia = replaceAll("[$icon]", "fa-check-circle", Garantia);
|
|
Garantia = replaceAll("[$state_color]", "muted", Garantia);
|
|
option = replaceAll("[$valueGarantia]", "0", option);
|
|
}
|
|
|
|
//----------------------------------------------------FIn Garantia--------------------------------------------
|
|
|
|
//----------------------------------------------------linea Especifico--------------------------------------------
|
|
|
|
|
|
if (item.EsLinea == true) {
|
|
linea = replaceAll("[$icon]", "fa-check-circle", linea);
|
|
linea = replaceAll("[$state_color]", "success", linea);
|
|
option = replaceAll("[$valueLinea]", "1", option);
|
|
|
|
} else {
|
|
linea = replaceAll("[$icon]", "fa-check-circle", linea);
|
|
linea = replaceAll("[$state_color]", "muted", linea);
|
|
option = replaceAll("[$valueLinea]", "1", option);
|
|
}
|
|
|
|
if (item.EsEspecifico == true) {
|
|
especifico = replaceAll("[$icon]", "fa-check-circle", especifico);
|
|
especifico = replaceAll("[$state_color]", "success", especifico);
|
|
option = replaceAll("[$valueEspecifico]", "1", option);
|
|
}
|
|
else {
|
|
especifico = replaceAll("[$icon]", "fa-check-circle", especifico);
|
|
especifico = replaceAll("[$state_color]", "muted", especifico);
|
|
option = replaceAll("[$valueEspecifico]", "0", option);
|
|
}
|
|
|
|
//----------------------------------------------------FIn linea Especifico--------------------------------------------
|
|
|
|
|
|
TableItems.row.add([stateIcon, item.IdCondicionFormalizacion, condicion, tipocategoria, tipofacilidad, proceso, Garantia, linea, especifico, option]).draw();
|
|
|
|
});
|
|
|
|
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo mas tarde");
|
|
|
|
console.log("Request Failed: " + textStatus + ', ' + error);
|
|
|
|
}).then(function (value) {
|
|
|
|
ENDREQUEST();
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.EditarItem = function (id) {
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
limpiar();
|
|
var indexes = getRowIndex(TableItems, id_column, id);
|
|
|
|
var linea, especifico, Garantia;
|
|
|
|
|
|
if (indexes != null) {
|
|
|
|
$('#hiddenId').val(id)
|
|
$('#txtCondicionesGeneralesCredito').val(TableItems.cell(indexes, 2).data());
|
|
$('#txtCategoria').val(TableItems.cell(indexes, 3).data());
|
|
$('#txtFacilidad').val(TableItems.cell(indexes, 4).data());
|
|
$('#txtProceso').val(TableItems.cell(indexes, 5).data());
|
|
|
|
$("#formCatalogo").validateElement("#txtCondicionesGeneralesCredito");
|
|
$("#formCatalogo").validateElement("#txtCategoria");
|
|
$("#formCatalogo").validateElement("#txtFacilidad");
|
|
$("#formCatalogo").validateElement("#txtProceso");
|
|
|
|
$.each(CatalogoItem, function (key, item) {
|
|
if (item.IdCondicionFormalizacion == id) {
|
|
$('#hiddenCondicionesGeneralesCredito').val(item.IdCondicion);
|
|
$('#hiddenCategoria').val(item.IdTipoCategoria);
|
|
$('#hiddenFacilidad').val(item.IdTipoFacilidad);
|
|
$('#hiddenProceso').val(item.IdProceso);
|
|
|
|
if (item.ConGarantiaReal == false) { Garantia = "0"; } else { Garantia = "1"; }
|
|
if (item.EsLinea == false) { linea = "0"; } else { linea = "1"; }
|
|
if (item.EsEspecifico == false) { especifico = "0"; } else { especifico = "1"; }
|
|
|
|
|
|
}
|
|
});
|
|
|
|
if (linea == "1") {
|
|
$("#radioEsLinea").prop("checked", true);
|
|
} else {
|
|
$("#radioEsLinea").prop("checked", false);
|
|
}
|
|
|
|
if (especifico == "1") {
|
|
$("#radioEsEspecifico").prop("checked", true);
|
|
} else {
|
|
$("#radioEsEspecifico").prop("checked", false);
|
|
}
|
|
|
|
|
|
if (Garantia == "1") {
|
|
$("#chkGarantiaReal").prop("checked", true);
|
|
} else {
|
|
$("#chkGarantiaReal").prop("checked", false);
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#lbTituloAccion').empty();
|
|
$('#lbTituloAccion').append('Editar Valor de Campo ID: ' + id);
|
|
|
|
$('#btnInsertar').hide();
|
|
$('#btnGuardar').show();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
this.toggleEnabledItem = function (id, value) {
|
|
|
|
var msg = 'Está seguro que desea habilitar la Condición Formalización?';
|
|
|
|
if (value == 0) {
|
|
msg = 'Está seguro que desea deshabilitar la Condición Formalización?';
|
|
}
|
|
|
|
if (id == null || value == null) {
|
|
toastr.warning("No se pudo obtener el ID de la Condición Formalización seleccionada.");
|
|
return;
|
|
}
|
|
|
|
if (!confirm(msg))
|
|
{ return; }
|
|
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
|
|
Item = {
|
|
IdCondicionFormalizacion: id,
|
|
Estado: value
|
|
}
|
|
|
|
var uri = 'api/CondicionesFormalizacionAPI/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.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 = {
|
|
IdCondicionFormalizacion: $("#hiddenId").val(),
|
|
IdCondicion: $("#hiddenCondicionesGeneralesCredito").val(),
|
|
IdTipoCategoria: $('#hiddenCategoria').val(),
|
|
IdTipoFacilidad: $("#hiddenFacilidad").val(),
|
|
ConGarantiaReal: $('#chkGarantiaReal').is(":checked"),
|
|
IdProceso: $('#hiddenProceso').val(),
|
|
EsLinea: ($("#radioEsLinea").is(":checked") ? true : ($("#radioEsEspecifico").is(":checked") ? false : null)),
|
|
EsEspecifico: ($("#radioEsEspecifico").is(":checked") ? true : ($("#radioEsLinea").is(":checked") ? false : null)),
|
|
|
|
}
|
|
|
|
var uri = 'api/CondicionesFormalizacionAPI/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 Nueva Condición Formalización');
|
|
|
|
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 (!$("#formCatalogo").valid()) {
|
|
toastr.warning("Ingresar todos los campos que son requeridos.");
|
|
return false;
|
|
}
|
|
|
|
|
|
if (!confirm("Va a Ingresar una Nueva Condición Formalización.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
CondicionesFormalizacion = {
|
|
|
|
IdCondicion: $("#hiddenCondicionesGeneralesCredito").val(),
|
|
IdTipoCategoria: $('#hiddenCategoria').val(),
|
|
IdTipoFacilidad: $("#hiddenFacilidad").val(),
|
|
ConGarantiaReal: $('#chkGarantiaReal').is(":checked"),
|
|
IdProceso: $('#hiddenProceso').val(),
|
|
EsLinea : ($("#radioEsLinea").is(":checked") ? true : ($("#radioEsEspecifico").is(":checked") ? false : null)),
|
|
EsEspecifico: ($("#radioEsEspecifico").is(":checked") ? true : ($("#radioEsLinea").is(":checked") ? false : null)),
|
|
}
|
|
|
|
var uri = 'api/CondicionesFormalizacionAPI/InsertarItem/';
|
|
var DTO = JSON.stringify(CondicionesFormalizacion);
|
|
|
|
$.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();
|
|
|
|
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 Nueva Condición Formalización');
|
|
|
|
$('#txtCondicionesGeneralesCredito').val('');
|
|
$("#formCatalogo").validateElement("#txtCondicionesGeneralesCredito");
|
|
|
|
$("#txtCategoria").val('');
|
|
$("#formCatalogo").validateElement("#txtCategoria");
|
|
|
|
|
|
$("#txtFacilidad").val('');
|
|
$("#formCatalogo").validateElement("#txtFacilidad");
|
|
|
|
$("#txtProceso").val('');
|
|
$("#formCatalogo").validateElement("#txtProceso");
|
|
|
|
|
|
|
|
$("#radioEsLinea").prop("checked", false);
|
|
|
|
$("#radioEsEspecifico").prop("checked", true);
|
|
|
|
$("#chkGarantiaReal").prop("checked", false);
|
|
|
|
|
|
|
|
|
|
}
|