コード例 #1
0
        public JsonResult EditarDetallePartidos(DetallePartidos oDetallePartido, Deducciones[] oDeducciones)
        {
            JsonResult jsonData = null;
            try
            {
                BaseDatosTorneos bdTorneos = new BaseDatosTorneos();
                int idAsociacion = Utilidades.ObtenerValorSession("idAsociacion");

                DetallePartidos oDetallePartidoEditado = (from d in bdTorneos.DetallePartidos
                                             where d.id == oDetallePartido.id
                                             select d).Single();
                oDetallePartidoEditado.estado = oDetallePartido.estado;
                oDetallePartidoEditado.total_pagar = oDetallePartido.total_pagar;
                oDetallePartidoEditado.total_rebajos = oDetallePartido.total_rebajos;
                oDetallePartidoEditado.deposito = oDetallePartido.deposito;

                bdTorneos.SaveChanges();
                bdTorneos.Detach(oDetallePartidoEditado);

                jsonData = Json(new { estado = "exito", mensaje = "", ObjetoDetalle = oDetallePartidoEditado, estadoValidacion = "exito" });

                if (oDeducciones != null)
                {
                    foreach (Deducciones oDeduccion in oDeducciones)
                    {
                        EditarDeducciones(oDeduccion, oDetallePartidoEditado.id);
                    }
                }
            }
            catch
            {
                jsonData = Json(new { estado = "error", mensaje = "Error cargando datos" });
            }
            return jsonData;
        }
コード例 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            Deducciones deducciones = db.Deducciones.Find(id);

            db.Deducciones.Remove(deducciones);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "IdDeduccion,NombreTipoDeducciones,DependeSalario,Estado")] Deducciones deducciones)
 {
     if (ModelState.IsValid)
     {
         db.Entry(deducciones).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(deducciones));
 }
コード例 #4
0
        public ActionResult Create([Bind(Include = "IdDeduccion,NombreTipoDeducciones,DependeSalario,Estado")] Deducciones deducciones)
        {
            if (ModelState.IsValid)
            {
                db.Deducciones.Add(deducciones);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(deducciones));
        }
コード例 #5
0
        // GET: Deducciones/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Deducciones deducciones = db.Deducciones.Find(id);

            if (deducciones == null)
            {
                return(HttpNotFound());
            }
            return(View(deducciones));
        }
コード例 #6
0
        public async Task <ICollection <TerceroDeduccionDto> > ObtenerDeduccionesXTercero(int parametroLiquidacionId)
        {
            var lista = await(from td in _context.TerceroDeducciones
                              join ae in _context.ActividadEconomica on td.ActividadEconomicaId equals ae.ActividadEconomicaId into ActividadEconomica
                              from acteco in ActividadEconomica.DefaultIfEmpty()
                              join d in _context.Deduccion on td.DeduccionId equals d.DeduccionId into Deducciones
                              from ded in Deducciones.DefaultIfEmpty()
                              join td1 in _context.Tercero on ded.TerceroId equals td1.TerceroId into TerceroDeducciones1
                              from ter1 in TerceroDeducciones1.DefaultIfEmpty()
                              join td2 in _context.Tercero on td.TerceroDeDeduccionId equals td2.TerceroId into TerceroDeducciones2
                              from ter2 in TerceroDeducciones2.DefaultIfEmpty()
                              where (td.ParametroLiquidacionTerceroId == parametroLiquidacionId)
                              select new TerceroDeduccionDto()
            {
                TerceroDeduccionId = td.TerceroDeduccionId,
                Codigo             = ded.DeduccionId > 0 ? ded.Codigo : string.Empty,
                ValorFijo          = td.ValorFijo.HasValue ? td.ValorFijo.Value : 0,
                Tercero            = new ValorSeleccion()
                {
                    Id = td.TerceroId
                },
                ActividadEconomica = new ValorSeleccion()
                {
                    Id     = acteco.ActividadEconomicaId > 0 ? acteco.ActividadEconomicaId : 0,
                    Codigo = acteco.ActividadEconomicaId > 0 ? acteco.Codigo : string.Empty,
                    Nombre = acteco.ActividadEconomicaId > 0 ? acteco.Nombre : string.Empty,
                },
                Deduccion = new DeduccionDto()
                {
                    DeduccionId = ded.DeduccionId > 0 ? ded.DeduccionId : 0,
                    Codigo      = ded.DeduccionId > 0 ? ded.Codigo : string.Empty,
                    Nombre      = ded.DeduccionId > 0 ? ded.Nombre : string.Empty,
                    Tarifa      = ded.DeduccionId > 0 ? ded.Tarifa : 0,
                    EsValorFijo = ded.DeduccionId > 0 ? ded.EsValorFijo : false,
                },
                TerceroDeDeduccion = new ValorSeleccion()
                {
                    Id     = ter2.TerceroId > 0 ? ter2.TerceroId : 0,
                    Codigo = ter2.TerceroId > 0 ? ter2.NumeroIdentificacion : string.Empty,
                    Nombre = ter2.TerceroId > 0 ? ter2.Nombre : string.Empty,
                    Valor  = ter2.TerceroId > 0 ? "SI" : "NO",
                }
            }
                              )
                        .Distinct()
                        .OrderBy(d => d.Codigo)
                        .ToListAsync();

            return(lista);
        }
