Beispiel #1
0
    public static string getFechaUltImputacion()
    {
        DBConn DBConn = new DBConn();

        IB.sqldblib.SqlServerSP cDblib = DBConn.dblibclass;

        BLL.Usuario           usuarioBLL           = new BLL.Usuario(cDblib);
        BLL.JornadaCalendario jornadaCalendarioBLL = new BLL.JornadaCalendario(cDblib);
        Models.Usuario        oUsuario             = new Models.Usuario();
        try
        {
            //Se comprueba si hay huecos por el proceso de imputación de vacaciones para proponerle como fecha inicio el primer hueco en vez del siguiente día imputable a la última fecha de imputación
            DateTime fechaAnteriorPrimerHueco = jornadaCalendarioBLL.anteriorPrimerHueco((int)(HttpContext.Current.Session["NUM_EMPLEADO_IAP"]), (int)HttpContext.Current.Session["IDCALENDARIO_IAP"], (int)HttpContext.Current.Session["UMC_IAP"], (string)HttpContext.Current.Session["FEC_ALTA"], (string)HttpContext.Current.Session["FEC_BAJA"]);
            DateTime fecha = usuarioBLL.GetFechaUltImputacion((int)HttpContext.Current.Session["UsuarioActual"]).fUltImputacion;

            if (fechaAnteriorPrimerHueco < fecha)
            {
                fecha = fechaAnteriorPrimerHueco;
            }

            return(fecha.ToShortDateString());
        }
        catch (Exception ex)
        {
            LogError.LogearError("Error al obtener la fecha de última imputación", ex);
            throw new Exception(System.Uri.EscapeDataString("No se han podido obtener la fecha de última imputación del profesional."));
        }
        finally
        {
            usuarioBLL.Dispose();
            jornadaCalendarioBLL.Dispose();
            DBConn.Dispose();
        }
    }
