fix js which calculates the index for the next created invoice item