From 46fbd4fab6f366810e31847d33ccaec07c1145e8 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Wed, 14 Dec 2022 11:25:14 -0800 Subject: [PATCH] Another tweak --- src/clj/auto_ap/graphql/ledger.clj | 35 ++++++++++++++++-------- src/cljs/auto_ap/views/pages/ledger.cljs | 8 ++++-- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/clj/auto_ap/graphql/ledger.clj b/src/clj/auto_ap/graphql/ledger.clj index f3ce8ebd..61c88329 100644 --- a/src/clj/auto_ap/graphql/ledger.clj +++ b/src/clj/auto_ap/graphql/ledger.clj @@ -58,21 +58,34 @@ (.getBytes (with-open [w (java.io.StringWriter.)] (csv/write-csv w - (into [["Client" "Vendor" "Date" "Journal Entry" "Journal Entry Line" "Account" "Debit" "Credit"]] + (into [["Client" "Vendor" "Date" "Journal Entry" "Journal Entry Line" "Account Code" "Account Name" "Account Type" "Debit" "Credit" "Net"]] (->> journal-entries (mapcat (fn [j] (map (fn [li] - [(-> j :journal-entry/client :client/code) - (-> j :journal-entry/vendor :vendor/name) - (atime/unparse (coerce/to-date-time (-> j :journal-entry/date)) - atime/normal-date) - (-> j :db/id) - (-> li :db/id) - (-> li :journal-entry-line/account :account/name) - (-> li :journal-entry-line/debit) - (-> li :journal-entry-line/credit) - ]) + (let [account-type (or (:db/ident (:account/type (:journal-entry-line/account li))) + ({:bank-account-type/check :account-type/asset + :bank-account-type/cash :account-type/asset + :bank-account-type/credit :account-type/liability} + (:db/ident (:bank-account/type (:account li)))))] + [(-> j :journal-entry/client :client/code) + (-> j :journal-entry/vendor :vendor/name) + (atime/unparse (coerce/to-date-time (-> j :journal-entry/date)) + atime/normal-date) + (-> j :db/id) + (-> li :db/id) + (-> li :journal-entry-line/account :account/numeric-code) + (-> li :journal-entry-line/account :account/name) + (some-> account-type name ) + (-> li :journal-entry-line/debit) + (-> li :journal-entry-line/credit) + (if (#{:account-type/asset + :account-type/dividend + :account-type/expense} account-type) + (- (or (-> li :journal-entry-line/debit) 0.0) (or (-> li :journal-entry-line/credit) 0.0)) + (- (or (-> li :journal-entry-line/credit) 0.0) (or (-> li :journal-entry-line/debit) 0.0))) + + ])) (:journal-entry/line-items j)) )))) :quote? (constantly true)) diff --git a/src/cljs/auto_ap/views/pages/ledger.cljs b/src/cljs/auto_ap/views/pages/ledger.cljs index 7650a20c..a20b098f 100644 --- a/src/cljs/auto_ap/views/pages/ledger.cljs +++ b/src/cljs/auto_ap/views/pages/ledger.cljs @@ -9,6 +9,7 @@ :refer [ledger-side-bar]] [auto-ap.views.pages.ledger.table :as table] [auto-ap.views.utils :refer [with-user date->str standard]] + [auto-ap.status :as status] [cljs-time.core :as time] [clojure.set :as set] [re-frame.core :as re-frame] @@ -103,7 +104,8 @@ (defn action-buttons [] (let [params @(re-frame/subscribe [::data-page/params ::page]) csv-content @(re-frame/subscribe [::csv-content]) - is-admin? @(re-frame/subscribe [::subs/is-admin?])] + is-admin? @(re-frame/subscribe [::subs/is-admin?]) + status @(re-frame/subscribe [::status/single [::data-page/page ::page]])] (when is-admin? (if csv-content [:a {:href (str "data:attachment/csv;base64," csv-content) @@ -111,7 +113,9 @@ :download (str "ledger.csv")} "Click here to download"] [buttons/event-button {:event [::export-csv] - :name "Export"}])))) + :name "Export" + :class (status/class-for status) + :disabled (status/disabled-for status)}])))) (defn ledger-content [] [:div