Streamlining invoices

This commit is contained in:
Bryce Covert
2020-08-10 14:13:19 -07:00
parent 9dede12b61
commit 5bc0e957ef
13 changed files with 185 additions and 67 deletions

View File

@@ -132,10 +132,10 @@
[:div.buttons
(when (seq expense-accounts)
[drop-down {:id [::expense-accounts id ]
:header [:a.button.badge {:data-badge (str (clojure.core/count expense-accounts))
:aria-haspopup true
:on-click (dispatch-event [::events/toggle-menu [::expense-accounts id]])
:tab-index "0"} "Accounts"]}
:header [buttons/sl-icon {:class "badge"
:event [::events/toggle-menu [::expense-accounts id]]
:data-badge (str (clojure.core/count expense-accounts))
:icon "icon-navigation-menu"}]}
[drop-down-contents
[:div
(for [e expense-accounts]
@@ -147,6 +147,32 @@
(when expense-event
[:a.dropdown-item.is-primary {:on-click (dispatch-event (conj expense-event i))} "Change"])]]])
[:span {:style {:margin-left "1em"}}]
(when (seq payments)
[:<>
[drop-down {:id [::payments id]
:header [buttons/sl-icon {:class "badge"
:event [::events/toggle-menu [::payments id]]
:data-badge (str (clojure.core/count payments))
:icon "icon-accounting-bill"}]}
[:div
(for [payment payments]
(if (:check-number (:payment payment))
^{:key (:id payment)}
[:a.dropdown-item {:href (str (bidi/path-for routes/routes :payments )
"?"
(url/map->query {:check-number-like (:check-number (:payment payment))}))
:target "_new"}
[:i.fa.fa-money-check]
[:span.icon [:i.fa.fa-money]]
(str " " (:check-number (:payment payment)) " (" (gstring/format "$%.2f" (:amount payment) ) ")")]
^{:key (:id payment)}
[:span.dropdown-item [:span.icon {:class [(when (= :cleared (:status (:payment payment)))
"has-text-success")]}
[:i.fa.fa-money]] (str " " (:check-number (:payment payment)) " (" (gstring/format "$%.2f" (:amount payment) ) ") "
(when (= :cleared (:status (:payment payment)))
(str " - " (:post-date (:transaction (:payment payment))))))]))]]
[:span {:style {:margin-right "1em"}}]])
(when (not= ":voided" (:status i))
[buttons/fa-icon {:icon "fa-pencil"
:event [::form/editing i]}])
@@ -155,37 +181,12 @@
:event [::void-invoice i]}])
(when (= ":voided" (:status i))
[buttons/fa-icon {:icon "fa-undo"
:event [::unvoid-invoice i]}])
(when (seq payments)
[drop-down {:id [::payments id]
:header [:button.button.badge {:data-badge (str (clojure.core/count payments))
:aria-haspopup true
:tab-index "0"
:on-click (dispatch-event [::events/toggle-menu [::payments id]])
} "Payments"]}
[:div
(for [payment payments]
(if (:check-number (:payment payment))
^{:key (:id payment)}
[:a.dropdown-item {:href (str (bidi/path-for routes/routes :payments )
"?"
(url/map->query {:check-number-like (:check-number (:payment payment))}))
:target "_new"}
[:i.fa.fa-money-check]
[:span.icon [:i.fa.fa-money]]
(str " " (:check-number (:payment payment)) " (" (gstring/format "$%.2f" (:amount payment) ) ")")]
^{:key (:id payment)}
[:span.dropdown-item [:span.icon {:class [(when (= :cleared (:status (:payment payment)))
"has-text-success")]}
[:i.fa.fa-money]] (str " " (:check-number (:payment payment)) " (" (gstring/format "$%.2f" (:amount payment) ) ") "
(when (= :cleared (:status (:payment payment)))
(str " - " (:post-date (:transaction (:payment payment))))))]))]])]]]))
:event [::unvoid-invoice i]}])]]]))
(defn invoice-table [{:keys [id invoice-page status vendors check-boxes checked on-check-changed expense-event overrides]}]
(let [selected-client @(re-frame/subscribe [::subs/client])
{:keys [sort]} @(re-frame/subscribe [::table-params])
{:keys [invoices outstanding start end count total]} @invoice-page
{:keys [invoices outstanding]} invoice-page
selected-client @(re-frame/subscribe [::subs/client])
is-loading? (= :loading status)
is-sorted-by-vendor? (and (= "vendor" (:sort-key (first sort)))
@@ -200,15 +201,15 @@
[(update-in acc [(dec (clojure.core/count acc))] #(conj (or % []) invoice))
(:id (:vendor invoice))]))
[[] nil]
(:invoices @invoice-page))
[[(:invoices @invoice-page)]])]
(:invoices invoice-page))
[[(:invoices invoice-page)]])]
[grid/grid {:on-params-change (fn [p]
(re-frame/dispatch [::params-changed p]))
:params @(re-frame/subscribe [::table-params])
:status status
;; TODO checkboxes
:column-count (if selected-client 8 9)}
[grid/controls @invoice-page
[grid/controls invoice-page
[:div.level-item
"Outstanding " (nf outstanding)]]
(for [invoices invoice-groups]
@@ -232,7 +233,7 @@
[grid/sortable-header-cell {:sort-key "total" :sort-name "Total" :style {:width "8em"} :class "has-text-right"} "Total"]
[grid/sortable-header-cell {:sort-key "outstanding-balance" :sort-name "Outstanding" :style {:width "10em"} :class "has-text-right"} "Outstanding"]
[grid/header-cell {:style {:width "20rem" }}]
[grid/header-cell {:style {:width "14rem" }}]
]]
[grid/body

View File

@@ -15,7 +15,9 @@
[cljsjs.dropzone :as dropzone]
[cljs.reader :as edn]
[clojure.string :as str]
[vimsical.re-frame.cofx.inject :as inject]))
[vimsical.re-frame.cofx.inject :as inject]
[auto-ap.status :as status]
[vimsical.re-frame.fx.track :as track]))
(defn dropzone []
(let [client (re-frame/subscribe [::subs/client])
token (re-frame/subscribe [::subs/token])
@@ -23,7 +25,6 @@
(reagent/create-class
{:display-name "dropzone"
:component-did-mount (fn [this]
(println "HERE?")
(js/Dropzone. (rdom/dom-node this)
(clj->js {:init (fn []
(.on (js-this) "success" (fn [_ files]
@@ -87,6 +88,19 @@
(fn [cofx [_ params]]
{:dispatch [::params-change @(re-frame/subscribe [::params])]}))
(re-frame/reg-event-fx
::mounted
(fn [cofx [_ params]]
{::track/register {:id ::params
:subscription [::params]
:event-fn (fn [params]
[::params-change params])}}))
(re-frame/reg-event-fx
::unmounted
(fn [cofx [_ params]]
{::track/dispose {:id ::params}}))
(re-frame/reg-event-fx
::completed
(fn [cofx [_ params]]
@@ -95,35 +109,24 @@
:db (-> (:db cofx)
(update ::batch inc))}))
(re-frame/reg-sub
::last-params
(fn [db]
(-> db ::last-params)))
(re-frame/reg-sub
::params
:<- [::last-params]
:<- [::subs/client]
:<- [::invoice-table/table-params]
(fn [[last-params client table-params]]
(println "RE-EVALUATING")
(let [params (cond-> {:import-status "pending"}
client (assoc :client-id (:id client))
(seq table-params) (merge table-params))]
(when (not= params last-params)
(re-frame/dispatch [::params-change]))
params)))
(fn [[client table-params]]
(cond-> {:import-status "pending"}
client (assoc :client-id (:id client))
(seq table-params) (merge table-params))))
(re-frame/reg-event-fx
::params-change
[with-user (re-frame/inject-cofx ::inject/sub [::params])]
(fn [{:keys [db user] ::keys [params]} [_]]
{:db (-> db
(dissoc ::error)
(assoc-in [:status :loading] true)
(assoc-in [::last-params] params))
(dissoc ::error))
:graphql {:token user
:owns-state {:single ::page}
:query-obj (invoice-table/query params)
:on-success [::received]}}))
@@ -147,6 +150,7 @@
(fn [{:keys [db]} [_ invoices on-success]]
{:graphql
{:token (-> db :user)
:owns-state {:single ::reject}
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "RejectInvoices"}
@@ -161,6 +165,7 @@
(fn [{:keys [db]} [_ invoices on-success]]
{:graphql
{:token (-> db :user)
:owns-state {:single ::approve}
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "ApproveInvoices"}
@@ -195,6 +200,7 @@
[:div.is-pulled-right
[:button.button.is-success {:on-click (dispatch-event [::approve-invoices-clicked checked])
:class (status/class-for @(re-frame/subscribe [::status/single ::approve]))
:disabled (if (seq checked)
""
"disabled")}
@@ -207,6 +213,7 @@
[:span " "]]
[:button.button.is-danger {:on-click (dispatch-event [::reject-invoices-clicked checked])
:class (status/class-for @(re-frame/subscribe [::status/single ::reject]))
:disabled (if (seq checked)
""
"disabled")}
@@ -247,7 +254,7 @@
[approve-reject-button (:checked @invoice-page)]
(if (seq (:invoices @invoice-page))
[invoice-table {:id :approved
:invoice-page invoice-page
:invoice-page @invoice-page
:overrides {:client (fn [row]
[:p (:name (:client row))
[:p [:i.is-size-7 (:client-identifier row)]]])}
@@ -255,10 +262,12 @@
:checked (:checked @invoice-page)
:on-check-changed (fn [which invoice]
(re-frame/dispatch [::toggle-check which invoice]))
:status (re-frame/subscribe [::subs/status])}]
:status @(re-frame/subscribe [::status/single ::page])}]
[:span "No pending invoices"])]]]))
{:component-will-mount (fn []
(re-frame/dispatch-sync [::invalidated]))}))
{:component-did-mount (fn []
(re-frame/dispatch-sync [::mounted]))
:component-will-unmount (fn []
(re-frame/dispatch-sync [::unmounted]))}))
(defn import-invoices-page []
[side-bar-layout {:side-bar [invoices-side-bar {}]

View File

@@ -605,7 +605,7 @@
(when (= status :unpaid)
[pay-button {:print-checks-shown? print-checks-shown? :checked-invoices checked :print-checks-loading? print-checks-loading?}])
[table/invoice-table {:id :unpaid
:invoice-page (re-frame/subscribe [::invoice-page])
:invoice-page @(re-frame/subscribe [::invoice-page])
:status @(re-frame/subscribe [::status/single ::page])
:check-boxes (= status :unpaid)