compute spent, given and balance for each line, fix tests