This is a very tricky situation to deal with in a calculation like this. To make this work via the calculations would require a bit of custom coding and it might not be so easy to get rite.
The best way to do this would be to apply the discounts in the form of a calculation on a per item basis. This way you can effect the total price for the item directly. This would make applying the tax charge rule much easier as the total price of the items that are taxable would account for the discount already and you would just tax the total of total price where taxable.