Пример #1
0
 private void dgvFacturas_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     foreach (Factura item in listaFacturas)
     {
         foreach (DetalleLibroVentas det in listaDetalleLibro)
         {
             if (item.txtNroFactura == Convert.ToString(dgvFacturas.Rows[e.RowIndex].Cells[0].Value) && det.txtNroFactura == Convert.ToString(dgvFacturas.Rows[e.RowIndex].Cells[0].Value.ToString()))
             {
                 if (original == " COPIA")
                 {
                     original = "ORIGINAL";
                 }
                 List <DetalleVenta> listaDetalle = DetalleVentaBLL.GetDetalleVentaByIDFactura(item.pkFactura);
                 imprimirFactura(item.txtNroFactura, det.txtNroAutorizacion, det.dateFechaFactura.ToShortDateString(), det.dateFechaFactura.ToShortTimeString(), det.txtNitCliente, det.txtNombreRazon, listaDetalle, det.decImporteTotal + "", det.txtCodigoControl, det.decImporteBaseDF + "", det.decDescuentos + "");
                 original = "COPIA";
                 imprimirFactura(item.txtNroFactura, det.txtNroAutorizacion, det.dateFechaFactura.ToShortDateString(), det.dateFechaFactura.ToShortTimeString(), det.txtNitCliente, det.txtNombreRazon, listaDetalle, det.decImporteTotal + "", det.txtCodigoControl, det.decImporteBaseDF + "", det.decDescuentos + "");
                 return;
             }
         }
     }
 }
Пример #2
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");
         }
     }
 }