Exemplo n.º 1
0
        public bool modificarDB(ro_periodo_Info info)
        {
            try
            {
                using (Entities_rrhh Context = new Entities_rrhh())
                {
                    ro_periodo Entity = Context.ro_periodo.FirstOrDefault(q => q.IdEmpresa == info.IdEmpresa && q.IdPeriodo == info.IdPeriodo);
                    if (Entity == null)
                    {
                        return(false);
                    }
                    Entity.IdEmpresa             = info.IdEmpresa;
                    Entity.IdPeriodo             = info.IdPeriodo;
                    Entity.pe_FechaIni           = info.pe_FechaIni.Date;
                    Entity.pe_FechaFin           = info.pe_FechaFin.Date;
                    Entity.Carga_Todos_Empleados = info.Carga_Todos_Empleados;
                    Entity.Cod_region            = info.Cod_region;
                    Entity.Fecha_UltMod          = info.Fecha_UltMod = DateTime.Now;
                    Context.SaveChanges();
                }

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        public ro_periodo_Info get_info(int IdEmpresa, int IdPeriodo)
        {
            try
            {
                ro_periodo_Info info = new ro_periodo_Info();

                using (Entities_rrhh Context = new Entities_rrhh())
                {
                    ro_periodo Entity = Context.ro_periodo.FirstOrDefault(q => q.IdEmpresa == IdEmpresa && q.IdPeriodo == IdPeriodo);
                    if (Entity == null)
                    {
                        return(null);
                    }

                    info = new ro_periodo_Info
                    {
                        IdEmpresa             = Entity.IdEmpresa,
                        IdPeriodo             = Entity.IdPeriodo,
                        pe_FechaIni           = Entity.pe_FechaIni,
                        pe_FechaFin           = Entity.pe_FechaFin,
                        Carga_Todos_Empleados = (Entity.Carga_Todos_Empleados) == null?false:Convert.ToBoolean(Entity.Carga_Todos_Empleados),
                        Cod_region            = Entity.Cod_region,
                        pe_mes    = Entity.pe_mes,
                        pe_anio   = Entity.pe_anio,
                        pe_estado = Entity.pe_estado
                    };
                }

                return(info);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 3
0
 public bool guardar_periodos_generadosDB(ro_periodo_Info info)
 {
     try
     {
         if (si_existe_periodo(info.IdEmpresa, info.IdPeriodo))
         {
             return(false);
         }
         using (Entities_rrhh Context = new Entities_rrhh())
         {
             ro_periodo Entity = new ro_periodo
             {
                 IdEmpresa             = info.IdEmpresa,
                 IdPeriodo             = info.IdPeriodo,
                 pe_FechaIni           = info.pe_FechaIni.Date,
                 pe_FechaFin           = info.pe_FechaFin.Date,
                 Carga_Todos_Empleados = info.Carga_Todos_Empleados,
                 pe_anio       = info.pe_anio,
                 pe_mes        = info.pe_mes,
                 Cod_region    = info.Cod_region,
                 IdUsuario     = info.IdUsuario,
                 pe_estado     = "A",
                 Fecha_Transac = info.Fecha_Transac = DateTime.Now
             };
             Context.ro_periodo.Add(Entity);
             Context.SaveChanges();
         }
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 4
0
 public bool guardarDB(ro_periodo_Info info)
 {
     try
     {
         using (Entities_rrhh Context = new Entities_rrhh())
         {
             ffin = info.pe_FechaFin.Date.Day;
             anio = Convert.ToInt32(info.pe_anio);
             mes  = Convert.ToInt32(info.pe_mes);
             ro_periodo Entity = new ro_periodo
             {
                 IdEmpresa             = info.IdEmpresa,
                 IdPeriodo             = get_id(info.IdEmpresa),
                 pe_FechaIni           = info.pe_FechaIni.Date,
                 pe_FechaFin           = info.pe_FechaFin.Date,
                 pe_anio               = info.pe_anio,
                 pe_mes                = info.pe_mes,
                 Carga_Todos_Empleados = info.Carga_Todos_Empleados,
                 Cod_region            = info.Cod_region,
                 IdUsuario             = info.IdUsuario,
                 pe_estado             = "A",
                 Fecha_Transac         = info.Fecha_Transac = DateTime.Now
             };
             Context.ro_periodo.Add(Entity);
             Context.SaveChanges();
         }
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 5
0
        public Boolean GrabarDB(ro_periodo_Info info, ref string msg)
        {
            try
            {
                using (EntitiesRoles context = new EntitiesRoles())
                {
                    var que = from C in context.ro_periodo
                              where C.IdPeriodo == info.IdPeriodo
                              select C;
                    if (que.Count() == 0)
                    {
                        var address = new ro_periodo();

                        info.IdPeriodo                = getId(info.IdEmpresa);
                        address.IdEmpresa             = info.IdEmpresa;
                        address.IdPeriodo             = info.IdPeriodo;
                        address.pe_FechaIni           = Convert.ToDateTime(info.pe_FechaIni.ToShortDateString());
                        address.pe_FechaFin           = Convert.ToDateTime(info.pe_FechaFin.ToShortDateString());
                        address.pe_anio               = Convert.ToInt32(info.pe_anio);
                        address.pe_mes                = Convert.ToByte(info.pe_mes);
                        address.pe_estado             = info.pe_estado;
                        address.Cod_region            = info.Cod_region;
                        address.Carga_Todos_Empleados = info.Carga_Todos_Empleados;

                        context.ro_periodo.Add(address);

                        context.SaveChanges();
                    }
                    else
                    {
                        msg = "Error en el ingreso; código Existente";
                        return(false);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                string array = ToString();
                tb_sis_Log_Error_Vzen_Data oDataLog      = new tb_sis_Log_Error_Vzen_Data();
                tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), "", array, "", "", "", "", "", DateTime.Now);
                oDataLog.Guardar_Log_Error(Log_Error_sis, ref mensaje);
                mensaje = ex.InnerException + " " + ex.Message;
                throw new Exception(ex.InnerException.ToString());
            }
        }
Exemplo n.º 6
0
        public Boolean GuardarPeriodos(List <ro_periodo_Info> Lst, ref string mensaje)
        {
            try
            {
                using (EntitiesRoles Context = new EntitiesRoles())
                {
                    foreach (var Item in Lst)
                    {
                        ro_periodo Periodo = new ro_periodo();

                        Periodo.IdEmpresa   = Item.IdEmpresa;
                        Periodo.IdPeriodo   = Item.IdPeriodo;
                        Periodo.pe_anio     = Item.pe_anio;
                        Periodo.pe_mes      = Item.pe_mes;
                        Periodo.pe_FechaIni = Convert.ToDateTime(Item.pe_FechaIni.ToShortDateString());
//                        Periodo.pe_FechaFin = Convert.ToDateTime(Item.pe_FechaFin.ToShortDateString());
                        Periodo.pe_FechaFin = Item.pe_FechaFin.AddHours(23).AddMinutes(59);

                        Periodo.pe_estado  = Item.pe_estado;
                        Periodo.Cod_region = Item.Cod_region;


                        Context.ro_periodo.Add(Periodo);
                        Context.SaveChanges();
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                string array = ToString();
                tb_sis_Log_Error_Vzen_Data oDataLog      = new tb_sis_Log_Error_Vzen_Data();
                tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), "", array, "", "", "", "", "", DateTime.Now);
                oDataLog.Guardar_Log_Error(Log_Error_sis, ref mensaje);
                mensaje = ex.InnerException + " " + ex.Message;
                throw new Exception(ex.InnerException.ToString());
            }
        }
Exemplo n.º 7
0
        public bool anularDB(ro_periodo_Info info)
        {
            try
            {
                using (Entities_rrhh Context = new Entities_rrhh())
                {
                    ro_periodo Entity = Context.ro_periodo.FirstOrDefault(q => q.IdEmpresa == info.IdEmpresa && q.IdPeriodo == info.IdPeriodo);
                    if (Entity == null)
                    {
                        return(false);
                    }
                    Entity.pe_estado       = "I";
                    Entity.IdUsuarioUltAnu = info.IdUsuarioUltAnu;
                    Entity.FechaHoraAnul   = DateTime.Now;
                    Context.SaveChanges();
                }

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public bool modificarDB(ro_participacion_utilidad_Info info)
        {
            try
            {
                using (Entities_rrhh Context = new Entities_rrhh())
                {
                    int IdNomina_General;
                    int IdNomina_TipoLiqui_PagoUtilidad;

                    ro_rubros_calculados RubrosCalculados = Context.ro_rubros_calculados.FirstOrDefault(q => q.IdEmpresa == info.IdEmpresa);
                    if (RubrosCalculados == null | RubrosCalculados.IdRubro_utilidad == null)
                    {
                        return(false);
                    }
                    #region Nomina y periodo
                    DateTime fi = new DateTime(info.IdPeriodo, 1, 1);
                    DateTime ff = new DateTime(info.IdPeriodo, 12, 31);

                    ro_Parametros param = Context.ro_Parametros.FirstOrDefault(q => q.IdEmpresa == info.IdEmpresa);
                    if (param == null || param.IdNomina_General == null || param.IdNomina_TipoLiqui_PagoUtilidad == null)
                    {
                        return(false);
                    }
                    IdNomina_General = Convert.ToInt32(param.IdNomina_General);
                    IdNomina_TipoLiqui_PagoUtilidad = Convert.ToInt32(param.IdNomina_TipoLiqui_PagoUtilidad);

                    ro_periodo Entity_periodo = Context.ro_periodo.FirstOrDefault(q => q.IdEmpresa == info.IdEmpresa && q.IdPeriodo == info.IdPeriodo);
                    if (Entity_periodo == null)
                    {
                        Context.ro_periodo.Add(new ro_periodo
                        {
                            IdEmpresa     = info.IdEmpresa,
                            IdPeriodo     = info.IdPeriodo,
                            pe_FechaIni   = new DateTime(info.IdPeriodo, 1, 1),
                            pe_FechaFin   = new DateTime(info.IdPeriodo, 12, 31),
                            pe_anio       = info.IdPeriodo,
                            pe_estado     = "A",
                            IdUsuario     = info.UsuarioIngresa,
                            Fecha_Transac = DateTime.Now
                        });
                        ro_periodo_x_ro_Nomina_TipoLiqui Entity_periodo_nom = Context.ro_periodo_x_ro_Nomina_TipoLiqui.FirstOrDefault(q => q.IdEmpresa == info.IdEmpresa && q.IdPeriodo == info.IdPeriodo &&
                                                                                                                                      q.IdNomina_Tipo == IdNomina_General && q.IdNomina_TipoLiqui == IdNomina_TipoLiqui_PagoUtilidad);

                        Context.ro_periodo_x_ro_Nomina_TipoLiqui.Add(new ro_periodo_x_ro_Nomina_TipoLiqui
                        {
                            IdEmpresa          = info.IdEmpresa,
                            IdPeriodo          = info.IdPeriodo,
                            IdNomina_Tipo      = IdNomina_General,
                            IdNomina_TipoLiqui = IdNomina_TipoLiqui_PagoUtilidad,
                            Cerrado            = "N",
                            Procesado          = "S",
                            Contabilizado      = "N"
                        });
                    }

                    #endregion
                    #region Utilidad cabecera

                    ro_participacion_utilidad Entity = Context.ro_participacion_utilidad.FirstOrDefault(q => q.IdEmpresa == info.IdEmpresa && q.IdUtilidad == info.IdUtilidad);
                    if (Entity == null)
                    {
                        return(false);
                    }
                    Entity.IdUsuarioModifica         = info.IdUsuarioModifica;
                    Entity.BaseUtilidad              = info.BaseUtilidad;
                    Entity.UtilidadDerechoIndividual = info.UtilidadDerechoIndividual;
                    Entity.UtilidadCargaFamiliar     = info.UtilidadCargaFamiliar;
                    Entity.Utilidad           = info.Utilidad;
                    Entity.Fecha_ultima_modif = DateTime.Now;



                    #endregion

                    #region Rol
                    ro_rol Entity_rol = Context.ro_rol.FirstOrDefault(q => q.IdEmpresa == info.IdEmpresa &&
                                                                      q.IdNominaTipo == IdNomina_General &&
                                                                      q.IdNominaTipoLiqui == IdNomina_TipoLiqui_PagoUtilidad);

                    decimal rolId = 0;
                    if (Entity_rol == null)
                    {
                        var lst = from q in Context.ro_rol
                                  where q.IdEmpresa == info.IdEmpresa
                                  select q;
                        rolId = lst.Max(q => q.IdRol) + 1;
                        Context.ro_rol.Add(new ro_rol
                        {
                            IdRol             = rolId,
                            IdSucursal        = info.IdSucursal,
                            IdEmpresa         = info.IdEmpresa,
                            IdNominaTipo      = IdNomina_General,
                            IdNominaTipoLiqui = IdNomina_TipoLiqui_PagoUtilidad,
                            Cerrado           = "N",
                            Descripcion       = "PAGO DE UTILIDA " + info.IdPeriodo.ToString(),
                            UsuarioIngresa    = info.UsuarioIngresa,
                            FechaIngresa      = DateTime.Now
                        });
                    }
                    else
                    {
                        Entity_rol.Observacion   = "PAGO DE UTILIDA " + info.IdPeriodo.ToString();
                        Entity_rol.FechaModifica = DateTime.Now;
                        rolId = Entity_rol.IdRol;
                        var rol_detalle = Context.ro_rol_detalle.Where(s => s.IdEmpresa == info.IdEmpresa && s.IdRol == Entity_rol.IdRol);
                        Context.ro_rol_detalle.RemoveRange(rol_detalle);
                    }

                    #region INSERTANDO ROL DETALLE
                    var utilidad_detalle = Context.ro_participacion_utilidad_empleado.Where(s => s.IdEmpresa == info.IdEmpresa && s.IdUtilidad == info.IdUtilidad);
                    Context.ro_participacion_utilidad_empleado.RemoveRange(utilidad_detalle);


                    foreach (var item in info.detalle)// LISTADO DE EMPLEADOS CON BENEFICIOS DE UTILIDAS
                    {
                        double TotalEgreso = 0;
                        // DIAS TRABAJADOS
                        Context.ro_rol_detalle.Add(new ro_rol_detalle
                        {
                            IdEmpresa           = info.IdEmpresa,
                            IdRol               = rolId,
                            IdEmpleado          = item.IdEmpleado,
                            IdRubro             = RubrosCalculados.IdRubro_dias_trabajados,
                            Observacion         = " ",
                            IdSucursal          = item.IdSucursal,
                            rub_visible_reporte = true,
                            Orden               = 0,
                            Valor               = item.DiasTrabajados
                        });
                        // TOTAL DE UTILIDAD
                        Context.ro_rol_detalle.Add(new ro_rol_detalle
                        {
                            IdEmpresa           = info.IdEmpresa,
                            IdRol               = rolId,
                            IdEmpleado          = item.IdEmpleado,
                            IdRubro             = RubrosCalculados.IdRubro_utilidad,
                            Observacion         = " ",
                            IdSucursal          = item.IdSucursal,
                            rub_visible_reporte = true,
                            Orden               = 0,
                            Valor               = item.ValorTotal
                        });
                        // TOTAL DE INGRESO
                        Context.ro_rol_detalle.Add(new ro_rol_detalle
                        {
                            IdEmpresa           = info.IdEmpresa,
                            IdRol               = rolId,
                            IdEmpleado          = item.IdEmpleado,
                            IdRubro             = RubrosCalculados.IdRubro_tot_ing,
                            Observacion         = " ",
                            IdSucursal          = item.IdSucursal,
                            rub_visible_reporte = true,
                            Orden               = 0,
                            Valor               = item.ValorTotal
                        });

                        #region Novedades y prestamos POR EMPLEADO
                        string sql = "";
                        sql = "  SELECT  n.IdEmpresa, n.IdEmpleado,IdSucursal, nd.IdRubro,sum( nd.Valor)Valor " +
                              "FROM dbo.ro_empleado_Novedad AS n INNER JOIN " +
                              "dbo.ro_empleado_novedad_det AS nd ON n.IdEmpresa = nd.IdEmpresa AND n.IdNovedad = nd.IdNovedad " +
                              "where nd.EstadoCobro = 'PEN' and n.IdEmpresa='" + info.IdEmpresa + "' and IdNomina_Tipo=" + param.IdNomina_General + " and n.IdNomina_TipoLiqui=" + param.IdNomina_TipoLiqui_PagoUtilidad + "" +
                              "and  nd.FechaPago between '" + fi.ToString("yyyy-MM-dd") + "'  and '" + ff.ToString("yyyy-MM-dd") + "'" +
                              " and n.IdEmpleado='" + item.IdEmpleado + "'" +
                              "GROUP BY n.IdEmpresa, n.IdEmpleado,IdSucursal, nd.IdRubro, nd.Valor " +
                              "union all " +
                              "SELECT p.IdEmpresa, p.IdEmpleado,IdSucursal, p.IdRubro, pd.TotalCuota " +
                              "FROM dbo.ro_prestamo AS p INNER JOIN " +
                              " dbo.ro_prestamo_detalle AS pd ON p.IdEmpresa = pd.IdEmpresa AND p.IdPrestamo = pd.IdPrestamo INNER JOIN " +
                              " dbo.ro_empleado AS e ON p.IdEmpresa = e.IdEmpresa AND p.IdEmpleado = e.IdEmpleado " +
                              " where pd.EstadoPago = 'PEN' and p.IdEmpresa='" + info.IdEmpresa + "' and descuento_ben_soc='1' and pd.IdNominaTipoLiqui=" + param.IdNomina_TipoLiqui_PagoUtilidad + "" +
                              " and  pd.FechaPago between '" + fi.ToString("yyyy-MM-dd") + "'  and '" + ff.ToString("yyyy-MM-dd") + "'" +
                              " and p.IdEmpleado='" + item.IdEmpleado + "'" +
                              " GROUP BY p.IdEmpresa, p.IdEmpleado,e.IdSucursal, pd.TotalCuota, p.IdRubro";
                        var lstNovedades = Context.Database.SqlQuery <ro_empleado_novedad_det_Info>(sql).ToList();
                        foreach (var item_ in lstNovedades)
                        {
                            Context.ro_rol_detalle.Add(new ro_rol_detalle
                            {
                                IdEmpresa           = info.IdEmpresa,
                                IdRol               = rolId,
                                IdEmpleado          = item_.IdEmpleado,
                                IdRubro             = item_.IdRubro,
                                Observacion         = " ",
                                IdSucursal          = item_.IdSucursal,
                                rub_visible_reporte = true,
                                Orden               = 0,
                                Valor               = item_.Valor
                            });
                        }
                        #endregion

                        #region Total de egreso por empleado
                        var lst_total_egreso = lstNovedades.GroupBy(c => new
                        {
                            c.IdEmpleado,
                            c.IdSucursal
                        })
                                               .Select(x => new
                        {
                            IdEmpleado = x.Key.IdEmpleado,
                            IdSucursal = x.Key.IdSucursal,
                            Valor      = x.Sum(y => y.Valor)
                        }).ToList();
                        foreach (var item_egr in lst_total_egreso)
                        {
                            TotalEgreso = item_egr.Valor;
                            Context.ro_rol_detalle.Add(new ro_rol_detalle
                            {
                                IdEmpresa           = info.IdEmpresa,
                                IdRol               = rolId,
                                IdEmpleado          = item_egr.IdEmpleado,
                                IdRubro             = RubrosCalculados.IdRubro_tot_egr,
                                Observacion         = " ",
                                IdSucursal          = item_egr.IdSucursal,
                                rub_visible_reporte = true,
                                Orden               = 0,
                                Valor               = item_egr.Valor
                            });
                        }
                        #endregion

                        #region liquido a recibir en rol
                        Context.ro_rol_detalle.Add(new ro_rol_detalle
                        {
                            IdEmpresa           = info.IdEmpresa,
                            IdRol               = rolId,
                            IdEmpleado          = item.IdEmpleado,
                            IdRubro             = RubrosCalculados.IdRubro_tot_pagar,
                            Observacion         = " ",
                            IdSucursal          = item.IdSucursal,
                            rub_visible_reporte = true,
                            Orden               = 0,
                            Valor               = item.ValorTotal - TotalEgreso
                        });
                        #endregion

                        #region detalle de utilidad
                        ro_participacion_utilidad_empleado Entity_det = new ro_participacion_utilidad_empleado
                        {
                            IdEmpresa          = info.IdEmpresa,
                            IdUtilidad         = info.IdUtilidad,
                            IdEmpleado         = item.IdEmpleado,
                            CargasFamiliares   = item.CargasFamiliares,
                            ValorCargaFamiliar = item.ValorCargaFamiliar,
                            ValorIndividual    = item.ValorIndividual,
                            ValorTotal         = item.ValorTotal,
                            DiasTrabajados     = item.DiasTrabajados,
                            Descuento          = TotalEgreso,
                            NetoRecibir        = (item.ValorTotal - TotalEgreso)
                        };
                        Context.ro_participacion_utilidad_empleado.Add(Entity_det);
                        #endregion



                        #endregion
                    }


                    #endregion

                    Context.SaveChanges();
                }

                return(true);
            }
            catch (Exception e)
            {
                throw;
            }
        }