makes cloud search possible.
This commit is contained in:
@@ -39,119 +39,129 @@
|
||||
([args] (raw-graphql-ids (dc/db conn) args))
|
||||
([db args]
|
||||
(let [check-number-like (try (Long/parseLong (:check-number-like args)) (catch Exception _ nil))
|
||||
query (cond-> {:query {:find []
|
||||
:in ['$]
|
||||
:where []}
|
||||
:args [db]}
|
||||
(:sort args) (add-sorter-fields {"client" ['[?e :payment/client ?c]
|
||||
'[?c :client/name ?sort-client]]
|
||||
"vendor" ['[?e :payment/vendor ?v]
|
||||
'[?v :vendor/name ?sort-vendor]]
|
||||
"bank-account" ['[?e :payment/bank-account ?ba]
|
||||
'[?ba :bank-account/name ?sort-bank-account]]
|
||||
"check-number" ['[(get-else $ ?e :payment/check-number 0) ?sort-check-number]]
|
||||
"date" ['[?e :payment/date ?sort-date]]
|
||||
"amount" ['[?e :payment/amount ?sort-amount]]
|
||||
"status" ['[?e :payment/status ?sort-status]]}
|
||||
args)
|
||||
(:exact-match-id args)
|
||||
(merge-query {:query {:in ['?e]
|
||||
:where []}
|
||||
:args [(:exact-match-id args)]})
|
||||
query (if (:exact-match-id args)
|
||||
(cond-> {:query {:find '[?e]
|
||||
:in '[$ ?e]
|
||||
:where '[[?e :payment/client ?c]]}
|
||||
:args [db
|
||||
(:exact-match-id args)]}
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :payment/client ?xx]]}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]}))
|
||||
(cond-> {:query {:find []
|
||||
:in ['$]
|
||||
:where []}
|
||||
:args [db]}
|
||||
(:sort args) (add-sorter-fields {"client" ['[?e :payment/client ?c]
|
||||
'[?c :client/name ?sort-client]]
|
||||
"vendor" ['[?e :payment/vendor ?v]
|
||||
'[?v :vendor/name ?sort-vendor]]
|
||||
"bank-account" ['[?e :payment/bank-account ?ba]
|
||||
'[?ba :bank-account/name ?sort-bank-account]]
|
||||
"check-number" ['[(get-else $ ?e :payment/check-number 0) ?sort-check-number]]
|
||||
"date" ['[?e :payment/date ?sort-date]]
|
||||
"amount" ['[?e :payment/amount ?sort-amount]]
|
||||
"status" ['[?e :payment/status ?sort-status]]}
|
||||
args)
|
||||
(:exact-match-id args)
|
||||
(merge-query {:query {:in ['?e]
|
||||
:where []}
|
||||
:args [(:exact-match-id args)]})
|
||||
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :payment/client ?xx]]}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
||||
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :payment/client ?xx]]}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
||||
|
||||
|
||||
(:client-id args)
|
||||
(merge-query {:query {:in ['?client-id]
|
||||
:where ['[?e :payment/client ?client-id]]}
|
||||
:args [(:client-id args)]})
|
||||
(:client-code args)
|
||||
(merge-query {:query {:in ['?client-code]
|
||||
:where ['[?e :payment/client ?client-id]
|
||||
'[?client-id :client/code ?client-code]]}
|
||||
:args [(:client-code args)]})
|
||||
(:client-id args)
|
||||
(merge-query {:query {:in ['?client-id]
|
||||
:where ['[?e :payment/client ?client-id]]}
|
||||
:args [(:client-id args)]})
|
||||
(:client-code args)
|
||||
(merge-query {:query {:in ['?client-code]
|
||||
:where ['[?e :payment/client ?client-id]
|
||||
'[?client-id :client/code ?client-code]]}
|
||||
:args [(:client-code args)]})
|
||||
|
||||
|
||||
(:vendor-id args)
|
||||
(merge-query {:query {:in ['?vendor-id]
|
||||
:where ['[?e :payment/vendor ?vendor-id]]}
|
||||
:args [(:vendor-id args)]})
|
||||
|
||||
(:vendor-id args)
|
||||
(merge-query {:query {:in ['?vendor-id]
|
||||
:where ['[?e :payment/vendor ?vendor-id]]}
|
||||
:args [(:vendor-id args)]})
|
||||
|
||||
(:original-id args)
|
||||
(merge-query {:query {:in ['?original-id]
|
||||
:where ['[?e :payment/client ?c]
|
||||
'[?c :client/original-id ?original-id]]}
|
||||
:args [(:original-id args)]})
|
||||
(:original-id args)
|
||||
(merge-query {:query {:in ['?original-id]
|
||||
:where ['[?e :payment/client ?c]
|
||||
'[?c :client/original-id ?original-id]]}
|
||||
:args [(:original-id args)]})
|
||||
|
||||
(:check-number args)
|
||||
(merge-query {:query {:in ['?check-number]
|
||||
:where ['[?e :payment/check-number ?check-number]]}
|
||||
:args [(:check-number args)]})
|
||||
(:check-number args)
|
||||
(merge-query {:query {:in ['?check-number]
|
||||
:where ['[?e :payment/check-number ?check-number]]}
|
||||
:args [(:check-number args)]})
|
||||
|
||||
(not-empty (:invoice-number args))
|
||||
(merge-query {:query {:in ['?invoice-number]
|
||||
:where ['[?e :payment/invoices ?i]
|
||||
'[?i :invoice/invoice-number ?invoice-number]]}
|
||||
:args [(:invoice-number args)]})
|
||||
(not-empty (:invoice-number args))
|
||||
(merge-query {:query {:in ['?invoice-number]
|
||||
:where ['[?e :payment/invoices ?i]
|
||||
'[?i :invoice/invoice-number ?invoice-number]]}
|
||||
:args [(:invoice-number args)]})
|
||||
|
||||
(:bank-account-id args)
|
||||
(merge-query {:query {:in ['?bank-account-id]
|
||||
:where ['[?e :payment/bank-account ?bank-account-id]]}
|
||||
:args [(:bank-account-id args)]})
|
||||
(:bank-account-id args)
|
||||
(merge-query {:query {:in ['?bank-account-id]
|
||||
:where ['[?e :payment/bank-account ?bank-account-id]]}
|
||||
:args [(:bank-account-id args)]})
|
||||
|
||||
(:amount-gte args)
|
||||
(merge-query {:query {:in ['?amount-gte]
|
||||
:where ['[?e :payment/amount ?a]
|
||||
'[(>= ?a ?amount-gte)]]}
|
||||
:args [(:amount-gte args)]})
|
||||
(:amount-gte args)
|
||||
(merge-query {:query {:in ['?amount-gte]
|
||||
:where ['[?e :payment/amount ?a]
|
||||
'[(>= ?a ?amount-gte)]]}
|
||||
:args [(:amount-gte args)]})
|
||||
|
||||
(:amount-lte args)
|
||||
(merge-query {:query {:in ['?amount-lte]
|
||||
:where ['[?e :payment/amount ?a]
|
||||
'[(<= ?a ?amount-lte)]]}
|
||||
:args [(:amount-lte args)]})
|
||||
(:amount-lte args)
|
||||
(merge-query {:query {:in ['?amount-lte]
|
||||
:where ['[?e :payment/amount ?a]
|
||||
'[(<= ?a ?amount-lte)]]}
|
||||
:args [(:amount-lte args)]})
|
||||
|
||||
(:amount args)
|
||||
(merge-query {:query {:in ['?amount]
|
||||
:where ['[?e :payment/amount ?transaction-amount]
|
||||
'[(iol-ion.query/dollars= ?transaction-amount ?amount)]]}
|
||||
:args [(:amount args)]})
|
||||
(:amount args)
|
||||
(merge-query {:query {:in ['?amount]
|
||||
:where ['[?e :payment/amount ?transaction-amount]
|
||||
'[(iol-ion.query/dollars= ?transaction-amount ?amount)]]}
|
||||
:args [(:amount args)]})
|
||||
|
||||
|
||||
(:status args)
|
||||
(merge-query {:query {:in ['?status]
|
||||
:where ['[?e :payment/status ?status]]}
|
||||
:args [(:status args)]})
|
||||
|
||||
(:start (:date-range args))
|
||||
(merge-query {:query {:in '[?start-date]
|
||||
:where ['[?e :payment/date ?date]
|
||||
'[(>= ?date ?start-date)]]}
|
||||
:args [(c/to-date (:start (:date-range args)))]})
|
||||
|
||||
(:status args)
|
||||
(merge-query {:query {:in ['?status]
|
||||
:where ['[?e :payment/status ?status]]}
|
||||
:args [(:status args)]})
|
||||
|
||||
(:start (:date-range args))
|
||||
(merge-query {:query {:in '[?start-date]
|
||||
:where ['[?e :payment/date ?date]
|
||||
'[(>= ?date ?start-date)]]}
|
||||
:args [(c/to-date (:start (:date-range args)))]})
|
||||
|
||||
(:end (:date-range args))
|
||||
(merge-query {:query {:in '[?end-date]
|
||||
:where ['[?e :payment/date ?date]
|
||||
'[(<= ?date ?end-date)]]}
|
||||
:args [(c/to-date (:end (:date-range args)))]})
|
||||
(:end (:date-range args))
|
||||
(merge-query {:query {:in '[?end-date]
|
||||
:where ['[?e :payment/date ?date]
|
||||
'[(<= ?date ?end-date)]]}
|
||||
:args [(c/to-date (:end (:date-range args)))]})
|
||||
|
||||
(:payment-type args)
|
||||
(merge-query {:query {:in '[?payment-type]
|
||||
:where ['[?e :payment/type ?payment-type]]}
|
||||
:args [(:payment-type args)]})
|
||||
(:payment-type args)
|
||||
(merge-query {:query {:in '[?payment-type]
|
||||
:where ['[?e :payment/type ?payment-type]]}
|
||||
:args [(:payment-type args)]})
|
||||
|
||||
check-number-like
|
||||
(merge-query {:query {:in '[?check-number-like]
|
||||
:where ['[?e :payment/check-number ?check-number-like]]}
|
||||
:args [check-number-like]})
|
||||
check-number-like
|
||||
(merge-query {:query {:in '[?check-number-like]
|
||||
:where ['[?e :payment/check-number ?check-number-like]]}
|
||||
:args [check-number-like]})
|
||||
|
||||
true
|
||||
(merge-query {:query {:find ['?sort-default '?e]
|
||||
:where ['[?e :payment/date ?sort-default]]}}))]
|
||||
true
|
||||
(merge-query {:query {:find ['?sort-default '?e]
|
||||
:where ['[?e :payment/date ?sort-default]]}})))]
|
||||
|
||||
|
||||
(log/info query)
|
||||
|
||||
@@ -46,131 +46,138 @@
|
||||
([args]
|
||||
(raw-graphql-ids (dc/db conn) args))
|
||||
([db args]
|
||||
(let [query (cond-> {:query {:find []
|
||||
:in ['$]
|
||||
:where ['[?e :invoice/client]]}
|
||||
:args [db]}
|
||||
(let [query
|
||||
(if (:exact-match-id args)
|
||||
(cond-> {:query {:find '[?e]
|
||||
:in '[$ ?e]
|
||||
:where '[[?e :invoice/client ?c]]}
|
||||
:args [db
|
||||
(:exact-match-id args)]}
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :invoice/client ?xx]]}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]}))
|
||||
(cond-> {:query {:find []
|
||||
:in ['$]
|
||||
:where ['[?e :invoice/client]]}
|
||||
:args [db]}
|
||||
|
||||
(:exact-match-id args)
|
||||
(merge-query {:query {:in ['?e]
|
||||
:where []}
|
||||
:args [(:exact-match-id args)]})
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :invoice/client ?xx]]}
|
||||
:args [ (set (map :db/id (limited-clients (:id args))))]})
|
||||
(:client-id args)
|
||||
(merge-query {:query {:in ['?client-id]
|
||||
:where ['[?e :invoice/client ?client-id]]}
|
||||
:args [ (:client-id args)]})
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :invoice/client ?xx]]}
|
||||
:args [ (set (map :db/id (limited-clients (:id args))))]})
|
||||
(:client-id args)
|
||||
(merge-query {:query {:in ['?client-id]
|
||||
:where ['[?e :invoice/client ?client-id]]}
|
||||
:args [ (:client-id args)]})
|
||||
|
||||
(:client-code args)
|
||||
(merge-query {:query {:in ['?client-code]
|
||||
:where ['[?e :invoice/client ?client-id]
|
||||
'[?client-id :client/code ?client-code]]}
|
||||
:args [ (:client-code args)]})
|
||||
(:client-code args)
|
||||
(merge-query {:query {:in ['?client-code]
|
||||
:where ['[?e :invoice/client ?client-id]
|
||||
'[?client-id :client/code ?client-code]]}
|
||||
:args [ (:client-code args)]})
|
||||
|
||||
(:original-id args)
|
||||
(merge-query {:query {:in ['?original-id]
|
||||
:where [
|
||||
'[?e :invoice/client ?c]
|
||||
'[?c :client/original-id ?original-id]]}
|
||||
:args [ (cond-> (:original-id args)
|
||||
(string? (:original-id args)) Long/parseLong )]})
|
||||
(:original-id args)
|
||||
(merge-query {:query {:in ['?original-id]
|
||||
:where [
|
||||
'[?e :invoice/client ?c]
|
||||
'[?c :client/original-id ?original-id]]}
|
||||
:args [ (cond-> (:original-id args)
|
||||
(string? (:original-id args)) Long/parseLong )]})
|
||||
|
||||
(:start (:date-range args)) (merge-query {:query {:in '[?start-date]
|
||||
(:start (:date-range args)) (merge-query {:query {:in '[?start-date]
|
||||
:where ['[?e :invoice/date ?date]
|
||||
'[(>= ?date ?start-date)]]}
|
||||
:args [(coerce/to-date (:start (:date-range args)))]})
|
||||
|
||||
(:end (:date-range args)) (merge-query {:query {:in '[?end-date]
|
||||
:where ['[?e :invoice/date ?date]
|
||||
'[(>= ?date ?start-date)]]}
|
||||
:args [(coerce/to-date (:start (:date-range args)))]})
|
||||
'[(<= ?date ?end-date)]]}
|
||||
:args [(coerce/to-date (:end (:date-range args)))]})
|
||||
|
||||
(:end (:date-range args)) (merge-query {:query {:in '[?end-date]
|
||||
:where ['[?e :invoice/date ?date]
|
||||
'[(<= ?date ?end-date)]]}
|
||||
:args [(coerce/to-date (:end (:date-range args)))]})
|
||||
(:start (:due-range args)) (merge-query {:query {:in '[?start-due]
|
||||
:where ['[?e :invoice/due ?due]
|
||||
'[(>= ?due ?start-due)]]}
|
||||
:args [(coerce/to-date (:start (:due-range args)))]})
|
||||
|
||||
(:start (:due-range args)) (merge-query {:query {:in '[?start-due]
|
||||
:where ['[?e :invoice/due ?due]
|
||||
'[(>= ?due ?start-due)]]}
|
||||
:args [(coerce/to-date (:start (:due-range args)))]})
|
||||
(:end (:due-range args)) (merge-query {:query {:in '[?end-due]
|
||||
:where ['[?e :invoice/due ?due]
|
||||
'[(<= ?due ?end-due)]]}
|
||||
:args [(coerce/to-date (:end (:due-range args)))]})
|
||||
|
||||
(:end (:due-range args)) (merge-query {:query {:in '[?end-due]
|
||||
:where ['[?e :invoice/due ?due]
|
||||
'[(<= ?due ?end-due)]]}
|
||||
:args [(coerce/to-date (:end (:due-range args)))]})
|
||||
(:import-status args)
|
||||
(merge-query {:query {:in ['?import-status]
|
||||
:where ['[?e :invoice/import-status ?import-status]]}
|
||||
:args [ (keyword "import-status" (:import-status args))]})
|
||||
(:status args)
|
||||
(merge-query {:query {:in ['?status]
|
||||
:where ['[?e :invoice/status ?status]]}
|
||||
:args [ (:status args)]})
|
||||
(:vendor-id args)
|
||||
(merge-query {:query {:in ['?vendor-id]
|
||||
:where ['[?e :invoice/vendor ?vendor-id]]}
|
||||
:args [ (:vendor-id args)]})
|
||||
|
||||
(:import-status args)
|
||||
(merge-query {:query {:in ['?import-status]
|
||||
:where ['[?e :invoice/import-status ?import-status]]}
|
||||
:args [ (keyword "import-status" (:import-status args))]})
|
||||
(:status args)
|
||||
(merge-query {:query {:in ['?status]
|
||||
:where ['[?e :invoice/status ?status]]}
|
||||
:args [ (:status args)]})
|
||||
(:vendor-id args)
|
||||
(merge-query {:query {:in ['?vendor-id]
|
||||
:where ['[?e :invoice/vendor ?vendor-id]]}
|
||||
:args [ (:vendor-id args)]})
|
||||
(:account-id args)
|
||||
(merge-query {:query {:in ['?account-id]
|
||||
:where ['[?e :invoice/expense-accounts ?iea ?]
|
||||
'[?iea :invoice-expense-account/account ?account-id]]}
|
||||
:args [ (:account-id args)]})
|
||||
|
||||
(:account-id args)
|
||||
(merge-query {:query {:in ['?account-id]
|
||||
:where ['[?e :invoice/expense-accounts ?iea ?]
|
||||
'[?iea :invoice-expense-account/account ?account-id]]}
|
||||
:args [ (:account-id args)]})
|
||||
(:amount-gte args)
|
||||
(merge-query {:query {:in ['?amount-gte]
|
||||
:where ['[?e :invoice/total ?total-filter]
|
||||
'[(>= ?total-filter ?amount-gte)]]}
|
||||
:args [(:amount-gte args)]})
|
||||
|
||||
(:amount-gte args)
|
||||
(merge-query {:query {:in ['?amount-gte]
|
||||
:where ['[?e :invoice/total ?total-filter]
|
||||
'[(>= ?total-filter ?amount-gte)]]}
|
||||
:args [(:amount-gte args)]})
|
||||
(:amount-lte args)
|
||||
(merge-query {:query {:in ['?amount-lte]
|
||||
:where ['[?e :invoice/total ?total-filter]
|
||||
'[(<= ?total-filter ?amount-lte)]]}
|
||||
:args [(:amount-lte args)]})
|
||||
|
||||
(:amount-lte args)
|
||||
(merge-query {:query {:in ['?amount-lte]
|
||||
:where ['[?e :invoice/total ?total-filter]
|
||||
'[(<= ?total-filter ?amount-lte)]]}
|
||||
:args [(:amount-lte args)]})
|
||||
(seq (:invoice-number-like args))
|
||||
(merge-query {:query {:in ['?invoice-number-like]
|
||||
:where ['[?e :invoice/invoice-number ?invoice-number]
|
||||
'[(.contains ^String ?invoice-number ?invoice-number-like)]]}
|
||||
:args [(:invoice-number-like args)]})
|
||||
|
||||
(seq (:invoice-number-like args))
|
||||
(merge-query {:query {:in ['?invoice-number-like]
|
||||
:where ['[?e :invoice/invoice-number ?invoice-number]
|
||||
'[(.contains ^String ?invoice-number ?invoice-number-like)]]}
|
||||
:args [(:invoice-number-like args)]})
|
||||
(:scheduled-payments args)
|
||||
(merge-query {:query {:in []
|
||||
:where ['[?e :invoice/scheduled-payment]]}
|
||||
:args []})
|
||||
|
||||
(:scheduled-payments args)
|
||||
(merge-query {:query {:in []
|
||||
:where ['[?e :invoice/scheduled-payment]]}
|
||||
:args []})
|
||||
(:unresolved args)
|
||||
(merge-query {:query {:in []
|
||||
:where ['(or-join [?e]
|
||||
(not [?e :invoice/expense-accounts ])
|
||||
(and [?e :invoice/expense-accounts ?ea]
|
||||
(not [?ea :invoice-expense-account/account])))]}
|
||||
:args []})
|
||||
|
||||
(:unresolved args)
|
||||
(merge-query {:query {:in []
|
||||
:where ['(or-join [?e]
|
||||
(not [?e :invoice/expense-accounts ])
|
||||
(and [?e :invoice/expense-accounts ?ea]
|
||||
(not [?ea :invoice-expense-account/account])))]}
|
||||
:args []})
|
||||
(seq (:location args))
|
||||
(merge-query {:query {:in ['?location]
|
||||
:where ['[?e :invoice/expense-accounts ?eas]
|
||||
'[?eas :invoice-expense-account/location ?location]]}
|
||||
:args [(:location args)]})
|
||||
|
||||
(seq (:location args))
|
||||
(merge-query {:query {:in ['?location]
|
||||
:where ['[?e :invoice/expense-accounts ?eas]
|
||||
'[?eas :invoice-expense-account/location ?location]]}
|
||||
:args [(:location args)]})
|
||||
|
||||
(:sort args) (add-sorter-fields {"client" ['[?e :invoice/client ?c]
|
||||
'[?c :client/name ?sort-client]]
|
||||
"vendor" ['[?e :invoice/vendor ?v]
|
||||
'[?v :vendor/name ?sort-vendor]]
|
||||
"description-original" ['[?e :transaction/description-original ?sort-description-original]]
|
||||
"location" ['[?e :invoice/expense-accounts ?iea]
|
||||
'[?iea :invoice-expense-account/location ?sort-location]]
|
||||
"date" ['[?e :invoice/date ?sort-date]]
|
||||
"due" ['[(get-else $ ?e :invoice/due #inst "2050-01-01") ?sort-due]]
|
||||
"invoice-number" ['[?e :invoice/invoice-number ?sort-invoice-number]]
|
||||
"total" ['[?e :invoice/total ?sort-total]]
|
||||
"outstanding-balance" ['[?e :invoice/outstanding-balance ?sort-outstanding-balance]]}
|
||||
args)
|
||||
true
|
||||
(merge-query {:query {:find ['?sort-default '?e ]
|
||||
:where ['[?e :invoice/client]
|
||||
'[?e :invoice/date ?sort-default]]}}) )]
|
||||
(:sort args) (add-sorter-fields {"client" ['[?e :invoice/client ?c]
|
||||
'[?c :client/name ?sort-client]]
|
||||
"vendor" ['[?e :invoice/vendor ?v]
|
||||
'[?v :vendor/name ?sort-vendor]]
|
||||
"description-original" ['[?e :transaction/description-original ?sort-description-original]]
|
||||
"location" ['[?e :invoice/expense-accounts ?iea]
|
||||
'[?iea :invoice-expense-account/location ?sort-location]]
|
||||
"date" ['[?e :invoice/date ?sort-date]]
|
||||
"due" ['[(get-else $ ?e :invoice/due #inst "2050-01-01") ?sort-due]]
|
||||
"invoice-number" ['[?e :invoice/invoice-number ?sort-invoice-number]]
|
||||
"total" ['[?e :invoice/total ?sort-total]]
|
||||
"outstanding-balance" ['[?e :invoice/outstanding-balance ?sort-outstanding-balance]]}
|
||||
args)
|
||||
true
|
||||
(merge-query {:query {:find ['?sort-default '?e ]
|
||||
:where ['[?e :invoice/client]
|
||||
'[?e :invoice/date ?sort-default]]}}) ))]
|
||||
(->> (query2 query)
|
||||
(apply-sort-3 args)
|
||||
(apply-pagination args)))))
|
||||
|
||||
@@ -28,9 +28,33 @@
|
||||
(update :expected-deposit first)))
|
||||
cs)))))
|
||||
|
||||
(def default-read '[*
|
||||
(def default-read '[:db/id
|
||||
:sales-order/external-id,
|
||||
:sales-order/location,
|
||||
:sales-order/date,
|
||||
:sales-order/total,
|
||||
:sales-order/tax,
|
||||
:sales-order/tip,
|
||||
:sales-order/line-items,
|
||||
:sales-order/discount,
|
||||
:sales-order/returns,
|
||||
:sales-order/service-charge,
|
||||
:sales-order/vendor,
|
||||
:sales-order/source,
|
||||
:sales-order/reference-link,
|
||||
{:sales-order/client [:client/name :db/id :client/code]
|
||||
:sales-order/charges [* {:charge/processor [:db/ident]} {:expected-deposit/_charges [:db/id]}]}])
|
||||
:sales-order/charges [
|
||||
:charge/type-name,
|
||||
:charge/total,
|
||||
:charge/tax,
|
||||
:charge/tip,
|
||||
:charge/external-id,
|
||||
:charge/note,
|
||||
:charge/date,
|
||||
:charge/client,
|
||||
:charge/location,
|
||||
:charge/reference-link,
|
||||
{:charge/processor [:db/ident]} {:expected-deposit/_charges [:db/id]}]}])
|
||||
|
||||
(defn raw-graphql-ids [db args]
|
||||
(let [visible-clients (visible-clients (:id args))
|
||||
@@ -140,8 +164,8 @@
|
||||
|
||||
(defn get-graphql [args]
|
||||
(let [db (dc/db conn)
|
||||
{ids-to-retrieve :ids matching-count :count} (raw-graphql-ids db args)]
|
||||
[(->> (graphql-results ids-to-retrieve db args))
|
||||
{ids-to-retrieve :ids matching-count :count} (mu/trace ::get-sales-order-ids [] (raw-graphql-ids db args))]
|
||||
[(->> (mu/trace ::get-results [] (graphql-results ids-to-retrieve db args)))
|
||||
matching-count
|
||||
(summarize-orders ids-to-retrieve)]))
|
||||
|
||||
|
||||
@@ -42,137 +42,143 @@
|
||||
([args] (raw-graphql-ids (dc/db conn) args))
|
||||
([db args]
|
||||
(let [potential-duplicates (potential-duplicate-ids db args)
|
||||
query (cond-> {:query {:find []
|
||||
:in ['$ ]
|
||||
:where []}
|
||||
:args [db]}
|
||||
query
|
||||
(if (:exact-match-id args)
|
||||
(cond-> {:query {:find '[?e]
|
||||
:in '[$ ?e]
|
||||
:where '[[?e :transaction/client ?c]]}
|
||||
:args [db
|
||||
(:exact-match-id args)]}
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :transaction/client ?xx]]}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]}))
|
||||
(cond-> {:query {:find []
|
||||
:in ['$ ]
|
||||
:where []}
|
||||
:args [db]}
|
||||
|
||||
(:potential-duplicates args)
|
||||
(merge-query {:query {:in '[[?e ...]]}
|
||||
:args [potential-duplicates]})
|
||||
|
||||
(:exact-match-id args)
|
||||
(merge-query {:query {:in ['?e]
|
||||
:where []}
|
||||
:args [(:exact-match-id args)]})
|
||||
(:potential-duplicates args)
|
||||
(merge-query {:query {:in '[[?e ...]]}
|
||||
:args [potential-duplicates]})
|
||||
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :transaction/client ?xx]]}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
||||
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :transaction/client ?xx]]}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
||||
(:bank-account-id args)
|
||||
(merge-query {:query {:in ['?bank-account-id]
|
||||
:where ['[?e :transaction/bank-account ?bank-account-id]]}
|
||||
:args [(:bank-account-id args)]})
|
||||
|
||||
(:bank-account-id args)
|
||||
(merge-query {:query {:in ['?bank-account-id]
|
||||
:where ['[?e :transaction/bank-account ?bank-account-id]]}
|
||||
:args [(:bank-account-id args)]})
|
||||
(:import-batch-id args)
|
||||
(merge-query {:query {:in ['?import-batch-id]
|
||||
:where ['[?import-batch-id :import-batch/entry ?e]]}
|
||||
:args [(:import-batch-id args)]})
|
||||
|
||||
(:import-batch-id args)
|
||||
(merge-query {:query {:in ['?import-batch-id]
|
||||
:where ['[?import-batch-id :import-batch/entry ?e]]}
|
||||
:args [(:import-batch-id args)]})
|
||||
(:account-id args)
|
||||
(merge-query {:query {:in ['?account-id]
|
||||
:where ['[?e :transaction/accounts ?accounts]
|
||||
'[?accounts :transaction-account/account ?account-id]]}
|
||||
:args [(:account-id args)]})
|
||||
|
||||
(:account-id args)
|
||||
(merge-query {:query {:in ['?account-id]
|
||||
:where ['[?e :transaction/accounts ?accounts]
|
||||
'[?accounts :transaction-account/account ?account-id]]}
|
||||
:args [(:account-id args)]})
|
||||
(:client-id args)
|
||||
(merge-query {:query {:in ['?client-id]
|
||||
:where ['[?e :transaction/client ?client-id]]}
|
||||
:args [(:client-id args)]})
|
||||
|
||||
(:client-id args)
|
||||
(merge-query {:query {:in ['?client-id]
|
||||
:where ['[?e :transaction/client ?client-id]]}
|
||||
:args [(:client-id args)]})
|
||||
(:vendor-id args)
|
||||
(merge-query {:query {:in ['?vendor-id]
|
||||
:where ['[?e :transaction/vendor ?vendor-id]]}
|
||||
:args [(:vendor-id args)]})
|
||||
|
||||
(:vendor-id args)
|
||||
(merge-query {:query {:in ['?vendor-id]
|
||||
:where ['[?e :transaction/vendor ?vendor-id]]}
|
||||
:args [(:vendor-id args)]})
|
||||
|
||||
(:amount-gte args)
|
||||
(merge-query {:query {:in ['?amount-gte]
|
||||
:where ['[?e :transaction/amount ?a]
|
||||
'[(>= ?a ?amount-gte)]]}
|
||||
:args [(:amount-gte args)]})
|
||||
|
||||
|
||||
(:amount-gte args)
|
||||
(merge-query {:query {:in ['?amount-gte]
|
||||
:where ['[?e :transaction/amount ?a]
|
||||
'[(>= ?a ?amount-gte)]]}
|
||||
:args [(:amount-gte args)]})
|
||||
(:amount-lte args)
|
||||
(merge-query {:query {:in ['?amount-lte]
|
||||
:where ['[?e :transaction/amount ?a]
|
||||
'[(<= ?a ?amount-lte)]]}
|
||||
:args [(:amount-lte args)]})
|
||||
|
||||
(:amount-lte args)
|
||||
(merge-query {:query {:in ['?amount-lte]
|
||||
:where ['[?e :transaction/amount ?a]
|
||||
'[(<= ?a ?amount-lte)]]}
|
||||
:args [(:amount-lte args)]})
|
||||
(:start (:date-range args))
|
||||
(merge-query {:query {:in ['?start-date]
|
||||
:where ['[?e :transaction/date ?date]
|
||||
'[(>= ?date ?start-date)]]}
|
||||
:args [(coerce/to-date (:start (:date-range args)))]})
|
||||
|
||||
(:start (:date-range args))
|
||||
(merge-query {:query {:in ['?start-date]
|
||||
:where ['[?e :transaction/date ?date]
|
||||
'[(>= ?date ?start-date)]]}
|
||||
:args [(coerce/to-date (:start (:date-range args)))]})
|
||||
(:end (:date-range args))
|
||||
(merge-query {:query {:in ['?end-date]
|
||||
:where ['[?e :transaction/date ?date]
|
||||
'[(<= ?date ?end-date)]]}
|
||||
:args [(coerce/to-date (:end (:date-range args)))]})
|
||||
|
||||
(:end (:date-range args))
|
||||
(merge-query {:query {:in ['?end-date]
|
||||
:where ['[?e :transaction/date ?date]
|
||||
'[(<= ?date ?end-date)]]}
|
||||
:args [(coerce/to-date (:end (:date-range args)))]})
|
||||
(:approval-status args)
|
||||
(merge-query {:query {:in ['?approval-status]
|
||||
:where ['[?e :transaction/approval-status ?approval-status]]}
|
||||
:args [(:approval-status args)]})
|
||||
|
||||
(:approval-status args)
|
||||
(merge-query {:query {:in ['?approval-status]
|
||||
:where ['[?e :transaction/approval-status ?approval-status]]}
|
||||
:args [(:approval-status args)]})
|
||||
(:client-code args)
|
||||
(merge-query {:query {:in ['?client-code]
|
||||
:where ['[?e :transaction/client ?client-id]
|
||||
'[?client-id :client/code ?client-code]]}
|
||||
:args [(:client-code args)]})
|
||||
|
||||
(:original-id args)
|
||||
(merge-query {:query {:in ['?original-id]
|
||||
:where ['[?e :transaction/client ?c]
|
||||
'[?c :client/original-id ?original-id]]}
|
||||
:args [(:original-id args)]})
|
||||
|
||||
(:client-code args)
|
||||
(merge-query {:query {:in ['?client-code]
|
||||
:where ['[?e :transaction/client ?client-id]
|
||||
'[?client-id :client/code ?client-code]]}
|
||||
:args [(:client-code args)]})
|
||||
|
||||
(:original-id args)
|
||||
(merge-query {:query {:in ['?original-id]
|
||||
:where ['[?e :transaction/client ?c]
|
||||
'[?c :client/original-id ?original-id]]}
|
||||
:args [(:original-id args)]})
|
||||
(seq (:location args))
|
||||
(merge-query {:query {:in ['?location]
|
||||
:where ['[?e :transaction/accounts ?tas]
|
||||
'[?tas :transaction-account/location ?location]]}
|
||||
:args [(:location args)]})
|
||||
|
||||
(seq (:location args))
|
||||
(merge-query {:query {:in ['?location]
|
||||
:where ['[?e :transaction/accounts ?tas]
|
||||
'[?tas :transaction-account/location ?location]]}
|
||||
:args [(:location args)]})
|
||||
(:unresolved args)
|
||||
(merge-query {:query {:where ['[?e :transaction/date]
|
||||
'(or-join [?e]
|
||||
(not [?e :transaction/accounts])
|
||||
(and [?e :transaction/accounts ?tas]
|
||||
(not [?tas :transaction-account/account])))]}})
|
||||
|
||||
(:unresolved args)
|
||||
(merge-query {:query {:where ['[?e :transaction/date]
|
||||
'(or-join [?e]
|
||||
(not [?e :transaction/accounts])
|
||||
(and [?e :transaction/accounts ?tas]
|
||||
(not [?tas :transaction-account/account])))]}})
|
||||
(:description args)
|
||||
(merge-query {:query {:in ['?description]
|
||||
:where ['[?e :transaction/description-original ?do]
|
||||
'[(clojure.string/lower-case ?do) ?do2]
|
||||
'[(.contains ?do2 ?description)]]}
|
||||
:args [(clojure.string/lower-case (:description args))]})
|
||||
|
||||
(:description args)
|
||||
(merge-query {:query {:in ['?description]
|
||||
:where ['[?e :transaction/description-original ?do]
|
||||
'[(clojure.string/lower-case ?do) ?do2]
|
||||
'[(.contains ?do2 ?description)]]}
|
||||
:args [(clojure.string/lower-case (:description args))]})
|
||||
|
||||
(:sort args) (add-sorter-fields {"client" ['[?e :transaction/client ?c]
|
||||
'[?c :client/name ?sort-client]]
|
||||
"account" ['[?e :transaction/date]
|
||||
'(or-join [?e ?sort-account]
|
||||
(and [?e :transaction/bank-account ?c]
|
||||
[?c :bank-account/name ?sort-account])
|
||||
(and
|
||||
(not [?e :transaction/bank-account])
|
||||
[(ground "") ?sort-account]))]
|
||||
"description-original" ['[?e :transaction/description-original ?sort-description-original]]
|
||||
"date" ['[?e :transaction/date ?sort-date]]
|
||||
"vendor" ['(or-join [?e ?sort-vendor]
|
||||
(and [(missing? $ ?e :transaction/vendor)]
|
||||
[?e :transaction/description-original ?sort-vendor])
|
||||
(and [?e :transaction/vendor ?v]
|
||||
[?v :vendor/name ?sort-vendor]))]
|
||||
"amount" ['[?e :transaction/amount ?sort-amount]]
|
||||
"status" ['[?e :transaction/status ?sort-status]]}
|
||||
args)
|
||||
true
|
||||
(merge-query {:query {:find ['?sort-default '?e]
|
||||
:where ['[?e :transaction/id]
|
||||
'[?e :transaction/date ?sort-default]
|
||||
'(not [?e :transaction/approval-status :transaction-approval-status/suppressed])]}}))]
|
||||
(:sort args) (add-sorter-fields {"client" ['[?e :transaction/client ?c]
|
||||
'[?c :client/name ?sort-client]]
|
||||
"account" ['[?e :transaction/date]
|
||||
'(or-join [?e ?sort-account]
|
||||
(and [?e :transaction/bank-account ?c]
|
||||
[?c :bank-account/name ?sort-account])
|
||||
(and
|
||||
(not [?e :transaction/bank-account])
|
||||
[(ground "") ?sort-account]))]
|
||||
"description-original" ['[?e :transaction/description-original ?sort-description-original]]
|
||||
"date" ['[?e :transaction/date ?sort-date]]
|
||||
"vendor" ['(or-join [?e ?sort-vendor]
|
||||
(and [(missing? $ ?e :transaction/vendor)]
|
||||
[?e :transaction/description-original ?sort-vendor])
|
||||
(and [?e :transaction/vendor ?v]
|
||||
[?v :vendor/name ?sort-vendor]))]
|
||||
"amount" ['[?e :transaction/amount ?sort-amount]]
|
||||
"status" ['[?e :transaction/status ?sort-status]]}
|
||||
args)
|
||||
true
|
||||
(merge-query {:query {:find ['?sort-default '?e]
|
||||
:where ['[?e :transaction/id]
|
||||
'[?e :transaction/date ?sort-default]
|
||||
'(not [?e :transaction/approval-status :transaction-approval-status/suppressed])]}})))]
|
||||
(log/info "query is" query)
|
||||
(cond->> (query2 query)
|
||||
true (apply-sort-3 (assoc args :default-asc? false))
|
||||
|
||||
32
src/clj/auto_ap/solr.clj
Normal file
32
src/clj/auto_ap/solr.clj
Normal file
@@ -0,0 +1,32 @@
|
||||
(ns auto-ap.solr
|
||||
(:require [clojure.data.json :as json]
|
||||
[clj-http.client :as client]
|
||||
[config.core :refer [env]]))
|
||||
|
||||
(def solr-uri (:solr-uri env))
|
||||
|
||||
(defn index-documents [xs]
|
||||
(client/post
|
||||
(str solr-uri "/solr/invoices/update?commitWithin=15000")
|
||||
{:headers {"Content-Type" "application/json"}
|
||||
:method "POST"
|
||||
:body (json/write-str xs)}))
|
||||
|
||||
(defn query [q]
|
||||
(-> (client/post (str solr-uri "/solr/invoices/query")
|
||||
{:body (json/write-str {"query" q
|
||||
"fields" "id, date, amount, type, description, number, client_code, client_id, vendor_name"})
|
||||
:headers {"Content-Type" "application/json"}
|
||||
:as :json}
|
||||
)
|
||||
:body
|
||||
:response
|
||||
:docs))
|
||||
|
||||
(defn solr-delete []
|
||||
(client/post
|
||||
(str solr-uri "/solr/invoices/update?commitWithin=1000")
|
||||
{:headers {"Content-Type" "application/json"}
|
||||
:method "POST"
|
||||
:body (json/write-str {"delete" {"query" "*:*"}})})
|
||||
)
|
||||
@@ -6,6 +6,7 @@
|
||||
[auto-ap.ssr.auth :as auth]
|
||||
[auto-ap.ssr.transaction.insights :as insights]
|
||||
[auto-ap.ssr.company.company-1099 :as company-1099]
|
||||
[auto-ap.ssr.search :as search]
|
||||
[auto-ap.ssr.company-dropdown :as company-dropdown]))
|
||||
|
||||
;; from auto-ap.ssr-routes, because they're shared
|
||||
@@ -25,5 +26,6 @@
|
||||
:transaction-insight-table (wrap-client-redirect-unauthenticated (wrap-secure insights/insight-table))
|
||||
:transaction-insight-rows (wrap-client-redirect-unauthenticated (wrap-secure insights/transaction-rows))
|
||||
:transaction-insight-approve (wrap-client-redirect-unauthenticated (wrap-secure insights/approve))
|
||||
:transaction-insight-explain (wrap-client-redirect-unauthenticated (wrap-secure insights/explain))})
|
||||
:transaction-insight-explain (wrap-client-redirect-unauthenticated (wrap-secure insights/explain))
|
||||
:search (wrap-client-redirect-unauthenticated (wrap-secure search/dialog-contents))})
|
||||
|
||||
|
||||
125
src/clj/auto_ap/ssr/search.clj
Normal file
125
src/clj/auto_ap/ssr/search.clj
Normal file
@@ -0,0 +1,125 @@
|
||||
(ns auto-ap.ssr.search
|
||||
(:require
|
||||
[auto-ap.graphql.utils :refer [can-see-client?]]
|
||||
[auto-ap.ssr.utils :refer [html-response]]
|
||||
[auto-ap.time :as atime]
|
||||
[clj-http.client :as client]
|
||||
[clojure.data.json :as json]
|
||||
[clojure.string :as str]
|
||||
[auto-ap.solr :as solr]))
|
||||
|
||||
(defn try-cleanse-date [d]
|
||||
(try
|
||||
(or
|
||||
(some-> (atime/parse-utc d atime/normal-date) (atime/unparse atime/solr-date))
|
||||
(some-> (atime/parse-utc d atime/iso-date) (atime/unparse atime/solr-date))
|
||||
d)
|
||||
(catch Exception _
|
||||
d)))
|
||||
|
||||
(defn try-parse-number [n]
|
||||
(if (re-find #"^[\-]?\d+\.\d+$" n )
|
||||
(str (with-precision 2
|
||||
(some-> n
|
||||
(Double/parseDouble)
|
||||
bigdec
|
||||
(.setScale 2 java.math.RoundingMode/HALF_UP)
|
||||
(double))))
|
||||
n))
|
||||
|
||||
|
||||
(defn q->solr-q [q]
|
||||
(let [matches (re-seq #"(?:\".*?\"|\S)+" q)]
|
||||
(str/join " AND "
|
||||
(->> matches
|
||||
(map (fn [m]
|
||||
(cond (= "payment" m)
|
||||
"type:payment"
|
||||
|
||||
(= "invoice" m)
|
||||
"type:invoice"
|
||||
|
||||
(= "transaction" m)
|
||||
"type:transaction"
|
||||
|
||||
:else
|
||||
(str "_text_:\"" (try-parse-number (try-cleanse-date m)) ""\"))))))))
|
||||
|
||||
|
||||
(defn search-results [q id]
|
||||
(into []
|
||||
(filter (fn [d]
|
||||
(can-see-client? id (first (:client_id d)))))
|
||||
(solr/query (q->solr-q q))))
|
||||
|
||||
|
||||
(defn search-results* [q id]
|
||||
(let [results (search-results q id)]
|
||||
[:div
|
||||
(if (seq results)
|
||||
(for [doc results]
|
||||
[:div.block
|
||||
[:div.card
|
||||
[:div.card-header.has-background-info-light
|
||||
(cond (= "transaction" (:type doc))
|
||||
[:div.card-header-icon.icon-task-list-text-1]
|
||||
|
||||
(= "invoice" (:type doc))
|
||||
[:div.card-header-icon.icon-accounting-invoice-mail]
|
||||
|
||||
(= "payment" (:type doc))
|
||||
[:div.card-header-icon.icon-check-payment-sign])
|
||||
[:div.card-header-title (clojure.string/capitalize (:type doc))
|
||||
" "
|
||||
" "
|
||||
[:span.tags.ml-3
|
||||
[:span.tag.is-warning "client: " (:client_code doc)]
|
||||
[:span.tag.is-info "amount: $" (first (:amount doc))]
|
||||
(when-let [vendor-name (first (:vendor_name doc))]
|
||||
[:span.tag.is-primary "vendor: " vendor-name])]]
|
||||
[:a.card-header-icon.fa.fa-external-link {:href (str "/" (cond (= "invoice"
|
||||
(:type doc))
|
||||
"invoices"
|
||||
|
||||
(= "transaction"
|
||||
(:type doc))
|
||||
"transactions"
|
||||
|
||||
:else
|
||||
"payments") "/?exact-match-id=" (:id doc))
|
||||
:target "_blank"}]
|
||||
]
|
||||
|
||||
|
||||
[:div.card-content
|
||||
[:span
|
||||
|
||||
[:strong (atime/unparse (atime/parse (:date doc) atime/solr-date) atime/normal-date)]
|
||||
": "
|
||||
(str (or (first (:description doc))
|
||||
(first (:number doc))))]]]]
|
||||
)
|
||||
[:div.block "No results found."])]))
|
||||
|
||||
(defn dialog-contents [request]
|
||||
(if-let [q (:q (:params request))]
|
||||
(html-response (search-results* q (:identity request)))
|
||||
(html-response
|
||||
[:div#search {:style {:height "400px" :overflow "auto"}}
|
||||
|
||||
[:div.block
|
||||
[:input#search-input.input {:type "search"
|
||||
:placeholder "5/5/2034 Magheritas"
|
||||
:name "q"
|
||||
:hx-post "/search"
|
||||
:hx-trigger "keyup changed delay:300ms, search"
|
||||
:hx-target "#search-results"
|
||||
:hx-indicator "#search"
|
||||
:value (:q (:params request))
|
||||
:autofocus true}]]
|
||||
[:style
|
||||
".htmx-request #search-results {display: none} .htmx-request .htmx-indicator { display: block !important; }"]
|
||||
[:div#search-results
|
||||
]
|
||||
[:div.loader.is-loading.big.htmx-indicator {:style {:display "none"}}]])))
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
[config.core :refer [env]]
|
||||
[hiccup2.core :as hiccup]))
|
||||
|
||||
(defn html-response [hiccup & {:keys [status] :or {status 200}}]
|
||||
(defn html-response [hiccup & {:keys [status headers] :or {status 200 headers {}}}]
|
||||
{:status status
|
||||
:headers {"Content-Type" "text/html"}
|
||||
:headers (into {"Content-Type" "text/html"}
|
||||
headers)
|
||||
:body (str
|
||||
(hiccup/html
|
||||
{}
|
||||
|
||||
@@ -14,9 +14,16 @@
|
||||
|
||||
(def normal-date "MM/dd/yyyy")
|
||||
(def iso-date "yyyy-MM-dd")
|
||||
(def solr-date "yyyy-MM-dd'T'HH:mm:ss'Z'")
|
||||
|
||||
(def standard-time "MM/dd/yyyy hh:mm aa")
|
||||
|
||||
(defn parse-utc [v format]
|
||||
(try
|
||||
(f/parse (f/formatter format) v)
|
||||
(catch Exception _
|
||||
nil)))
|
||||
|
||||
(defn parse [v format]
|
||||
(try
|
||||
(time/from-time-zone (f/parse (f/formatter format) v)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
[auto-ap.datomic :refer [conn pull-attr random-tempid]]
|
||||
[auto-ap.ledger :as l ]
|
||||
[clj-http.core :as http]
|
||||
[clj-http.client :as client]
|
||||
[auto-ap.server]
|
||||
[auto-ap.square.core :as square]
|
||||
[auto-ap.square.core2 :as square2]
|
||||
@@ -24,12 +25,17 @@
|
||||
[unilog.context :as lc]
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[com.brunobonacci.mulog.buffer :as rb]
|
||||
[datomic.api :as d])
|
||||
[datomic.api :as d]
|
||||
[clojure.data.json :as json]
|
||||
[auto-ap.solr :as solr])
|
||||
(:import
|
||||
(org.apache.commons.io.input BOMInputStream)))
|
||||
|
||||
(defn println-event [item]
|
||||
(printf "%s - %s: %s\n" (:mulog/namespace item) (:mulog/event-name item)
|
||||
(printf "%s - %s:%s %s\n" (:mulog/namespace item) (:mulog/event-name item)
|
||||
(if (:mulog/duration item)
|
||||
(str " " (int (/ (:mulog/duration item) 1000000)) "ms")
|
||||
"")
|
||||
(pr-str (reduce
|
||||
(fn [acc [k v]]
|
||||
(assoc acc k v))
|
||||
@@ -554,14 +560,96 @@
|
||||
:separator \tab))))
|
||||
|
||||
|
||||
(defn fmt-amount [a]
|
||||
(with-precision 2
|
||||
(some-> a
|
||||
bigdec
|
||||
(.setScale 2 java.math.RoundingMode/HALF_UP)
|
||||
(double))))
|
||||
|
||||
(defn index-solr
|
||||
[]
|
||||
)
|
||||
(doseq [batch (->> (dc/qseq {:query '[:find (pull ?i [:db/id :invoice/invoice-number
|
||||
:invoice/total
|
||||
{:invoice/client [:client/code :db/id]
|
||||
:invoice/vendor [:vendor/name :db/id]}
|
||||
:invoice/date])
|
||||
:in $
|
||||
:where [?i :invoice/invoice-number]
|
||||
(not [?i :invoice/status :invoice-status/voided])]
|
||||
:args [
|
||||
(dc/db conn)]})
|
||||
(map (fn [[i]]
|
||||
{"id" (-> i :db/id)
|
||||
"client_id" (-> i :invoice/client :db/id)
|
||||
"client_code" (-> i :invoice/client :client/code)
|
||||
"date" (some-> i :invoice/date c/to-date-time (atime/unparse atime/iso-date) (str "T00:00:00Z"))
|
||||
"amount" (-> i :invoice/total fmt-amount)
|
||||
"number" (-> i :invoice/invoice-number)
|
||||
"vendor_name" (-> i :invoice/vendor :vendor/name)
|
||||
"vendor_id" (-> i :invoice/vendor :db/id)
|
||||
"type" "invoice"
|
||||
}))
|
||||
(partition-all 1000))]
|
||||
(print ".")
|
||||
(flush)
|
||||
(solr/index-documents batch))
|
||||
|
||||
(doseq [batch (->> (dc/qseq {:query '[:find (pull ?i [:db/id :payment/check-number
|
||||
:payment/amount
|
||||
{:payment/client [:client/code :db/id]
|
||||
:payment/vendor [:vendor/name :db/id]}
|
||||
:payment/date])
|
||||
:in $
|
||||
:where [?i :payment/date]
|
||||
(not [?i :payment/status :payment-status/voided])]
|
||||
:args [(dc/db conn)]})
|
||||
(map (fn [[i]]
|
||||
{"id" (-> i :db/id)
|
||||
"client_id" (-> i :payment/client :db/id)
|
||||
"client_code" (-> i :payment/client :client/code)
|
||||
"date" (some-> i :payment/date c/to-date-time (atime/unparse atime/iso-date) (str "T00:00:00Z"))
|
||||
"amount" (-> i :payment/amount fmt-amount)
|
||||
"description" (-> i :payment/check-number)
|
||||
"vendor_name" (-> i :payment/vendor :vendor/name)
|
||||
"vendor_id" (-> i :payment/vendor :db/id)
|
||||
"type" "payment"}))
|
||||
(partition-all 1000))]
|
||||
(print ".")
|
||||
(flush)
|
||||
(solr/index-documents batch))
|
||||
|
||||
(doseq [batch (->> (dc/qseq {:query '[:find (pull ?i [:db/id :transaction/description-original
|
||||
:transaction/amount
|
||||
{:transaction/client [:client/code :db/id]
|
||||
:transaction/vendor [:vendor/name :db/id]}
|
||||
:transaction/date])
|
||||
:in $
|
||||
:where [?i :transaction/description-original]
|
||||
(not [?i :transaction/approval-status :transaction-approval-status/suppressed])]
|
||||
:args [(dc/db conn)]})
|
||||
(map (fn [[i]]
|
||||
{"id" (-> i :db/id)
|
||||
"client_id" (-> i :transaction/client :db/id)
|
||||
"client_code" (-> i :transaction/client :client/code)
|
||||
"date" (some-> i :transaction/date c/to-date-time (atime/unparse atime/iso-date) (str "T00:00:00Z"))
|
||||
"amount" (-> i :transaction/amount fmt-amount)
|
||||
"description" (-> i :transaction/description-original)
|
||||
"vendor_name" (-> i :transaction/vendor :vendor/name)
|
||||
"vendor_id" (-> i :transaction/vendor :db/id)
|
||||
"type" "transaction"}))
|
||||
(partition-all 1000))]
|
||||
(print ".")
|
||||
(flush)
|
||||
(solr/index-documents batch)
|
||||
))
|
||||
|
||||
(defn setup-sales-orders []
|
||||
(doseq [n (->> (dc/qseq {:query '[:find ?s ?c :where [?s :sales-order/client ?c]] :args [(dc/db auto-ap.datomic/conn)]})
|
||||
(map (fn [[s c]]
|
||||
{:db/id s :sales-order/client c}))
|
||||
(partition-all 1000)
|
||||
(take 10))]
|
||||
(partition-all 1000))]
|
||||
(print ".")
|
||||
@(dc/transact auto-ap.datomic/conn n)))
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
(ns auto-ap.ssr-routes)
|
||||
|
||||
(def routes {"logout" :logout
|
||||
"search" :search
|
||||
"admin" {"/history" {"" :admin-history
|
||||
"/" :admin-history
|
||||
#"/search/?" :admin-history-search
|
||||
|
||||
@@ -158,6 +158,7 @@
|
||||
:else
|
||||
{:db (-> db
|
||||
(assoc :active-route handler
|
||||
:auto-ap.views.components.modal/state nil
|
||||
:page-failure nil
|
||||
:menu nil
|
||||
:query-params params
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
[auto-ap.routes :as routes]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.modal :as modal]
|
||||
[auto-ap.views.components.search :as search]
|
||||
[auto-ap.views.components.vendor-dialog :as vendor-dialog]
|
||||
[auto-ap.views.utils
|
||||
:refer [active-when
|
||||
@@ -33,8 +34,7 @@
|
||||
(println (.-activeElement js/document))
|
||||
(when-not (.contains @!child (.-activeElement js/document))
|
||||
(re-frame/dispatch [::events/toggle-menu id])))
|
||||
2))
|
||||
}
|
||||
2))}
|
||||
[:a {:class "navbar-link login" :on-click (fn [e]
|
||||
(.preventDefault e)
|
||||
(.stopPropagation e)
|
||||
@@ -127,7 +127,7 @@
|
||||
clients (re-frame/subscribe [::subs/clients])
|
||||
is-initial-loading @(re-frame/subscribe [::subs/is-initial-loading?])]
|
||||
[:nav {:class "navbar has-shadow is-fixed-top is-grey"}
|
||||
|
||||
|
||||
[:div {:class "container"}
|
||||
[:div {:class "navbar-brand"}
|
||||
[:a {:class "navbar-item", :href "../"}
|
||||
@@ -166,14 +166,13 @@
|
||||
(when-not is-initial-loading
|
||||
[:div.navbar-end
|
||||
(when (> (count @clients) 1)
|
||||
[client-dropdown])])]
|
||||
[client-dropdown])
|
||||
])]
|
||||
(when-not is-initial-loading
|
||||
[login-dropdown])]
|
||||
|
||||
|
||||
]))))
|
||||
|
||||
|
||||
(when (= "admin" (:user/role @user))
|
||||
[:div {:style {:position "fixed" :top "4px" :right "8px"}}
|
||||
[search/search-button ]])]))))
|
||||
|
||||
|
||||
(defn appearing-side-bar [{:keys [visible?]} ]
|
||||
@@ -188,6 +187,7 @@
|
||||
[:div
|
||||
[modal/global-modal]
|
||||
[navbar ap]
|
||||
|
||||
[:div {:class "columns has-shadow", :style {:margin-bottom "0px" :height "calc(100vh - 46px)" } :id "mail-app" }
|
||||
[:aside {:class "column aside menu is-2 " }
|
||||
[:div.main.left-nav
|
||||
|
||||
30
src/cljs/auto_ap/views/components/search.cljs
Normal file
30
src/cljs/auto_ap/views/components/search.cljs
Normal file
@@ -0,0 +1,30 @@
|
||||
(ns auto-ap.views.components.search
|
||||
(:require
|
||||
[auto-ap.views.utils :refer [dispatch-event]]
|
||||
[auto-ap.views.components.modal :as modal]
|
||||
[reagent.core :as reagent]))
|
||||
|
||||
(defn search-dialog-body []
|
||||
(let [a (atom nil)]
|
||||
(reagent/create-class
|
||||
{
|
||||
:component-did-mount
|
||||
(fn [this]
|
||||
(.process js/htmx @a))
|
||||
:should-component-update
|
||||
(fn [this]
|
||||
false)
|
||||
:reagent-render
|
||||
(fn []
|
||||
[:div {:ref (fn [x] (reset! a x))
|
||||
"hx-get" "/search"
|
||||
"hx-trigger" "load"}
|
||||
""])})))
|
||||
|
||||
(defn search-button []
|
||||
[:i.fa.fa-search.button {:on-click
|
||||
(dispatch-event [::modal/modal-requested
|
||||
{:title "Search"
|
||||
:body [search-dialog-body]
|
||||
:class "semi-wide"}])}
|
||||
#_[:i.fa.fa-search]])
|
||||
@@ -190,7 +190,8 @@
|
||||
|
||||
|
||||
(defn content []
|
||||
(let [is-admin? @(re-frame/subscribe [::subs/is-admin?])]
|
||||
(let [is-admin? @(re-frame/subscribe [::subs/is-admin?])
|
||||
_ @(re-frame/subscribe [::data-page/params ::page])]
|
||||
[:div
|
||||
[:h1.title "Transactions"]
|
||||
[status/status-notification {:statuses [[::status/single ::delete-selected]
|
||||
|
||||
Reference in New Issue
Block a user