can unapprove, but there are bugs. UI doesnt refresh, filters are lost.
This commit is contained in:
@@ -17,104 +17,106 @@
|
|||||||
(keyword "transaction" sort-by)))
|
(keyword "transaction" sort-by)))
|
||||||
|
|
||||||
|
|
||||||
(defn raw-graphql-ids [db args]
|
(defn raw-graphql-ids
|
||||||
(let [query (cond-> {:query {:find []
|
([args] (raw-graphql-ids (d/db (d/connect uri)) args))
|
||||||
:in ['$ ]
|
([db args]
|
||||||
:where []}
|
(let [query (cond-> {:query {:find []
|
||||||
:args [db]}
|
:in ['$ ]
|
||||||
|
:where []}
|
||||||
|
:args [db]}
|
||||||
|
|
||||||
(:sort-by args) (add-sorter-field {"client" ['[?e :transaction/client ?c]
|
(:sort-by args) (add-sorter-field {"client" ['[?e :transaction/client ?c]
|
||||||
'[?c :client/name ?sorter]]
|
'[?c :client/name ?sorter]]
|
||||||
"account" ['[?e :transaction/date]
|
"account" ['[?e :transaction/date]
|
||||||
'(or-join [?e ?sorter]
|
'(or-join [?e ?sorter]
|
||||||
(and [?e :transaction/account ?c]
|
(and [?e :transaction/account ?c]
|
||||||
[?c :account/name ?sorter])
|
[?c :account/name ?sorter])
|
||||||
(and
|
(and
|
||||||
(not [?e :transaction/account])
|
(not [?e :transaction/account])
|
||||||
[(ground "") ?sorter]))]
|
[(ground "") ?sorter]))]
|
||||||
"description-original" ['[?e :transaction/description-original ?sorter]]
|
"description-original" ['[?e :transaction/description-original ?sorter]]
|
||||||
"date" ['[?e :transaction/date ?sorter]]
|
"date" ['[?e :transaction/date ?sorter]]
|
||||||
"vendor" ['[?e :transaction/vendor ?v]
|
"vendor" ['[?e :transaction/vendor ?v]
|
||||||
'[?v :vendor/name ?sorter]]
|
'[?v :vendor/name ?sorter]]
|
||||||
"amount" ['[?e :transaction/amount ?sorter]]
|
"amount" ['[?e :transaction/amount ?sorter]]
|
||||||
"status" ['[?e :transaction/status ?sorter]]}
|
"status" ['[?e :transaction/status ?sorter]]}
|
||||||
args)
|
args)
|
||||||
|
|
||||||
(limited-clients (:id args))
|
(limited-clients (:id args))
|
||||||
(merge-query {:query {:in ['[?xx ...]]
|
(merge-query {:query {:in ['[?xx ...]]
|
||||||
:where ['[?e :transaction/client ?xx]]}
|
:where ['[?e :transaction/client ?xx]]}
|
||||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
:args [(set (map :db/id (limited-clients (:id args))))]})
|
||||||
|
|
||||||
(:bank-account-id args)
|
(:bank-account-id args)
|
||||||
(merge-query {:query {:in ['?bank-account-id]
|
(merge-query {:query {:in ['?bank-account-id]
|
||||||
:where ['[?e :transaction/bank-account ?bank-account-id]]}
|
:where ['[?e :transaction/bank-account ?bank-account-id]]}
|
||||||
:args [(:bank-account-id args)]})
|
:args [(:bank-account-id args)]})
|
||||||
|
|
||||||
(:client-id args)
|
(:client-id args)
|
||||||
(merge-query {:query {:in ['?client-id]
|
(merge-query {:query {:in ['?client-id]
|
||||||
:where ['[?e :transaction/client ?client-id]]}
|
:where ['[?e :transaction/client ?client-id]]}
|
||||||
:args [(:client-id args)]})
|
:args [(:client-id args)]})
|
||||||
|
|
||||||
(:vendor-id args)
|
(:vendor-id args)
|
||||||
(merge-query {:query {:in ['?vendor-id]
|
(merge-query {:query {:in ['?vendor-id]
|
||||||
:where ['[?e :transaction/vendor ?vendor-id]]}
|
:where ['[?e :transaction/vendor ?vendor-id]]}
|
||||||
:args [(:vendor-id args)]})
|
:args [(:vendor-id args)]})
|
||||||
|
|
||||||
|
|
||||||
(:amount-gte args)
|
(:amount-gte args)
|
||||||
(merge-query {:query {:in ['?amount-gte]
|
(merge-query {:query {:in ['?amount-gte]
|
||||||
:where ['[?e :transaction/amount ?a]
|
:where ['[?e :transaction/amount ?a]
|
||||||
'[(>= ?a ?amount-gte)]]}
|
'[(>= ?a ?amount-gte)]]}
|
||||||
:args [(:amount-gte args)]})
|
:args [(:amount-gte args)]})
|
||||||
|
|
||||||
(:amount-lte args)
|
(:amount-lte args)
|
||||||
(merge-query {:query {:in ['?amount-lte]
|
(merge-query {:query {:in ['?amount-lte]
|
||||||
:where ['[?e :transaction/amount ?a]
|
:where ['[?e :transaction/amount ?a]
|
||||||
'[(<= ?a ?amount-lte)]]}
|
'[(<= ?a ?amount-lte)]]}
|
||||||
:args [(:amount-lte args)]})
|
:args [(:amount-lte args)]})
|
||||||
|
|
||||||
(:start (:date-range args))
|
(:start (:date-range args))
|
||||||
(merge-query {:query {:in ['?start-date]
|
(merge-query {:query {:in ['?start-date]
|
||||||
:where ['[?e :transaction/date ?date]
|
:where ['[?e :transaction/date ?date]
|
||||||
'[(>= ?date ?start-date)]]}
|
'[(>= ?date ?start-date)]]}
|
||||||
:args [(coerce/to-date (:start (:date-range args)))]})
|
:args [(coerce/to-date (:start (:date-range args)))]})
|
||||||
|
|
||||||
(:end (:date-range args))
|
(:end (:date-range args))
|
||||||
(merge-query {:query {:in ['?end-date]
|
(merge-query {:query {:in ['?end-date]
|
||||||
:where ['[?e :transaction/date ?date]
|
:where ['[?e :transaction/date ?date]
|
||||||
'[(<= ?date ?end-date)]]}
|
'[(<= ?date ?end-date)]]}
|
||||||
:args [(coerce/to-date (:end (:date-range args)))]})
|
:args [(coerce/to-date (:end (:date-range args)))]})
|
||||||
|
|
||||||
(:approval-status args)
|
(:approval-status args)
|
||||||
(merge-query {:query {:in ['?approval-status]
|
(merge-query {:query {:in ['?approval-status]
|
||||||
:where ['[?e :transaction/approval-status ?approval-status]]}
|
:where ['[?e :transaction/approval-status ?approval-status]]}
|
||||||
:args [(:approval-status args)]})
|
:args [(:approval-status args)]})
|
||||||
|
|
||||||
(:client-code args)
|
(:client-code args)
|
||||||
(merge-query {:query {:in ['?client-code]
|
(merge-query {:query {:in ['?client-code]
|
||||||
:where ['[?e :transaction/client ?client-id]
|
:where ['[?e :transaction/client ?client-id]
|
||||||
'[?client-id :client/code ?client-code]]}
|
'[?client-id :client/code ?client-code]]}
|
||||||
:args [(:client-code args)]})
|
:args [(:client-code args)]})
|
||||||
|
|
||||||
(:original-id args)
|
(:original-id args)
|
||||||
(merge-query {:query {:in ['?original-id]
|
(merge-query {:query {:in ['?original-id]
|
||||||
:where ['[?e :transaction/client ?c]
|
:where ['[?e :transaction/client ?c]
|
||||||
'[?c :client/original-id ?original-id]]}
|
'[?c :client/original-id ?original-id]]}
|
||||||
:args [(:original-id args)]})
|
:args [(:original-id args)]})
|
||||||
|
|
||||||
(:description args)
|
(:description args)
|
||||||
(merge-query {:query {:in ['?description]
|
(merge-query {:query {:in ['?description]
|
||||||
:where ['[?e :transaction/description-original ?do]
|
:where ['[?e :transaction/description-original ?do]
|
||||||
'[(.contains ?do ?description)]]}
|
'[(.contains ?do ?description)]]}
|
||||||
:args [(:description args)]})
|
:args [(:description args)]})
|
||||||
|
|
||||||
true
|
true
|
||||||
(merge-query {:query {:find ['?base-date '?e] :where ['[?e :transaction/id]
|
(merge-query {:query {:find ['?base-date '?e] :where ['[?e :transaction/id]
|
||||||
'[?e :transaction/date ?base-date]]}}))]
|
'[?e :transaction/date ?base-date]]}}))]
|
||||||
(cond->> query
|
(cond->> query
|
||||||
true (d/query)
|
true (d/query)
|
||||||
true (apply-sort-2 args [:desc :asc])
|
true (apply-sort-2 args [:desc :asc])
|
||||||
true (apply-pagination args))))
|
true (apply-pagination args)))))
|
||||||
|
|
||||||
(defn graphql-results [ids db args]
|
(defn graphql-results [ids db args]
|
||||||
(let [results (->> (d/pull-many db '[* {:transaction/client [:client/name :db/id :client/code]
|
(let [results (->> (d/pull-many db '[* {:transaction/client [:client/name :db/id :client/code]
|
||||||
@@ -160,3 +162,12 @@
|
|||||||
(update :transaction/date c/from-date)
|
(update :transaction/date c/from-date)
|
||||||
(update :transaction/post-date c/from-date)
|
(update :transaction/post-date c/from-date)
|
||||||
(dissoc :transaction/id)))
|
(dissoc :transaction/id)))
|
||||||
|
|
||||||
|
(defn unapprove [ids]
|
||||||
|
(doseq [x (partition-all 1000 ids)]
|
||||||
|
@(d/transact (d/connect uri)
|
||||||
|
(doto (mapv (fn [i]
|
||||||
|
{:db/id i
|
||||||
|
:transaction/approval-status :transaction-approval-status/unapproved})
|
||||||
|
x)
|
||||||
|
println))))
|
||||||
|
|||||||
@@ -611,6 +611,21 @@
|
|||||||
:args {:invoices {:type '(list :id)}}
|
:args {:invoices {:type '(list :id)}}
|
||||||
:resolve :mutation/approve-invoices}
|
:resolve :mutation/approve-invoices}
|
||||||
|
|
||||||
|
:unapprove_transactions {:type '(list :transaction_page)
|
||||||
|
:args {:client_id {:type :id}
|
||||||
|
:vendor_id {:type :id}
|
||||||
|
:bank_account_id {:type :id}
|
||||||
|
:date_range {:type :date_range}
|
||||||
|
:amount_lte {:type :money}
|
||||||
|
:amount_gte {:type :money}
|
||||||
|
:description {:type 'String}
|
||||||
|
:start {:type 'Int}
|
||||||
|
:sort_by {:type 'String}
|
||||||
|
:asc {:type 'Boolean}
|
||||||
|
:approval_status {:type :transaction_approval_status}}
|
||||||
|
|
||||||
|
:resolve :mutation/unapprove-transactions}
|
||||||
|
|
||||||
:merge_vendors {:type :id
|
:merge_vendors {:type :id
|
||||||
:args {:from {:type :id}
|
:args {:from {:type :id}
|
||||||
:to {:type :id}}
|
:to {:type :id}}
|
||||||
@@ -844,6 +859,7 @@
|
|||||||
:mutation/add-and-print-invoice gq-invoices/add-and-print-invoice
|
:mutation/add-and-print-invoice gq-invoices/add-and-print-invoice
|
||||||
:mutation/edit-invoice gq-invoices/edit-invoice
|
:mutation/edit-invoice gq-invoices/edit-invoice
|
||||||
:mutation/edit-transaction gq-transactions/edit-transaction
|
:mutation/edit-transaction gq-transactions/edit-transaction
|
||||||
|
:mutation/unapprove-transactions gq-transactions/unapprove-transactions
|
||||||
:mutation/upsert-transaction-rule gq-transaction-rules/upsert-transaction-rule
|
:mutation/upsert-transaction-rule gq-transaction-rules/upsert-transaction-rule
|
||||||
:test-transaction-rule gq-transaction-rules/test-transaction-rule
|
:test-transaction-rule gq-transaction-rules/test-transaction-rule
|
||||||
:run-transaction-rule gq-transaction-rules/run-transaction-rule
|
:run-transaction-rule gq-transaction-rules/run-transaction-rule
|
||||||
|
|||||||
@@ -39,6 +39,16 @@
|
|||||||
:start (:start args 0)
|
:start (:start args 0)
|
||||||
:end (+ (:start args 0) (count transactions))}]))
|
:end (+ (:start args 0) (count transactions))}]))
|
||||||
|
|
||||||
|
(defn unapprove-transactions [context args value]
|
||||||
|
(let [args (assoc args :id (:id context))
|
||||||
|
ids (:ids (d-transactions/raw-graphql-ids (update (<-graphql args) :approval-status
|
||||||
|
#(some->> %
|
||||||
|
name
|
||||||
|
snake->kebab
|
||||||
|
(keyword "transaction-approval-status")))))]
|
||||||
|
(d-transactions/unapprove ids)
|
||||||
|
(get-transaction-page context args value)))
|
||||||
|
|
||||||
(defn transaction-account->entity [{:keys [id account_id amount location]}]
|
(defn transaction-account->entity [{:keys [id account_id amount location]}]
|
||||||
(remove-nils #:transaction-account {:amount (Double/parseDouble amount)
|
(remove-nils #:transaction-account {:amount (Double/parseDouble amount)
|
||||||
:db/id id
|
:db/id id
|
||||||
|
|||||||
@@ -65,6 +65,27 @@
|
|||||||
:end]]]}
|
:end]]]}
|
||||||
:on-success [::received]}}))
|
:on-success [::received]}}))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::unapprove-all
|
||||||
|
(fn [cofx [_ params]]
|
||||||
|
|
||||||
|
{:db (-> (:db cofx)
|
||||||
|
(assoc-in [:status :loading] true)
|
||||||
|
(assoc-in [::params] params))
|
||||||
|
:graphql {:token (-> cofx :db :user)
|
||||||
|
:query-obj
|
||||||
|
{:venia/operation {:operation/type :mutation
|
||||||
|
:operation/name "UnapproveTransactions"}
|
||||||
|
:venia/queries [{:query/data
|
||||||
|
[:unapprove-transactions
|
||||||
|
(assoc (::params (:db cofx)) :client-id (:id @(re-frame/subscribe [::subs/client])))
|
||||||
|
[[:transactions transaction-read]
|
||||||
|
:total
|
||||||
|
:start
|
||||||
|
:end]]}]}
|
||||||
|
|
||||||
|
:on-success [::received]}}))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::received
|
::received
|
||||||
(fn [db [_ data]]
|
(fn [db [_ data]]
|
||||||
@@ -161,7 +182,9 @@
|
|||||||
[:div.is-pulled-right
|
[:div.is-pulled-right
|
||||||
[:div.buttons
|
[:div.buttons
|
||||||
[:button.button.is-outlined.is-primary {:on-click (dispatch-event [::manual/opening])}
|
[:button.button.is-outlined.is-primary {:on-click (dispatch-event [::manual/opening])}
|
||||||
"Manual Yodlee Import"]]]])
|
"Manual Yodlee Import"]
|
||||||
|
[:button.button.is-outlined.is-danger {:on-click (dispatch-event [::unapprove-all])}
|
||||||
|
"Unapprove all"]]]])
|
||||||
[table/table {:id :transactions
|
[table/table {:id :transactions
|
||||||
:params (re-frame/subscribe [::params])
|
:params (re-frame/subscribe [::params])
|
||||||
:transaction-page (re-frame/subscribe [::transaction-page])
|
:transaction-page (re-frame/subscribe [::transaction-page])
|
||||||
|
|||||||
Reference in New Issue
Block a user