multi clients complete.

This commit is contained in:
2021-10-23 10:18:09 -07:00
parent 66ad411e3d
commit 43e0bc682a

View File

@@ -70,6 +70,15 @@
"ZZZZZZ" "ZZZZZZ"
x)))))) x))))))
(re-frame/reg-sub
::multi-client?
:<- [::forms/form ::form]
(fn [db]
(> (->> db
:data
:clients
count) 1 )))
(re-frame/reg-sub (re-frame/reg-sub
::error ::error
(fn [db] (fn [db]
@@ -130,7 +139,18 @@
(transduce (transduce
(comp (comp
(map parse-amounts) (map parse-amounts)
(map #(by (juxt :numeric-code :location) (:accounts %)))) (map #(->> (:accounts %)
(group-by (juxt :numeric-code :location))
(map (fn [[k v]]
[k
(reduce (fn [a n]
(-> a
(update :count (fn [z] (+ z (:count n))))
(update :amount (fn [z] (+ z (:amount n))))))
(first v)
(rest v))]))
(into {}))))
conj conj
[] []
@@ -181,8 +201,7 @@
[(date->str start standard) [(date->str start standard)
(date->str end standard)]) (date->str end standard)])
(:periods (:data db))) (:periods (:data db)))
:client (select-keys (:client (:data db)) :clients (mapv #(select-keys % [:name :id]) (:clients (:data db))) }
[:name :id])}
:db (dissoc db :report)}))) :db (dissoc db :report)})))
@@ -429,7 +448,8 @@
;; TODO do we need squashing locations? ;; TODO do we need squashing locations?
(defn grouping [{:keys [header type groupings location periods all-accounts]}] (defn grouping [{:keys [header type groupings location periods all-accounts]}]
(let [include-deltas @(re-frame/subscribe [::include-deltas])] (let [include-deltas @(re-frame/subscribe [::include-deltas])
multi-client? @(re-frame/subscribe [::multi-client?])]
[:<> [:<>
(doall (doall
(for [[grouping-name from to] groupings (for [[grouping-name from to] groupings
@@ -456,8 +476,11 @@
(fn [i] (fn [i]
(let [amount (get-in all-accounts [i [numeric-code location] :amount] 0.0)] (let [amount (get-in all-accounts [i [numeric-code location] :amount] 0.0)]
[:<> [:<>
[:td.has-text-right [:a {:on-click (dispatch-event [::investigate-clicked location numeric-code numeric-code i :current])} [:td.has-text-right (if multi-client?
(->$ amount)]] [:span (->$ amount)]
[:a {:on-click (dispatch-event [::investigate-clicked location numeric-code numeric-code i :current])
:disabled (boolean multi-client?)}
(->$ amount)])]
[:td.has-text-right (->% (percent-of-sales amount all-accounts i location))]])) [:td.has-text-right (->% (percent-of-sales amount all-accounts i location))]]))
(fn [i] (fn [i]
[:td.has-text-right (->$ (- (get-in all-accounts [i [numeric-code location] :amount] 0.0) [:td.has-text-right (->$ (- (get-in all-accounts [i [numeric-code location] :amount] 0.0)
@@ -471,8 +494,10 @@
(fn [i] (fn [i]
(let [amount (aggregate-accounts (filter-accounts all-accounts i [from to] location))] (let [amount (aggregate-accounts (filter-accounts all-accounts i [from to] location))]
[:<> [:<>
[:th.has-text-right.total [:a {:on-click (dispatch-event [::investigate-clicked location from to i])} [:th.has-text-right.total (if multi-client?
(->$ amount)]] [:span (->$ amount)]
[:a {:on-click (dispatch-event [::investigate-clicked location from to i])}
(->$ amount)])]
[:th.has-text-right.total (->% (percent-of-sales amount all-accounts i location))]])) [:th.has-text-right.total (->% (percent-of-sales amount all-accounts i location))]]))
(fn [i] (fn [i]
[:th.has-text-right.total (->$ (- (aggregate-accounts (filter-accounts all-accounts i [from to] location)) [:th.has-text-right.total (->$ (- (aggregate-accounts (filter-accounts all-accounts i [from to] location))
@@ -486,8 +511,8 @@
(let [all-accounts @(re-frame/subscribe [::all-accounts]) (let [all-accounts @(re-frame/subscribe [::all-accounts])
periods @(re-frame/subscribe [::periods]) periods @(re-frame/subscribe [::periods])
[min-numeric-code max-numeric-code] (ranges type) [min-numeric-code max-numeric-code] (ranges type)
include-deltas @(re-frame/subscribe [::include-deltas])] include-deltas @(re-frame/subscribe [::include-deltas])
multi-client? @(re-frame/subscribe [::multi-client?])]
[:<> [:<>
[:tr [:th.is-size-5 title]] [:tr [:th.is-size-5 title]]
@@ -501,9 +526,11 @@
(fn [i] (fn [i]
(let [amount (aggregate-accounts (filter-accounts all-accounts i [min-numeric-code max-numeric-code] location))] (let [amount (aggregate-accounts (filter-accounts all-accounts i [min-numeric-code max-numeric-code] location))]
[:<> [:<>
[:th.has-text-right [:a [:th.has-text-right (if multi-client?
{:on-click (dispatch-event [::investigate-clicked location min-numeric-code max-numeric-code i])} [:span (->$ amount)]
(->$ amount)]] [:a
{:on-click (dispatch-event [::investigate-clicked location min-numeric-code max-numeric-code i])}
(->$ amount)])]
[:th.has-text-right (->% (percent-of-sales amount all-accounts i location))] [:th.has-text-right (->% (percent-of-sales amount all-accounts i location))]
])) ]))
(fn [i] (fn [i]
@@ -633,8 +660,8 @@
[:div.level-item [:div.level-item
[buttons/dropdown {:on-click (fn [] (reset! active :clients))} [buttons/dropdown {:on-click (fn [] (reset! active :clients))}
[:span (str "Companies" [:span (str "Companies"
(when (:client data) (when-let [clients (:clients data)]
(str " (" (:name (:client data)) ")")))]] (str " (" (str/join ", " (map :name clients)) ")")))]]
[report-control-detail {:active active :box !box :which :clients} [report-control-detail {:active active :box !box :which :clients}
[:div {:style {:width "20em"}} [:div {:style {:width "20em"}}
[:h4.subtitle "Companies"] [:h4.subtitle "Companies"]
@@ -890,10 +917,9 @@
(fn [dt] (fn [dt]
(str->date dt standard)) (str->date dt standard))
period)))) period))))
:client (or (:client qp)
(some-> @(re-frame/subscribe [::subs/client]) (select-keys [:name :id]))) :clients (or (:clients qp)
:clients [(or (:client qp) [(some-> @(re-frame/subscribe [::subs/client]) (select-keys [:name :id]))])
(some-> @(re-frame/subscribe [::subs/client]) (select-keys [:name :id])))]
:include-deltas true}) :include-deltas true})
::track/register {:id ::ledger-params ::track/register {:id ::ledger-params
:subscription [::data-page/params ::ledger] :subscription [::data-page/params ::ledger]