Exemplo n.º 1
0
        private void dgvVentas_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            if (e.ColumnIndex == 9)
            {
                string          id  = dgvVentas.Rows[e.RowIndex].Cells["ID"].Value.ToString();
                frmDetalleVenta frm = new frmDetalleVenta(id);
                frm.ShowDialog();
            }

            if (e.ColumnIndex == 11)
            {
                string nro_doc = dgvVentas.Rows[e.RowIndex].Cells["DOC"].Value.ToString();
                string tipo    = dgvVentas.Rows[e.RowIndex].Cells["TIPO_VENTA"].Value.ToString();

                InvoicePDF pdf = new InvoicePDF();

                ent_venta                 = new Ent_Venta();
                ent_venta.nro_doc_str     = dgvVentas.Rows[e.RowIndex].Cells["NRO_DOC"].Value.ToString();
                ent_venta.tipo_venta      = dgvVentas.Rows[e.RowIndex].Cells["TIPO_VENTA"].Value.ToString();
                ent_venta.emision         = dgvVentas.Rows[e.RowIndex].Cells["FECHA"].Value.ToString();
                ent_venta.cliente         = dgvVentas.Rows[e.RowIndex].Cells["NOMBRES"].Value.ToString();
                ent_venta.cliente_doc     = dgvVentas.Rows[e.RowIndex].Cells["DNI"].Value.ToString();
                ent_venta.direccion       = dgvVentas.Rows[e.RowIndex].Cells["DIRECCION"].Value.ToString();
                ent_venta.monto_total     = Convert.ToDouble(dgvVentas.Rows[e.RowIndex].Cells["TOTAL"].Value.ToString());
                ent_venta.monto_subtotal  = Convert.ToDouble(ent_venta.monto_total / (ent_configuracion.IGV + 1));
                ent_venta.monto_igv       = (ent_venta.monto_total - Convert.ToDouble(ent_venta.monto_subtotal));
                ent_venta.monto_descuento = Convert.ToDouble(dgvVentas.Rows[e.RowIndex].Cells["DESCUENTO"].Value.ToString());;
                ent_venta.nro_doc         = Convert.ToInt32(dgvVentas.Rows[e.RowIndex].Cells["DOC"].Value.ToString());
                ent_venta.moneda          = dgvVentas.Rows[e.RowIndex].Cells["MONEDA"].Value.ToString();

                ent_venta.lstProductos = BL_Ventas.getDetalleVenta(nro_doc);

                if (tipo == "BO")
                {
                    pdf.createBoleta(ent_configuracion, ent_venta);
                }
                else
                {
                    pdf.createFactura(ent_configuracion, ent_venta);
                }

                /*String filename = "invoices\\" + (tipo == "BO" ? "boleta" : "factura") + "_" + nro_doc + ".pdf";
                 * if (File.Exists(filename))
                 * {
                 *  Process.Start(filename);
                 * } else
                 * {
                 *  MessageBox.Show((tipo == "BO" ? "Boleta" : "Factura") + " no encontrada.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 * }*/
            }
        }
Exemplo n.º 2
0
        private void btnImprimir_Click(object sender, EventArgs e)
        {
            InvoicePDF invoicePDF = new InvoicePDF();

            invoicePDF.createCotizacion(ent_configuracion, cotizacion);

            /*String filename = "invoices\\cotizacion_" + id_cab + ".pdf";
             * if (File.Exists(filename))
             * {
             *  Process.Start(filename);
             * }
             * else
             * {
             *  MessageBox.Show("Cotización no encontrada.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             * }*/
        }
Exemplo n.º 3
0
        private void btnVer_Click(object sender, EventArgs e)
        {
            InvoicePDF invoicePDF = new InvoicePDF();

            invoicePDF.createServicioTecnico(ent_configuracion, prog);

            /*String filename = "invoices\\serviciotecnico_" + nro_doc + ".pdf";
             * if (File.Exists(filename))
             * {
             *  Process.Start(filename);
             * }
             * else
             * {
             *  MessageBox.Show("Documento no encontrado.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             * }*/
        }
