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

@@ -6,3 +6,7 @@ GHI DEMO Payroll 123551123 12/19/2018 21550 HQ 100 0
aosentuh DEMO Payroll 123551123 12/19/2018 21550 HQ 100 0 aosentuh DEMO Payroll 123551123 12/19/2018 21550 HQ 100 0
aonet DEMO Payroll 123551123 12/19/2018 2750 HQ 0 50 aonet DEMO Payroll 123551123 12/19/2018 2750 HQ 0 50
1923 DEMO Payroll 123551123 12/19/2018 2950 HQ 0 50 1923 DEMO Payroll 123551123 12/19/2018 2950 HQ 0 50
1923 ABC Payroll 123551123 12/19/2018 24400 HQ 0 50
1923 ABC Payroll 123551123 12/19/2018 25200 HQ 50 0
1 DEF DEMO Payroll 223551123 12/19/2018 2950 HQ 0 50
6 aosentuh DEMO Payroll 123551123 12/19/2018 21550 HQ 100 0
7 aonet DEMO Payroll 123551123 12/19/2018 2750 HQ 0 50
8 1923 DEMO Payroll 123551123 12/19/2018 2950 HQ 0 50
9 1923 ABC Payroll 123551123 12/19/2018 24400 HQ 0 50
10 1923 ABC Payroll 123551123 12/19/2018 25200 HQ 50 0
11
12

View File

@@ -64,6 +64,11 @@
'[(.contains ^String ?external-id ?external-id-like)]]} '[(.contains ^String ?external-id ?external-id-like)]]}
:args [(:external-id-like args)]}) :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) (:vendor-id args)
(merge-query {:query {:in ['?vendor-id] (merge-query {:query {:in ['?vendor-id]
:where ['[?e :journal-entry/vendor ?vendor-id]]} :where ['[?e :journal-entry/vendor ?vendor-id]]}

View File

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

View File

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

View File

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

View File

@@ -95,6 +95,13 @@
(when (= :external-ledger ap) (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"] [:p.menu-label "External ID"]
[:div [:div
[:div.field [:div.field