Magento order calculation formula
orders.subtotal = ((orders.grand_total+IFNULL(orders.base_customer_balance_amount,0)) + ABS(orders.base_discount_amount))-orders.base_shipping_amount Explanation: Order items makes subtotal, then shipping cost is added to it. From that sum discount is extracted and customer balance (if any) extracted. Remaining amount is total due to pay (amount which really needs to be paid by customer) or grand_total