コード例 #7
0
        public void EditarDeducciones(Deducciones oDeducciones, int idDetallePartido)
        {
            BaseDatosTorneos bdTorneos = new BaseDatosTorneos();

            switch (oDeducciones.accionregistro)
            {
            case 1:
                Deducciones oDeduccionesNuevo = new Deducciones();
                oDeduccionesNuevo.idDetallePartido = idDetallePartido;
                oDeduccionesNuevo.tipo             = oDeducciones.tipo;
                oDeduccionesNuevo.monto            = oDeducciones.monto;
                oDeduccionesNuevo.observaciones    = oDeducciones.observaciones;


                bdTorneos.AddToDeducciones(oDeduccionesNuevo);
                bdTorneos.SaveChanges();

                break;

            case 3:
                Deducciones oDeduccionesEliminado = (from t in bdTorneos.Deducciones
                                                     where t.id == oDeducciones.id
                                                     select t).Single();

                bdTorneos.DeleteObject(oDeduccionesEliminado);
                bdTorneos.SaveChanges();
                break;

            case 2:
                Deducciones oDeduccionesEditado = (from t in bdTorneos.Deducciones
                                                   where t.id == oDeducciones.id
                                                   select t).Single();

                oDeduccionesEditado.tipo          = oDeducciones.tipo;
                oDeduccionesEditado.monto         = oDeducciones.monto;
                oDeduccionesEditado.observaciones = oDeducciones.observaciones;

                bdTorneos.SaveChanges();

                break;
            }
        }
コード例 #8
0
        void limpiar()
        {
            BordEmpleado.Visibility = Visibility.Collapsed;

            EmpleadoSeleccionado = null;

            Deudas.Clear();
            modelo.Clear();
            dgOperaciones.ItemsSource = null;
            dgOperaciones.Visibility  = Visibility.Collapsed;

            Sueldo = Bonificaciones = Deducciones = Total = 0;

            txtHorasTrabajadas.Text = "0";
            txtHorasExtras.Text     = "0";

            txtTotalSueldo.Text         = Sueldo.ToString("0.00") + " €";
            txtMontoBonificaciones.Text = Bonificaciones.ToString("0.00") + " €";
            txtMontoDeducciones.Text    = "-" + Deducciones.ToString("0.00") + " €";
            txtMontoTotal.Text          = Total.ToString("0.00") + " €";
        }
コード例 #9
0
        public JsonResult ValidarDeducciones(Deducciones oDeducciones, String oper)
        {
            JsonResult jsonData = null;

            try
            {
                switch (oper)
                {
                case "edit":
                    if (oDeducciones.accionregistro == 0)
                    {
                        oDeducciones.accionregistro = 2;
                    }
                    break;

                case "add":
                    oDeducciones.accionregistro = 1;
                    oDeducciones.id             = Math.Abs(Guid.NewGuid().GetHashCode());
                    break;

                case "del":
                    if (oDeducciones.accionregistro == 1 || oDeducciones.accionregistro == null)
                    {
                        oDeducciones.accionregistro = 0;
                    }
                    else
                    {
                        oDeducciones.accionregistro = 3;
                    }
                    break;
                }
                jsonData = Json(new { estado = "exito", mensaje = "", ObjetoDetalle = oDeducciones, estadoValidacion = "exito" });
            }
            catch
            {
                jsonData = Json(new { estado = "error", mensaje = "Error cargando datos" });
            }
            return(jsonData);
        }
コード例 #10
0
        public void EditarDeducciones(Deducciones oDeducciones, int idDetallePartido)
        {
            BaseDatosTorneos bdTorneos = new BaseDatosTorneos();
            switch (oDeducciones.accionregistro)
            {
                case 1:
                    Deducciones oDeduccionesNuevo = new Deducciones();
                    oDeduccionesNuevo.idDetallePartido = idDetallePartido;
                    oDeduccionesNuevo.tipo = oDeducciones.tipo;
                    oDeduccionesNuevo.monto = oDeducciones.monto;
                    oDeduccionesNuevo.observaciones = oDeducciones.observaciones;

                    bdTorneos.AddToDeducciones(oDeduccionesNuevo);
                    bdTorneos.SaveChanges();

                    break;
                case 3:
                    Deducciones oDeduccionesEliminado = (from t in bdTorneos.Deducciones
                                                    where t.id == oDeducciones.id
                                                    select t).Single();

                    bdTorneos.DeleteObject(oDeduccionesEliminado);
                    bdTorneos.SaveChanges();
                    break;
                case 2:
                    Deducciones oDeduccionesEditado = (from t in bdTorneos.Deducciones
                                                where t.id == oDeducciones.id
                                                select t).Single();

                    oDeduccionesEditado.tipo = oDeducciones.tipo;
                    oDeduccionesEditado.monto = oDeducciones.monto;
                    oDeduccionesEditado.observaciones = oDeducciones.observaciones;

                    bdTorneos.SaveChanges();

                    break;
            }
        }
