source filtering and making it so 0s get deleted

This commit is contained in:
2022-03-03 09:18:32 -08:00
parent 223a3749ec
commit 7d0320dfcc
6 changed files with 37 additions and 13 deletions

View File

@@ -64,6 +64,11 @@
'[(.contains ^String ?external-id ?external-id-like)]]}
:args [(:external-id-like args)]})
(seq (:source args))
(merge-query {:query {:in ['?source]
:where ['[?e :journal-entry/source ?source]]}
:args [(:source args)]})
(:vendor-id args)
(merge-query {:query {:in ['?vendor-id]
:where ['[?e :journal-entry/vendor ?vendor-id]]}

View File

@@ -535,6 +535,7 @@
:per_page {:type 'Int}
:only_external {:type 'Boolean}
:external_id_like {:type 'String}
:source {:type 'String}
:sort {:type '(list :sort_item)}}}
:edit_location_match {:fields {:location {:type 'String}

View File

@@ -10,17 +10,14 @@
[auto-ap.parse.util :as parse]
[auto-ap.utils :refer [by dollars=]]
[clj-time.coerce :as coerce]
[clj-time.core :as time]
[clojure.string :as str]
[clojure.tools.logging :as log]
[datomic.api :as d]
[unilog.context :as lc]
[yang.scheduler :as scheduler]
[mount.core :as mount]))
(mount/defstate running-balance-cache
:start (atom {}))
(defn get-ledger-page [context args value]
(defn get-ledger-page [context args _]
(let [args (assoc args :id (:id context))
[journal-entries journal-entries-count] (l/get-graphql (assoc (<-graphql (:filters args))
:id (:id context)))
@@ -170,7 +167,7 @@
:args [(d/db (d/connect uri)) client-id]})
(sort-by first)))
(defn get-balance-sheet [context args value]
(defn get-balance-sheet [context args _]
(let [client-id (:client_id args)
_ (assert-can-see-client (:id context) client-id)
end-date (coerce/to-date (:date args))
@@ -183,7 +180,7 @@
(:include_comparison args) (assoc :comparable-balance-sheet-accounts (roll-up-until lookup-account all-ledger-entries comparable-date))
true ->graphql)))
(defn get-profit-and-loss [context args value]
(defn get-profit-and-loss [context args _]
(let [client-id (:client_id args)
client-ids (or (some-> client-id vector)
(:client_ids args))
@@ -198,8 +195,7 @@
lookup-account (->> client-ids
(map (fn [client-id]
[client-id (build-account-lookup client-id)]))
(into {}))
client-id (first client-ids)]
(into {}))]
(->graphql
{:periods
(->> (:periods args)
@@ -219,7 +215,7 @@
:status (or (:status (ex-data e))
:error))))))
(defn delete-external-ledger [context args value]
(defn delete-external-ledger [context args _]
(let [_ (assert-admin (:id context))
args (assoc args :id (:id context))
ids (some-> (:filters args)
@@ -241,7 +237,7 @@
(:id context))
{:message (str "Succesfully deleted " (count all-ids) " ledger entries.")}))))
(defn import-ledger [context args value]
(defn import-ledger [context args _]
(assert-admin (:id context))
(lc/with-context {:area "import ledger"}
(let [all-vendors (by :vendor/name (d-vendors/get-graphql {}))
@@ -263,7 +259,7 @@
{}
(d-clients/get-all))
new-hidden-vendors (reduce
(fn [new-vendors {:keys [vendor_name line_items]}]
(fn [new-vendors {:keys [vendor_name]}]
(if (or (all-vendors vendor_name)
(new-vendors vendor_name))
new-vendors
@@ -369,12 +365,22 @@
ignored (filter #(= (:status %) :ignored) transaction)
success (filter #(= (:status %) :success) transaction)
retraction (mapv (fn [x] [:db/retractEntity [:journal-entry/external-id (:external_id x)]])
success)]
success)
ignore-retraction (->> ignored
(map :external_id )
(d/q '[:find [?je ...]
:in $ [?ei ...]
:where [?je :journal-entry/external-id ?ei]]
(d/db conn)
)
(map (fn [je] [:db/retractEntity je])))]
(log/info "manual ledger import has " (count success) " new rows")
(log/info errors)
(audit-transact-batch retraction (:id context))
(when (seq ignore-retraction)
(audit-transact-batch ignore-retraction (:id context)))
#_(log/info (map :tx success))
(audit-transact-batch (map :tx success) (:id context))
@@ -400,7 +406,7 @@
[{} {}])
(second)
(reduce-kv
(fn [acc jel {:keys [debit credit count account-id]}]
(fn [acc jel {:keys [debit credit account-id]}]
(let [account (lookup-account account-id)
account-type (:account_type account)]
(assoc acc jel

View File

@@ -25,6 +25,7 @@
:account-id (:id (:account params))
:bank-account-id (:id (:bank-account params))
:external-id-like (:external-id params)
:source (:source params)
:amount-gte (:amount-gte (:amount-range params))
:amount-lte (:amount-lte (:amount-range params))
:only-external true})

View File

@@ -95,6 +95,13 @@
(when (= :external-ledger ap)
[:<>
[:p.menu-label "Source"]
[:div
[:div.field
[:div.control [:input.input {:placeholder "Source"
:value @(re-frame/subscribe [::data-page/filter data-page :source])
:on-change (dispatch-value-change [::data-page/filter-changed data-page :source])} ]]]]
[:p.menu-label "External ID"]
[:div
[:div.field