Adding transaction approval status to transaction page
This commit is contained in:
@@ -88,6 +88,7 @@
|
|||||||
|
|
||||||
(defn graphql-results [ids db args]
|
(defn graphql-results [ids db args]
|
||||||
(let [results (->> (d/pull-many db '[* {:transaction/client [:client/name :db/id :client/code]
|
(let [results (->> (d/pull-many db '[* {:transaction/client [:client/name :db/id :client/code]
|
||||||
|
:transaction/approval-status [:db/ident :db/id]
|
||||||
:transaction/bank-account [:bank-account/name :bank-account/code :bank-account/yodlee-account-id :db/id]
|
:transaction/bank-account [:bank-account/name :bank-account/code :bank-account/yodlee-account-id :db/id]
|
||||||
:transaction/vendor [:db/id :vendor/name]
|
:transaction/vendor [:db/id :vendor/name]
|
||||||
:transaction/matched-rule [:db/id :transaction-rule/note]
|
:transaction/matched-rule [:db/id :transaction-rule/note]
|
||||||
@@ -116,6 +117,7 @@
|
|||||||
(->
|
(->
|
||||||
(d/pull (d/db (d/connect uri))
|
(d/pull (d/db (d/connect uri))
|
||||||
'[* {:transaction/client [:client/name :db/id :client/code :client/locations]
|
'[* {:transaction/client [:client/name :db/id :client/code :client/locations]
|
||||||
|
:transaction/approval-status [:db/ident :db/id]
|
||||||
:transaction/bank-account [:bank-account/name :bank-account/code :bank-account/yodlee-account-id :db/id]
|
:transaction/bank-account [:bank-account/name :bank-account/code :bank-account/yodlee-account-id :db/id]
|
||||||
:transaction/vendor [:db/id :vendor/name]
|
:transaction/vendor [:db/id :vendor/name]
|
||||||
:transaction/matched-rule [:db/id :transaction-rule/note]
|
:transaction/matched-rule [:db/id :transaction-rule/note]
|
||||||
|
|||||||
@@ -190,6 +190,7 @@
|
|||||||
:bank_account {:type :bank_account}
|
:bank_account {:type :bank_account}
|
||||||
:date {:type 'String}
|
:date {:type 'String}
|
||||||
:post_date {:type 'String}
|
:post_date {:type 'String}
|
||||||
|
:approval_status {:type :transaction_approval_status}
|
||||||
:matched_rule {:type :transaction_rule}}}
|
:matched_rule {:type :transaction_rule}}}
|
||||||
|
|
||||||
:transaction_rule {:fields {:id {:type :id}
|
:transaction_rule {:fields {:id {:type :id}
|
||||||
@@ -529,6 +530,7 @@
|
|||||||
{:fields {:id {:type :id}
|
{:fields {:id {:type :id}
|
||||||
:exclude_from_ledger {:type 'Boolean}
|
:exclude_from_ledger {:type 'Boolean}
|
||||||
:vendor_id {:type :id}
|
:vendor_id {:type :id}
|
||||||
|
:approval_status {:type :transaction_approval_status}
|
||||||
:accounts {:type '(list :edit_expense_account)}}}
|
:accounts {:type '(list :edit_expense_account)}}}
|
||||||
|
|
||||||
:edit_percentage_account
|
:edit_percentage_account
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
[datomic.api :as d]
|
[datomic.api :as d]
|
||||||
[auto-ap.datomic :refer [remove-nils uri merge-query replace-nils-with-retract]]
|
[auto-ap.datomic :refer [remove-nils uri merge-query replace-nils-with-retract]]
|
||||||
[auto-ap.utils :refer [dollars=]]
|
[auto-ap.utils :refer [dollars=]]
|
||||||
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page snake->kebab]]
|
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page snake->kebab ident->enum-f]]
|
||||||
[clj-time.coerce :as c]
|
[clj-time.coerce :as c]
|
||||||
[clojure.set :as set]
|
[clojure.set :as set]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
@@ -13,9 +13,7 @@
|
|||||||
[clj-time.coerce :as coerce])
|
[clj-time.coerce :as coerce])
|
||||||
(:import [java.time.temporal ChronoField]))
|
(: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]
|
(defn get-transaction-rule-page [context args value]
|
||||||
(let [args (assoc args :id (:id context))
|
(let [args (assoc args :id (:id context))
|
||||||
@@ -47,7 +45,7 @@
|
|||||||
:account account_id
|
:account account_id
|
||||||
:location location}))
|
:location location}))
|
||||||
;; TODO ASSERT ADMIN
|
;; TODO ASSERT ADMIN
|
||||||
(defn upsert-transaction-rule [context {{:keys [id description yodlee_merchant_id note client_id bank_account_id amount_lte amount_gte vendor_id accounts transaction_approval_status ]} :transaction_rule :as z} value]
|
(defn upsert-transaction-rule [context {{:keys [id description yodlee_merchant_id note client_id bank_account_id amount_lte amount_gte vendor_id accounts transaction_approval_status dom_gte dom_lte]} :transaction_rule :as z} value]
|
||||||
#_(assert-admin (:id context))
|
#_(assert-admin (:id context))
|
||||||
(let [existing-transaction (tr/get-by-id id)
|
(let [existing-transaction (tr/get-by-id id)
|
||||||
deleted (deleted-accounts existing-transaction accounts)
|
deleted (deleted-accounts existing-transaction accounts)
|
||||||
@@ -67,6 +65,8 @@
|
|||||||
:client client_id
|
:client client_id
|
||||||
:bank-account bank_account_id
|
:bank-account bank_account_id
|
||||||
:yodlee-merchant yodlee_merchant_id
|
:yodlee-merchant yodlee_merchant_id
|
||||||
|
:dom-lte dom_lte
|
||||||
|
:dom-gte dom_gte
|
||||||
:amount-lte amount_lte
|
:amount-lte amount_lte
|
||||||
:amount-gte amount_gte
|
:amount-gte amount_gte
|
||||||
:vendor vendor_id
|
:vendor vendor_id
|
||||||
@@ -78,7 +78,6 @@
|
|||||||
:accounts (map transaction-rule-account->entity accounts)}
|
:accounts (map transaction-rule-account->entity accounts)}
|
||||||
existing-transaction)
|
existing-transaction)
|
||||||
|
|
||||||
_ (println transaction)
|
|
||||||
|
|
||||||
transaction (into transaction
|
transaction (into transaction
|
||||||
(map (fn [d]
|
(map (fn [d]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
(ns auto-ap.graphql.transactions
|
(ns auto-ap.graphql.transactions
|
||||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-client assert-admin]]
|
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-client assert-admin ident->enum-f snake->kebab]]
|
||||||
[auto-ap.datomic.transactions :as d-transactions]
|
[auto-ap.datomic.transactions :as d-transactions]
|
||||||
[auto-ap.datomic.vendors :as d-vendors]
|
[auto-ap.datomic.vendors :as d-vendors]
|
||||||
[auto-ap.datomic.checks :as d-checks]
|
[auto-ap.datomic.checks :as d-checks]
|
||||||
@@ -17,11 +17,17 @@
|
|||||||
[auto-ap.datomic.transaction-rules :as tr]
|
[auto-ap.datomic.transaction-rules :as tr]
|
||||||
[auto-ap.rule-matching :as rm]
|
[auto-ap.rule-matching :as rm]
|
||||||
[clj-time.coerce :as coerce]))
|
[clj-time.coerce :as coerce]))
|
||||||
|
(defn prn-each [xs]
|
||||||
|
(doseq [x xs]
|
||||||
|
(println x))
|
||||||
|
xs)
|
||||||
|
|
||||||
|
(def approval-status->graphql (ident->enum-f :transaction/approval-status))
|
||||||
|
|
||||||
(defn get-transaction-page [context args value]
|
(defn get-transaction-page [context args value]
|
||||||
(let [args (assoc args :id (:id context))
|
(let [args (assoc args :id (:id context))
|
||||||
[transactions transactions-count] (d-transactions/get-graphql (<-graphql args))
|
[transactions transactions-count] (d-transactions/get-graphql (<-graphql args))
|
||||||
transactions (map ->graphql transactions)]
|
transactions (map ->graphql (map approval-status->graphql transactions))]
|
||||||
[{:transactions transactions
|
[{:transactions transactions
|
||||||
:total transactions-count
|
:total transactions-count
|
||||||
:count (count transactions)
|
:count (count transactions)
|
||||||
@@ -45,7 +51,7 @@
|
|||||||
set)]
|
set)]
|
||||||
(set/difference existing-ids specified-ids)))
|
(set/difference existing-ids specified-ids)))
|
||||||
|
|
||||||
(defn edit-transaction [context {{:keys [id exclude_from_ledger accounts vendor_id] :as transaction} :transaction} value]
|
(defn edit-transaction [context {{:keys [id exclude_from_ledger accounts vendor_id approval_status] :as transaction} :transaction} value]
|
||||||
(let [existing-transaction (d-transactions/get-by-id id)
|
(let [existing-transaction (d-transactions/get-by-id id)
|
||||||
_ (assert-can-see-client (:id context) (:transaction/client existing-transaction) )
|
_ (assert-can-see-client (:id context) (:transaction/client existing-transaction) )
|
||||||
deleted (deleted-accounts existing-transaction accounts)
|
deleted (deleted-accounts existing-transaction accounts)
|
||||||
@@ -69,13 +75,19 @@
|
|||||||
@(d/transact (d/connect uri)
|
@(d/transact (d/connect uri)
|
||||||
(concat [(remove-nils {:db/id id
|
(concat [(remove-nils {:db/id id
|
||||||
:transaction/vendor vendor_id
|
:transaction/vendor vendor_id
|
||||||
|
:transaction/approval-status (some->> approval_status
|
||||||
|
name
|
||||||
|
snake->kebab
|
||||||
|
(keyword "transaction-approval-status"))
|
||||||
:transaction/exclude-from-ledger exclude_from_ledger
|
:transaction/exclude-from-ledger exclude_from_ledger
|
||||||
:transaction/accounts (map transaction-account->entity accounts)
|
:transaction/accounts (map transaction-account->entity accounts)
|
||||||
})]
|
})]
|
||||||
(map (fn [d]
|
(map (fn [d]
|
||||||
[:db/retract id :transaction/accounts d])
|
[:db/retract id :transaction/accounts d])
|
||||||
deleted)))
|
deleted)))
|
||||||
(->graphql (d-transactions/get-by-id id))))
|
(-> (d-transactions/get-by-id id)
|
||||||
|
approval-status->graphql
|
||||||
|
->graphql)))
|
||||||
|
|
||||||
(defn match-transaction [context {:keys [transaction_id payment_id]} value]
|
(defn match-transaction [context {:keys [transaction_id payment_id]} value]
|
||||||
(let [transaction (d-transactions/get-by-id transaction_id)
|
(let [transaction (d-transactions/get-by-id transaction_id)
|
||||||
@@ -103,7 +115,9 @@
|
|||||||
:transaction-account/amount (Math/abs (:transaction/amount transaction))}]}]
|
:transaction-account/amount (Math/abs (:transaction/amount transaction))}]}]
|
||||||
(map (fn [x] [:db/retractEntity (:db/id x)] )
|
(map (fn [x] [:db/retractEntity (:db/id x)] )
|
||||||
(:transaction/accounts transaction)))))
|
(:transaction/accounts transaction)))))
|
||||||
(->graphql (d-transactions/get-by-id transaction_id)))
|
(-> (d-transactions/get-by-id transaction_id)
|
||||||
|
approval-status->graphql
|
||||||
|
->graphql))
|
||||||
|
|
||||||
(defn match-transaction-rule [context {:keys [transaction_id transaction_rule_id]} value]
|
(defn match-transaction-rule [context {:keys [transaction_id transaction_rule_id]} value]
|
||||||
(let [_ (assert-admin (:id context))
|
(let [_ (assert-admin (:id context))
|
||||||
@@ -122,4 +136,6 @@
|
|||||||
|
|
||||||
;; TODO use bank account locations as well
|
;; TODO use bank account locations as well
|
||||||
(-> transaction :transaction/client :client/locations))]))
|
(-> transaction :transaction/client :client/locations))]))
|
||||||
(->graphql (d-transactions/get-by-id transaction_id)))
|
(-> (d-transactions/get-by-id transaction_id)
|
||||||
|
approval-status->graphql
|
||||||
|
->graphql))
|
||||||
|
|||||||
@@ -77,3 +77,7 @@
|
|||||||
:count (count results)
|
:count (count results)
|
||||||
:start (:start args 0)
|
:start (:start args 0)
|
||||||
:end (+ (:start args 0) (count results))})
|
:end (+ (:start args 0) (count results))})
|
||||||
|
|
||||||
|
(defn ident->enum-f [k]
|
||||||
|
#(update % k
|
||||||
|
(fn [value] (some-> value :db/ident name keyword))))
|
||||||
|
|||||||
12
src/cljs/auto_ap/views/components/button_radio.cljs
Normal file
12
src/cljs/auto_ap/views/components/button_radio.cljs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
(ns auto-ap.views.components.button-radio)
|
||||||
|
|
||||||
|
(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]])]])
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
[auto-ap.forms :as forms]
|
[auto-ap.forms :as forms]
|
||||||
[auto-ap.subs :as subs]
|
[auto-ap.subs :as subs]
|
||||||
[auto-ap.views.components.modal :refer [modal]]
|
[auto-ap.views.components.modal :refer [modal]]
|
||||||
|
[auto-ap.views.components.button-radio :refer [button-radio]]
|
||||||
[auto-ap.utils :refer [dollars=]]
|
[auto-ap.utils :refer [dollars=]]
|
||||||
[auto-ap.views.components.dropdown :refer [drop-down]]
|
[auto-ap.views.components.dropdown :refer [drop-down]]
|
||||||
[auto-ap.views.components.expense-accounts-field :as expense-accounts-field :refer [expense-accounts-field recalculate-amounts]]
|
[auto-ap.views.components.expense-accounts-field :as expense-accounts-field :refer [expense-accounts-field recalculate-amounts]]
|
||||||
@@ -178,16 +179,7 @@
|
|||||||
:submit-event [::saving ]
|
:submit-event [::saving ]
|
||||||
:id ::form}))
|
: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}]
|
(defn form [{:keys [can-change-amount?] :as params}]
|
||||||
[layouts/side-bar {:on-close (dispatch-event [::forms/form-closing ::form ])}
|
[layouts/side-bar {:on-close (dispatch-event [::forms/form-closing ::form ])}
|
||||||
@@ -296,8 +288,7 @@
|
|||||||
:field [:transaction-approval-status]
|
:field [:transaction-approval-status]
|
||||||
:options [[:unapproved "Unapproved"]
|
:options [[:unapproved "Unapproved"]
|
||||||
[:requires-feedback "Client Review"]
|
[:requires-feedback "Client Review"]
|
||||||
[:approved "Approved"]
|
[:approved "Approved"]]}]]
|
||||||
]}]]
|
|
||||||
|
|
||||||
|
|
||||||
[:div.is-divider]
|
[:div.is-divider]
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
:amount
|
:amount
|
||||||
:location
|
:location
|
||||||
:exclude-from-ledger
|
:exclude-from-ledger
|
||||||
|
:approval-status
|
||||||
[:matched-rule [:note :id]]
|
[:matched-rule [:note :id]]
|
||||||
[:vendor [:name :id]]
|
[:vendor [:name :id]]
|
||||||
[:accounts [:id :amount :location [:account [:name :id :location :numeric-code]]]]
|
[:accounts [:id :amount :location [:account [:name :id :location :numeric-code]]]]
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
[auto-ap.subs :as subs]
|
[auto-ap.subs :as subs]
|
||||||
[auto-ap.views.components.layouts :as layouts]
|
[auto-ap.views.components.layouts :as layouts]
|
||||||
[auto-ap.views.components.typeahead :refer [typeahead typeahead-entity]]
|
[auto-ap.views.components.typeahead :refer [typeahead typeahead-entity]]
|
||||||
|
[auto-ap.views.components.button-radio :refer [button-radio]]
|
||||||
[auto-ap.views.components.expense-accounts-field :refer [expense-accounts-field] :as expense-accounts-field]
|
[auto-ap.views.components.expense-accounts-field :refer [expense-accounts-field] :as expense-accounts-field]
|
||||||
[auto-ap.views.pages.transactions.common :refer [transaction-read]]
|
[auto-ap.views.pages.transactions.common :refer [transaction-read]]
|
||||||
[auto-ap.views.utils :refer [bind-field dispatch-event with-user]]
|
[auto-ap.views.utils :refer [bind-field dispatch-event with-user]]
|
||||||
@@ -14,7 +15,7 @@
|
|||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::submit-query
|
::submit-query
|
||||||
:<- [::forms/form ::form]
|
:<- [::forms/form ::form]
|
||||||
(fn [{{:keys [id vendor accounts exclude-from-ledger]} :data}]
|
(fn [{{:keys [id vendor accounts exclude-from-ledger approval-status]} :data}]
|
||||||
{:venia/operation {:operation/type :mutation
|
{:venia/operation {:operation/type :mutation
|
||||||
:operation/name "EditTransaction"}
|
:operation/name "EditTransaction"}
|
||||||
:venia/queries [{:query/data
|
:venia/queries [{:query/data
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
{:transaction {:id id
|
{:transaction {:id id
|
||||||
:vendor-id (:id vendor)
|
:vendor-id (:id vendor)
|
||||||
:exclude-from-ledger exclude-from-ledger
|
:exclude-from-ledger exclude-from-ledger
|
||||||
|
:approval-status approval-status
|
||||||
:accounts (map
|
:accounts (map
|
||||||
(fn [{:keys [id account amount location]}]
|
(fn [{:keys [id account amount location]}]
|
||||||
{:id (when-not (str/starts-with? id "new-")
|
{:id (when-not (str/starts-with? id "new-")
|
||||||
@@ -49,7 +51,7 @@
|
|||||||
(-> which
|
(-> which
|
||||||
(select-keys [:vendor :amount :payment :client :description-original
|
(select-keys [:vendor :amount :payment :client :description-original
|
||||||
:yodlee-merchant :id :potential-payment-matches
|
:yodlee-merchant :id :potential-payment-matches
|
||||||
:exclude-from-ledger :location :accounts :transaction-approval-status
|
:exclude-from-ledger :location :accounts :approval-status
|
||||||
:matched-rule])
|
:matched-rule])
|
||||||
(assoc :potential-payment-matches (if (:matched-rule which)
|
(assoc :potential-payment-matches (if (:matched-rule which)
|
||||||
nil
|
nil
|
||||||
@@ -249,6 +251,22 @@
|
|||||||
:field [:exclude-from-ledger]}]]
|
:field [:exclude-from-ledger]}]]
|
||||||
" Exclude from ledger"]]
|
" Exclude from ledger"]]
|
||||||
|
|
||||||
|
[field "Include in ledger"
|
||||||
|
[button-radio
|
||||||
|
{:type "button-radio"
|
||||||
|
:field [:exclude-from-ledger]
|
||||||
|
:options [[true "Exclude from Ledger"]
|
||||||
|
[false "Include in Ledger"]
|
||||||
|
]}]]
|
||||||
|
|
||||||
|
[field "Approval Status"
|
||||||
|
[button-radio
|
||||||
|
{:type "button-radio"
|
||||||
|
:field [:approval-status]
|
||||||
|
:options [[:unapproved "Unapproved"]
|
||||||
|
[:requires-feedback "Client Review"]
|
||||||
|
[:approved "Approved"]]}]]
|
||||||
|
|
||||||
[:hr]
|
[:hr]
|
||||||
|
|
||||||
[error-notification]
|
[error-notification]
|
||||||
|
|||||||
Reference in New Issue
Block a user