// POST api/<controller> public void Post(int[] idProductos, int[] cantidades) { En.Factura fact = new En.Factura(); fact.FechaFactura = System.DateTime.Today; fact.descuento = 5; //descuento porque estamos en prueba int j = idProductos.Length; int monto = 0; for (int i = 0; i < j; i++) { //Monto total monto += ctProductos.GetProducto(idProductos[i], true).Precio *cantidades[i]; //Disminuir el stock ctProductos.changeStock(idProductos[i], ctProductos.GetProducto(idProductos[i], true).stock - cantidades[i]); } fact.montoFinal = monto; ctFactura.Crear(fact); //Obtener el id de la facura int idFactura = ctFactura.getIdFactura(fact.FechaFactura); //ingresamos los productos uno por uno a detalle factura for (int i = 0; i < j; i++) { En.DetalleFactura dfact = new En.DetalleFactura(); dfact.idFactura = idFactura; dfact.precioUnitario = ctProductos.GetProducto(idProductos[i], true).Precio; dfact.nombres = ctProductos.getNameProducto(idProductos[i]); dfact.cantidad = cantidades[i]; ctDetalleFactura.Crear(dfact); } }
private void btn_agregar_a_factura_Click(object sender, EventArgs e) { if (dgv_detalle.Rows.Count >= 1) { List<DetalleFactura> detalle = new List<DetalleFactura>(); for (int c = 0; c < dgv_detalle.RowCount; c++) { DetalleFactura de = new DetalleFactura(); Producto p = new Producto(); UnidadMedida u = new UnidadMedida(); p.idProducto = (int)dgv_detalle.Rows[c].Cells["idProductodetalle"].Value; p.CODProducto = (int)dgv_detalle.Rows[c].Cells["codigo"].Value; p.Nombre = (string )dgv_detalle.Rows[c].Cells["nombreproductodetalle"].Value; u.Nombre = (string)dgv_detalle.Rows[c].Cells["unidadmedida"].Value; p.Unidad = u; p.precio = (double)dgv_detalle.Rows[c].Cells["preciodetalle"].Value; de.cantidad = Convert.ToDouble(dgv_detalle.Rows[c].Cells["cantidad"].Value); de.producto = p; detalle.Add(de); } Vista.iniciador.detalle = detalle; Close(); Dispose(); } }
public bool Crear(EN.DetalleFactura other) { bool resultado = false; BR.DetalleFactura df = new BR.DetalleFactura(); try { //se crea el detalle factura en la base de datos df.cantidad = other.cantidad; df.idFactura = other.idFactura; df.idProducto = ctProducto.getIdProducto(other.nombres); df.precioUnitario = other.precioUnitario; db.DetalleFactura.Add(df); db.SaveChanges(); //var consulta = from Productos in db.Productos // where (Productos.idProducto == detfac.idProducto) // select Productos; resultado = true; //disminuir el stock //Al annaidr una factura debemos annadir un detalleFactura y disminuir el Stock //Consulta del id de la factura asociada al cliente //foreach (var item in consulta) //{ // factura.idFactura = item.idFactura; //} //for (int i = 0; i < factura.DetallesFactura.Count; i++) //{ // BR.DetalleFactura detalleFactura = new BR.DetalleFactura(); // detalleFactura.idFactura = factura.idFactura; // detalleFactura.idProducto = factura.DetallesFactura[i].idProducto; // detalleFactura.cantidad = factura.DetallesFactura[i].cantidad; // BR.Productos producto = db.Productos.Find(factura.DetallesFactura[i].idProducto); // producto.stock = producto.stock - factura.DetallesFactura[i].cantidad; // db.DetalleFactura.Add(detalleFactura); // db.SaveChanges(); //} } catch (Exception) { throw; } return(resultado); }
public List <EN.DetalleFactura> GetDetalleFacturas() { List <BR.DetalleFactura> query = db.DetalleFactura.ToList(); List <EN.DetalleFactura> listDest = new List <EN.DetalleFactura>(); //Recorremos la consulta foreach (var item in query) { EN.DetalleFactura other = new EN.DetalleFactura(); other.cantidad = item.cantidad; other.idFactura = item.idFactura; other.nombres = item.Productos.nombreProducto; other.precioUnitario = item.precioUnitario; //Annadimos a la lista que retornamos listDest.Add(other); } return(listDest); }
protected void btn_facturar_Click(object sender, EventArgs e) { Factura f = new Factura(); f.MontoFact = int.Parse(txt_total.Text); f.Cuit = txt_cuit.Text; f.Fecha = DateTime.Parse(txt_fechaActual.Text); f.IDcli1 = int.Parse(txt_numCli.Text); List<DetalleFactura> listdet = new List<DetalleFactura>(); List<DetalleReserva> list = (List<DetalleReserva>)ViewState["view"]; ArrayList categoryIDList = (ArrayList)Session["CHECKED_ITEMS"]; for (int i = 0; i < categoryIDList.Count; i++) { for (int k = 0; k < list.Count; k++) { if (categoryIDList[i].Equals(list[k].Id)) { DetalleFactura det = new DetalleFactura(); det.Fact = int.Parse(txt_nroFactura.Text); det.IdDet = list[k].Id; det.Cab = int.Parse(list[k].Cab.IdCabania.ToString()); det.Precio = int.Parse(list[k].Precio.ToString()); det.SubTotal = int.Parse(list[k].Subtotal.ToString()); det.CantDias = int.Parse(list[k].CantDias.ToString()); listdet.Add(det); } } } f.ListaDetalles = listdet; string resultado; resultado = GestorFactura.insetar(f); txt_apellido.Text = ""; txt_nombre.Text = ""; txt_fechaNac.Text = ""; txt_fechaActual.Text = ""; txt_idReserva.Text = ""; txt_numCli.Text = ""; txt_nroFactura.Text = ""; txt_fechaReserva.Text = ""; txt_cuit.Text = ""; txt_total.Text = ""; dgv_detalles.DataSource = null; dgv_detalles.DataBind(); btn_facturar.Enabled = false; lbl_mensaje.Text = resultado; }
public static void Insert(DetalleFactura det, SqlConnection cn, SqlTransaction tran, int idFac) { Acceso ac = new Acceso(); //SqlConnection conexion = new SqlConnection(ac.getCadenaConexion()); SqlCommand cmd = new SqlCommand("sp_Insertar_detalle_factura", cn); cmd.Parameters.AddWithValue("@idFactura", idFac); if ( det.producto != null ) { cmd.Parameters.AddWithValue("@idProducto", det.producto.idProducto); } if ( det.detPedido != null ) { cmd.Parameters.AddWithValue("@idPedido", det.detPedido.pedido.idPedido); } cmd.Parameters.AddWithValue("@subtotal", det.subTotal ); // es el precio cmd.Parameters.AddWithValue("@cantidad", det.cantidad); if (det.detPedido != null) { cmd.Parameters.AddWithValue("@idProductoPedido", det.detPedido.producto.idProducto); } cmd.Parameters.AddWithValue("@iva", det.iva ); try { cmd.Connection = cn; cmd.Transaction = tran; cmd.CommandType = CommandType.StoredProcedure; cmd.ExecuteNonQuery(); //if (det.producto != null) //{ // ProductoDAO.UpdateStockActualYDisponible(det, cn, tran); //} if (det.detPedido != null) { ProductoDAO.UpdateStockReservadoYActualdePedidoEntregado(det.detPedido, det.detPedido.pedido.idPedido, 7); } } catch (ArgumentException ex) { throw new ApplicationException(ex.Message); } catch (SqlException ex) { throw new ApplicationException("Error en BD: " + ex.Message); } }
public static List<DetalleFactura> GetDetalleFactura(int idFactura) { Acceso ac = new Acceso(); List<DetalleFactura> detalles = new List<DetalleFactura>(); string sql = "SELECT * from CONSULTAR_DETALLE_FACTURA where idFactura = @id"; SqlCommand cmd = new SqlCommand(); cmd.Parameters.AddWithValue("@id", idFactura); SqlConnection conexion = new SqlConnection(ac.getCadenaConexion()); try { conexion.Open(); cmd.Connection = conexion; cmd.CommandText = sql; cmd.CommandType = CommandType.Text; SqlDataReader dr = cmd.ExecuteReader(); DetalleFactura detalle; Producto producto; Producto productoPedido; UnidadMedida unidad; UnidadMedida unidadPedido; while (dr.Read()) { unidad = new UnidadMedida(); unidadPedido = new UnidadMedida(); unidad.Nombre = dr["unidadProducto"].ToString(); unidadPedido.Nombre = dr["unidadProdPedido"].ToString(); producto = new Producto(); productoPedido = new Producto(); producto.Unidad = unidad; producto.Nombre = dr["nombreProd"].ToString(); producto.idProducto = Convert.ToInt32(dr["idProducto"]); productoPedido.Unidad = unidadPedido; productoPedido.Nombre = dr["nombreProdPedido"].ToString(); productoPedido.idProducto = Convert.ToInt32(dr["idProductoPedido"]); detalle = new DetalleFactura(); detalle.cantidad = Convert.ToDouble(dr["cantidad"]); detalle.producto = producto; detalle.detPedido = new DetallePedido() { producto = productoPedido }; detalle.subTotal = Convert.ToDouble(dr["subtotal"]); detalle.iva = Convert.ToDouble(dr["iva"]); detalle.idDetalle = Convert.ToInt32(dr["idDetalleFactura"]); detalles.Add(detalle); } } catch (InvalidOperationException ex) { throw new ApplicationException(ex.Message); } catch (SqlException ex) { throw new ApplicationException("Error en BD: " + ex.Message); } finally { conexion.Close(); } return detalles; }
private void btn_guardar_Click(object sender, EventArgs e) { if (estadoFormulario == estados.nuevo) { Factura factura = new Factura(); List<DetalleFactura> detalle= new List<DetalleFactura>(); try { if (Convert.ToInt32(cmb_iva.SelectedIndex) == 0) { for (int c = 0; c < dgv_detalle.RowCount; c++) { int esSinpedido = (int)dgv_detalle.Rows[c].Cells["add"].Value; DetalleFactura det = new DetalleFactura(); det.cantidad = Convert.ToDouble(dgv_detalle.Rows[c].Cells["cantidad"].Value); if (esSinpedido == 0) { det.detPedido = new DetallePedido() { producto = new Producto() { idProducto = Convert.ToInt32(dgv_detalle.Rows[c].Cells["idProductodetalle"].Value) }, pedido = new Pedido() { idPedido = idPedido }, }; foreach (DetallePedido detp in ped.detallePedido) { if(detp.producto.idProducto==Convert.ToInt32(dgv_detalle.Rows[c].Cells["idProductodetalle"].Value)) { det.detPedido.cantidad = detp.cantidad; } } } else { det.producto = new Producto() { idProducto = Convert.ToInt32(dgv_detalle.Rows[c].Cells["idProductodetalle"].Value) }; } det.subTotal = Convert.ToDouble(dgv_detalle.Rows[c].Cells["preciodetalle"].Value); det.iva = Convert.ToDouble(dgv_detalle.Rows[c].Cells["sinIva"].Value); detalle.Add(det); } factura.detalleFactura = detalle; factura.cliente = ped.cliente; factura.pedido = ped; factura.fechaCreacion = dtp_fecha_factura.Value.Date; factura.importeTotal = Convert.ToDouble(txt_monto_total.Text); if (rbtn_contado.Checked) { factura.estado = new Estado() { idEstado = 28 }; } else { factura.estado = new Estado() { idEstado = 27 }; } factura.totalIVA = Convert.ToDouble(txt_totalIva.Text); factura.tipoFactura = Convert.ToChar(cmb_tipo_factura.Text); } else { for (int c = 0; c < dgv_detalle.RowCount; c++) { int esSinpedido = (int)dgv_detalle.Rows[c].Cells["add"].Value; DetalleFactura det = new DetalleFactura(); det.cantidad = Convert.ToDouble(dgv_detalle.Rows[c].Cells["cantidad"].Value); if (esSinpedido == 0) { det.detPedido = new DetallePedido() { producto = new Producto() { idProducto = Convert.ToInt32(dgv_detalle.Rows[c].Cells["idProductodetalle"].Value) }, pedido = new Pedido() { idPedido = idPedido } }; foreach (DetallePedido detp in ped.detallePedido) { if (detp.producto.idProducto == Convert.ToInt32(dgv_detalle.Rows[c].Cells["idProductodetalle"].Value)) { det.detPedido.cantidad = detp.cantidad; } } } else { det.producto = new Producto() { idProducto = Convert.ToInt32(dgv_detalle.Rows[c].Cells["idProductodetalle"].Value) }; } det.subTotal = Convert.ToDouble(dgv_detalle.Rows[c].Cells["preciodetalle"].Value); detalle.Add(det); } factura.detalleFactura = detalle; factura.cliente = ped.cliente; factura.fechaCreacion = dtp_fecha_factura.Value.Date; factura.importeTotal = Convert.ToDouble(txt_monto_total.Text); if (rbtn_contado.Checked) { factura.estado = new Estado() { idEstado = 28 }; } else { factura.estado = new Estado() { idEstado = 27 }; } factura.pedido = ped; factura.tipoFactura = Convert.ToChar(cmb_tipo_factura.Text); } iniciador.idFactura = FacturaDAO.Insert(factura, detalleAgregado); //MessageBox.Show("Registrado con Exito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); _estado = estados.guardado; btn_guardar.Enabled = false; btn_salir_Click(sender, e); } catch (ApplicationException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } } }
public void CalcularTotal() { TotalFactura = DetalleFactura.Sum(p => p.ValorSubtotal); }
private void btn_imprimir_Click(object sender, EventArgs e) { if (dgv_detalle.Rows.Count >= 1) { if (res == null && chk_Venta_Rapida.Checked == true || res != null && chk_Venta_Rapida.Checked == false) { List<DetalleFactura> detalle = new List<DetalleFactura>(); Factura fact = new Factura(); Persona per = new Persona(); Estado est = new Estado(); if (chk_Venta_Rapida.Checked == true) { per.idPersona = 17; } else { per.idPersona = res.idPersona; } fact.cliente = per; fact.fechaCreacion = DateTime.Now.Date; est.idEstado = 27; fact.estado = est; fact.importeTotal = int.Parse(txt_monto_total.Text); fact.tipoFactura = char.Parse(cmb_tipo_factura.Text); fact.totalIVA = double.Parse(txt_totalIva.Text); for (int c = 0; c < dgv_detalle.RowCount; c++) { DetalleFactura de = new DetalleFactura(); Producto p = new Producto(); p.idProducto = (int)dgv_detalle.Rows[c].Cells["idProductodetalle"].Value; de.subTotal = (double)dgv_detalle.Rows[c].Cells["preciodetalle"].Value; de.cantidad = Convert.ToDouble(dgv_detalle.Rows[c].Cells["cantidad"].Value); de.iva = Convert.ToDouble(dgv_detalle.Rows[c].Cells["iva"].Value); de.producto = p; detalle.Add(de); } fact.detalleFactura = detalle; try { //iniciador.idFactura = FacturaDAO.InsertFacturaDirecta(fact); MessageBox.Show("Registrado con Exito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); btn_guardar.Enabled = false; } catch (ApplicationException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } Emitir_Factura factura = new Emitir_Factura(); factura.ShowDialog(); btn_nuevo_Click(sender, e); } } EmitirPresupuesto emitir = new EmitirPresupuesto(); emitir.ShowDialog(); }