Esempio n. 1
0
        private void consultarExistencia()
        {
            ReportesDAO reportesDAO = new ReportesDAO();

            Existencia[] existencia = null;
            int          i          = 0;

            dateTimePicker2.Format       = DateTimePickerFormat.Custom;
            dateTimePicker2.CustomFormat = "yyyy-MM-dd";
            String fechaSel = dateTimePicker2.Text;

            dateTimePicker2.Format = DateTimePickerFormat.Long;
            int numeroReg = 0;

            numeroReg  = reportesDAO.numeroConsulta(fechaSel, comboBox1.SelectedIndex);
            existencia = reportesDAO.consultaExistencia(fechaSel, numeroReg, comboBox1.SelectedIndex);
            while (i < numeroReg)
            {
                DataGridViewRow row = (DataGridViewRow)dataGridView3.Rows[0].Clone();
                row.Cells[0].Value = existencia[i].IdProducto;
                row.Cells[1].Value = reportesDAO.nombreProducto(existencia[i].IdProducto);
                row.Cells[2].Value = existencia[i].Cantidad;
                dataGridView3.Rows.Add(row);
                i++;
            }
        }
Esempio n. 2
0
        private void top5Recorridos_Click(object sender, EventArgs e)
        {
            int semestreSeleccionado = 0;
            int anioSeleccionado = 0;

            Program.Navigation.PopUpPage(
                new ListadoEstadistico_SemestreAnio(
                (semestre, anio) => {
                    semestreSeleccionado = semestre;
                    anioSeleccionado = anio;
                }));

            if (DatosValidos(semestreSeleccionado, anioSeleccionado))
            {
                dataGridView1.DataSource = ReportesDAO.GetRecorridosConPasajesMasComprados(semestreSeleccionado, anioSeleccionado);
            }
        }
Esempio n. 3
0
        private void top5CrucerosSinVentas_Click(object sender, EventArgs e)
        {
            int semestreSeleccionado = 0;
            int anioSeleccionado = 0;

            Program.Navigation.PopUpPage(
                new ListadoEstadistico_SemestreAnio(
                (semestre, anio) =>
                {
                    semestreSeleccionado = semestre;
                    anioSeleccionado = anio;
                }));

            if (DatosValidos(semestreSeleccionado, anioSeleccionado))
            {
                dataGridView1.DataSource = ReportesDAO.GetCrucerosConMasCabinasLibresEnCadaViaje(semestreSeleccionado, anioSeleccionado);
            }
        }
