Esempio n. 1
0
        private void GenerarReporte()
        {
            try
            {
                FacturasCajTableAdapter adapterFac = new FacturasCajTableAdapter();
                FacturasCajDataTable    dataFac    = new FacturasCajDataTable();

                if (fechaIni != fechaFin)
                {
                    dataFac = adapterFac.BuscarFacConCajEntreFechas(fechaIni, fechaFin);
                    log.Info($"Se buscó el reporte del {fechaIni.ToString("dd/MM/yyyy")} al {fechaFin.ToString("dd/MM/yyyy")} por el usuario {usuario.Nombre} {usuario.Apellidos}");
                }
                else
                {
                    dataFac = adapterFac.BuscarFacConCajeroHoy(fechaIni);
                    log.Info($"Se buscó el reporte del {fechaIni.ToString("dd/MM/yyyy")}  por el usuario {usuario.Nombre} {usuario.Apellidos}");
                }

                decimal totalVentas = 0;

                if (dataFac.Rows.Count > 0)
                {
                    foreach (FacturasCajRow facturas in dataFac)
                    {
                        DetalleProTableAdapter adapterDet = new DetalleProTableAdapter();
                        DetalleProDataTable    dataDet    = adapterDet.DetallePorIdFacConProd(facturas.IdFactura);

                        foreach (DetalleProRow detalles in dataDet)
                        {
                            double ITBIS = Convert.ToDouble(detalles.Precio * detalles.Cantidad) * 0.18;
                            ITBIS = Math.Round(ITBIS, 2);
                            double importe = Convert.ToDouble(detalles.Precio * detalles.Cantidad) + ITBIS;
                            importe = Math.Round(importe, 2);

                            dgvDetalles.Rows.Add(facturas.Cajero, facturas.IdFactura, detalles.Descripcion, detalles.Precio, detalles.Cantidad, ITBIS, detalles.Descuento, importe - Convert.ToDouble(detalles.Descuento));
                        }

                        totalVentas += facturas.TotalGeneral;
                    }

                    txtTotalVentas.Text = totalVentas.ToString();
                    txtNumVentas.Text   = dataFac.Rows.Count.ToString();

                    btnGuardar.Enabled  = true;
                    btnDetallar.Enabled = true;
                }
                else
                {
                    btnGuardar.Enabled  = false;
                    btnDetallar.Enabled = false;
                    LimpiarTodo();
                    MessageBox.Show("No hay facturas entre las fechas ingresadas");
                }
            }
            catch (Exception error)
            {
                log.Error($"Error: {error.Message}", error);
                MessageBox.Show($"Error: {error.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 2
0
        private void GenerarReporte(DateTime FechaInicio, DateTime FechaFin)
        {
            try
            {
                FacturasCajTableAdapter adapterFac = new FacturasCajTableAdapter();
                FacturasCajDataTable    dataFac    = adapterFac.BuscarFacConCajEntreFechas(FechaInicio, fechaFin);

                decimal totalVentas = 0, totalDeuda = 0, totalPagado = 0;
                ushort  contDeudas = 0;

                foreach (FacturasCajRow facturas in dataFac)
                {
                    DetalleProTableAdapter adapterDet = new DetalleProTableAdapter();
                    DetalleProDataTable    dataDet    = adapterDet.DetallePorIdFacConProd(facturas.IdFactura);

                    foreach (DetalleProRow detalles in dataDet)
                    {
                        double ITBIS = Convert.ToDouble(detalles.Precio * detalles.Cantidad) * 0.18;
                        ITBIS = Math.Round(ITBIS, 2);
                        double importe = Convert.ToDouble(detalles.Precio * detalles.Cantidad) + ITBIS;
                        importe = Math.Round(importe, 2);

                        dgvDetalles.Rows.Add(facturas.Cajero, facturas.IdFactura, detalles.Descripcion, detalles.Precio, detalles.Cantidad, ITBIS, detalles.Descuento, importe - Convert.ToDouble(detalles.Descuento));
                    }

                    totalVentas += facturas.TotalGeneral;

                    if (facturas.Pago < facturas.TotalGeneral)
                    {
                        decimal deudaHoy = facturas.Pago - facturas.TotalGeneral;
                        deudaHoy *= -1;

                        dgvDeudas.Rows.Add(facturas.Cajero, facturas.NomCliente, deudaHoy.ToString(), facturas.MontoDebe);
                        totalDeuda += deudaHoy;
                        contDeudas++;
                    }
                }

                PagoDeudaTableAdapter adapterPaD = new PagoDeudaTableAdapter();
                PagoDeudaDataTable    dataPaD    = adapterPaD.BuscarEntreFechasPD(FechaInicio, fechaFin);

                foreach (PagoDeudaRow item in dataPaD)
                {
                    dgvPagoDeudas.Rows.Add(item.NomCliente, item.DeudaAnterior, item.Abono, item.DeudaActual);
                    totalPagado += (decimal)item.Abono;
                }

                txtTotalVentas.Text = totalVentas.ToString();
                txtDeudas.Text      = totalDeuda.ToString();
                txtAbonos.Text      = totalPagado.ToString();
                txtNumVentas.Text   = dataFac.Rows.Count.ToString();
                txtNumDeudas.Text   = contDeudas.ToString();
                txtNumAbonos.Text   = dataPaD.Rows.Count.ToString();
                txtTotal.Text       = (totalVentas - totalDeuda).ToString();
            }
            catch (Exception error)
            {
                log.Error($"Error: {error.Message}", error);
                MessageBox.Show($"Error: {error.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }