ledger final fixes
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.graphql.utils :refer [->graphql limited-clients]]
|
||||
[auto-ap.utils :refer [dollars-0?]]
|
||||
[auto-ap.datomic :refer [merge-query apply-sort-3 apply-pagination add-sorter-fields]]
|
||||
[auto-ap.datomic :refer [merge-query apply-sort-3 apply-pagination add-sorter-fields conn]]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[clj-time.coerce :as c]
|
||||
[clj-time.core :as time]))
|
||||
@@ -141,7 +141,7 @@
|
||||
(map first))))
|
||||
|
||||
(defn get-graphql [args]
|
||||
(let [db (d/db (d/connect uri))
|
||||
(let [db (d/db conn)
|
||||
{ids-to-retrieve :ids matching-count :count} (raw-graphql-ids db args)]
|
||||
|
||||
[(->> (graphql-results ids-to-retrieve db args))
|
||||
@@ -149,9 +149,17 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#_(get-graphql {})
|
||||
(defn filter-ids [ids]
|
||||
(if ids
|
||||
(->> {:query {:find ['?e]
|
||||
:in ['$ '[?e ...]]
|
||||
:where ['[?e :journal-entry/date]]}
|
||||
:args [(d/db conn) ids]}
|
||||
(d/query)
|
||||
(map first)
|
||||
vec)
|
||||
[]))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -206,7 +206,26 @@
|
||||
(assoc entry :error (.getMessage e))))))
|
||||
|
||||
(defn delete-external-ledger [context args value]
|
||||
)
|
||||
(let [_ (assert-admin (:id context))
|
||||
args (assoc args :id (:id context))
|
||||
ids (some-> (:filters args)
|
||||
(assoc :only-external true)
|
||||
(<-graphql)
|
||||
(assoc :per-page Integer/MAX_VALUE)
|
||||
(#(l/raw-graphql-ids (d/db conn) %))
|
||||
:ids)
|
||||
specific-ids (l/filter-ids (:ids args))
|
||||
all-ids (into (set ids) specific-ids)]
|
||||
(if (> (count all-ids) 1000)
|
||||
{:message (str "You can only delete 1000 ledger entries at a time.")}
|
||||
(do
|
||||
(log/info "Deleting " (count all-ids) args)
|
||||
(audit-transact-batch
|
||||
(map (fn [i]
|
||||
[:db/retractEntity i])
|
||||
all-ids)
|
||||
(:id context))
|
||||
{:message (str "Succesfully deleted " (count all-ids) " ledger entries.")}))))
|
||||
|
||||
(defn import-ledger [context args value]
|
||||
(assert-admin (:id context))
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
[auto-ap.datomic.accounts :as a]
|
||||
[auto-ap.datomic :refer [uri remove-nils conn]]
|
||||
[clojure.spec.alpha :as s]
|
||||
[auto-ap.utils :refer [dollars-0?] ]
|
||||
[clojure.tools.logging :as log]
|
||||
[auto-ap.logging :refer [info-event]]
|
||||
[unilog.context :as lc]))
|
||||
@@ -45,7 +46,8 @@
|
||||
:invoice/import-status '[:db/ident]}] id)]
|
||||
(when-not (or (= true (:invoice/exclude-from-ledger entity))
|
||||
(= :import-status/pending (:db/ident (:invoice/import-status entity)))
|
||||
(= :invoice-status/voided (:db/ident (:invoice/status entity))))
|
||||
(= :invoice-status/voided (:db/ident (:invoice/status entity)))
|
||||
(dollars-0? (:invoice/total entity)))
|
||||
(remove-nils
|
||||
{:journal-entry/source "invoice"
|
||||
:journal-entry/client (:db/id (:invoice/client entity))
|
||||
@@ -78,7 +80,8 @@
|
||||
decreasing? (< (:transaction/amount entity) 0.0)
|
||||
credit-from-bank? decreasing?
|
||||
debit-from-bank? (not decreasing?)]
|
||||
(when-not (= :transaction-approval-status/excluded (:db/ident (:transaction/approval-status entity)))
|
||||
(when-not (or (= :transaction-approval-status/excluded (:db/ident (:transaction/approval-status entity)))
|
||||
(dollars-0? (:transaction/amount entity)))
|
||||
(remove-nils
|
||||
{:journal-entry/source "transaction"
|
||||
:journal-entry/client (:db/id (:transaction/client entity))
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
(:error state)
|
||||
"An unexpected error occured.")]))])
|
||||
(if (seq info-states)
|
||||
[:div.notification
|
||||
[:div.notification.is-info.is-light
|
||||
(for [state states]
|
||||
(do
|
||||
^{:key (:info state)}
|
||||
|
||||
@@ -63,7 +63,8 @@
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted
|
||||
(fn [{:keys [db]} _]
|
||||
{:dispatch [::data-page/dispose ::page]
|
||||
{:dispatch-n [[::data-page/dispose ::page]
|
||||
[::status/dispose-single ::delete-selected]]
|
||||
::track/dispose {:id ::params}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
@@ -73,13 +74,39 @@
|
||||
:subscription [::data-page/params ::page]
|
||||
:event-fn (fn [params] [::params-change params])}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::delete-successful
|
||||
(fn [cofx [_ result params]]
|
||||
{:dispatch-n [[::params-change params]
|
||||
[::status/info ::delete-selected (:message (:delete-external-ledger result))]]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::delete-selected
|
||||
(fn [cofx [_ params]]
|
||||
(let [checked @(re-frame/subscribe [::data-page/checked ::page])
|
||||
checked-params (get checked "header")
|
||||
specific-ledger-entries (map :id (vals (dissoc checked "header")))]
|
||||
{:db (:db cofx)
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:owns-state {:single ::delete-selected}
|
||||
:query-obj
|
||||
{:venia/operation {:operation/type :mutation
|
||||
:operation/name "DeleteExternalLedger"}
|
||||
:venia/queries [{:query/data
|
||||
[:delete-external-ledger
|
||||
{:filters (some-> checked-params data-params->query-params)
|
||||
:ids specific-ledger-entries}
|
||||
[:message]]}]}
|
||||
:on-success (fn [result]
|
||||
[::delete-successful result params])}})))
|
||||
|
||||
(defn ledger-content []
|
||||
(let [current-client @(re-frame/subscribe [::subs/client])
|
||||
params @(re-frame/subscribe [::data-page/params ::page])
|
||||
checked @(re-frame/subscribe [::data-page/checked ::page])]
|
||||
[:div
|
||||
[:h1.title "External Ledger"]
|
||||
[status/status-notification {:statuses [[::status/single ::delete-selected]]}]
|
||||
[:div.is-pulled-right
|
||||
[:div.buttons
|
||||
(into [:div.tags ] (map (fn [[z {:keys [id external-id]}]]
|
||||
@@ -91,10 +118,10 @@
|
||||
[:button.delete.is-small {:on-click
|
||||
(dispatch-event [::data-page/remove-check ::page id])}]]))
|
||||
checked))
|
||||
[:button.button.is-danger {#_#_:on-click (dispatch-event [::delete-selected params])
|
||||
[:button.button.is-danger {:on-click (dispatch-event [::delete-selected params])
|
||||
:class (status/class-for @(re-frame/subscribe [::status/single ::delete-selected]))
|
||||
:disabled true #_(or (status/disabled-for @(re-frame/subscribe [::status/single ::delete-selected]))
|
||||
(not (seq checked)))}
|
||||
:disabled (or (status/disabled-for @(re-frame/subscribe [::status/single ::delete-selected]))
|
||||
(not (seq checked)))}
|
||||
"Delete selected"]]]
|
||||
[table/table {:id :ledger
|
||||
:data-page ::page}]]))
|
||||
|
||||
Reference in New Issue
Block a user