コード例 #11
0
        /// <summary>
        /// Función que lee los nodos XML de un documento CFDI
        /// </summary>
        /// <param name="padre"></param>
        private void LeerNodos(XmlNode padre)
        {
            // Procesamos el nodo
            switch (padre.Prefix)
            {
            case "cfdi": {
                switch (padre.LocalName)
                {
                case "Comprobante":
                    cfdi           = new Comprobante();
                    cfdi.atributos = leerAtributos(padre);
                    break;

                case "Emisor":
                    cfdi.Emisor           = new Emisor();
                    cfdi.Emisor.atributos = leerAtributos(padre);
                    break;

                case "DomicilioFiscal":
                    cfdi.Emisor.DomicilioFiscal           = new DomicilioFiscal();
                    cfdi.Emisor.DomicilioFiscal.atributos = leerAtributos(padre);
                    break;

                case "ExpedidoEn":
                    cfdi.Emisor.ExpedidoEn           = new ExpedidoEn();
                    cfdi.Emisor.ExpedidoEn.atributos = leerAtributos(padre);
                    break;

                case "RegimenFiscal":
                    cfdi.Emisor.RegimenFiscal = padre.Attributes["Regimen"].Value;
                    break;

                case "Receptor":
                    cfdi.Receptor           = new Receptor();
                    cfdi.Receptor.atributos = leerAtributos(padre);
                    break;

                case "Domicilio":
                    cfdi.Receptor.Domicilio           = new Domicilio();
                    cfdi.Receptor.Domicilio.atributos = leerAtributos(padre);
                    break;

                case "Conceptos":
                    cfdi.Conceptos = new Conceptos();
                    break;

                case "Concepto":
                    Concepto concepto = new Concepto();
                    concepto.atributos = leerAtributos(padre);
                    cfdi.Conceptos.Agregar(concepto);
                    break;

                case "Impuestos":
                    cfdi.Impuestos           = new Impuestos();
                    cfdi.Impuestos.atributos = leerAtributos(padre);
                    break;

                case "Traslados":
                    cfdi.Impuestos.Traslados = new Traslados();
                    break;

                case "Traslado":
                    Traslado traslado = new Traslado();
                    traslado.atributos = leerAtributos(padre);
                    cfdi.Impuestos.Traslados.Agregar(traslado);
                    break;

                case "Retenciones":
                    cfdi.Impuestos.Retenciones = new Retenciones();
                    break;

                case "Retencion":
                    Retencion retencion = new Retencion();
                    retencion.atributos = leerAtributos(padre);
                    cfdi.Impuestos.Retenciones.Agregar(retencion);
                    break;
                }
                break;
            }

            case "tfd": {
                switch (padre.LocalName)
                {
                case "TimbreFiscalDigital":
                    TimbreFiscalDigital timbre = new TimbreFiscalDigital();
                    timbre.atributos = leerAtributos(padre);
                    cfdi.AgregarComplemento(timbre);
                    break;
                }
                break;
            }

            case "nomina": {
                switch (padre.LocalName)
                {
                case "Nomina":
                    Nomina nomina = new Nomina();
                    nomina.atributos = leerAtributos(padre);
                    cfdi.AgregarComplemento(nomina);
                    break;

                case "Percepciones":
                    Percepciones percepciones = new Percepciones();
                    percepciones.atributos = leerAtributos(padre);
                    nomina = cfdi.Complemento("nomina") as Nomina;
                    nomina.Percepciones = new Percepciones();
                    break;

                case "Percepcion":
                    Percepcion percepcion = new Percepcion();
                    percepcion.atributos = leerAtributos(padre);
                    nomina = cfdi.Complemento("nomina") as Nomina;
                    nomina.Percepciones.Agregar(percepcion);
                    break;

                case "Deducciones":
                    Deducciones deducciones = new Deducciones();
                    deducciones.atributos = leerAtributos(padre);
                    nomina             = cfdi.Complemento("nomina") as Nomina;
                    nomina.Deducciones = deducciones;
                    break;

                case "Deduccion":
                    Deduccion deduccion = new Deduccion();
                    deduccion.atributos = leerAtributos(padre);
                    nomina = cfdi.Complemento("nomina") as Nomina;
                    nomina.Deducciones.Agregar(deduccion);
                    break;

                case "Incapacidades":
                    nomina = cfdi.Complemento("nomina") as Nomina;
                    nomina.Incapacidades = new Incapacidades();
                    break;

                case "Incapacidad":
                    Incapacidad incapacidad = new Incapacidad();
                    incapacidad.atributos = leerAtributos(padre);
                    nomina = cfdi.Complemento("nomina") as Nomina;
                    nomina.Incapacidades.Agregar(incapacidad);
                    break;

                case "HorasExtras":
                    nomina             = cfdi.Complemento("nomina") as Nomina;
                    nomina.HorasExtras = new HorasExtras();
                    break;

                case "HorasExtra":
                    HorasExtra horasExtra = new HorasExtra();
                    horasExtra.atributos = leerAtributos(padre);
                    nomina = cfdi.Complemento("nomina") as Nomina;
                    nomina.HorasExtras.Agregar(horasExtra);
                    break;
                }
                break;
            }

            case "ecc": {
                switch (padre.LocalName)
                {
                case "EstadoDeCuentaCombustible":
                    EstadoDeCuentaCombustible edoCta = new EstadoDeCuentaCombustible();
                    edoCta.atributos = leerAtributos(padre);
                    cfdi.AgregarComplemento(edoCta);
                    break;

                case "Conceptos":
                    EstadoDeCuentaCombustible combustible = cfdi.Complemento("combustible") as EstadoDeCuentaCombustible;
                    combustible.conceptos = new ConceptosEstadoDeCuentaCombustibles();
                    break;

                case "ConceptoEstadoDeCuentaCombustible":
                    ConceptoEstadoDeCuenta concepto = new ConceptoEstadoDeCuenta();
                    concepto.atributos = leerAtributos(padre);
                    combustible        = cfdi.Complemento("combustible") as EstadoDeCuentaCombustible;
                    combustible.Agregar(concepto);
                    break;

                case "Traslados":
                    combustible = cfdi.Complemento("combustible") as EstadoDeCuentaCombustible;
                    combustible.conceptos[combustible.conceptos.Elementos - 1].traslados = new TrasladosConceptosEstadoDeCuentaCombustible();
                    break;

                case "Traslado":
                    TrasladoEstadoDeCuentaCombustible traslado = new TrasladoEstadoDeCuentaCombustible();
                    traslado.atributos = leerAtributos(padre);
                    combustible        = cfdi.Complemento("combustible") as EstadoDeCuentaCombustible;
                    combustible.conceptos[combustible.conceptos.Elementos - 1].AgregaTraslado(traslado);
                    break;
                }
                break;
            }

            case "implocal": {
                switch (padre.LocalName)
                {
                case "ImpuestosLocales":
                    ImpuestosLocales implocal = new ImpuestosLocales();
                    implocal.atributos = leerAtributos(padre);
                    cfdi.AgregarComplemento(implocal);
                    break;
                }
                break;
            }
            }

            // Procesamos los nodos hijos
            for (int i = 0; i < padre.ChildNodes.Count; i++)
            {
                if (padre.ChildNodes[i].NodeType == XmlNodeType.Element)
                {
                    LeerNodos(padre.ChildNodes[i]);
                }
            }
        }
