public List <VentasBLL> TraerTodaV()
        {
            VentasDAL        ventasDAL   = new VentasDAL();
            DataTable        tabla       = ventasDAL.GetAllVentas();
            List <VentasBLL> listaVentas = new List <VentasBLL>();

            int i = 0;

            while (i < tabla.Rows.Count)
            {
                int      id_ventas = int.Parse(tabla.Rows[i]["idVentas"].ToString());
                DateTime fecha     = DateTime.Parse(tabla.Rows[i]["fecha"].ToString());
                int      monto     = int.Parse(tabla.Rows[i]["monto"].ToString());



                VentasBLL objVentas = new VentasBLL();

                objVentas.id_ventas = id_ventas;
                objVentas.fecha     = fecha;
                objVentas.monto     = monto;

                listaVentas.Add(objVentas);
            }
            return(listaVentas);
        }
 public List <VentasVIEW> ListarVentasRangoFecha(DateTime desde, DateTime hasta)
 {
     try
     {
         VentasDAL ventasDAL = new VentasDAL();
         return(ventasDAL.ListarVentasRangoFecha(desde, hasta));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public List <VentasVIEW> ListarTodasVentas()
 {
     try
     {
         VentasDAL ventasDAL = new VentasDAL();
         return(ventasDAL.ListarTodasVentas());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public int ObtenerUtlimoIdVenta()
 {
     try
     {
         VentasDAL ventasDAL = new VentasDAL();
         return(ventasDAL.ObtenerUtlimoIdVenta());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public string EmitirVenta(VENTAS ventas, List <DETALLE_VENTAS> listaDetalle, string reservas)
 {
     try
     {
         VentasDAL ventasDAL = new VentasDAL();
         return(ventasDAL.EmitirVents(ventas, listaDetalle, reservas));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        private void btnPDF_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Espere mientras el documento es generado. Presione 'Aceptar para comenzar'");
            int       idVenta            = int.Parse(dataRow["ID"].ToString());
            VentasDAL ventasDAL          = new VentasDAL();
            DatosDocumentoPagoVIEW datos = ventasDAL.CargarDatos(idVenta);

            datos.DETALLE_BOLETA = ventasDAL.ListarDetalleBoleta(idVenta);
            ExportarArchivos PDF   = new ExportarArchivos();
            string           folio = datos.FOLIO.ToString();

            for (int i = 0; i < 9; i++)
            {
                if (folio.Length < 8)
                {
                    folio = "0" + folio;
                }
            }
            string rutaDcoc = PDF.DocumentoPagoPDF(datos, folio);

            MessageBox.Show("El documento ha sido generado correctamente. Puede buecar el archivo en 'Mis Documentos'");
        }
        private void CargarBoleta(DataRow dataRow)
        {
            CargarTablaDetalle();
            int                idBoleta           = int.Parse(dataRow["ID"].ToString());
            VentasDAL          ventas             = new VentasDAL();
            AnulacionVentasDAL anulacionVentasDAL = new AnulacionVentasDAL();

            datosDocumentoPagoVIEW = ventas.CargarDatos(idBoleta);
            VENTAS       datoVenta    = ventas.ObtenerVentaId(idBoleta);
            SucursalNEG  sucursalNEG  = new SucursalNEG();
            EmpleadosNEG empleadosNEG = new EmpleadosNEG();

            txtCliente.Text  = datosDocumentoPagoVIEW.NOMBRE_CLIENTE + " " + datosDocumentoPagoVIEW.APELLIDO_CLIENTE;
            txtSucursal.Text = sucursalNEG.CargarSucursal(datoVenta.SUCURSAL_ID).NOMBRE;
            txtEmpleado.Text = empleadosNEG.CargarEmpleado(datoVenta.EMPLEADO_ID).NOMBRE + " " + empleadosNEG.CargarEmpleado(datoVenta.EMPLEADO_ID).APELLIDO;
            dpkFechaCreacion.SelectedDate = datoVenta.FECHA_VENTA;
            string folio = idBoleta.ToString();

            for (int i = 0; i < 9; i++)
            {
                if (folio.Length < 8)
                {
                    folio = "0" + folio;
                }
            }

            txtFolio.Text         = folio;
            txtTipoDocumento.Text = datosDocumentoPagoVIEW.TIPO_DOCUMENTO;
            txtestadoVenta.Text   = anulacionVentasDAL.ValidaEstadoVenta(idBoleta);
            txtMoneda.Text        = datosDocumentoPagoVIEW.TIPO_MONEDA;
            double neto = Convert.ToDouble(datosDocumentoPagoVIEW.TOTAL) / 1.19;

            txtNeto.Text = string.Format("{0:n2}", (neto));
            double iva = neto * 0.19;

            txtIva.Text         = string.Format("{0:n2}", iva);
            txtTotal.Text       = string.Format("{0:n2}", (Convert.ToDouble(datosDocumentoPagoVIEW.TOTAL)));
            txtTotalMoneda.Text = string.Format("{0:n2}", (datosDocumentoPagoVIEW.TOTAL * datosDocumentoPagoVIEW.COSTO_MONEDA));
            //ORDEN DE TRABAJO N°"
            List <DETALLE_VENTAS> listaDetalles = ventas.ListarDetalleVenta(idBoleta);

            foreach (var x in listaDetalles)
            {
                if (x.SERVICIO_ID == 1 && x.PRODUCTO_ID == 1)
                {//OT
                    string    idOrden = x.NOMBRE_PRODUCTO.Split('°')[1];
                    DataTable tabla   = ((DataView)dgDetalleDocumento.ItemsSource).ToTable();
                    DataRow   fila    = tabla.NewRow();
                    fila["CANTIDAD"]    = 1;
                    fila["TIPO ITEM"]   = "OT";
                    fila["ID ITEM"]     = idOrden;
                    fila["NOMBRE ITEM"] = x.NOMBRE_PRODUCTO;
                    fila["P UNITARIO"]  = x.PRECIO_VENTA;
                    fila["TOTAL"]       = x.PRECIO_VENTA;
                    tabla.Rows.Add(fila);
                    dgDetalleDocumento.ItemsSource = tabla.DefaultView;
                }
                else if (x.PRODUCTO_ID == 1 && x.SERVICIO_ID > 1)
                {//serv
                    DataTable tabla = ((DataView)dgDetalleDocumento.ItemsSource).ToTable();
                    DataRow   fila  = tabla.NewRow();
                    fila["CANTIDAD"]    = 1;
                    fila["TIPO ITEM"]   = "SER";
                    fila["ID ITEM"]     = x.SERVICIO_ID;
                    fila["NOMBRE ITEM"] = x.NOMBRE_PRODUCTO;
                    fila["P UNITARIO"]  = x.PRECIO_VENTA;
                    fila["TOTAL"]       = x.MONTO_TOTAL;
                    tabla.Rows.Add(fila);
                    dgDetalleDocumento.ItemsSource = tabla.DefaultView;
                }
                else if (x.PRODUCTO_ID > 1 && x.SERVICIO_ID == 1)
                {//prod
                    DataTable tabla = ((DataView)dgDetalleDocumento.ItemsSource).ToTable();
                    DataRow   fila  = tabla.NewRow();
                    fila["CANTIDAD"]    = x.CANTIDAD;
                    fila["TIPO ITEM"]   = "PRO";
                    fila["ID ITEM"]     = x.PRODUCTO_ID;
                    fila["NOMBRE ITEM"] = x.NOMBRE_PRODUCTO;
                    fila["P UNITARIO"]  = x.PRECIO_VENTA;
                    fila["TOTAL"]       = x.MONTO_TOTAL;
                    tabla.Rows.Add(fila);
                    dgDetalleDocumento.ItemsSource = tabla.DefaultView;
                }
            }
        }
        public void reporteVentasEmpleadoMes(EmpleadoDAO c, int mes, int anio)
        {
            List <VentaDAO> ventas = new VentasDAL().reporteVentasAnio(c.id, mes, anio);


            PdfFont estilocolumnas = PdfFontFactory.CreateFont(
                StandardFonts.HELVETICA_BOLD);
            PdfFont estiloContenido = PdfFontFactory.CreateFont(
                StandardFonts.HELVETICA
                );


            PdfWriter   lector  = new PdfWriter("Reporte.pdf");
            PdfDocument pdf     = new PdfDocument(lector);
            PageSize    tamanio = new PageSize(792, 612);
            Document    re      = new Document(pdf, tamanio);

            re.SetMargins(60, 20, 55, 20);



            String[] columnas = { "ID", "Nombre", "Total", "Fecha" };
            float[]  tamanios = { 1, 2, 2, 2 };

            Table tabla = new Table(UnitValue.CreatePercentArray(tamanios));

            tabla.SetWidth(UnitValue.CreatePercentValue(100));

            foreach (String columna in columnas)
            {
                tabla.AddHeaderCell(new Cell().Add(new Paragraph(columna).SetFont(estilocolumnas)).SetBackgroundColor(iText.Kernel.Colors.WebColors.GetRGBColor("#ea2c62")));
            }



            double totalventa = 0;

            for (int i = 0; i < ventas.Count; i++)
            {
                tabla.AddCell(new Paragraph("" + c.id).SetFont(estiloContenido)).SetBackgroundColor(iText.Kernel.Colors.WebColors.GetRGBColor("#ff9a8c"));
                tabla.AddCell(new Paragraph(c.nombre).SetFont(estiloContenido)).SetBackgroundColor(iText.Kernel.Colors.WebColors.GetRGBColor("#fad5ad"));
                tabla.AddCell(new Paragraph("$" + ventas[i].total).SetFont(estiloContenido)).SetBackgroundColor(iText.Kernel.Colors.WebColors.GetRGBColor("#fad5ad"));
                tabla.AddCell(new Paragraph("" + ventas[i].fecha).SetFont(estiloContenido)).SetBackgroundColor(iText.Kernel.Colors.WebColors.GetRGBColor("#fad5ad"));

                totalventa += ventas[i].total;
            }
            re.Add(tabla);


            String[] columnastotal = { "N. ventas: " + ventas.Count + ".\n Total ventas: $" + totalventa };
            float[]  tamaniostotal = { 2 };
            tamaniostotal[0] = 2;

            Table total = new Table(UnitValue.CreatePercentArray(tamaniostotal));

            tabla.SetWidth(UnitValue.CreatePercentValue(100));

            foreach (String columna in columnastotal)
            {
                total.AddHeaderCell(new Cell().Add(new Paragraph(columna).SetFont(estilocolumnas))).SetBackgroundColor(iText.Kernel.Colors.WebColors.GetRGBColor("#c4fb6d"));
            }

            re.Add(total);
            re.Close();



            var titulo = new Paragraph("Reporte de ventas del mes " + mes + " del año " + anio + " del empleado " + c.nombre + ".").SetFont(estilocolumnas);

            titulo.SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
            titulo.SetFontSize(16);



            PdfDocument pdf2 = new PdfDocument(new PdfReader("Reporte.pdf"), new
                                               PdfWriter(@"C:\reportes\reporte_" + c.nombre + ".pdf"));
            Document reporte_ = new Document(pdf2);



            int numeropaginas = pdf2.GetNumberOfPages();

            reporte_.Add(titulo);

            reporte_.Close();
        }
        private void btnIngresar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (cbxSucursal.SelectedValue != null)
                {
                    if (int.Parse(cbxSucursal.SelectedValue.ToString()) > 0)
                    {
                        if (cbxCliente.SelectedValue != null)
                        {
                            if (int.Parse(cbxCliente.SelectedValue.ToString()) > 0)
                            {
                                if (cbxTipoDocumento.SelectedValue != null)
                                {
                                    if (int.Parse(cbxTipoDocumento.SelectedValue.ToString()) > 0)
                                    {
                                        if (cbxMoneda.SelectedValue != null)
                                        {
                                            if (int.Parse(cbxTipoDocumento.SelectedValue.ToString()) > 0)
                                            {
                                                if (cbxEmpleado.SelectedValue != null)
                                                {
                                                    if (int.Parse(cbxEmpleado.SelectedValue.ToString()) > 0)
                                                    {
                                                        DataTable tabla = ((DataView)dgDetalleDocumento.ItemsSource).ToTable();
                                                        if (tabla.Rows.Count > 0)
                                                        {
                                                            MessageBox.Show("Espere mientras el documento es generado. Presione 'Aceptar para comenzar'");
                                                            int      _idCliente                = int.Parse(cbxCliente.SelectedValue.ToString());
                                                            int      _sucursal                 = int.Parse(cbxSucursal.SelectedValue.ToString());
                                                            int      _tipoDocumento            = int.Parse(cbxTipoDocumento.SelectedValue.ToString());
                                                            DateTime _fechaDocumento           = DateTime.Parse(dpkFechaCreacion.SelectedDate.ToString());
                                                            double   _neto                     = double.Parse(txtNeto.Text);
                                                            int      _idEmpleado               = int.Parse(cbxEmpleado.SelectedValue.ToString());
                                                            double   _iva                      = double.Parse(txtIva.Text);
                                                            double   _total                    = double.Parse(txtTotal.Text);
                                                            double   _totalMoneda              = double.Parse(txtTotalMoneda.Text);
                                                            int      _idMoneda                 = int.Parse(cbxTipoDocumento.SelectedValue.ToString());
                                                            List <DETALLE_VENTAS> listaDetalle = new List <DETALLE_VENTAS>();
                                                            int    cantidadTotal               = 0;
                                                            string reservas                    = "";
                                                            foreach (DataRow fila in tabla.Rows)
                                                            {
                                                                DETALLE_VENTAS detalle = new DETALLE_VENTAS();
                                                                detalle.FECHA_CREACION      = DateTime.Now;
                                                                detalle.FECHA_ULTIMO_UPDATE = DateTime.Now;
                                                                detalle.CANTIDAD            = int.Parse(fila.ItemArray[0].ToString());
                                                                detalle.MONTO_TOTAL         = int.Parse(fila.ItemArray[5].ToString());
                                                                detalle.NOMBRE_PRODUCTO     = fila.ItemArray[3].ToString();
                                                                detalle.PRECIO_VENTA        = Convert.ToDecimal(fila.ItemArray[4].ToString());
                                                                detalle.MULTI_MONEDA_ID     = _idMoneda;

                                                                if (fila.ItemArray[1].ToString() == "PRO")
                                                                {
                                                                    detalle.PRODUCTO_ID = int.Parse(fila.ItemArray[2].ToString());
                                                                    detalle.SERVICIO_ID = 1;
                                                                }
                                                                if (fila.ItemArray[1].ToString() == "SER")
                                                                {
                                                                    detalle.PRODUCTO_ID = 1;
                                                                    detalle.SERVICIO_ID = int.Parse(fila.ItemArray[2].ToString());
                                                                }
                                                                if (fila.ItemArray[1].ToString() == "OT")
                                                                {
                                                                    detalle.PRODUCTO_ID = 1;
                                                                    detalle.SERVICIO_ID = 1;
                                                                    reservas            = reservas + fila.ItemArray[2].ToString() + ";";
                                                                }
                                                                listaDetalle.Add(detalle);
                                                                cantidadTotal = cantidadTotal + int.Parse(detalle.CANTIDAD.ToString());
                                                            }
                                                            VENTAS ventas = new VENTAS();
                                                            ventas.FECHA_CREACION      = DateTime.Now;
                                                            ventas.FECHA_ULTIMO_UPDATE = DateTime.Now;
                                                            ventas.CANTIDAD_TOTAL      = cantidadTotal;
                                                            ventas.FECHA_VENTA         = DateTime.Now;
                                                            ventas.MONTO_TOTAL         = Convert.ToDecimal(_total);
                                                            ventas.CLIENTE_ID          = _idCliente;
                                                            ventas.EMPLEADO_ID         = _idEmpleado;
                                                            ventas.MULTI_MONEDA_ID     = _idMoneda;
                                                            ventas.SUCURSAL_ID         = _sucursal;
                                                            ventas.TIPO_VENTA_ID       = _tipoDocumento;
                                                            VentasNEG ventasNEG = new VentasNEG();
                                                            string    respuesta = ventasNEG.EmitirVenta(ventas, listaDetalle, reservas);
                                                            if (respuesta == "creado")
                                                            {
                                                                int       idVenta            = ventasNEG.ObtenerUtlimoIdVenta();
                                                                VentasDAL ventasDAL          = new VentasDAL();
                                                                DatosDocumentoPagoVIEW datos = ventasDAL.CargarDatos(idVenta);
                                                                datos.DETALLE_BOLETA = ventasDAL.ListarDetalleBoleta(idVenta);
                                                                ExportarArchivos PDF   = new ExportarArchivos();
                                                                string           folio = datos.FOLIO.ToString();
                                                                for (int i = 0; i < 9; i++)
                                                                {
                                                                    if (folio.Length < 8)
                                                                    {
                                                                        folio = "0" + folio;
                                                                    }
                                                                }

                                                                string       rutaDcoc     = PDF.DocumentoPagoPDF(datos, folio);
                                                                ServerCorreo abrir_server = new ServerCorreo();
                                                                Correo       correoM      = new Correo();
                                                                SmtpClient   server       = abrir_server.InstanciaServer();
                                                                //Instancia la libreria que permite armar correo electronico y llama el metodo que lo crea
                                                                MailMessage email = correoM.CorreoEnvioFactura(rutaDcoc, datos.CORREO_CLIENTE, datos.NOMBRE_CLIENTE + " " + datos.APELLIDO_CLIENTE, folio);
                                                                //envia el correo
                                                                server.Send(email);
                                                                Limpiar();

                                                                MessageBox.Show("El documento ha sido generado correctamente. Se ha enviado una copia por correo al cliente y puede tambien buscar una copia del archivo en 'Mis Documentos'");
                                                            }
                                                        }
                                                        else
                                                        {
                                                            MessageBox.Show("Deben ingresar productos o servicios al documento");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        MessageBox.Show("Debe seleccionar un empleado");
                                                    }
                                                }
                                                else
                                                {
                                                    MessageBox.Show("Debe seleccionar un empleado");
                                                }
                                            }
                                            else
                                            {
                                                MessageBox.Show("Debe seleccionar un tipo de documento");
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Debe seleccionar una moneda");
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Debe seleccionar un tipo de documento");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Debe seleccionar un tipo de documento");
                                }
                            }
                            else
                            {
                                MessageBox.Show("Debe seleccionar un cliente");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Debe seleccionar un cliente");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Debe seleccionar una sucursal");
                    }
                }
                else
                {
                    MessageBox.Show("Debe seleccionar una sucursal");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:\n" + ex.TargetSite + "\n" + ex.Message.ToString());
            }
        }