Exemplo n.º 4
0
        public dynamic Post(Invoice invoice)
        {
            var invoicePDF = new InvoicePDF();

            invoicePDF.CreateInvoice(invoice);

            var filePath = $"./Reports/Invoice/{invoice.Id + invoice.Clients.First().Name}.pdf";

            invoicePDF.ExportToPdf(filePath);

            using (var fileStream = new FileStream(filePath, FileMode.Open))
            {
                using (var stream = new MemoryStream())
                {
                    fileStream.CopyTo(stream);

                    return(File(stream.ToArray(), "application/octet-stream"));
                }
            }
        }
Exemplo n.º 5
0
        private void btnPagar_Click(object sender, EventArgs e)
        {
            Ent_Prog_Mantenimiento prog = new Ent_Prog_Mantenimiento();

            prog.documento        = correlativo == "" ? 0 : int.Parse(correlativo);
            prog.documento_des    = lblSerie.Text;
            prog.tienda           = cod_tienda;
            prog.usuario          = usuario;
            prog.tipo_persona     = rdbEmpresa.Checked == true ? "N" : "E";
            prog.numero_documento = txtDesRuc.Text;
            prog.cliente_des      = txtDesCliente.Text;
            prog.cliente          = cliente;
            prog.estado           = cboEstado.SelectedValue.ToString();
            prog.fecha_salida     = dtpFechaSalida.Value.ToShortDateString();

            List <Ent_Tipo_Mantenimiento> lista_mant = new List <Ent_Tipo_Mantenimiento>();

            foreach (DataGridViewRow row in dgvMantenimiento.Rows)
            {
                Ent_Tipo_Mantenimiento prd = new Ent_Tipo_Mantenimiento();
                prd.id          = int.Parse(row.Cells["ID"].Value.ToString());
                prd.descripcion = row.Cells["DESCRIPCION"].Value.ToString();

                lista_mant.Add(prd);
            }
            prog.mantenimiento = lista_mant;
            string request = BL_Mantenimiento.setProg_Mantenimiento(prog);

            if (request == "1")
            {
                MessageBox.Show("Se agregó correctamente");
                InvoicePDF pdf = new InvoicePDF();
                pdf.createServicioTecnico(ent_configuracion, prog);
            }
            else
            {
                MessageBox.Show(request);
            }
        }