コード例 #12
0
 public JsonResult ValidarDeducciones(Deducciones oDeducciones, String oper)
 {
     JsonResult jsonData = null;
     try
     {
         switch (oper)
         {
             case "edit":
                 if (oDeducciones.accionregistro == 0)
                 {
                     oDeducciones.accionregistro = 2;
                 }
                 break;
             case "add":
                 oDeducciones.accionregistro = 1;
                 oDeducciones.id = Math.Abs(Guid.NewGuid().GetHashCode());
                 break;
             case "del":
                 if (oDeducciones.accionregistro == 1 || oDeducciones.accionregistro == null)
                 {
                     oDeducciones.accionregistro = 0;
                 }
                 else
                 {
                     oDeducciones.accionregistro = 3;
                 }
                 break;
         }
         jsonData = Json(new { estado = "exito", mensaje = "", ObjetoDetalle = oDeducciones, estadoValidacion = "exito" });
     }
     catch
     {
         jsonData = Json(new { estado = "error", mensaje = "Error cargando datos" });
     }
     return jsonData;
 }
コード例 #13
0
        public async Task <ActionResult> GenerarPlanilla(int?ID, bool?enviarEmail, DateTime fechaInicio, DateTime fechaFin, List <ViewModelTasasDeCambio> monedas, int tmon_IdMonedaDeduccionesDePlanilla)
        {
            #region declaracion de instancias

            // helper
            General utilities = new General();

            // instancias para el comprobante de pago
            List <IngresosDeduccionesVoucher> ListaIngresosVoucher    = new List <IngresosDeduccionesVoucher>();
            List <IngresosDeduccionesVoucher> ListaDeduccionesVoucher = new List <IngresosDeduccionesVoucher>();
            ComprobantePagoModel       oComprobantePagoModel          = new ComprobantePagoModel();
            IngresosDeduccionesVoucher ingresosColaborador            = new IngresosDeduccionesVoucher();
            IngresosDeduccionesVoucher deduccionesColaborador         = new IngresosDeduccionesVoucher();

            // instancias para el reporte final
            ReportePlanillaViewModel        oPlanillaEmpleado;
            List <ReportePlanillaViewModel> reporte = new List <ReportePlanillaViewModel>();
            ViewModelListaErrores           oError;
            List <ViewModelListaErrores>    listaErrores = new List <ViewModelListaErrores>();

            // instancia para resultado del proceso en izitoast
            General.iziToast response       = new General.iziToast();
            int    errores                  = 0;
            string codigoDePlanillaGenerada = String.Empty;
            #endregion

            #region inicia proceso de generación de planilla
            try
            {
                using (ERP_GMEDINAEntities db = new ERP_GMEDINAEntities())
                {
                    List <tbCatalogoDePlanillas> oIDSPlanillas = new List <tbCatalogoDePlanillas>();
                    List <int> planillasConColaboradores       = db.V_ColaboradoresPorPlanilla.Where(x => x.CantidadColaboradores > 0).Select(x => x.cpla_IdPlanilla).ToList();

                    // seleccionar las planillas que se van a generar
                    if (ID != null)
                    {
                        oIDSPlanillas = db.tbCatalogoDePlanillas
                                        .Where(X => X.cpla_IdPlanilla == ID)
                                        .ToList();
                    }
                    else
                    {
                        oIDSPlanillas = db.tbCatalogoDePlanillas
                                        .Where(x => x.cpla_Activo == true && planillasConColaboradores.Contains(x.cpla_IdPlanilla))
                                        .ToList();
                    }

                    if (oIDSPlanillas != null)
                    {
                        // procesar todas las planillas seleccionadas
                        foreach (var iter in oIDSPlanillas)
                        {
                            codigoDePlanillaGenerada = $"PLANI_{Function.DatetimeNow().Year}{Function.DatetimeNow().Month}{Function.DatetimeNow().Day}_{Function.DatetimeNow().Hour}{Function.DatetimeNow().Minute}{Function.DatetimeNow().Second}";
                            try
                            {
                                // planilla actual del foreach
                                tbCatalogoDePlanillas oPlanilla = db.tbCatalogoDePlanillas
                                                                  .Find(iter.cpla_IdPlanilla);

                                // ingresos de la planilla actual
                                List <V_PlanillaIngresos> oIngresos = db.V_PlanillaIngresos
                                                                      .Where(x => x.cpla_IdPlanilla == oPlanilla.cpla_IdPlanilla)
                                                                      .ToList();

                                // deducciones de la planilla actual
                                List <V_PlanillaDeducciones> oDeducciones = db.V_PlanillaDeducciones
                                                                            .Where(x => x.cpla_IdPlanilla == oPlanilla.cpla_IdPlanilla)
                                                                            .ToList();

                                // empleados de la planilla actual
                                List <tbEmpleados> oEmpleados = db.tbEmpleados
                                                                .Where(emp => emp.cpla_IdPlanilla == oPlanilla.cpla_IdPlanilla &&
                                                                       emp.emp_Estado == true)
                                                                .ToList();

                                int contador        = 1,
                                    idHistorialPago = 0,
                                    idDetalleDeduccionHisotorialesContador = 1,
                                    idDetalleIngresoHisotorialesContador   = 1;

                                string identidadEmpleado = string.Empty,
                                       NombresEmpleado   = string.Empty;

                                // procesar planilla empleado por empleado
                                foreach (var empleadoActual in oEmpleados)
                                {
                                    using (var dbContextTransaccion = db.Database.BeginTransaction())
                                    {
                                        try
                                        {
                                            #region variables reporte view model

                                            string codColaborador = string.Empty,
                                             nombreColaborador    = string.Empty,
                                             tipoPlanilla         = string.Empty;

                                            decimal SalarioBase  = 0,
                                                    salarioHora  = 0,
                                                    totalAFP     = 0,
                                                    totalISR     = 0,
                                                    totalSalario = 0;

                                            int horasTrabajadas       = 0,
                                                horasExtrasTrabajadas = 0,
                                                cantidadUnidadesBonos = 0;

                                            decimal?totalComisiones              = 0,
                                                   totalHorasExtras              = 0,
                                                   totalHorasPermiso             = 0,
                                                   totalBonificaciones           = 0,
                                                   totalIngresosIndivuales       = 0,
                                                   totalVacaciones               = 0,
                                                   totalIngresosEmpleado         = 0,
                                                   colaboradorDeducciones        = 0,
                                                   totalInstitucionesFinancieras = 0,
                                                   totalOtrasDeducciones         = 0,
                                                   adelantosSueldo               = 0,
                                                   totalDeduccionesEmpleado      = 0,
                                                   totalDeduccionesIndividuales  = 0,
                                                   netoAPagarColaborador         = 0;

                                            oPlanillaEmpleado = new ReportePlanillaViewModel();
                                            oError            = new ViewModelListaErrores();
                                            string moneda = db.tbSueldos.Where(x => x.emp_Id == empleadoActual.emp_Id && x.sue_Estado == true).Select(x => x.tbTipoMonedas.tmon_Descripcion).FirstOrDefault();

                                            // variables para insertar en los historiales de pago
                                            IEnumerable <object> listHistorialPago = null;
                                            string MensajeError = "";
                                            List <tbHistorialDeduccionPago>  lisHistorialDeducciones = new List <tbHistorialDeduccionPago>();
                                            List <tbHistorialDeIngresosPago> lisHistorialIngresos    = new List <tbHistorialDeIngresosPago>();


                                            #endregion

                                            V_InformacionColaborador InformacionDelEmpleadoActual = null;
                                            decimal resultSeptimoDia = 0;

                                            int userId = (int)Session["UserLogin"];
                                            //Procesar Ingresos
                                            await Task.Run(() => Ingresos.ProcesarIngresos(userId, fechaInicio,
                                                                                           fechaFin,
                                                                                           ListaIngresosVoucher,
                                                                                           listaErrores,
                                                                                           ref errores,
                                                                                           db,
                                                                                           empleadoActual,
                                                                                           ref SalarioBase,
                                                                                           out horasTrabajadas,
                                                                                           ref salarioHora,
                                                                                           ref totalSalario,
                                                                                           ref totalComisiones,
                                                                                           out horasExtrasTrabajadas,
                                                                                           ref cantidadUnidadesBonos,
                                                                                           ref totalHorasExtras,
                                                                                           ref totalHorasPermiso,
                                                                                           ref totalBonificaciones,
                                                                                           ref totalIngresosIndivuales,
                                                                                           ref totalVacaciones,
                                                                                           out totalIngresosEmpleado,
                                                                                           lisHistorialIngresos,
                                                                                           out InformacionDelEmpleadoActual,
                                                                                           out resultSeptimoDia));

                                            //Procesar Deducciones
                                            await Task.Run(() => Deducciones.ProcesarDeducciones(tmon_IdMonedaDeduccionesDePlanilla,
                                                                                                 monedas,
                                                                                                 userId, fechaInicio,
                                                                                                 fechaFin,
                                                                                                 ListaDeduccionesVoucher,
                                                                                                 listaErrores,
                                                                                                 ref errores,
                                                                                                 db,
                                                                                                 oDeducciones,
                                                                                                 empleadoActual,
                                                                                                 SalarioBase,
                                                                                                 totalIngresosEmpleado,
                                                                                                 ref colaboradorDeducciones,
                                                                                                 ref totalAFP,
                                                                                                 ref totalInstitucionesFinancieras,
                                                                                                 ref totalOtrasDeducciones,
                                                                                                 ref adelantosSueldo,
                                                                                                 out totalDeduccionesEmpleado,
                                                                                                 ref totalDeduccionesIndividuales,
                                                                                                 out netoAPagarColaborador,
                                                                                                 lisHistorialDeducciones,
                                                                                                 InformacionDelEmpleadoActual));

                                            //ISR
                                            TimeSpan tDias = fechaFin - fechaInicio;
                                            totalISR = CalculoISR.CalcularISR(db, empleadoActual, totalSalario, totalISR, tDias.Days + 1);

                                            idHistorialPago = GuardarEnHistorialDePago.GuardarHistorialDePago(fechaInicio,
                                                                                                              fechaFin,
                                                                                                              listaErrores,
                                                                                                              ref errores,
                                                                                                              codigoDePlanillaGenerada,
                                                                                                              db,
                                                                                                              ref contador,
                                                                                                              ref idDetalleDeduccionHisotorialesContador,
                                                                                                              ref idDetalleIngresoHisotorialesContador,
                                                                                                              empleadoActual,
                                                                                                              totalSalario,
                                                                                                              totalComisiones,
                                                                                                              horasExtrasTrabajadas,
                                                                                                              cantidadUnidadesBonos,
                                                                                                              totalHorasExtras,
                                                                                                              totalHorasPermiso,
                                                                                                              totalBonificaciones,
                                                                                                              totalIngresosIndivuales,
                                                                                                              totalVacaciones,
                                                                                                              totalISR,
                                                                                                              totalAFP,
                                                                                                              adelantosSueldo,
                                                                                                              totalDeduccionesIndividuales,
                                                                                                              netoAPagarColaborador,
                                                                                                              ref listHistorialPago,
                                                                                                              ref MensajeError,
                                                                                                              lisHistorialDeducciones,
                                                                                                              lisHistorialIngresos,
                                                                                                              InformacionDelEmpleadoActual,
                                                                                                              resultSeptimoDia);

                                            // guardar cambios en la bbdd
                                            db.SaveChanges();
                                            dbContextTransaccion.Commit();

                                            //EnviarComprobanteDePago
                                            await Task.Run(() => EnviarComprobanteDePago.EnviarComprobanteDePagoColaborador(moneda,
                                                                                                                            enviarEmail,
                                                                                                                            fechaInicio,
                                                                                                                            fechaFin,
                                                                                                                            utilities,
                                                                                                                            ref ListaIngresosVoucher,
                                                                                                                            ref ListaDeduccionesVoucher,
                                                                                                                            oComprobantePagoModel,
                                                                                                                            listaErrores,
                                                                                                                            ref errores,
                                                                                                                            db,
                                                                                                                            empleadoActual,
                                                                                                                            totalIngresosEmpleado,
                                                                                                                            totalDeduccionesEmpleado,
                                                                                                                            netoAPagarColaborador,
                                                                                                                            InformacionDelEmpleadoActual));

                                            #region crear registro de la planilla del colaborador para el reporte
                                            await Task.Run(() => ReportePlanilla.ReporteColaboradorPlanilla(moneda,
                                                                                                            ref oPlanillaEmpleado,
                                                                                                            empleadoActual,
                                                                                                            SalarioBase,
                                                                                                            horasTrabajadas,
                                                                                                            salarioHora,
                                                                                                            totalSalario,
                                                                                                            totalComisiones,
                                                                                                            horasExtrasTrabajadas,
                                                                                                            totalHorasExtras,
                                                                                                            totalHorasPermiso,
                                                                                                            totalBonificaciones,
                                                                                                            totalIngresosIndivuales,
                                                                                                            totalVacaciones,
                                                                                                            totalIngresosEmpleado,
                                                                                                            totalISR,
                                                                                                            colaboradorDeducciones,
                                                                                                            totalAFP,
                                                                                                            totalInstitucionesFinancieras,
                                                                                                            totalOtrasDeducciones,
                                                                                                            adelantosSueldo,
                                                                                                            totalDeduccionesEmpleado,
                                                                                                            totalDeduccionesIndividuales,
                                                                                                            netoAPagarColaborador,
                                                                                                            InformacionDelEmpleadoActual));

                                            reporte.Add(oPlanillaEmpleado);
                                            oPlanillaEmpleado = null;
                                            identidadEmpleado = InformacionDelEmpleadoActual.per_Identidad;
                                            NombresEmpleado   = InformacionDelEmpleadoActual.per_Nombres;
                                            #endregion
                                        }
                                        #endregion
                                        // catch por si hubo un error al generar la planilla de un empleado
                                        catch (Exception ex)
                                        {
                                            // si hay un error, hacer un rollback
                                            dbContextTransaccion.Rollback();

                                            // mensaje del error en el registro del colaborador
                                            errores++;

                                            listaErrores.Add(new ViewModelListaErrores
                                            {
                                                Identidad         = identidadEmpleado,
                                                NombreColaborador = NombresEmpleado,
                                                Error             = "Error al procesar planilla del colaborador.",
                                                PosibleSolucion   = "Verifique información registrada al colaborador y vuelva a intentarlo."
                                            });
                                        }
                                    } // termina transaccion
                                }
                            }
                            // catch si se produjo un error al procesar una sola planilla
                            catch (Exception ex)
                            {
                                listaErrores.Add(new ViewModelListaErrores
                                {
                                    Identidad         = $"Planilla {iter.cpla_DescripcionPlanilla}",
                                    NombreColaborador = "",
                                    Error             = $"Ocurrió un error al procesar la planilla {iter.cpla_DescripcionPlanilla}"
                                });
                                errores++;
                            }
                        } // for each idsPlanillas
                    }     // if idsPlanilla != null
                }         // using entities model

                // enviar resultado al cliente
                response.Response   = $"El proceso de generación de planilla se realizó, con {errores} errores";
                response.Encabezado = "Exito";
                response.Tipo       = errores == 0 ? "success" : "warning";
            }
            // catch se produjo un error fatal en el proceso generar planilla
            catch (Exception ex)
            {
                response.Response   = "";
                response.Encabezado = "Error";
                response.Tipo       = "error";
                listaErrores.Add(new ViewModelListaErrores
                {
                    Identidad         = $"Planilla",
                    NombreColaborador = "",
                    Error             = $"El proceso de generación de planillas falló, contacte al adminstrador.",
                    PosibleSolucion   = "Vuelva a intentarlo"
                });
            }

            // retornar resultado del proceso
            return(Json(new { Data = reporte, listaDeErrores = listaErrores, Response = response }, JsonRequestBehavior.AllowGet));
        }
