452 lines
13 KiB
JavaScript
452 lines
13 KiB
JavaScript
|
|
$("#formCatalogo").EnableValidationToolTip();
|
|||
|
|
var DataCatalogo;
|
|||
|
|
var id_column = 1;
|
|||
|
|
var Item = {};
|
|||
|
|
|
|||
|
|
|
|||
|
|
//#region READY
|
|||
|
|
|
|||
|
|
jQuery(document).ready(function () {
|
|||
|
|
|
|||
|
|
//$('#txtDescripcion').attr('size', 30);
|
|||
|
|
|
|||
|
|
//$("#btnBuscar").click(function () {
|
|||
|
|
// CargarDataCatalogo(DireccionAPICatalogo, $("#txtDescripcion").val());
|
|||
|
|
//});
|
|||
|
|
|
|||
|
|
GetControlsSettings("Motivo", "Motivo", "formCatalogo");
|
|||
|
|
|
|||
|
|
$('#btnGuardar').hide();
|
|||
|
|
$('#btnInsertar').show();
|
|||
|
|
|
|||
|
|
obtenerItems();
|
|||
|
|
obtenerItemsDDL();
|
|||
|
|
|
|||
|
|
$('#btnLimpiar').click(function () {
|
|||
|
|
limpiar();
|
|||
|
|
|
|||
|
|
$('#btnGuardar').hide();
|
|||
|
|
$('#btnInsertar').show();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
$('#btnGuardar').click(function () {
|
|||
|
|
ActualizarItem();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
$('#btnInsertar').click(function () {
|
|||
|
|
InsertarItem();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
$("#ddlMoneda").change(function () {
|
|||
|
|
filtrarPorTipo();
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
//#endregion
|
|||
|
|
|
|||
|
|
this.obtenerItems = function () {
|
|||
|
|
|
|||
|
|
|
|||
|
|
var uri = 'api/CuentaAgenciaAPI/ObtenerItems/';
|
|||
|
|
|
|||
|
|
$.getJSON(server + uri).done(function (data) {
|
|||
|
|
|
|||
|
|
|
|||
|
|
var TableItems = $('#TableItems').DataTable();
|
|||
|
|
|
|||
|
|
$.each(data, function (key, item) {
|
|||
|
|
|
|||
|
|
|
|||
|
|
var option = $("#ucItemsCatalogo").html();
|
|||
|
|
|
|||
|
|
option = replaceAll("[$CodItem]", item.IdCuentaAgencia, 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.IdCuentaAgencia, item.TipoCuenta, item.NumCuenta, item.Moneda.Descripcion, item.Descripcion, item.TipoFuncionalidadCuenta.Descripcion, option]).draw(); // Steven Rojas
|
|||
|
|
|
|||
|
|
});
|
|||
|
|
filtrarPorTipo();
|
|||
|
|
|
|||
|
|
}).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.obtenerItemsDDL = function () {
|
|||
|
|
|
|||
|
|
//Obtener Monedas
|
|||
|
|
var uri = 'api/CuentaAgenciaAPI/ObtenerItemsMoneda/';
|
|||
|
|
|
|||
|
|
$.getJSON(server + uri).done(function (data) {
|
|||
|
|
|
|||
|
|
var registros = '<option></option>'
|
|||
|
|
$.each(data, function (key, item) {
|
|||
|
|
registros += '<option value="' + item.IdMoneda + '">' + item.Descripcion + '</option>'
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
$("#ddlMoneda").html(registros);
|
|||
|
|
|
|||
|
|
}).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();
|
|||
|
|
});
|
|||
|
|
// Fin Obtener Monedas
|
|||
|
|
|
|||
|
|
//Obtener Tipo Funcionalidad Steven Rojas
|
|||
|
|
var uri = 'api/CuentaAgenciaAPI/ObtenerItemsTipoFuncionalidad/';
|
|||
|
|
|
|||
|
|
$.getJSON(server + uri).done(function (data) {
|
|||
|
|
|
|||
|
|
var registros = '<option></option>'
|
|||
|
|
$.each(data, function (key, item) {
|
|||
|
|
registros += '<option value="' + item.IdTipoFuncionalidadCuenta + '">' + item.Descripcion + '</option>'
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
$("#ddlTipoFuncionalidad").html(registros);
|
|||
|
|
|
|||
|
|
}).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();
|
|||
|
|
});
|
|||
|
|
// Fin Obtener Tipo Funcionalidad
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this.EditarItem = function (id) {
|
|||
|
|
|
|||
|
|
TableItems = $('#TableItems').DataTable();
|
|||
|
|
limpiar();
|
|||
|
|
var indexes = getRowIndex(TableItems, id_column, id);
|
|||
|
|
|
|||
|
|
if (indexes != null) {
|
|||
|
|
|
|||
|
|
$('#hiddenId').val(id);
|
|||
|
|
$("#ddlMoneda option").filter(function () { return this.text == TableItems.cell(indexes, 4).data() }).attr('selected', true);
|
|||
|
|
$("#ddlTipo").val(TableItems.cell(indexes, 2).data());
|
|||
|
|
$("#ddlTipoFuncionalidad option").filter(function () { return this.text == TableItems.cell(indexes, 6).data() }).attr('selected', true); // Steven Rojas
|
|||
|
|
$('#txtDescripcion').val(TableItems.cell(indexes, 3).data());
|
|||
|
|
$('#txtDescripcionCuenta').val(TableItems.cell(indexes, 5).data());
|
|||
|
|
|
|||
|
|
filtrarPorTipo();
|
|||
|
|
$("#formCatalogo").validateElement("#ddlMoneda");
|
|||
|
|
$("#formCatalogo").validateElement("#ddlTipo");
|
|||
|
|
$("#formCatalogo").validateElement("#txtDescripcion");
|
|||
|
|
$("#formCatalogo").validateElement("#txtDescripcionCuenta");
|
|||
|
|
$("#formCatalogo").validateElement("#ddlTipoFuncionalidad"); // Steven Rojas
|
|||
|
|
|
|||
|
|
$('#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 Cuenta?';
|
|||
|
|
|
|||
|
|
if (value == 0) {
|
|||
|
|
msg = 'Está seguro que desea deshabilitar la Cuenta?';
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (id == null || value == null) {
|
|||
|
|
toastr.warning("No se pudo obtener el ID de la Cuenta seleccionada.");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!confirm(msg))
|
|||
|
|
{ return; }
|
|||
|
|
|
|||
|
|
|
|||
|
|
TableItems = $('#TableItems').DataTable();
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
Item = {
|
|||
|
|
IdCuentaAgencia: id,
|
|||
|
|
Estado: value
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var uri = 'api/CuentaAgenciaAPI/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 = {
|
|||
|
|
IdCuentaAgencia: $('#hiddenId').val(),
|
|||
|
|
IdMoneda: $('#ddlMoneda').val(),
|
|||
|
|
NumCuenta: $('#txtDescripcion').val(),
|
|||
|
|
Descripcion: $('#txtDescripcionCuenta').val(),
|
|||
|
|
TipoCuenta: $('#ddlTipo').val(),
|
|||
|
|
IdTipoFuncionalidadCuenta: $('#ddlTipoFuncionalidad').val() // Steven Rojas, agregar campo Tipo Funcionalidad
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
// Valida si la funcionalidad ya existe para la moneda seleccionada Steven Rojas
|
|||
|
|
var uri = 'api/CuentaAgenciaAPI/ValidarTipoFuncionalidad/';
|
|||
|
|
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") {
|
|||
|
|
var uri = 'api/CuentaAgenciaAPI/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 é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) {
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
else {
|
|||
|
|
toastr.error("Ya existe un Tipo de Funcionalidad para esta moneda.");
|
|||
|
|
ENDREQUEST();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|||
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo.");
|
|||
|
|
}).then(function (value) {
|
|||
|
|
});
|
|||
|
|
// Fin valida tipo funcionalidad
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this.InsertarItem = function () {
|
|||
|
|
|
|||
|
|
|
|||
|
|
if (!$("#formCatalogo").valid()) {
|
|||
|
|
toastr.warning("Ingresar todos los campos que son requeridos.");
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!confirm("Va a ingresar una nueva Cuenta.\n ¿Desea continuar?"))
|
|||
|
|
{ return; }
|
|||
|
|
|
|||
|
|
TableItems = $('#TableItems').DataTable();
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
Item = {
|
|||
|
|
IdMoneda: $('#ddlMoneda').val(),
|
|||
|
|
NumCuenta: $('#txtDescripcion').val(),
|
|||
|
|
Descripcion: $('#txtDescripcionCuenta').val(),
|
|||
|
|
TipoCuenta: $('#ddlTipo').val(),
|
|||
|
|
IdTipoFuncionalidadCuenta: $('#ddlTipoFuncionalidad').val()// Steven Rojas, agregar campo Tipo Funcionalidad
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Valida si la funcionalidad ya existe para la moneda seleccionada Steven Rojas
|
|||
|
|
var uri = 'api/CuentaAgenciaAPI/ValidarTipoFuncionalidad/';
|
|||
|
|
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") {
|
|||
|
|
|
|||
|
|
var uri = 'api/CuentaAgenciaAPI/InsertarItem/';
|
|||
|
|
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 é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) {
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
else {
|
|||
|
|
toastr.error("Ya existe un Tipo de Funcionalidad para esta moneda.");
|
|||
|
|
ENDREQUEST();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|||
|
|
toastr.error("Ha ocurrido un error inesperado. Vuela a intentarlo.");
|
|||
|
|
}).then(function (value) {
|
|||
|
|
});
|
|||
|
|
// Fin valida tipo funcionalidad
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this.limpiar = function () {
|
|||
|
|
|
|||
|
|
$('#lbTituloAccion').html('Ingresar nueva Cuenta');
|
|||
|
|
//$('#ddlMoneda').val('');
|
|||
|
|
$('#ddlTipo').val('');
|
|||
|
|
$('#ddlTipoFuncionalidad').val('');// Steven Rojas
|
|||
|
|
$('#txtDescripcion').val('');
|
|||
|
|
$('#txtDescripcionCuenta').val('');
|
|||
|
|
|
|||
|
|
$("#formCatalogo").validateElement("#ddlMoneda");
|
|||
|
|
$("#formCatalogo").validateElement("#ddlTipo");
|
|||
|
|
$("#formCatalogo").validateElement("#txtDescripcion");
|
|||
|
|
$("#formCatalogo").validateElement("#txtDescripcionCuenta");
|
|||
|
|
$("#formCatalogo").validateElement("#ddlTipoFuncionalidad");// Steven Rojas
|
|||
|
|
|
|||
|
|
filtrarPorTipo();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this.filtrarPorTipo = function () {
|
|||
|
|
var tipo = $('#ddlMoneda option:selected').text();
|
|||
|
|
|
|||
|
|
$.each($("#TableItems tr"), function (index, value) {
|
|||
|
|
|
|||
|
|
if (index == 0 || $($(value).find("td")[4]).html() == tipo) {
|
|||
|
|
$(value).show();
|
|||
|
|
}
|
|||
|
|
else {
|
|||
|
|
$(value).hide();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
});
|
|||
|
|
}
|