lots of fixes.
This commit is contained in:
@@ -33,7 +33,7 @@
|
|||||||
:db/fn (d/function '{:lang "clojure"
|
:db/fn (d/function '{:lang "clojure"
|
||||||
:params [db e a amount]
|
:params [db e a amount]
|
||||||
:code [[:db/add e a
|
:code [[:db/add e a
|
||||||
(-> (d/entity db e) a (+ amount))]] })}]] )
|
(-> (d/entity db e) a (+ amount))]] })}]] )
|
||||||
|
|
||||||
(defn fix-pay-function [conn]
|
(defn fix-pay-function [conn]
|
||||||
[[{:db/ident :pay
|
[[{:db/ident :pay
|
||||||
@@ -53,6 +53,24 @@
|
|||||||
:db/valueType :db.type/string
|
:db/valueType :db.type/string
|
||||||
:db/cardinality :db.cardinality/one}]])
|
:db/cardinality :db.cardinality/one}]])
|
||||||
|
|
||||||
|
(defn reset-function [conn]
|
||||||
|
[[{:db/ident :reset
|
||||||
|
:db/doc "Resets a relationship to the values specified "
|
||||||
|
:db/fn (d/function '{:lang "clojure"
|
||||||
|
:params [db e a vs]
|
||||||
|
:code (let [ids (when-not (string? e)
|
||||||
|
(->> (d/query {:query {:find ['?z]
|
||||||
|
:in ['$ '?e '?a]
|
||||||
|
:where [['?e '?a '?z]]}
|
||||||
|
:args [db e a]})
|
||||||
|
(map first)))
|
||||||
|
new-id-set (set (map :db/id vs))
|
||||||
|
retract-ids (filter (complement new-id-set) ids)]
|
||||||
|
(cond-> []
|
||||||
|
true (into (map (fn [i] [:db/retractEntity i ]) retract-ids))
|
||||||
|
(seq vs) (conj {:db/id e
|
||||||
|
a vs})))})}]])
|
||||||
|
|
||||||
(defn -main [& args]
|
(defn -main [& args]
|
||||||
(println "Creating database ..." uri)
|
(println "Creating database ..." uri)
|
||||||
(doto (d/create-database uri) println)
|
(doto (d/create-database uri) println)
|
||||||
@@ -174,7 +192,7 @@
|
|||||||
:db/doc "Overrides per-client"
|
:db/doc "Overrides per-client"
|
||||||
:db/valueType :db.type/ref
|
:db/valueType :db.type/ref
|
||||||
:db/cardinality :db.cardinality/many}]]}
|
:db/cardinality :db.cardinality/many}]]}
|
||||||
}]
|
:auto-ap/add-reset-rels {:txes-fn `reset-function}}]
|
||||||
(println "Conforming database...")
|
(println "Conforming database...")
|
||||||
(c/ensure-conforms conn norms-map)
|
(c/ensure-conforms conn norms-map)
|
||||||
(when (not (seq args))
|
(when (not (seq args))
|
||||||
|
|||||||
@@ -39,11 +39,25 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn terms-for-client-id [vendor client-id]
|
(defn terms-for-client-id [vendor client-id]
|
||||||
(->>
|
(or
|
||||||
(filter
|
(->>
|
||||||
(fn [to]
|
(filter
|
||||||
(= (:db/id (:vendor-terms-override/client to))
|
(fn [to]
|
||||||
client-id))
|
(= (:db/id (:vendor-terms-override/client to))
|
||||||
(:vendor/terms-overrides vendor))
|
client-id))
|
||||||
first
|
(:vendor/terms-overrides vendor))
|
||||||
:vendor-terms-override/terms))
|
first
|
||||||
|
:vendor-terms-override/terms)
|
||||||
|
(:vendor/terms vendor)))
|
||||||
|
|
||||||
|
(defn account-for-client-id [vendor client-id]
|
||||||
|
(or
|
||||||
|
(->>
|
||||||
|
(filter
|
||||||
|
(fn [to]
|
||||||
|
(= (:db/id (:vendor-account-override/client to))
|
||||||
|
client-id))
|
||||||
|
(:vendor/account-overrides vendor))
|
||||||
|
first
|
||||||
|
:vendor-account-override/account)
|
||||||
|
(:vendor/default-account vendor)))
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
(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]
|
(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]
|
||||||
(when id
|
(when id
|
||||||
(assert-admin (:id context)))
|
(assert-admin (:id context)))
|
||||||
(let [term-overrides (mapv
|
(let [terms-overrides (mapv
|
||||||
(fn [to]
|
(fn [to]
|
||||||
(cond->
|
(cond->
|
||||||
#:vendor-terms-override {:client (:client_id to)
|
#:vendor-terms-override {:client (:client_id to)
|
||||||
@@ -25,47 +25,48 @@
|
|||||||
:account (:account_id ao)}
|
:account (:account_id ao)}
|
||||||
(:id ao) (assoc :db/id (:id ao))))
|
(:id ao) (assoc :db/id (:id ao))))
|
||||||
account_overrides)
|
account_overrides)
|
||||||
transaction [(remove-nils #:vendor {:db/id (if id
|
transaction (cond->
|
||||||
id
|
[(remove-nils #:vendor {:db/id (if id
|
||||||
"vendor")
|
id
|
||||||
:name name
|
"vendor")
|
||||||
:code code
|
:name name
|
||||||
:hidden hidden
|
:code code
|
||||||
:terms terms
|
:hidden hidden
|
||||||
:print-as print_as
|
:terms terms
|
||||||
:default-account default_account_id
|
:print-as print_as
|
||||||
:invoice-reminder-schedule (keyword invoice_reminder_schedule)
|
:default-account default_account_id
|
||||||
:term-overrides (when (is-admin? (:id context))
|
:invoice-reminder-schedule (keyword invoice_reminder_schedule)
|
||||||
term-overrides)
|
|
||||||
:account-overrides (when (is-admin? (:id context))
|
|
||||||
account-overrides)
|
:address (when address
|
||||||
:address (when address
|
(remove-nils #:address {:db/id (if (:id address)
|
||||||
(remove-nils #:address {:db/id (if (:id address)
|
(:id address)
|
||||||
(:id address)
|
"address")
|
||||||
"address")
|
:street1 (:street1 address)
|
||||||
:street1 (:street1 address)
|
:street2 (:street2 address)
|
||||||
:street2 (:street2 address)
|
:city (:city address)
|
||||||
:city (:city address)
|
:state (:state address)
|
||||||
:state (:state address)
|
:zip (:zip address)}))
|
||||||
:zip (:zip address)}))
|
:primary-contact (when primary_contact
|
||||||
:primary-contact (when primary_contact
|
|
||||||
|
|
||||||
(remove-nils #:contact {:db/id (if (:id primary_contact)
|
(remove-nils #:contact {:db/id (if (:id primary_contact)
|
||||||
(:id primary_contact)
|
(:id primary_contact)
|
||||||
"primary")
|
"primary")
|
||||||
:name (:name primary_contact)
|
:name (:name primary_contact)
|
||||||
:phone (:phone primary_contact)
|
:phone (:phone primary_contact)
|
||||||
:email (:email primary_contact)}))
|
:email (:email primary_contact)}))
|
||||||
|
|
||||||
:secondary-contact (when secondary_contact
|
:secondary-contact (when secondary_contact
|
||||||
|
|
||||||
(remove-nils #:contact {:db/id (if (:id secondary_contact)
|
(remove-nils #:contact {:db/id (if (:id secondary_contact)
|
||||||
(:id secondary_contact)
|
(:id secondary_contact)
|
||||||
"secondary")
|
"secondary")
|
||||||
:name (:name secondary_contact)
|
:name (:name secondary_contact)
|
||||||
:phone (:phone secondary_contact)
|
:phone (:phone secondary_contact)
|
||||||
:email (:email secondary_contact)})
|
:email (:email secondary_contact)})
|
||||||
)})]
|
)})]
|
||||||
|
(is-admin? (:id context)) (conj [:reset (if id id "vendor") :vendor/account-overrides account-overrides])
|
||||||
|
(is-admin? (:id context)) (conj [:reset (if id id "vendor") :vendor/terms-overrides terms-overrides]))
|
||||||
transaction-result @(d/transact (d/connect uri) transaction)]
|
transaction-result @(d/transact (d/connect uri) transaction)]
|
||||||
|
|
||||||
(-> (d-vendors/get-by-id (or (-> transaction-result :tempids (get "vendor"))
|
(-> (d-vendors/get-by-id (or (-> transaction-result :tempids (get "vendor"))
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn template-applies? [text {:keys [keywords]}]
|
(defn template-applies? [text {:keys [keywords]}]
|
||||||
(println text)
|
|
||||||
(every? #(re-find % text) keywords))
|
(every? #(re-find % text) keywords))
|
||||||
|
|
||||||
(defn extract-template
|
(defn extract-template
|
||||||
|
|||||||
@@ -11,7 +11,9 @@
|
|||||||
[auto-ap.parse.util :as parse-u]
|
[auto-ap.parse.util :as parse-u]
|
||||||
[auto-ap.graphql.utils :refer [assert-admin]]
|
[auto-ap.graphql.utils :refer [assert-admin]]
|
||||||
[auto-ap.routes.utils :refer [wrap-secure]]
|
[auto-ap.routes.utils :refer [wrap-secure]]
|
||||||
[clj-time.coerce :refer [to-date]]
|
|
||||||
|
[clj-time.core :as time]
|
||||||
|
[clj-time.coerce :as coerce :refer [to-date]]
|
||||||
[ring.middleware.json :refer [wrap-json-response]]
|
[ring.middleware.json :refer [wrap-json-response]]
|
||||||
[compojure.core :refer [GET POST context defroutes
|
[compojure.core :refer [GET POST context defroutes
|
||||||
wrap-routes]]
|
wrap-routes]]
|
||||||
@@ -126,26 +128,28 @@
|
|||||||
(defn invoice-rows->transaction [rows]
|
(defn invoice-rows->transaction [rows]
|
||||||
(->> rows
|
(->> rows
|
||||||
(mapcat (fn [{:keys [vendor-id total client-id amount date invoice-number default-location account-id check vendor]}]
|
(mapcat (fn [{:keys [vendor-id total client-id amount date invoice-number default-location account-id check vendor]}]
|
||||||
(println account-id vendor)
|
(let [invoice (cond->
|
||||||
(let [invoice #:invoice {:db/id (.toString (java.util.UUID/randomUUID))
|
#:invoice {:db/id (.toString (java.util.UUID/randomUUID))
|
||||||
:vendor vendor-id
|
:vendor vendor-id
|
||||||
:client client-id
|
:client client-id
|
||||||
:default-location default-location
|
:default-location default-location
|
||||||
:import-status :import-status/imported
|
:import-status :import-status/imported
|
||||||
#_#_:default-expense-account default-expense-account
|
#_#_:default-expense-account default-expense-account
|
||||||
:total total
|
:total total
|
||||||
:outstanding-balance (if (= "Cash" check)
|
:outstanding-balance (if (= "Cash" check)
|
||||||
0.0
|
0.0
|
||||||
total)
|
total)
|
||||||
:status (if (= "Cash" check)
|
:status (if (= "Cash" check)
|
||||||
:invoice-status/paid
|
:invoice-status/paid
|
||||||
:invoice-status/unpaid)
|
:invoice-status/unpaid)
|
||||||
:invoice-number invoice-number
|
:invoice-number invoice-number
|
||||||
:date (to-date date)
|
:date (to-date date)
|
||||||
:expense-accounts [#:invoice-expense-account {:account (or account-id
|
:expense-accounts [#:invoice-expense-account {:account (or account-id
|
||||||
(-> vendor :vendor/default-account :db/id))
|
(:db/id (d-vendors/account-for-client-id vendor client-id)))
|
||||||
:location default-location
|
:location default-location
|
||||||
:amount total}]}
|
:amount total}]}
|
||||||
|
(:vendor/terms vendor) (assoc :invoice/due (coerce/to-date
|
||||||
|
(time/plus date (time/days (d-vendors/terms-for-client-id vendor client-id))))))
|
||||||
payment (if (= :invoice-status/paid (:invoice/status invoice))
|
payment (if (= :invoice-status/paid (:invoice/status invoice))
|
||||||
#:invoice-payment {:invoice (:db/id invoice)
|
#:invoice-payment {:invoice (:db/id invoice)
|
||||||
:amount (:invoice/total invoice)
|
:amount (:invoice/total invoice)
|
||||||
|
|||||||
Reference in New Issue
Block a user