117 lines
5.5 KiB
Clojure
117 lines
5.5 KiB
Clojure
(ns auto-ap.views.pages.transactions.table
|
|
(:require [auto-ap.events :as events]
|
|
[auto-ap.subs :as subs]
|
|
[auto-ap.views.components.dropdown
|
|
:refer
|
|
[drop-down drop-down-contents]]
|
|
[auto-ap.views.components.grid :as grid]
|
|
[auto-ap.views.pages.transactions.form :as edit]
|
|
[auto-ap.views.utils
|
|
:refer
|
|
[action-cell-width date->str dispatch-event nf]]
|
|
[goog.string :as gstring]
|
|
[re-frame.core :as re-frame]
|
|
[auto-ap.views.components.buttons :as buttons]
|
|
[auto-ap.status :as status]
|
|
[auto-ap.views.pages.data-page :as data-page]))
|
|
|
|
(re-frame/reg-event-fx
|
|
::editing-matches-found
|
|
(fn [{:keys [db]} [_ which matches]]
|
|
{:dispatch
|
|
[::edit/editing which (:potential-payment-matches matches) (:potential-autopay-invoices-matches matches) (:potential-transaction-rule-matches matches)]}))
|
|
|
|
(re-frame/reg-event-fx
|
|
::editing-matches-failed
|
|
(fn [{:keys [db]} [_ which payment-matches]]
|
|
{:dispatch
|
|
[::edit/editing which payment-matches]}))
|
|
|
|
(re-frame/reg-event-fx
|
|
::intend-to-edit
|
|
(fn [{:keys [db]} [_ which]]
|
|
{:graphql
|
|
{:token (-> db :user)
|
|
:owns-state {:multi ::edits
|
|
:which (:id which)}
|
|
:query-obj {:venia/queries (into [{:query/data [:potential-payment-matches
|
|
{:transaction_id (:id which)}
|
|
[:id :memo :check-number [:vendor [:name]]]]}
|
|
{:query/data [:potential-autopay-invoices-matches
|
|
{:transaction_id (:id which)}
|
|
[:id :invoice-number :total :date :scheduled-payment [:vendor [:name]]]]}]
|
|
(when @(re-frame/subscribe [::subs/is-admin?])
|
|
[{:query/data [:potential-transaction-rule-matches
|
|
{:transaction_id (:id which)}
|
|
[:id :note]]}]))}
|
|
:on-success [::editing-matches-found which]
|
|
:on-error [::editing-matches-failed which]}}))
|
|
|
|
(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)}))
|
|
|
|
(defn table [{:keys [id data-page check-boxes?]}]
|
|
(let [selected-client @(re-frame/subscribe [::subs/client])
|
|
{:keys [data status params]} @(re-frame/subscribe [::data-page/page data-page])
|
|
states @(re-frame/subscribe [::status/multi ::edits])]
|
|
[grid/grid {:data-page data-page
|
|
:column-count (if selected-client 6 7)
|
|
:check-boxes? check-boxes?}
|
|
[grid/controls data]
|
|
[grid/table {:fullwidth true}
|
|
[grid/header {}
|
|
[grid/row {:id "header"
|
|
:entity params}
|
|
(when-not selected-client
|
|
[grid/sortable-header-cell {:sort-key "client" :sort-name "Client"} "Client"])
|
|
[grid/sortable-header-cell {:sort-key "account" :sort-name "Bank Account"} "Bank Account"]
|
|
[grid/sortable-header-cell {:sort-key "vendor" :sort-name "Vendor"} "Vendor"]
|
|
[grid/sortable-header-cell {:sort-key "date" :sort-name "Date" :style {:width "8em"}} "Date"]
|
|
[grid/sortable-header-cell {:sort-key "amount" :sort-name "Amount" :class "has-text-right" :style {:width "8em"}} "Amount"]
|
|
[grid/sortable-header-cell {:sort-key "status" :sort-name "Status" :style {:width "7em"}} "Status"]
|
|
[grid/header-cell {:style {:width (action-cell-width 3)}}]]]
|
|
[grid/body
|
|
(for [{:keys [client account vendor approval-status payment status bank-account description-original date amount id yodlee-merchant ] :as i} (:data data)]
|
|
^{:key id}
|
|
[grid/row {:class (:class i) :id id :entity i}
|
|
(when-not selected-client
|
|
[grid/cell {} (:name client)])
|
|
|
|
#_[:td description-original]
|
|
[grid/cell {} (:name bank-account )]
|
|
[grid/cell {} (cond vendor
|
|
(:name vendor)
|
|
yodlee-merchant
|
|
[:i.has-text-grey (str "Merchant '" (:name yodlee-merchant) "'")]
|
|
|
|
:else
|
|
[:i.has-text-grey (str description-original)])]
|
|
[grid/cell {} (date->str date) ]
|
|
[grid/cell {:class "has-text-right"} (nf amount )]
|
|
[grid/cell {} status]
|
|
[grid/button-cell {}
|
|
[:div.buttons
|
|
[drop-down {:id [::expense-accounts id ]
|
|
:header [buttons/sl-icon {:aria-haspopup true
|
|
:event [::events/toggle-menu [::expense-accounts id]]
|
|
:tab-index "0"
|
|
:icon "icon-saving-bank-1"}]}
|
|
[drop-down-contents
|
|
[:div
|
|
[:span.dropdown-item description-original ]]]]
|
|
[buttons/fa-icon {:event [::intend-to-edit i]
|
|
:class (status/class-for (get states id))
|
|
:icon "fa-pencil"}]
|
|
(when payment
|
|
[:a.tag {:href (:s3-url payment) :target "_new"}
|
|
[:span.icon [:i.fa.fa-money]]
|
|
(str " " (:check-number payment) " (" (gstring/format "$%.2f" amount ) ")")])]]])]]]))
|