From 611ecc438d118729cea7109eaf4e5c60afbb2014 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sun, 24 Jan 2021 13:25:41 -0800 Subject: [PATCH] Adds ability to link across entities more. --- src/clj/auto_ap/graphql.clj | 1 + src/clj/auto_ap/graphql/ledger.clj | 22 +++---- src/cljs/auto_ap/views/pages/ledger.cljs | 1 + .../views/pages/ledger/profit_and_loss.cljs | 1 + .../auto_ap/views/pages/ledger/table.cljs | 65 ++++++++++++++++--- 5 files changed, 69 insertions(+), 21 deletions(-) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 149999a3..205e03e6 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -231,6 +231,7 @@ {:fields {:id {:type :id} :source {:type 'String} :external_id {:type 'String} + :original_entity {:type :id} :amount {:type 'String} :note {:type 'String} :cleared_against {:type 'String} diff --git a/src/clj/auto_ap/graphql/ledger.clj b/src/clj/auto_ap/graphql/ledger.clj index 6bb58696..23b665d3 100644 --- a/src/clj/auto_ap/graphql/ledger.clj +++ b/src/clj/auto_ap/graphql/ledger.clj @@ -22,21 +22,21 @@ (defn get-ledger-page [context args value] (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))) + journal-entries (mapv (fn [je] - (update je :journal-entry/line-items - (fn [jels] - (mapv - (fn [jel] - (assoc jel :running-balance (get-in @running-balance-cache [(:db/id (:journal-entry/client je)) - (:db/id jel)]))) + (-> je + (update :journal-entry/original-entity :db/id) + (update :journal-entry/line-items + (fn [jels] + (mapv + (fn [jel] + (assoc jel :running-balance (get-in @running-balance-cache [(:db/id (:journal-entry/client je)) + (:db/id jel)]))) - jels) - )) - ) + jels))))) journal-entries)] (result->page journal-entries journal-entries-count :journal_entries (:filters args)))) diff --git a/src/cljs/auto_ap/views/pages/ledger.cljs b/src/cljs/auto_ap/views/pages/ledger.cljs index 97de9612..5b149c26 100644 --- a/src/cljs/auto_ap/views/pages/ledger.cljs +++ b/src/cljs/auto_ap/views/pages/ledger.cljs @@ -46,6 +46,7 @@ {:filters (data-params->query-params params)} [[:journal-entries [:id :source + :original-entity :amount :note :cleared-against diff --git a/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs b/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs index b5e865cd..999f780a 100644 --- a/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs +++ b/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs @@ -247,6 +247,7 @@ {:filters (data-params->query-params ledger-params)} [[:journal-entries [:id :source + :original-entity :amount :alternate-description [:vendor diff --git a/src/cljs/auto_ap/views/pages/ledger/table.cljs b/src/cljs/auto_ap/views/pages/ledger/table.cljs index e2dfc5b5..99dada75 100644 --- a/src/cljs/auto_ap/views/pages/ledger/table.cljs +++ b/src/cljs/auto_ap/views/pages/ledger/table.cljs @@ -1,15 +1,21 @@ (ns auto-ap.views.pages.ledger.table - (:require [auto-ap.subs :as subs] - [auto-ap.views.components.paginator :refer [paginator]] - [auto-ap.views.components.sorter :refer [sorted-column]] - [auto-ap.views.components.sort-by-list :refer [sort-by-list]] - [auto-ap.views.utils :refer [date->str dispatch-event nf]] - [goog.string :as gstring] - [re-frame.core :as re-frame] + (:require [auto-ap.events :as events] + [auto-ap.routes :as routes] + [auto-ap.subs :as subs] + [auto-ap.views.components.buttons :as buttons] + [auto-ap.views.components.dropdown + :refer + [drop-down drop-down-contents]] [auto-ap.views.components.grid :as grid] - [auto-ap.views.pages.data-page :as data-page])) + [auto-ap.views.pages.data-page :as data-page] + [auto-ap.views.utils + :refer + [date->str dispatch-event-with-propagation nf action-cell-width]] + [bidi.bidi :as bidi] + [cemerick.url :as url] + [re-frame.core :as re-frame])) -(defn ledger-row [{{:keys [client vendor alternate-description status date amount id line-items] :as i} :row +(defn ledger-row [{{:keys [client vendor alternate-description status date amount id line-items source original-entity] :as i} :row :keys [selected-client accounts-by-id bank-accounts-by-id]}] [:<> [grid/row {:class (:class i) :id id} @@ -22,7 +28,42 @@ [grid/cell {} (date->str date) ] [grid/cell {} ] [grid/cell {:class "has-text-right"} (nf amount )] - [grid/cell {:class "has-text-right"} (nf amount )]] + [grid/cell {:class "has-text-right"} (nf amount )] + [grid/button-cell {} + (when (#{"invoice" "transaction"} source) + [drop-down {:id [::links id] + :is-right? true + :header [buttons/fa-icon {:class "badge" + :on-click (dispatch-event-with-propagation [::events/toggle-menu [::links id]]) + :data-badge (str 1) + :icon "fa-paperclip"}]} + [drop-down-contents + [:div.dropdown-item + [:table.table.grid.compact + [:tbody + (cond + (= "invoice" source) + [:tr + [:td + "Invoice"] + [:td + [buttons/fa-icon {:icon "fa-external-link" + :href (str (bidi/path-for routes/routes :invoices ) + "?" + (url/map->query {:exact-match-id original-entity}))}]]] + (= "transaction" source) + [:tr + [:td + "Transaction"] + [:td + [buttons/fa-icon {:icon "fa-external-link" + :href (str (bidi/path-for routes/routes :transactions ) + "?" + (url/map->query {:exact-match-id original-entity}))}]]] + + :else + nil + )]]]]])]] [:<> (for [{:keys [debit credit location account id running-balance]} line-items :let [account (or (accounts-by-id (:id account)) @@ -39,6 +80,9 @@ [:i "unknown"])] [grid/cell {:class "has-text-right"} (when debit (nf debit ))] [grid/cell {:class "has-text-right"} (when credit (nf credit ))] + [grid/button-cell {} + ] + #_[grid/cell {:class "has-text-right"} (when running-balance (nf running-balance ))]])]]) (defn table [{:keys [id data-page status vendors on-check-changed expense-event]}] @@ -59,6 +103,7 @@ [grid/header-cell {} "Account"] [grid/sortable-header-cell {:sort-key "amount" :sort-name "Amount" :class "has-text-right" :style {:width "7em"}} "Debit"] [grid/sortable-header-cell {:sort-key "amount" :sort-name "Amount" :class "has-text-right" :style {:width "7em"}} "Credit"] + [grid/header-cell {:style {:width (action-cell-width 1)}}] #_[grid/header-cell {:class "has-text-right" :style {:width "10em"}} "Running Balance"]]] [grid/body (for [{:keys [client vendor status date amount id line-items] :as i} (:data data)]