    [:td.text-right (currency-format (:polarized-value item))]
    [:td.text-right (currency-format (:balance item))]])
 
-(defn- items-table []
+(defn- items-table
+  [{:keys [items]}]
   [:table.table.table-striped.table-hover
    [:thead
     [:tr

        (rename-keys rename-map))))

(defn- handle-saved-transaction
  [transaction]
  (reset! working-transaction nil)
  (reset! transaction-items nil)
  (get-items))

(defn- save-transaction []
  (-> @working-transaction
      transform-transaction
      (transactions/create handle-saved-transaction
                           notify/danger)))

(defn- transaction-form []
  (when @working-transaction
    [:div.panel.panel-primary
     [:div.panel-heading
      [:h2.panel-title (if (:id @working-transaction)
                         "Edit Transaction"
                         "New Transaction")]]

     [:div.panel-body
      [bind-fields trx-form working-transaction]
      (util/button "Save"
                   #(save-transaction)
                   {:class "btn btn-primary"
                    :icon :ok
                    :title "Click here to save the transaction"})]]))

(defn- show-account
  [id]
  (reset! transaction-items nil)
  (accounts/get-all (:id @state/current-entity)
                    #(reset! *accounts* (-> % nest unnest))
                    notify/danger)
  (accounts/get-one id
                    (fn [a]
                      (reset! account a)
                      (get-items))
                    notify/danger)
  (with-layout
    [:section
     [:div.row
      [:div.col-md-12
       [account-header]]]
     [:div.row
      [:div.col-md-6
       [transaction-form]]
      [:div.col-md-6
       [:div.panel.panel-default
        [:div.panel-heading
         [:h2.panel-title "Transaction Items"]]
        [:div.panel-body {:style {:height "40em" :overflow "auto"}}
         [items-table transaction-items]]]]]]))

(secretary/defroute new-account-path "/accounts/new" []
  (r/render [new-account] (app-element)))

    [start (-> start (t/plus (t/months 2)) t/last-day-of-the-month)]))

(defn- get-items
  ([context] (get-items context nil))
  ([{:keys [account items] :as context} prev-date-range]
   (let [[start end :as date-range] (next-query-range context prev-date-range)]
     (transaction-items/search
       {:account-id (:id @account)
        :transaction-date [:between start end]}
       (fn [result]
         (swap! items
                (fnil concat [])
                (map #(polarize-item % @account) result))
         (when (query-again? @items)
           (get-items context date-range)))
       notify/danger))))

(def ^:private trx-form
