you can add overrides.

This commit is contained in:
Bryce Covert
2020-04-19 14:38:55 -07:00
parent 5579fc95b2
commit a48ee8dd52
6 changed files with 179 additions and 103 deletions

View File

@@ -147,7 +147,34 @@
:auto-ap/add-due {:txes [[{:db/ident :invoice/due
:db/doc "When you gotta pay"
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one}]]}}]
:db/cardinality :db.cardinality/one}]]}
:auto-ap/add-vendor-overrides {:txes [[{:db/ident :vendor-account-override/account
:db/doc "the account for invoices"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :vendor-account-override/client
:db/doc "How many days till you pay"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :vendor-terms-override/terms
:db/doc "How many days till you pay"
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}
{:db/ident :vendor-terms-override/client
:db/doc "How many days till you pay"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}
{:db/ident :vendor/terms-overrides
:db/doc "Overrides per-client"
:db/isComponent true
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}
{:db/ident :vendor/account-overrides
:db/isComponent true
:db/doc "Overrides per-client"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}]]}
}]
(println "Conforming database...")
(c/ensure-conforms conn norms-map)
(when (not (seq args))

View File

@@ -3,31 +3,23 @@
[auto-ap.datomic :refer [uri]]))
(defn get-graphql [args]
(prn (->> (d/q '[:find (pull ?e [*])
(->> (d/q '[:find (pull ?e [* {:vendor/account-overrides [* {:vendor-account-override/client [:client/name :db/id]
:vendor-account-override/account [:account/name :account/numeric-code :db/id]}]
:vendor/terms-overrides [* {:vendor-terms-override/client [:client/name :db/id]}]}])
:where [?e :vendor/name]]
(d/db (d/connect uri)))
(map first)
(take 5)))
(->> (d/q '[:find (pull ?e [*])
:where [?e :vendor/name]]
(d/db (d/connect uri)))
(map first)
#_(map (fn [c]
(update c :client/bank-accounts
(fn [bas]
(map (fn [ba]
(update ba :bank-account/type :db/ident ))
bas)))))))
(map first)))
(defn get-by-id [id]
(->> (d/q '[:find (pull ?e [* {:default-account [:account/name :db/id :account/location]}])
(->> (d/q '[:find (pull ?e [*
{:default-account [:account/name :db/id :account/location]
:vendor/account-overrides [* {:vendor-account-override/client [:client/name :db/id]
:vendor-account-override/account [:account/name :account/numeric-code :db/id]}]
:vendor/terms-overrides [* {:vendor-terms-override/client [:client/name :db/id]}]}])
:in $ ?e
:where [?e]]
(d/db (d/connect uri))
id)
(map first)
(first)
))
(first)))

View File

@@ -110,12 +110,26 @@
:city {:type 'String}
:state {:type 'String}
:zip {:type 'String}}}
:terms_override
{:fields {:id {:type :id}
:client {:type :client}
:terms {:type 'Int}
}}
:account_override
{:fields {:id {:type :id}
:client {:type :client}
:account {:type :account}}}
:vendor
{:fields {:id {:type :id}
:name {:type 'String}
:code {:type 'String}
:terms {:type 'Int}
:hidden {:type 'Boolean}
:terms_overrides {:type '(list :terms_override)}
:account_overrides {:type '(list :account_override)}
:print_as {:type 'String}
:primary_contact {:type :contact}
@@ -516,10 +530,22 @@
:state {:type 'String}
:zip {:type 'String}}}
:add_terms_override
{:fields {:id {:type :id}
:client_id {:type :id}
:terms {:type 'Int}
}}
:add_account_override
{:fields {:id {:type :id}
:client_id {:type :id}
:account_id {:type :id}}}
:add_vendor
{:fields {:id {:type :id}
:name {:type 'String}
:terms {:type 'Int}
:terms_overrides {:type '(list :add_terms_override)}
:code {:type 'String}
:hidden {:type 'Boolean}
@@ -529,6 +555,7 @@
:address {:type :add_address}
:default_account_id {:type :id}
:account_overrides {:type '(list :add_account_override)}
:invoice_reminder_schedule {:type 'String}}}
:edit_expense_account

View File

@@ -8,7 +8,7 @@
[clojure.set :as set]))
(defn upsert-vendor [context {{:keys [id name hidden terms code print_as primary_contact secondary_contact address default_account_id invoice_reminder_schedule] :as in} :vendor} value]
(defn upsert-vendor [context {{:keys [id name hidden terms code print_as primary_contact secondary_contact address default_account_id invoice_reminder_schedule terms_overrides account_overrides] :as in} :vendor} value]
(let [_ (println default_account_id)
transaction [(remove-nils #:vendor {:db/id (if id
id
@@ -20,6 +20,20 @@
:print-as print_as
:default-account default_account_id
:invoice-reminder-schedule (keyword invoice_reminder_schedule)
:terms-overrides (mapv
(fn [to]
(cond->
#:vendor-terms-override {:client (:client_id to)
:terms (:terms to)}
(:id to) (assoc :db/id (:id to))))
terms_overrides)
:account-overrides (mapv
(fn [ao]
(cond->
#:vendor-account-override {:client (:client_id ao)
:account (:account_id ao)}
(:id ao) (assoc :db/id (:id ao))))
account_overrides)
:address (when address
(remove-nils #:address {:db/id (if (:id address)
(:id address)