460 lines
15 KiB
JavaScript
460 lines
15 KiB
JavaScript
$("#formCatalogo").EnableValidationToolTip();
|
|
var DataCatalogo;
|
|
var id_column = 1;
|
|
var Item = {};
|
|
var CatalogoItem = {};
|
|
|
|
|
|
//#region READY
|
|
|
|
jQuery(document).ready(function () {
|
|
|
|
GetControlsSettings("Cathay_DocumentosFormalizacion", "Cathay_DocumentosFormalizacion", "formCatalogo");
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
|
|
$('#btnLimpiar').click(function () {
|
|
limpiar();
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
});
|
|
|
|
$('#btnGuardar').click(function () {
|
|
ActualizarItem();
|
|
});
|
|
|
|
$('#btnInsertar').click(function () {
|
|
InsertarItem();
|
|
});
|
|
|
|
$('#btnObtener').click(function () {
|
|
obtenerItems();
|
|
});
|
|
|
|
$('#TableItems').TableInit(0, false, true, true, false, null, null);
|
|
});
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
this.obtenerItems = function () {
|
|
|
|
|
|
var uri = 'api/DocumentosFormalizacionAPI/ObtenerItems/';
|
|
|
|
var DocumentoFormalizacion = {
|
|
|
|
IdTipoDocumento: $("#hiddenTipoDocumento").val(),
|
|
IdTipoCategoria: $('#hiddenCategoria').val(),
|
|
IdTipoFacilidad: $("#hiddenFacilidad").val(),
|
|
IdProceso: $('#hiddenProceso').val()
|
|
};
|
|
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: server + uri,
|
|
cache: false,
|
|
data: JSON.stringify(DocumentoFormalizacion),
|
|
contentType: 'application/json; charset=utf-8',
|
|
dataType: 'json',
|
|
async: true,
|
|
success: function (data) {
|
|
//$.getJSON(server + uri).done(function (data) {
|
|
CatalogoItem = data.ListaDocumentosFormalizacion;
|
|
$('#TableItems').TableInit(0, false, true, true, false, null, null);
|
|
var TableItems = $('#TableItems').DataTable();
|
|
TableItems.clear().draw();
|
|
|
|
if (data != null && data.ListaDocumentosFormalizacion.length > 0)
|
|
$.each(data.ListaDocumentosFormalizacion, function (key, item) {
|
|
|
|
var tipoDocumento;
|
|
var tipocategoria;
|
|
var tipofacilidad;
|
|
var proceso;
|
|
|
|
tipoDocumento = item.TipoDocumento == null ? "" : item.TipoDocumento.Descripcion;
|
|
tipocategoria = item.TipoCategoria == null ? "" : item.TipoCategoria.Descripcion;
|
|
tipofacilidad = item.TipoFacilidad == null ? "" : item.TipoFacilidad.Descripcion;
|
|
proceso = item.Procesos == null ? "" : item.Procesos.NombreProceso;
|
|
|
|
var linea = $("#ucILinea").html();
|
|
var especifico = $("#ucIEspecifico").html();
|
|
var Garantia = $("#ucIGarantia").html();
|
|
var option = $("#ucItemsCatalogo").html();
|
|
|
|
option = replaceAll("[$CodItem]", item.IdDocumentoFormalizacion, 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.IdDocumentoFormalizacion, tipoDocumento, tipocategoria, tipofacilidad, proceso, Garantia, linea, especifico, option]).draw();
|
|
|
|
});
|
|
}
|
|
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|
if (typeof AjaxFailEvent !== 'undefined' && $.isFunction(AjaxFailEvent) && !AjaxFailEvent(jqxhr, textStatus, error))
|
|
return;
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo mas tarde", Message_Error);
|
|
ENDREQUEST();
|
|
}).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)
|
|
$('#txtTipoDocumento').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("#txtTipoDocumento");
|
|
$("#formCatalogo").validateElement("#txtCategoria");
|
|
$("#formCatalogo").validateElement("#txtFacilidad");
|
|
$("#formCatalogo").validateElement("#txtProceso");
|
|
|
|
$.each(CatalogoItem, function (key, item) {
|
|
if (item.IdDocumentoFormalizacion == id) {
|
|
$('#hiddenTipoDocumento').val(item.IdTipoDocumento);
|
|
$('#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 el Documento Formalización?';
|
|
|
|
if (value == 0) {
|
|
msg = 'Está seguro que desea deshabilitar el Documento Formalización?';
|
|
}
|
|
|
|
if (id == null || value == null) {
|
|
toastr.warning("No se pudo obtener el ID de el Documento Formalización seleccionada.");
|
|
return;
|
|
}
|
|
|
|
if (!confirm(msg))
|
|
{ return; }
|
|
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
|
|
Item = {
|
|
IdDocumentoFormalizacion: id,
|
|
Estado: value
|
|
}
|
|
|
|
var uri = 'api/DocumentosFormalizacionAPI/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 = {
|
|
IdDocumentoFormalizacion: $("#hiddenId").val(),
|
|
IdTipoDocumento: $("#hiddenTipoDocumento").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/DocumentosFormalizacionAPI/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 General 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.InsertarItem = function () {
|
|
if (!$("#formCatalogo").valid()) {
|
|
toastr.warning("Ingresar todos los campos que son requeridos.");
|
|
return false;
|
|
}
|
|
|
|
|
|
if (!confirm("Va a Ingresar un Nuevo Documento Formalización.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
DocumentosFormalizacion = {
|
|
|
|
IdTipoDocumento: $("#hiddenTipoDocumento").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/DocumentosFormalizacionAPI/InsertarItem/';
|
|
var DTO = JSON.stringify(DocumentosFormalizacion);
|
|
|
|
$.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 Nuevo Documento Formalización');
|
|
|
|
$('#txtTipoDocumento').val('');
|
|
$("#formCatalogo").validateElement("#txtTipoDocumento");
|
|
|
|
$("#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);
|
|
|
|
$("#hiddenTipoDocumento").val(null);
|
|
$('#hiddenCategoria').val(null);
|
|
$("#hiddenFacilidad").val(null);
|
|
$('#hiddenProceso').val(null);
|
|
}
|