Supports assigning vendors to transactions
This commit is contained in:
@@ -113,10 +113,12 @@
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
(->> (d/pull-many db '[* {:transaction/client [:client/name :db/id :client/code]
|
||||
: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]}]
|
||||
ids)
|
||||
(map #(update % :transaction/date c/from-date))
|
||||
(map #(update % :transaction/post-date c/from-date))
|
||||
(map #(dissoc % :transaction/id))
|
||||
(apply-sort args (some-> (:sort-by args) sort-fn))))
|
||||
|
||||
(defn get-graphql [args]
|
||||
@@ -125,3 +127,14 @@
|
||||
|
||||
[(->> (graphql-results ids-to-retrieve db args))
|
||||
matching-count]))
|
||||
|
||||
(defn get-by-id [id]
|
||||
(->
|
||||
(d/pull (d/db (d/connect uri))
|
||||
'[* {:transaction/client [:client/name :db/id :client/code]
|
||||
:transaction/bank-account [:bank-account/name :bank-account/code :bank-account/yodlee-account-id :db/id]
|
||||
:transaction/vendor [:db/id :vendor/name]}]
|
||||
id)
|
||||
(update :transaction/date c/from-date)
|
||||
(update :transaction/post-date c/from-date)
|
||||
(dissoc :transaction/id)))
|
||||
|
||||
@@ -359,7 +359,10 @@
|
||||
:invoice_number {:type 'String}
|
||||
:expense_accounts {:type '(list :edit_expense_account)}
|
||||
:date {:type 'String}
|
||||
:total {:type 'Float}}}}
|
||||
:total {:type 'Float}}}
|
||||
:edit_transaction
|
||||
{:fields {:id {:type :id}
|
||||
:vendor_id {:type :id}}}}
|
||||
|
||||
:enums {:payment_type {:values [{:enum-value :check}
|
||||
{:enum-value :cash}
|
||||
@@ -411,6 +414,9 @@
|
||||
:edit_invoice {:type :invoice
|
||||
:args {:invoice {:type :edit_invoice}}
|
||||
:resolve :mutation/edit-invoice}
|
||||
:edit_transaction {:type :transaction
|
||||
:args {:transaction {:type :edit_transaction}}
|
||||
:resolve :mutation/edit-transaction}
|
||||
:void_invoice {:type :invoice
|
||||
:args {:invoice_id {:type :id}}
|
||||
:resolve :mutation/void-invoice}
|
||||
@@ -577,6 +583,7 @@
|
||||
:mutation/add-invoice gq-invoices/add-invoice
|
||||
:mutation/add-and-print-invoice gq-invoices/add-and-print-invoice
|
||||
:mutation/edit-invoice gq-invoices/edit-invoice
|
||||
:mutation/edit-transaction gq-transactions/edit-transaction
|
||||
:mutation/edit-client gq-clients/edit-client
|
||||
:mutation/upsert-vendor gq-vendors/upsert-vendor
|
||||
:mutation/void-invoice gq-invoices/void-invoice
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
(ns auto-ap.graphql.transactions
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql]]
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-client]]
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[com.walmartlabs.lacinia :refer [execute]]
|
||||
[com.walmartlabs.lacinia.executor :as executor]
|
||||
[com.walmartlabs.lacinia.resolve :as resolve]
|
||||
@@ -20,3 +23,12 @@
|
||||
|
||||
|
||||
|
||||
|
||||
(defn edit-transaction [context {{:keys [id vendor_id] :as transaction} :transaction} value]
|
||||
(assert-can-see-client (:id context) (:db/id (d-transactions/get-by-id id)))
|
||||
@(d/transact (d/connect uri)
|
||||
[{:db/id id
|
||||
:transaction/vendor vendor_id}])
|
||||
(->graphql (d-transactions/get-by-id id))
|
||||
#_(->graphql {:id id
|
||||
:vendor (d-vendors/get-by-id vendor_id) }))
|
||||
|
||||
@@ -17,6 +17,18 @@
|
||||
[auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table]
|
||||
[auto-ap.subs :as subs]))
|
||||
|
||||
(def transaction-read
|
||||
[:id
|
||||
:amount
|
||||
[:vendor [:name :id]]
|
||||
:date
|
||||
:post_date
|
||||
:status
|
||||
:description_original
|
||||
[:payment [:check_number :s3_url]]
|
||||
[:client [:name :id]]
|
||||
[:bank-account [:name :yodlee-account-id]]])
|
||||
|
||||
|
||||
(re-frame/reg-sub
|
||||
::transaction-page
|
||||
@@ -38,16 +50,7 @@
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:query-obj {:venia/queries [[:transaction_page
|
||||
(assoc params :client-id (:id @(re-frame/subscribe [::subs/client])))
|
||||
[[:transactions [:id
|
||||
:amount
|
||||
[:vendor [:name :id]]
|
||||
:date
|
||||
:post_date
|
||||
:status
|
||||
:description_original
|
||||
[:payment [:check_number :s3_url]]
|
||||
[:client [:name :id]]
|
||||
[:bank-account [:name :yodlee-account-id]]]]
|
||||
[[:transactions transaction-read]
|
||||
:total
|
||||
:start
|
||||
:end]]]}
|
||||
@@ -63,14 +66,56 @@
|
||||
(re-frame/reg-event-db
|
||||
::transaction-editing
|
||||
(fn [db [_ which]]
|
||||
(println (:vendor which))
|
||||
(-> db
|
||||
(forms/start-form ::edit-transaction {}))))
|
||||
(forms/start-form ::edit-transaction {:id (:id which)
|
||||
:vendor-id (:id (:vendor which))
|
||||
:vendor-name (:name (:vendor which))}))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invalidated
|
||||
(fn [cofx [_ params]]
|
||||
{:dispatch [::params-change @(re-frame/subscribe [::params])]}))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::can-submit-edit-transaction
|
||||
:<- [::forms/form ::edit-transaction]
|
||||
(fn [{:keys [data status]} _]
|
||||
(not= :loading status)))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::transaction-edited
|
||||
(fn [{:keys [db]} [_ {:keys [edit-transaction]}]]
|
||||
{:db (-> db
|
||||
(forms/stop-form ::edit-transaction)
|
||||
(update-in [::transaction-page :transactions]
|
||||
(fn [ts]
|
||||
(mapv (fn [t]
|
||||
(if (= (:id t) (:id edit-transaction))
|
||||
(assoc edit-transaction :class "live-added")
|
||||
t))
|
||||
ts))))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::edit-transaction-saving
|
||||
(fn [{:keys [db]} _]
|
||||
(when @(re-frame/subscribe [::can-submit-edit-transaction])
|
||||
(let [{{:keys [id vendor-id]} :data :as data} @(re-frame/subscribe [::forms/form ::edit-transaction])]
|
||||
|
||||
{:db (forms/loading db ::edit-transaction )
|
||||
:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "EditTransaction"}
|
||||
|
||||
:venia/queries [{:query/data [:edit-transaction
|
||||
{:transaction {:id id :vendor-id vendor-id}}
|
||||
|
||||
transaction-read]}]}
|
||||
:on-success [::transaction-edited]
|
||||
:on-error [::forms/save-error ::edit-transaction]}}))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::change-selected-bank-account
|
||||
(fn [db [_ key value]]
|
||||
@@ -164,7 +209,7 @@
|
||||
[:td status]
|
||||
[:td (:name bank-account )]
|
||||
[:td
|
||||
[:a.button {:on-click (dispatch-event [::transaction-editing id])} [:span [:span.icon [:i.fa.fa-pencil]]]]
|
||||
[:a.button {:on-click (dispatch-event [::transaction-editing i])} [:span [:span.icon [:i.fa.fa-pencil]]]]
|
||||
(when check
|
||||
[:a.tag {:href (:s3-url check) :target "_new"} [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " (:check-number check) " (" (gstring/format "$%.2f" amount ) ")")])]
|
||||
]))]]]))))
|
||||
@@ -297,7 +342,7 @@
|
||||
[bind-field
|
||||
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/vendors]))
|
||||
:type "typeahead"
|
||||
:auto-focus (if @(re-frame/subscribe [::subs/client]) true false)
|
||||
:auto-focus true
|
||||
:field [:vendor-id]
|
||||
:text-field [:vendor-name]
|
||||
:event change-event
|
||||
@@ -326,7 +371,7 @@
|
||||
^{:key error} [:div.notification.is-warning.animated.fadeInUp
|
||||
error])
|
||||
|
||||
[:button.button.is-medium.is-primary.is-fullwidth {#_#_:disabled (if @(re-frame/subscribe [::can-submit-edit-invoice])
|
||||
[:button.button.is-medium.is-primary.is-fullwidth {:disabled (if @(re-frame/subscribe [::can-submit-edit-transaction])
|
||||
""
|
||||
"disabled")
|
||||
:class (str @(re-frame/subscribe [::forms/loading-class ::edit-transaction])
|
||||
|
||||
Reference in New Issue
Block a user