コード例 #14
0
        public ActionResult PrevisualizarPlanilla(int?ID, bool?enviarEmail, DateTime fechaInicio, DateTime fechaFin, List <ViewModelTasasDeCambio> monedas, int tmon_IdMonedaDeduccionesDePlanilla)
        {
            #region declaracion de instancias

            // helper
            General utilities = new General();

            // instancias para el reporte final
            ReportePlanillaViewModel        oPlanillaEmpleado;
            List <ReportePlanillaViewModel> reporte = new List <ReportePlanillaViewModel>();
            ViewModelListaErrores           oError;
            List <ViewModelListaErrores>    listaErrores = new List <ViewModelListaErrores>();

            // instancia para resultado del proceso en izitoast
            General.iziToast response = new General.iziToast();
            int errores = 0;
            #endregion

            #region inicia proceso de previsualizacion de planilla
            try
            {
                using (ERP_GMEDINAEntities db = new ERP_GMEDINAEntities())
                {
                    List <tbCatalogoDePlanillas> oIDSPlanillas = new List <tbCatalogoDePlanillas>();
                    List <int> planillasConColaboradores       = db.V_ColaboradoresPorPlanilla.Where(x => x.CantidadColaboradores > 0).Select(x => x.cpla_IdPlanilla).ToList();

                    // seleccionar las planillas que se van a generar
                    if (ID != null)
                    {
                        oIDSPlanillas = db.tbCatalogoDePlanillas
                                        .Where(X => X.cpla_IdPlanilla == ID)
                                        .ToList();
                    }
                    else
                    {
                        oIDSPlanillas = db.tbCatalogoDePlanillas
                                        .Where(x => x.cpla_Activo == true && planillasConColaboradores.Contains(x.cpla_IdPlanilla))
                                        .ToList();
                    }

                    // procesar todas las planillas seleccionadas
                    foreach (var iter in oIDSPlanillas)
                    {
                        try
                        {
                            // planilla actual del foreach
                            tbCatalogoDePlanillas oPlanilla = db.tbCatalogoDePlanillas
                                                              .Find(iter.cpla_IdPlanilla);

                            // ingresos de la planilla actual
                            List <V_PlanillaIngresos> oIngresos = db.V_PlanillaIngresos
                                                                  .Where(x => x.cpla_IdPlanilla == oPlanilla.cpla_IdPlanilla)
                                                                  .ToList();

                            // deducciones de la planilla actual
                            List <V_PlanillaDeducciones> oDeducciones = db.V_PlanillaDeducciones
                                                                        .Where(x => x.cpla_IdPlanilla == oPlanilla.cpla_IdPlanilla)
                                                                        .ToList();

                            // empleados de la planilla actual
                            List <tbEmpleados> oEmpleados = db.tbEmpleados
                                                            .Where(emp => emp.cpla_IdPlanilla == oPlanilla.cpla_IdPlanilla &&
                                                                   emp.emp_Estado == true)
                                                            .ToList();


                            // procesar planilla empleado por empleado
                            foreach (var empleadoActual in oEmpleados)
                            {
                                using (var dbContextTransaccion = db.Database.BeginTransaction())
                                {
                                    try
                                    {
                                        #region inicia proceso de previsualización

                                        #region variables reporte view model

                                        string codColaborador = string.Empty,
                                         nombreColaborador    = string.Empty,
                                         tipoPlanilla         = string.Empty;

                                        decimal SalarioBase  = 0,
                                                salarioHora  = 0,
                                                totalSalario = 0,
                                                totalISR     = 0,
                                                totalAFP     = 0;

                                        int horasTrabajadas       = 0,
                                            horasExtrasTrabajadas = 0,
                                            cantidadUnidadesBonos = 0;

                                        decimal?
                                            totalComisiones               = 0,
                                            totalHorasExtras              = 0,
                                            totalHorasPermiso             = 0,
                                            totalBonificaciones           = 0,
                                            totalIngresosIndivuales       = 0,
                                            totalVacaciones               = 0,
                                            totalIngresosEmpleado         = 0,
                                            colaboradorDeducciones        = 0,
                                            totalInstitucionesFinancieras = 0,
                                            totalOtrasDeducciones         = 0,
                                            adelantosSueldo               = 0,
                                            totalDeduccionesEmpleado      = 0,
                                            totalDeduccionesIndividuales  = 0,
                                            netoAPagarColaborador         = 0;

                                        oPlanillaEmpleado = new ReportePlanillaViewModel();
                                        string moneda = db.tbSueldos.Where(x => x.emp_Id == empleadoActual.emp_Id).Select(x => x.tbTipoMonedas.tmon_Descripcion).FirstOrDefault();

                                        #endregion

                                        V_InformacionColaborador InformacionDelEmpleadoActual;
                                        decimal resultSeptimoDia = 0;
                                        int     userId           = (int)Session["UserLogin"];

                                        // procesa ingresos
                                        Ingresos.PrevisualizarProcesarIngresos(userId,
                                                                               fechaInicio,
                                                                               fechaFin,
                                                                               listaErrores,
                                                                               ref errores,
                                                                               db,
                                                                               empleadoActual,
                                                                               ref SalarioBase,
                                                                               out horasTrabajadas,
                                                                               ref salarioHora,
                                                                               ref totalSalario,
                                                                               ref totalComisiones,
                                                                               out horasExtrasTrabajadas,
                                                                               ref cantidadUnidadesBonos,
                                                                               ref totalHorasExtras,
                                                                               ref totalHorasPermiso,
                                                                               ref totalBonificaciones,
                                                                               ref totalIngresosIndivuales,
                                                                               ref totalVacaciones,
                                                                               out totalIngresosEmpleado,
                                                                               out InformacionDelEmpleadoActual,
                                                                               out resultSeptimoDia);

                                        // procesar deducciones
                                        Deducciones.PrevisualizarProcesarDeducciones(tmon_IdMonedaDeduccionesDePlanilla,
                                                                                     monedas,
                                                                                     userId,
                                                                                     fechaInicio,
                                                                                     fechaFin,
                                                                                     listaErrores,
                                                                                     ref errores,
                                                                                     db,
                                                                                     oDeducciones,
                                                                                     empleadoActual,
                                                                                     SalarioBase,
                                                                                     totalIngresosEmpleado,
                                                                                     ref colaboradorDeducciones,
                                                                                     ref totalAFP,
                                                                                     ref totalInstitucionesFinancieras,
                                                                                     ref totalOtrasDeducciones,
                                                                                     ref adelantosSueldo,
                                                                                     out totalDeduccionesEmpleado,
                                                                                     ref totalDeduccionesIndividuales,
                                                                                     out netoAPagarColaborador,
                                                                                     InformacionDelEmpleadoActual);

                                        //Deducciones.ProcesarDeduccionesParaPrevisualizacion(fechaInicio, fechaFin, db, oDeducciones, empleadoActual, SalarioBase, totalIngresosEmpleado, ref colaboradorDeducciones, ref totalAFP, ref totalInstitucionesFinancieras, ref totalOtrasDeducciones, ref adelantosSueldo, out totalDeduccionesEmpleado, ref totalDeduccionesIndividuales, out netoAPagarColaborador);

                                        // procesar isr
                                        TimeSpan tDias = fechaFin - fechaInicio;
                                        totalISR = CalculoISR.CalcularISR(db, empleadoActual, totalSalario, totalISR, tDias.Days + 1);

                                        #region crear registro de la planilla del colaborador para el reporte

                                        // reporte
                                        ReportePlanilla.ReportePlanillaPrevisualizacion(moneda, ref oPlanillaEmpleado, empleadoActual, SalarioBase, horasTrabajadas, salarioHora, totalSalario, totalComisiones, horasExtrasTrabajadas, totalHorasExtras, totalHorasPermiso, totalBonificaciones, totalIngresosIndivuales, totalVacaciones, totalIngresosEmpleado, totalISR, colaboradorDeducciones, totalAFP, totalInstitucionesFinancieras, totalOtrasDeducciones, adelantosSueldo, totalDeduccionesEmpleado, totalDeduccionesIndividuales, netoAPagarColaborador, InformacionDelEmpleadoActual);
                                        reporte.Add(oPlanillaEmpleado);
                                        oPlanillaEmpleado = null;
                                        #endregion


                                        #endregion
                                    }
                                    // catch por si hubo un error al generar la planilla de un empleado
                                    catch (Exception ex)
                                    {
                                        // mensaje del error en el registro del colaborador
                                        errores++;
                                    }
                                }
                            }
                        }
                        // catch si se produjo un error al procesar una sola planilla
                        catch (Exception ex)
                        {
                            errores++;
                        }
                    }
                }

                // enviar resultado al cliente
                response.Response   = $"El proceso de generación de planilla se realizó, con {errores} errores";
                response.Encabezado = "Exito";
                response.Tipo       = errores == 0 ? "success" : "warning";
            }
            // catch se produjo un error fatal en el proceso generar planilla
            catch (Exception ex)
            {
                response.Response   = "El proceso de generación de planillas falló, contacte al adminstrador.";
                response.Encabezado = "Error";
                response.Tipo       = "error";
            }
            #endregion

            // retornar resultado del proceso
            return(Json(new { Data = reporte, listaDeErrores = listaErrores, Response = response }, JsonRequestBehavior.AllowGet));
        }