Makes beginning of new invoice
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
(defn get-all-graphql [context args _]
|
||||
(assert-admin (:id context))
|
||||
(let [args (assoc args :id (:id context))
|
||||
[accounts _ ] (d-accounts/get-graphql (assoc (<-graphql args) :per-page Integer/MAX_VALUE))]
|
||||
[accounts _] (d-accounts/get-graphql (assoc (<-graphql args) :per-page Integer/MAX_VALUE))]
|
||||
(map ->graphql accounts)))
|
||||
|
||||
(defn default-for-vendor [context args _]
|
||||
@@ -31,34 +31,32 @@
|
||||
(->graphql (d-accounts/clientize result (:client_id args)))))
|
||||
|
||||
(def search-pattern [:db/id
|
||||
:account/numeric-code
|
||||
:account/location
|
||||
{:account/vendor-allowance [:db/ident]
|
||||
:account/default-allowance [:db/ident]
|
||||
:account/invoice-allowance [:db/ident]}])
|
||||
:account/numeric-code
|
||||
:account/location
|
||||
{:account/vendor-allowance [:db/ident]
|
||||
:account/default-allowance [:db/ident]
|
||||
:account/invoice-allowance [:db/ident]}])
|
||||
(defn search- [id query client]
|
||||
(let [client-part (if (some->> client (can-see-client? id))
|
||||
(format "((applicability:(global OR optional) AND -client_id:*) OR (account_client_override_id:* AND client_id:%s))" client)
|
||||
"(applicability:(global OR optional) AND -client_id:*)"
|
||||
|
||||
)
|
||||
"(applicability:(global OR optional) AND -client_id:*)")
|
||||
query (format "_text_:(%s) AND %s" (cleanse-query query) client-part)]
|
||||
(mu/log ::searching :search-query query)
|
||||
(for [{:keys [account_id name] :as g} (solr/query solr/impl "accounts"
|
||||
{"query" query
|
||||
"fields" "id, name, client_id, numeric_code, applicability, account_id"})]
|
||||
|
||||
{"query" query
|
||||
"fields" "id, name, client_id, numeric_code, applicability, account_id"})]
|
||||
|
||||
{:account_id (first account_id)
|
||||
:name (first name)})))
|
||||
:name (first name)})))
|
||||
|
||||
(defn search [context {query :query client :client_id allowance :allowance vendor-id :vendor_id} _]
|
||||
(when client
|
||||
(assert-can-see-client (:id context) client))
|
||||
(let [num (some-> (re-find #"([0-9]+)" query)
|
||||
second
|
||||
(not-empty )
|
||||
(not-empty)
|
||||
Integer/parseInt)
|
||||
|
||||
|
||||
valid-allowances (cond-> #{:allowance/allowed
|
||||
:allowance/warn}
|
||||
(is-admin? (:id context)) (conj :allowance/admin-only))
|
||||
@@ -71,77 +69,76 @@
|
||||
|
||||
vendor-account (when vendor-id
|
||||
(-> (dc/q '[:find ?da
|
||||
:in $ ?v
|
||||
:where [?v :vendor/default-account ?da]]
|
||||
(dc/db conn)
|
||||
vendor-id)
|
||||
:in $ ?v
|
||||
:where [?v :vendor/default-account ?da]]
|
||||
(dc/db conn)
|
||||
vendor-id)
|
||||
ffirst))
|
||||
xform (comp
|
||||
(filter (fn [[_ a]]
|
||||
(or
|
||||
(valid-allowances (-> a allowance :db/ident))
|
||||
(= (:db/id a) vendor-account))))
|
||||
(map (fn [[n a]]
|
||||
{:name (str (:account/numeric-code a) " - " n)
|
||||
:id (:db/id a)
|
||||
:location (:account/location a)
|
||||
:warning (when (= :allowance/warn (-> a allowance :db/ident))
|
||||
"This account is not typically used for this purpose.")})))]
|
||||
(if query
|
||||
(filter (fn [[_ a]]
|
||||
(or
|
||||
(valid-allowances (-> a allowance :db/ident))
|
||||
(= (:db/id a) vendor-account))))
|
||||
(map (fn [[n a]]
|
||||
{:name (str (:account/numeric-code a) " - " n)
|
||||
:id (:db/id a)
|
||||
:location (:account/location a)
|
||||
:warning (when (= :allowance/warn (-> a allowance :db/ident))
|
||||
"This account is not typically used for this purpose.")})))]
|
||||
(if query
|
||||
(if num
|
||||
(->> (dc/q '[:find ?n (pull ?i pattern)
|
||||
:in $ ?numeric-code ?allowance pattern
|
||||
:where [?i :account/numeric-code ?numeric-code]
|
||||
[?i :account/name ?n]
|
||||
(or [?i :account/applicability :account-applicability/global]
|
||||
[?i :account/applicability :account-applicability/optional]
|
||||
[?i :account/applicability :account-applicability/customized])]
|
||||
(dc/db conn)
|
||||
num
|
||||
allowance
|
||||
search-pattern)
|
||||
:in $ ?numeric-code ?allowance pattern
|
||||
:where [?i :account/numeric-code ?numeric-code]
|
||||
[?i :account/name ?n]
|
||||
(or [?i :account/applicability :account-applicability/global]
|
||||
[?i :account/applicability :account-applicability/optional]
|
||||
[?i :account/applicability :account-applicability/customized])]
|
||||
(dc/db conn)
|
||||
num
|
||||
allowance
|
||||
search-pattern)
|
||||
(sequence xform))
|
||||
(->> (search- (:id context) query client)
|
||||
(sequence
|
||||
(comp (map (fn [i] [(:name i) (dc/pull (dc/db conn) search-pattern (:account_id i))]))
|
||||
xform))))
|
||||
(comp (map (fn [i] [(:name i) (dc/pull (dc/db conn) search-pattern (:account_id i))]))
|
||||
xform))))
|
||||
[])))
|
||||
|
||||
(defn rebuild-search-index []
|
||||
(solr/index-documents-raw
|
||||
solr/impl
|
||||
"accounts"
|
||||
(for [result (map first (dc/qseq {:query '[:find (pull ?aco [:account-client-override/search-terms :account-client-override/client :db/id {:account/_client-overrides [:account/numeric-code :account/location :db/id {:account/applicability [:db/ident]}]}])
|
||||
:in $
|
||||
:where [?aco :account-client-override/client ]
|
||||
[?aco :account-client-override/search-terms ]
|
||||
[_ :account/client-overrides ?aco]]
|
||||
:args [(dc/db conn)]}))
|
||||
:when (:account/numeric-code (:account/_client-overrides result))]
|
||||
{"id" (:db/id result)
|
||||
"account_id" (:db/id (:account/_client-overrides result))
|
||||
"account_client_override_id" (str (:db/id result))
|
||||
"name" (:account-client-override/search-terms result)
|
||||
"client_id" (str (:db/id (:account-client-override/client result)))
|
||||
"numeric_code" (:account/numeric-code (:account/_client-overrides result))
|
||||
"location" (:account/location (:account/_client-overrides result))
|
||||
"applicability" (name (:db/ident (:account/applicability (:account/_client-overrides result))))}))
|
||||
solr/impl
|
||||
"accounts"
|
||||
(for [result (map first (dc/qseq {:query '[:find (pull ?aco [:account-client-override/search-terms :account-client-override/client :db/id {:account/_client-overrides [:account/numeric-code :account/location :db/id {:account/applicability [:db/ident]}]}])
|
||||
:in $
|
||||
:where [?aco :account-client-override/client]
|
||||
[?aco :account-client-override/search-terms]
|
||||
[_ :account/client-overrides ?aco]]
|
||||
:args [(dc/db conn)]}))
|
||||
:when (:account/numeric-code (:account/_client-overrides result))]
|
||||
{"id" (:db/id result)
|
||||
"account_id" (:db/id (:account/_client-overrides result))
|
||||
"account_client_override_id" (str (:db/id result))
|
||||
"name" (:account-client-override/search-terms result)
|
||||
"client_id" (str (:db/id (:account-client-override/client result)))
|
||||
"numeric_code" (:account/numeric-code (:account/_client-overrides result))
|
||||
"location" (:account/location (:account/_client-overrides result))
|
||||
"applicability" (name (:db/ident (:account/applicability (:account/_client-overrides result))))}))
|
||||
(solr/index-documents-raw
|
||||
solr/impl
|
||||
"accounts"
|
||||
(for [result (map first (dc/qseq {:query '[:find (pull ?a [:account/numeric-code
|
||||
:account/search-terms
|
||||
{:account/applicability [:db/ident]}
|
||||
:db/id
|
||||
:account/location])
|
||||
:in $
|
||||
:where [?a :account/search-terms ]]
|
||||
:args [(dc/db conn)]}))
|
||||
:when (:account/search-terms result)
|
||||
]
|
||||
{"id" (:db/id result)
|
||||
"account_id" (:db/id result)
|
||||
"name" (:account/search-terms result)
|
||||
"numeric_code" (:account/numeric-code result)
|
||||
"location" (:account/location result)
|
||||
"applicability" (name (:db/ident (:account/applicability result)))})))
|
||||
solr/impl
|
||||
"accounts"
|
||||
(for [result (map first (dc/qseq {:query '[:find (pull ?a [:account/numeric-code
|
||||
:account/search-terms
|
||||
{:account/applicability [:db/ident]}
|
||||
:db/id
|
||||
:account/location])
|
||||
:in $
|
||||
:where [?a :account/search-terms]]
|
||||
:args [(dc/db conn)]}))
|
||||
:when (:account/search-terms result)]
|
||||
{"id" (:db/id result)
|
||||
"account_id" (:db/id result)
|
||||
"name" (:account/search-terms result)
|
||||
"numeric_code" (:account/numeric-code result)
|
||||
"location" (:account/location result)
|
||||
"applicability" (name (:db/ident (:account/applicability result)))})))
|
||||
@@ -21,18 +21,18 @@
|
||||
|
||||
(defn can-user-edit-vendor? [vendor-id id]
|
||||
(if (is-admin? id)
|
||||
true
|
||||
(empty?
|
||||
(set/difference (set (->> (dc/q '[:find ?c
|
||||
:in $ ?v
|
||||
:where [?vu :vendor-usage/vendor ?v]
|
||||
[?vu :vendor-usage/client ?c]
|
||||
[?vu :vendor-usage/count ?d]
|
||||
[(>= ?d 0)]]
|
||||
(dc/db conn)
|
||||
vendor-id)
|
||||
(map first)))
|
||||
(set (map :db/id (:user/clients id)))))))
|
||||
true
|
||||
(empty?
|
||||
(set/difference (set (->> (dc/q '[:find ?c
|
||||
:in $ ?v
|
||||
:where [?vu :vendor-usage/vendor ?v]
|
||||
[?vu :vendor-usage/client ?c]
|
||||
[?vu :vendor-usage/count ?d]
|
||||
[(>= ?d 0)]]
|
||||
(dc/db conn)
|
||||
vendor-id)
|
||||
(map first)))
|
||||
(set (map :db/id (:user/clients id)))))))
|
||||
|
||||
(defn upsert-vendor [context {{:keys [id name hidden terms code print_as primary_contact plaid_merchant secondary_contact address default_account_id invoice_reminder_schedule schedule_payment_dom terms_overrides account_overrides] :as in} :vendor} _]
|
||||
(when (and id (not (can-user-edit-vendor? id (:id context))))
|
||||
@@ -63,11 +63,11 @@
|
||||
hidden
|
||||
false)
|
||||
terms-overrides (mapv
|
||||
(fn [to]
|
||||
#:vendor-terms-override {:client (:client_id to)
|
||||
:terms (:terms to)
|
||||
:db/id (or (:id to) (random-tempid))})
|
||||
terms_overrides)
|
||||
(fn [to]
|
||||
#:vendor-terms-override {:client (:client_id to)
|
||||
:terms (:terms to)
|
||||
:db/id (or (:id to) (random-tempid))})
|
||||
terms_overrides)
|
||||
account-overrides (mapv
|
||||
(fn [ao]
|
||||
#:vendor-account-override {:client (:client_id ao)
|
||||
@@ -75,11 +75,11 @@
|
||||
:db/id (or (:id ao) (random-tempid))})
|
||||
account_overrides)
|
||||
schedule-payment-dom (mapv
|
||||
(fn [ao]
|
||||
#:vendor-schedule-payment-dom {:client (:client_id ao)
|
||||
:dom (:dom ao)
|
||||
:db/id (or (:id ao) (random-tempid))})
|
||||
schedule_payment_dom)
|
||||
(fn [ao]
|
||||
#:vendor-schedule-payment-dom {:client (:client_id ao)
|
||||
:dom (:dom ao)
|
||||
:db/id (or (:id ao) (random-tempid))})
|
||||
schedule_payment_dom)
|
||||
transaction [:upsert-entity (cond-> #:vendor {:db/id (if id
|
||||
id
|
||||
"vendor")
|
||||
@@ -114,41 +114,40 @@
|
||||
"secondary")
|
||||
:name (:name secondary_contact)
|
||||
:phone (:phone secondary_contact)
|
||||
:email (:email secondary_contact)})
|
||||
)
|
||||
:email (:email secondary_contact)}))
|
||||
:search-terms [name]}
|
||||
(is-admin? (:id context)) (assoc
|
||||
:vendor/legal-entity-name (:legal_entity_name in)
|
||||
:vendor/legal-entity-first-name (:legal_entity_first_name in)
|
||||
:vendor/legal-entity-middle-name (:legal_entity_middle_name in)
|
||||
:vendor/legal-entity-last-name (:legal_entity_last_name in)
|
||||
:vendor/legal-entity-tin (:legal_entity_tin in)
|
||||
:vendor/legal-entity-tin-type (enum->keyword (:legal_entity_tin_type in) "legal-entity-tin-type")
|
||||
:vendor/legal-entity-1099-type (enum->keyword (:legal_entity_1099_type in) "legal-entity-1099-type")
|
||||
:vendor/plaid-merchant plaid_merchant
|
||||
:vendor/account-overrides account-overrides
|
||||
:vendor/terms-overrides terms-overrides
|
||||
:vendor/schedule-payment-dom schedule-payment-dom
|
||||
:vendor/automatically-paid-when-due (:automatically_paid_when_due in)))]
|
||||
:vendor/legal-entity-name (:legal_entity_name in)
|
||||
:vendor/legal-entity-first-name (:legal_entity_first_name in)
|
||||
:vendor/legal-entity-middle-name (:legal_entity_middle_name in)
|
||||
:vendor/legal-entity-last-name (:legal_entity_last_name in)
|
||||
:vendor/legal-entity-tin (:legal_entity_tin in)
|
||||
:vendor/legal-entity-tin-type (enum->keyword (:legal_entity_tin_type in) "legal-entity-tin-type")
|
||||
:vendor/legal-entity-1099-type (enum->keyword (:legal_entity_1099_type in) "legal-entity-1099-type")
|
||||
:vendor/plaid-merchant plaid_merchant
|
||||
:vendor/account-overrides account-overrides
|
||||
:vendor/terms-overrides terms-overrides
|
||||
:vendor/schedule-payment-dom schedule-payment-dom
|
||||
:vendor/automatically-paid-when-due (:automatically_paid_when_due in)))]
|
||||
|
||||
|
||||
|
||||
transaction-result (audit-transact [transaction] (:id context))
|
||||
new-vendor (d-vendors/get-by-id (or (-> transaction-result :tempids (get "vendor"))
|
||||
id))]
|
||||
|
||||
|
||||
(auto-ap.solr/index-documents-raw
|
||||
auto-ap.solr/impl
|
||||
"vendors"
|
||||
[{"id" (:db/id new-vendor)
|
||||
"name" (:vendor/name new-vendor)
|
||||
"hidden" (boolean (:vendor/hidden new-vendor))}])
|
||||
|
||||
auto-ap.solr/impl
|
||||
"vendors"
|
||||
[{"id" (:db/id new-vendor)
|
||||
"name" (:vendor/name new-vendor)
|
||||
"hidden" (boolean (:vendor/hidden new-vendor))}])
|
||||
|
||||
(-> new-vendor
|
||||
(->graphql))))
|
||||
|
||||
(defn merge-vendors [context {:keys [from to]} _]
|
||||
(let [transaction (->> (dc/q {:find '[?x ?a2]
|
||||
:in '[$ ?vendor-from ]
|
||||
:in '[$ ?vendor-from]
|
||||
:where ['[?x ?a ?vendor-from]
|
||||
'[?a :db/ident ?a2]]}
|
||||
(dc/db conn)
|
||||
@@ -165,13 +164,13 @@
|
||||
(defn get-graphql [context args _]
|
||||
(assert-admin (:id context))
|
||||
(let [args (assoc args :id (:id context))
|
||||
[vendors vendors-count ] (d-vendors/get-graphql (<-graphql args))]
|
||||
[vendors vendors-count] (d-vendors/get-graphql (<-graphql args))]
|
||||
(result->page vendors vendors-count :vendors args)))
|
||||
|
||||
(defn get-by-id [context args _]
|
||||
(->graphql
|
||||
(d-vendors/get-graphql-by-id (assoc args :id (:id context))
|
||||
(:id args))))
|
||||
(d-vendors/get-graphql-by-id (assoc args :id (:id context))
|
||||
(:id args))))
|
||||
|
||||
(defn partial-match-first [query matches]
|
||||
(if-let [best-match (->> matches
|
||||
@@ -187,7 +186,7 @@
|
||||
(defn search [context args _]
|
||||
(if-let [query (not-empty (cleanse-query (:query args)))]
|
||||
(let [search-query (str "name:(" query ")")]
|
||||
|
||||
|
||||
|
||||
(for [{:keys [id name]} (solr/query solr/impl "vendors" {"query" (cond-> search-query
|
||||
(not (is-admin? (:id context))) (str " hidden:false"))
|
||||
@@ -210,4 +209,4 @@
|
||||
:args [(dc/db conn)]})]
|
||||
{"id" (:db/id result)
|
||||
"name" (:vendor/name result)
|
||||
"hidden" (boolean (:vendor/hidden result))}))))
|
||||
"hidden" (boolean (:vendor/hidden result))}))))
|
||||
Reference in New Issue
Block a user