Supports editing the approval status.
This commit is contained in:
@@ -74,14 +74,7 @@
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "Location of the entry"}
|
||||
|
||||
{:db/ident :transaction/approval-status
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "Status of a transaction"}
|
||||
|
||||
{:db/ident :transaction-approval-status/approved}
|
||||
{:db/ident :transaction-approval-status/unapproved}
|
||||
{:db/ident :transaction-approval-status/requires-feedback}]
|
||||
]
|
||||
]
|
||||
)
|
||||
(def add-transaction-account
|
||||
@@ -385,6 +378,20 @@
|
||||
:db/cardinality :db.cardinality/many
|
||||
:db/isComponent true
|
||||
:db/doc "The outcome split"}
|
||||
|
||||
{:db/ident :transaction/approval-status
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "Status of a transaction"}
|
||||
|
||||
{:db/ident :transaction-rule/transaction-approval-status
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "Status of a transaction"}
|
||||
|
||||
{:db/ident :transaction-approval-status/approved}
|
||||
{:db/ident :transaction-approval-status/unapproved}
|
||||
{:db/ident :transaction-approval-status/requires-feedback}
|
||||
]])
|
||||
|
||||
(def add-credit-bank-account
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
{:transaction-rule/client [:client/name :db/id :client/code]}
|
||||
{:transaction-rule/bank-account [*]}
|
||||
{:transaction-rule/yodlee-merchant [*]}
|
||||
{:transaction-rule/transaction-status [:db/id :db/ident]}
|
||||
{:transaction-rule/transaction-approval-status [:db/id :db/ident]}
|
||||
{:transaction-rule/vendor [:vendor/name :db/id :vendor/default-account]}
|
||||
{:transaction-rule/accounts [:transaction-rule-account/percentage
|
||||
:transaction-rule-account/location
|
||||
@@ -70,7 +70,6 @@
|
||||
(defn get-graphql [args]
|
||||
(let [db (d/db (d/connect uri))
|
||||
{ids-to-retrieve :ids matching-count :count} (raw-graphql-ids db args)]
|
||||
|
||||
[(->> (graphql-results ids-to-retrieve db args))
|
||||
matching-count]))
|
||||
|
||||
|
||||
@@ -9,10 +9,16 @@
|
||||
[clojure.set :as set])
|
||||
(:import [java.time.temporal ChronoField]))
|
||||
|
||||
(defn ident->enum-f [k]
|
||||
#(update % k
|
||||
(fn [value] (some-> value :db/ident name keyword))))
|
||||
|
||||
(defn get-transaction-rule-page [context args value]
|
||||
(let [args (assoc args :id (:id context))
|
||||
[journal-entries journal-entries-count] (tr/get-graphql (<-graphql args))]
|
||||
(result->page journal-entries journal-entries-count :transaction_rules args)))
|
||||
(result->page (->> journal-entries
|
||||
(map (ident->enum-f :transaction-rule/transaction-approval-status)))
|
||||
journal-entries-count :transaction_rules args)))
|
||||
|
||||
(defn deleted-accounts [transaction accounts]
|
||||
(let [current-accounts (:transaction-rule/accounts transaction)
|
||||
@@ -30,7 +36,7 @@
|
||||
:account account_id
|
||||
:location location}))
|
||||
;; TODO ASSERT ADMIN
|
||||
(defn upsert-transaction-rule [context {{:keys [id description note client_id bank_account_id amount_lte amount_gte vendor_id accounts ]} :transaction_rule :as z} value]
|
||||
(defn upsert-transaction-rule [context {{:keys [id description note client_id bank_account_id amount_lte amount_gte vendor_id accounts transaction_approval_status ]} :transaction_rule :as z} value]
|
||||
#_(assert-admin (:id context))
|
||||
(let [existing-transaction (tr/get-by-id id)
|
||||
deleted (deleted-accounts existing-transaction accounts)
|
||||
@@ -50,6 +56,7 @@
|
||||
:amount-lte amount_lte
|
||||
:amount-gte amount_gte
|
||||
:vendor vendor_id
|
||||
:transaction-approval-status (keyword "transaction-approval-status" (name (<-graphql transaction_approval_status)))
|
||||
:accounts (map transaction-rule-account->entity accounts)})]
|
||||
|
||||
transaction (into transaction
|
||||
@@ -59,6 +66,7 @@
|
||||
transaction-result @(d/transact (d/connect uri) transaction)]
|
||||
(-> (tr/get-by-id (or (-> transaction-result :tempids (get "transaction-rule"))
|
||||
id))
|
||||
((ident->enum-f :transaction-rule/transaction-approval-status))
|
||||
(->graphql))))
|
||||
|
||||
(defn tr [z x]
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
:amount-lte
|
||||
:dom-gte
|
||||
:dom-lte
|
||||
:transaction-approval-status
|
||||
[:vendor [:name :id]]
|
||||
[:client [:name :id]]
|
||||
[:bank-account [:name :id]]
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
{:transaction-rule (-> data
|
||||
(select-keys [:id
|
||||
:description
|
||||
:transaction-approval-status
|
||||
:amount-lte
|
||||
:amount-gte
|
||||
:dom-lte
|
||||
@@ -115,7 +116,8 @@
|
||||
:dom-lte
|
||||
:dom-gte
|
||||
:vendor
|
||||
:accounts])
|
||||
:accounts
|
||||
:transaction-approval-status])
|
||||
(update :accounts (fn [xs]
|
||||
(println xs)
|
||||
(mapv #(assoc % :amount-percentage (* (:percentage %) 100.0))
|
||||
@@ -173,6 +175,17 @@
|
||||
:submit-event [::saving ]
|
||||
:id ::form}))
|
||||
|
||||
(defn button-radio [{:keys [options on-change value]}]
|
||||
[:div.control
|
||||
[:div.field.has-addons
|
||||
(for [[k v] options]
|
||||
^{:key k}
|
||||
[:p.control
|
||||
[:a.button {:class (if (= value k)
|
||||
"is-primary"
|
||||
"")
|
||||
:on-click (fn [] (on-change k))} v]])]])
|
||||
|
||||
(defn form [{:keys [can-change-amount?] :as params}]
|
||||
[layouts/side-bar {:on-close (dispatch-event [::forms/form-closing ::form ])}
|
||||
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::form])
|
||||
@@ -268,7 +281,17 @@
|
||||
:max 100
|
||||
:field [:accounts]}]]
|
||||
|
||||
[field "Approval Status"
|
||||
[button-radio
|
||||
{:type "button-radio"
|
||||
:field [:transaction-approval-status]
|
||||
:options [[:unapproved "Unapproved"]
|
||||
[:requires-feedback "Client Review"]
|
||||
[:approved "Approved"]
|
||||
]}]]
|
||||
|
||||
|
||||
[:div.is-divider]
|
||||
[error-notification]
|
||||
|
||||
[:div.columns
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
(-> which
|
||||
(select-keys [:vendor :amount :payment :client :description-original
|
||||
:yodlee-merchant :id :potential-payment-matches
|
||||
:exclude-from-ledger :location :accounts])
|
||||
:exclude-from-ledger :location :accounts :transaction-approval-status])
|
||||
(assoc :potential-payment-matches potential-payment-matches)
|
||||
(update :accounts expense-accounts-field/from-graphql (:amount which) locations))))))
|
||||
|
||||
@@ -183,6 +183,8 @@
|
||||
{:type "checkbox"
|
||||
:field [:exclude-from-ledger]}]]
|
||||
" Exclude from ledger"]]
|
||||
|
||||
[:hr]
|
||||
|
||||
[error-notification]
|
||||
[submit-button "Save"]])])])
|
||||
|
||||
@@ -191,6 +191,20 @@
|
||||
keys (dissoc keys :field :subscription :spec)]
|
||||
(into [dom keys] (with-keys rest))))
|
||||
|
||||
|
||||
(defmethod do-bind "button-radio" [dom {:keys [field event subscription class spec] :as keys} & rest]
|
||||
(let [field (if (keyword? field) [field] field)
|
||||
event (if (keyword? event) [event] event)
|
||||
keys (assoc keys
|
||||
:value (get-in subscription field)
|
||||
:on-change (fn [v]
|
||||
(re-frame/dispatch (-> event (conj field) (conj v))))
|
||||
:class (str class
|
||||
(when (and spec (not (s/valid? spec (get-in subscription field))))
|
||||
" is-danger")))
|
||||
keys (dissoc keys :field :event :subscription :spec)]
|
||||
(into [dom keys] (with-keys rest))))
|
||||
|
||||
(defmethod do-bind "number" [dom {:keys [field precision event subscription class spec] :as keys :or {precision 2}} & rest]
|
||||
(let [field (if (keyword? field) [field] field)
|
||||
event (if (keyword? event) [event] event)
|
||||
|
||||
Reference in New Issue
Block a user