Can edit locations now.
This commit is contained in:
@@ -441,3 +441,11 @@ nav.navbar .navbar-item.is-active {
|
||||
.dropdown.is-fullwidth .dropdown-trigger * {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
.known-field.location {
|
||||
width: 5em;
|
||||
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@
|
||||
(mapv #(vector %)))]
|
||||
z))
|
||||
|
||||
#_(test-run (bulk-load-transaction-ledger (d/connect auto-ap.datomic/uri)))
|
||||
#_(test-run (bulk-load-transaction-ledger (d/connect auto-ap.datomic/uri)))
|
||||
#_(test-run (bulk-load-invoice-ledger (d/connect auto-ap.datomic/uri)))
|
||||
|
||||
#_(do (doseq [tran (convert-transactions (d/connect auto-ap.datomic/uri))]
|
||||
|
||||
@@ -423,6 +423,7 @@
|
||||
{:fields {:id {:type :id}
|
||||
:type {:type :account_type}
|
||||
:numeric_code {:type 'Int}
|
||||
:location {:type 'String}
|
||||
:account_set {:type 'String}
|
||||
:name {:type 'String}}}}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
(->graphql (d-accounts/get-accounts (<-graphql args))))
|
||||
|
||||
(defn upsert-account [context args value]
|
||||
(let [{{:keys [id numeric-code account-set name type]} :account} (<-graphql args)]
|
||||
(let [{{:keys [id numeric-code location account-set name type]} :account} (<-graphql args)]
|
||||
(when-not id
|
||||
(when (seq (d/query {:query {:find ['?e]
|
||||
:in '[$ ?account-set ?numeric-code]
|
||||
@@ -19,17 +19,20 @@
|
||||
(throw (ex-info (str "Account set " account-set " already has an account for code " numeric-code)
|
||||
{} ))))
|
||||
|
||||
(let [
|
||||
(let [original (if id (d/entity (d/db (d/connect uri)) id))
|
||||
result @(d/transact (d/connect uri)
|
||||
[(remove-nils
|
||||
{:db/id (or id "new-account")
|
||||
:account/name name
|
||||
:account/type (keyword "account-type" (clojure.core/name type))
|
||||
:account/account-set account-set
|
||||
:account/numeric-code (if-not id
|
||||
numeric-code)
|
||||
:account/code (if-not id
|
||||
(str numeric-code))})])]
|
||||
(cond->
|
||||
[(remove-nils
|
||||
{:db/id (or id "new-account")
|
||||
:account/name name
|
||||
:account/type (keyword "account-type" (clojure.core/name type))
|
||||
:account/account-set account-set
|
||||
:account/location location
|
||||
:account/numeric-code (if-not id
|
||||
numeric-code)
|
||||
:account/code (if-not id
|
||||
(str numeric-code))})]
|
||||
(and (not location) (:account/location original)) (conj [:db/retract (or id "new-account") :account/location (:account/location original)])))]
|
||||
(->graphql
|
||||
(if id
|
||||
(:account args)
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
[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 %))
|
||||
(s/def ::numeric-code (s/or :numeric-string? (s/and string?
|
||||
#(re-matches shared/numeric-regex %))
|
||||
:numeric? int?))
|
||||
(s/def ::name string?)
|
||||
(s/def ::location (s/nilable (s/and string?
|
||||
#(re-matches shared/only-upper-case %))))
|
||||
(s/def ::type #{:dividend :expense :asset :liability :equities :revenue})
|
||||
|
||||
(s/def ::account (s/keys :req-un [::account-set ::numeric-code ::name ::type]))
|
||||
(s/def ::account (s/keys :req-un [::account-set ::numeric-code ::name ::type ::location]))
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
(def date-regex #"[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}")
|
||||
(def money-regex #"\-?[0-9]+(\.[0-9]{1,2})?$")
|
||||
(def numeric-regex #"^[0-9]+$")
|
||||
(def only-upper-case #"^[A-Z]+$")
|
||||
|
||||
(s/def ::identifier (s/nilable string?))
|
||||
(s/def ::date (s/and string? #(re-matches date-regex %)))
|
||||
|
||||
@@ -28,14 +28,16 @@
|
||||
[:th "Code"]
|
||||
[:th "Name"]
|
||||
[:th "Type"]
|
||||
[:th "Location"]
|
||||
[:th {:style {:width "5em"}}]]]
|
||||
[:tbody
|
||||
(for [{:keys [id numeric-code name type] :as account} (sort-by :numeric-code accounts)]
|
||||
(for [{:keys [id numeric-code name type location] :as account} (sort-by :numeric-code accounts)]
|
||||
^{:key id}
|
||||
[:tr
|
||||
[:td numeric-code]
|
||||
[:td name]
|
||||
[:td type]
|
||||
[:td location]
|
||||
[:td [:a.button {:on-click (dispatch-event [::account-form/editing account])} [:span [:span.icon [:i.fa.fa-pencil]]]]]])]]])])
|
||||
|
||||
(defn admin-accounts-content []
|
||||
|
||||
@@ -16,9 +16,12 @@
|
||||
(re-frame/reg-sub
|
||||
::account-request
|
||||
:<- [::forms/form ::form]
|
||||
(fn [{{:keys [id type numeric-code name account-set]} :data}]
|
||||
(fn [{{:keys [id location type numeric-code name account-set]} :data}]
|
||||
{:id id
|
||||
:type (keyword type)
|
||||
:location (if (clojure.string/blank? location)
|
||||
nil
|
||||
location)
|
||||
:numeric-code numeric-code
|
||||
:name name
|
||||
:account-set account-set}))
|
||||
@@ -47,7 +50,7 @@
|
||||
:operation/name "UpsertAccount"}
|
||||
:venia/queries [{:query/data [:upsert-account
|
||||
{:account @(re-frame/subscribe [::account-request])}
|
||||
[:id :type :name :account-set :numeric-code]]}]}
|
||||
[:id :type :name :account-set :numeric-code :location]]}]}
|
||||
:on-success [::edited edit-completed]
|
||||
:on-error [::forms/save-error ::form]}}))))
|
||||
|
||||
@@ -112,6 +115,17 @@
|
||||
(map (fn [l]
|
||||
[:option {:value (name l)} (str/capitalize (name l))]) types)]]]]]
|
||||
|
||||
|
||||
[:div.field
|
||||
[:p.help "Location"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:input.input.known-field.location {:type "text"
|
||||
:field :location
|
||||
:spec ::entity/location
|
||||
:event change-event
|
||||
:subscription account}]]]]
|
||||
|
||||
(when error
|
||||
[:div.notification.is-warning.animated.fadeInUp
|
||||
error])
|
||||
|
||||
Reference in New Issue
Block a user