Beispiel #2
0
    public static string grabarImputacionMasiva(string idTarea, string tipoImp, string ultDiaReport, string fechaDesde, string fechaHasta,
                                                string cmbModo, Int32 festivos, Int32 finalizado, string horas, string obsImputacion,
                                                string obsTecnico, string totalEst, string fechaFinEst, Int32 obligaEst, Int32 PSN)
    {
        //bool bHuecoControlado = false;//bAvisado = false, bError = false;
        bool   bJornadaReducida = false;
        string sRes             = "Grabación correcta.";

        BLL.Usuario    bUsuario = new BLL.Usuario();
        Models.Usuario cUsuario = new Models.Usuario();
        Models.Usuario cUser    = new Models.Usuario();

        try
        {
            int idCalendario  = int.Parse(HttpContext.Current.Session["IDCALENDARIO_IAP"].ToString());
            int idUser        = int.Parse(HttpContext.Current.Session["UsuarioActual"].ToString());
            int idUserEntrada = int.Parse(HttpContext.Current.Session["NUM_EMPLEADO_ENTRADA"].ToString());

            #region Control de jornada reducida
            bJornadaReducida = (bool)HttpContext.Current.Session["JORNADA_REDUCIDA"];
            double   nHorasRed = 0;
            DateTime?dDesdeRed = null;
            DateTime?dHastaRed = null;
            if (bJornadaReducida)
            {
                nHorasRed = double.Parse(HttpContext.Current.Session["NHORASRED"].ToString());
                dDesdeRed = DateTime.Parse(HttpContext.Current.Session["FECDESRED"].ToString());
                dHastaRed = DateTime.Parse(HttpContext.Current.Session["FECHASRED"].ToString());
            }
            #endregion

            cUsuario = bUsuario.ObtenerRecurso(HttpContext.Current.Session["IDRED"].ToString(), ((int)HttpContext.Current.Session["UsuarioActual"] == 0) ? null : (int?)int.Parse(HttpContext.Current.Session["UsuarioActual"].ToString()));

            #region Ultimo mes cerrado IAP (Si el usuario tiene nodo el del nodo, sino el de empresa)
            HttpContext.Current.Session["UMC_IAP"] = cUsuario.t303_ultcierreIAP;
            #endregion
            #region Obtención de datos de la pantalla

            int      nOpcion  = int.Parse(tipoImp);                //Tipo imputación
            int      nTarea   = int.Parse(idTarea);                //Código de tarea
            DateTime dUDR     = DateTime.Parse(ultDiaReport);      //Último día reportado
            DateTime dDesde   = DateTime.Parse(fechaDesde);        //Fecha desde
            DateTime dHasta   = DateTime.Parse(fechaHasta);        //Fecha hasta
            int      nDifDias = Fechas.DateDiff("day", dDesde, dHasta);
            int      nModo    = int.Parse(cmbModo);                //Modo (Sustitución o Acumulación)

            bool   bFestivos   = (festivos == 1) ? true : false;   //Incluir no laborables y festivos
            bool   bFinalizado = (finalizado == 1) ? true : false; //Tarea finalizada
            double nHoras      = double.Parse(horas);              //Número de horas

            double   nETE = double.Parse(totalEst);                //Total estimado
            DateTime?dFFE = null;
            if (fechaFinEst != "")
            {
                dFFE = DateTime.Parse(fechaFinEst);            //Fecha fin estimación
            }
            bool bObligaest = (obligaEst == 1) ? true : false; //Obligatorio estimar
            int  nPSN       = PSN;                             //Código de proyectosubnodo
            #endregion

            cUser = bUsuario.Grabar(idCalendario, idUser, idUserEntrada,
                                    HttpContext.Current.Session["IDRED"].ToString(),
                                    cUsuario.t303_ultcierreIAP,
                                    HttpContext.Current.Session["DES_EMPLEADO_IAP"].ToString(),
                                    HttpContext.Current.Session["DES_EMPLEADO_ENTRADA"].ToString(),
                                    bJornadaReducida, nHorasRed, dDesdeRed, dHastaRed,
                                    nTarea, nOpcion, dUDR, dDesde, dHasta, nModo, bFestivos, bFinalizado, nHoras,
                                    obsImputacion, obsTecnico, nETE, dFFE, bObligaest, nPSN);
            //Actualizo la vble de sesión con la última fecha de imputación
            cUsuario = bUsuario.GetFechaUltImputacion(idUser);
            HttpContext.Current.Session["FEC_ULT_IMPUTACION"] = cUsuario.fUltImputacion.ToShortDateString();
            try
            {
                if (cUser.aListCorreo.Count > 0)
                {
                    SUPER.Capa_Negocio.Correo.EnviarCorreos(cUser.aListCorreo);
                }
            }
            catch (Exception ex)
            {
                //sResul = "Error@#@" + Errores.mostrarError("Error al enviar el mail a los responsables del proyecto", ex);
                IB.SUPER.Shared.LogError.LogearError("Error al enviar el mail a los responsables del proyecto", ex);
            }
            //bUsuario.Dispose();

            return(sRes);
        }
        catch (Exception ex)
        {
            //if (bErrorControlado)
            //    throw new ValidationException(System.Uri.EscapeDataString(sMsg));
            //else
            throw new ValidationException(System.Uri.EscapeDataString(ex.Message));
            //throw new ValidationException(System.Uri.EscapeDataString("Error en la grabación de la imputación masiva"));
        }

        finally
        {
            bUsuario.Dispose();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            #region Variables cliente (luego bajar)
            this.Head.PreCss = Session["strServer"].ToString() + "Capa_Presentacion/IAP30/css/IAP30.css";

            #endregion
            #region Recogida de parámetros y control de usuario

            nCurrentMonth = DateTime.Now.Month;
            nCurrentYear  = DateTime.Now.Year;

            string sOrigen = "";
            if (Request.QueryString["or"] != null)
            {
                if (Request.QueryString["or"].ToString() != "")
                {
                    sOrigen = SUPER.Capa_Negocio.Utilidades.decodpar(Request.QueryString["or"].ToString());
                }
            }

            if (sOrigen == "menu")
            {
                string sNumEmpleadoIAP = "", sUsuarioActual = "";
                if (Session["NUM_EMPLEADO_IAP"] != null)
                {
                    sNumEmpleadoIAP = Session["NUM_EMPLEADO_IAP"].ToString();
                }
                if (Session["UsuarioActual"] != null)
                {
                    sUsuarioActual = Session["UsuarioActual"].ToString();
                }
                if (sUsuarioActual != sNumEmpleadoIAP)
                {
                    BLL.Usuario    bUsuario = new BLL.Usuario();
                    Models.Usuario cUsuario = new Models.Usuario();

                    try
                    {
                        if (sUsuarioActual != "")
                        {
                            cUsuario = bUsuario.ObtenerRecursoReducido((int)Session["UsuarioActual"]);
                        }
                        //else
                        // cUsuario = bUsuario.ObtenerRecursoReducido(null);
                    }
                    finally
                    {
                        bUsuario.Dispose();
                    }

                    if (cUsuario != null)
                    {
                        #region Variables necesarias para IAP

                        Session["IDFICEPI_IAP"] = cUsuario.t001_IDFICEPI;
                        //Session["NUM_EMPLEADO_IAP"] = cUsuario.t314_idusuario.ToString();
                        Session["NUM_EMPLEADO_IAP"] = cUsuario.t314_idusuario;
                        if (Session["UsuarioActual"] == null)
                        {
                            Session["UsuarioActual"] = cUsuario.t314_idusuario.ToString();
                        }
                        Session["DES_EMPLEADO_IAP"]   = cUsuario.NOMBRE + " " + cUsuario.APELLIDO1 + " " + cUsuario.APELLIDO2;
                        Session["IDRED_IAP"]          = cUsuario.t001_codred;
                        Session["JORNADA_REDUCIDA"]   = cUsuario.t314_jornadareducida;
                        Session["CONTROLHUECOS"]      = cUsuario.t314_controlhuecos;
                        Session["IDCALENDARIO_IAP"]   = cUsuario.IdCalendario;
                        Session["DESCALENDARIO_IAP"]  = cUsuario.desCalendario;
                        Session["FEC_ULT_IMPUTACION"] = cUsuario.fUltImputacion.ToShortDateString();
                        Session["FEC_ALTA"]           = cUsuario.t314_falta.ToShortDateString();
                        Session["FEC_BAJA"]           = (!Convert.IsDBNull(cUsuario.t314_fbaja)) ? ((DateTime)cUsuario.t314_fbaja).ToShortDateString() : null;
                        Session["UMC_IAP"]            = (!Convert.IsDBNull(cUsuario.t303_ultcierreIAP)) ? (int?)cUsuario.t303_ultcierreIAP : DateTime.Now.AddMonths(-1).Year * 100 + DateTime.Now.AddMonths(-1).Month;
                        Session["NHORASRED"]          = cUsuario.t314_horasjor_red;
                        Session["FECDESRED"]          = (!Convert.IsDBNull(cUsuario.t314_fdesde_red)) ? ((DateTime)cUsuario.t314_fdesde_red).ToShortDateString() : null;
                        Session["FECHASRED"]          = (!Convert.IsDBNull(cUsuario.t314_fhasta_red)) ? ((DateTime)cUsuario.t314_fhasta_red).ToShortDateString() : null;
                        Session["aSemLab"]            = cUsuario.t066_semlabL + "," + cUsuario.t066_semlabM + "," + cUsuario.t066_semlabX + "," + cUsuario.t066_semlabJ + "," + cUsuario.t066_semlabV + "," + cUsuario.t066_semlabS + "," + cUsuario.t066_semlabD;
                        Session["SEXOUSUARIO"]        = cUsuario.t001_sexo;
                        #endregion
                    }
                    else
                    {
                        string script2 = "IB.vars.error = 'No se han podido obtener los datos del usuario actual.';";
                        Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "script2", script2, true);
                        return;
                    }
                }
            }
            else
            {
                //Cuando regresa de la pantalla de imputación diaria, debe recoger los parámetros mes y anno para cargar el calendario en esa fecha
                Hashtable ht = Utils.ParseQuerystring(Request.QueryString.ToString());
                nCurrentMonth = int.Parse(ht["im"].ToString()) + 1;
                nCurrentYear  = int.Parse(ht["ia"].ToString());
            }

            string script1 = "IB.vars.idficepi = '" + Session["IDFICEPI_IAP"] + "';";
            script1 += "IB.vars.codUsu = '" + Session["NUM_EMPLEADO_IAP"].ToString() + "';";
            script1 += "IB.vars.UMC_IAP = '" + Session["UMC_IAP"].ToString() + "';";
            script1 += "IB.vars.FechaUltimaImputacion = '" + Session["FEC_ULT_IMPUTACION"].ToString() + "';";
            bool sControlHuecos = ((bool)Session["CONTROLHUECOS"]) ? true : false;
            script1 += "IB.vars.controlhuecos = '" + sControlHuecos + "';";
            script1 += "IB.vars.aSemLab = '" + Session["aSemLab"] + "';";
            script1 += "IB.vars.reconectar_msg = '" + Session["reconectar_msg_iap"].ToString() + "';";
            string sDia   = DateTime.Now.Day.ToString();
            string sMonth = (DateTime.Now.Month - 1).ToString();
            if (sDia.Length == 1)
            {
                sDia = "0" + sDia;
            }
            if (sMonth.Length == 1)
            {
                sMonth = "0" + sMonth;
            }
            script1 += "IB.vars.oDiaActual =  '" + sDia + "/" + sMonth + "/" + DateTime.Now.Year + "';";

            script1 += "IB.vars.nCurrentMonth = '" + nCurrentMonth + "';";
            script1 += "IB.vars.nCurrentYear = '" + nCurrentYear + "';";

            if (Session["IDCALENDARIO_IAP"] == null)
            {
                string script3 = "IB.vars.error = 'No hay un calendario asignado para el usuario actual. Contacte con el administrador.';";
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "script3", script3, true);
                return;
            }
            else
            {
                script1 += "IB.vars.codCal = '" + (int)Session["IDCALENDARIO_IAP"] + "';";
            }

            // Opción reconexión
            BLL.FestivosCals cFestivosCals = new BLL.FestivosCals();
            try
            {
                cFestivosCals.obtenerOpcionReconexion();
                cFestivosCals.Dispose();
                script1 += "IB.vars.nReconectar = '" + Session["reconectar_iap"].ToString() + "';";
                script1 += "IB.vars.perfil = '" + Session["perfil_iap"].ToString() + "';";
            }
            catch (Exception ex)
            {
                cFestivosCals.Dispose();
                string script4 = "IB.vars.error = 'Error al establecer la opción de reconexión. Contacte con el administrador.';";
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "script4", script4, true);
                return;
            }
            Session["reconectar_msg_iap"] = (int)Session["reconectar_msg_iap"] + 1;

            BLL.JornadaCalendario jornadaCalendarioBLL = new BLL.JornadaCalendario();
            try
            {
                script1 += "IB.vars.anteriorprimerhueco = '" + jornadaCalendarioBLL.anteriorPrimerHueco((int)(Session["NUM_EMPLEADO_IAP"]), (int)Session["IDCALENDARIO_IAP"], (int)Session["UMC_IAP"], (string)HttpContext.Current.Session["FEC_ALTA"], (string)HttpContext.Current.Session["FEC_BAJA"]).ToShortDateString() + "';";
            }
            catch (Exception ex)
            {
                string script4 = "IB.vars.error = 'Error al obtener las jornadas del calendario. Contacte con el administrador.';";
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "script5", script4, true);
                return;
            }
            finally
            {
                jornadaCalendarioBLL.Dispose();
            }

            //registramos en un form runat='server'
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "script1", script1, true);

            #endregion
        }
        catch (Exception ex)
        {
            string script1 = "IB.vars.error = 'Error al cargar la pantalla';";
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "script1", script1, true);
        }
    }