 (ns clj-money.models.transactions
   (:refer-clojure :exclude [update])
   (:require [clojure.pprint :refer [pprint]]
+            [clojure.set :refer [difference]]
             [clj-time.coerce :as tc]
             [schema.core :as schema]
             [clj-money.validation :as validation]

       (map before-save-item)
       (mapv #(update-item storage %))))

(defn update
  "Updates the specified transaction"
  [storage-spec transaction]

      validated
      (let [items-with-balances (calculate-balances-and-indexes storage
                                                                (:transaction-date validated)
                                                                (:items validated))
            _ (process-dereferenced-accounts storage validated) ; this relies on old values still being in the database
            _ (update-affected-balances storage
                                        items-with-balances
                                        (:transaction-date validated))
            processed-items (process-item-updates storage items-with-balances)]
        (assoc validated [:items] processed-items)))))

(defn- get-preceding-items
  "Returns the items that precede each item in the