Exemplo n.º 6
0
        private void procesarCompra()
        {
            forma_pago = cboFormaPago.SelectedValue.ToString();

            Ent_Venta venta = new Ent_Venta();

            venta.nro_doc         = int.Parse(correlativo);
            venta.nro_doc_str     = lblSerie.Text;
            venta.cod_tienda      = cod_tienda;
            venta.tipo_venta      = tipo_venta;
            venta.forma_pago      = forma_pago;
            venta.cantidad        = sumarCantidad();
            venta.monto_total     = total;
            venta.monto_subtotal  = double.Parse(txtSubTotal.Text);
            venta.monto_igv       = double.Parse(txtIGV.Text);
            venta.monto_recibido  = double.Parse(txtRecibido.Text);
            venta.monto_vuelto    = double.Parse(txtVuelto.Text);
            venta.monto_descuento = double.Parse(txtDescuento.Text);
            venta.cliente_doc     = txtDNI.Text;
            venta.cliente         = txtNombres.Text + " " + txtApellidos.Text;
            venta.direccion       = txtDireccion.Text;
            venta.usuario         = ent_usuario.username;

            venta.fecha_inicio = dtpFechaInicio.Value.ToShortDateString();
            venta.fecha_fin    = dtpFechaEntrega.Value.ToShortDateString();

            venta.moneda = cboMoneda.SelectedValue.ToString();

            bool existe_cliente = BL_Clientes.existeCliente(venta.cliente_doc);

            //save customer if doesnt exists
            if (!existe_cliente)
            {
                log.Info("Cliente " + txtDNI.Text + " no existe en la base de datos.", System.Reflection.MethodBase.GetCurrentMethod().Name);

                var confirm = MessageBox.Show("¿Desea guardar el cliente en el sistema?", "Atención", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (confirm == DialogResult.Yes)
                {
                    Ent_Clientes nuevo_cliente = new Ent_Clientes();
                    nuevo_cliente.dni       = txtDNI.Text;
                    nuevo_cliente.nombres   = txtNombres.Text;
                    nuevo_cliente.apellidos = txtApellidos.Text;
                    nuevo_cliente.direccion = txtDireccion.Text;
                    nuevo_cliente.telefono  = txtTelefono.Text;
                    nuevo_cliente.email     = txtEmail.Text;
                    nuevo_cliente.tipo      = (tipo_venta == "FA") ? "E" : "N";
                    nuevo_cliente.posible   = "1";

                    try
                    {
                        string _result = BL_Clientes.insertarCliente(nuevo_cliente);

                        if (_result == "1")
                        {
                            log.Info("Cliente " + nuevo_cliente.dni + " grabado con éxito.", System.Reflection.MethodBase.GetCurrentMethod().Name);
                        }
                        else
                        {
                            log.Error("Error al grabar cliente: " + _result, System.Reflection.MethodBase.GetCurrentMethod().Name);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ocurrió un error al grabar al cliente, sin embargo, el proceso de compra continuará.\n\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        log.Error("Error al grabar cliente: " + ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name);
                    }
                }
                else
                {
                    log.Info("Cliente " + txtDNI.Text + " no se guardará en la base de datos.", System.Reflection.MethodBase.GetCurrentMethod().Name);
                }
            }

            foreach (DataGridViewRow row in dgvProductos.Rows)
            {
                Ent_Productos prd = new Ent_Productos();
                prd.id       = int.Parse(row.Cells["ID"].Value.ToString());
                prd.nombre   = row.Cells["DESCRIPCION"].Value.ToString();
                prd.cantidad = int.Parse(row.Cells["CANTIDAD"].Value.ToString());
                prd.precio   = float.Parse(row.Cells["PU"].Value.ToString());

                venta.lstProductos.Add(prd);
            }

            try
            {
                string result = BL_Ventas.procesarVenta(venta);

                if (result == "1")
                {
                    MessageBox.Show("Venta Realizada con Éxito!.", "Venta", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    InvoicePDF pdf = new InvoicePDF();
                    if (venta.tipo_venta == "BO")
                    {
                        pdf.createBoleta(ent_configuracion, venta);
                    }
                    else
                    {
                        pdf.createFactura(ent_configuracion, venta);
                    }

                    log.Info("Venta " + lblSerie.Text + " realizada con éxito.", System.Reflection.MethodBase.GetCurrentMethod().Name);
                    string resumen =
                        "\n-----------------------------------\n" +
                        "Resumen Venta:\n" +
                        "Serie: " + lblSerie.Text + "\n" +
                        "Tipo Venta: " + tipo_venta + "\n" +
                        "Forma de Pago: " + cboFormaPago.Text + "\n" +
                        "Cliente: " + txtDNI.Text + "\n" +
                        "Productos:\n";
                    foreach (DataGridViewRow item in dgvProductos.Rows)
                    {
                        resumen += "  - " + item.Cells["CODIGO"].Value.ToString() + " | " +
                                   item.Cells["DESCRIPCION"].Value.ToString() + " | " +
                                   item.Cells["CANTIDAD"].Value.ToString() + " | " +
                                   item.Cells["PU"].Value.ToString() + " | " +
                                   item.Cells["IMPORTE"].Value.ToString() + "\n";
                    }
                    resumen +=
                        "Subtotal: " + txtSubTotal.Text + "\n" +
                        "IGV: " + txtIGV.Text + "\n" +
                        "TOTAL: " + txtTotal.Text + "\n" +
                        "Recibido: " + txtRecibido.Text + "\n" +
                        "Vuelto: " + txtVuelto.Text + "\n" +
                        "-----------------------------------\n\n";
                    log.Info(resumen, System.Reflection.MethodBase.GetCurrentMethod().Name);
                    reiniciarVenta();
                }
                else
                {
                    MessageBox.Show(result, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error en el proceso de compra.\n\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                log.Error("Error en el proceso de compra: " + ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }
Exemplo n.º 7
0
        private void procesarCotizacion()
        {
            Ent_Venta venta = new Ent_Venta();

            venta.cod_tienda      = cod_tienda;
            venta.tipo_venta      = tipo_venta;
            venta.cantidad        = sumarCantidad();
            venta.cliente_doc     = txtDesRuc.Text;
            venta.emision         = DateTime.Now.ToString("dd/MM/yyyy");
            venta.cliente         = txtDesCliente.Text;
            venta.email           = txtEmail.Text;
            venta.usuario         = usuario;
            venta.tipo_cotizacion = cboTipo.SelectedValue.ToString();
            venta.dias_alquiler   = int.Parse(txtDias.Text);
            venta.monto_subtotal  = double.Parse(txtSubTotal.Text);
            venta.monto_igv       = double.Parse(txtIGV.Text);
            venta.monto_total     = total;
            venta.denominacion    = txtDenominación.Text;
            venta.observacion     = txtObservacion.Text;
            venta.moneda          = cboMoneda.SelectedValue.ToString();

            bool existe_cliente = BL_Clientes.existeCliente(venta.cliente_doc);

            //save customer if doesnt exists
            if (!existe_cliente)
            {
                var confirm = MessageBox.Show("¿Desea guardar el cliente en el sistema?", "Atención", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (confirm == DialogResult.Yes)
                {
                    Ent_Clientes nuevo_cliente = new Ent_Clientes();
                    nuevo_cliente.dni       = txtDesRuc.Text;
                    nuevo_cliente.nombres   = txtDesCliente.Text;
                    nuevo_cliente.apellidos = "";
                    nuevo_cliente.direccion = "";
                    nuevo_cliente.telefono  = "";
                    nuevo_cliente.email     = txtEmail.Text;
                    nuevo_cliente.tipo      = (nuevo_cliente.dni.Length > 8) ? "E" : "N";
                    nuevo_cliente.posible   = "1";

                    try
                    {
                        string _result = BL_Clientes.insertarCliente(nuevo_cliente);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ocurrió un error al grabar al cliente, sin embargo, el proceso de compra continuará.\n\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                }
            }

            foreach (DataGridViewRow row in dgvProductos.Rows)
            {
                Ent_Productos prd = new Ent_Productos();
                prd.cod_producto = row.Cells["CODIGO"].Value.ToString();
                prd.id           = int.Parse(row.Cells["ID"].Value.ToString());
                prd.nombre       = row.Cells["DESCRIPCION"].Value.ToString();
                prd.cantidad     = int.Parse(row.Cells["CANTIDAD"].Value.ToString());
                prd.precio       = float.Parse(row.Cells["PU"].Value.ToString());
                prd.monto_total  = float.Parse(row.Cells["IMPORTE"].Value.ToString());

                venta.lstProductos.Add(prd);
            }

            try
            {
                string id_cab = "";
                string result = BL_Ventas.procesarCotizacion(venta, out id_cab);

                venta.id_cab = Convert.ToInt32(id_cab);

                Email email = new Email();
                email.Send_Email(venta, _ent_tienda, ent_configuracion, txtObservacion.Text, adjunto);

                if (result == "1")
                {
                    MessageBox.Show("Cotización Realizada con Éxito!.", "Cotización", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    InvoicePDF pdf = new InvoicePDF();
                    pdf.createCotizacion(ent_configuracion, venta);
                    reiniciarVenta();
                }
                else
                {
                    MessageBox.Show(result, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error en el proceso de cotización.\n\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }