From 7d0320dfcccf758bd3333a95774fbef2011eb101 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Thu, 3 Mar 2022 09:18:32 -0800 Subject: [PATCH] source filtering and making it so 0s get deleted --- resources/sample-ledger.csv | 4 +++ src/clj/auto_ap/datomic/ledger.clj | 5 +++ src/clj/auto_ap/graphql.clj | 1 + src/clj/auto_ap/graphql/ledger.clj | 32 +++++++++++-------- .../views/pages/ledger/external_ledger.cljs | 1 + .../auto_ap/views/pages/ledger/side_bar.cljs | 7 ++++ 6 files changed, 37 insertions(+), 13 deletions(-) diff --git a/resources/sample-ledger.csv b/resources/sample-ledger.csv index 506bec9b..b797befc 100644 --- a/resources/sample-ledger.csv +++ b/resources/sample-ledger.csv @@ -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 aonet DEMO Payroll 123551123 12/19/2018 2750 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 diff --git a/src/clj/auto_ap/datomic/ledger.clj b/src/clj/auto_ap/datomic/ledger.clj index 59d4d384..77f614cd 100644 --- a/src/clj/auto_ap/datomic/ledger.clj +++ b/src/clj/auto_ap/datomic/ledger.clj @@ -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]]} diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 8134081a..9fbcdc7a 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -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} diff --git a/src/clj/auto_ap/graphql/ledger.clj b/src/clj/auto_ap/graphql/ledger.clj index 73b579c4..be6b9794 100644 --- a/src/clj/auto_ap/graphql/ledger.clj +++ b/src/clj/auto_ap/graphql/ledger.clj @@ -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 diff --git a/src/cljs/auto_ap/views/pages/ledger/external_ledger.cljs b/src/cljs/auto_ap/views/pages/ledger/external_ledger.cljs index 1cd4ec72..84fd1b7e 100644 --- a/src/cljs/auto_ap/views/pages/ledger/external_ledger.cljs +++ b/src/cljs/auto_ap/views/pages/ledger/external_ledger.cljs @@ -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}) diff --git a/src/cljs/auto_ap/views/pages/ledger/side_bar.cljs b/src/cljs/auto_ap/views/pages/ledger/side_bar.cljs index d46a6b2f..a1d93c85 100644 --- a/src/cljs/auto_ap/views/pages/ledger/side_bar.cljs +++ b/src/cljs/auto_ap/views/pages/ledger/side_bar.cljs @@ -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