customized transactions.
This commit is contained in:
@@ -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])
|
||||
multi-location? (> (count locations) 1)
|
||||
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
|
||||
(map :new-amount)
|
||||
(map js/parseFloat)
|
||||
@@ -143,8 +143,7 @@
|
||||
[:th {:style {:width "5em"}}]]]
|
||||
[:tbody
|
||||
(doall (for [{:keys [id] :as expense-account} expense-accounts
|
||||
:let [sub @(re-frame/subscribe [::expense-account (:id expense-account)])
|
||||
_ (println "SUBB" sub)]]
|
||||
:let [sub @(re-frame/subscribe [::expense-account (:id expense-account)])]]
|
||||
^{:key id}
|
||||
[:tr
|
||||
[:td.expandable [:div.control
|
||||
@@ -158,7 +157,7 @@
|
||||
|
||||
(when multi-location?
|
||||
[: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
|
||||
[:select {:disabled "disabled" :value forced-location} [:option {:value forced-location} forced-location]]]
|
||||
[:div.select
|
||||
|
||||
@@ -27,11 +27,14 @@
|
||||
:account default-account}])
|
||||
|
||||
|
||||
(defn from-graphql [accounts total locations]
|
||||
(defn from-graphql [accounts accounts-by-id total locations]
|
||||
(if (seq accounts)
|
||||
(vec (map
|
||||
(fn [a]
|
||||
(-> a
|
||||
(update :account (fn [a]
|
||||
(accounts-by-id (:id a))))
|
||||
|
||||
(update :amount js/parseFloat)
|
||||
(assoc :amount-percentage (* 100 (/ (js/parseFloat (:amount a))
|
||||
(Math/abs (js/parseFloat total)))))
|
||||
@@ -93,7 +96,7 @@
|
||||
(fn [_ [_ event expense-accounts max-value field value]]
|
||||
(let [updated-accounts (cond-> expense-accounts
|
||||
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]
|
||||
(js/parseFloat
|
||||
(goog.string/format "%.2f"
|
||||
@@ -108,9 +111,9 @@
|
||||
|
||||
|
||||
;; 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}}]
|
||||
(let [chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])
|
||||
accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])]
|
||||
(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/accounts client])
|
||||
accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id client])]
|
||||
[:div
|
||||
[:div.columns
|
||||
[:div.column
|
||||
@@ -151,8 +154,10 @@
|
||||
[:p.help "Account"]
|
||||
[:div.control.is-fullwidth
|
||||
[bind-field
|
||||
^{:key (:id client)}
|
||||
[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
|
||||
:type "typeahead-entity"
|
||||
:field [index :account]
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
[[:invoices [:id :total :outstanding-balance :invoice-number :date :due :status :client-identifier
|
||||
[:vendor [:name :id]]
|
||||
[:expense_accounts [:amount :id :location
|
||||
[:account [:id :name :numeric-code :location ]]]]
|
||||
[:account [:id ]]]]
|
||||
[:client [:name :id :locations]]
|
||||
[:payments [:amount :id [:payment [:id :status :amount :s3_url :check_number
|
||||
[:transaction [:post_date]]]]]]]]
|
||||
@@ -70,7 +70,9 @@
|
||||
: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]}]
|
||||
(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)}
|
||||
(when check-boxes
|
||||
[:td [:input.checkbox {:type "checkbox"
|
||||
@@ -104,7 +106,7 @@
|
||||
[:div
|
||||
(for [e expense-accounts]
|
||||
^{: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]
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
(not can-submit?) (assoc :disabled "disabled"))
|
||||
]
|
||||
: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
|
||||
:timeout 200
|
||||
:enter-class "appear"
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
%))
|
||||
(update :default-account
|
||||
(fn [da]
|
||||
@(re-frame/subscribe [::subs/account (:id da)]))))))
|
||||
@(re-frame/subscribe [::subs/account nil (:id da)]))))))
|
||||
:dispatch [::events/modal-status ::dialog {:visible? true}]}))
|
||||
|
||||
(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]]]]])])]))
|
||||
|
||||
(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])]
|
||||
[:div
|
||||
[horizontal-field
|
||||
@@ -219,7 +219,7 @@
|
||||
[default-with-overrides {:data data :change-event change-event
|
||||
:default-key :default-account
|
||||
:override-key :account-overrides}
|
||||
[typeahead-entity {:matches chooseable-expense-accounts
|
||||
[typeahead-entity {:matches accounts
|
||||
:match->text (fn [x ] (str (:numeric-code x) " - " (:name x)))
|
||||
:type "typeahead-entity"
|
||||
:event change-event
|
||||
|
||||
Reference in New Issue
Block a user