Пример #1
0
        public Boolean ModificaEstructura(MssBD.Usuarios _usu, MssBD.EstructuraSueldos _estr)
        {
            try
            {
                var _act = (from p in Modelo_BDMSS.EstructuraSueldos
                            where p.Estructura_Codigo == _estr.Estructura_Codigo
                            select p).First();

                _act.Descripcion    = _estr.Descripcion;
                _act.SueldoBase     = _estr.SueldoBase;
                _act.Gratificacion  = _estr.Gratificacion;
                _act.BonoAsistencia = _estr.BonoAsistencia;
                _act.BonoProduccion = _estr.BonoProduccion;
                _act.Colacion       = _estr.Colacion;
                _act.Movilizacion   = _estr.Movilizacion;
                _act.BonoTurno      = _estr.BonoTurno;

                Modelo_BDMSS.SaveChanges();

                _log.IngresaLog(_usu, String.Concat(_usu.Usuario_Nombre, "ha modificado Estructura de Sueldo ", _estr.Estructura_Codigo));

                return(true);
            }
            catch (Exception ex)
            {
                return(false);

                throw ex;
            }
        }
Пример #2
0
        public bool CambioContraseña(MssBD.Usuarios _usuCambio)
        {
            try
            {
                var _act = (from p in Modelo_BDMSS.Usuarios
                            where p.Usuario_Nombre == _usuCambio.Usuario_Nombre
                            select p).First();

                _act.Usuario_Password = _usuCambio.Usuario_Password;
                Modelo_BDMSS.SaveChanges();

                return(true);
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);
                    }
                }
                throw;
            }
            catch (Exception ex)
            {
                return(false);

                throw ex;
            }
        }
