   with new balance and index values"
   [storage transaction-date [account-id items]]
   (let [sorted-items (sort-by :index items)
-        previous-item (get-previous-item storage (first sorted-items) transaction-date)
+        previous-item (get-previous-item storage (first sorted-items))
         previous-balance (or (get previous-item :balance)
                              (bigdec 0))
         previous-index (or (get previous-item :index) -1)]


(defn- get-previous-item
  "Finds the transaction item that immediately precedes the specified item"
  [storage item transaction-date]
  (->> (select-transaction-items storage
                                 {:account-id (:account-id item)
                                  :transaction-date [:between nil transaction-date]}
                                 {:sort [[:transaction-date :desc] [:index :desc]]})
       (remove #(= (:id %) (:id item)))
       first))

(defn- process-item-balance-and-index

    (let [validated (validate s ::new-transaction transaction)]
      (if (validation/has-error? validated)
        validated
        (if (delay-balances? (:entity-id transaction))
            (create-transaction-without-balances s validated)
            (create-transaction-and-adjust-balances s validated))))))

