This is happening because a discount applies to the thing directly above it. This is more obvious if the discount is a percentage discount.
So,
- If the discount applies to a specific line item, use it directly below that line item.
- If the discount applies to the entire invoice evenly (it is awarded because of the nature of the entire purchase) then use a subtotal after the items an then the discount.
- If the discount applies to some but not all of the line items, then list those item, then a subtotal and the discount, and then the rest of the items.