public List <EDetalleCompra> Seleccionar(string Serie, string Numero)
        {
            List <EDetalleCompra> List = new List <EDetalleCompra>();

            try
            {
                DataTable      data       = new DataTable();
                SQLParameter[] parameters = new SQLParameter[2];
                parameters[0] = new SQLParameter("@Serie", Serie, SqlDbType.VarChar);
                parameters[1] = new SQLParameter("@Numero", Numero, SqlDbType.VarChar);
                data          = Conexion.ExecuteProcedureD("USP_S_SeleccionarDetalleCompra", parameters).Tables[0];
                foreach (DataRow row in data.Rows)
                {
                    EDetalleCompra be = new EDetalleCompra
                    {
                        ID             = Convert.ToInt32(row[0]),
                        Serie          = row[1].ToString(),
                        Numero         = row[2].ToString(),
                        Producto       = row[3].ToString(),
                        PrecioUnitario = Convert.ToDouble(row[4]),
                        Cantidad       = Convert.ToInt32(row[5]),
                        PrecioTotal    = Convert.ToDouble(row[6])
                    };
                    List.Add(be);
                }
            }
            catch
            {
                Console.WriteLine("No se encontro Procedimiento Almacenado");
            }
            return(List);
        }
 public bool Agregar(EDetalleCompra obj)
 {
     SQLParameter[] parameters = new SQLParameter[6];
     parameters[0] = new SQLParameter("@Serie", obj.Serie, SqlDbType.VarChar);
     parameters[1] = new SQLParameter("@Numero", obj.Numero, SqlDbType.VarChar);
     parameters[2] = new SQLParameter("@Producto", obj.Producto, SqlDbType.VarChar);
     parameters[3] = new SQLParameter("@PrecioUnitario", obj.PrecioUnitario, SqlDbType.Decimal);
     parameters[4] = new SQLParameter("@Cantidad", obj.Cantidad, SqlDbType.Int);
     parameters[5] = new SQLParameter("@PrecioTotal", obj.PrecioTotal, SqlDbType.Decimal);
     Response      = Conexion.ExecuteProcedureB("USP_I_AgregarDetalleCompra", parameters);
     return(Response);
 }
Exemplo n.º 3
0
        private void GuardarCompra()
        {
            ECompra beCompra = new ECompra
            {
                Proveedor       = Convert.ToInt32(LblIDProveedor.Text),
                Empleado        = Frm_Principal.AccesoUsernameID,
                TipoComprobante = CbxTipoComprobante.SelectedValue.ToString(),
                Serie           = TxtSerie.Text,
                Numero          = TxtNumero.Text,
                Fecha           = Convert.ToDateTime(DtpFecha.Text),
                SubTotal        = Compra_SubTotal,
                Igv             = Compra_Igv,
                Total           = Compra_Total,
                Estado          = 1
            };
            NCompra boCompra = new NCompra();

            if (boCompra.Agregar(beCompra) == true)
            {
                if (MLVDetalle.Items.Count > 0)
                {
                    NDetalleCompra boDetalleCompra = new NDetalleCompra();
                    foreach (ListViewItem items in MLVDetalle.Items)
                    {
                        EDetalleCompra beDetalleCompra = new EDetalleCompra
                        {
                            Serie          = beCompra.Serie,
                            Numero         = beCompra.Numero,
                            Producto       = items.SubItems[0].Text,
                            PrecioUnitario = Convert.ToDouble(items.SubItems[3].Text),
                            Cantidad       = Convert.ToInt32(items.SubItems[4].Text),
                            PrecioTotal    = Convert.ToDouble(items.SubItems[5].Text)
                        };
                        //Agregar dettalle compra
                        if (boDetalleCompra.Agregar(beDetalleCompra) == true)
                        {
                            int    cantidadfinal      = 0;
                            double costounitariofinal = 0;
                            double costototalfinal    = 0;
                            //Obteniendo Ultimo Movimiento
                            NMovimiento boM   = new NMovimiento();
                            EMovimiento datos = boM.SeleccionarUltimoMovimientoProducto(beDetalleCompra.Producto);
                            if (string.IsNullOrEmpty(datos.Producto))
                            {
                                cantidadfinal      = beDetalleCompra.Cantidad;
                                costounitariofinal = beDetalleCompra.PrecioUnitario;
                                costototalfinal    = beDetalleCompra.PrecioTotal;
                            }
                            else
                            {
                                //Si hay datos
                                cantidadfinal      = datos.CantidadFinal + beDetalleCompra.Cantidad;
                                costototalfinal    = datos.CostoTotalFinal + beDetalleCompra.PrecioTotal;
                                costounitariofinal = Math.Round((costototalfinal / cantidadfinal), 2);
                            }
                            EMovimiento beMovimiento = new EMovimiento
                            {
                                Fecha                = DateTime.Now,
                                TipoComprobante      = beCompra.TipoComprobante,
                                Serie                = beCompra.Serie,
                                Numero               = beCompra.Numero,
                                TipoOperacion        = "02",
                                Producto             = beDetalleCompra.Producto,
                                CantidadEntrada      = beDetalleCompra.Cantidad,
                                CostoUnitarioEntrada = beDetalleCompra.PrecioUnitario,
                                CostoTotalEntrada    = beDetalleCompra.PrecioTotal,
                                CantidadSalida       = 0,
                                CostoUnitarioSalida  = 0,
                                CostoTotalSalida     = 0,
                                CantidadFinal        = cantidadfinal,
                                CostoUnitarioFinal   = costounitariofinal,
                                CostoTotalFinal      = costototalfinal
                            };
                            NMovimiento boMovimiento = new NMovimiento();
                            if (boMovimiento.Agregar(beMovimiento) == true)
                            {
                                EInventario beInventario = new EInventario
                                {
                                    Producto        = beMovimiento.Producto,
                                    ValorUnitario   = beMovimiento.CostoUnitarioFinal,
                                    Existencias     = beMovimiento.CantidadFinal,
                                    ValorInventario = beMovimiento.CostoTotalFinal
                                };
                                NInventario boInventario = new NInventario();
                                boInventario.Modificar(beInventario);
                            }
                        }
                    }
                }
                //message
                Frm_Buscar_Compra frm = Owner as Frm_Buscar_Compra;
                frm.Listar();
                Close();
                Frm_Principal.Main.ChangeMessage("La Compra se ingreso correctamente", "Success");
            }
            else
            {
                Frm_Principal.Main.ChangeMessage("Algo salio mal", "Failed");
            }
        }