Supports editing expense accounts

This commit is contained in:
Bryce Covert
2019-04-12 12:00:42 -07:00
parent bdb06d802b
commit e64820d71a
6 changed files with 119 additions and 53 deletions

View File

@@ -0,0 +1,16 @@
(ns auto-ap.entities.account
(:require [clojure.spec.alpha :as s]
[clojure.string :as str]
[auto-ap.entities.shared :as shared]))
(def numeric-regex #"^[0-9]+$")
(s/def ::account-set string?)
(s/def ::numeric-code (s/or :numericstring? (s/and string?
#(re-matches numeric-regex %))
:numeric? int?))
(s/def ::name string?)
(s/def ::type #{:dividend :expense :asset :liability :equities :revenue})
(s/def ::account (s/keys :req-un [::account-set ::numeric-code ::name ::type]))

View File

@@ -19,12 +19,18 @@
existing))
(defn replace-by [xs f x]
(mapv
(fn [t]
(if (= (f t) (f x))
x
t))
xs))
(let [found? (atom false)
replaced (mapv
(fn [t]
(if (= (f t) (f x))
(do (reset! found? true)
(println "found" (f t) t (f x) x)
x)
t))
xs)]
(if @found?
replaced
(conj replaced x))))
(defn dollars-0? [amt]
(< -0.001 amt 0.001))