minor fixes.

This commit is contained in:
Bryce Covert
2020-07-17 12:46:44 -07:00
parent 976cd1e7c3
commit 3737cfa628
6 changed files with 348 additions and 148 deletions

View File

@@ -137,13 +137,13 @@
(defn sum-outstanding [ids]
(->>
(d/query {:query {:find ['?o]
(d/query {:query {:find ['?id '?o]
:in ['$ '[?id ...]]
:where ['[?id :invoice/outstanding-balance ?o]]
}
:args [(d/db (d/connect uri))
ids]})
(map first)
(map last)
(reduce
+
0.0)))

View File

@@ -282,6 +282,7 @@
:body (json/write-str data)
:as :json}))
(refresh-provider-account pa)))
#_(defn get-users []
(let [cob-session (login-cobrand)]
(-> "https://developer.api.yodlee.com/ysl/user"

View File

@@ -6,7 +6,7 @@
[goog.string :as gstring]
[auto-ap.utils :refer [dollars-0? by ]]
[auto-ap.views.pages.ledger.side-bar :refer [ledger-side-bar]]
[auto-ap.views.utils :refer [date->str date-picker bind-field standard dispatch-event local-now ->% ->$ str->date with-user]]
[auto-ap.views.utils :refer [date->str date-picker bind-field standard pretty dispatch-event local-now ->% ->$ str->date with-user]]
[cljs-time.core :as t]
[re-frame.core :as re-frame]))
(def ranges
@@ -172,7 +172,6 @@
(re-frame/reg-event-fx
::params-change
(fn [cofx [_ params]]
(println params)
(let [c @(re-frame/subscribe [::subs/client])]
(cond-> {:db (-> (:db cofx)
(assoc-in [::error] nil)
@@ -302,48 +301,65 @@
(set)
(sort-by :numeric-code)))
(defn grouping [{:keys [header type groupings location]}]
(let [periods @(re-frame/subscribe [::periods])
all-accounts @(re-frame/subscribe [::all-accounts])]
(defn map-periods [for-every between periods]
(for [[_ i] (map vector periods (range))]
^{:key (str "period-" i)}
[:<>
(doall
(for [[grouping-name from to] groupings
:let [account-codes (used-accounts all-accounts [from to] location)]
:when (seq account-codes)]
^{:key grouping-name}
[:<>
[:tr [:td "---" grouping-name "---"]
(for [[_ i] (map vector periods (range))]
[:<>
[:td]
[:td]
(when (not= 0 i)
[:td])])]
[:<>
(for [{:keys [numeric-code name]} account-codes]
^{:key numeric-code}
[:tr [:td name]
(for [[p i] (map vector periods (range))
: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])}
(->$ amount)]]
[:td.has-text-right (->% (percent-of-sales amount all-accounts i location))]
(when (not= 0 i)
[:td.has-text-right (->$ (- amount
(get-in all-accounts [(dec i) [numeric-code location] :amount] 0.0)))])])])]
(with-meta
(for-every i)
{:key i})
(if (not= 0 i)
(with-meta (between i)
{:key (str "between-" i)}))]))
[:tr [:th ]
(for [[p i] (map vector periods (range))
: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])}
(->$ amount)]]
[:th.has-text-right.total (->% (percent-of-sales amount all-accounts i location))]
(when (not= 0 i)
[:th.has-text-right.total (->$ (- amount
(aggregate-accounts (filter-accounts all-accounts (dec i) [from to] location))))])])]]))]))
(defn grouping [{:keys [header type groupings location periods all-accounts]}]
[:<>
(doall
(for [[grouping-name from to] groupings
:let [account-codes (used-accounts all-accounts [from to] location)]
:when (seq account-codes)]
^{:key grouping-name}
[:<>
[:tr [:td "---" grouping-name "---"]
(map-periods
(fn [i]
[:<>
[:td]
[:td]])
(fn [i]
[:td])
periods)]
[:<>
(for [{:keys [numeric-code name]} account-codes]
^{:key numeric-code}
[:tr
[:td name]
(map-periods
(fn [i]
(let [amount (get-in all-accounts [(dec 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])}
(->$ amount)]]
[:td.has-text-right (->% (percent-of-sales amount all-accounts i location))]]))
(fn [i]
[:td.has-text-right (->$ (- (get-in all-accounts [(dec i) [numeric-code location] :amount] 0.0)
(get-in all-accounts [(dec i) [numeric-code location] :amount] 0.0)))])
periods)])]
[:tr
[:th]
(map-periods
(fn [i]
(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])}
(->$ amount)]]
[:th.has-text-right.total (->% (percent-of-sales amount all-accounts i location))]]))
(fn [i]
[:th.has-text-right.total (->$ (- (aggregate-accounts (filter-accounts all-accounts i [from to] location))
(aggregate-accounts (filter-accounts all-accounts (dec i) [from to] location))))])
periods)]]))])
@@ -356,42 +372,49 @@
[:tr [:th.is-size-5 title]]
[grouping {:location location
:groupings (type groupings)}]
:groupings (type groupings)
:periods periods
:all-accounts all-accounts}]
[:tr [:th.is-size-5 title]
(for [[i p] (map vector (range) periods)
:let [amount (aggregate-accounts (filter-accounts all-accounts i [min-numeric-code max-numeric-code] location))]]
[:<>
[:th.has-text-right [: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))]
(when (not= 0 i)
[:th.has-text-right (->$ (- amount
(aggregate-accounts (filter-accounts all-accounts (dec i) [min-numeric-code max-numeric-code] location))))])])]]))
(map-periods
(fn [i]
(let [amount (aggregate-accounts (filter-accounts all-accounts i [min-numeric-code max-numeric-code] location))]
[:<>
[:th.has-text-right [: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))]
]))
(fn [i]
[:th.has-text-right (->$ (- (aggregate-accounts (filter-accounts all-accounts i [min-numeric-code max-numeric-code] location))
(aggregate-accounts (filter-accounts all-accounts (dec i) [min-numeric-code max-numeric-code] location))))])
periods)]]))
(defn subtotal [types negs title location]
(let [all-accounts @(re-frame/subscribe [::all-accounts])
periods @(re-frame/subscribe [::periods])]
[:tr [:th.is-size-5 title]
(for [[p i] (map vector periods (range))
:let [amount (aggregate-accounts (mapcat (fn [t]
(cond->> (filter-accounts all-accounts i (ranges t) location)
(negs t) (map #(update % :amount -))))
types))]]
[:<>
[:td.has-text-right [:span (->$ amount)]]
[:td.has-text-right (->% (percent-of-sales amount all-accounts i location))]
(when (not= 0 i)
[:td.has-text-right (->$ (- amount
(aggregate-accounts (mapcat (fn [t]
(cond->> (filter-accounts all-accounts (dec i) (ranges t) location)
(negs t) (map #(update % :amount -))))
types))))]
)
])]))
(map-periods
(fn [i]
(let [amount (aggregate-accounts (mapcat (fn [t]
(cond->> (filter-accounts all-accounts i (ranges t) location)
(negs t) (map #(update % :amount -))))
types))]
[:<>
[:td.has-text-right [:span (->$ amount)]]
[:td.has-text-right (->% (percent-of-sales amount all-accounts i location))]]))
(fn [i]
[:td.has-text-right (->$ (- (aggregate-accounts (mapcat (fn [t]
(cond->> (filter-accounts all-accounts i (ranges t) location)
(negs t) (map #(update % :amount -))))
types))
(aggregate-accounts (mapcat (fn [t]
(cond->> (filter-accounts all-accounts (dec i) (ranges t) location)
(negs t) (map #(update % :amount -))))
types))))])
periods)]))
(defn location-rows [location]
@@ -416,13 +439,16 @@
[:tbody
[:tr
[:td.has-text-right "Period ending"]
(for [[[_ date] i] (map vector periods (range))]
[:<>
[:td.has-text-right (when date
(date->str date))]
[:td]
(when (not= 0 i)
[:td])])]
(map-periods
(fn [i]
[:<>
[:td.has-text-right (when-let [ date (get-in periods [i 1])]
(date->str date))]
[:td]
])
(fn [i]
[:td])
periods)]
[subtotal [:sales ] #{} "Sales" location]
[subtotal [:cogs ] #{} "Cogs" location]
[subtotal [:payroll ]#{} "Payroll" location]
@@ -456,7 +482,7 @@
[:h2.title.is-4 "Range"]
[:div
[:div.field.is-grouped
[:p.control
[:div.control
[:a.button
{:class (when (= (:selected params) "13 periods") "is-active")
:on-click (dispatch-event
@@ -473,7 +499,7 @@
"13 periods"])}
"13 periods"]]
[:p.control
[:div.control
[:a.button
{:class (when (= (:selected params) "Last week") "is-active")
:on-click (dispatch-event
@@ -485,7 +511,7 @@
(and-last-year [(t/minus last-sunday (t/period :days 6)) last-sunday])
"Last week"]))}
"Last week"]]
[:p.control
[:div.control
[:a.button
{:class (when (= (:selected params) "Week to date") "is-active")
:on-click (dispatch-event [::range-selected
@@ -496,7 +522,7 @@
(local-now)])
"Week to date"])}
"Week to date"]]
[:p.control
[:div.control
[:a.button
{:class (when (= (:selected params) "Last Month") "is-active")
:on-click (dispatch-event [::range-selected
@@ -510,7 +536,7 @@
(t/period :days 1))])
"Last Month"])}
"Last Month"]]
[:p.control
[:div.control
[:a.button
{:class (when (= (:selected params) "Month to date") "is-active")
:on-click (dispatch-event [::range-selected
@@ -520,7 +546,7 @@
(local-now)])
"Month to date"])}
"Month to date"]]
[:p.control
[:div.control
[:a.button
{:class (when (= (:selected params) "Year to date") "is-active")
:on-click (dispatch-event [::range-selected
@@ -528,7 +554,7 @@
(local-now)])
"Year to date"])}
"Year to date"]]
[:p.control
[:div.control
[:a.button
{:class (when (= (:selected params) "Full year") "is-active")
:on-click (dispatch-event [::range-selected
@@ -538,8 +564,9 @@
"Full year"])}
"Full year"]]]]
(for [[_ i] (map vector periods (range))]
^{:key i}
[:div.field.is-grouped
[:p.control
[:div.control
[:p.help "From"]
[bind-field
[date-picker {:class-name "input"
@@ -555,7 +582,7 @@
:popper-props (clj->js {:placement "right"})
:subscription params}]]]
[:p.control
[:div.control
[:p.help "To"]
[bind-field
[date-picker {:class-name "input"
@@ -589,15 +616,14 @@
[:tbody
[:tr
[:td.has-text-right "Period Ending"]
[:td.has-text-right (date->str (last (first periods)))]
[:td]
[:<>
(for [[_ end] (rest periods)]
(map-periods
(fn [i]
[:<>
[:td.has-text-right (date->str end)]
[:td]
[:td.has-text-right "𝝙"]]
)]]
[:td.has-text-right (date->str (get-in periods [i 1]))]
[:td]])
(fn [i]
[:td.has-text-right "𝝙"])
periods)]
[:<>
(for [location @(re-frame/subscribe [::locations])]
^{:key location}

View File

@@ -183,7 +183,7 @@
(instance? goog.date.DateTime selected)
(c/to-date selected)
(c/to-date (time/to-default-time-zone (time/from-default-time-zone selected)))
(instance? goog.date.Date selected)
(c/to-date selected)