tons of small fixes.
This commit is contained in:
@@ -15,6 +15,17 @@
|
||||
(defn jwt->data [token]
|
||||
(js->clj (.parse js/JSON (b64/decodeString (second (str/split token #"\." ))))))
|
||||
|
||||
(def vendor-query
|
||||
[:id :name :hidden :terms [:default-account [:name :id :location]]
|
||||
[:account-overrides [[:client [:id :name]] :id [:account [:id :numeric-code :name]]]]
|
||||
[:automatically-paid-when-due [:id :name]]
|
||||
[:terms-overrides [[:client [:id :name]] :id :terms]]
|
||||
[:usage [:client-id :count]]
|
||||
[:primary-contact [:name :phone :email :id]]
|
||||
[:secondary-contact [:id :name :phone :email]]
|
||||
:print-as :invoice-reminder-schedule :code
|
||||
[:address [:street1 :street2 :city :state :zip]]])
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::initialize-db
|
||||
(fn [{:keys [db]} [_ token]]
|
||||
@@ -48,22 +59,10 @@
|
||||
[:address [:street1 :street2 :city :state :zip]]
|
||||
[:forecasted-transactions [:id :amount :identifier :day-of-month]]]]
|
||||
[:vendor
|
||||
[:id :name :hidden [:default-account [:name :id :location]] [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code
|
||||
[:account-overrides [[:client [:id :name]] :id [:account [:id :numeric-code :name]]]]
|
||||
|
||||
[:automatically-paid-when-due [:id :name]]
|
||||
[:terms-overrides [[:client [:id :name]] :id :terms]]]]
|
||||
vendor-query]
|
||||
[:accounts [:numeric-code :location :name :type :account_set :applicability :id [:client-overrides [:name [:client [:name :id]]]]]]]}
|
||||
:on-success [::received-initial]}}))))
|
||||
(def vendor-query
|
||||
[:id :name :hidden :terms [:default-account [:name :id :location]]
|
||||
[:account-overrides [[:client [:id :name]] :id [:account [:id :numeric-code :name]]]]
|
||||
[:automatically-paid-when-due [:id :name]]
|
||||
[:terms-overrides [[:client [:id :name]] :id :terms]]
|
||||
[:primary-contact [:name :phone :email :id]]
|
||||
[:secondary-contact [:id :name :phone :email]]
|
||||
:print-as :invoice-reminder-schedule :code
|
||||
[:address [:street1 :street2 :city :state :zip]]])
|
||||
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::toggle-menu
|
||||
|
||||
@@ -177,6 +177,30 @@
|
||||
(filter #(or (not (:hidden %))
|
||||
is-admin) all-vendors)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::searchable-vendors
|
||||
:<- [::is-admin?]
|
||||
:<- [::client]
|
||||
:<- [::all-vendors]
|
||||
(fn [[is-admin client all-vendors]]
|
||||
(cond client
|
||||
(filter (fn [{:keys [hidden usage name] :as vendor}]
|
||||
(or (not hidden)
|
||||
(-> (first (filter #(= (:client-id %)
|
||||
(:id client))
|
||||
usage))
|
||||
(:count 0)
|
||||
(> 0))))
|
||||
all-vendors)
|
||||
|
||||
is-admin
|
||||
all-vendors
|
||||
|
||||
:else
|
||||
|
||||
|
||||
(filter #(not (:hidden %)) all-vendors))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::all-vendors
|
||||
(fn [db]
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
[:div
|
||||
[:p.menu-label "Vendor"]
|
||||
[:div
|
||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
|
||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/searchable-vendors])
|
||||
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor %])
|
||||
:match->text :name
|
||||
:type "typeahead-entity"
|
||||
|
||||
@@ -31,13 +31,16 @@
|
||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
|
||||
:type "typeahead-entity"
|
||||
:auto-focus true
|
||||
:match->text :name
|
||||
:match->text (fn [x]
|
||||
(str (:name x) " (" (reduce + 0 (map :count (:usage x))) " usages)") )
|
||||
:field [:from]}])
|
||||
|
||||
|
||||
(field "To Vendor"
|
||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
|
||||
:type "typeahead-entity"
|
||||
:match->text :name
|
||||
:match->text (fn [x]
|
||||
(str (:name x) " (" (reduce + 0 (map :count (:usage x))) " usages)") )
|
||||
:field [:to]}])])))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
|
||||
@@ -40,7 +40,11 @@
|
||||
(for [v (:data page)]
|
||||
^{:key (str (:id v))}
|
||||
[grid/row {:class (:class v) :id (:id v)}
|
||||
[grid/cell {} (:name v)]
|
||||
[grid/cell {} (:name v)
|
||||
(let [total-usage (reduce + 0 (map :count (:usage v)))]
|
||||
(if (> total-usage 0 )
|
||||
[:div.mx-2.tag.is-info.is-light total-usage " usages, " (count (:usage v)) " clients" ]
|
||||
[:div.mx-2.tag.is-warning.is-light "Unused"]))]
|
||||
[grid/cell {} (:email (:primary-contact v))]
|
||||
[grid/cell {} (-> v :default-account :id accounts :name)]
|
||||
[grid/cell {}
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
:amount
|
||||
:note
|
||||
:cleared-against
|
||||
:alternate-description
|
||||
[:vendor
|
||||
[:name :id]]
|
||||
[:client
|
||||
|
||||
@@ -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 pretty dispatch-event local-today ->% ->$ str->date with-user]]
|
||||
[auto-ap.views.utils :refer [date->str date-picker bind-field standard pretty dispatch-event local-today ->% ->$ str->date with-user dispatch-value-change query-params]]
|
||||
[cljs-time.core :as t]
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.status :as status]
|
||||
@@ -22,6 +22,10 @@
|
||||
:fixed-overhead [80000 89999]
|
||||
:ownership-controllable [90000 99999]})
|
||||
|
||||
(defn and-last-year [[from to]]
|
||||
[[from to]
|
||||
[(t/minus from (t/years 1)) (t/minus to (t/years 1))]])
|
||||
|
||||
;; SUBS
|
||||
(re-frame/reg-sub
|
||||
::locations
|
||||
@@ -112,6 +116,11 @@
|
||||
(fn [db]
|
||||
(-> db ::params)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::period-inputs
|
||||
(fn [db]
|
||||
(-> db ::period-inputs)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::periods
|
||||
(fn [db]
|
||||
@@ -124,6 +133,24 @@
|
||||
(fn [db]
|
||||
(assoc db ::ledger-list-active? false)))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::mounted
|
||||
(fn [{:keys [db]}]
|
||||
(let [qp (query-params)]
|
||||
(if (:periods qp)
|
||||
(let [periods (mapv (fn [[start end title]]
|
||||
[
|
||||
(str->date start standard)
|
||||
(str->date end standard)
|
||||
title])
|
||||
(:periods qp))]
|
||||
{:dispatch [::range-selected periods (:include-deltas qp) nil]})
|
||||
{:dispatch [::range-selected (and-last-year [(t/minus (local-today) (t/period :years 1)) (local-today)]) true nil]}))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::period-inputs-change
|
||||
(fn [db [_ field value]]
|
||||
(assoc-in db (into [::period-inputs ] field) value)))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-change
|
||||
@@ -131,7 +158,15 @@
|
||||
(let [c @(re-frame/subscribe [::subs/client])]
|
||||
(cond-> {:db (-> (:db cofx)
|
||||
(assoc-in [::params] params)
|
||||
(dissoc ::report))}
|
||||
(dissoc ::report))
|
||||
:set-uri-params (update params
|
||||
:periods
|
||||
(fn [p]
|
||||
(mapv (fn [[start end title]]
|
||||
[(date->str start standard)
|
||||
(date->str end standard)
|
||||
title]
|
||||
) p)))}
|
||||
c (assoc :graphql (when @(re-frame/subscribe [::subs/client])
|
||||
{:token (-> cofx :db :user)
|
||||
:owns-state {:single ::page}
|
||||
@@ -149,15 +184,17 @@
|
||||
(re-frame/reg-event-fx
|
||||
::date-picked
|
||||
(fn [cofx [_ [_ period which] date]]
|
||||
(println date (str->date date standard))
|
||||
{:dispatch [::range-selected (assoc-in @(re-frame/subscribe [::periods]) [period which] (str->date date standard)) nil]}))
|
||||
{:dispatch [::range-selected (assoc-in @(re-frame/subscribe [::periods]) [period which] (str->date date standard)) nil nil]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::range-selected
|
||||
(fn [{:keys [db]} [_ periods selected]]
|
||||
{:dispatch [::params-change (assoc @(re-frame/subscribe [::params])
|
||||
:periods periods
|
||||
:selected selected)]
|
||||
(fn [{:keys [db]} [_ periods include-deltas selected]]
|
||||
{:dispatch [::params-change (cond-> @(re-frame/subscribe [::params])
|
||||
true (assoc
|
||||
:periods periods
|
||||
:include-deltas include-deltas
|
||||
:selected selected)
|
||||
(not (nil? include-deltas)) (assoc :include-deltas include-deltas))]
|
||||
:db (assoc db ::periods periods)}))
|
||||
|
||||
|
||||
@@ -186,6 +223,7 @@
|
||||
[[:journal-entries [:id
|
||||
:source
|
||||
:amount
|
||||
:alternate-description
|
||||
[:vendor
|
||||
[:name :id]]
|
||||
[:client
|
||||
@@ -267,72 +305,77 @@
|
||||
(set)
|
||||
(sort-by :numeric-code)))
|
||||
|
||||
(defn map-periods [for-every between periods]
|
||||
(defn map-periods [for-every between periods include-deltas]
|
||||
(for [[_ i] (map vector periods (range))]
|
||||
^{:key (str "period-" i)}
|
||||
[:<>
|
||||
(with-meta
|
||||
(for-every i)
|
||||
{:key i})
|
||||
(if (not= 0 i)
|
||||
(if (and include-deltas (not= 0 i))
|
||||
(with-meta (between i)
|
||||
{:key (str "between-" i)}))]))
|
||||
|
||||
|
||||
(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 [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 [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))]
|
||||
(let [params @(re-frame/subscribe [::params])]
|
||||
[:<>
|
||||
(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]
|
||||
[:<>
|
||||
[: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)]]))])
|
||||
[:td]
|
||||
[:td]])
|
||||
(fn [i]
|
||||
[:td])
|
||||
periods
|
||||
(:include-deltas params))]
|
||||
[:<>
|
||||
(for [{:keys [numeric-code name]} account-codes]
|
||||
^{:key numeric-code}
|
||||
[:tr
|
||||
[:td name]
|
||||
(map-periods
|
||||
(fn [i]
|
||||
(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))]]))
|
||||
(fn [i]
|
||||
[:td.has-text-right (->$ (- (get-in all-accounts [i [numeric-code location] :amount] 0.0)
|
||||
(get-in all-accounts [(dec i) [numeric-code location] :amount] 0.0)))])
|
||||
periods
|
||||
(:include-deltas params))])]
|
||||
|
||||
[: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
|
||||
(:include-deltas params))]]))]))
|
||||
|
||||
|
||||
|
||||
(defn overall-grouping [type title location]
|
||||
(let [all-accounts @(re-frame/subscribe [::all-accounts])
|
||||
periods @(re-frame/subscribe [::periods])
|
||||
[min-numeric-code max-numeric-code] (ranges type)]
|
||||
[min-numeric-code max-numeric-code] (ranges type)
|
||||
params @(re-frame/subscribe [::params])]
|
||||
|
||||
[:<>
|
||||
[:tr [:th.is-size-5 title]]
|
||||
@@ -355,11 +398,13 @@
|
||||
(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)]]))
|
||||
periods
|
||||
(:include-deltas params))]]))
|
||||
|
||||
(defn subtotal [types negs title location]
|
||||
(let [all-accounts @(re-frame/subscribe [::all-accounts])
|
||||
periods @(re-frame/subscribe [::periods])]
|
||||
periods @(re-frame/subscribe [::periods])
|
||||
params @(re-frame/subscribe [::params])]
|
||||
[:tr [:th.is-size-5 title]
|
||||
|
||||
(map-periods
|
||||
@@ -380,7 +425,8 @@
|
||||
(cond->> (filter-accounts all-accounts (dec i) (ranges t) location)
|
||||
(negs t) (map #(update % :amount -))))
|
||||
types))))])
|
||||
periods)]))
|
||||
periods
|
||||
(:include-deltas params))]))
|
||||
|
||||
(defn location-rows [location]
|
||||
|
||||
@@ -400,21 +446,24 @@
|
||||
(defn location-summary [location params]
|
||||
(let [periods @(re-frame/subscribe [::periods])]
|
||||
[:div
|
||||
[:h2.title.is-4 {:style {:margin-bottom "1rem"}} location " Summary"]
|
||||
[:table.table.compact.balance-sheet {:style {:margin-bottom "2.5rem"}}
|
||||
[:h2.title.is-4.mb-4 location " Summary"]
|
||||
[:table.table.compact.balance-sheet.mb-6
|
||||
[:tbody
|
||||
[:tr
|
||||
[:td.has-text-right "Period ending"]
|
||||
(map-periods
|
||||
(fn [i]
|
||||
[:<>
|
||||
[:td.has-text-right (when-let [ date (get-in periods [i 1])]
|
||||
(date->str date))]
|
||||
[:td.has-text-right
|
||||
(or (get-in periods [i 2])
|
||||
(when-let [ date (get-in periods [i 1])]
|
||||
(date->str date)))]
|
||||
[:td]
|
||||
])
|
||||
(fn [i]
|
||||
[:td])
|
||||
periods)]
|
||||
periods
|
||||
(:include-deltas params))]
|
||||
[subtotal [:sales ] #{} "Sales" location]
|
||||
[subtotal [:cogs ] #{} "Cogs" location]
|
||||
[subtotal [:payroll ]#{} "Payroll" location]
|
||||
@@ -424,9 +473,7 @@
|
||||
|
||||
]))
|
||||
|
||||
(defn and-last-year [[from to]]
|
||||
[[from to]
|
||||
[(t/minus from (t/years 1)) (t/minus to (t/years 1))]])
|
||||
|
||||
|
||||
(def profit-and-loss-content
|
||||
(with-meta
|
||||
@@ -435,6 +482,7 @@
|
||||
user @(re-frame/subscribe [::subs/user])
|
||||
status @(re-frame/subscribe [::status/single ::page])
|
||||
params @(re-frame/subscribe [::params])
|
||||
period-inputs @(re-frame/subscribe [::period-inputs])
|
||||
periods @(re-frame/subscribe [::periods])]
|
||||
|
||||
(if-not current-client
|
||||
@@ -450,22 +498,82 @@
|
||||
[:div
|
||||
[:div.field.is-grouped
|
||||
[:div.control
|
||||
[:a.button
|
||||
{:class (when (= (:selected params) "13 periods") "is-active")
|
||||
:on-click (dispatch-event
|
||||
[::range-selected
|
||||
(let [this-month (t/local-date (t/year (local-today))
|
||||
(t/month (local-today))
|
||||
1)]
|
||||
(into
|
||||
[[this-month (t/minus (t/plus this-month (t/months 1)) (t/days 1))]]
|
||||
(for [i (range 12)]
|
||||
[(t/minus this-month (t/months (- 12 i)))
|
||||
(t/minus (t/minus this-month (t/months (- 11 i)))
|
||||
(t/days 1))])))
|
||||
|
||||
"13 periods"])}
|
||||
"13 periods"]]
|
||||
[:div.field.has-addons
|
||||
[:div.control
|
||||
[bind-field
|
||||
[date-picker {:class-name "input"
|
||||
:class "input"
|
||||
:format-week-number (fn [] "")
|
||||
:previous-month-button-label ""
|
||||
:placeholder "End date"
|
||||
:next-month-button-label ""
|
||||
:next-month-label ""
|
||||
:type "date"
|
||||
:field [:thirteen-periods-end]
|
||||
:subscription period-inputs
|
||||
:event [::period-inputs-change]}]]]
|
||||
[:div.control
|
||||
[:a.button
|
||||
{:class (when (= (:selected params) "13 periods") "is-active")
|
||||
:on-click (dispatch-event
|
||||
[::range-selected
|
||||
(let [today (or (some-> (:thirteen-periods-end period-inputs) (str->date standard))
|
||||
(local-today))]
|
||||
(into
|
||||
[[(t/plus (t/minus today (t/weeks (* 13 4)))
|
||||
(t/days 1))
|
||||
today
|
||||
"Total"]]
|
||||
(for [i (range 13)]
|
||||
[(t/plus (t/minus today (t/weeks (* (inc i) 4)))
|
||||
(t/days 1))
|
||||
(t/minus today (t/weeks (* i 4)))])))
|
||||
|
||||
false
|
||||
"13 periods"])}
|
||||
"13 periods"]]]]
|
||||
|
||||
[:div.control
|
||||
[:div.field.has-addons
|
||||
[:div.control
|
||||
[bind-field
|
||||
[date-picker {:class-name "input"
|
||||
:class "input"
|
||||
:format-week-number (fn [] "")
|
||||
:previous-month-button-label ""
|
||||
:placeholder "End date"
|
||||
:next-month-button-label ""
|
||||
:next-month-label ""
|
||||
:type "date"
|
||||
:field [:twelve-periods-end]
|
||||
:subscription period-inputs
|
||||
:event [::period-inputs-change]}]]]
|
||||
[:div.control
|
||||
[:a.button
|
||||
{:class (when (= (:selected params) "13 periods") "is-active")
|
||||
:on-click (dispatch-event
|
||||
[::range-selected
|
||||
(let [end-date (or (some-> (:twelve-periods-end period-inputs) (str->date standard))
|
||||
(local-today))
|
||||
this-month (t/local-date (t/year end-date)
|
||||
(t/month end-date)
|
||||
1)
|
||||
]
|
||||
(into
|
||||
[[(t/minus this-month (t/months 11))
|
||||
(t/minus (t/plus this-month (t/months 1))
|
||||
(t/days 1))
|
||||
"Total"]]
|
||||
(for [i (range 12)]
|
||||
[(t/minus this-month (t/months (- 11 i)))
|
||||
(t/minus (t/minus this-month (t/months (- 10 i)))
|
||||
(t/days 1))])))
|
||||
|
||||
false
|
||||
"12 months"]
|
||||
)}
|
||||
"12 months"]]]]
|
||||
|
||||
[:div.control
|
||||
[:a.button
|
||||
{:class (when (= (:selected params) "Last week") "is-active")
|
||||
@@ -476,6 +584,7 @@
|
||||
(recur (t/minus current (t/period :days 1)))))]
|
||||
[::range-selected
|
||||
(and-last-year [(t/minus last-sunday (t/period :days 6)) last-sunday])
|
||||
true
|
||||
"Last week"]))}
|
||||
"Last week"]]
|
||||
[:div.control
|
||||
@@ -487,6 +596,7 @@
|
||||
current
|
||||
(recur (t/minus current (t/period :days 1)))))
|
||||
(local-today)])
|
||||
true
|
||||
"Week to date"])}
|
||||
"Week to date"]]
|
||||
[:div.control
|
||||
@@ -501,6 +611,7 @@
|
||||
(t/month (local-today))
|
||||
1)
|
||||
(t/period :days 1))])
|
||||
true
|
||||
"Last Month"])}
|
||||
"Last Month"]]
|
||||
[:div.control
|
||||
@@ -511,6 +622,7 @@
|
||||
(t/month (local-today))
|
||||
1)
|
||||
(local-today)])
|
||||
true
|
||||
"Month to date"])}
|
||||
"Month to date"]]
|
||||
[:div.control
|
||||
@@ -519,6 +631,7 @@
|
||||
:on-click (dispatch-event [::range-selected
|
||||
(and-last-year [(t/local-date (t/year (local-today)) 1 1)
|
||||
(local-today)])
|
||||
true
|
||||
"Year to date"])}
|
||||
"Year to date"]]
|
||||
[:div.control
|
||||
@@ -528,77 +641,92 @@
|
||||
(and-last-year [(t/plus (t/minus (local-today) (t/period :years 1))
|
||||
(t/period :days 1))
|
||||
(local-today)])
|
||||
true
|
||||
"Full year"])}
|
||||
"Full year"]]]]
|
||||
(for [[_ i] (map vector periods (range))]
|
||||
^{:key i}
|
||||
[:div.field.is-grouped
|
||||
[:div.control
|
||||
[:p.help "From"]
|
||||
[bind-field
|
||||
[date-picker {:class-name "input"
|
||||
:class "input"
|
||||
:format-week-number (fn [] "")
|
||||
:previous-month-button-label ""
|
||||
:placeholder "mm/dd/yyyy"
|
||||
:next-month-button-label ""
|
||||
:next-month-label ""
|
||||
:type "date"
|
||||
:field [:periods i 0]
|
||||
:event [::date-picked]
|
||||
:popper-props (clj->js {:placement "right"})
|
||||
:subscription params}]]]
|
||||
[:div
|
||||
[:div.field
|
||||
[:label.checkbox
|
||||
[bind-field
|
||||
[:input {:type "checkbox"
|
||||
:field [:show-advanced?]
|
||||
:event [::period-inputs-change]
|
||||
:subscription period-inputs}]]
|
||||
" Show Advanced"]]]
|
||||
(when (:show-advanced? period-inputs)
|
||||
(for [[_ i] (map vector periods (range))]
|
||||
^{:key i}
|
||||
[:div.field.is-grouped
|
||||
[:div.control
|
||||
[:p.help "From"]
|
||||
[bind-field
|
||||
[date-picker {:class-name "input"
|
||||
:class "input"
|
||||
:format-week-number (fn [] "")
|
||||
:previous-month-button-label ""
|
||||
:placeholder "mm/dd/yyyy"
|
||||
:next-month-button-label ""
|
||||
:next-month-label ""
|
||||
:type "date"
|
||||
:field [:periods i 0]
|
||||
:event [::date-picked]
|
||||
:popper-props (clj->js {:placement "right"})
|
||||
:subscription params}]]]
|
||||
|
||||
[:div.control
|
||||
[:p.help "To"]
|
||||
[bind-field
|
||||
[date-picker {:class-name "input"
|
||||
:class "input"
|
||||
:format-week-number (fn [] "")
|
||||
:previous-month-button-label ""
|
||||
:placeholder "mm/dd/yyyy"
|
||||
:next-month-button-label ""
|
||||
:next-month-label ""
|
||||
:type "date"
|
||||
:field [:periods i 1]
|
||||
:event [::date-picked]
|
||||
:popper-props (clj->js {:placement "right"})
|
||||
:subscription params}]]]])]
|
||||
[:div.control
|
||||
[:p.help "To"]
|
||||
[bind-field
|
||||
[date-picker {:class-name "input"
|
||||
:class "input"
|
||||
:format-week-number (fn [] "")
|
||||
:previous-month-button-label ""
|
||||
:placeholder "mm/dd/yyyy"
|
||||
:next-month-button-label ""
|
||||
:next-month-label ""
|
||||
:type "date"
|
||||
:field [:periods i 1]
|
||||
:event [::date-picked]
|
||||
:popper-props (clj->js {:placement "right"})
|
||||
:subscription params}]]]]))]
|
||||
[status/big-loader status]
|
||||
[:div
|
||||
[:<>
|
||||
(for [location @(re-frame/subscribe [::locations])]
|
||||
^{:key (str location "-summary")}
|
||||
[location-summary location params]
|
||||
)]
|
||||
[:h2.title.is-4 {:style {:margin-bottom "1rem"}} "Detail"]
|
||||
[:table.table.compact.balance-sheet
|
||||
[:tbody
|
||||
[:tr
|
||||
[:td.has-text-right "Period Ending"]
|
||||
(map-periods
|
||||
(fn [i]
|
||||
[:<>
|
||||
[:td.has-text-right (date->str (get-in periods [i 1]))]
|
||||
[:td]])
|
||||
(fn [i]
|
||||
[:td.has-text-right "𝝙"])
|
||||
periods)]
|
||||
(when (not= :loading (:state status))
|
||||
[:div
|
||||
[:<>
|
||||
(for [location @(re-frame/subscribe [::locations])]
|
||||
^{:key location}
|
||||
[location-rows location]
|
||||
)]]]]])))
|
||||
{:component-will-mount #(do (re-frame/dispatch-sync [::range-selected (and-last-year [(t/minus (local-today) (t/period :years 1)) (local-today)]) nil])) }))
|
||||
^{:key (str location "-summary")}
|
||||
[location-summary location params]
|
||||
)]
|
||||
[:h2.title.is-4 {:style {:margin-bottom "1rem"}} "Detail"]
|
||||
[:table.table.compact.balance-sheet
|
||||
[:tbody
|
||||
[:tr
|
||||
[:td.has-text-right "Period Ending"]
|
||||
(map-periods
|
||||
(fn [i]
|
||||
[:<>
|
||||
[:td.has-text-right
|
||||
(or (get-in periods [i 2])
|
||||
(date->str (get-in periods [i 1])))]
|
||||
[:td]])
|
||||
(fn [i]
|
||||
[:td.has-text-right "𝝙"])
|
||||
periods
|
||||
(:include-deltas params))]
|
||||
[:<>
|
||||
(for [location @(re-frame/subscribe [::locations])]
|
||||
^{:key location}
|
||||
[location-rows location]
|
||||
)]]]])])))
|
||||
{:component-will-mount #(re-frame/dispatch [::mounted]) }))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted
|
||||
::unmounted-pnl
|
||||
(fn [{:keys [db]} _]
|
||||
{:dispatch [::data-page/dispose ::ledger]
|
||||
::track/dispose {:id ::ledger-params}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::mounted
|
||||
::mounted-pnl
|
||||
(fn [{:keys [db]} _]
|
||||
{::track/register {:id ::ledger-params
|
||||
:subscription [::data-page/params ::ledger]
|
||||
@@ -614,8 +742,8 @@
|
||||
(defn profit-and-loss-page []
|
||||
(reagent/create-class
|
||||
{:display-name "profit-and-loss-page"
|
||||
:component-did-mount #(re-frame/dispatch [::mounted])
|
||||
:component-will-unmount #(re-frame/dispatch [::unmounted])
|
||||
:component-did-mount #(re-frame/dispatch [::mounted-pnl])
|
||||
:component-will-unmount #(re-frame/dispatch [::unmounted-pnl])
|
||||
:reagent-render
|
||||
(fn []
|
||||
(let [ledger-list-active? @(re-frame/subscribe [::ledger-list-active?])
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
[:p.menu-label "Vendor"]
|
||||
[:div
|
||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
|
||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/searchable-vendors])
|
||||
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor %])
|
||||
:include-keys [:name :id]
|
||||
:match->text :name
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
[auto-ap.views.components.grid :as grid]
|
||||
[auto-ap.views.pages.data-page :as data-page]))
|
||||
|
||||
(defn ledger-row [{{:keys [client vendor status date amount id line-items] :as i} :row
|
||||
(defn ledger-row [{{:keys [client vendor alternate-description status date amount id line-items] :as i} :row
|
||||
:keys [selected-client accounts-by-id bank-accounts-by-id]}]
|
||||
[:<>
|
||||
[grid/row {:class (:class i) :id id}
|
||||
@@ -17,7 +17,8 @@
|
||||
[grid/cell {} (:name client)])
|
||||
[grid/cell {} (if vendor
|
||||
(:name vendor)
|
||||
[:i.has-text-grey (str "Unknown Merchant")])]
|
||||
[:i.has-text-grey (or (when alternate-description (str "Bank Description: " alternate-description))
|
||||
"Unknown Merchant")])]
|
||||
[grid/cell {} (date->str date) ]
|
||||
[grid/cell {} ]
|
||||
[grid/cell {:class "has-text-right"} (nf amount )]
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
[:div
|
||||
[:p.menu-label "Vendor"]
|
||||
[:div
|
||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
|
||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/searchable-vendors])
|
||||
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor %])
|
||||
:include-keys [:name :id]
|
||||
:match->text :name
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
|
||||
[:p.menu-label "Vendor"]
|
||||
[:div
|
||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
|
||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/searchable-vendors])
|
||||
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor %])
|
||||
:include-keys [:name :id]
|
||||
:match->text :name
|
||||
|
||||
Reference in New Issue
Block a user