Files
integreat/src/cljs/auto_ap/views/pages/transactions/table.cljs
Bryce Covert 452e663049 several fixes.
2019-04-24 21:29:38 -07:00

127 lines
5.3 KiB
Clojure

(ns auto-ap.views.pages.transactions.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.pages.transactions.form :as edit]
[auto-ap.views.utils :refer [date->str dispatch-event nf]]
[goog.string :as gstring]
[re-frame.core :as re-frame]))
(re-frame/reg-event-fx
::editing-matches-found
(fn [{:keys [db]} [_ which payment-matches]]
{:dispatch
[::edit/editing which (:potential-payment-matches payment-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)
:query-obj {:venia/queries [{:query/data [:potential-payment-matches
{:transaction_id (:id which)}
[:id :memo :check-number [:vendor [:name]]]]}]}
:on-success [::editing-matches-found which]
:on-error [::editing-matches-failed which]}} ))
(defn table [{:keys [id transaction-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 transaction-page status on-params-change vendors checked]}]
(let [{:keys [sort-by asc]} @params
{:keys [transactions start end count total]} @transaction-page
selected-client @(re-frame/subscribe [::subs/client])
percentage-size (if selected-client "25%" "33%")]
[:div
[paginator {:start start :end end :count count :total total
:on-change (fn [p ]
(on-params-change (merge @params p)))}]
[:table.table.is-fullwidth
[:thead
[:tr
(when-not selected-client
[sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"}
:sort-key "client"
:sort-by sort-by
:asc asc}
"Client"])
[sorted-column {:on-sort opc
:style {:width percentage-size :cursor "pointer"}
:sort-key "description-original"
:sort-by sort-by
:asc asc}
"Vendor"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "date"
:sort-by sort-by
:asc asc}
"Date"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "amount"
:class "has-text-right"
:sort-by sort-by
:asc asc}
"Amount"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "account"
:class "has-text-right"
:sort-by sort-by
:asc asc}
"Account"]
[sorted-column {:on-sort opc
:style {:width "8em" :cursor "pointer"}
:sort-key "status"
:sort-by sort-by
:asc asc}
"Status"]
[:th {:width percentage-size} "Bank account"]
[:th {:style {:width "10em"}} "" ]]]
[:tbody
(if (:loading @status)
[:tr
[:td {:col-span 5}
[:i.fa.fa-spin.fa-spinner]]]
(for [{:keys [client account vendor payment status bank-account description-original date amount id yodlee-merchant ] :as i} (:transactions @transaction-page)]
^{:key id}
[:tr {:class (:class i)}
(when-not selected-client
[:td (:name client)])
[:td (cond vendor
(:name vendor)
yodlee-merchant
[:i.has-text-grey (str "Merchant '" (:name yodlee-merchant) "'")]
:else
[:i.has-text-grey (str "Unknown Merchant")])]
#_[:td description-original]
[:td (date->str date) ]
[:td.has-text-right (nf amount )]
[:td (:name account)]
[:td status]
[:td (:name bank-account )]
[:td
[:a.button {:on-click (dispatch-event [::intend-to-edit i])} [:span [:span.icon [:i.fa.fa-pencil]]]]
(when payment
[:a.tag {:href (:s3-url payment) :target "_new"}
#_[:i.fa.fa-money-check]
[:span.icon [:i.fa.fa-money]]
(str " " (:check-number payment) " (" (gstring/format "$%.2f" amount ) ")")])]
]))]]]))))