customized transactions.

This commit is contained in:
Bryce Covert
2020-04-30 07:22:39 -07:00
parent 8043fb0b81
commit 4a6aeaab8f
18 changed files with 184 additions and 126 deletions

View File

@@ -41,8 +41,17 @@
(defn expense-account? [account] (defn expense-account? [account]
(= :account-type/expense (:db/ident (:account/type account)))) (= :account-type/expense (:db/ident (:account/type account))))
(defn account-name [account client]
(let [overriden-name (->>
(:account/client-overrides account)
(filter (fn [co]
(= (:db/id (:account-client-override/client co)) (:db/id client))))
(map :account-client-override/name)
first)]
(defn roll-up [results] (or overriden-name (:account/name account))))
(defn roll-up [client results]
(->> results (->> results
(mapcat :journal-entry/line-items) (mapcat :journal-entry/line-items)
(group-by (juxt :journal-entry-line/account :journal-entry-line/location)) (group-by (juxt :journal-entry-line/account :journal-entry-line/location))
@@ -51,9 +60,10 @@
#_(when-not (or (:bank-account/name account) (:account/name account)) #_(when-not (or (:bank-account/name account) (:account/name account))
(println "WARNING " account line-items)) (println "WARNING " account line-items))
(conj result (conj result
{:name (str (or (:bank-account/name account) (:account/name account)) (when-not (#{"A" } location) {:name (str (or (:bank-account/name account) (account-name account client))
(str (when-not (#{"A" } location)
"-" location))) (str
"-" location)))
:location location :location location
:id (str (:db/id account) "-" location) :id (str (:db/id account) "-" location)
:numeric-code (or (:account/numeric-code account) :numeric-code (or (:account/numeric-code account)
@@ -87,6 +97,7 @@
(defn get-balance-sheet [context args value] (defn get-balance-sheet [context args value]
(let [args (assoc args :id (:id context)) (let [args (assoc args :id (:id context))
client (d-clients/get-by-id (:client_id args))
[results] (l/get-graphql {:client-id (:client_id args) [results] (l/get-graphql {:client-id (:client_id args)
:date-range {:end (coerce/to-date (:date args))} :date-range {:end (coerce/to-date (:date args))}
:count Integer/MAX_VALUE}) :count Integer/MAX_VALUE})
@@ -96,12 +107,13 @@
:to-date (coerce/to-date (time/minus (:date args) (time/years 1))) :to-date (coerce/to-date (time/minus (:date args) (time/years 1)))
:count Integer/MAX_VALUE})] :count Integer/MAX_VALUE})]
(->graphql (->graphql
{:balance-sheet-accounts (roll-up results) {:balance-sheet-accounts (roll-up client results)
:comparable-balance-sheet-accounts (roll-up comparable-results)}))) :comparable-balance-sheet-accounts (roll-up client comparable-results)})))
(defn get-profit-and-loss [context args value] (defn get-profit-and-loss [context args value]
(let [args (assoc args :id (:id context)) (let [args (assoc args :id (:id context))
client (d-clients/get-by-id (:client_id args))
pnl (fn [from-date to-date] pnl (fn [from-date to-date]
(println "FROM" from-date to-date) (println "FROM" from-date to-date)
(let [[starting-results] (l/get-graphql {:client-id (:client_id args) (let [[starting-results] (l/get-graphql {:client-id (:client_id args)
@@ -112,8 +124,8 @@
[ending-results] (l/get-graphql {:client-id (:client_id args) [ending-results] (l/get-graphql {:client-id (:client_id args)
:date-range {:end (coerce/to-date to-date)} :date-range {:end (coerce/to-date to-date)}
:count Integer/MAX_VALUE}) :count Integer/MAX_VALUE})
starting-accounts (by :id (roll-up starting-results)) starting-accounts (by :id (roll-up client starting-results))
ending-accounts (by :id (roll-up ending-results))] ending-accounts (by :id (roll-up client ending-results))]
(reduce-kv (reduce-kv
(fn [results k v] (fn [results k v]
(conj results (update v :amount (fn [amt] (conj results (update v :amount (fn [amt]

View File

@@ -43,7 +43,7 @@
:journal-entry/vendor (:db/id (:invoice/vendor entity)) :journal-entry/vendor (:db/id (:invoice/vendor entity))
:journal-entry/amount (:invoice/total entity) :journal-entry/amount (:invoice/total entity)
:journal-entry/line-items (into [{:journal-entry-line/account (a/get-account-by-numeric-code-and-sets 2110 ["default"]) :journal-entry/line-items (into [{:journal-entry-line/account (:db/id (a/get-account-by-numeric-code-and-sets 2110 ["default"]))
:journal-entry-line/location "A" :journal-entry-line/location "A"
:journal-entry-line/credit (:invoice/total entity)}] :journal-entry-line/credit (:invoice/total entity)}]
(map (fn [ea] (map (fn [ea]
@@ -138,7 +138,7 @@
(doseq [d-tx d-txs] (doseq [d-tx d-txs]
#_(println "updating general-ledger " d-tx) (println "updating general-ledger " d-tx)
@(d/transact (d/connect uri) [d-tx])))) @(d/transact (d/connect uri) [d-tx]))))
(def break (atom false)) (def break (atom false))

View File

@@ -16,33 +16,71 @@
(sort-by :name (vals (:clients db)))))) (sort-by :name (vals (:clients db))))))
(re-frame/reg-sub (re-frame/reg-sub
::accounts ::all-accounts
(fn [db] (fn [db]
(:accounts db))) (:accounts db)))
(re-frame/reg-sub
::all-accounts-by-id
(fn [db]
(by :id (:accounts db))))
(defn clientize-account [account client]
(let [override (->>
(:client-overrides account)
(filter (fn [co]
(= (:id (:client co)) (:id client))))
first)]
(condp = (:applicability account)
nil
(assoc account :name (or (:name override) (:name account)))
:global
(assoc account :name (or (:name override) (:name account)))
:optional
(when override
(assoc account :name (or (:name override) (:name account))))
:customized
(when override
(assoc account :name (or (:name override) (:name account)))))))
(re-frame/reg-sub
::accounts
:<- [::all-accounts]
:<- [::client]
(fn [[accounts client] [_ client-override]]
(transduce
(comp
(map
#(clientize-account % (or client-override client)))
(filter identity))
conj
[]
accounts)))
(re-frame/reg-sub (re-frame/reg-sub
::account ::account
(fn [[_ client]]
[(re-frame/subscribe [::accounts-by-id client])])
(fn [[as] [_ _ i]]
(as i)))
(defn accounts-by-id [accounts client]
(by :id
(map
#(clientize-account % client)
accounts)))
(re-frame/reg-sub
::accounts-by-id
:<- [::accounts] :<- [::accounts]
(fn [as [_ i]] :<- [::client]
(first (filter (fn [[accounts client] [_ client-override]]
#(= (:id %) i) (accounts-by-id accounts (or client-override client))))
as))))
(re-frame/reg-sub
::accounts-for-client
(fn [db client]
(:accounts db)))
(re-frame/reg-sub
::accounts-for-client-by-id
(fn [db client]
(by :id (:accounts db))))
(re-frame/reg-sub
::accounts-for-current-client
(fn [db]
(:accounts db)))
(re-frame/reg-sub (re-frame/reg-sub
::bank-accounts ::bank-accounts
@@ -132,7 +170,8 @@
(re-frame/reg-sub (re-frame/reg-sub
::vendor-default-account ::vendor-default-account
(fn [db [_ v client]] (fn [db [_ v client]]
(let [vendor (if (:default-account v) (let [accounts (accounts-by-id (:accounts db) client)
vendor (if (:default-account v)
v v
(-> (:vendors db) (get v))) (-> (:vendors db) (get v)))
client-override (->> (:account-overrides vendor) client-override (->> (:account-overrides vendor)
@@ -143,9 +182,7 @@
:id) :id)
default-id (:id (:default-account v)) default-id (:id (:default-account v))
i (or client-override default-id)] i (or client-override default-id)]
(first (filter (accounts i))))
#(= (:id %) i)
(:accounts db))))))
(re-frame/reg-sub (re-frame/reg-sub
::sorted-vendors ::sorted-vendors
@@ -202,12 +239,6 @@
(fn [db] (fn [db]
(:query-params db))) (:query-params db)))
(re-frame/reg-sub
::chooseable-expense-accounts
:<- [::accounts-for-current-client]
(fn [accounts]
accounts))
(re-frame/reg-sub (re-frame/reg-sub
::page-failure ::page-failure
(fn [db] (fn [db]

View File

@@ -113,7 +113,7 @@
(let [{{:keys [expense-accounts total] :or {expense-accounts [] total 0} {:keys [locations]} :client} :invoice error :error :as data} @(re-frame/subscribe [::change-expense-accounts]) (let [{{:keys [expense-accounts total] :or {expense-accounts [] total 0} {:keys [locations]} :client} :invoice error :error :as data} @(re-frame/subscribe [::change-expense-accounts])
multi-location? (> (count locations) 1) multi-location? (> (count locations) 1)
change-event [::change] change-event [::change]
chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts]) chooseable-expense-accounts @(re-frame/subscribe [::subs/accounts (:client (:invoice data))])
expense-accounts-total (->> expense-accounts expense-accounts-total (->> expense-accounts
(map :new-amount) (map :new-amount)
(map js/parseFloat) (map js/parseFloat)
@@ -143,8 +143,7 @@
[:th {:style {:width "5em"}}]]] [:th {:style {:width "5em"}}]]]
[:tbody [:tbody
(doall (for [{:keys [id] :as expense-account} expense-accounts (doall (for [{:keys [id] :as expense-account} expense-accounts
:let [sub @(re-frame/subscribe [::expense-account (:id expense-account)]) :let [sub @(re-frame/subscribe [::expense-account (:id expense-account)])]]
_ (println "SUBB" sub)]]
^{:key id} ^{:key id}
[:tr [:tr
[:td.expandable [:div.control [:td.expandable [:div.control
@@ -158,7 +157,7 @@
(when multi-location? (when multi-location?
[:td [:td
(if-let [forced-location (:location @(re-frame/subscribe [::subs/account (-> sub :account :id )]))] (if-let [forced-location (:location @(re-frame/subscribe [::subs/account (:client (:invoice data)) (-> sub :account :id )]))]
[:div.select [:div.select
[:select {:disabled "disabled" :value forced-location} [:option {:value forced-location} forced-location]]] [:select {:disabled "disabled" :value forced-location} [:option {:value forced-location} forced-location]]]
[:div.select [:div.select

View File

@@ -27,11 +27,14 @@
:account default-account}]) :account default-account}])
(defn from-graphql [accounts total locations] (defn from-graphql [accounts accounts-by-id total locations]
(if (seq accounts) (if (seq accounts)
(vec (map (vec (map
(fn [a] (fn [a]
(-> a (-> a
(update :account (fn [a]
(accounts-by-id (:id a))))
(update :amount js/parseFloat) (update :amount js/parseFloat)
(assoc :amount-percentage (* 100 (/ (js/parseFloat (:amount a)) (assoc :amount-percentage (* 100 (/ (js/parseFloat (:amount a))
(Math/abs (js/parseFloat total))))) (Math/abs (js/parseFloat total)))))
@@ -93,7 +96,7 @@
(fn [_ [_ event expense-accounts max-value field value]] (fn [_ [_ event expense-accounts max-value field value]]
(let [updated-accounts (cond-> expense-accounts (let [updated-accounts (cond-> expense-accounts
true (assoc-in field value) true (assoc-in field value)
(= (list :account :id) (drop 1 field)) (assoc-in [(first field) :account] @(re-frame/subscribe [::subs/account value])) (= (list :account :id) (drop 1 field)) (assoc-in [(first field) :account] @(re-frame/subscribe [::subs/account nil value]))
(= (list :amount-percentage) (drop 1 field)) (assoc-in [(first field) :amount] (= (list :amount-percentage) (drop 1 field)) (assoc-in [(first field) :amount]
(js/parseFloat (js/parseFloat
(goog.string/format "%.2f" (goog.string/format "%.2f"
@@ -108,9 +111,9 @@
;; VIEWS ;; VIEWS
(defn expense-accounts-field [{expense-accounts :value max-value :max locations :locations event :event descriptor :descriptor disabled :disabled percentage-only? :percentage-only? :or {percentage-only? false}}] (defn expense-accounts-field [{expense-accounts :value client :client max-value :max locations :locations event :event descriptor :descriptor disabled :disabled percentage-only? :percentage-only? :or {percentage-only? false}}]
(let [chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts]) (let [chooseable-expense-accounts @(re-frame/subscribe [::subs/accounts client])
accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])] accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id client])]
[:div [:div
[:div.columns [:div.columns
[:div.column [:div.column
@@ -151,8 +154,10 @@
[:p.help "Account"] [:p.help "Account"]
[:div.control.is-fullwidth [:div.control.is-fullwidth
[bind-field [bind-field
^{:key (:id client)}
[typeahead-entity {:matches chooseable-expense-accounts [typeahead-entity {:matches chooseable-expense-accounts
:match->text (fn [x ] (str (:numeric-code x) " - " (:name x))) :match->text (fn [x ]
(str (:numeric-code x) " - " (:name x)))
:disabled disabled :disabled disabled
:type "typeahead-entity" :type "typeahead-entity"
:field [index :account] :field [index :account]

View File

@@ -49,7 +49,7 @@
[[:invoices [:id :total :outstanding-balance :invoice-number :date :due :status :client-identifier [[:invoices [:id :total :outstanding-balance :invoice-number :date :due :status :client-identifier
[:vendor [:name :id]] [:vendor [:name :id]]
[:expense_accounts [:amount :id :location [:expense_accounts [:amount :id :location
[:account [:id :name :numeric-code :location ]]]] [:account [:id ]]]]
[:client [:name :id :locations]] [:client [:name :id :locations]]
[:payments [:amount :id [:payment [:id :status :amount :s3_url :check_number [:payments [:amount :id [:payment [:id :status :amount :s3_url :check_number
[:transaction [:post_date]]]]]]]] [:transaction [:post_date]]]]]]]]
@@ -70,7 +70,9 @@
:dispatch [:auto-ap.views.pages.unpaid-invoices/params-change]})) :dispatch [:auto-ap.views.pages.unpaid-invoices/params-change]}))
(defn row [{:keys [invoice check-boxes checked on-check-changed selected-client overrides expense-event on-edit-invoice on-void-invoice on-unvoid-invoice]}] (defn row [{:keys [invoice check-boxes checked on-check-changed selected-client overrides expense-event on-edit-invoice on-void-invoice on-unvoid-invoice]}]
(let [{:keys [client payments expense-accounts invoice-number date due total outstanding-balance id vendor] :as i} invoice] (let [{:keys [client payments expense-accounts invoice-number date due total outstanding-balance id vendor] :as i} invoice
accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id client])
account->name #(:name (accounts-by-id (:id %)))]
[:tr {:class (:class i)} [:tr {:class (:class i)}
(when check-boxes (when check-boxes
[:td [:input.checkbox {:type "checkbox" [:td [:input.checkbox {:type "checkbox"
@@ -104,7 +106,7 @@
[:div [:div
(for [e expense-accounts] (for [e expense-accounts]
^{:key (:id e)} ^{:key (:id e)}
[:span.dropdown-item (:name (:account e)) " " (gstring/format "$%.2f" (:amount e) ) ]) [:span.dropdown-item (account->name (:account e)) " " (gstring/format "$%.2f" (:amount e) ) ])
[:hr.dropdown-divider] [:hr.dropdown-divider]

View File

@@ -42,7 +42,7 @@
(not can-submit?) (assoc :disabled "disabled")) (not can-submit?) (assoc :disabled "disabled"))
] ]
:id id :id id
:hide-event [::events/modal-status id {:visible? false}]} :hide-event [::events/modal-status id {:visible? false :error-message nil}]}
[appearing {:visible? error-message [appearing {:visible? error-message
:timeout 200 :timeout 200
:enter-class "appear" :enter-class "appear"

View File

@@ -78,7 +78,7 @@
%)) %))
(update :default-account (update :default-account
(fn [da] (fn [da]
@(re-frame/subscribe [::subs/account (:id da)])))))) @(re-frame/subscribe [::subs/account nil (:id da)]))))))
:dispatch [::events/modal-status ::dialog {:visible? true}]})) :dispatch [::events/modal-status ::dialog {:visible? true}]}))
(re-frame/reg-event-db (re-frame/reg-event-db
@@ -170,7 +170,7 @@
[:a.button {:on-click (dispatch-event [::removed-override override-key i])} [:span.icon [:span.icon-remove]]]]])])])) [:a.button {:on-click (dispatch-event [::removed-override override-key i])} [:span.icon [:span.icon-remove]]]]])])]))
(defn form-content [{:keys [data change-event]}] (defn form-content [{:keys [data change-event]}]
(let [chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts]) (let [accounts @(re-frame/subscribe [::subs/accounts])
clients @(re-frame/subscribe [::subs/clients])] clients @(re-frame/subscribe [::subs/clients])]
[:div [:div
[horizontal-field [horizontal-field
@@ -219,7 +219,7 @@
[default-with-overrides {:data data :change-event change-event [default-with-overrides {:data data :change-event change-event
:default-key :default-account :default-key :default-account
:override-key :account-overrides} :override-key :account-overrides}
[typeahead-entity {:matches chooseable-expense-accounts [typeahead-entity {:matches accounts
:match->text (fn [x ] (str (:numeric-code x) " - " (:name x))) :match->text (fn [x ] (str (:numeric-code x) " - " (:name x)))
:type "typeahead-entity" :type "typeahead-entity"
:event change-event :event change-event

View File

@@ -44,7 +44,7 @@
(defn admin-accounts-content [] (defn admin-accounts-content []
[:div [:div
(let [accounts @(re-frame/subscribe [::subs/accounts])] (let [accounts @(re-frame/subscribe [::subs/all-accounts])]
[:div [:div
[:h1.title "Accounts"] [:h1.title "Accounts"]
[:div.is-pulled-right [:div.is-pulled-right

View File

@@ -115,7 +115,7 @@
form @(re-frame/subscribe [::forms/form ::excel-import]) form @(re-frame/subscribe [::forms/form ::excel-import])
chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts]) chooseable-expense-accounts @(re-frame/subscribe [::subs/all-accounts])
change-event [::all-events/change-form [::expense-accounts]]] change-event [::all-events/change-form [::expense-accounts]]]
(println form) (println form)
[:div [:div

View File

@@ -135,23 +135,26 @@
(re-frame/reg-event-db (re-frame/reg-event-db
::editing ::editing
(fn [db [_ which]] (fn [db [_ which]]
(-> db (forms/start-form ::form (-> which (let [accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id (:client which)])]
(select-keys [:description (-> db (forms/start-form ::form (-> which
:id (select-keys [:description
:client :id
:bank-account :client
:note :bank-account
:amount-lte :note
:amount-gte :amount-lte
:dom-lte :amount-gte
:dom-gte :dom-lte
:vendor :dom-gte
:accounts :vendor
:yodlee-merchant :accounts
:transaction-approval-status]) :yodlee-merchant
(update :accounts (fn [xs] :transaction-approval-status])
(mapv #(assoc % :amount-percentage (* (:percentage %) 100.0)) (update :accounts (fn [xs]
xs)))))))) (mapv #(-> %
(assoc :amount-percentage (* (:percentage %) 100.0))
(update :account (fn [a] (accounts-by-id (:id a)))))
xs)))))))))
(re-frame/reg-event-db (re-frame/reg-event-db
@@ -219,9 +222,7 @@
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::form]) (let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::form])
{:keys [form field raw-field error-notification submit-button ]} rule-form {:keys [form field raw-field error-notification submit-button ]} rule-form
default-note @(re-frame/subscribe [::default-note]) default-note @(re-frame/subscribe [::default-note])
exists? (:id data) exists? (:id data)]
chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])
accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])]
^{:key id} ^{:key id}
[form (assoc params :title "New Transaction Rule") [form (assoc params :title "New Transaction Rule")
@@ -307,6 +308,7 @@
[expense-accounts-field {:type "expense-accounts" [expense-accounts-field {:type "expense-accounts"
:descriptor "account asssignment" :descriptor "account asssignment"
:percentage-only? true :percentage-only? true
:client (:client data)
:locations (into ["Shared"] @(re-frame/subscribe [::subs/locations-for-client-or-bank-account (:id (:client data)) (:id (:bank-account data))])) :locations (into ["Shared"] @(re-frame/subscribe [::subs/locations-for-client-or-bank-account (:id (:client data)) (:id (:bank-account data))]))
:max 100 :max 100
:field [:accounts]}]] :field [:accounts]}]]

View File

@@ -106,15 +106,18 @@
(re-frame/reg-event-db (re-frame/reg-event-db
::adding ::adding
(fn [db [_ new]] (fn [db [_ new]]
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:client new)])] (let [locations @(re-frame/subscribe [::subs/locations-for-client (:client new)])
accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id (:client new)])]
(-> db (forms/start-form ::form (assoc new :expense-accounts (-> db (forms/start-form ::form (assoc new :expense-accounts
(expense-accounts-field/from-graphql (:expense-accounts new) (expense-accounts-field/from-graphql (:expense-accounts new)
accounts-by-id
0.0 0.0
locations))))))) locations)))))))
(re-frame/reg-event-db (re-frame/reg-event-db
::editing ::editing
(fn [db [_ which]] (fn [db [_ which]]
(let [edit-invoice (update which :date #(date->str % standard)) (let [accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id (:client which)])
edit-invoice (update which :date #(date->str % standard))
edit-invoice (update edit-invoice :due #(date->str % standard)) edit-invoice (update edit-invoice :due #(date->str % standard))
edit-invoice (assoc edit-invoice :original edit-invoice) edit-invoice (assoc edit-invoice :original edit-invoice)
locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client which))])] locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client which))])]
@@ -129,6 +132,7 @@
:vendor (:vendor edit-invoice) :vendor (:vendor edit-invoice)
:client (:client edit-invoice) :client (:client edit-invoice)
:expense-accounts (expense-accounts-field/from-graphql (:expense-accounts which) :expense-accounts (expense-accounts-field/from-graphql (:expense-accounts which)
accounts-by-id
(:amount which) (:amount which)
locations)}))))) locations)})))))
@@ -212,9 +216,7 @@
can-change-amount? (#{:unpaid ":unpaid"} (:status data)) can-change-amount? (#{:unpaid ":unpaid"} (:status data))
min-total (if (= (:total (:original data)) (:outstanding-balance (:original data))) min-total (if (= (:total (:original data)) (:outstanding-balance (:original data)))
nil nil
(- (:total (:original data)) (:outstanding-balance (:original data)))) (- (:total (:original data)) (:outstanding-balance (:original data))))]
chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])
accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])]
^{:key id} ^{:key id}
[form (assoc params :title "New Invoice") [form (assoc params :title "New Invoice")
(when-not @(re-frame/subscribe [::subs/client]) (when-not @(re-frame/subscribe [::subs/client])
@@ -278,6 +280,7 @@
:descriptor "expense account" :descriptor "expense account"
:locations (:locations (:client data)) :locations (:locations (:client data))
:max (:total data) :max (:total data)
:client (or (:client data) @(re-frame/subscribe [::subs/client]))
:field [:expense-accounts]}]] :field [:expense-accounts]}]]

View File

@@ -59,7 +59,7 @@
[:name :id]] [:name :id]]
[:line-items [:line-items
[:id :debit :credit :location [:id :debit :credit :location
[:account [:id :name]]]] [:account [:id]]]]
:date]] :date]]
:total :total
:start :start

View File

@@ -173,40 +173,44 @@
(let [current-client @(re-frame/subscribe [::subs/client]) (let [current-client @(re-frame/subscribe [::subs/client])
user @(re-frame/subscribe [::subs/user]) user @(re-frame/subscribe [::subs/user])
params @(re-frame/subscribe [::params])] params @(re-frame/subscribe [::params])]
[:div.is-inline (if current-client
[:h1.title "Balance Sheet"] [:div.is-inline
[:div.report-controls [:h1.title "Balance Sheet"]
[:p.help "Date"] [:div.report-controls
[bind-field [:p.help "Date"]
[date-picker {:class-name "input" [bind-field
:class "input" [date-picker {:class-name "input"
:format-week-number (fn [] "") :class "input"
:previous-month-button-label "" :format-week-number (fn [] "")
:placeholder "mm/dd/yyyy" :previous-month-button-label ""
:next-month-button-label "" :placeholder "mm/dd/yyyy"
:next-month-label "" :next-month-button-label ""
:type "date" :next-month-label ""
:field [:date] :type "date"
:event [::date-picked] :field [:date]
:popper-props (clj->js {:placement "right"}) :event [::date-picked]
:subscription params}]]] :popper-props (clj->js {:placement "right"})
(if @(re-frame/subscribe [::loading]) :subscription params}]]]
[:div [:i.icon.fa.fa-spin.fa-spinner]] (if @(re-frame/subscribe [::loading])
[:table.table.compact.balance-sheet [:div [:i.icon.fa.fa-spin.fa-spinner]]
[:tr [:table.table.compact.balance-sheet
[:td.has-text-right "Period ending"] [:tr
[:td.has-text-right (date->str (str->date (:date params) standard))] [:td.has-text-right "Period ending"]
[:td.has-text-right (when (:date params) [:td.has-text-right (date->str (str->date (:date params) standard))]
(date->str (t/minus (str->date (:date params) standard) (t/years 1))))] [:td.has-text-right (when (:date params)
[:td]] (date->str (t/minus (str->date (:date params) standard) (t/years 1))))]
(list [:td]]
(overall-grouping :asset "Assets") (list
(overall-grouping :liability "Liabilities" ) (overall-grouping :asset "Assets")
(overall-grouping :equity "Owner's Equity" ) (overall-grouping :liability "Liabilities" )
(retained-earnings))]) (overall-grouping :equity "Owner's Equity" )
(retained-earnings))])
])) ]
[:div
[:h1.title "Balance sheet"]
[:h2.subtitle "Please choose a client first"]])))
{:component-will-mount #(re-frame/dispatch-sync [::params-change {:date (date->str (local-now) standard)}]) })) {:component-will-mount #(re-frame/dispatch-sync [::params-change {:date (date->str (local-now) standard)}]) }))
(defn balance-sheet-page [] (defn balance-sheet-page []

View File

@@ -132,7 +132,6 @@
(re-frame/reg-event-db (re-frame/reg-event-db
::error ::error
(fn [db [_ [error]]] (fn [db [_ [error]]]
(println (:message error))
(assoc db ::error (:message error) (assoc db ::error (:message error)
::loading false))) ::loading false)))
@@ -209,7 +208,6 @@
(re-frame/reg-event-fx (re-frame/reg-event-fx
::investigate-clicked ::investigate-clicked
(fn [{:keys [db] } [_ location from-numeric-code to-numeric-code which]] (fn [{:keys [db] } [_ location from-numeric-code to-numeric-code which]]
(println from-numeric-code to-numeric-code)
{:db (assoc db {:db (assoc db
::ledger-list-active? true ::ledger-list-active? true
::ledger-list-loading true) ::ledger-list-loading true)

View File

@@ -25,6 +25,7 @@
(let [{:keys [sort]} @(re-frame/subscribe [::table-params]) (let [{:keys [sort]} @(re-frame/subscribe [::table-params])
{:keys [journal-entries start end count total]} @ledger-page {:keys [journal-entries start end count total]} @ledger-page
selected-client @(re-frame/subscribe [::subs/client]) selected-client @(re-frame/subscribe [::subs/client])
accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id selected-client])
percentage-size (if selected-client "25%" "33%") percentage-size (if selected-client "25%" "33%")
opc (fn [e] opc (fn [e]
(re-frame/dispatch [::params-changed e]))] (re-frame/dispatch [::params-changed e]))]
@@ -114,7 +115,8 @@
(when status? (when status?
[:td status])]] [:td status])]]
(for [{:keys [debit credit location account id]} line-items] (for [{:keys [debit credit location account id]} line-items
:let [account (accounts-by-id (:id account))]]
^{:key id} ^{:key id}
[:tr {:class (:class i)} [:tr {:class (:class i)}
(when-not selected-client (when-not selected-client

View File

@@ -160,6 +160,5 @@
[manual/modal {:import-completed [::manual-import-completed ]}]] [manual/modal {:import-completed [::manual-import-completed ]}]]
:right-side-bar [appearing-side-bar :right-side-bar [appearing-side-bar
{:visible? transaction-bar-active?} {:visible? transaction-bar-active?}
[edit/form {:edit-completed [::edit-completed]}]]}]))}) [edit/form {:edit-completed [::edit-completed]}]]}]))}))
)

View File

@@ -45,7 +45,8 @@
(re-frame/reg-event-db (re-frame/reg-event-db
::editing ::editing
(fn [db [_ which potential-payment-matches potential-transaction-rule-matches]] (fn [db [_ which potential-payment-matches potential-transaction-rule-matches]]
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client which))])] (let [locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client which))])
accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id (:client which)])]
(forms/start-form db ::form (forms/start-form db ::form
(-> which (-> which
(select-keys [:vendor :amount :payment :client :description-original (select-keys [:vendor :amount :payment :client :description-original
@@ -59,7 +60,7 @@
(assoc :potential-transaction-rule-matches (if (:matched-rule which) (assoc :potential-transaction-rule-matches (if (:matched-rule which)
nil nil
potential-transaction-rule-matches)) potential-transaction-rule-matches))
(update :accounts expense-accounts-field/from-graphql (:amount which) locations)))))) (update :accounts expense-accounts-field/from-graphql accounts-by-id (:amount which) locations))))))
(re-frame/reg-event-db (re-frame/reg-event-db
::changed ::changed