Beispiel #1
0
        private void dgvEncontrados_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == btnUpdate.Index)
            {
                if (e.RowIndex >= 0)
                {
                    frmInsertarProductos frm = new frmInsertarProductos();
                    frm.MdiParent   = this.MdiParent;
                    frm.WindowState = FormWindowState.Maximized;
                    frm.Show();
                    frm.TipoInsercion = 1;
                    int      idP = Convert.ToInt32(dgvEncontrados.Rows[e.RowIndex].Cells[0].Value);
                    Producto aux = ProductoBLL.GetProductById(idP);
                    frm.BoxProveedor.SelectedValue = aux.fkProveedor;
                    frm.BoxMarca.SelectedValue     = aux.fkMarca;
                    frm.BoxModelo.SelectedValue    = aux.fkModelo;
                    frm.BoxTalla.SelectedValue     = aux.fkTalla;
                    frm.CodProducto         = aux.pkProducto + "";
                    frm.TxtCodigo.Text      = aux.txtCodigo;
                    frm.TxtNombre.Text      = aux.txtNombre;
                    frm.TxtDescripcion.Text = aux.txtDescripcion;
                    frm.TxtCantidad.Text    = aux.intCantidad + "";
                    frm.TxtValorCompra.Text = aux.decValorCompra + "";
                    frm.TxtValorVenta.Text  = aux.decValorVenta + "";
                    if (aux.intGenero == 0)
                    {
                        frm.BoxGenero.SelectedIndex = 1;
                    }
                    else
                    {
                        frm.BoxGenero.SelectedIndex = 2;
                    }

                    this.Dispose();
                }
            }
            if (e.ColumnIndex == btnEliminar.Index)
            {
                if (e.RowIndex >= 0)
                {
                    if (MessageBox.Show("Esta seguro de eliminar este producto?", "Eliminar Producto", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        if (MessageBox.Show("Esta totalmente seguro?", "Eliminar Producto", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            int codigo = Convert.ToInt32(dgvEncontrados.Rows[e.RowIndex].Cells[0].Value);
                            ProductoBLL.DeleteProducto(codigo);
                            MessageBox.Show("Registro eliminado");
                            dgvEncontrados.Rows.RemoveAt(e.RowIndex);
                            dgvEncontrados.Refresh();
                        }
                    }
                }
            }
        }
Beispiel #2
0
 private void btnBuscar_Click(object sender, EventArgs e)
 {
     if (optID.Checked && txtBuscado.Text != "")
     {
         int idProd;
         if (int.TryParse(txtBuscado.Text, out idProd))
         {
             Producto aux = ProductoBLL.GetProductById(idProd);
             if (aux != null)
             {
                 limpiarTabla();
                 dgvEncontrados.Refresh();
                 dgvEncontrados.Rows.Add(aux.pkProducto, aux.txtNombre, aux.txtCodigo, aux.txtNombreMarca, aux.txtNombreModelo, aux.txtNombreTalla);
                 dgvEncontrados.Refresh();
             }
             else
             {
                 MessageBox.Show("No se encontró ningun producto con ese ID");
             }
         }
         else
         {
             MessageBox.Show("El ID debe ser un número entero positivo");
         }
     }
     if (optName.Checked && txtBuscado.Text != "")
     {
         List <Producto> auxLista = ProductoBLL.GetProductsByName(txtBuscado.Text);
         if (auxLista.Count > 0)
         {
             limpiarTabla();
             dgvEncontrados.Refresh();
             foreach (Producto aux in auxLista)
             {
                 dgvEncontrados.Rows.Add(aux.pkProducto, aux.txtNombre, aux.txtCodigo, aux.txtNombreMarca, aux.txtNombreModelo, aux.txtNombreTalla);
             }
             dgvEncontrados.Refresh();
         }
         else
         {
             MessageBox.Show("No se encontró ningun producto con ese nombre");
         }
     }
     if (optCode.Checked && txtBuscado.Text != "")
     {
         Producto aux = ProductoBLL.GetProductByCode(txtBuscado.Text);
         if (aux != null)
         {
             limpiarTabla();
             dgvEncontrados.Refresh();
             dgvEncontrados.Rows.Add(aux.pkProducto, aux.txtNombre, aux.txtCodigo, aux.txtNombreMarca, aux.txtNombreModelo, aux.txtNombreTalla);
             dgvEncontrados.Refresh();
         }
         else
         {
             MessageBox.Show("No se encontró ningun producto con ese Código");
         }
     }
     if (optMark.Checked)
     {
         int             idAux    = Convert.ToInt32(boxOpciones.SelectedValue);
         List <Producto> auxLista = ProductoBLL.GetProductsByMark(idAux);
         if (auxLista.Count > 0)
         {
             limpiarTabla();
             dgvEncontrados.Refresh();
             foreach (Producto aux in auxLista)
             {
                 dgvEncontrados.Rows.Add(aux.pkProducto, aux.txtNombre, aux.txtCodigo, aux.txtNombreMarca, aux.txtNombreModelo, aux.txtNombreTalla);
             }
             dgvEncontrados.Refresh();
         }
         else
         {
             MessageBox.Show("No se encontró ningun producto con esa Marca");
             limpiarTabla();
             dgvEncontrados.Refresh();
         }
     }
     if (optModel.Checked)
     {
         int             idAux    = Convert.ToInt32(boxOpciones.SelectedValue);
         List <Producto> auxLista = ProductoBLL.GetProductsByModel(idAux);
         if (auxLista.Count > 0)
         {
             limpiarTabla();
             dgvEncontrados.Refresh();
             foreach (Producto aux in auxLista)
             {
                 dgvEncontrados.Rows.Add(aux.pkProducto, aux.txtNombre, aux.txtCodigo, aux.txtNombreMarca, aux.txtNombreModelo, aux.txtNombreTalla);
             }
             dgvEncontrados.Refresh();
         }
         else
         {
             MessageBox.Show("No se encontró ningun producto con esa Modelo");
             limpiarTabla();
             dgvEncontrados.Refresh();
         }
     }
     if (optSize.Checked)
     {
         int             idAux    = Convert.ToInt32(boxOpciones.SelectedValue);
         List <Producto> auxLista = ProductoBLL.GetProductsBySize(idAux);
         if (auxLista.Count > 0)
         {
             limpiarTabla();
             dgvEncontrados.Refresh();
             foreach (Producto aux in auxLista)
             {
                 dgvEncontrados.Rows.Add(aux.pkProducto, aux.txtNombre, aux.txtCodigo, aux.txtNombreMarca, aux.txtNombreModelo, aux.txtNombreTalla);
             }
             dgvEncontrados.Refresh();
         }
         else
         {
             MessageBox.Show("No se encontró ningun producto con esa Talla");
             limpiarTabla();
             dgvEncontrados.Refresh();
         }
     }
 }
Beispiel #3
0
 private void btnGuardar_Click(object sender, EventArgs e)
 {
     if (validarStock() == true)
     {
         if (txtNitCliente.Text != "" && txtNombreCliente.Text != "" && tblDetalleVenta.RowCount > 0)
         {
             string nroFact = getNroFactura().ToString();
             int    idCliente;
             if (objCliente == null)
             {
                 int idPersona = PersonaBLL.InsertDatosPersona(txtNitCliente.Text, txtNombreCliente.Text, "", "", "", "", 1);
                 idCliente = ClienteBLL.InsertDatosCliente(idPersona, 1);
             }
             else
             {
                 idCliente = objCliente.pkCliente;
             }
             int idFactura = 0;
             if (llave != null && llave.txtLlave != "")
             {
                 idFactura = FacturaBLL.InsertarFactura(0, idCliente, 2, Convert.ToInt32(boxDescuentos.SelectedValue), 1, nroFact, llave.txtNroAutorizacion, llave.txtLlave, Convert.ToDecimal(sumarTotalVenta()), 1);
             }
             else
             {
                 MessageBox.Show("USTED NO HA INGRESADO LA LLAVE NI EL CODIGO DE AUTORIZACIÓN DE LA FACTURA");
                 return;
             }
             foreach (DataGridViewRow fila in tblDetalleVenta.Rows)
             {
                 if (Convert.ToInt32(fila.Cells["txtCantidad"].Value.ToString()) > 0)
                 {
                     if (fila.Cells["idProducto"] != null)
                     {
                         GananciasDTO ganancias = new GananciasDTO();
                         ganancias.fkProducto  = Convert.ToInt32(fila.Cells["idProducto"].Value.ToString());
                         ganancias.intCantidad = Convert.ToInt32(fila.Cells["txtCantidad"].Value.ToString());
                         Producto pro = ProductoBLL.GetProductById(ganancias.fkProducto);
                         ganancias.decValorVenta  = pro.decValorVenta;
                         ganancias.decValorCompra = pro.decValorCompra;
                         ganancias.decTotal       = Convert.ToDecimal(fila.Cells["txtSubTotal"].Value.ToString());
                         DetalleVentaBLL.InsertarDetalleVenta(0, Convert.ToInt32(fila.Cells["idProducto"].Value.ToString()), idFactura, Convert.ToInt32(fila.Cells["txtCantidad"].Value.ToString()), Convert.ToDecimal(fila.Cells["txtSubTotal"].Value.ToString()));
                         GananciasBLL.InsertObjetoGanancias(ganancias);
                         Producto auxProducto = getProductoOfList(fila.Cells["idProducto"].Value.ToString());
                         auxProducto.intCantidad -= Convert.ToInt32(fila.Cells["txtCantidad"].Value.ToString());
                         ProductoBLL.UpdateProducto(auxProducto);
                         sumaReal       += (double)auxProducto.decValorVenta * Convert.ToInt32(fila.Cells["txtCantidad"].Value.ToString());
                         sumaDescuentos += Convert.ToDouble(fila.Cells["txtSubTotal"].Value.ToString());
                     }
                 }
                 else
                 {
                     MessageBox.Show("Usted a ingresado una cantidad de 0");
                     return;
                 }
             }
             if (lastLibroVenta != null)
             {
                 if (lastLibroVenta.txtMes == DateTime.Now.Month.ToString() && lastLibroVenta.txtAño == DateTime.Now.Year.ToString())
                 {
                     List <DetalleLibroVentas> lista = DetalleLibroVentasBLL.GetDetalleLibroVentasByIdLibro(lastLibroVenta.pkLibro);
                     int lastNro = 0;
                     if (lista.Count != 0)
                     {
                         lastNro = lista[(lista.Count - 1)].intNro;
                     }
                     if (sumaReal == sumaDescuentos)
                     {
                         sumaDescuentos = 0;
                     }
                     double dif = sumaReal - sumaDescuentos;
                     double db  = 0;
                     if (dif == sumaReal)
                     {
                         db = sumaReal * 13 / 100;
                     }
                     else
                     {
                         db = (sumaReal - dif) * 13 / 100;
                     }
                     DetalleLibroVentasBLL.InsertDatosDetalleLibroVentas(lastNro + 1, DateTime.Now, nroFact, llave.txtNroAutorizacion, txtNitCliente.Text, txtNombreCliente.Text, Convert.ToDecimal(sumaReal), 0, 0, 0, Convert.ToDecimal(sumaReal), (dif == sumaReal) ? 0 : Convert.ToDecimal(dif), (dif == sumaReal) ? Convert.ToDecimal(sumaReal) : Convert.ToDecimal(sumaReal - dif), Convert.ToDecimal(db), getCodigoControl(), lastLibroVenta.pkLibro, 1);
                 }
                 else
                 {
                     int pkLibro = LibroVentasBLL.InsertDatosLibroVentas(DateTime.Now.Month.ToString(), DateTime.Now.Year.ToString());
                     int lastNro = 0;
                     if (sumaReal == sumaDescuentos)
                     {
                         sumaDescuentos = 0;
                     }
                     double dif = sumaReal - sumaDescuentos;
                     double db  = 0;
                     if (dif == sumaReal)
                     {
                         db = sumaReal * 13 / 100;
                     }
                     else
                     {
                         db = (sumaReal - dif) * 13 / 100;
                     }
                     DetalleLibroVentasBLL.InsertDatosDetalleLibroVentas(lastNro + 1, DateTime.Now, nroFact, llave.txtNroAutorizacion, txtNitCliente.Text, txtNombreCliente.Text, Convert.ToDecimal(sumaReal), 0, 0, 0, Convert.ToDecimal(sumaReal), (dif == sumaReal) ? 0 : Convert.ToDecimal(dif), (dif == sumaReal) ? Convert.ToDecimal(sumaReal) : Convert.ToDecimal(sumaReal - dif), Convert.ToDecimal(db), getCodigoControl(), pkLibro, 1);
                 }
             }
             else
             {
                 int pkLibro = LibroVentasBLL.InsertDatosLibroVentas(DateTime.Now.Month.ToString(), DateTime.Now.Year.ToString());
                 int lastNro = 0;
                 if (sumaReal == sumaDescuentos)
                 {
                     sumaDescuentos = 0;
                 }
                 double dif = sumaReal - sumaDescuentos;
                 double db  = 0;
                 if (dif == sumaReal)
                 {
                     db = sumaReal * 13 / 100;
                 }
                 else
                 {
                     db = (sumaReal - dif) * 13 / 100;
                 }
                 DetalleLibroVentasBLL.InsertDatosDetalleLibroVentas(lastNro + 1, DateTime.Now, nroFact, llave.txtNroAutorizacion, txtNitCliente.Text, txtNombreCliente.Text, Convert.ToDecimal(sumaReal), 0, 0, 0, Convert.ToDecimal(sumaReal), (dif == sumaReal) ? 0 : Convert.ToDecimal(dif), (dif == sumaReal) ? Convert.ToDecimal(sumaReal) : Convert.ToDecimal(sumaReal - dif), Convert.ToDecimal(db), getCodigoControl(), pkLibro, 1);
             }
             if (original == " COPIA")
             {
                 original = "ORIGINAL";
             }
             imprimirFactura();
             original = " COPIA";
             imprimirFactura();
             tblDetalleVenta.RowCount = 0;
             txtNitCliente.Text       = "";
             txtNombreCliente.Text    = "";
             sumaReal       = 0;
             sumaDescuentos = 0;
             lastFactura    = FacturaBLL.GetLastFactura();
             llave          = LlaveFacturaBLL.GetLastLlaveFactura();
             lastFactura    = FacturaBLL.GetLastFactura();
             lastLibroVenta = LibroVentasBLL.GetLastLibroVentas();
             listaProductos = new List <Producto>();
         }
         else
         {
             MessageBox.Show("Debe ingresar el nit, el nombre del cliente y al menos un producto");
         }
     }
 }
Beispiel #4
0
        public string generarCuerpoFactura(string nro, string autorizacion, string fecha, string hora, string nit, string nombre, List <DetalleVenta> productos, string total, string codigo)
        {
            string factura = "";

            factura += "                               MINILULIS" + "\n";
            factura += "         BARRIO URBARI AV. BARRIENTOS NRO.24" + "\n";
            factura += "          COND. TORRE MANGABEIRA P.B. OF. 2" + "\n";
            factura += "                          TELÉFONO: 3599175" + "\n";
            factura += "                      SANTA CRUZ - BOLIVIA" + "\n";
            factura += "                                FACTURA" + "\n";
            factura += "                                " + original + "\n";
            factura += "------------------------------------------------------------------" + "\n";
            factura += "                            NIT: 4648284010" + "\n";
            factura += "                   NRO. FACTURA: " + rellenarConCeros(5, nro) + "\n";
            factura += "              NRO. AUTORIZACIÓN: " + autorizacion + "\n";
            factura += "------------------------------------------------------------------" + "\n";
            factura += "                     COMERCIO MINORISTA" + "\n";
            factura += "------------------------------------------------------------------" + "\n";
            factura += " FECHA: " + fecha + "       " + hora + "\n";
            factura += " NIT/CI: " + nit + "\n";
            factura += " SEÑOR(ES): " + nombre + "\n";
            factura += "------------------------------------------------------------------" + "\n";
            factura += String.Format("{0,-20}  {1,-20}  {2}", "CANT.", "PRODUCTO", "SUB-TOTAL") + "\n";
            factura += "------------------------------------------------------------------" + "\n";
            foreach (DetalleVenta item in productos)
            {
                Producto auxProd = ProductoBLL.GetProductById(item.fkProducto);
                string   nam     = "";
                if (auxProd.txtNombre.Length >= 12)
                {
                    nam = auxProd.txtNombre.Substring(0, 12) + "...";
                }
                else
                {
                    nam = auxProd.txtNombre;
                    if (rellenarDecimales(item.decimalTotal + "").Length == 5)
                    {
                        while (nam.Length < 20)
                        {
                            nam += " ";
                        }
                        nam += "...";
                    }
                    else
                    {
                        while (nam.Length < 15)
                        {
                            nam += " ";
                        }
                        nam += "...";
                    }
                }
                factura += String.Format("  {0,-20}  {1,-20}  {2,17}", item.intCantidad, nam, rellenarDecimales(item.decimalTotal + "")) + "\n";
            }
            factura += "------------------------------------------------------------------" + "\n";
            if (total.Length == 7)
            {
                factura += "                                               TOTAL BS. " + rellenarDecimales(total) + "\n";
            }
            else
            {
                factura += "                                                TOTAL BS. " + rellenarDecimales(total) + "\n";
            }
            factura += "------------------------------------------------------------------" + "\n";
            factura += " SON: " + objLiteral.Convertir(rellenarDecimales(total), true) + "\n";
            factura += " CÓDIGO DE CONTROL: " + codigo + "\n";
            LlaveFactura llave = LlaveFacturaBLL.GetLlaveFacturaByAutorizacion(autorizacion);

            factura += " FECHA LÍMITE DE EMISIÓN: " + llave.dateFechaLimite.ToShortDateString() + "\n";
            return(factura);
        }