nnull fix...
This commit is contained in:
@@ -95,7 +95,8 @@
|
|||||||
(defn best-category [a]
|
(defn best-category [a]
|
||||||
(->> ranges
|
(->> ranges
|
||||||
(filter (fn [[_ [start end]]]
|
(filter (fn [[_ [start end]]]
|
||||||
(<= start (:numeric-code a) end)))
|
(and (:numeric-code a)
|
||||||
|
(<= start (:numeric-code a) end))))
|
||||||
first
|
first
|
||||||
first))
|
first))
|
||||||
|
|
||||||
|
|||||||
@@ -35,54 +35,20 @@
|
|||||||
[vimsical.re-frame.cofx.inject :as inject]
|
[vimsical.re-frame.cofx.inject :as inject]
|
||||||
[vimsical.re-frame.fx.track :as track]))
|
[vimsical.re-frame.fx.track :as track]))
|
||||||
|
|
||||||
(def ranges
|
|
||||||
{:sales [40000 49999]
|
|
||||||
:cogs [50000 59999]
|
|
||||||
:payroll [60000 69999]
|
|
||||||
:controllable [70000 79999]
|
|
||||||
:fixed-overhead [80000 89999]
|
|
||||||
:ownership-controllable [90000 99999]})
|
|
||||||
|
|
||||||
(defn and-last-year [[from to]]
|
(defn and-last-year [[from to]]
|
||||||
[[from to]
|
[[from to]
|
||||||
[(t/minus from (t/years 1)) (t/minus to (t/years 1))]])
|
[(t/minus from (t/years 1)) (t/minus to (t/years 1))]])
|
||||||
|
|
||||||
(defn in-range? [code]
|
|
||||||
(reduce
|
|
||||||
(fn [acc [start end]]
|
|
||||||
(if (<= start code end)
|
|
||||||
(reduced true)
|
|
||||||
acc))
|
|
||||||
false
|
|
||||||
(vals ranges)))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; SUBS
|
;; SUBS
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::error
|
|
||||||
(fn [db]
|
|
||||||
(-> db ::error)))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::ledger-list-active?
|
::ledger-list-active?
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(-> db ::ledger-list-active?)))
|
(-> db ::ledger-list-active?)))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::period-accounts
|
|
||||||
:<- [::forms/form ::form]
|
|
||||||
(fn [db [_ which type only-location]]
|
|
||||||
|
|
||||||
(->> (get-in db [:report :periods which :accounts])
|
|
||||||
(map #(update % :amount js/parseFloat))
|
|
||||||
(filter (fn [{:keys [account-type location numeric-code]}]
|
|
||||||
(and (or (nil? only-location)
|
|
||||||
(= only-location location))
|
|
||||||
(<= (get-in ranges [type 0]) numeric-code (get-in ranges [type 1])))))
|
|
||||||
(sort-by :numeric-code))))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::uncategorized-accounts
|
::uncategorized-accounts
|
||||||
:<- [::forms/form ::form]
|
:<- [::forms/form ::form]
|
||||||
@@ -94,35 +60,6 @@
|
|||||||
(filter (fn [{:keys [account-type location numeric-code]}]
|
(filter (fn [{:keys [account-type location numeric-code]}]
|
||||||
(nil? numeric-code))))))
|
(nil? numeric-code))))))
|
||||||
|
|
||||||
(defn parse-amounts [period]
|
|
||||||
(update period :accounts (fn [a]
|
|
||||||
(map #(update % :amount js/parseFloat) a))))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::all-accounts
|
|
||||||
:<- [::forms/form ::form]
|
|
||||||
(fn [db [_ which type only-location]]
|
|
||||||
(transduce
|
|
||||||
(comp
|
|
||||||
(map parse-amounts)
|
|
||||||
(map #(->> (:accounts %)
|
|
||||||
(group-by (juxt :numeric-code :client-id :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
|
|
||||||
[]
|
|
||||||
(get-in db [:report :periods]))))
|
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::received
|
::received
|
||||||
@@ -130,21 +67,6 @@
|
|||||||
(fn [db [_ data]]
|
(fn [db [_ data]]
|
||||||
(-> db (assoc :report (:profit-and-loss data)))))
|
(-> db (assoc :report (:profit-and-loss data)))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::period-inputs
|
|
||||||
(fn [db]
|
|
||||||
(-> db ::period-inputs)))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::periods
|
|
||||||
(fn [db]
|
|
||||||
(-> db ::forms/forms ::form :data :periods)))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::include-deltas
|
|
||||||
(fn [db]
|
|
||||||
(-> db ::forms/forms ::form :data :include-deltas)))
|
|
||||||
|
|
||||||
;; EVENTS
|
;; EVENTS
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
@@ -188,8 +110,6 @@ Please download it by clicking this link: " report-url)))
|
|||||||
(-> clients-by-id
|
(-> clients-by-id
|
||||||
(get (:id (first selected-clients)))
|
(get (:id (first selected-clients)))
|
||||||
:emails))]
|
:emails))]
|
||||||
|
|
||||||
|
|
||||||
{:dispatch [::modal/modal-requested {:title "Your report is ready"
|
{:dispatch [::modal/modal-requested {:title "Your report is ready"
|
||||||
:body [:div
|
:body [:div
|
||||||
[:div "Click "
|
[:div "Click "
|
||||||
@@ -203,7 +123,7 @@ Please download it by clicking this link: " report-url)))
|
|||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::export-pdf
|
::export-pdf
|
||||||
[with-user (forms/in-form ::form)]
|
[with-user (forms/in-form ::form)]
|
||||||
(fn [{:keys [db user] :as cofx}]
|
(fn [{:keys [db user]}]
|
||||||
(cond-> {:graphql {:token user
|
(cond-> {:graphql {:token user
|
||||||
:owns-state {:single ::page}
|
:owns-state {:single ::page}
|
||||||
:query-obj {:venia/queries [[:profit-and-loss-pdf
|
:query-obj {:venia/queries [[:profit-and-loss-pdf
|
||||||
@@ -243,7 +163,8 @@ Please download it by clicking this link: " report-url)))
|
|||||||
[with-user (forms/in-form ::form)]
|
[with-user (forms/in-form ::form)]
|
||||||
(fn [{:keys [db]} [_ & event]]
|
(fn [{:keys [db]} [_ & event]]
|
||||||
{:db (dissoc db :report)
|
{:db (dissoc db :report)
|
||||||
:dispatch (into [::change-internal] event)}))
|
:dispatch-n [(into [::change-internal] event)
|
||||||
|
[::ledger-list-closing]]}))
|
||||||
|
|
||||||
|
|
||||||
(defn data-params->query-params [params]
|
(defn data-params->query-params [params]
|
||||||
@@ -261,29 +182,29 @@ Please download it by clicking this link: " report-url)))
|
|||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::ledger-params-change
|
::ledger-params-change
|
||||||
[with-user]
|
[with-user]
|
||||||
(fn [{:keys [user db]} [_ ledger-params]]
|
(fn [{:keys [user]} [_ ledger-params]]
|
||||||
(if (seq ledger-params)
|
(when (seq ledger-params)
|
||||||
{:graphql {:token user
|
{:graphql {:token user
|
||||||
:owns-state {:single [::data-page/page ::ledger]}
|
:owns-state {:single [::data-page/page ::ledger]}
|
||||||
:query-obj {:venia/queries [[:ledger-page
|
:query-obj {:venia/queries [[:ledger-page
|
||||||
{:filters (data-params->query-params ledger-params)}
|
{:filters (data-params->query-params ledger-params)}
|
||||||
[[:journal-entries [:id
|
[[:journal-entries [:id
|
||||||
:source
|
:source
|
||||||
:original-entity
|
:original-entity
|
||||||
:note
|
:note
|
||||||
:amount
|
:amount
|
||||||
:alternate-description
|
:alternate-description
|
||||||
[:vendor
|
[:vendor
|
||||||
[:name :id]]
|
[:name :id]]
|
||||||
[:client
|
[:client
|
||||||
[:name :id]]
|
[:name :id]]
|
||||||
[:line-items
|
[:line-items
|
||||||
[:id :debit :credit :location :running-balance
|
[:id :debit :credit :location :running-balance
|
||||||
[:account [:id :name]]]]
|
[:account [:id :name]]]]
|
||||||
:date]]
|
:date]]
|
||||||
:total
|
:total
|
||||||
:start
|
:start
|
||||||
:end]]]}
|
:end]]]}
|
||||||
:on-success (fn [result]
|
:on-success (fn [result]
|
||||||
[::data-page/received ::ledger (set/rename-keys (:ledger-page result)
|
[::data-page/received ::ledger (set/rename-keys (:ledger-page result)
|
||||||
{:journal-entries :data})])}})))
|
{:journal-entries :data})])}})))
|
||||||
@@ -291,8 +212,7 @@ Please download it by clicking this link: " report-url)))
|
|||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::investigate-clicked
|
::investigate-clicked
|
||||||
(fn [{:keys [db]} [_ {:keys [location from-numeric-code to-numeric-code client-id]
|
(fn [{:keys [db]} [_ {:keys [location from-numeric-code to-numeric-code client-id]
|
||||||
{:keys [start end]} :date-range
|
{:keys [start end]} :date-range}]]
|
||||||
:as filters}]]
|
|
||||||
{:db (-> db (assoc ::ledger-list-active? true))
|
{:db (-> db (assoc ::ledger-list-active? true))
|
||||||
:dispatch [::data-page/additional-params-changed ::ledger {:client-id client-id
|
:dispatch [::data-page/additional-params-changed ::ledger {:client-id client-id
|
||||||
:from-numeric-code from-numeric-code
|
:from-numeric-code from-numeric-code
|
||||||
@@ -311,11 +231,9 @@ Please download it by clicking this link: " report-url)))
|
|||||||
|
|
||||||
(= :dollar (:format c))
|
(= :dollar (:format c))
|
||||||
(->$ (:value c))
|
(->$ (:value c))
|
||||||
#_(.format (DecimalFormat. "$###,##0.00") (:value cell))
|
|
||||||
|
|
||||||
(= :percent (:format c))
|
(= :percent (:format c))
|
||||||
(->% (:value c))
|
(->% (:value c))
|
||||||
#_(.format (DecimalFormat. "0%") (:value cell))
|
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(str (:value c)))
|
(str (:value c)))
|
||||||
@@ -344,8 +262,7 @@ Please download it by clicking this link: " report-url)))
|
|||||||
(:color c))
|
(:color c))
|
||||||
")")))
|
")")))
|
||||||
|
|
||||||
cell-contents
|
cell-contents]))
|
||||||
]))
|
|
||||||
|
|
||||||
(defn cell-count [table]
|
(defn cell-count [table]
|
||||||
(let [counts (map count (:rows table))]
|
(let [counts (map count (:rows table))]
|
||||||
|
|||||||
Reference in New Issue
Block a user