Line items first, totals second
Each line is a description, a quantity and a unit price, and the amount is the product of the two. The subtotal is the sum of the lines, and every other figure on the invoice is derived from it, so a change anywhere flows through automatically.
A discount comes off before tax, because tax is charged on what the customer actually pays. A deposit reduces the balance rather than the invoice total, which keeps the headline figure and the amount still owed separate.