Fixes for inventory average costing calculations

This fix repair the issues involving average costing transactions and
adds a new field to the inventory_history table. Closes issue #87