384 lines
11 KiB
JavaScript
384 lines
11 KiB
JavaScript
$("#formCatalogo").EnableValidationToolTip();
|
|
var DataCatalogo;
|
|
var id_column = 1;
|
|
var Item = {};
|
|
|
|
|
|
//#region READY
|
|
|
|
jQuery(document).ready(function () {
|
|
$('#txtDescripcionSector').attr('size', 50);
|
|
|
|
|
|
GetControlsSettings("Cathay_Sector", "Cathay_Sector", "formCatalogo");
|
|
|
|
$('#btnGuardar').hide();
|
|
|
|
|
|
obtenerItems();
|
|
|
|
$('#btnLimpiar').click(function () {
|
|
limpiar();
|
|
|
|
$('#btnGuardar').hide();
|
|
$('#btnInsertar').show();
|
|
});
|
|
|
|
$('#btnGuardar').click(function () {
|
|
ActualizarItem();
|
|
});
|
|
|
|
$('#btnInsertar').click(function () {
|
|
InsertarItem();
|
|
});
|
|
});
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
this.obtenerItems = function () {
|
|
|
|
|
|
var uri = 'api/SectorAPI/ObtenerItems/';
|
|
|
|
$.getJSON(server + uri).done(function (data) {
|
|
|
|
$('#TableItems').TableInit(0, false, true, true, false, null, null);
|
|
|
|
var TableItems = $('#TableItems').DataTable();
|
|
|
|
$.each(data, function (key, item) {
|
|
|
|
|
|
var option = $("#ucItemsCatalogo").html();
|
|
|
|
option = replaceAll("[$CodItem]", item.IdSector, 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);
|
|
}
|
|
|
|
var PersonalPromedio = CustomNumberFormat(item.PersonalPromedio == null ? 0 : item.PersonalPromedio, 2, "", ".", ",")
|
|
var VentasAnualesNetas = CustomNumberFormat(item.VentasAnualesNetas == null ? 0 : item.VentasAnualesNetas, 2, "", ".", ",")
|
|
var ValorActivosTotales = CustomNumberFormat(item.ValorActivosTotales == null ? 0 : item.ValorActivosTotales, 2, "", ".", ",")
|
|
var PorcentajePersonalPromedio = CustomNumberFormat(item.PorcentajePersonalPromedio == null ? 0 : item.PorcentajePersonalPromedio, 2, "", ".", ",")
|
|
var PorcentajeVentasAnualesNetas = CustomNumberFormat(item.PorcentajeVentasAnualesNetas == null ? 0 : item.PorcentajeVentasAnualesNetas, 2, "", ".", ",")
|
|
var PorcentajeValorActivosTotales = CustomNumberFormat(item.PorcentajeValorActivosTotales == null ? 0 : item.PorcentajeValorActivosTotales, 2, "", ".", ",")
|
|
|
|
|
|
TableItems.row.add([stateIcon, item.IdSector, item.Descripcion, PersonalPromedio, VentasAnualesNetas, ValorActivosTotales, PorcentajePersonalPromedio, PorcentajeVentasAnualesNetas, PorcentajeValorActivosTotales, item.Porcentaje, 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);
|
|
|
|
if (indexes != null) {
|
|
|
|
$('#hiddenId').val(id)
|
|
|
|
|
|
$('#txtDescripcionSector').val(TableItems.cell(indexes, 2).data());
|
|
$('#txtPersonalPromedio').val(TableItems.cell(indexes, 3).data());
|
|
$('#txtVentasAnualesNetas').val(TableItems.cell(indexes, 4).data());
|
|
$('#txtValorActivosTotales').val(TableItems.cell(indexes, 5).data());
|
|
$('#txtPorcentajePersonalPromedio').val(TableItems.cell(indexes, 6).data());
|
|
$('#txtPorcentajeVentasAnualesNetas').val(TableItems.cell(indexes, 7).data());
|
|
$('#txtPorcentajeValorActivosTotales').val(TableItems.cell(indexes, 8).data());
|
|
$('#txtPorcentaje').val(TableItems.cell(indexes, 9).data());
|
|
|
|
$("#formCatalogo").validateElement("#txtDescripcionSector");
|
|
$("#formCatalogo").validateElement("#txtPersonalPromedio");
|
|
$("#formCatalogo").validateElement("#txtVentasAnualesNetas");
|
|
$("#formCatalogo").validateElement("#txtValorActivosTotales");
|
|
$("#formCatalogo").validateElement("#txtPorcentajePersonalPromedio");
|
|
$("#formCatalogo").validateElement("#txtPorcentajeVentasAnualesNetas");
|
|
$("#formCatalogo").validateElement("#txtPorcentajeValorActivosTotales");
|
|
$("#formCatalogo").validateElement("#txtPorcentaje");
|
|
|
|
$('#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 Sector?';
|
|
|
|
if (value == 0) {
|
|
msg = 'Está seguro que desea deshabilitar el Sector?';
|
|
}
|
|
|
|
if (id == null || value == null) {
|
|
toastr.warning("No se pudo obtener el ID del Sector seleccionado.");
|
|
return;
|
|
}
|
|
|
|
if (!confirm(msg))
|
|
{ return; }
|
|
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
|
|
|
|
Item = {
|
|
IdSector: id,
|
|
Estado: value,
|
|
UsuarioModificado: $("#hiddenUserID").val()
|
|
|
|
}
|
|
|
|
var uri = 'api/SectorAPI/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 = {
|
|
IdSector: $('#hiddenId').val(),
|
|
Descripcion: $('#txtDescripcionSector').val(),
|
|
PersonalPromedio: $('#txtPersonalPromedio').autoNumeric('get'),
|
|
VentasAnualesNetas: $('#txtVentasAnualesNetas').autoNumeric('get'),
|
|
ValorActivosTotales: $('#txtValorActivosTotales').autoNumeric('get'),
|
|
PorcentajePersonalPromedio: $('#txtPorcentajePersonalPromedio').autoNumeric('get'),
|
|
PorcentajeVentasAnualesNetas: $('#txtPorcentajeVentasAnualesNetas').autoNumeric('get'),
|
|
PorcentajeValorActivosTotales: $('#txtPorcentajeValorActivosTotales').autoNumeric('get'),
|
|
Porcentaje: $('#txtPorcentaje').autoNumeric('get'),
|
|
UsuarioModificado: $("#hiddenUserID").val()
|
|
|
|
}
|
|
|
|
var uri = 'api/SectorAPI/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 Sector');
|
|
|
|
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 Tipo de Facilidad.\n ¿Desea continuar?"))
|
|
{ return; }
|
|
|
|
TableItems = $('#TableItems').DataTable();
|
|
|
|
|
|
|
|
Item = {
|
|
Descripcion: $('#txtDescripcionSector').val(),
|
|
PersonalPromedio: $('#txtPersonalPromedio').autoNumeric('get'),
|
|
VentasAnualesNetas: $('#txtVentasAnualesNetas').autoNumeric('get'),
|
|
ValorActivosTotales: $('#txtValorActivosTotales').autoNumeric('get'),
|
|
PorcentajePersonalPromedio: $('#txtPorcentajePersonalPromedio').autoNumeric('get'),
|
|
PorcentajeVentasAnualesNetas: $('#txtPorcentajeVentasAnualesNetas').autoNumeric('get'),
|
|
PorcentajeValorActivosTotales: $('#txtPorcentajeValorActivosTotales').autoNumeric('get'),
|
|
Porcentaje: $('#txtPorcentaje').autoNumeric('get'),
|
|
UsuarioCreador: $("#hiddenUserID").val()
|
|
|
|
}
|
|
|
|
var uri = 'api/SectorAPI/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 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 Sector');
|
|
|
|
$('#txtDescripcionSector').val('');
|
|
$('#txtPersonalPromedio').autoNumeric('set', 0);;
|
|
$('#txtVentasAnualesNetas').autoNumeric('set', 0);
|
|
$('#txtValorActivosTotales').autoNumeric('set', 0);
|
|
$('#txtPorcentajePersonalPromedio').autoNumeric('set', 0);
|
|
$('#txtPorcentajeVentasAnualesNetas').autoNumeric('set', 0);
|
|
$('#txtPorcentajeValorActivosTotales').autoNumeric('set', 0);
|
|
$('#txtPorcentaje').autoNumeric('set', 0);
|
|
|
|
$("#formCatalogo").validateElement("#txtDescripcionSector");
|
|
$("#formCatalogo").validateElement("#txtPersonalPromedio");
|
|
$("#formCatalogo").validateElement("#txtVentasAnualesNetas");
|
|
$("#formCatalogo").validateElement("#txtValorActivosTotales");
|
|
$("#formCatalogo").validateElement("#txtPorcentajePersonalPromedio");
|
|
$("#formCatalogo").validateElement("#txtPorcentajeVentasAnualesNetas");
|
|
$("#formCatalogo").validateElement("#txtPorcentajeValorActivosTotales");
|
|
$("#formCatalogo").validateElement("#txtPorcentaje");
|
|
}
|
|
|