Esempio n. 4
0
        public string crearexcel(int idusuario, string ruta, int idSucursal, NOM_PeriodosPago Periodo, bool complemento, DateTime FechaIni, DateTime FechaFin)
        {
            using (var context = new RHEntities())
            {
                var cliente = (from c in context.Cliente
                               join s in context.Sucursal
                               on c.IdCliente equals s.IdCliente
                               where s.IdSucursal == idSucursal
                               select c.Nombre).FirstOrDefault();

                var sucursal = context.Sucursal.FirstOrDefault(x => x.IdSucursal == idSucursal);

                List <SucursalesEmpresa> ListaEmpresas = new List <SucursalesEmpresa>();
                ReportesDAO       rep     = new ReportesDAO();
                List <int>        lista   = new List <int>();
                List <NOM_Nomina> nominas = new List <NOM_Nomina>();
                ReportesDAO       banemp  = new ReportesDAO();

                bool spei, bnte;



                int CountTotal = 0;

                if (complemento == false) // pregunta si la sesion esta en modo complemento o no
                {
                    ListaEmpresas = rep.ListSucursalEmpresaFiscales(idSucursal);
                    // si no esta en modo complemento solo trae el listado de las empresas fiscales
                }
                else
                {
                    if (Periodo.Sindicato == false)
                    // si la sesion esta en modo complemento , pregunta si el periodo es sindicato o no
                    {
                        ListaEmpresas = rep.ListaSucursalesEmpresasConComplemento(idSucursal, Periodo);
                        // si es solo complemento /trae las empresas fiscales y complemento
                    }
                    else
                    {
                        ListaEmpresas = rep.ListaSucursalesEmpresasConSindicato(idSucursal);
                        // si es sindicato trae las empresas fiscales , complemento y sindicato
                    }
                }
                var idempelados = rep.GetIdEmpleadosProcesados(Periodo.IdPeriodoPago);

                if (idempelados == null)
                {
                    return("No se encontró datos en este periodo");
                }

                var newruta = ValidarFolderUsuario(idusuario, ruta);
                var nombre  = "Dispersion " + cliente + " del Periodo " + Periodo.Descripcion;
                newruta = newruta + nombre + ".xlsx";
                var wb = new XLWorkbook();



                foreach (var emp in ListaEmpresas)
                {
                    List <RegistroEmpleados> pago_efectivo = new List <RegistroEmpleados>();
                    spei = false;
                    bnte = false;
                    decimal total = 0, totale = 0, totalS = 0, totalB = 0, totalisr = 0;
                    if (Periodo.IdTipoNomina == 16)
                    {
                        nominas =
                            context.NOM_Nomina.Where(
                                x => x.IdPeriodo == Periodo.IdPeriodoPago && x.IdEmpresaAsimilado == emp.IdTabla)
                            .ToList();
                    }
                    else if (Periodo.SoloComplemento == false && Periodo.Sindicato == false)
                    {
                        nominas =
                            context.NOM_Nomina.Where(
                                x =>
                                x.IdPeriodo == Periodo.IdPeriodoPago &&
                                (x.IdEmpresaFiscal == emp.IdTabla || x.IdEmpresaComplemento == emp.IdTabla))
                            .ToList();
                    }
                    else if (Periodo.SoloComplemento == true)
                    {
                        nominas =
                            context.NOM_Nomina.Where(
                                x => x.IdPeriodo == Periodo.IdPeriodoPago && x.IdEmpresaComplemento == emp.IdTabla)
                            .ToList();
                    }
                    else if (Periodo.IdTipoNomina == 17 || Periodo.Sindicato == true)
                    {
                        nominas =
                            context.NOM_Nomina.Where(
                                x => x.IdPeriodo == Periodo.IdPeriodoPago && x.IdEmpresaSindicato == emp.IdTabla)
                            .ToList();
                    }

                    int count = 0;
                    int aux   = 1;


                    if (emp.RP != null)
                    {
                        CountTotal =
                            nominas.Count(x => x.IdEmpresaFiscal == emp.IdTabla || x.IdEmpresaAsimilado == emp.IdTabla);
                    }
                    else
                    {
                        CountTotal =
                            nominas.Count(
                                x => x.IdEmpresaComplemento == emp.IdTabla || x.IdEmpresaSindicato == emp.IdTabla);
                    }

                    string[] nombreEmpresa;
                    int      i = 7;
                    int      j = 0;

                    if (CountTotal >= 0)
                    {
                        if (Periodo.IdTipoNomina == 16)
                        {
                            var lista_idnomina = nominas.Select(x => x.IdNomina).ToList();
                            totalisr =
                                context.NOM_Nomina_Detalle.Where(
                                    x => x.IdConcepto == 43 && lista_idnomina.Contains(x.IdNomina))
                                .Select(x => x.Total)
                                .Sum();
                        }

                        nombreEmpresa = emp.Nombre.Split(' ');
                        var nombreHoja = "Dispersion " + nombreEmpresa[0];

                        if (nombreHoja.Length > 30)
                        {
                            nombreHoja = nombreHoja.Substring(0, 30);
                        }

                        var ws = wb.Worksheets.Add(nombreHoja);
                        ws.Cell("A3").Value = $"{cliente} - {sucursal.Ciudad}"; //mty
                        ws.Cell("A4").Value = emp.Nombre;
                        ws.Cell("A5").Value = "Dispersion";
                        ws.Cell("A6").Value = FechaIni.ToString("dd-MM-yyyy") + " al " + FechaFin.ToString("dd-MM-yyyy");

                        foreach (var em in nominas)
                        {
                            var listbank = banemp.datosBancariosByEmpresa(em.IdEmpleado);

                            if (!lista.Contains(listbank.IdBanco))
                            {
                                lista.Add(listbank.IdBanco);
                            }
                        }
                        List <ListadoBancoEmpleados> listadoRegistros = new List <ListadoBancoEmpleados>();
                        foreach (var b in lista)
                        {
                            var datos = rep.datosBancoEmpleados(b, nominas, emp.IdTabla);
                            listadoRegistros.Add(datos);
                        }



                        if (emp.RP != null)
                        {
                            foreach (var r in listadoRegistros)
                            {
                                if (r.IdBanco == 2)
                                {
                                    if (!bnte)
                                    {
                                        ws.Cell("A" + i).Value = r.NombreBanco;
                                        ws.Range("A" + i + ":E" + i).Merge();
                                        ws.Cell("A" + i)
                                        .Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                                        ws.Cell("A" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1);
                                        i++;
                                        ws.Cell("A" + i).Value = "NoSiga";
                                        ws.Cell("A" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        ws.Cell("B" + i).Value = "NOMBRE DEL COLABORADOR";
                                        ws.Cell("B" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        ws.Cell("C" + i).Value = "IMPORTE TOTAL";
                                        ws.Cell("C" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        ws.Cell("D" + i).Value = "Cuenta";
                                        ws.Cell("D" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        ws.Cell("E" + i).Value = "Metodo De Pago";
                                        ws.Cell("E" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        i++;
                                        bnte = true;
                                    }

                                    foreach (var e in r.empleados.OrderBy(x => x.NoSigaF).ThenBy(im => im.Importe))
                                    {
                                        if (e.tipocuenta != "Efectivo")
                                        {
                                            if (e.NoSigaF > 0)
                                            {
                                                ws.Cell("A" + i).Value = e.NoSigaF;
                                            }
                                            else
                                            {
                                                ws.Cell("A" + i).Value = 0;
                                            }

                                            ws.Cell("B" + i).Value = e.Empleado;
                                            ws.Cell("C" + i).Value = Utils.TruncateDecimales(e.Importe);
                                            ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                            ws.Cell("D" + i).Value    = e.cuenta;
                                            ws.Cell("D" + i).DataType = XLCellValues.Text;
                                            ws.Cell("E" + i).Value    = e.tipocuenta;


                                            total  = total + e.Importe;
                                            totalB = totalB + e.Importe;
                                            i++;
                                        }
                                        else
                                        {
                                            pago_efectivo.Add(e);
                                        }
                                    }
                                    ws.Cell("B" + i).Value                     = "Suma";
                                    ws.Cell("B" + i).Style.Font.Bold           = true;
                                    ws.Cell("C" + i).Value                     = totalB;
                                    ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                    ws.Cell("C" + i).Style.Font.Bold           = true;
                                    i++;
                                }
                                else
                                {
                                    if (!spei)
                                    {
                                        ws.Cell("A" + i).Value = "SPEI";
                                        ws.Range("A" + i + ":E" + i).Merge();
                                        ws.Cell("A" + i)
                                        .Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                                        ws.Cell("A" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1);
                                        i++;
                                        ws.Cell("A" + i).Value = "NoSiga";
                                        ws.Cell("A" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        ws.Cell("B" + i).Value = "NOMBRE DEL COLABORADOR";
                                        ws.Cell("B" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        ws.Cell("C" + i).Value = "IMPORTE TOTAL";
                                        ws.Cell("C" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        ws.Cell("D" + i).Value = "Cuenta";
                                        ws.Cell("D" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        ws.Cell("E" + i).Value = "Metodo De Pago";
                                        ws.Cell("E" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        i++;
                                        spei = true;
                                    }



                                    foreach (var e in r.empleados.OrderBy(x => x.NoSigaF).ThenBy(im => im.Importe))
                                    {
                                        if (e.tipocuenta != "Efectivo")
                                        {
                                            if (e.NoSigaF > 0)
                                            {
                                                ws.Cell("A" + i).Value = e.NoSigaF;
                                            }
                                            else
                                            {
                                                ws.Cell("A" + i).Value = 0;
                                            }

                                            ws.Cell("B" + i).Value = e.Empleado;
                                            ws.Cell("C" + i).Value = Utils.TruncateDecimales(e.Importe);
                                            ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                            ws.Cell("D" + i).Value    = e.cuenta;
                                            ws.Cell("D" + i).DataType = XLCellValues.Text;
                                            ws.Cell("E" + i).Value    = e.tipocuenta;
                                            total  = total + e.Importe;
                                            totalS = totalS + e.Importe;
                                            i++;
                                        }
                                        else
                                        {
                                            pago_efectivo.Add(e);
                                        }
                                    }


                                    count++;
                                    aux++;
                                }
                            }

                            if (spei)
                            {
                                ws.Cell("B" + i).Value                     = "Suma";
                                ws.Cell("B" + i).Style.Font.Bold           = true;
                                ws.Cell("C" + i).Value                     = totalS;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                ws.Cell("C" + i).Style.Font.Bold           = true;
                            }
                        }
                        else
                        {
                            foreach (var r in listadoRegistros)
                            {
                                if (r.IdBanco == 2)
                                {
                                    if (!bnte)
                                    {
                                        ws.Cell("A" + i).Value = r.NombreBanco;
                                        ws.Range("A" + i + ":E" + i).Merge();
                                        ws.Cell("A" + i)
                                        .Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                                        ws.Cell("A" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1);
                                        i++;
                                        ws.Cell("A" + i).Value = "NoSiga";
                                        ws.Cell("A" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        ws.Cell("B" + i).Value = "NOMBRE DEL COLABORADOR";
                                        ws.Cell("B" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        ws.Cell("C" + i).Value = "IMPORTE TOTAL";
                                        ws.Cell("C" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        ws.Cell("D" + i).Value = "Cuenta";
                                        ws.Cell("D" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        ws.Cell("E" + i).Value = "Metodo De Pago";
                                        ws.Cell("E" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        i++;
                                        bnte = true;
                                    }

                                    foreach (var e in r.empleados.OrderBy(x => x.NoSigaC).ThenBy(im => im.Importe))
                                    {
                                        if (e.tipocuenta != "Efectivo")
                                        {
                                            if (e.NoSigaC > 0)
                                            {
                                                ws.Cell("A" + i).Value = e.NoSigaC;
                                            }
                                            else
                                            {
                                                ws.Cell("A" + i).Value = 0;
                                            }

                                            ws.Cell("B" + i).Value = e.Empleado;
                                            ws.Cell("C" + i).Value = Utils.TruncateDecimales(e.Importe);
                                            ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                            ws.Cell("D" + i).Value    = e.cuenta;
                                            ws.Cell("D" + i).DataType = XLCellValues.Text;
                                            ws.Cell("E" + i).Value    = e.tipocuenta;
                                            total  = total + e.Importe;
                                            totalB = totalB + e.Importe;
                                            i++;
                                        }
                                        else
                                        {
                                            pago_efectivo.Add(e);
                                        }
                                    }
                                    ws.Cell("B" + i).Value                     = "Suma";
                                    ws.Cell("B" + i).Style.Font.Bold           = true;
                                    ws.Cell("C" + i).Value                     = totalB;
                                    ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                    ws.Cell("C" + i).Style.Font.Bold           = true;
                                    i++;
                                }
                                else
                                {
                                    if (!spei)
                                    {
                                        ws.Cell("A" + i).Value = "SPEI";
                                        ws.Range("A" + i + ":E" + i).Merge();
                                        ws.Cell("A" + i)
                                        .Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                                        ws.Cell("A" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1);
                                        i++;
                                        ws.Cell("A" + i).Value = "NoSiga";
                                        ws.Cell("A" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        ws.Cell("B" + i).Value = "NOMBRE DEL COLABORADOR";
                                        ws.Cell("B" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        ws.Cell("C" + i).Value = "IMPORTE TOTAL";
                                        ws.Cell("C" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        ws.Cell("D" + i).Value = "Cuenta";
                                        ws.Cell("D" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        ws.Cell("E" + i).Value = "Metodo De Pago";
                                        ws.Cell("E" + i).Style.Fill.BackgroundColor =
                                            XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                                        i++;
                                        spei = true;
                                    }



                                    foreach (var e in r.empleados.OrderBy(x => x.NoSigaC).ThenBy(im => im.Importe))
                                    {
                                        if (e.tipocuenta != "Efectivo")
                                        {
                                            if (e.NoSigaC > 0)
                                            {
                                                ws.Cell("A" + i).Value = e.NoSigaC;
                                            }
                                            else
                                            {
                                                ws.Cell("A" + i).Value = 0;
                                            }

                                            ws.Cell("B" + i).Value = e.Empleado;
                                            ws.Cell("C" + i).Value = Utils.TruncateDecimales(e.Importe);
                                            ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                            ws.Cell("D" + i).Value    = e.cuenta;
                                            ws.Cell("D" + i).DataType = XLCellValues.Text;
                                            ws.Cell("E" + i).Value    = e.tipocuenta;
                                            total  = total + e.Importe;
                                            totalS = totalS + e.Importe;
                                            i++;
                                        }
                                        else
                                        {
                                            pago_efectivo.Add(e);
                                        }
                                    }



                                    aux++;
                                }
                            }

                            if (spei)
                            {
                                ws.Cell("B" + i).Value                     = "Suma";
                                ws.Cell("B" + i).Style.Font.Bold           = true;
                                ws.Cell("C" + i).Value                     = totalS;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                ws.Cell("C" + i).Style.Font.Bold           = true;
                            }
                        }
                        //////////////////////////////////////////////////////////////////////////////
                        i++;
                        ws.Cell("A" + i).Value = "EFECTIVO";
                        ws.Range("A" + i + ":E" + i).Merge();
                        ws.Cell("A" + i).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                        ws.Cell("A" + i).Style.Fill.BackgroundColor = XLColor.FromTheme(XLThemeColor.Accent1);
                        i++;
                        ws.Cell("A" + i).Value = "NoSiga";
                        ws.Cell("A" + i).Style.Fill.BackgroundColor = XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                        ws.Cell("B" + i).Value = "NOMBRE DEL COLABORADOR";
                        ws.Cell("B" + i).Style.Fill.BackgroundColor = XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                        ws.Cell("C" + i).Value = "IMPORTE TOTAL";
                        ws.Cell("C" + i).Style.Fill.BackgroundColor = XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                        ws.Cell("D" + i).Value = "Cuenta";
                        ws.Cell("D" + i).Style.Fill.BackgroundColor = XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                        ws.Cell("E" + i).Value = "Metodo De Pago";
                        ws.Cell("E" + i).Style.Fill.BackgroundColor = XLColor.FromTheme(XLThemeColor.Accent1, 0.5);
                        i++;
                        foreach (var e in pago_efectivo.OrderBy(x => x.NoSigaC).ThenBy(im => im.Importe))
                        {
                            if (e.NoSigaC > 0)
                            {
                                ws.Cell("A" + i).Value = e.NoSigaC;
                            }
                            else
                            {
                                ws.Cell("A" + i).Value = 0;
                            }

                            ws.Cell("B" + i).Value = e.Empleado;
                            ws.Cell("C" + i).Value = Utils.TruncateDecimales(e.Importe);
                            ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                            ws.Cell("D" + i).Value    = e.cuenta;
                            ws.Cell("D" + i).DataType = XLCellValues.Text;
                            ws.Cell("E" + i).Value    = e.tipocuenta;
                            total  = total + e.Importe;
                            totale = totale + e.Importe;
                            i++;
                        }
                        ws.Cell("B" + i).Value                     = "Suma";
                        ws.Cell("B" + i).Style.Font.Bold           = true;
                        ws.Cell("C" + i).Value                     = totale;
                        ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                        ws.Cell("C" + i).Style.Font.Bold           = true;
                        i++;
                        /////////////////////////////////////////////////////

                        ws.Cell("B" + i).Value                       = "Total Dispersion:";
                        ws.Cell("B" + i).Style.Font.Bold             = true;
                        ws.Cell("C" + i).Value                       = total;
                        ws.Cell("C" + i).Style.NumberFormat.Format   = "$ #,##0.00";
                        ws.Cell("C" + i).Style.Font.Bold             = true;
                        ws.Cell("C" + i).Style.Font.FontSize         = 13;
                        ws.Cell("C" + i).Style.Border.TopBorder      = XLBorderStyleValues.Medium;
                        ws.Cell("C" + i).Style.Border.TopBorderColor = XLColor.Black;
                        /////////////////////////////////////////////////////
                        if (emp.RP != null)
                        {
                            var factura =
                                context.NOM_Facturacion.Where(
                                    x => x.IdEmpresaFi_As == emp.IdTabla && x.IdPeriodo == Periodo.IdPeriodoPago)
                                .FirstOrDefault();
                            if (factura != null)
                            {
                                #region FACTURA

                                i = i + 2;
                                ws.Cell("B" + i).Value = "Relativos";
                                ws.Range("B" + i + ":F" + i).Merge();
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center)
                                .Font.SetBold();
                                i = i + 1;

                                ws.Cell("B" + i).Value = "CUOTAS IMSS E INFONAVIT";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = factura.F_Cuota_IMSS_Infonavit;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "IMPUESTO SOBRE NOMINAS";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = factura.F_Impuesto_Nomina;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "AMORTIZACION INFONAVIT";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = factura.F_Amortizacion_Infonavit;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;

                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                if (Periodo.IdTipoNomina == 16)
                                {
                                    ws.Cell("B" + i).Value = "ISR";
                                    ws.Cell("C" + i).Value = totalisr;
                                }
                                else
                                {
                                    ws.Cell("B" + i).Value = "FONACOT";
                                    ws.Cell("C" + i).Value = factura.F_Fonacot;
                                }
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                if (factura.F_Pension_Alimenticia > 0)
                                {
                                    ws.Cell("B" + i).Value = "PENSION ALIMENTICIA";
                                    ws.Cell("B" + i).Style
                                    .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                    .Font.SetBold();
                                    ws.Cell("C" + i).Value = factura.F_Pension_Alimenticia;
                                    ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                    i = i + 1;
                                }

                                ws.Cell("B" + i).Value = "RELATIVO";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = factura.F_Relativo + totalisr;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "TOTAL PERCEPCIONES";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = factura.F_Total_Nomina;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "TOTAL NETO";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = factura.F_Total_Fiscal + totalisr;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;

                                #endregion
                            }
                        }
                        else
                        {
                            var factura =
                                context.NOM_FacturacionComplemento.Where(
                                    x => x.IdPeriodo == Periodo.IdPeriodoPago && x.IdEmpresaC == emp.IdTabla)
                                .FirstOrDefault();

                            var facturaS =
                                context.NOM_FacturacionSindicato.Where(
                                    x => x.IdPeriodo == Periodo.IdPeriodoPago && x.IdEmpresaS == emp.IdTabla)
                                .FirstOrDefault();

                            if (factura != null)
                            {
                                #region FACTURA
                                i = i + 2;
                                ws.Cell("B" + i).Value = "FACTURACION";
                                ws.Range("B" + i + ":F" + i).Merge();
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center)
                                .Font.SetBold();
                                i = i + 1;

                                ws.Cell("B" + i).Value = "PERCEPCIONES";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = factura.C_Percepciones;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "SERVICIOS " + factura.C_Porcentaje_Servicio;
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = factura.C_Total_Servicio;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;



                                ws.Cell("B" + i).Value = "RELATIVO";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = factura.C_Relativos;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "DESCUENTOS";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = factura.C_Descuentos;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "OTROS";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = factura.C_Otros;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "SUBTOTAL";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = factura.C_Subtotal;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "IVA";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = factura.C_Total_IVA;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "TOTAL NETO";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = factura.C_Total_Complemento;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                #endregion
                            }
                            else if (facturaS != null) // facturacion de sindicato
                            {
                                #region FACTURA S



                                i = i + 2;
                                ws.Cell("B" + i).Value = "FACTURACION";
                                ws.Range("B" + i + ":F" + i).Merge();
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center)
                                .Font.SetBold();
                                i = i + 1;

                                ws.Cell("B" + i).Value = "PERCEPCIONES SINDICATO";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = facturaS.S_Percepcion_Sindicato;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "SERVICIOS " + facturaS.S_Porcentaje_Comision;
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = facturaS.S_Total_Comision;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;


                                ws.Cell("B" + i).Value = "PERCEPCIONES FISCAL";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = facturaS.S_Percepcion_Fiscal;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "IVA PERCEPCION FISCAL";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = facturaS.S_IVA_Percepcion_Fiscal;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;


                                ws.Cell("B" + i).Value = "DIFERENCIA EMPRESA";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = facturaS.S_Dif_Montvde;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "CUOTA LEGADO";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = facturaS.S_Cuota_Legado;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "COSTO IMSS";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = facturaS.S_Costo_IMSS;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "IVA COSTO IMSS";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = facturaS.S_IVA_Costo_IMSS;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "IMPUESTO SOBRE NOMINA";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = facturaS.S_Total_Porcentaje_Nomina;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "IVA IMPUESTO SOBRE NOMINA";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = facturaS.S_IVA_Porcentaje_Nomina;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;
                                ws.Cell("B" + i).Value = "TOTAL FACTURA";
                                ws.Cell("B" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("C" + i).Value = facturaS.S_Total_Sindicato;
                                ws.Cell("C" + i).Style.NumberFormat.Format = "$ #,##0.00";
                                i = i + 1;


                                #endregion
                            }
                        }


                        //ESTILOS DE LAS CELDAS
                        #region ESTILOS
                        ws.Range("A3:E3").Merge();
                        ws.Cell("A3").Style
                        .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center)
                        .Font.SetBold();
                        ws.Range("A4:E4").Merge();
                        ws.Cell("A4").Style
                        .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center)
                        .Font.SetBold();

                        ws.Range("A5:E5").Merge();
                        ws.Cell("A5").Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);

                        ws.Range("A6:E6").Merge();
                        ws.Cell("A6").Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);

                        ws.Columns("8,1").AdjustToContents();
                        ws.Columns("8,2").AdjustToContents();
                        ws.Columns("8,3").AdjustToContents();
                        ws.Columns("8,4").AdjustToContents();
                        ws.Columns("8,5").AdjustToContents();
                        #endregion
                    }
                }
                wb.SaveAs(newruta);

                //Guardar como, y aqui ponemos la ruta de nuestro archivo

                return(newruta);
            }
        }
 public List <ReporteReservasAnio> ReservasxAnio(string anio, int idSede)
 {
     return(ReportesDAO.ReservasXAnio(anio, idSede));
 }
Esempio n. 6
0
 public Reportes()
 {
     this.reporteAsistencia = new ReportesDAO();
 }
Esempio n. 7
0
        private void consultar()
        {
            String      estado      = "";
            String      canceladas  = "";
            int         idIni       = 0;
            int         idFin       = 0;
            int         numImp      = 0;
            int         numPen      = 0;
            int         numFac      = 0;
            int         numCan      = 0;
            Double      totSub      = 0;
            Double      totImp      = 0;
            Double      kilos       = 0;
            Double      importe     = 0;
            ReportesDAO reportesDAO = new ReportesDAO();
            String      fechaHoy    = DateTime.Today.ToShortDateString();

            dateTimePicker1.Format       = DateTimePickerFormat.Custom;
            dateTimePicker1.CustomFormat = "yyyy-MM-dd";
            String fechaSel = dateTimePicker1.Text;

            dateTimePicker1.Format = DateTimePickerFormat.Long;
            int numeroReg = 0;

            numeroReg     = reportesDAO.numeroRegistros(fechaSel);
            textBox5.Text = numeroReg.ToString();
            int i = 0;

            VentaNota[] ventaNota = null;
            ventaNota = reportesDAO.consultaNota(fechaSel, numeroReg);
            // No sumar notas canceladas
            try
            {
                idIni = ventaNota[i].IdNota;
            }
            catch (Exception ex) {
                idIni = 0;
            }
            while (i < numeroReg)
            {
                DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();
                row.Cells[0].Value = ventaNota[i].FolioNota;
                row.Cells[1].Value = ventaNota[i].IdCliente;
                row.Cells[2].Value = ventaNota[i].Subtotal;
                row.Cells[3].Value = ventaNota[i].Iva;
                row.Cells[4].Value = ventaNota[i].Total;
                if (ventaNota[i].Estado != 4)
                {
                    totSub += ventaNota[i].Subtotal;
                    totImp += ventaNota[i].Total;
                }
                switch (ventaNota[i].Estado)
                {
                case 1:
                    estado = "Impresa";
                    numImp++;
                    break;

                case 2:
                    estado = "Pendiente";
                    numPen++;
                    break;

                case 3:
                    estado = "Facturada";
                    numFac++;
                    break;

                case 4:
                    estado      = "Cancelada";
                    canceladas += " && idNota != " + ventaNota[i].IdNota;
                    numCan++;
                    break;
                }
                row.Cells[5].Value = estado;
                idFin = ventaNota[i].IdNota;
                dataGridView1.Rows.Add(row);
                i++;
            }
            textBox1.Text = numCan.ToString();
            textBox2.Text = numFac.ToString();
            textBox3.Text = numImp.ToString();
            textBox4.Text = numPen.ToString();
            textBox6.Text = totSub.ToString();
            textBox7.Text = totImp.ToString();
            dataGridView2.Rows.Clear();
            if (idIni != 0)
            {
                i = 0;
                idIni--;
                idFin++;
                String      query        = "SELECT count(distinct(IdProducto)) FROM ordenventa where idNota > " + idIni + " && idNota < " + idFin + canceladas + ";";
                String      query2       = "SELECT IdProducto,sum(cantidad),sum(importe) FROM ordenventa where idNota > " + idIni + " && idNota < " + idFin + canceladas + " group by IdProducto;";
                int         numProductos = reportesDAO.numeroProductos(query);
                OrdenNota[] ordenNota    = null;
                ordenNota = reportesDAO.consultaOrden(query2, numProductos);
                while (i < numProductos)
                {
                    DataGridViewRow row = (DataGridViewRow)dataGridView2.Rows[0].Clone();
                    row.Cells[0].Value = ordenNota[i].IdProducto;
                    row.Cells[1].Value = reportesDAO.nombreProducto(ordenNota[i].IdProducto);
                    row.Cells[2].Value = ordenNota[i].Cantidad;
                    kilos += ordenNota[i].Cantidad;
                    row.Cells[3].Value = ordenNota[i].Importe;
                    importe           += ordenNota[i].Importe;
                    dataGridView2.Rows.Add(row);
                    i++;
                }
            }
            textBox8.Text = kilos.ToString();
            textBox9.Text = importe.ToString();
        }
Esempio n. 8
0
        public string crearexcel(int idusuario, string ruta, int IdSucursal, int IdPeriodo, bool complemento, DateTime FechaIni, DateTime FechaFin)
        {
            List <SucursalesEmpresa> s = new List <SucursalesEmpresa>();
            ReportesDAO rep            = new ReportesDAO();
            List <int>  lista          = new List <int>();

            if (complemento == false)
            {
                s = rep.ListSucursalEmpresaFiscales(IdSucursal);
            }
            else
            {
                s = rep.ListaSucursalesEmpresasConComplemento(IdSucursal);
            }
            var idempelados = rep.GetIdEmpleadosProcesados(IdPeriodo);

            if (idempelados == null)
            {
                return("No se encontró datos en este periodo");
            }

            var newruta = ValidarFolderUsuario(idusuario, ruta);

            newruta = newruta + "Dispersion.xlsx";
            var wb         = new XLWorkbook();
            int count      = 0;
            int count2     = 0;
            int count3     = 0;
            int count4     = 0;
            int CountTotal = 0;

            foreach (var empresas in s)
            {
                string[] oracion;
                decimal  total = 0;

                ReportesDAO banemp = new ReportesDAO();
                if (empresas.RP != null)
                {
                    count      = ctx.NOM_Nomina.Where(x => x.IdEmpresaFiscal == empresas.IdTabla && x.IdPeriodo == IdPeriodo).Count();
                    count4     = ctx.NOM_Nomina.Where(x => x.IdEmpresaAsimilado == empresas.IdTabla && x.IdPeriodo == IdPeriodo).Count();
                    CountTotal = count + count4;
                }
                else
                {
                    count2 = ctx.NOM_Nomina.Where(x => x.IdEmpresaComplemento == empresas.IdTabla && x.IdPeriodo == IdPeriodo).Count();
                    count3 = ctx.NOM_Nomina.Where(x => x.IdEmpresaSindicato == empresas.IdTabla && x.IdPeriodo == IdPeriodo).Count();

                    CountTotal = +count2 + count3;
                }



                int i = 6;
                int j = 0;
                if (CountTotal > 0)
                {
                    oracion = empresas.Nombre.Split(' ');
                    var ws = wb.Worksheets.Add("Dispersion " + oracion[0]);
                    ws.Cell("C2").Value = empresas.Nombre;
                    ws.Cell("C3").Value = "Dispersion";
                    ws.Cell("C4").Value = FechaIni.ToString("dd-MM-yyyy") + " al " + FechaFin.ToString("dd-MM-yyyy");



                    foreach (var em in idempelados)
                    {
                        var listbank = banemp.datosBancariosByEmpresa(em.idempleado);

                        if (!lista.Contains(listbank.IdBanco))
                        {
                            lista.Add(listbank.IdBanco);
                        }
                    }
                    foreach (var b in lista)
                    {
                        var banco = ctx.C_Banco_SAT.Where(x => x.IdBanco == b).FirstOrDefault();
                        ws.Cell("C" + i).Value = banco.Descripcion;
                        ws.Range("C" + i + ":F" + i).Merge();
                        ws.Cell("C" + i).Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);
                        i++;
                        ws.Cell("C" + i).Value = "NOMBRE DEL COLABORADOR";
                        ws.Cell("D" + i).Value = "IMPORTE TOTAL";
                        ws.Cell("E" + i).Value = "NoSiga";
                        ws.Cell("F" + i).Value = "Cuenta";
                        i++;
                        foreach (var idemp in idempelados)
                        {
                            var datosbanco = banemp.DatosBancarios(idemp.idempleado);
                            if (datosbanco != null)
                            {
                                if (banco.IdBanco == datosbanco.idBanco)
                                {
                                    var DatosEmpleadoNomina = ctx.NOM_Nomina.Where(x => x.IdEmpleado == idemp.idempleado && x.IdPeriodo == IdPeriodo).FirstOrDefault();
                                    if (empresas.IdTabla == DatosEmpleadoNomina.IdEmpresaFiscal || empresas.IdTabla == DatosEmpleadoNomina.IdEmpresaAsimilado)
                                    {
                                        var datosBanco = ctx.DatosBancarios.Where(x => x.IdEmpleado == DatosEmpleadoNomina.IdEmpleado).FirstOrDefault();
                                        var nomina     = rep.EmpleadoDispersion(IdPeriodo, idemp.idempleado);
                                        ws.Cell("C" + i).Value = nomina.nombres + " " + nomina.paterno + " " + nomina.materno;
                                        ws.Cell("D" + i).Value = nomina.importePagar;
                                        ws.Cell("D" + i).Style.NumberFormat.Format = "$ #,##0.0000";
                                        ws.Cell("E" + i).Value = datosBanco.NoSigaF;
                                        ws.Cell("F" + i).Value = datosBanco.CuentaBancaria;
                                        total = total + nomina.importePagar;
                                        i++;
                                        //j = i;
                                    }
                                    else
                                    if (empresas.IdTabla == DatosEmpleadoNomina.IdEmpresaComplemento || empresas.IdTabla == DatosEmpleadoNomina.IdEmpresaSindicato)
                                    {
                                        var datosBanco = ctx.DatosBancarios.Where(x => x.IdEmpleado == DatosEmpleadoNomina.IdEmpleado).FirstOrDefault();
                                        var nomina     = rep.EmpleadoDispersion(IdPeriodo, idemp.idempleado);
                                        if (nomina.totalComplemento != 0)
                                        {
                                            ws.Cell("C" + i).Value = nomina.nombres + " " + nomina.paterno + " " + nomina.materno;
                                            ws.Cell("D" + i).Value = nomina.totalComplemento;
                                            ws.Cell("D" + i).Style.NumberFormat.Format = "$ #,##0.0000";
                                            ws.Cell("E" + i).Value = datosBanco.NoSigaC;
                                            ws.Cell("F" + i).Value = datosBanco.CuentaBancaria;
                                            total = total + nomina.totalComplemento;
                                            i++;
                                        }
                                    }
                                }
                                ws.Cell("C" + i).Value = "Total";
                                ws.Cell("D" + i).Value = total;
                            }
                        }
                        i++;
                        total = 0;
                    }


                    if (empresas.RP != null)
                    {
                        var factura = ctx.NOM_Facturacion.Where(x => x.IdEmpresaFi_As == empresas.IdTabla && x.IdPeriodo == IdPeriodo).FirstOrDefault();
                        if (factura != null)
                        {
                            i = i + 2;
                            ws.Cell("C" + i).Value = "Relativos";
                            ws.Range("C" + i + ":F" + i).Merge();
                            ws.Cell("C" + i).Style
                            .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center)
                            .Font.SetBold();
                            i = i + 1;

                            ws.Cell("C" + i).Value = "CUOTAS IMSS E INFONAVIT";
                            ws.Cell("C" + i).Style
                            .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                            .Font.SetBold();
                            ws.Cell("D" + i).Value = factura.F_Cuota_IMSS_Infonavit;
                            ws.Cell("D" + i).Style.NumberFormat.Format = "$ #,##0.0000";
                            i = i + 1;
                            ws.Cell("C" + i).Value = "IMPUESTO SOBRE NOMINAS";
                            ws.Cell("C" + i).Style
                            .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                            .Font.SetBold();
                            ws.Cell("D" + i).Value = factura.F_Impuesto_Nomina;
                            ws.Cell("D" + i).Style.NumberFormat.Format = "$ #,##0.0000";
                            i = i + 1;
                            ws.Cell("C" + i).Value = "AMORTIZACION INFONAVIT";
                            ws.Cell("C" + i).Style
                            .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                            .Font.SetBold();
                            ws.Cell("D" + i).Value = factura.F_Amortizacion_Infonavit;
                            ws.Cell("D" + i).Style.NumberFormat.Format = "$ #,##0.0000";
                            i = i + 1;
                            ws.Cell("C" + i).Value = "FONACOT";
                            ws.Cell("C" + i).Style
                            .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                            .Font.SetBold();
                            ws.Cell("D" + i).Value = factura.F_Fonacot;
                            ws.Cell("D" + i).Style.NumberFormat.Format = "$ #,##0.0000";
                            i = i + 1;
                            if (factura.F_Pension_Alimenticia > 0)
                            {
                                ws.Cell("C" + i).Value = "PENSION ALIMENTICIA";
                                ws.Cell("C" + i).Style
                                .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                                .Font.SetBold();
                                ws.Cell("D" + i).Value = factura.F_Pension_Alimenticia;
                                ws.Cell("D" + i).Style.NumberFormat.Format = "$ #,##0.0000";
                                i = i + 1;
                            }

                            ws.Cell("C" + i).Value = "RELATIVO";
                            ws.Cell("C" + i).Style
                            .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                            .Font.SetBold();
                            ws.Cell("D" + i).Value = factura.F_Relativo;
                            ws.Cell("D" + i).Style.NumberFormat.Format = "$ #,##0.0000";
                            i = i + 1;
                            ws.Cell("C" + i).Value = "TOTAL PERCEPCIONES";
                            ws.Cell("C" + i).Style
                            .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                            .Font.SetBold();
                            ws.Cell("D" + i).Value = factura.F_Total_Nomina;
                            ws.Cell("D" + i).Style.NumberFormat.Format = "$ #,##0.0000";
                            i = i + 1;
                            ws.Cell("C" + i).Value = "TOTAL NETO";
                            ws.Cell("C" + i).Style
                            .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                            .Font.SetBold();
                            ws.Cell("D" + i).Value = factura.F_Total_Fiscal;
                            ws.Cell("D" + i).Style.NumberFormat.Format = "$ #,##0.0000";
                            i = i + 1;
                        }
                    }
                    else
                    {
                        decimal cuotasImss       = 0;
                        decimal impuestoNomina   = 0;
                        decimal relativos        = 0;
                        decimal percepciones     = 0;
                        decimal totalComplemento = 0;
                        var     factura          = ctx.NOM_FacturacionComplemento.Where(x => x.IdPeriodo == IdPeriodo && x.IdEmpresaC == empresas.IdTabla).ToList();
                        foreach (var f in factura)
                        {
                            cuotasImss       = cuotasImss + f.C_Cuotas_IMSS_Infonavit;
                            impuestoNomina   = impuestoNomina + f.C_Impuesto_Nomina;
                            relativos        = relativos + f.C_Relativos;
                            percepciones     = percepciones + f.C_Relativos;
                            totalComplemento = totalComplemento + f.C_Total_Complemento;
                        }
                        if (factura != null)
                        {
                            i = i + 2;
                            ws.Cell("C" + i).Value = "Relativos";
                            ws.Range("C" + i + ":F" + i).Merge();
                            ws.Cell("C" + i).Style
                            .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center)
                            .Font.SetBold();
                            i = i + 1;

                            ws.Cell("C" + i).Value = "CUOTAS IMSS E INFONAVIT";
                            ws.Cell("C" + i).Style
                            .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                            .Font.SetBold();
                            ws.Cell("D" + i).Value = cuotasImss;
                            ws.Cell("D" + i).Style.NumberFormat.Format = "$ #,##0.0000";
                            i = i + 1;
                            ws.Cell("C" + i).Value = "IMPUESTO SOBRE NOMINAS";
                            ws.Cell("C" + i).Style
                            .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                            .Font.SetBold();
                            ws.Cell("D" + i).Value = impuestoNomina;
                            ws.Cell("D" + i).Style.NumberFormat.Format = "$ #,##0.0000";
                            i = i + 1;



                            ws.Cell("C" + i).Value = "RELATIVO";
                            ws.Cell("C" + i).Style
                            .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                            .Font.SetBold();
                            ws.Cell("D" + i).Value = relativos;
                            ws.Cell("D" + i).Style.NumberFormat.Format = "$ #,##0.0000";
                            i = i + 1;
                            ws.Cell("C" + i).Value = "TOTAL PERCEPCIONES";
                            ws.Cell("C" + i).Style
                            .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                            .Font.SetBold();
                            ws.Cell("D" + i).Value = percepciones;
                            ws.Cell("D" + i).Style.NumberFormat.Format = "$ #,##0.0000";
                            i = i + 1;
                            ws.Cell("C" + i).Value = "TOTAL NETO";
                            ws.Cell("C" + i).Style
                            .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Left)
                            .Font.SetBold();
                            ws.Cell("D" + i).Value = totalComplemento;
                            ws.Cell("D" + i).Style.NumberFormat.Format = "$ #,##0.0000";
                            i = i + 1;
                        }
                    }



                    //ESTILOS DE LAS CELDAS
                    //Titulo
                    ws.Range("C2:F2").Merge();
                    ws.Cell("C2").Style
                    .Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center)
                    .Font.SetBold();

                    ws.Range("C3:F3").Merge();
                    ws.Cell("C3").Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);

                    ws.Range("C4:F4").Merge();
                    ws.Cell("C4").Style.Alignment.SetHorizontal(XLAlignmentHorizontalValues.Center);

                    ws.Columns("7,3").AdjustToContents();
                    ws.Columns("7,4").AdjustToContents();
                    ws.Columns("7,5").AdjustToContents();
                    ws.Columns("7,6").AdjustToContents();
                }
            }



            wb.SaveAs(newruta);

            //Guardar como, y aqui ponemos la ruta de nuestro archivo

            return(newruta);
        }