If the discount is fixed at 20% you don't have to calculate the discount rate, it's 20%...
The amount is simply 0.2 times the amount of the invoice. Whether that should be taken before or after taxes is irrelevant to the invoice after taxes. It may however be relevant for tax purposes, I don't know your taxlaw so I can't say.
Your calculation is seriously flawed.
And oh, NEVER chain assignments like you did. It easily leads to confusion.
The ++ operator also seems unfamiliar to you. Do you really want to increase the totalPurchase amount only after calculating the discount over that purchase?
There's more wrong there, but that should be a start.