How to calculate total pricing from input tables?