This commit is contained in:
Bryce Covert
2020-04-27 09:30:30 -07:00
parent b89b4a86c5
commit 25f1cebe51
9 changed files with 196 additions and 127 deletions

View File

@@ -23,6 +23,7 @@ services:
- 3000
depends_on:
- database
- datomic-transactor
environment:
config: /usr/local/config/local.edn
VIRTUAL_HOST: local.app.integreatconsult.com
@@ -36,6 +37,8 @@ services:
volumes:
- ./data/var/lib/postgresql/data:/var/lib/postgresql/data
datomic-transactor:
depends_on:
- database
image: 679918342773.dkr.ecr.us-east-1.amazonaws.com/datomic:latest
environment:
- DATOMIC_HOST=datomic-transactor

View File

@@ -30,6 +30,11 @@
:where ['[?e :journal-entry/client ?client-id]]}
:args [(:client-id args)]})
(:vendor-id args)
(merge-query {:query {:in ['?vendor-id]
:where ['[?e :journal-entry/vendor ?vendor-id]]}
:args [(:vendor-id args)]})
(:client-code args)
(merge-query {:query {:in ['?client-code]
:where ['[?e :journal-entry/client ?client-id]

View File

@@ -436,6 +436,7 @@
:ledger_page {:type :ledger_page
:args {:client_id {:type :id}
:vendor_id {:type :id}
:bank_account_id {:type :id}
:from_date {:type :iso_date}
:to_date {:type :iso_date}
@@ -786,7 +787,6 @@
->graphql
(first (d-checks/get-graphql (assoc (<-graphql args) :count Integer/MAX_VALUE)))))
(defn get-user [context args value]
(assert-admin (:id context))

View File

@@ -116,7 +116,7 @@
(defn process-one [report-queue]
(let [transaction (.take report-queue)
_ (println "processing transaction" transaction)
_ (println "processing transaction")
db (:db-after transaction)
affected-entities (->> (:tx-data transaction)
(map (fn [^datomic.db.Datum x]
@@ -144,6 +144,7 @@
(def break (atom false))
(defn process-all []
(println "Starting worker")
(while (and (not @break)
(not (Thread/interrupted)))
(process-one (d/tx-report-queue (d/connect uri) ))))

View File

@@ -1,6 +1,6 @@
(ns auto-ap.views.components.button-radio)
(defn button-radio [{:keys [options on-change value]}]
(defn button-radio [{:keys [options on-change value disabled]}]
[:div.control
[:div.field.has-addons
(for [[k v] options]
@@ -9,4 +9,5 @@
[:a.button {:class (if (= value k)
"is-primary"
"")
:disabled disabled
:on-click (fn [] (on-change k))} v]])]])

View File

@@ -10,7 +10,7 @@
[auto-ap.views.components.paginator :refer [paginator]]
[auto-ap.views.components.sorter :refer [sorted-column]]
[auto-ap.views.pages.ledger.table :as table]
[auto-ap.views.pages.ledger.side-bar :refer [ledger-side-bar]]
[auto-ap.views.pages.ledger.side-bar :refer [ledger-side-bar] :as side-bar]
[auto-ap.views.pages.transactions.common :refer [transaction-read]]
[auto-ap.utils :refer [replace-by]]
@@ -27,18 +27,24 @@
(re-frame/reg-sub
::params
(fn [db]
(-> db (::params {}))))
:<- [::subs/client]
:<- [::side-bar/filter-params]
:<- [::table/table-params]
(fn [[client filter-params table-params]]
(cond-> {}
client (assoc :client-id (:id client))
(seq filter-params) (merge filter-params)
(seq table-params) (merge @(re-frame/subscribe [::table/table-params])))))
(re-frame/reg-event-fx
::params-change
(fn [cofx [_ params]]
{:db (-> (:db cofx)
(assoc-in [:status :loading] true)
(assoc-in [::params] params))
(assoc-in [:status :loading] true))
:graphql {:token (-> cofx :db :user)
:query-obj {:venia/queries [[:ledger-page
(assoc params :client-id (:id @(re-frame/subscribe [::subs/client])))
@(re-frame/subscribe [::params])
[[:journal-entries [:id
:source
:amount
@@ -64,7 +70,7 @@
(assoc ::ledger-page (:ledger-page data))
(assoc-in [:status :loading] false))))
(re-frame/reg-event-db
#_(re-frame/reg-event-db
::change-selected-bank-account
(fn [db [_ key value]]
(let [[key] key
@@ -95,6 +101,6 @@
(defn ledger-page []
[side-bar-layout
{:side-bar [ledger-side-bar]
{:side-bar [ledger-side-bar]
:main [ledger-content]}])

View File

@@ -2,9 +2,33 @@
(:require [auto-ap.routes :as routes]
[auto-ap.subs :as subs]
[auto-ap.views.utils :refer [active-when]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[bidi.bidi :as bidi]
[re-frame.core :as re-frame]))
(re-frame/reg-sub
::filters
(fn [db ]
(::filters db {})))
(re-frame/reg-sub
::filter
:<- [::filters]
(fn [filters [_ which]]
(filters which)))
(re-frame/reg-sub
::filter-params
:<- [::filters]
(fn [filters]
{:vendor-id (:id (:vendor filters))}))
(re-frame/reg-event-fx
::filter-changed
(fn [{:keys [db]} [_ which val]]
{:dispatch [:auto-ap.views.pages.ledger/params-change]
:db (assoc-in db [::filters which] val)}))
(defn ledger-side-bar []
(let [ap @(re-frame/subscribe [::subs/active-page])
user @(re-frame/subscribe [::subs/user])]
@@ -35,4 +59,11 @@
[:a.item {:href (bidi/path-for routes/routes :external-import-ledger)
:class [(active-when ap = :external-import-ledger)]}
[:span.icon [:i {:class "fa fa-download"}]]
[:span {:class "name"} "External Import"]]])]]))
[:span {:class "name"} "External Import"]]])
[:p.menu-label "Vendor"]
[:div
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
:on-change #(re-frame/dispatch [::filter-changed :vendor %])
:match->text :name
:type "typeahead-entity"
:value @(re-frame/subscribe [::filter :vendor])}]]]]))

View File

@@ -7,117 +7,130 @@
[goog.string :as gstring]
[re-frame.core :as re-frame]))
(defn table [{:keys [id ledger-page status on-params-change vendors params check-boxes checked on-check-changed expense-event]}]
(let [opc (fn [p]
(on-params-change (merge @params p )))]
(fn [{:keys [id ledger-page status on-params-change vendors checked status?]
:or {status? true}}]
(let [{:keys [sort]} @params
{:keys [journal-entries start end count total]} @ledger-page
selected-client @(re-frame/subscribe [::subs/client])
percentage-size (if selected-client "25%" "33%")]
[:div
[:div.level
[:div.level-left
[:div.level-item
[paginator {:start start :end end :count count :total total
:on-change (fn [p ]
(on-params-change (merge @params p)))}]]
[:div.level-item
[sort-by-list {:sort sort
:on-change opc}]]]]
[:table.table.is-fullwidth.compact
[:thead
[:tr
(when-not selected-client
[sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"}
:sort-key "client"
:sort-name "Client"
:sort sort}
"Client"])
(re-frame/reg-sub
::table-params
(fn [db]
(::table-params db)))
(re-frame/reg-event-fx
::params-changed
[(re-frame/path [::table-params])]
(fn [{table-params :db} [_ params :as z]]
{:db (merge table-params params)
:dispatch [:auto-ap.views.pages.ledger/params-change]}
))
(defn table [{:keys [id ledger-page status vendors params check-boxes checked on-check-changed expense-event]}]
(fn [{:keys [id ledger-page status vendors checked status?]
:or {status? true}}]
(let [{:keys [sort]} @params
{:keys [journal-entries start end count total]} @ledger-page
selected-client @(re-frame/subscribe [::subs/client])
percentage-size (if selected-client "25%" "33%")
opc (fn [e]
(re-frame/dispatch [::params-changed e]))]
[:div
[:div.level
[:div.level-left
[:div.level-item
[paginator {:start start :end end :count count :total total
:on-change opc}]]
[:div.level-item
[sort-by-list {:sort sort
:on-change opc}]]]]
[:table.table.is-fullwidth.compact
[:thead
[:tr
(when-not selected-client
[sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"}
:sort-key "vendor"
:sort-name "Vendor"
:sort-key "client"
:sort-name "Client"
:sort sort}
"Vendor"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "date"
:sort-name "Date"
:sort sort}
"Date"]
[:th
{:style {:width percentage-size }}
"Account"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "amount"
:sort-name "Amount"
:class "has-text-right"
:sort sort}
"Debit"]
"Client"])
[sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"}
:sort-key "vendor"
:sort-name "Vendor"
:sort sort}
"Vendor"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "date"
:sort-name "Date"
:sort sort}
"Date"]
[:th
{:style {:width percentage-size }}
"Account"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "amount"
:sort-name "Amount"
:class "has-text-right"
:sort sort}
"Debit"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "amount"
:sort-name "Amount"
:class "has-text-right"
:sort sort}
"Credit"]
(when status?
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "amount"
:sort-name "Amount"
:class "has-text-right"
:sort-key "status"
:sort-name "Status"
:sort sort}
"Credit"]
(when status?
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "status"
:sort-name "Status"
:sort sort}
"Status"])]]
[:tbody
(if (:loading @status)
[:tr
[:td {:col-span 5}
[:i.fa.fa-spin.fa-spinner]]]
(->>
(for [{:keys [client vendor status date amount id line-items] :as i} (:journal-entries @ledger-page)]
(into
[^{:key id}
[:tr {:class (:class i)}
(when-not selected-client
[:td (:name client)])
[:td (if vendor
(:name vendor)
[:i.has-text-grey (str "Unknown Merchant")])]
#_[:td description-original]
[:td (date->str date) ]
[:td ]
[:td.has-text-right (nf amount )]
[:td.has-text-right (nf amount )]
(when status?
[:td status])]]
(for [{:keys [debit credit location account]} line-items]
[:tr {:class (:class i)}
(when-not selected-client
[:td ])
[:td ]
#_[:td description-original]
[:td ]
[:td (if (:name account)
(str location ": " (:name account))
[:i "unknown"])]
[:td.has-text-right (when debit (nf debit ))]
[:td.has-text-right (when credit (nf credit ))]
(when status?
[:td status])]
)))
(mapcat identity)))]]]))))
"Status"])]]
[:tbody
(if (:loading @status)
[:tr
[:td {:col-span 5}
[:i.fa.fa-spin.fa-spinner]]]
(->>
(for [{:keys [client vendor status date amount id line-items] :as i} (:journal-entries @ledger-page)]
(into
[^{:key id}
[:tr {:class (:class i)}
(when-not selected-client
[:td (:name client)])
[:td (if vendor
(:name vendor)
[:i.has-text-grey (str "Unknown Merchant")])]
#_[:td description-original]
[:td (date->str date) ]
[:td ]
[:td.has-text-right (nf amount )]
[:td.has-text-right (nf amount )]
(when status?
[:td status])]]
(for [{:keys [debit credit location account]} line-items]
[:tr {:class (:class i)}
(when-not selected-client
[:td ])
[:td ]
#_[:td description-original]
[:td ]
[:td (if (:name account)
(str location ": " (:name account))
[:i "unknown"])]
[:td.has-text-right (when debit (nf debit ))]
[:td.has-text-right (when credit (nf credit ))]
(when status?
[:td status])]
)))
(mapcat identity)))]]])))

