bank accounts can now have locations.

This commit is contained in:
Bryce Covert
2019-06-04 07:08:10 -07:00
parent cf2319b681
commit 7ac17c9cbc
13 changed files with 90 additions and 18 deletions

View File

@@ -50,3 +50,18 @@ server {
access_log /var/log/nginx/access.log vhost;
return 503;
}
# local.app.integreatconsult.com
upstream local.app.integreatconsult.com {
## Can be connected with "integreat_default" network
# integreat_app_1
server 172.30.0.3:3000;
}
server {
server_name local.app.integreatconsult.com;
listen 80 ;
access_log /var/log/nginx/access.log vhost;
location / {
proxy_pass http://local.app.integreatconsult.com;
include /etc/nginx/vhost.d/default_location;
}
}

View File

@@ -132,6 +132,7 @@
:auto-ap/convert-transactions {:txes-fn `add-general-ledger/convert-transactions :requires [:auto-ap/add-external-id-to-ledger]}
:auto-ap/add-transaction-rules {:txes add-general-ledger/add-transaction-rules :requires [:auto-ap/convert-transactions]}
:auto-ap/add-bank-account-locations {:txes add-general-ledger/add-bank-account-locations :requires [:auto-ap/add-transaction-rules]}

View File

@@ -400,6 +400,12 @@
{:db/ident :transaction-approval-status/excluded}
]])
(def add-bank-account-locations
[[{:db/ident :bank-account/locations
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
:db/doc "Which bank accounts this bank account is valid for"}]])
(def add-credit-bank-account
[[{:db/ident :bank-account-type/credit}]])

View File

@@ -94,7 +94,7 @@
(defn graphql-results [ids db args]
(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 :bank-account/locations]
:transaction/vendor [:db/id :vendor/name]
:transaction/matched-rule [:db/id :transaction-rule/note]
:transaction/accounts [:transaction-account/amount
@@ -123,7 +123,7 @@
(d/pull (d/db (d/connect uri))
'[* {: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 :bank-account/locations]
:transaction/vendor [:db/id :vendor/name]
:transaction/matched-rule [:db/id :transaction-rule/note]
:transaction/accounts [:transaction-account/amount

View File

@@ -84,7 +84,8 @@
:name {:type 'String}
:bank_code {:type 'String}
:bank_name {:type 'String}
:yodlee_account_id {:type 'Int}}}
:yodlee_account_id {:type 'Int}
:locations {:type '(list String)}}}
:balance_sheet_account
{:fields {:id {:type 'String}
:amount {:type 'String}
@@ -470,6 +471,7 @@
:bank_code {:type 'String}
:routing {:type 'String}
:bank_name {:type 'String}
:locations {:type '(list String)}
:yodlee_account_id {:type 'Int}}}
:edit_user
{:fields {:id {:type :id}

View File

@@ -51,6 +51,7 @@
:bank-account/number (:number %)
:bank-account/check-number (:check_number %)
:bank-account/sort-order (:sort_order %)
:bank-account/locations (:locations %)
:bank-account/yodlee-account-id (:yodlee_account_id %)
:bank-account/type (keyword "bank-account-type" (name (:type %)))

View File

@@ -138,8 +138,8 @@
:transaction/amount (:transaction/amount transaction)}
transaction-rule
;; TODO use bank account locations as well
(-> transaction :transaction/client :client/locations)))]
(or (-> transaction :transaction/bank-account :bank-account/locations)
(-> transaction :transaction/client :client/locations))))]
(map (fn [x] [:db/retractEntity (:db/id x)] )
(:transaction/accounts transaction)))))
(-> (d-transactions/get-by-id transaction_id)

View File

@@ -11,7 +11,8 @@
[auto-ap.datomic.clients :as d-clients]
[auto-ap.time :as time]
[auto-ap.datomic.transaction-rules :as tr]
[auto-ap.rule-matching :as rm]))
[auto-ap.rule-matching :as rm]
[clojure.string :as str]))
@@ -77,7 +78,7 @@
bank-account-id (:db/id bank-account)
client (:client/_bank-accounts bank-account)
client-id (:db/id client)
valid-locations (:client/locations client)
valid-locations (or (:bank-account/locations bank-account) (:client/locations client))
check (transaction->payment transaction check-number client-id bank-account-id amount id)]
:when (and client-id
(not (existing (sha-256 (str id)))))]
@@ -87,7 +88,8 @@
:id (sha-256 (str id))
:account-id account-id
:date (coerce/to-date (time/parse date "YYYY-MM-dd"))
:yodlee-merchant (when (and merchant-id merchant-name)
:yodlee-merchant (when (and merchant-id merchant-name (not (str/blank? merchant-id)))
{:yodlee-merchant/yodlee-id merchant-id
:yodlee-merchant/name merchant-name})
:amount (double amount)

View File

@@ -42,7 +42,7 @@
:graphql {:token token
:query-obj {:venia/queries [[:client
[:id :name :code :email :locations [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id] ]
[:id :name :code :email :locations [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id :locations] ]
[:address [:street1 :street2 :city :state :zip]]]]
[:vendor
[:id :name :hidden [:default-account [:name :id :location]] [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]
@@ -65,7 +65,7 @@
(fn [{:keys [db]} [_ token user]]
{:graphql {:token token
:query-obj {:venia/queries [[:client
[:id :name :code [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id] ]]]
[:id :name :code [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id :locations] ]]]
[:vendor
[:id :name :hidden [:default-account [:name :id :location]] [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]
[:accounts [:numeric-code :name :location :type :account_set :id]]]}

View File

@@ -74,6 +74,16 @@
(fn [db [_ client]]
(:locations (get (:clients db) (or client (:client db))))))
(re-frame/reg-sub
::locations-for-client-or-bank-account
(fn [db [_ client-id bank-account-id]]
(let [client (get (:clients db) (or client (:client db)))
client-locations (:locations client)
bank-account-locations (-> (by :id (:bank-accounts client))
(get bank-account-id)
:locations)]
(or bank-account-locations client-locations))))
(re-frame/reg-sub
::clients-by-id
(fn [db]

View File

@@ -47,7 +47,7 @@
:city (:city (:address new-client-data))
:state (:state (:address new-client-data))
:zip (:zip (:address new-client-data))}
:bank-accounts (map (fn [{:keys [number name check-number type id code bank-name routing bank-code new? sort-order visible yodlee-account-id]}]
:bank-accounts (map (fn [{:keys [number name check-number type id code bank-name routing bank-code new? sort-order visible yodlee-account-id locations]}]
{:number number
:name name
:check-number check-number
@@ -55,6 +55,7 @@
:id id
:sort-order sort-order
:visible visible
:locations (vec locations)
:yodlee-account-id (when yodlee-account-id
(js/parseInt yodlee-account-id))
:code (if new?
@@ -85,7 +86,7 @@
:operation/name "EditClient"}
:venia/queries [{:query/data [:edit-client
{:edit-client new-client-req}
[:id :name :code :email :locations [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing :type :visible :yodlee-account-id :sort-order]]]]}]}
[:id :name :code :email :locations [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing :type :visible :yodlee-account-id :sort-order :locations]]]]}]}
:on-success [::save-complete]
:on-error [::forms/save-error ::new-client]}}
{:db new-client-form}))))
@@ -107,6 +108,15 @@
(update :locations conj (:location client))
(dissoc :location))))
(re-frame/reg-event-db
::add-location-to-bank-account
[(forms/in-form ::new-client) (re-frame/path [:data])]
(fn [client [_ which-account]]
(println client which-account)
(-> client
(update-in [:bank-accounts which-account :locations] #(conj (or % #{}) (get-in client [:bank-accounts which-account :location-select])))
(update-in [:bank-accounts which-account] dissoc :location-select))))
(re-frame/reg-event-db
::add-new-bank-account
[(forms/in-form ::new-client) (re-frame/path [:data])]
@@ -306,7 +316,9 @@
:type "text"
:field [:bank-accounts sort-order :yodlee-account-id]
:event change-event
:subscription new-client}]]]]])
:subscription new-client}]]]]
])
(when (#{:credit ":credit"} type )
[:div
@@ -340,7 +352,30 @@
:type "text"
:field [:bank-accounts sort-order :yodlee-account-id]
:event change-event
:subscription new-client}]]]]])])
:subscription new-client}]]]]])
[:div.field
[:label.label "Locations"]
[:div.control
[:p.help "If this account is location-specific, add the valid locations"]
[:div.field.has-addons
[:p.control
[:div.select
[bind-field
[:select {:type "select"
:style {:width "7em"}
:field [:bank-accounts sort-order :location-select]
:allow-nil? true
:spec (set (get-in new-client [:locations]))
:event change-event
:subscription new-client}
(map (fn [l] ^{:key l} [:option {:value l} l]) (get-in new-client [:locations]))]]]]
[:p.control {:on-click (dispatch-event [::add-location-to-bank-account sort-order]) } [:a.button "Add"]]]]
(if-let [locations (seq (get-in new-client [:bank-accounts sort-order :locations]))]
[:ul
(for [location locations]
^{:key location} [:li location ])]
[:i "This account applies to all locations"])]])
(when active?
[:footer.card-footer

View File

@@ -289,7 +289,7 @@
[expense-accounts-field {:type "expense-accounts"
:descriptor "account asssignment"
:percentage-only? true
:locations (into ["Shared"] @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))]))
:locations (into ["Shared"] @(re-frame/subscribe [::subs/locations-for-client-or-bank-account (:id (:client data)) (:id (:bank-account data))]))
:max 100
:field [:accounts]}]]

View File

@@ -189,7 +189,7 @@
(testing "based on date "
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 14 :dom-lte 16})))
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 14})))
(is (= [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-lte 15})))
(is (= (set [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}]) (set (rule-test {:dom-lte 15}))))
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 15})))
(is (= [{:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:dom-gte 15 :dom-lte 15}))))
@@ -198,8 +198,8 @@
(testing "based on amount"
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:amount-gte 1.0 :amount-lte 1.0})))
(is (= [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:amount-gte 1.0 })) )
(is (= [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}] (rule-test {:amount-lte 2.0 })) ))
(is (= (set [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}]) (set (rule-test {:amount-gte 1.0 }))) )
(is (= (set [{:id "2019-01-05 matching-desc 1"} {:id "2019-01-15 nonmatching-desc 2"}]) (set (rule-test {:amount-lte 2.0 }))) ))
(testing "based on client"
(is (= [{:id "2019-01-05 matching-desc 1"}] (rule-test {:client-id client-1})))