Exemple #1
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);
            }
        }
Exemple #2
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);
            }
        }