added ability to reload the bank balances automatically.

This commit is contained in:
2021-10-29 14:47:27 -07:00
parent 43e0bc682a
commit edeb1b1f2e
5 changed files with 135 additions and 94 deletions

View File

@@ -163,6 +163,9 @@ nav.navbar .navbar-item.is-active {
display:block; display:block;
background-color: #F9F9F9; background-color: #F9F9F9;
border-right: 1px solid #DEDEDE; border-right: 1px solid #DEDEDE;
@include until(1280px) {
}
} }
.aside .subtitle { .aside .subtitle {

View File

@@ -259,3 +259,19 @@
(dates->date-times) (dates->date-times)
(on-success) (on-success)
(re-frame/dispatch)))))))) (re-frame/dispatch))))))))
(defonce interval-handler
(let [live-intervals (atom {})]
(fn handler [{:keys [action id frequency event]}]
(condp = action
:clean (doall
(map #(handler {:action :end :id %1}) (keys @live-intervals)))
:start (swap! live-intervals assoc id (js/setInterval #(re-frame/dispatch event) frequency))
:end (do (js/clearInterval (get @live-intervals id))
(swap! live-intervals dissoc id))))))
(interval-handler {:action :clean})
(re-frame.core/reg-fx ;; the re-frame API for registering effect handlers
:interval ;; the effect id
interval-handler)

View File

@@ -104,20 +104,37 @@
:user (assoc user :token token) :user (assoc user :token token)
:is-initial-loading? true)})) :is-initial-loading? true)}))
(re-frame/reg-event-db (re-frame/reg-event-fx
::received-initial ::received-initial
(fn [db [_ {accounts :accounts clients :client vendors :vendor :as x}]] (fn [{:keys [db]} [_ {accounts :accounts clients :client vendors :vendor :as x}]]
(-> db {:db (-> db
(assoc :clients (by :id clients) ) (assoc :clients (by :id clients) )
(assoc :vendors (by :id vendors) ) (assoc :vendors (by :id vendors) )
(assoc :is-initial-loading? false) (assoc :is-initial-loading? false)
(assoc :accounts accounts ) (assoc :accounts accounts )
(assoc :client (or (when (= 1 (count clients)) (->> clients first :id )) (assoc :client (or (when (= 1 (count clients)) (->> clients first :id ))
(->> clients (->> clients
(map :id) (map :id)
(filter #(= % (:last-client-id db))) (filter #(= % (:last-client-id db)))
first)))))) first))))
:interval {:action :start
:id :refresh-clients
:frequency 600000
:event [::refresh-clients]}}))
(re-frame/reg-event-fx
::refresh-clients
(fn [{:keys [db]}]
(let [token (-> db :user)]
{:graphql {:token token
:query-obj {:venia/queries [[:client (client-query token)]]}
:on-success [::received-refreshed-clients]}})))
(re-frame/reg-event-fx
::received-refreshed-clients
(fn [{:keys [db]} [_ {clients :client}]]
{:db (assoc db :clients (by :id clients))}))
(re-frame/reg-event-db (re-frame/reg-event-db
::failed-initial ::failed-initial

View File

@@ -125,7 +125,7 @@
(:name client))]) (:name client))])
[grid/cell {} (:name vendor)] [grid/cell {} (:name vendor)]
[grid/cell {} invoice-number] [grid/cell {} invoice-number]
[grid/cell {} (date->str date) ] [grid/cell {:class "is-hidden-mobile"} (date->str date) ]
[grid/cell {} [grid/cell {}
(when due (when due
(if (#{":paid" :paid ":voided" :voided} status) (if (#{":paid" :paid ":voided" :voided} status)
@@ -257,7 +257,7 @@
[grid/sortable-header-cell {:sort-key "invoice-number" :sort-name "Invoice Number"} "Invoice #"] [grid/sortable-header-cell {:sort-key "invoice-number" :sort-name "Invoice Number"} "Invoice #"]
[grid/sortable-header-cell {:sort-key "date" :sort-name "Date" :style {:width "8em"}} "Date"] [grid/sortable-header-cell {:sort-key "date" :sort-name "Date" :style {:width "8em"}} "Date"]
[grid/sortable-header-cell {:sort-key "due" :sort-name "Due" :style {:width "8em"}} "Due"] [grid/sortable-header-cell {:sort-key "due" :sort-name "Due" :style {:width "8em"} :class "is-hidden-mobile"} "Due"]
[grid/sortable-header-cell {:sort-key "location" :sort-name "Location" :style {:width "5em"}} "Loc"] [grid/sortable-header-cell {:sort-key "location" :sort-name "Location" :style {:width "5em"}} "Loc"]
[grid/sortable-header-cell {:sort-key "total" :sort-name "Total" :style {:width "8em"} :class "has-text-right"} "Total"] [grid/sortable-header-cell {:sort-key "total" :sort-name "Total" :style {:width "8em"} :class "has-text-right"} "Total"]

View File

@@ -84,88 +84,93 @@
(assoc-in client-search path value))) (assoc-in client-search path value)))
(defn navbar [ap] (defn navbar [ap]
(let [user (re-frame/subscribe [::subs/user]) (let [navbar-menu-shown? (r/atom false)]
client (re-frame/subscribe [::subs/client]) (fn [ap]
clients (re-frame/subscribe [::subs/clients]) (let [user (re-frame/subscribe [::subs/user])
matching-clients @(re-frame/subscribe [::matching-clients]) client (re-frame/subscribe [::subs/client])
menu (re-frame/subscribe [::subs/menu]) clients (re-frame/subscribe [::subs/clients])
client-search @(re-frame/subscribe [::client-search]) matching-clients @(re-frame/subscribe [::matching-clients])
is-initial-loading @(re-frame/subscribe [::subs/is-initial-loading?])] menu (re-frame/subscribe [::subs/menu])
[:nav {:class "navbar has-shadow is-fixed-top is-grey"} client-search @(re-frame/subscribe [::client-search])
is-initial-loading @(re-frame/subscribe [::subs/is-initial-loading?])]
[:nav {:class "navbar has-shadow is-fixed-top is-grey"}
[:div {:class "container"} [:div {:class "container"}
[:div {:class "navbar-brand"} [:div {:class "navbar-brand"}
[:a {:class "navbar-item", :href "../"} [:a {:class "navbar-item", :href "../"}
[:img {:src "/img/logo.png"}]]] [:img {:src "/img/logo.png"}]]
[:div.navbar-menu [:div {:class "navbar-burger burger", :data-target "navMenu" :on-click (fn [] (swap! navbar-menu-shown? #(not %)))}
(when-not is-initial-loading [:span]
[:div.navbar-start [:span]
[:a.navbar-item {:class [(active-when ap = :index)] [:span]]]
:href (bidi/path-for routes/routes :index)} [:div.navbar-menu {:id "navMenu" :class (if @navbar-menu-shown?
"Home" ] "is-active"
[:a.navbar-item {:class [(active-when ap #{:unpaid-invoices :paid-invoices})] "")}
:href (bidi/path-for routes/routes :unpaid-invoices)} (when-not is-initial-loading
"Invoices" ] [:div.navbar-start
[:a.navbar-item {:class [(active-when ap = :payments)] [:a.navbar-item {:class [(active-when ap = :index)]
:href (bidi/path-for routes/routes :payments)} :href (bidi/path-for routes/routes :index)}
"Payments" ] "Home" ]
(when (= "admin" (:user/role @user)) [:a.navbar-item {:class [(active-when ap #{:unpaid-invoices :paid-invoices})]
[:a.navbar-item {:class [(active-when ap = :sales-orders)] :href (bidi/path-for routes/routes :unpaid-invoices)}
:href (bidi/path-for routes/routes :sales-orders)} "Invoices" ]
"POS" ]) [:a.navbar-item {:class [(active-when ap = :payments)]
[:a.navbar-item {:class [(active-when ap = :transactions)] :href (bidi/path-for routes/routes :payments)}
:href (bidi/path-for routes/routes :transactions)} "Payments" ]
"Transactions" ] (when (= "admin" (:user/role @user))
[:a.navbar-item {:class [(active-when ap = :sales-orders)]
:href (bidi/path-for routes/routes :sales-orders)}
"POS" ])
[:a.navbar-item {:class [(active-when ap = :transactions)]
:href (bidi/path-for routes/routes :transactions)}
"Transactions" ]
(when (not= "manager" (:user/role @user)) (when (not= "manager" (:user/role @user))
[:a.navbar-item {:class [(active-when ap = :ledger)] [:a.navbar-item {:class [(active-when ap = :ledger)]
:href (bidi/path-for routes/routes :ledger)} :href (bidi/path-for routes/routes :ledger)}
"Ledger" ])]) "Ledger" ])])
[:div {:class "navbar-burger burger", :data-target "navMenu"}
[:span] (when-not is-initial-loading
[:span] [:div.navbar-end
[:span]] [:div.navbar-item
(when-not is-initial-loading [buttons/new-button {:event [::vendor-dialog/started {}]
[:div.navbar-end :name "Vendor"
[:div.navbar-item :class "is-primary"}]]
[buttons/new-button {:event [::vendor-dialog/started {}]
:name "Vendor"
:class "is-primary"}]]
(when (> (count @clients) 1) (when (> (count @clients) 1)
[navbar-drop-down {:header (str "Company: " (if @client (:name @client) [navbar-drop-down {:header (str "Company: " (if @client (:name @client)
"All")) "All"))
:id ::select-client} :id ::select-client}
[:div [:div
[:a {:class "navbar-item" [:a {:class "navbar-item"
:on-click (fn [] :on-click (fn []
(re-frame/dispatch [::events/swap-client nil]))} "All" ] (re-frame/dispatch [::events/swap-client nil]))} "All" ]
[:hr {:class "navbar-divider"}] [:hr {:class "navbar-divider"}]
[bind-field [bind-field
[:input.input.navbar-item {:placeholder "Company name" [:input.input.navbar-item {:placeholder "Company name"
:auto-focus true :auto-focus true
:field [:value] :field [:value]
:on-key-up (fn [k] :on-key-up (fn [k]
(when (= 13 (.-which k)) (when (= 13 (.-which k))
(do (do
(re-frame/dispatch [::events/swap-client (first matching-clients)]) (re-frame/dispatch [::events/swap-client (first matching-clients)])
(re-frame/dispatch [::events/toggle-menu ::select-client]) (re-frame/dispatch [::events/toggle-menu ::select-client])
(re-frame/dispatch [::client-search-changed [:value] nil]))) (re-frame/dispatch [::client-search-changed [:value] nil])))
) )
:event [::client-search-changed] :event [::client-search-changed]
:subscription client-search}]] :subscription client-search}]]
(for [{:keys [name id] :as client} matching-clients] (for [{:keys [name id] :as client} matching-clients]
^{:key id } ^{:key id }
[:a {:class "navbar-item" [:a {:class "navbar-item"
:on-click (fn [] :on-click (fn []
(re-frame/dispatch [::events/swap-client client])) (re-frame/dispatch [::events/swap-client client]))
} name])]])])] } name])]])])]
(when-not is-initial-loading (when-not is-initial-loading
[login-dropdown])] [login-dropdown])]
])) ]))))
(defn footer [] (defn footer []