   [storage transaction]
   (let [items-with-balances (calculate-balances-and-indexes
                               storage
-                              (:transaction-date transaction)
                               (:items transaction))
         _ (update-affected-balances storage items-with-balances
                                     (:transaction-date transaction))

  on the balance of the associated account and is dependant on the action
  (debit or credit) and the account type (asset, liability, equity,
  income, or expense)"
  [storage transaction-date items]
  (->> items
       (group-by :account-id)
       (mapcat (partial add-item-balance-and-index
                     storage
                     transaction-date))))

(defn- subsequent-items
  "Returns items in the specified account on or after the specified

(defn- add-item-balance-and-index
  "Updates the specified items, which belong to the specified account
  with new balance and index values"
  [storage [account-id items]]
  (let [sorted-items (sort-by :index items)
        previous-item (get-previous-item storage (first sorted-items))
        previous-balance (or (get previous-item :balance)
