made it possible to change accounts.
This commit is contained in:
@@ -2,12 +2,17 @@
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.graphql.utils :refer [->graphql]]
|
||||
[auto-ap.datomic :refer [uri merge-query]]))
|
||||
(defn <-datomic [a]
|
||||
(update a :account/applicability :db/ident))
|
||||
|
||||
(defn get-accounts
|
||||
([]
|
||||
(get-accounts {}))
|
||||
([args]
|
||||
(let [query (cond-> {:query {:find ['(pull ?e [* {:account/type [:db/ident :db/id]}])]
|
||||
(let [query (cond-> {:query {:find ['(pull ?e [* {:account/type [:db/ident :db/id]
|
||||
:account/applicability [:db/ident :db/id]
|
||||
:account/client-overrides [:account-client-override/name
|
||||
{:account-client-override/client [:db/id :client/name]}]}])]
|
||||
:in ['$]
|
||||
:where [['?e :account/name]]}
|
||||
:args [(d/db (d/connect uri))]}
|
||||
@@ -16,7 +21,21 @@
|
||||
:args [(:account-set args)]}))]
|
||||
(->>
|
||||
(d/query query)
|
||||
(map first)))))
|
||||
(map first)
|
||||
(map <-datomic)))))
|
||||
|
||||
(defn get-by-id [id]
|
||||
(let [query {:query {:find ['(pull ?e [* {:account/type [:db/ident :db/id]
|
||||
:account/applicability [:db/ident :db/id]
|
||||
:account/client-overrides [:account-client-override/name
|
||||
{:account-client-override/client [:db/id :client/name]}]}])]
|
||||
:in ['$ '?e]}
|
||||
:args [(d/db (d/connect uri) ) id]}]
|
||||
(->>
|
||||
(d/query query)
|
||||
(map first)
|
||||
(map <-datomic)
|
||||
first)))
|
||||
|
||||
(defn get-account-by-numeric-code-and-sets [numeric-code sets]
|
||||
(let [query (cond-> {:query {:find ['(pull ?e [* {:account/type [:db/ident :db/id]}])]
|
||||
@@ -26,6 +45,7 @@
|
||||
(->>
|
||||
(d/query query)
|
||||
(map first)
|
||||
(map <-datomic)
|
||||
(first))))
|
||||
|
||||
#_(get-account-by-numeric-code-and-sets 5110 nil)
|
||||
|
||||
@@ -192,7 +192,42 @@
|
||||
:db/doc "Overrides per-client"
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/many}]]}
|
||||
:auto-ap/add-reset-rels {:txes-fn `reset-function}}]
|
||||
:auto-ap/add-reset-rels {:txes-fn `reset-function}
|
||||
:auto-ap/add-account-overrides {:txes [[{:db/ident :account/applicability
|
||||
:db/doc ":global, :optional :customized"
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/one}
|
||||
|
||||
{:db/ident :account-applicability/global
|
||||
:db/doc "The account applies to all cutsomers"}
|
||||
|
||||
{:db/ident :account-applicability/optional
|
||||
:db/doc "This account is optional"}
|
||||
|
||||
{:db/ident :account-applicability/customized
|
||||
:db/doc "This account is customized per-customer"}
|
||||
|
||||
{:db/ident :account/client-overrides
|
||||
:db/doc "Customizations per customer"
|
||||
:db/valueType :db.type/ref
|
||||
:db/isComponent true
|
||||
:db/cardinality :db.cardinality/many}
|
||||
|
||||
|
||||
{:db/ident :account-client-override/client
|
||||
:db/doc "The client for the override"
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/one}
|
||||
|
||||
{:db/ident :account-client-override/enabled
|
||||
:db/doc "Does this apply?"
|
||||
:db/valueType :db.type/boolean
|
||||
:db/cardinality :db.cardinality/one}
|
||||
|
||||
{:db/ident :account-client-override/name
|
||||
:db/doc "client override"
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/one}]]} }]
|
||||
(println "Conforming database...")
|
||||
(c/ensure-conforms conn norms-map)
|
||||
(when (not (seq args))
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
:terms {:type 'Int}
|
||||
}}
|
||||
|
||||
:account_override
|
||||
:vendor_account_override
|
||||
{:fields {:id {:type :id}
|
||||
:client {:type :client}
|
||||
:account {:type :account}}}
|
||||
@@ -129,7 +129,7 @@
|
||||
:terms {:type 'Int}
|
||||
:hidden {:type 'Boolean}
|
||||
:terms_overrides {:type '(list :terms_override)}
|
||||
:account_overrides {:type '(list :account_override)}
|
||||
:account_overrides {:type '(list :vendor_account_override)}
|
||||
|
||||
:print_as {:type 'String}
|
||||
:primary_contact {:type :contact}
|
||||
@@ -244,14 +244,19 @@
|
||||
:role {:type 'String}
|
||||
:clients {:type '(list :client)}}}
|
||||
|
||||
|
||||
:account_client_override
|
||||
{:fields {:id {:type :id}
|
||||
:client {:type :client}
|
||||
:name {:type 'String}}}
|
||||
|
||||
:account {:fields {:id {:type :id}
|
||||
:numeric_code {:type 'Int}
|
||||
:type {:type :ident}
|
||||
:applicability {:type :applicability}
|
||||
:account_set {:type 'String}
|
||||
:location {:type 'String}
|
||||
:name {:type 'String}}}
|
||||
:name {:type 'String}
|
||||
:client_overrides {:type '(list :account_client_override)}}}
|
||||
|
||||
:invoices_expense_accounts
|
||||
{:fields {:id {:type :id}
|
||||
@@ -613,13 +618,20 @@
|
||||
:accounts {:type '(list :edit_percentage_account)}
|
||||
:transaction_approval_status {:type :transaction_approval_status}}}
|
||||
|
||||
:edit_account_client_override
|
||||
{:fields {:id {:type :id}
|
||||
:client_id {:type :id}
|
||||
:name {:type 'String}}}
|
||||
|
||||
:edit_account
|
||||
{:fields {:id {:type :id}
|
||||
:type {:type :account_type}
|
||||
:applicability {:type :applicability}
|
||||
:numeric_code {:type 'Int}
|
||||
:location {:type 'String}
|
||||
:account_set {:type 'String}
|
||||
:name {:type 'String}}}}
|
||||
:name {:type 'String}
|
||||
:client_overrides {:type '(list :edit_account_client_override)}}}}
|
||||
|
||||
:enums {:payment_type {:values [{:enum-value :check}
|
||||
{:enum-value :cash}
|
||||
@@ -630,6 +642,9 @@
|
||||
:bank_account_type {:values [{:enum-value :check}
|
||||
{:enum-value :credit}
|
||||
{:enum-value :cash}]}
|
||||
:applicability {:values [{:enum-value :global}
|
||||
{:enum-value :optional}
|
||||
{:enum-value :customized}]}
|
||||
:account_type {:values [{:enum-value :dividend}
|
||||
{:enum-value :expense}
|
||||
{:enum-value :asset}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
(ns auto-ap.graphql.accounts
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic.accounts :as d-accounts]
|
||||
[auto-ap.graphql.utils :refer [->graphql <-graphql] ]
|
||||
[auto-ap.graphql.utils :refer [->graphql <-graphql enum->keyword] ]
|
||||
[auto-ap.datomic :refer [uri merge-query remove-nils]]))
|
||||
|
||||
|
||||
|
||||
(defn get-accounts [context args value]
|
||||
(->graphql (d-accounts/get-accounts (<-graphql args))))
|
||||
|
||||
(defn upsert-account [context args value]
|
||||
(let [{{:keys [id numeric-code location account-set name type]} :account} (<-graphql args)]
|
||||
(let [{{:keys [id client-overrides numeric-code location applicability account-set name type]} :account} (<-graphql args)]
|
||||
(when-not id
|
||||
(when (seq (d/query {:query {:find ['?e]
|
||||
:in '[$ ?account-set ?numeric-code]
|
||||
@@ -26,16 +28,21 @@
|
||||
{:db/id (or id "new-account")
|
||||
:account/name name
|
||||
:account/type (keyword "account-type" (clojure.core/name type))
|
||||
:account/applicability (enum->keyword applicability "account-applicability")
|
||||
:account/account-set account-set
|
||||
:account/location location
|
||||
:account/numeric-code (if-not id
|
||||
numeric-code)
|
||||
:account/code (if-not id
|
||||
(str numeric-code))})]
|
||||
(str numeric-code))})
|
||||
[:reset (or id "new-account") :account/client-overrides
|
||||
(mapv
|
||||
(fn [client-override]
|
||||
(remove-nils
|
||||
{:account-client-override/client (:client-id client-override)
|
||||
:account-client-override/name (:name client-override)}))
|
||||
client-overrides)]]
|
||||
(and (not location) (:account/location original)) (conj [:db/retract (or id "new-account") :account/location (:account/location original)])))]
|
||||
(->graphql
|
||||
(if id
|
||||
(:account args)
|
||||
(assoc (:account args)
|
||||
:id (get-in result [:tempids "new-account"])))))))
|
||||
(d-accounts/get-by-id (or id (get-in result [:tempids "new-account"])))))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user