Improve estimation calculation, take discounts and taxes into account.

The current commit is not functional. Needs debug.