View File

@@ -52,6 +52,7 @@
:yodlee-merchant :id :potential-payment-matches
:location :accounts :approval-status
:matched-rule])
(assoc :original-status (:approval-status which))
(assoc :potential-payment-matches (if (:matched-rule which)
nil
potential-payment-matches))
@@ -182,8 +183,11 @@
(let [change-event [::forms/change ::form]
{:keys [data] } @(re-frame/subscribe [::forms/form ::form])
locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))])
{:keys [form field raw-field error-notification submit-button ]} transaction-form]
[form {:title "Hello" :edit-completed edit-completed}
{:keys [form field raw-field error-notification submit-button ]} transaction-form
is-admin? @(re-frame/subscribe [::subs/is-admin?])
should-disable-for-client? (and (not is-admin?)
(not= :requires-feedback (:original-status data)))]
[form {:title "Transaction" :edit-completed edit-completed}
(when (and @(re-frame/subscribe [::subs/is-admin?])
(get-in data [:yodlee-merchant]))
@@ -195,7 +199,7 @@
" - "
(get-in data [:yodlee-merchant :yodlee-id]))}]])
(when @(re-frame/subscribe [::subs/is-admin?])
(when is-admin?
[field "Matched Rule"
[:input.input {:type "text"
:field [:matched-rule :note]
@@ -209,16 +213,17 @@
:field [:description-original]
:disabled "disabled"}]]
(when (and (seq (:potential-transaction-rule-matches data))
(not (:matched-rule data))
(not (:payment data)))
(not (:payment data))
is-admin?)
[potential-transaction-rule-matches-box {:potential-transaction-rule-matches (:potential-transaction-rule-matches data)
:edit-completed edit-completed}])
(when (and (seq (:potential-payment-matches data))
(not (:payment data)))
(not (:payment data))
is-admin?)
[potential-payment-matches-box {:potential-payment-matches (:potential-payment-matches data)
:edit-completed edit-completed}])
@@ -231,14 +236,16 @@
:type "typeahead-entity"
:auto-focus true
:field [:vendor]
:disabled (boolean (:payment data))}]]
:disabled (or (boolean (:payment data))
should-disable-for-client?)}]]
[field nil
[expense-accounts-field
{:type "expense-accounts"
:field [:accounts]
:max (Math/abs (js/parseFloat (:amount data)))
:descriptor "credit account"
:disabled (boolean (:payment data))
:disabled (or (boolean (:payment data))
should-disable-for-client?)
:locations locations}]]
@@ -251,9 +258,11 @@
:options [[:unapproved "Unapproved"]
[:requires-feedback "Client Review"]
[:approved "Approved"]
[:excluded "Excluded from Ledger"]]}]]
[:excluded "Excluded from Ledger"]]
:disabled should-disable-for-client?}]]
[:hr]
[error-notification]
[submit-button "Save"]])])])
(when-not should-disable-for-client?
[submit-button "Save"])])])])