Пример #3
0
        public Boolean RegistrarDocumento(Int32 DocumentoTipo_Id
                                          , MssBD.Usuarios _usu
                                          , MssBD.CON_Empleados_Rut_Centro_Result _per
                                          , bool PorVisar
                                          , string RutaFinal
                                          , ref String Mensaje
                                          , ref Int32 Doc_Id)
        {
            try
            {
                MssBD.Documentos _doc = new MssBD.Documentos();
                _doc.DocumentoTipo_Id = DocumentoTipo_Id;
                _doc.Fecha            = DateTime.Now;
                _doc.Personal_Id      = _per.Rut;
                _doc.PorVisar         = true;
                _doc.RutaFinal        = RutaFinal;
                _doc.Usuario_Id       = _usu.Usuario_Id;

                Modelo_BDMSS.Documentos.Add(_doc);
                Modelo_BDMSS.SaveChanges();

                switch (DocumentoTipo_Id)
                {
                case 1:
                    Mensaje = "Se ha registrado Contrato. Dar a conocer a Administrador para su visado.";
                    break;

                case 2:
                    Mensaje = "Se ha registrado Anexo. Dar a conocer a Administrador para su visado.";
                    break;

                case 3:
                    Mensaje = "Se ha registrado Finiquito. Dar a conocer a Administrador para su visado.";
                    break;

                default:
                    break;
                }

                try
                {
                    Doc_Id = Modelo_BDMSS.Documentos.Where(doc => doc.Documento_Id == doc.Documento_Id)
                             .Max(doc => doc.Documento_Id);
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #4
0
        public Boolean RegistrarContrato(Int32 DocumentoTipo_Id
                                         , MssBD.Usuarios _usu
                                         , MssBD.CON_Empleados_Rut_Centro_Result _per
                                         , bool PorVisar
                                         , string RutaFinal
                                         , ref String Mensaje
                                         , Int32 Doc_Id)
        {
            try
            {
                MssBD.Contratos _con = new MssBD.Contratos();
                _con.Afp_Id              = _per.Afp_Id;
                _con.CentroCosto_Id      = _per.CentroCosto_Id;
                _con.Documento_Id        = Doc_Id;
                _con.EstructuraSueldo_Id = _per.EstructuraSueldo_Id;
                _con.FechaDesde          = _per.FechaIngreso.Value;
                _con.FechaHasta          = _per.FechaVencimiento.Value;
                _con.Isapre_Id           = _per.Isapre_Id;
                _con.TipoContrato        = _per.TipoContrato;

                Modelo_BDMSS.Contratos.Add(_con);
                Modelo_BDMSS.SaveChanges();

                _log.IngresaLog(_usu, String.Concat(_usu.Usuario_Nombre, " ha registrado Contratos de ", _per.Rut, "-", _per.Dv));

                switch (DocumentoTipo_Id)
                {
                case 1:
                    Mensaje = "Se ha registrado Contrato. Dar a conocer a Administrador para su visado.";
                    break;

                case 2:
                    Mensaje = "Se ha registrado Anexo. Dar a conocer a Administrador para su visado.";
                    break;

                case 3:
                    Mensaje = "Se ha registrado Finiquito. Dar a conocer a Administrador para su visado.";
                    break;

                default:
                    break;
                }

                return(true);
            }
            catch (Exception)
            {
                throw;;
            }
        }
Пример #5
0
        public Boolean EliminaCentroCosto(MssBD.Usuarios _usu, MssBD.CentrosDeCostos _centro)
        {
            try
            {
                Modelo_BDMSS.CentrosDeCostos.Remove(_centro);
                Modelo_BDMSS.SaveChanges();

                _log.IngresaLog(_usu, String.Concat(_usu.Usuario_Nombre, "ha eliminado el Centro de Costo ", _centro.CentroNombre));

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #6
0
        public Boolean GuardarCentro(MssBD.Usuarios _usu, MssBD.CentrosDeCostos _centro)
        {
            try
            {
                Modelo_BDMSS.CentrosDeCostos.Add(_centro);
                Modelo_BDMSS.SaveChanges();

                _log.IngresaLog(_usu, String.Concat(_usu.Usuario_Nombre, "ha guardado nuevo Centro de Costo ", _centro.CentroNombre));

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #7
0
        public Boolean GuardarEstructura(MssBD.Usuarios _usu, MssBD.EstructuraSueldos _estr)
        {
            try
            {
                Modelo_BDMSS.EstructuraSueldos.Add(_estr);
                Modelo_BDMSS.SaveChanges();

                _log.IngresaLog(_usu, String.Concat(_usu.Usuario_Nombre, "ha guardado Estructura de Sueldo ", _estr.Estructura_Codigo));

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Пример #8
0
        public List <MssBD.CON_Empleados_Rut_Centro_Result> ConsultaPersonal_RutApellidosCentroCostos(MssBD.Usuarios _usuSesion, Int32?_Rut, String _Apellido, Int32?_CentroCosto)
        {
            if (_Apellido == String.Empty)
            {
                _Apellido = null;
            }

            if (_CentroCosto == 0)
            {
                _CentroCosto = null;
            }

            List <MssBD.CON_Empleados_Rut_Centro_Result> _listEmpleados = new List <MssBD.CON_Empleados_Rut_Centro_Result>();

            switch (_usuSesion.Privilegio_Id)
            {
            case 1:
                _listEmpleados = (from p in Modelo_BDMSS.CON_Empleados_Rut_Centro(_Rut.ToString(), _CentroCosto.ToString(), _Apellido, _Apellido)
                                  select p).ToList();
                break;

            case 2:
                _listEmpleados = (from p in Modelo_BDMSS.CON_Empleados_Rut_Centro(_Rut.ToString(), _CentroCosto.ToString(), _Apellido, _Apellido)
                                  where p.CentroCosto_Id != 26
                                  select p).ToList();
                break;

            default:
                _listEmpleados = (from p in Modelo_BDMSS.CON_Empleados_Rut_Centro(_Rut.ToString(), _CentroCosto.ToString(), _Apellido, _Apellido)
                                  where p.Vigencia == true && p.CentroCosto_Id != 26
                                  select p).ToList();
                break;
            }

            if (_listEmpleados != null)
            {
                return(_listEmpleados);
            }

            return(null);
        }
Пример #9
0
        public bool EliminaPersonal(MssBD.Usuarios _usu, MssBD.Personal _persEliminar)
        {
            try
            {
                var _Empleado = (from p in Modelo_BDMSS.Personal
                                 where p.Rut == _persEliminar.Rut
                                 select p).First();
                _Empleado.Vigencia = false;

                Modelo_BDMSS.SaveChanges();

                _log.IngresaLog(_usu, String.Concat(_usu.Usuario_Nombre, " ha eliminado Empleado ", _persEliminar.Rut, "-", _persEliminar.Dv, " ", _persEliminar.Nombres, " ", _persEliminar.ApellidoPaterno));

                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
Пример #10
0
        public Boolean ModificaCentro(MssBD.Usuarios _usu, MssBD.CentrosDeCostos _centro)
        {
            try
            {
                var _act = (from p in Modelo_BDMSS.CentrosDeCostos
                            where p.Centro_Codigo == _centro.Centro_Codigo
                            select p).First();
                //Modelo_BDMSS.Entry(_centro).State = Modelo_BDMSS.Modified;
                _act.CentroNombre        = _centro.CentroNombre;
                _act.Vigencia            = _centro.Vigencia;
                _act.EstructuraSueldo_Id = _centro.EstructuraSueldo_Id;

                Modelo_BDMSS.SaveChanges();

                _log.IngresaLog(_usu, String.Concat(_usu.Usuario_Nombre, "ha modificado Centro de Costo ", _centro.CentroNombre));

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #11
0
        public bool CambioContraseña(Int32 Rut, String Contraseña)
        {
            try
            {
                MssBD.Personal _per    = new MssBD.Personal();
                Personal       _NegPer = new Personal();
                _per = _NegPer.BuscaPersonalPorRut(Rut);

                var _act = (from p in Modelo_BDMSS.Usuarios
                            where p.Usuario_Id == _per.Usuario_Id
                            select p).First();

                _act.Usuario_Password = Contraseña;
                Modelo_BDMSS.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);

                throw ex;
            }
        }
Пример #12
0
        public bool GuardaPersonal(MssBD.Usuarios _usu, MssBD.Personal _persGuarda, ref bool Nuevo)
        {
            try
            {
                if (!ExistePersonal(_persGuarda))
                {
                    if (_persGuarda.Usuarios.Privilegio_Id <= 4)
                    {
                        _persGuarda.Usuarios.Usuario_Nombre   = String.Concat(_persGuarda.Rut, "-", _persGuarda.Dv);
                        _persGuarda.Usuarios.Privilegio_Id    = _persGuarda.Usuarios.Privilegio_Id;
                        _persGuarda.Usuarios.Usuario_Password = String.Empty;

                        Modelo_BDMSS.Usuarios.Add((MssBD.Usuarios)_persGuarda.Usuarios);
                        Modelo_BDMSS.SaveChanges();

                        var _us = (from u in Modelo_BDMSS.Usuarios
                                   where u.Usuario_Nombre == _persGuarda.Usuarios.Usuario_Nombre && u.Usuario_Password == string.Empty
                                   select u).First();

                        _persGuarda.Usuario_Id = _us.Usuario_Id;
                    }

                    Modelo_BDMSS.Personal.Add(_persGuarda);
                    Modelo_BDMSS.SaveChanges();

                    _log.IngresaLog(_usu, String.Concat(_usu.Usuario_Nombre, " ha ingresado nuevo Empleado ", _persGuarda.Rut, "-", _persGuarda.Dv, " ", _persGuarda.Nombres, " ", _persGuarda.ApellidoPaterno));

                    Nuevo = true;
                    return(true);
                }
                else
                {
                    MssBD.Personal _perAct = new MssBD.Personal();
                    _perAct = (from p in Modelo_BDMSS.Personal
                               where p.Rut == _persGuarda.Rut
                               select p).First();

                    _perAct.ApellidoPaterno = _persGuarda.ApellidoPaterno;
                    _perAct.ApellidoMaterno = _persGuarda.ApellidoMaterno;
                    _perAct.Nombres         = _persGuarda.Nombres;

                    _perAct.Direccion        = _persGuarda.Direccion;
                    _perAct.Pais_Codigo      = _persGuarda.Pais_Codigo;
                    _perAct.Region_Codigo    = _persGuarda.Region_Codigo;
                    _perAct.Provincia_Codigo = _persGuarda.Provincia_Codigo;
                    _perAct.Comuna_Codigo    = _persGuarda.Comuna_Codigo;
                    _perAct.FechaNacimiento  = _persGuarda.FechaNacimiento;
                    _perAct.TelFijo          = _persGuarda.TelFijo;
                    _perAct.TelCelular       = _persGuarda.TelCelular;
                    _perAct.NombreContacto   = _persGuarda.NombreContacto;
                    _perAct.Parentesco       = _persGuarda.Parentesco;

                    _perAct.TelContactoFijo    = _persGuarda.TelContactoFijo;
                    _perAct.TelContactoCelular = _persGuarda.TelContactoCelular;
                    _perAct.TipoContrato       = _persGuarda.TipoContrato;
                    _perAct.FechaIngreso       = _persGuarda.FechaIngreso;
                    _perAct.CursoOS10          = _persGuarda.CursoOS10;
                    _perAct.Credencial         = _persGuarda.Credencial;
                    _perAct.FechaVencimiento   = _persGuarda.FechaVencimiento;
                    _perAct.Calzado            = _persGuarda.Calzado;
                    _perAct.Pantalon           = _persGuarda.Pantalon;
                    _perAct.Polera             = _persGuarda.Polera;
                    _perAct.Camisa             = _persGuarda.Camisa;
                    _perAct.Polar               = _persGuarda.Polar;
                    _perAct.Casaca              = _persGuarda.Casaca;
                    _perAct.Corbata             = _persGuarda.Corbata;
                    _perAct.Gorro               = _persGuarda.Gorro;
                    _perAct.Cazadora            = _persGuarda.Cazadora;
                    _perAct.Imagen              = _persGuarda.Imagen;
                    _perAct.CentroCosto_Id      = _persGuarda.CentroCosto_Id;
                    _perAct.Usuario_Id          = _persGuarda.Usuario_Id;
                    _perAct.Estado              = _persGuarda.Estado;
                    _perAct.EstructuraSueldo_Id = _persGuarda.EstructuraSueldo_Id;

                    _perAct.EstadoCivil = _persGuarda.EstadoCivil;
                    _perAct.Isapre_Id   = _persGuarda.Isapre_Id;
                    _perAct.Afp_Id      = _persGuarda.Afp_Id;

                    _perAct.Id_Banco     = _persGuarda.Id_Banco;
                    _perAct.NumeroCuenta = _persGuarda.NumeroCuenta;
                    _perAct.TipoCuenta   = _persGuarda.TipoCuenta;
                    _perAct.Cargo        = _persGuarda.Cargo;

                    Modelo_BDMSS.SaveChanges();

                    if (_persGuarda.Usuarios != null)
                    {
                        if (_persGuarda.Usuarios.Privilegio_Id < 5)
                        {
                            _perAct.Usuarios = new MssBD.Usuarios();

                            _perAct.Usuarios = (from usu in Modelo_BDMSS.Usuarios
                                                where usu.Usuario_Nombre == String.Concat(_persGuarda.Rut.ToString(), "-", _persGuarda.Dv)
                                                select usu).First();
                            _perAct.Usuarios.Privilegio_Id = _persGuarda.Usuarios.Privilegio_Id;
                        }
                    }
                    _log.IngresaLog(_usu, String.Concat(_usu.Usuario_Nombre, " ha modificado Empleado ", _persGuarda.Rut, "-", _persGuarda.Dv, " ", _persGuarda.Nombres, " ", _persGuarda.ApellidoPaterno));

                    Nuevo = false;
                    return(true);
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);
                    }
                }
                throw;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #13
0
        public bool GenereAnexosMasivos(ref String Mensaje, List <MssBD.VW_DOC_Anexos> _ListAnexos, String _RutaFinal)
        {
            Application wordApp = new Application();;
            Document    wordDoc = new Document();;

            try
            {
                foreach (var item in _ListAnexos)
                {
                    Object oMissing      = System.Reflection.Missing.Value;
                    Object oTemplatePath = String.Concat(RutaArchivosMss, "\\Anexo_Template.dotx");

                    wordApp = new Application();
                    wordDoc = new Document();

                    wordDoc = wordApp.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);

                    foreach (Field myMergeField in wordDoc.Fields)
                    {
                        Range  rngFieldCode = myMergeField.Code;
                        String fieldText    = rngFieldCode.Text;

                        if (fieldText.StartsWith(" MERGEFIELD"))
                        {
                            Int32  endMerge        = fieldText.IndexOf("\\");
                            Int32  fieldNameLength = fieldText.Length - endMerge;
                            String fieldName       = fieldText.Substring(11, endMerge - 11);

                            switch (fieldName.Trim())
                            {
                            case "FechaInicio":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.FechaDesde.Value.ToLongDateString());
                                break;

                            case "Nombre":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(PrimeraMayuscula(String.Concat(item.Nombres, " ", item.ApellidoPaterno, " ", item.ApellidoMaterno)));
                                break;

                            case "Rut":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(String.Concat(FormatNumero(item.Rut.ToString()), "-", item.Dv));
                                break;

                            case "EstadoCivil":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.EstadoCivil);
                                break;

                            case "FechaNacimiento":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.FechaNacimiento.Value.ToLongDateString());
                                break;

                            case "Direccion":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.Direccion);
                                break;

                            case "Comuna":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.comuna_nombre);
                                break;

                            case "Telefono":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.TelFijo);
                                break;

                            case "FechaAnexo":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(_FechaAnexo.ToLongDateString());
                                break;

                            case "FechaVencimiento":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(_per.FechaVencimiento.Value.ToLongDateString());
                                break;

                            default:
                                break;
                            }
                        }
                    }

                    if (File.Exists(String.Concat(_RutaFinal, "Anexo_", DateTime.Now.ToShortDateString(), "_", item.Rut, "-", item.Dv, ".pdf")))
                    {
                        Mensaje = String.Concat("Anexo a crear '", _RutaFinal, "Anexo_", DateTime.Now.ToShortDateString(),
                                                "_", item.Rut, "-", item.Dv, ".pdf", "' ya existe en la carpeta destino, favor revisar");
                        return(false);
                    }

                    //wordDoc.SaveAs2(String.Concat(_RutaFinal, "Anexo_", DateTime.Now.ToShortDateString(), "_", item.Rut, "-", item.Dv, ".doc"));

                    Object objSaveAsFile = String.Concat(_RutaFinal, "Anexo_", DateTime.Now.ToShortDateString(), "_", item.Rut, "-", item.Dv, ".pdf");
                    Object objFileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
                    wordDoc.SaveAs2(objSaveAsFile, ref objFileFormat, ref oMissing, ref oMissing,
                                    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                    ref oMissing, ref oMissing);

                    MssBD.Documentos _doc = new MssBD.Documentos();
                    _doc = (from p in Modelo_BDMSS.Documentos
                            where p.Documento_Id == item.Documento_Id
                            select p).First();
                    _doc.PorVisar = false;

                    Modelo_BDMSS.SaveChanges();

                    _log.IngresaLog(_usuarioSesion, String.Concat(_usuarioSesion.Usuario_Nombre, " ha autorizado Visar Anexo de ", item.Rut.ToString(), "-", item.Dv));

                    if (wordDoc != null)
                    {
                        wordDoc.Close(ref objFalse, ref oMissing, ref oMissing);
                    }
                    if (wordApp != null)
                    {
                        wordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
                    }
                }

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                try
                {
                    Marshal.ReleaseComObject(wordDoc);
                    Marshal.ReleaseComObject(wordApp);
                    wordApp = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
                    wordApp = null;
                }
                catch (Exception)
                {
                }
            }
        }
Пример #14
0
        public Boolean RegistrarFiniquito(Int32 DocumentoTipo_Id
                                          , MssBD.Usuarios _usu
                                          , MssBD.CON_Empleados_Rut_Centro_Result _per
                                          , bool PorVisar
                                          , string RutaFinal
                                          , ref String Mensaje
                                          , Int32 Doc_Id
                                          , Finiquitos _Finiquito
                                          , IDictionary <int, Negocio.Documentos.Remuneracion> _listRemu)
        {
            try
            {
                Int32           _Finiquito_Id = 0;
                MssBD.Finiquito _fin          = new MssBD.Finiquito();
                _fin.Documento_Id    = Doc_Id;
                _fin.Articulo        = _Finiquito._Articulo;
                _fin.Articulo_Numero = Int32.Parse(_Finiquito._NumeroArticulo);
                _fin.Comentario      = _Finiquito._Motivo;
                _fin.Documento_Id    = Doc_Id;
                _fin.Vacaciones      = _Finiquito._Vacaciones;
                _fin.MontoTotal      = _Finiquito._Total;
                _fin.RutaFinal       = RutaFinal;

                Modelo_BDMSS.Finiquito.Add(_fin);
                Modelo_BDMSS.SaveChanges();

                _Finiquito_Id = Modelo_BDMSS.Finiquito.Where(fin => fin.Finiquito_Id == fin.Finiquito_Id)
                                .Max(fin => fin.Finiquito_Id);

                foreach (var item in _listRemu)
                {
                    Remuneracion remu = new Remuneracion();
                    remu = (Remuneracion)item.Value;

                    MssBD.Remuneraciones _remu = new MssBD.Remuneraciones();
                    _remu.FechaInicio  = remu.FechaInicio;
                    _remu.FechaTermino = remu.FechaTermino;
                    _remu.Finiquito_Id = _Finiquito_Id;
                    _remu.monto        = remu.Monto;

                    Modelo_BDMSS.Remuneraciones.Add(_remu);
                    Modelo_BDMSS.SaveChanges();
                }

                _log.IngresaLog(_usu, String.Concat(_usu.Usuario_Nombre, " ha registrado Finiquito de ", _per.Rut, "-", _per.Dv));

                switch (DocumentoTipo_Id)
                {
                case 1:
                    Mensaje = "Se ha registrado Contrato. Dar a conocer a Administrador para su visado.";
                    break;

                case 2:
                    Mensaje = "Se ha registrado Anexo. Dar a conocer a Administrador para su visado.";
                    break;

                case 3:
                    Mensaje = "Se ha registrado Finiquito. Dar a conocer a Administrador para su visado.";
                    break;

                default:
                    break;
                }

                return(true);
            }
            catch (Exception)
            {
                throw;;
            }
        }
Пример #15
0
        public bool GenereFiniquitosMasivos(ref String Mensaje, List <MssBD.VW_DOC_Finiquitos> _ListFiniquitos, String _RutaFinal)
        {
            Application wordApp = new Application();
            Document    wordDoc = new Document();;

            try
            {
                foreach (var item in _ListFiniquitos)
                {
                    Object oMissing = System.Reflection.Missing.Value;

                    //Object oTemplatePath = String.Concat(_RutaInicioProyecto.Replace("\\Mss Proyecto\\bin\\Debug", String.Empty), "\\Negocio\\WordTemplate\\Finiquito_Template.dotx");
                    //Object oTemplatePath = "C:/Users/Matias Aravena/Pegas/MSS/Mss Aplicativo/Negocio/WordTemplate/Finiquito_Template.dotx";
                    Object oTemplatePath = String.Concat(RutaArchivosMss, "\\Finiquito_Template.dotx");

                    wordApp = new Application();
                    wordDoc = new Document();

                    wordDoc = wordApp.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);

                    // Creacion bookmark / Tabla Finiquitos
                    Table tblRemuneraciones = getTableByBookmarkName(wordDoc, "Remuneraciones");

                    List <MssBD.Remuneraciones> _remuList = new List <MssBD.Remuneraciones>();
                    _remuList = Modelo_BDMSS.Remuneraciones.Where(fini => fini.Finiquito_Id == item.Finiquito_Id).ToList()
                                .OrderBy(fini => fini.Finiquito_Id).ToList();
                    Int32 orden = 1;
                    foreach (var _remu in _remuList)
                    {
                        tblRemuneraciones.Cell(orden, 1).Range.Text = String.Concat("Remuneraciones del ", _remu.FechaInicio.Value.ToShortDateString(), " al ", _remu.FechaTermino.Value.ToShortDateString());
                        tblRemuneraciones.Cell(orden, 2).Range.Text = String.Concat("$", _remu.monto.ToString());
                        tblRemuneraciones.Rows.Add();
                        orden = orden + 1;
                    }
                    tblRemuneraciones.Cell(orden, 1).Range.Text = "Vacaciones Proporcionales:";
                    tblRemuneraciones.Cell(orden, 2).Range.Text = String.Concat("$", item.Vacaciones.ToString(), ".-");

                    foreach (Field myMergeField in wordDoc.Fields)
                    {
                        Range  rngFieldCode = myMergeField.Code;
                        String fieldText    = rngFieldCode.Text;

                        if (fieldText.StartsWith(" MERGEFIELD"))
                        {
                            Int32  endMerge        = fieldText.IndexOf("\\");
                            Int32  fieldNameLength = fieldText.Length - endMerge;
                            String fieldName       = fieldText.Substring(11, endMerge - 11);

                            switch (fieldName.Trim())
                            {
                            case "FechaActual":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(DateTime.Now.ToLongDateString());
                                break;

                            case "Nombre":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(PrimeraMayuscula(String.Concat(item.Nombres, " ", item.ApellidoPaterno, " ", item.ApellidoMaterno)));
                                break;

                            case "Rut":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(String.Concat(item.Rut, "-", item.Dv));
                                break;

                            case "FechaInicio":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.FechaIngreso.Value.ToLongDateString());
                                break;

                            case "FechaHasta":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.FechaVencimiento.Value.ToLongDateString());
                                break;

                            case "Articulo":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.Articulo);
                                break;

                            case "NumeroArticulo":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.Articulo_Numero.ToString());
                                break;

                            case "Motivo":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.Comentario.ToString());
                                break;

                            case "TotalNumerico":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.MontoTotal.ToString());
                                break;

                            case "TotalLetras":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(PrimeraMayuscula(enletras(item.MontoTotal.ToString())));
                                break;

                            default:
                                break;
                            }
                        }
                    }

                    if (File.Exists(String.Concat(_RutaFinal, "Finiquito_", DateTime.Now.ToShortDateString(), "_", item.Rut, "-", item.Dv, ".pdf")))
                    {
                        Mensaje = String.Concat("Finiquito a crear '", _RutaFinal, "Finiquito_", DateTime.Now.ToShortDateString(),
                                                "_", item.Rut, "-", item.Dv, ".pdf", "' ya existe en la carpeta destino, favor revisar");
                        return(false);
                    }

                    //wordDoc.SaveAs2(String.Concat(_RutaFinal, "Finiquito_", DateTime.Now.ToShortDateString(), "_", item.Rut, "-", item.Dv, ".doc"));

                    Object objSaveAsFile = String.Concat(_RutaFinal, "Finiquito_", DateTime.Now.ToShortDateString(), "_", item.Rut, "-", item.Dv, ".pdf");
                    Object objFileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
                    wordDoc.SaveAs2(objSaveAsFile, ref objFileFormat, ref oMissing, ref oMissing,
                                    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                    ref oMissing, ref oMissing);

                    MssBD.Documentos _doc = new MssBD.Documentos();
                    _doc = (from p in Modelo_BDMSS.Documentos
                            where p.Documento_Id == item.Documento_Id
                            select p).First();
                    _doc.PorVisar = false;

                    Modelo_BDMSS.SaveChanges();

                    _log.IngresaLog(_usuarioSesion, String.Concat(_usuarioSesion.Usuario_Nombre, " ha autorizado Visar Finiquito de ", item.Rut.ToString(), "-", item.Dv));

                    if (wordDoc != null)
                    {
                        wordDoc.Close(ref objFalse, ref oMissing, ref oMissing);
                    }
                    if (wordApp != null)
                    {
                        wordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                try
                {
                    Marshal.ReleaseComObject(wordDoc);
                    Marshal.ReleaseComObject(wordApp);
                    wordApp = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
                    wordApp = null;
                }
                catch (Exception)
                {
                }
            }
        }
