231 lines
8.2 KiB
JavaScript
231 lines
8.2 KiB
JavaScript
|
|
//#region GLOBALES
|
|||
|
|
$("#formMotivos").EnableValidationToolTip();
|
|||
|
|
var IdTipoMotivo = null;
|
|||
|
|
var tableItemsMotivo = null;
|
|||
|
|
var IdMotivoSolicitud = 0;
|
|||
|
|
var SourceOrDestination = null;
|
|||
|
|
var _HasMotivosDevolucion = false;
|
|||
|
|
|
|||
|
|
//#endregion
|
|||
|
|
|
|||
|
|
//#region READY
|
|||
|
|
jQuery(document).ready(function () {
|
|||
|
|
tableItemsMotivo = $('#TableItemsMotivo').DataTable();
|
|||
|
|
GetControlsSettings("_Motivos", "_Motivos", "formMotivos");
|
|||
|
|
});
|
|||
|
|
//#endregion
|
|||
|
|
|
|||
|
|
$("#btnAgregarMotivo").click(function () {
|
|||
|
|
guardarMotivo(1);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
this.initializeFormMotivos = function (_IdTipoMotivo, _IsReadOnly, _SourceOrDestination) {
|
|||
|
|
try {
|
|||
|
|
IdTipoMotivo = _IdTipoMotivo;
|
|||
|
|
SourceOrDestination = _SourceOrDestination;
|
|||
|
|
|
|||
|
|
switch (_IsReadOnly) {
|
|||
|
|
case true:
|
|||
|
|
$("#divSelectorMotivoAgregar").attr("style", "display:none;");
|
|||
|
|
$("#txtComentarioMotivo").attr("disabled", true);
|
|||
|
|
break;
|
|||
|
|
case false:
|
|||
|
|
$("#divSelectorMotivoAgregar").attr("style", "display:block;");
|
|||
|
|
$("#txtComentarioMotivo").attr("disabled", false);
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
ddlMotivo_OnLoad(_IdTipoMotivo);
|
|||
|
|
|
|||
|
|
obtenerMotivo(_IsReadOnly);
|
|||
|
|
} catch (e) {
|
|||
|
|
IdTipoMotivo = null;
|
|||
|
|
toastr.error("Ha ocurrido un error inesperado. Vuelva a intentarlo mas tarde", Message_Error);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this.ddlMotivo_OnLoad = function (_IdTipoMotivo)
|
|||
|
|
{
|
|||
|
|
var uri = "api/MotivosAPI/ObtenerMotivo?idTipoMotivo=" + _IdTipoMotivo;
|
|||
|
|
StartSelectControlRequest("#ddlMotivo");
|
|||
|
|
$.getJSON(server + uri).done(function (data) {
|
|||
|
|
CleanSelectControl("#ddlMotivo");
|
|||
|
|
$.each(data, function (key, item) {
|
|||
|
|
AddSelectOption("#ddlMotivo", item.codigo, item.descripcion);
|
|||
|
|
});
|
|||
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|||
|
|
ENDREQUEST();
|
|||
|
|
toastr.error("Ha ocurrido un error inesperado. Vuelva a intentarlo mas tarde", Message_Error);
|
|||
|
|
}).then(function (value) {
|
|||
|
|
ENDREQUEST();
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this.guardarMotivo = function (_Estado) {
|
|||
|
|
try {
|
|||
|
|
var item = $("#ddlMotivo option:selected");
|
|||
|
|
if (item.val().trim() == "" || item.val().trim() == "-1")
|
|||
|
|
{
|
|||
|
|
toastr.error("Por favor seleccione una opción de la lista de motivos antes de agregar.");
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
var _model = {
|
|||
|
|
IdMotivoSolicitud: IdMotivoSolicitud,
|
|||
|
|
IdMotivoSolicitudSec : null,
|
|||
|
|
IdSolicitud: $("#hiddensol_co_solicitud").val(),
|
|||
|
|
IdMotivo: item.val(),
|
|||
|
|
Comentario: null,
|
|||
|
|
EtapaOrigen: $("#hiddenStep").val(),
|
|||
|
|
EtapaDestino: null,
|
|||
|
|
UsuarioOrigen: $("#hiddenUserID").val().split('/')[1],
|
|||
|
|
UsuarioDestino: null,
|
|||
|
|
FeRegistro: null,
|
|||
|
|
Estado: _Estado,
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var uri = 'api/MotivosAPI/InsertarMotivoSolicitud/';
|
|||
|
|
var DTO = JSON.stringify(_model);
|
|||
|
|
|
|||
|
|
$.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');
|
|||
|
|
obtenerMotivo();
|
|||
|
|
}
|
|||
|
|
else {
|
|||
|
|
toastr.error("Ha ocurrido un error inesperado al guardar el motivo. Vuelva a intentarlo.");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|||
|
|
toastr.error("Ha ocurrido un error inesperado. Vuelva a intentarlo.");
|
|||
|
|
ENDREQUEST();
|
|||
|
|
}).then(function (value) {
|
|||
|
|
ENDREQUEST();
|
|||
|
|
});
|
|||
|
|
} catch (e) {
|
|||
|
|
toastr.error("Ha ocurrido un error inesperado al intentar guardar el motivo. Vuelva a intentarlo.");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this.obtenerMotivo = function (_IsReadOnly) {
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var IdSolicitud = $("#hiddensol_co_solicitud").val();
|
|||
|
|
var EtapaOrigen = $("#hiddenStep").val();
|
|||
|
|
var Estado = $("#hiddenTaskStatus").val();
|
|||
|
|
|
|||
|
|
|
|||
|
|
var uri = 'api/MotivosAPI/ObtenerMotivoSolicitud?IdSolicitud=' + IdSolicitud +
|
|||
|
|
'&EtapaOrigen=' + EtapaOrigen +
|
|||
|
|
'&IdTipoMotivo=' + IdTipoMotivo +
|
|||
|
|
'&Estado=' + Estado +
|
|||
|
|
'&OrigenOrDestino=' + SourceOrDestination;
|
|||
|
|
|
|||
|
|
$.ajax({
|
|||
|
|
url: server + uri,
|
|||
|
|
dataType: 'json',
|
|||
|
|
data: null,
|
|||
|
|
async: false,
|
|||
|
|
success: function (data) {
|
|||
|
|
|
|||
|
|
tableItemsMotivo.clear().draw();
|
|||
|
|
|
|||
|
|
if (data == null || data.length == 0)
|
|||
|
|
_HasMotivosDevolucion = false;
|
|||
|
|
|
|||
|
|
|
|||
|
|
//************************************
|
|||
|
|
//Lista de Motivos de la Solicitud
|
|||
|
|
//************************************
|
|||
|
|
$.each(data, function (key, item) {
|
|||
|
|
|
|||
|
|
if (!_IsReadOnly) {
|
|||
|
|
var option = $("#ucItemsMotivo").html();
|
|||
|
|
option = replaceAll("[$CodItem]", item.IdMotivoSolicitud, option);
|
|||
|
|
option = replaceAll("[$CodItemSec]", item.IdMotivoSolicitudSec, option);
|
|||
|
|
tableItemsMotivo.row.add([item.IdMotivo, item.Motivo.Descripcion, option]).draw();
|
|||
|
|
}
|
|||
|
|
else {
|
|||
|
|
tableItemsMotivo.row.add([item.IdMotivo, item.Motivo.Descripcion, ""]).draw();
|
|||
|
|
}
|
|||
|
|
IdMotivoSolicitud = item.IdMotivoSolicitud;
|
|||
|
|
|
|||
|
|
if (item.Comentario != null) {
|
|||
|
|
$("#txtComentarioMotivo").val(item.Comentario.trim());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
_HasMotivosDevolucion = true;
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|||
|
|
toastr.error("Ha ocurrido un error inesperado. Vuelva a intentarlo mas tarde", Message_Error);
|
|||
|
|
_HasMotivosDevolucion = false;
|
|||
|
|
}).then(function (value) {
|
|||
|
|
ENDREQUEST();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
} catch (e) {
|
|||
|
|
toastr.error("Ha ocurrido un error inesperado al intentar obtener los motivos de la solicitud. Vuelva a intentarlo mas tarde");
|
|||
|
|
_HasMotivosDevolucion = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this.eliminarMotivo = function (_IdMotivoSolicitud, _IdMotivoSolicitudSec) {
|
|||
|
|
try {
|
|||
|
|
var _model = {
|
|||
|
|
IdMotivoSolicitud: _IdMotivoSolicitud,
|
|||
|
|
IdMotivoSolicitudSec: _IdMotivoSolicitudSec
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
var uri = 'api/MotivosAPI/EliminarMotivoSolicitud/';
|
|||
|
|
var DTO = JSON.stringify(_model);
|
|||
|
|
|
|||
|
|
$.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');
|
|||
|
|
obtenerMotivo();
|
|||
|
|
}
|
|||
|
|
else {
|
|||
|
|
toastr.error("Ha ocurrido un error inesperado. Vuelva a intentarlo.");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}).fail(function (jqxhr, textStatus, error) {
|
|||
|
|
toastr.error("Ha ocurrido un error inesperado. Vuelva a intentarlo.");
|
|||
|
|
ENDREQUEST();
|
|||
|
|
}).then(function (value) {
|
|||
|
|
ENDREQUEST();
|
|||
|
|
});
|
|||
|
|
} catch (e) {
|
|||
|
|
toastr.error("Ha ocurrido un error inesperado al intentar eliminar el motivo. Vuelva a intentarlo.");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
this.agregarMotivo = function () {
|
|||
|
|
try {
|
|||
|
|
var item = $("#ddlMotivo option:selected");
|
|||
|
|
if (item.val().trim() == "" || item.val().trim() == "-1")
|
|||
|
|
{
|
|||
|
|
toastr.error("Por favor seleccione una opción de la lista de motivos antes de agregar.");
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
var option = $("#ucItemsMotivo").html();
|
|||
|
|
option = replaceAll("[$CodItem]", item.val(), option);
|
|||
|
|
tableItemsMotivo.row.add([item.val(), item.text(), option]).draw();
|
|||
|
|
} catch (e) {
|
|||
|
|
toastr.error("Ha ocurrido un error inesperado. Vuelva a intentarlo mas tarde");
|
|||
|
|
}
|
|||
|
|
}
|