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

View File

@@ -30,6 +30,11 @@
:where ['[?e :journal-entry/client ?client-id]]} :where ['[?e :journal-entry/client ?client-id]]}
:args [(:client-id args)]}) :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) (:client-code args)
(merge-query {:query {:in ['?client-code] (merge-query {:query {:in ['?client-code]
:where ['[?e :journal-entry/client ?client-id] :where ['[?e :journal-entry/client ?client-id]

View File

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

View File

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

View File

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

View File

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

View File

@@ -2,9 +2,33 @@
(:require [auto-ap.routes :as routes] (:require [auto-ap.routes :as routes]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.views.utils :refer [active-when]] [auto-ap.views.utils :refer [active-when]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[bidi.bidi :as bidi] [bidi.bidi :as bidi]
[re-frame.core :as re-frame])) [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 [] (defn ledger-side-bar []
(let [ap @(re-frame/subscribe [::subs/active-page]) (let [ap @(re-frame/subscribe [::subs/active-page])
user @(re-frame/subscribe [::subs/user])] user @(re-frame/subscribe [::subs/user])]
@@ -35,4 +59,11 @@
[:a.item {:href (bidi/path-for routes/routes :external-import-ledger) [:a.item {:href (bidi/path-for routes/routes :external-import-ledger)
:class [(active-when ap = :external-import-ledger)]} :class [(active-when ap = :external-import-ledger)]}
[:span.icon [:i {:class "fa fa-download"}]] [: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] [goog.string :as gstring]
[re-frame.core :as re-frame])) [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]}] (re-frame/reg-sub
(let [opc (fn [p] ::table-params
(on-params-change (merge @params p )))] (fn [db]
(fn [{:keys [id ledger-page status on-params-change vendors checked status?] (::table-params db)))
: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-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 [sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"} :style {:width percentage-size :cursor "pointer"}
:sort-key "vendor" :sort-key "client"
:sort-name "Vendor" :sort-name "Client"
:sort sort} :sort sort}
"Vendor"] "Client"])
[sorted-column {:on-sort opc [sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"} :style {:width percentage-size :cursor "pointer"}
:sort-key "date" :sort-key "vendor"
:sort-name "Date" :sort-name "Vendor"
:sort sort} :sort sort}
"Date"] "Vendor"]
[:th
{:style {:width percentage-size }} [sorted-column {:on-sort opc
"Account"] :style {:width "8em" :cursor "pointer"}
[sorted-column {:on-sort opc :sort-key "date"
:style {:width "8em" :cursor "pointer"} :sort-name "Date"
:sort-key "amount" :sort sort}
:sort-name "Amount" "Date"]
:class "has-text-right" [:th
:sort sort} {:style {:width percentage-size }}
"Debit"] "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 [sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"} :style {:width "8em" :cursor "pointer"}
:sort-key "amount" :sort-key "status"
:sort-name "Amount" :sort-name "Status"
:class "has-text-right"
:sort sort} :sort sort}
"Credit"] "Status"])]]
[:tbody
(if (:loading @status)
(when status? [:tr
[:td {:col-span 5}
[sorted-column {:on-sort opc [:i.fa.fa-spin.fa-spinner]]]
:style {:width "8em" :cursor "pointer"} (->>
:sort-key "status" (for [{:keys [client vendor status date amount id line-items] :as i} (:journal-entries @ledger-page)]
:sort-name "Status" (into
:sort sort} [^{:key id}
"Status"])]] [:tr {:class (:class i)}
[:tbody (when-not selected-client
(if (:loading @status) [:td (:name client)])
[:tr [:td (if vendor
[:td {:col-span 5} (:name vendor)
[:i.fa.fa-spin.fa-spinner]]] [:i.has-text-grey (str "Unknown Merchant")])]
(->> #_[:td description-original]
(for [{:keys [client vendor status date amount id line-items] :as i} (:journal-entries @ledger-page)] [:td (date->str date) ]
(into [:td ]
[^{:key id} [:td.has-text-right (nf amount )]
[:tr {:class (:class i)} [:td.has-text-right (nf amount )]
(when-not selected-client
[:td (:name client)]) (when status?
[:td (if vendor [:td status])]]
(:name vendor) (for [{:keys [debit credit location account]} line-items]
[:i.has-text-grey (str "Unknown Merchant")])] [:tr {:class (:class i)}
#_[:td description-original] (when-not selected-client
[:td (date->str date) ] [:td ])
[:td ] [:td ]
[:td.has-text-right (nf amount )] #_[:td description-original]
[:td.has-text-right (nf amount )] [:td ]
[:td (if (:name account)
(when status? (str location ": " (:name account))
[:td status])]] [:i "unknown"])]
(for [{:keys [debit credit location account]} line-items] [:td.has-text-right (when debit (nf debit ))]
[:tr {:class (:class i)} [:td.has-text-right (when credit (nf credit ))]
(when-not selected-client
[:td ]) (when status?
[:td ] [:td status])]
#_[:td description-original] )))
[:td ] (mapcat identity)))]]])))
[: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 :yodlee-merchant :id :potential-payment-matches
:location :accounts :approval-status :location :accounts :approval-status
:matched-rule]) :matched-rule])
(assoc :original-status (:approval-status which))
(assoc :potential-payment-matches (if (:matched-rule which) (assoc :potential-payment-matches (if (:matched-rule which)
nil nil
potential-payment-matches)) potential-payment-matches))
@@ -182,8 +183,11 @@
(let [change-event [::forms/change ::form] (let [change-event [::forms/change ::form]
{:keys [data] } @(re-frame/subscribe [::forms/form ::form]) {:keys [data] } @(re-frame/subscribe [::forms/form ::form])
locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))]) locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))])
{:keys [form field raw-field error-notification submit-button ]} transaction-form] {:keys [form field raw-field error-notification submit-button ]} transaction-form
[form {:title "Hello" :edit-completed edit-completed} 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?]) (when (and @(re-frame/subscribe [::subs/is-admin?])
(get-in data [:yodlee-merchant])) (get-in data [:yodlee-merchant]))
@@ -195,7 +199,7 @@
" - " " - "
(get-in data [:yodlee-merchant :yodlee-id]))}]]) (get-in data [:yodlee-merchant :yodlee-id]))}]])
(when @(re-frame/subscribe [::subs/is-admin?]) (when is-admin?
[field "Matched Rule" [field "Matched Rule"
[:input.input {:type "text" [:input.input {:type "text"
:field [:matched-rule :note] :field [:matched-rule :note]
@@ -209,16 +213,17 @@
:field [:description-original] :field [:description-original]
:disabled "disabled"}]] :disabled "disabled"}]]
(when (and (seq (:potential-transaction-rule-matches data)) (when (and (seq (:potential-transaction-rule-matches data))
(not (:matched-rule 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) [potential-transaction-rule-matches-box {:potential-transaction-rule-matches (:potential-transaction-rule-matches data)
:edit-completed edit-completed}]) :edit-completed edit-completed}])
(when (and (seq (:potential-payment-matches data)) (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) [potential-payment-matches-box {:potential-payment-matches (:potential-payment-matches data)
:edit-completed edit-completed}]) :edit-completed edit-completed}])
@@ -231,14 +236,16 @@
:type "typeahead-entity" :type "typeahead-entity"
:auto-focus true :auto-focus true
:field [:vendor] :field [:vendor]
:disabled (boolean (:payment data))}]] :disabled (or (boolean (:payment data))
should-disable-for-client?)}]]
[field nil [field nil
[expense-accounts-field [expense-accounts-field
{:type "expense-accounts" {:type "expense-accounts"
:field [:accounts] :field [:accounts]
:max (Math/abs (js/parseFloat (:amount data))) :max (Math/abs (js/parseFloat (:amount data)))
:descriptor "credit account" :descriptor "credit account"
:disabled (boolean (:payment data)) :disabled (or (boolean (:payment data))
should-disable-for-client?)
:locations locations}]] :locations locations}]]
@@ -251,9 +258,11 @@
:options [[:unapproved "Unapproved"] :options [[:unapproved "Unapproved"]
[:requires-feedback "Client Review"] [:requires-feedback "Client Review"]
[:approved "Approved"] [:approved "Approved"]
[:excluded "Excluded from Ledger"]]}]] [:excluded "Excluded from Ledger"]]
:disabled should-disable-for-client?}]]
[:hr] [:hr]
[error-notification] [error-notification]
[submit-button "Save"]])])]) (when-not should-disable-for-client?
[submit-button "Save"])])])])