Пример #16
0
        public bool GenereContratosMasivos(ref String Mensaje, List <MssBD.VW_DOC_Contratos> _ListContratos, String _RutaFinal)
        {
            Application wordApp = new Application();
            Document    wordDoc = new Document();;

            try
            {
                foreach (var item in _ListContratos)
                {
                    //Assembly thisAssembly;
                    //thisAssembly = Assembly.GetExecutingAssembly();
                    //Stream someStream;
                    //someStream = thisAssembly.GetManifestResourceStream("Negocio.WordTemplate.Contrato_Template.dotx");
                    //Assembly _assembly = Assembly.GetExecutingAssembly();

                    // Object oTemplatePath = _assembly.GetManifestResourceStream("WordTemplate\\Contrato_Template.dotx");
                    //Object oTemplatePath = _assembly.GetManifestResourceStream("Negocio.WordTemplate.Contrato_Template.dotx");
                    //Object oTemplatePath2 = _assembly.GetManifestResourceStream("WordTemplate\\Contrato_Template.dotx");

                    Object oTemplatePath = String.Concat(RutaArchivosMss, "\\Contrato_Template.dotx");

                    wordApp = new Application();
                    wordDoc = new Document();

                    wordDoc = wordApp.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);

                    foreach (Field myMergeField in wordDoc.Fields)
                    {
                        Range  rngFieldCode = myMergeField.Code;
                        String fieldText    = rngFieldCode.Text;

                        if (fieldText.StartsWith(" MERGEFIELD"))
                        {
                            Int32  endMerge        = fieldText.IndexOf("\\");
                            Int32  fieldNameLength = fieldText.Length - endMerge;
                            String fieldName       = fieldText.Substring(11, endMerge - 11);

                            switch (fieldName.Trim())
                            {
                            case "FechaContrato":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(DateTime.Now.ToLongDateString());
                                break;

                            case "Nombre":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(PrimeraMayuscula(String.Concat(item.Nombres, " ", item.ApellidoPaterno, " ", item.ApellidoMaterno)));
                                break;

                            case "Rut":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(String.Concat(FormatNumero(item.Rut.ToString()), "-", item.Dv));
                                break;

                            case "EstadoCivil":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.EstadoCivil);
                                break;

                            case "FechaNacimiento":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.FechaNacimiento.Value.ToLongDateString());
                                break;

                            case "Dirección":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.Direccion);
                                break;

                            case "Comuna":
                                myMergeField.Select();
                                try
                                {
                                    if (item.comuna_nombre == null)
                                    {
                                        Mensaje = "Personal no tiene Comuna asociada. Favor ingresarla y volver a intentar.";
                                        return(false);
                                    }
                                    wordApp.Selection.TypeText(item.comuna_nombre);
                                }
                                catch (Exception)
                                {
                                    Mensaje = "Personal no tiene Comuna asociada. Favor ingresarla y volver a intentar.";
                                    return(false);
                                }
                                break;

                            case "Telefono":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.TelFijo);

                                if (item.TelCelular != string.Empty && item.TelFijo != string.Empty)
                                {
                                    wordApp.Selection.TypeText(String.Concat("Teléfono ", item.TelFijo, " y Teléfono Celular ", item.TelCelular));
                                }
                                else
                                {
                                    if (item.TelCelular != string.Empty)
                                    {
                                        wordApp.Selection.TypeText(String.Concat("Teléfono Celular ", item.TelCelular));
                                    }
                                    else
                                    {
                                        wordApp.Selection.TypeText(String.Concat("Teléfono ", item.TelFijo));
                                    }
                                }
                                break;

                            case "SueldoBaseNumero":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(FormatNumero(item.SueldoBase.ToString()));
                                break;

                            case "SueldoBaseLetras":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(PrimeraMayuscula(enletras(item.SueldoBase.ToString())));
                                break;

                            case "GratificacionNumero":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(FormatNumero(item.Gratificacion.ToString()));
                                break;

                            case "GratificacionLetras":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(PrimeraMayuscula(enletras(item.Gratificacion.ToString())));
                                break;

                            case "AsistenciaNumero":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(FormatNumero(item.BonoAsistencia.ToString()));
                                break;

                            case "AsistenciaLetras":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(PrimeraMayuscula(enletras(item.BonoAsistencia.ToString())));
                                break;

                            case "ProduccionNumero":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(FormatNumero(item.BonoProduccion.ToString()));
                                break;

                            case "ProduccionLetras":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(PrimeraMayuscula(enletras(item.BonoProduccion.ToString())));
                                break;

                            case "ColacionNumero":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(FormatNumero(item.Colacion.ToString()));
                                break;

                            case "ColacionLetras":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(PrimeraMayuscula(enletras(item.Colacion.ToString())));
                                break;

                            case "MovilizacionNumero":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(FormatNumero(item.Movilizacion.ToString()));
                                break;

                            case "MovilizacionLetras":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(PrimeraMayuscula(enletras(item.Movilizacion.ToString())));
                                break;

                            case "BonoTurno":
                                myMergeField.Select();
                                if (item.BonoTurno <= 0)
                                {
                                    wordApp.Selection.TypeText(FormatNumero("0"));
                                }
                                else
                                {
                                    wordApp.Selection.TypeText(FormatNumero(item.BonoTurno.ToString()));
                                }
                                break;

                            case "FechaVencimiento":
                                myMergeField.Select();
                                if (item.TipoContrato.Equals("INDEFINIDO"))
                                {
                                    wordApp.Selection.TypeText("Indefinida");
                                }
                                else
                                {
                                    wordApp.Selection.TypeText(String.Concat("hasta el ", item.FechaVencimiento.Value.ToLongDateString()));
                                }
                                break;

                            case "FechaInicio":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.FechaHasta.Value.ToLongDateString());
                                break;

                            case "AFP":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.Afp_Nombre);
                                break;

                            case "Isapre":
                                myMergeField.Select();
                                wordApp.Selection.TypeText(item.Isapre_Nombre);
                                break;

                            case "Desempeño":
                                myMergeField.Select();
                                try
                                {
                                    if (item.Cargo.Contains("guardia") || item.Cargo.Contains("Guardia") || item.Cargo.Contains("GUARDIA"))
                                    {
                                        wordApp.Selection.TypeText("Guardia de Seguridad.");
                                    }
                                    else
                                    {
                                        wordApp.Selection.TypeText(_personal.Cargo);
                                    }
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                                break;

                            case "SegundoParrafo":
                                myMergeField.Select();
                                try
                                {
                                    if (item.Cargo.Contains("guardia") || item.Cargo.Contains("Guardia") || item.Cargo.Contains("GUARDIA"))
                                    {
                                        wordApp.Selection.TypeText("Guardia de Seguridad, será el encargado de asistir en la organización y realización de tareas de seguridad del área, patrullar o supervisar las instalaciones para evitar el robo, la violencia, o infracciones contra la empresa contratante, autorizar la entrada y salida de los empleados, visitantes y otras personas con el fin de protegerse contra el Robo y/o Hurto. El guardia de Seguridad es responsable de mantener instalaciones seguras, debe ser capaz de escribir informes sobre las actividades diarias y las irregularidades, tales como daños en los equipos o la propiedad, robos, Hurtos, la presencia de personas no autorizadas o los acontecimientos inusuales, o cualquier otro acontecimiento que revista los caracteres de delito. Un guardia de seguridad debe llamar a la Carabineros o a la Policía, bomberos y/o Ambulancias en casos de emergencia. Cuando un guardia de seguridad se enfrenta a personas no autorizadas que se niegan a abandonar la zona custodiada, deben llamar a la policía para efectuar el procedimiento.");
                                    }
                                    else
                                    {
                                        wordApp.Selection.TypeText(String.Concat(item.Cargo, ", ", _SegundoParrafo));
                                    }
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                                break;

                            case "DireccionInstalacion":
                                myMergeField.Select();
                                try
                                {
                                    wordApp.Selection.TypeText(_DireccionInstalacion);
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                                break;

                            case "AfectoBonoAsistencia":
                                myMergeField.Select();
                                try
                                {
                                    //if (_personal.Usuarios.Privilegio_Id == 5)
                                    if (_personal.Cargo.Contains("guardia") || _personal.Cargo.Contains("Guardia") || _personal.Cargo.Contains("GUARDIA"))
                                    {
                                        wordApp.Selection.TypeText("En el evento que el trabajador tenga un día de inasistencia o un atraso injustificado, se le descontará el 100% del bono de Asistencia y Responsabilidad.  Lo anterior sin perjuicio de lo estipulado en el Art. 160, nro. 3 y 4, del Código del Trabajo. El trabajador no tendrá otros beneficios que los que se hagan contar por escrito en el presente contrato.");
                                    }
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                                break;

                            case "Anticipo":
                                myMergeField.Select();
                                try
                                {
                                    if (_personal.Cargo.Contains("guardia") || _personal.Cargo.Contains("Guardia") || _personal.Cargo.Contains("GUARDIA"))
                                    {
                                        wordApp.Selection.TypeText(FormatNumero("60000"));
                                    }
                                    else
                                    {
                                        wordApp.Selection.TypeText(FormatNumero(_Anticipo.ToString()));
                                    }
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                                break;

                            case "AnticipoLetras":
                                myMergeField.Select();
                                try
                                {
                                    if (_personal.Cargo.Contains("guardia") || _personal.Cargo.Contains("Guardia") || _personal.Cargo.Contains("GUARDIA"))
                                    {
                                        wordApp.Selection.TypeText(FormatNumero(String.Concat("(", PrimeraMayuscula(enletras("60000")), " pesos chilenos)")));
                                    }
                                    else
                                    {
                                        wordApp.Selection.TypeText(FormatNumero(String.Concat("(", PrimeraMayuscula(enletras(_Anticipo.ToString())), " pesos chilenos)")));
                                    }
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                                break;

                            case "DepositoBanco":
                                myMergeField.Select();
                                try
                                {
                                    //vista Nº 18162030, del Banco Estado.
                                    if (_personal.Id_Banco == 19 && _personal.TipoCuenta.ToString().Equals("Cuenta Vista"))
                                    {
                                        wordApp.Selection.TypeText(String.Concat("Cuenta Rut", " Nº", _personal.NumeroCuenta, ", del", _Bancos.BuscaNombreBanco((int)_personal.Id_Banco)));
                                    }
                                    else
                                    {
                                        wordApp.Selection.TypeText(String.Concat(_personal.TipoCuenta, " Nº", _personal.NumeroCuenta, ", del", _Bancos.BuscaNombreBanco((int)_personal.Id_Banco)));
                                    }
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }

                    if (File.Exists(String.Concat(_RutaFinal, "Contrato_", DateTime.Now.ToShortDateString(), "_", item.Rut, "-", item.Dv, ".pdf")))
                    {
                        Mensaje = String.Concat("Contrato a crear '", _RutaFinal, "Contrato_", DateTime.Now.ToShortDateString(),
                                                "_", item.Rut, "-", item.Dv, ".pdf", "' ya existe en la carpeta destino, favor revisar");
                        return(false);
                    }

                    Object objSaveAsFile = String.Concat(_RutaFinal, "Contrato_", DateTime.Now.ToShortDateString(), "_", item.Rut, "-", item.Dv, ".pdf");
                    Object objFileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
                    wordDoc.SaveAs2(objSaveAsFile, ref objFileFormat, ref oMissing, ref oMissing,
                                    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                    ref oMissing, ref oMissing);

                    MssBD.Documentos _doc = new MssBD.Documentos();
                    _doc = (from p in Modelo_BDMSS.Documentos
                            where p.Documento_Id == item.Documento_Id
                            select p).First();
                    _doc.PorVisar = false;

                    Modelo_BDMSS.SaveChanges();

                    _log.IngresaLog(_usuarioSesion, String.Concat(_usuarioSesion.Usuario_Nombre, " ha autorizado Visar Contratos de ", item.Rut.ToString(), "-", item.Dv));

                    if (wordDoc != null)
                    {
                        wordDoc.Close(ref objFalse, ref oMissing, ref oMissing);
                    }
                    if (wordApp != null)
                    {
                        wordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                try
                {
                    Marshal.ReleaseComObject(wordDoc);
                    Marshal.ReleaseComObject(wordApp);
                    wordApp = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
                    wordApp = null;
                }
                catch (Exception)
                {
                }
            }
        }