Giving products back from sales and purchases

Can you explain how can i do this.
For example i sold a product to a customer and one day this customer gave this product back.
Or
I bought a product from suppliers but this product is damaged. I wanna give back to supplier. How will i get to the accounts