Zend certified PHP/Magento developer

Coupon discount calculcated incorrectly on Magento

When an order is placed using both store and coupon discount, instead of calculating coupon discount first and then store discount, both discounts are added up and calculated together which leads to a difference in discount amount and discount invoiced. Further, when quantity of a product is more than 1, coupon discount seems to get multiplied by quantity ex qty=2, coupon discount of 10% becomes 20%. I have no idea how to fix this since it seems to be calculated on Magento’s backend.

Here is a picture of the order details, as you can see discount amounts calculated on top grey area are by Magento and order summary has data from my calculations.
Magento calculations of discount – 30% of subtotal for item with qty 2 and 20% of subtotal for qty=1.
Required discount calculation – where subtotal is total of both items.
1. Coupon discount (subotal -10% of subtotal)
2. Store discount 10% of subtotal after coupon discount.