Exemple #1
0
        public static string Insertar(int tipodocumento, string nombredocu, string seriedocu, string numdocu, int sujeto, decimal subtotal, decimal iva, decimal total, int bodega, int vendedor, int estado, DataTable Detalles)
        {
            D_Factura Datos = new D_Factura();
            E_Factura Obj   = new E_Factura();

            Obj.tipodocu   = tipodocumento;
            Obj.nombredocu = nombredocu;
            Obj.seriedocu  = seriedocu;
            Obj.numdocu    = numdocu;
            Obj.sujeto     = sujeto;
            Obj.subtotal   = subtotal;
            Obj.iva        = iva;
            Obj.total      = total;
            Obj.bodega     = bodega;
            Obj.vendedor   = vendedor;
            Obj.estado     = estado;
            Obj.Detalle    = Detalles;
            return(Datos.Insertar(Obj));
        }
        public async Task <E_Factura> Insertar(E_Factura entity)
        {
            using (var oConn = GetSqlConnection())
            {
                oConn.Open();
                var result = await oConn.QueryAsync <E_Factura>
                             (
                    "FacturaAddOrEdit",
                    new
                {
                    IdCliente = entity.IdCliente,
                    Subtotal  = entity.SubTotal,
                    Descuento = entity.Descuento,
                    Iva       = entity.Iva
                },
                    commandType : CommandType.StoredProcedure
                             );

                var factura = result.Distinct().FirstOrDefault();

                foreach (var item in entity.Detalle)
                {
                    var detalle = await oConn.QueryAsync <E_Detalle>
                                  (
                        "DetalleAddOrEdit",
                        new
                    {
                        IdFactura  = factura.Id,
                        IdProducto = item.IdProducto,
                        Cantidad   = item.Cantidad,
                        Descuento  = item.Descuento,
                        Iva        = item.Iva
                    },
                        commandType : CommandType.StoredProcedure
                                  );
                }

                return(await DevolverPorNumero(factura.Codigo));
            }
        }
Exemple #3
0
        public string Insertar(E_Factura Obj)
        {
            string        Rpta   = "";
            SqlConnection SqlCon = new SqlConnection();

            try
            {
                SqlCon = Conexion.getInstancia().CrearConexion();
                SqlCommand Comando = new SqlCommand("factura_insertar", SqlCon);
                Comando.CommandType = CommandType.StoredProcedure;
                Comando.Parameters.Add("@idusuario", SqlDbType.Int).Value             = Obj.vendedor;
                Comando.Parameters.Add("@idcliente", SqlDbType.Int).Value             = Obj.sujeto;
                Comando.Parameters.Add("@serie_comprobante", SqlDbType.VarChar).Value = Obj.seriedocu;
                Comando.Parameters.Add("@num_comprobante", SqlDbType.VarChar).Value   = Obj.numdocu;
                Comando.Parameters.Add("@subtotal", SqlDbType.Decimal).Value          = Obj.subtotal;
                Comando.Parameters.Add("@iva", SqlDbType.Decimal).Value        = Obj.iva;
                Comando.Parameters.Add("@total", SqlDbType.Decimal).Value      = Obj.total;
                Comando.Parameters.Add("@bodega", SqlDbType.Int).Value         = Obj.bodega;
                Comando.Parameters.Add("@detalle", SqlDbType.Structured).Value = Obj.Detalle;
                SqlCon.Open();
                Comando.ExecuteNonQuery();
                Rpta = "OK";
            }
            catch (Exception ex)
            {
                Rpta = ex.Message;
            }

            finally
            {
                if (SqlCon.State == ConnectionState.Open)
                {
                    SqlCon.Close();
                }
            }
            return(Rpta);
        }
 public Task <E_Factura> Actualizar(E_Factura entity)
 {
     throw new NotImplementedException();
 }
Exemple #5
0
 public async Task <E_Factura> Insertar(E_Factura entity)
 {
     return(await facturaRepository.Insertar(entity));
 }
        public async Task <ActionResult> Insertar(FacturaViewModel model)
        {
            try
            {
                E_Factura factura = new E_Factura();
                var       cliente = await clienteServices.DevolverPorCodigo(model.CodCliente);

                factura.IdCliente = cliente.Id;
                factura.SubTotal  = model.SubTotal;
                factura.Descuento = model.TotalDescuento;
                factura.Iva       = model.TotalIva;

                if (model.Detalle != null)
                {
                    factura.Detalle = new List <E_Detalle>();

                    foreach (var item in model.Detalle)
                    {
                        E_Detalle detalle  = new E_Detalle();
                        var       producto = await productoServices.DevolverPorCodigo(item.CodigoProducto);

                        detalle.IdProducto = producto.Id;
                        detalle.Cantidad   = item.Cantidad;
                        detalle.Descuento  = item.PorcentajeDescuento;
                        detalle.Iva        = item.PorcentajeIva;
                        factura.Detalle.Add(detalle);
                    }
                }

                E_Factura fac = await facturaServices.Insertar(factura);

                FacturaViewModel facturaViewModel = new FacturaViewModel();
                facturaViewModel.NumeroFactura = fac.Codigo;
                facturaViewModel.CodCliente    = fac.Cliente.Codigo;

                var resultcli = await clienteServices.DevolverPorCodigo(fac.Cliente.Codigo);

                ClienteViewModel clienteViewModel = new ClienteViewModel();
                clienteViewModel.Codigo         = resultcli.Codigo;
                clienteViewModel.Identificacion = resultcli.Identificacion;
                clienteViewModel.Tipo_Documento = resultcli.Tipo_Identificacion.Abreviatura;
                clienteViewModel.NombreCompleto = resultcli.NombreCompleto;
                clienteViewModel.Direccion      = resultcli.Direccion;
                clienteViewModel.Telefono       = resultcli.Telefono;
                clienteViewModel.FechaNac       = resultcli.FechaNac.ToString("dd/MM/yyyy");
                clienteViewModel.Correo         = resultcli.Correo;
                facturaViewModel.Cliente        = clienteViewModel;

                facturaViewModel.Fecha          = fac.Fecha.ToString("dd/MM/yyyy");
                facturaViewModel.SubTotal       = fac.SubTotal;
                facturaViewModel.TotalDescuento = fac.Descuento;
                facturaViewModel.TotalIva       = fac.Iva;
                facturaViewModel.TotalGeneral   = fac.Total;

                List <DetalleViewModel> listaDetalle = new List <DetalleViewModel>();

                foreach (var item in fac.Detalle)
                {
                    DetalleViewModel detalle = new DetalleViewModel();
                    detalle.NumeroFactura  = fac.Codigo;
                    detalle.CodigoProducto = item.Producto.Codigo;

                    ProductoViewModel Producto = new ProductoViewModel();
                    Producto.CodigoProducto = item.Producto.Codigo;
                    Producto.NombreProducto = item.Producto.Nombre;
                    Producto.Descripcion    = item.Producto.Descripcion;
                    Producto.Precio         = item.Lista_Precio.Precio;
                    detalle.Producto        = Producto;

                    detalle.Cantidad            = item.Cantidad;
                    detalle.Precio              = item.Lista_Precio.Precio;
                    detalle.PorcentajeDescuento = item.Descuento;
                    detalle.PorcentajeIva       = item.Iva;
                    listaDetalle.Add(detalle);
                }

                facturaViewModel.Detalle = listaDetalle;
                return(Ok(facturaViewModel));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }