Adds ability to link across entities more.

This commit is contained in:
Bryce Covert
2021-01-24 13:25:41 -08:00
parent e2cdb3c719
commit 611ecc438d
5 changed files with 69 additions and 21 deletions

View File

@@ -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}

View File

@@ -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))))

View File

@@ -46,6 +46,7 @@
{:filters (data-params->query-params params)}
[[:journal-entries [:id
:source
:original-entity
:amount
:note
:cleared-against

View File

@@ -247,6 +247,7 @@
{:filters (data-params->query-params ledger-params)}
[[:journal-entries [:id
:source
:original-entity
:amount
:alternate-description
[:vendor

View File

@@ -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)]