836 lines
31 KiB
C#
836 lines
31 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using System.Data;
|
|
|
|
using Extensiones;
|
|
using Microsoft.Reporting.WebForms;
|
|
using System.Text;
|
|
using System.Activities.Expressions;
|
|
|
|
public partial class RH_SolicitudViaticos : ClsPaginas
|
|
{
|
|
#region "PROPIEDADES"
|
|
private int CveSolicitudViatico
|
|
{
|
|
get
|
|
{
|
|
return ViewState["CveSolicitudViatico"].ToString().ToEntero();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["CveSolicitudViatico"] = value;
|
|
}
|
|
}
|
|
private DataTable DTConceptosDetalles
|
|
{
|
|
get
|
|
{
|
|
return (DataTable)ViewState["DTConceptosDetalles"];
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["DTConceptosDetalles"] = value;
|
|
}
|
|
}
|
|
private Double ImporteTotal
|
|
{
|
|
get
|
|
{
|
|
return ViewState["ImporteTotal"].ToString().ToDouble();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["ImporteTotal"] = value;
|
|
}
|
|
}
|
|
private int CveIE
|
|
{
|
|
get
|
|
{
|
|
return ViewState["CveIE"].ToString().ToEntero();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["CveIE"] = value;
|
|
}
|
|
}
|
|
private Double TotalDepositar
|
|
{
|
|
get
|
|
{
|
|
return ViewState["TotalDepositar"].ToString().ToDouble();
|
|
}
|
|
|
|
set
|
|
{
|
|
ViewState["TotalDepositar"] = value;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
RecuperaCve();
|
|
CargaDatosPersonal();
|
|
CargaConceptos();
|
|
|
|
if (!UsuarioActual.TienePermisoProceso(241))
|
|
{
|
|
DdlEstatus.Enabled = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
#region "CARGA DATOS"
|
|
protected void RecuperaCve()
|
|
{
|
|
if (Request["CveSolicitudViatico"] != null && !Request["CveSolicitudViatico"].ToString().Equals("") && Request["CveSolicitudViatico"].ToEntero() > 0)
|
|
{
|
|
ViewState["CveSolicitudViatico"] = Request["CveSolicitudViatico"];
|
|
}
|
|
else
|
|
{
|
|
ViewState["CveSolicitudViatico"] = -1;
|
|
}
|
|
}
|
|
|
|
protected void CargaDatosPersonal()
|
|
{
|
|
bool PuedeSolicitar = true;
|
|
// CARGA DDLS
|
|
DdlPersonal.DataSource = get_GlobalDTRHPersonal(UsuarioActual.CveEmpresa);
|
|
DdlPersonal.DataBind();
|
|
|
|
DdlDepartamento.DataSource = get_GlobalDTDepartamentos(UsuarioActual.CveEmpresa);
|
|
DdlDepartamento.DataBind();
|
|
|
|
DdlSupervisor.DataSource = get_GlobalDTRHPersonal(UsuarioActual.CveEmpresa);
|
|
DdlSupervisor.DataBind();
|
|
|
|
// SELECCIONA PERSONAL, DEPARTAMETO Y SUPERVISOR SI ESTAN ASIGNADOS
|
|
if (UsuarioActual.CvePersonal > 0)
|
|
{
|
|
DdlPersonal.SelectedValueExist(UsuarioActual.CvePersonal);
|
|
}
|
|
else
|
|
{
|
|
PuedeSolicitar = false;
|
|
}
|
|
|
|
if (get_GlobalDTRHPersonal(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CvePersonalPadre", String.Format("CvePersonal={0}", UsuarioActual.CvePersonal)).ToEntero() > 0)
|
|
{
|
|
DdlSupervisor.SelectedValueExist(get_GlobalDTRHPersonal(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CvePersonalPadre", String.Format("CvePersonal={0}", UsuarioActual.CvePersonal)).ToEntero());
|
|
}
|
|
else
|
|
{
|
|
PuedeSolicitar = false;
|
|
}
|
|
|
|
if (get_GlobalDTRHPersonal(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveDepartamento", String.Format("CvePersonal={0}", UsuarioActual.CvePersonal)).ToEntero() > 0)
|
|
{
|
|
DdlDepartamento.SelectedValueExist(get_GlobalDTRHPersonal(UsuarioActual.CveEmpresa).FiltroPrimeroValor("CveDepartamento", String.Format("CvePersonal={0}", UsuarioActual.CvePersonal)).ToEntero());
|
|
}
|
|
|
|
DdlPersonal.Enabled = false;
|
|
DdlSupervisor.Enabled = false;
|
|
DdlDepartamento.Enabled = false;
|
|
|
|
if (CveSolicitudViatico > 0)
|
|
{
|
|
CargaDatos();
|
|
}
|
|
else
|
|
{
|
|
|
|
if ((UsuarioActual.CveEmpresa.Contiene(1,2,72, 172, 173, 174)) && UsuarioActual.CvePersonal > 0)
|
|
{
|
|
CargaFolio();
|
|
}
|
|
|
|
|
|
BtnGuardar.Text = "Guardar";
|
|
LnkImprimirExcel.Visible = false;
|
|
LnkImprimirPDF.Visible = false;
|
|
LnkIE.Visible = false;
|
|
LblFecha.InnerText = "";
|
|
CreaDTConceptosDetalles();
|
|
}
|
|
|
|
if (!PuedeSolicitar && CveSolicitudViatico == -1)
|
|
{
|
|
Alert("No puede realizar una Solicitud de Viaticos ya que no esta registrado como Personal, no se le ha asigando un Supervisor o un Departamento. Pongase en contacto con Soporte Técnico.", ModExtensiones.TipoMensaje.MsgError);
|
|
DdlPersonal.SelectedValue = "-1";
|
|
DdlSupervisor.SelectedValue = "-1";
|
|
DdlDepartamento.SelectedValue = "-1";
|
|
LbAgregar.Enabled = false;
|
|
BtnGuardar.Enabled = false;
|
|
BtnNuevo.Enabled = false;
|
|
}
|
|
|
|
UpAcciones.Update();
|
|
UpSolicitud.Update();
|
|
}
|
|
|
|
protected void CargaDatos()
|
|
{
|
|
ClsBancos ObjBancos = new ClsBancos();
|
|
|
|
if (ObjBancos.GetSolicitudesViaticos(CveSolicitudViatico, UsuarioActual.CveEmpresa))
|
|
{
|
|
|
|
if (ObjBancos.DtResultados.Rows.Count > 0)
|
|
{
|
|
|
|
if (UsuarioActual.TienePermisoProceso(241) || UsuarioActual.CvePersonal == ObjBancos.DtResultados.FiltroPrimeroValor("CvePersonal").ToEntero())
|
|
{
|
|
CveIE = ObjBancos.DtResultados.FiltroPrimeroValor("CveIE").ToEntero() > 0 ? ObjBancos.DtResultados.FiltroPrimeroValor("CveIE").ToEntero() : -1;
|
|
TotalDepositar = ObjBancos.DtResultados.FiltroPrimeroValor("TotalADepositar").ToDouble() > 0 ? ObjBancos.DtResultados.FiltroPrimeroValor("TotalADepositar").ToDouble() : -1;
|
|
|
|
LnkImprimirPDF.Visible = true;
|
|
LnkImprimirExcel.Visible = false;
|
|
LnkIE.Visible = true;
|
|
|
|
if (CveIE > 0)
|
|
{
|
|
LnkIE.Text = "<i class=\"fa fa-money\"></i> <span style=\"padding - left:5px; \">Ver Total a Depositar</span>";
|
|
}
|
|
|
|
TxtFolio.Enabled = false;
|
|
TxtFolio.Text = ObjBancos.DtResultados.FiltroPrimeroValor("Folio");
|
|
|
|
DdlPersonal.SelectedValueExist(ObjBancos.DtResultados.FiltroPrimeroValor("CvePersonal"));
|
|
DdlDepartamento.SelectedValueExist(ObjBancos.DtResultados.FiltroPrimeroValor("CveDepartamento"));
|
|
DdlSupervisor.SelectedValueExist(ObjBancos.DtResultados.FiltroPrimeroValor("CveSupervisor"));
|
|
|
|
TxtDestino.Text = ObjBancos.DtResultados.FiltroPrimeroValor("Destino");
|
|
TxtAsunto.Text = ObjBancos.DtResultados.FiltroPrimeroValor("Asunto");
|
|
TxtFechaSalida.Text = ObjBancos.DtResultados.FiltroPrimeroValor("FechaSalida");
|
|
TxtFechaRegreso.Text = ObjBancos.DtResultados.FiltroPrimeroValor("FechaRegreso");
|
|
TxtTipoCarro.Text = ObjBancos.DtResultados.FiltroPrimeroValor("TipoCarro");
|
|
TxtKM.Text = ObjBancos.DtResultados.FiltroPrimeroValor("KM");
|
|
|
|
DdlEstatus.SelectedValueExist(ObjBancos.DtResultados.FiltroPrimeroValor("CveEstatus"));
|
|
|
|
TxtMotivo.Text = ObjBancos.DtResultados.FiltroPrimeroValor("Observaciones");
|
|
|
|
if (DdlEstatus.SelectedValue.Contiene("2", "4"))
|
|
{
|
|
DivMotivo.Visible = true;
|
|
TxtMotivo.Text = ObjBancos.DtResultados.FiltroPrimeroValor("Observaciones");
|
|
}
|
|
|
|
LblFecha.InnerHtml = String.Format("<b>Fecha Registro:</b> {0:g}", ObjBancos.DtResultados.FiltroPrimeroValor("FechaIng"));
|
|
|
|
BtnEliminar.Visible = true;
|
|
BtnGuardar.Text = "Actualizar";
|
|
|
|
CargaDetalles(ObjBancos);
|
|
|
|
}
|
|
else
|
|
{
|
|
CveSolicitudViatico = -1;
|
|
Alert("No tiene permisos para acceder a esta Solicitud.", ModExtensiones.TipoMensaje.MsgError);
|
|
CreaDTConceptosDetalles();
|
|
CargaFolio();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CveSolicitudViatico = -1;
|
|
Alert("La Solicitud de Viáticos solicitada no existe.", ModExtensiones.TipoMensaje.MsgError);
|
|
CreaDTConceptosDetalles();
|
|
}
|
|
}
|
|
|
|
ObjBancos.Dispose();
|
|
}
|
|
|
|
protected void CargaDetalles(ClsBancos ObjBancos)
|
|
{
|
|
if (ObjBancos.GetSolicitudesViaticosDetalle(CveSolicitudViatico, -1))
|
|
{
|
|
DTConceptosDetalles = ObjBancos.DtResultados;
|
|
CargaGVConceptosImportes(DTConceptosDetalles);
|
|
|
|
ImporteTotal = DTConceptosDetalles.SUM("Importe");
|
|
}
|
|
}
|
|
|
|
|
|
protected void CargaFolio()
|
|
{
|
|
int CveSubProyectoPersonal = GetCveSubproyecto();
|
|
|
|
if (CveSubProyectoPersonal > 0)
|
|
{
|
|
ClsBancos ObjBancos = new ClsBancos();
|
|
|
|
String Serie = get_GlobalDTSubProyectos(-1, CveSubProyectoPersonal, UsuarioActual.CveEmpresa).FiltroPrimeroValor("Serie");
|
|
|
|
if (ObjBancos.GetNextFolioSolicitudViaticos(UsuarioActual.CveEmpresa, String.Format("{0}-", Serie)))
|
|
{
|
|
TxtFolio.Text = ObjBancos.DtResultados.FiltroPrimeroValor("Folio");
|
|
TxtFolio.Enabled = false;
|
|
}
|
|
ObjBancos.Dispose();
|
|
}
|
|
}
|
|
|
|
protected int GetCveSubproyecto()
|
|
{
|
|
ClsRH ObjRH = new ClsRH();
|
|
|
|
int CveSubProyecto = -1;
|
|
|
|
if (ObjRH.GetPersonal(UsuarioActual.CvePersonal, UsuarioActual.CveEmpresa))
|
|
{
|
|
CveSubProyecto= ObjRH.DtResultados.FiltroPrimeroValor("CveSubProyecto").ToEntero();
|
|
}
|
|
|
|
|
|
ObjRH.Dispose();
|
|
return CveSubProyecto;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region "CONCEPTOS DETALLES"
|
|
protected void CargaConceptos()
|
|
{
|
|
ClsBancos ObjBancos = new ClsBancos();
|
|
if (ObjBancos.GetConceptosViaticos(UsuarioActual.CveEmpresa, 1))
|
|
{
|
|
DdlConceptoViatico.DataSource = ObjBancos.DtResultados;
|
|
DdlConceptoViatico.DataBind();
|
|
}
|
|
ObjBancos.Dispose();
|
|
UPDatos.Update();
|
|
}
|
|
|
|
protected void CreaDTConceptosDetalles()
|
|
{
|
|
DataTable dt = new DataTable();
|
|
|
|
//USAMOS CveSolicitudViaticoDetalle COMO CVETEMPORAL
|
|
DataColumn column = new DataColumn("CveSolicitudViaticoDetalle");
|
|
column.DataType = Type.GetType("System.Int32");
|
|
{
|
|
var withBlock = column;
|
|
withBlock.AutoIncrement = true;
|
|
withBlock.AutoIncrementSeed = 1;
|
|
withBlock.AutoIncrementStep = 1;
|
|
}
|
|
dt.Columns.Add(column);
|
|
|
|
dt.Columns.Add("CveSolicitudViatico", Type.GetType("System.Int32"));
|
|
dt.Columns.Add("CveConceptoViatico", Type.GetType("System.Int32"));
|
|
|
|
dt.Columns.Add("ConceptoViatico");
|
|
|
|
dt.Columns.Add("Importe", Type.GetType("System.Double"));
|
|
|
|
CargaGVConceptosImportes(dt);
|
|
|
|
DTConceptosDetalles = dt;
|
|
}
|
|
|
|
protected void CargaGVConceptosImportes(DataTable DtTemp)
|
|
{
|
|
GVConceptosImportes.DataSource = DtTemp;
|
|
GVConceptosImportes.DataBind();
|
|
}
|
|
|
|
|
|
protected void LbAgregar_Click(object sender, EventArgs e)
|
|
{
|
|
if (CveSolicitudViatico > 0)
|
|
{
|
|
ClsBancos ObjBancos = new ClsBancos();
|
|
if (ObjBancos.AddSolicitudesViaticosDetalle(CveSolicitudViatico, DdlConceptoViatico.SelectedValue.ToEntero(), TxtImporte.Text.ToDouble()))
|
|
{
|
|
Alert("El Detalle del Viático fue Agregado Correctamente.", ModExtensiones.TipoMensaje.MsgInformacion);
|
|
CargaDetalles(ObjBancos);
|
|
}
|
|
ObjBancos.Dispose();
|
|
}
|
|
else
|
|
{
|
|
DataRow registro = DTConceptosDetalles.NewRow();
|
|
|
|
registro["CveSolicitudViatico"] = -1;
|
|
registro["CveConceptoViatico"] = DdlConceptoViatico.SelectedValue.ToEntero();
|
|
registro["ConceptoViatico"] = DdlConceptoViatico.SelectedItem;
|
|
registro["Importe"] = TxtImporte.Text.ToDouble();
|
|
|
|
DTConceptosDetalles.Rows.Add(registro);
|
|
|
|
}
|
|
CargaGVConceptosImportes(DTConceptosDetalles);
|
|
LimpiaAgregarConceptos();
|
|
}
|
|
|
|
|
|
protected void GVConceptosImportes_RowEditing(object sender, GridViewEditEventArgs e)
|
|
{
|
|
GVConceptosImportes.EditIndex = e.NewEditIndex;
|
|
CargaGVConceptosImportes(DTConceptosDetalles);
|
|
}
|
|
|
|
protected void GVConceptosImportes_RowUpdating(object sender, GridViewUpdateEventArgs e)
|
|
{
|
|
Double Importe = GVConceptosImportes.Rows[e.RowIndex].FCTextBox("TxtImporteE").Text.ToDouble();
|
|
int CveDetalle = GVConceptosImportes.Rows[e.RowIndex].DataKey("CveSolicitudViaticoDetalle").ToEntero();
|
|
int CveConcepto = GVConceptosImportes.Rows[e.RowIndex].DataKey("CveConceptoViatico").ToEntero();
|
|
|
|
GVConceptosImportes.EditIndex = -1;
|
|
|
|
if (CveSolicitudViatico > 0)
|
|
{
|
|
ClsBancos ObjBancos = new ClsBancos();
|
|
if (ObjBancos.UpdateSolicitudesViaticosDetalle(CveDetalle, CveConcepto, Importe))
|
|
{
|
|
Alert("El Detalle del Viático fue Actualizado Correctamente.", ModExtensiones.TipoMensaje.MsgInformacion);
|
|
CargaDetalles(ObjBancos);
|
|
}
|
|
ObjBancos.Dispose();
|
|
}
|
|
else
|
|
{
|
|
DataRow RowUpp = DTConceptosDetalles.Select(String.Format("CveSolicitudViaticoDetalle = {0}", CveDetalle))[0];
|
|
|
|
if (RowUpp.Table.Rows.Count > 0)
|
|
{
|
|
RowUpp["Importe"] = Importe;
|
|
DTConceptosDetalles.AcceptChanges();
|
|
}
|
|
CargaGVConceptosImportes(DTConceptosDetalles);
|
|
}
|
|
|
|
}
|
|
|
|
protected void GVConceptosImportes_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
|
|
{
|
|
GVConceptosImportes.EditIndex = -1;
|
|
CargaGVConceptosImportes(DTConceptosDetalles);
|
|
}
|
|
|
|
protected void GVConceptosImportes_RowDeleting(object sender, GridViewDeleteEventArgs e)
|
|
{
|
|
Boolean ErrorEliminar = true;
|
|
|
|
int CveSolicitudViaticoDetalle = GVConceptosImportes.Rows[e.RowIndex].DataKey("CveSolicitudViaticoDetalle").ToEntero();
|
|
|
|
if (CveSolicitudViatico > 0)
|
|
{
|
|
ClsBancos ObjBancos = new ClsBancos();
|
|
if (ObjBancos.RemoveSolicitudesViaticosDetalle(CveSolicitudViaticoDetalle, -1))
|
|
{
|
|
Alert("El Detalle del Viático fue Eliminido Correctamente.", ModExtensiones.TipoMensaje.MsgInformacion);
|
|
CargaDetalles(ObjBancos);
|
|
}
|
|
ObjBancos.Dispose();
|
|
}
|
|
else
|
|
{
|
|
foreach (DataRow RowConcepto in DTConceptosDetalles.Rows)
|
|
{
|
|
if (RowConcepto["CveSolicitudViaticoDetalle"].ToEntero() == CveSolicitudViaticoDetalle)
|
|
{
|
|
DTConceptosDetalles.Rows.Remove(RowConcepto);
|
|
ErrorEliminar = false;
|
|
Alert("El Detalle del Viático fue Eliminido Correctamente.", ModExtensiones.TipoMensaje.MsgInformacion);
|
|
CargaGVConceptosImportes(DTConceptosDetalles);
|
|
break;
|
|
}
|
|
}
|
|
if (ErrorEliminar)
|
|
{
|
|
Alert("Ocurrio un error al eliminar el Detalle del Viático.", ModExtensiones.TipoMensaje.MsgError);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void LimpiaAgregarConceptos()
|
|
{
|
|
DdlConceptoViatico.SelectedValue = "-1";
|
|
TxtImporte.Text = "0.0";
|
|
}
|
|
|
|
protected void GVConceptosImportes_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
if (e.Row.RowType == DataControlRowType.Footer)
|
|
{
|
|
e.Row.FCLiteral("LtTotalImporte").Text = DTConceptosDetalles.SUM("Importe").FormatoNumero();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region "GUARDAR"
|
|
protected void BtnGuardar_Click(object sender, EventArgs e)
|
|
{
|
|
Boolean ErrorGuardar = false;
|
|
Boolean ErrorEditar = false;
|
|
Boolean EsEditar = false;
|
|
|
|
if (DTConceptosDetalles.Rows.Count > 0)
|
|
{
|
|
if (TxtFolio.Text == "")
|
|
{
|
|
Alert("El Campo Folio es necesario.", ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
return;
|
|
}
|
|
|
|
ClsBancos ObjBancos = new ClsBancos();
|
|
|
|
ObjBancos.IniciaTransacSQL();
|
|
|
|
if (CveSolicitudViatico > 0)
|
|
{
|
|
//EDITA SOLICITUDES
|
|
EsEditar = true;
|
|
ErrorEditar = ObjBancos.UpdateSolicitudesViaticos(CveSolicitudViatico, DdlEstatus.SelectedValue.ToEntero(), TxtDestino.Text, TxtAsunto.Text, TxtFechaSalida.Text, TxtFechaRegreso.Text, TxtMotivo.Text == "" ? "-1" : TxtMotivo.Text, TipoCarro:TxtTipoCarro.Text, KM: TxtKM.Text);
|
|
}
|
|
else
|
|
{
|
|
//GUARDA SOLICITUDES NUEVAS
|
|
CveSolicitudViatico = ObjBancos.AddSolicitudesViaticos(TxtFolio.Text, DdlEstatus.SelectedValue.ToEntero(), DdlPersonal.SelectedValue.ToEntero(), TxtDestino.Text, TxtAsunto.Text, TxtFechaSalida.Text, TxtFechaRegreso.Text, DateTime.Now, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, TipoCarro: TxtTipoCarro.Text, KM: TxtKM.Text);
|
|
if (CveSolicitudViatico > 0)
|
|
{
|
|
foreach (DataRow RowConcepto in DTConceptosDetalles.Rows)
|
|
{
|
|
if (!ObjBancos.AddSolicitudesViaticosDetalle(CveSolicitudViatico, RowConcepto["CveConceptoViatico"].ToString().ToEntero(), RowConcepto["Importe"].ToString().ToEntero()))
|
|
{
|
|
ErrorGuardar = true;
|
|
}
|
|
}
|
|
if (!ErrorGuardar)
|
|
{
|
|
StringBuilder Mensaje = new StringBuilder();
|
|
Mensaje.AppendLine(String.Format("La Solicitud de Viáticos con Folio <b>{0}</b> se guardo correctamente.", TxtFolio.Text));
|
|
|
|
|
|
BtnEliminar.Visible = true;
|
|
|
|
string Destinatario = "";
|
|
|
|
if (UsuarioActual.CveEmpresa.Contiene(72))
|
|
{
|
|
Destinatario = "recursoshumanos@compuproveedores.com";
|
|
}
|
|
if (EnviarCorreoNuevaSolicitud(Destinatario))
|
|
{
|
|
Mensaje.AppendLine(String.Format("<br /><br />Se ha notificado al correo <b>{0}</b>", Destinatario));
|
|
}
|
|
Alert(Mensaje.ToString(), ModExtensiones.TipoMensaje.MsgInformacion);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ErrorGuardar = true;
|
|
}
|
|
}
|
|
|
|
if (ErrorGuardar)
|
|
{
|
|
ObjBancos.RollBack();
|
|
}
|
|
else
|
|
{
|
|
ObjBancos.Commit();
|
|
}
|
|
|
|
ObjBancos.Dispose();
|
|
|
|
//NOTIFICACION Y CORREO DEL UPDATE
|
|
if (EsEditar && ErrorEditar)
|
|
{
|
|
StringBuilder Mensaje = new StringBuilder();
|
|
|
|
Mensaje.AppendLine("La Solicitud de Viáticos fue Actualizada Correctamente.");
|
|
|
|
if (DdlEstatus.SelectedValue.Contiene("2", "3", "4"))
|
|
{
|
|
if (EnviarCorreoSolicitante())
|
|
{
|
|
String DestinatarioCorreo = get_GlobalDTRHPersonal(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Correo", String.Format("CvePersonal={0}", DdlPersonal.SelectedValue.ToEntero()));
|
|
Mensaje.AppendLine(String.Format("<br /><br />Se ha notificado al correo <b>{0}</b>", DestinatarioCorreo));
|
|
}
|
|
else
|
|
{
|
|
Mensaje.AppendLine(String.Format("<br /><br />Ocurrio un error al notificar al Solicitante."));
|
|
}
|
|
}
|
|
|
|
Alert(Mensaje.ToString(), ModExtensiones.TipoMensaje.MsgInformacion);
|
|
}
|
|
|
|
if (!ErrorGuardar)
|
|
{
|
|
CargaDatosPersonal();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Alert("No hay ningun registro de Concepto Viático para generar la solicitud. Por favor rectifique y vuelva a intentar.", ModExtensiones.TipoMensaje.MsgError);
|
|
}
|
|
}
|
|
|
|
|
|
protected void BtnNuevo_Click(object sender, EventArgs e)
|
|
{
|
|
CveSolicitudViatico = -1;
|
|
|
|
DTConceptosDetalles = new DataTable();
|
|
|
|
LimpiaSolicitud();
|
|
}
|
|
|
|
protected void LimpiaSolicitud()
|
|
{
|
|
|
|
TxtFolio.Text = "";
|
|
TxtDestino.Text = "";
|
|
TxtAsunto.Text = "";
|
|
TxtFechaSalida.Text = "";
|
|
TxtFechaRegreso.Text = "";
|
|
|
|
TxtFolio.Enabled = true;
|
|
BtnEliminar.Visible = false;
|
|
|
|
DdlEstatus.SelectedValue = "1";
|
|
|
|
CargaDatosPersonal();
|
|
LimpiaAgregarConceptos();
|
|
}
|
|
|
|
protected void BtnEliminar_Click(object sender, EventArgs e)
|
|
{
|
|
ClsBancos ObjBancos = new ClsBancos();
|
|
|
|
ObjBancos.IniciaTransacSQL();
|
|
|
|
if (CveSolicitudViatico > 0 && ObjBancos.RemoveSolicitudesViaticosDetalle(-1, CveSolicitudViatico))
|
|
{
|
|
if (ObjBancos.RemoveSolicitudesViaticos(CveSolicitudViatico))
|
|
{
|
|
Alert("La Solicitud de Viáticos fue Eliminada.", ModExtensiones.TipoMensaje.MsgInformacion);
|
|
ObjBancos.Commit();
|
|
CveSolicitudViatico = -1;
|
|
}
|
|
else
|
|
{
|
|
ObjBancos.RollBack();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ObjBancos.RollBack();
|
|
}
|
|
ObjBancos.Dispose();
|
|
|
|
if (CveSolicitudViatico == -1)
|
|
{
|
|
CargaDatosPersonal();
|
|
LimpiaSolicitud();
|
|
}
|
|
}
|
|
|
|
protected void DdlEstatus_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (DdlEstatus.SelectedValue.Contiene("2", "4"))
|
|
{
|
|
DivMotivo.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
DivMotivo.Visible = false;
|
|
TxtMotivo.Text = "";
|
|
}
|
|
UpSolicitud.Update();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region "PDF"
|
|
protected void LnkImprimirPDF_Click(object sender, EventArgs e)
|
|
{
|
|
GenerarPDF("PDF");
|
|
}
|
|
protected void LnkImprimirExcel_Click(object sender, EventArgs e)
|
|
{
|
|
GenerarPDF("Excel");
|
|
}
|
|
|
|
private byte[] GenerarPDF(string Formato = "PDF", Boolean DesgargaArchivo = true)
|
|
{
|
|
byte[] retorno = null;
|
|
|
|
if (UsuarioActual.CveEmpresa == 1 || UsuarioActual.CveEmpresa == 2 || UsuarioActual.CveEmpresa == 72)
|
|
{
|
|
List<ReportParameter> @params = new List<ReportParameter>();
|
|
|
|
ClsBancos ObjBancos = new ClsBancos();
|
|
|
|
if (ObjBancos.GetSolicitudesViaticos(CveSolicitudViatico, UsuarioActual.CveEmpresa) && ObjBancos.DtResultados.Rows.Count > 0)
|
|
{
|
|
@params.Add(new ReportParameter("FolioViatico", ObjBancos.DtResultados.FiltroPrimeroValor("Folio")));
|
|
@params.Add(new ReportParameter("FechaRegistro", ObjBancos.DtResultados.FiltroPrimeroValor("FechaIng")));
|
|
|
|
@params.Add(new ReportParameter("FechaSalida", Convert.ToDateTime(ObjBancos.DtResultados.FiltroPrimeroValor("FechaSalida")).ToShortDateString()));
|
|
@params.Add(new ReportParameter("FechaRegreso", Convert.ToDateTime(ObjBancos.DtResultados.FiltroPrimeroValor("FechaRegreso")).ToShortDateString()));
|
|
@params.Add(new ReportParameter("NombreSolicitante", ObjBancos.DtResultados.FiltroPrimeroValor("NombrePersonal")));
|
|
@params.Add(new ReportParameter("Departamento", ObjBancos.DtResultados.FiltroPrimeroValor("DepartamentoSolicitante")));
|
|
@params.Add(new ReportParameter("SupervisorDirecto", ObjBancos.DtResultados.FiltroPrimeroValor("NombreSupervisor")));
|
|
@params.Add(new ReportParameter("Destino", ObjBancos.DtResultados.FiltroPrimeroValor("Destino")));
|
|
@params.Add(new ReportParameter("Asunto", ObjBancos.DtResultados.FiltroPrimeroValor("Asunto")));
|
|
@params.Add(new ReportParameter("TipoCarro", ObjBancos.DtResultados.FiltroPrimeroValor("TipoCarro")));
|
|
@params.Add(new ReportParameter("KM", ObjBancos.DtResultados.FiltroPrimeroValor("KM")));
|
|
@params.Add(new ReportParameter("FirmaRH", ""));
|
|
@params.Add(new ReportParameter("FirmaFinanzas", ""));
|
|
|
|
@params.Add(new ReportParameter("ImporteTotal", ImporteTotal.ToString()));
|
|
@params.Add(new ReportParameter("ImporteLetra", ImporteTotal.Texto2Letras()));
|
|
|
|
@params.Add(new ReportParameter("DireccionSolicitante", ObjBancos.DtResultados.FiltroPrimeroValor("DireccionPersonal")));
|
|
@params.Add(new ReportParameter("CiudadSolicitante", ObjBancos.DtResultados.FiltroPrimeroValor("CiudadPersonal")));
|
|
@params.Add(new ReportParameter("TelefonoSolicitante", ObjBancos.DtResultados.FiltroPrimeroValor("TelefonoPersonal")));
|
|
|
|
@params.Add(new ReportParameter("Empresa", UsuarioActual.Empresa.Empresa));
|
|
@params.Add(new ReportParameter("FechaImpresion", DateTime.Now.ToShortDateString()));
|
|
@params.Add(new ReportParameter("UsuarioImprimio", UsuarioActual.Nombre));
|
|
|
|
@params.Add(new ReportParameter("TotalADepositar", (ObjBancos.DtResultados.FiltroPrimeroValor("TotalADepositar").ToDouble() > 0 ? ObjBancos.DtResultados.FiltroPrimeroValor("TotalADepositar") : "0").ToString()));
|
|
|
|
var logouri = string.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa);
|
|
System.IO.FileInfo Imagen = new System.IO.FileInfo($"{UsuarioActual.Empresa.Ruta}/Logo.png");
|
|
|
|
if (Imagen.Exists)
|
|
{
|
|
@params.Add(new ReportParameter("LogoPath", $"file://{Imagen.FullName}"));
|
|
}
|
|
else
|
|
{
|
|
@params.Add(new ReportParameter("LogoPath", ""));
|
|
}
|
|
|
|
|
|
if (DesgargaArchivo)
|
|
{
|
|
ImprimirPDF(string.Format("Empresas/{0}/Formatos/SolicitudViaticos.rdlc",UsuarioActual.CveEmpresa), DTConceptosDetalles, @params, String.Format("Solicitud de Viáticos - {0} - {1}", TxtFolio.Text, DdlPersonal.SelectedItem), Formato);
|
|
}
|
|
else
|
|
{
|
|
retorno = StreamPDF(string.Format("Empresas/{0}/Formatos/SolicitudViaticos.rdlc", UsuarioActual.CveEmpresa), DTConceptosDetalles, @params, String.Format("Solicitud de Viáticos - {0} - {1}", TxtFolio.Text, DdlPersonal.SelectedItem), Formato);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Alert("Ocurrio un error al gerneral el reporte.", ModExtensiones.TipoMensaje.MsgError);
|
|
}
|
|
ObjBancos.Dispose();
|
|
}
|
|
|
|
return retorno;
|
|
}
|
|
#endregion
|
|
|
|
#region "VINCULACION CON EGRESOS POR COMPROBAR"
|
|
protected void LnkIE_Click(object sender, EventArgs e)
|
|
{
|
|
Confirmacion("Se le redireccionara para realizar el Egreso por Comprobar, ¿Desea continuar?", "", String.Format("document.location.href=\"/Bancos/IE.aspx?Opcion=EGSSINFACT&CveSolicitudViatico={0}&CvePersonal={1}&CveMoneda={2}&CveIE={3}\"", CveSolicitudViatico, DdlPersonal.SelectedValue, 1, CveIE), "");
|
|
}
|
|
#endregion
|
|
|
|
#region "ENVIO DE CORREOS"
|
|
protected Boolean EnviarCorreoNuevaSolicitud(string Destinatario)
|
|
{
|
|
ClsSisMail Correo = new ClsSisMail();
|
|
String Asunto = String.Format("{0} Nueva Solicitud de Viáticos: {1}", UsuarioActual.Empresa.NombreCorto, TxtFolio.Text);
|
|
StringBuilder Cuerpo = new StringBuilder();
|
|
|
|
Boolean MensajeEnviado = false;
|
|
|
|
// CORREO A USUARIO DENNISE CRUZ - RH
|
|
Cuerpo.AppendLine(String.Format("Se le informa que ha recibido una nueva Solicitud de Viáticos con folio <b>{2}</b> por parte del Personal {0} del Departamento de {1}.<br><br> Para mayor informacion consulte el módulo de <a href=\"http://sig.adssistemas.mx/RH/ReporteViaticos.aspx\">Solicitud de Viáticos</a>.", UsuarioActual.Nombre.ToUpper(), DdlDepartamento.SelectedItem, TxtFolio.Text));
|
|
|
|
if (UsuarioActual.CveEmpresa.Contiene(72, 1, 2))
|
|
{
|
|
|
|
if (Destinatario.Length > 0 && Correo.SendMail(UsuarioActual.Empresa, Destinatario, Asunto, Cuerpo.ToString()))
|
|
{
|
|
MensajeEnviado = true;
|
|
}
|
|
else
|
|
{
|
|
MensajeEnviado = false;
|
|
}
|
|
}
|
|
|
|
return MensajeEnviado;
|
|
}
|
|
|
|
protected Boolean EnviarCorreoSolicitante()
|
|
{
|
|
ClsSisMail Correo = new ClsSisMail();
|
|
String Asunto = String.Format("{0} Actualización de Solicitud de Viaticos {1}", UsuarioActual.Empresa.NombreCorto, TxtFolio.Text);
|
|
StringBuilder Cuerpo = new StringBuilder();
|
|
List<ClsSisMail.ArchivoMail> LSRutasMail = new List<ClsSisMail.ArchivoMail>();
|
|
|
|
Boolean MensajeEnviado = false;
|
|
|
|
Boolean ErrorArchivo = false;
|
|
|
|
// CORREO A SOLICITANTE
|
|
String DestinatarioNombre = get_GlobalDTRHPersonal(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Nombre", String.Format("CvePersonal={0}", DdlPersonal.SelectedValue.ToEntero())).ToUpper();
|
|
Cuerpo.AppendLine(String.Format("Estimado {0},<br><br> se le informa que la Solicitud de Viáticos con folio <b>{1}</b> ha sido {2}", DestinatarioNombre, TxtFolio.Text, DdlEstatus.SelectedItem));
|
|
|
|
if (DdlEstatus.SelectedValue.Contiene("2", "4"))
|
|
{
|
|
Cuerpo.AppendLine(String.Format(" con motivo: {0}.", TxtMotivo.Text));
|
|
}
|
|
else if (DdlEstatus.SelectedValue.Contiene("3"))
|
|
{
|
|
Cuerpo.AppendLine(String.Format(". Descargue el siguiente archivo para continuar con el proceso.<br><br>"));
|
|
|
|
ClsSisMail.ArchivoMail Archivo = new ClsSisMail.ArchivoMail();
|
|
Archivo.ArchivoBinario = GenerarPDF("PDF", false);
|
|
Archivo.NombreArchivo = String.Format("Solicitud de Viaticos - {0} - {1}.pdf", TxtFolio.Text, DdlPersonal.SelectedItem);
|
|
LSRutasMail.Add(Archivo);
|
|
|
|
if (Archivo.ArchivoBinario == null)
|
|
{
|
|
ErrorArchivo = true;
|
|
}
|
|
}
|
|
|
|
if (UsuarioActual.CveEmpresa.Contiene(72, 1, 2))
|
|
{
|
|
|
|
String DestinatarioCorreo = get_GlobalDTRHPersonal(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Correo", String.Format("CvePersonal={0}", DdlPersonal.SelectedValue.ToEntero()));
|
|
|
|
if (!ErrorArchivo && Correo.SendMail(UsuarioActual.Empresa, DestinatarioCorreo, Asunto, Cuerpo.ToString(), Archivos: LSRutasMail))
|
|
{
|
|
MensajeEnviado = true;
|
|
}
|
|
else
|
|
{
|
|
MensajeEnviado = false;
|
|
}
|
|
}
|
|
|
|
return MensajeEnviado;
|
|
}
|
|
#endregion
|
|
|
|
} |