almost allow completely adding new clients and sorting and filtering.

This commit is contained in:
BC
2019-02-18 09:33:32 -08:00
parent a5d0579164
commit b8dffa45d6
9 changed files with 105 additions and 34 deletions

View File

@@ -24,7 +24,7 @@
(let [result (reduce-kv (let [result (reduce-kv
(fn [m k v] (fn [m k v]
(if v (if (not (nil? v))
(assoc m k v) (assoc m k v)
m m
)) ))

View File

@@ -11,9 +11,12 @@
(map (fn [c] (map (fn [c]
(update c :client/bank-accounts (update c :client/bank-accounts
(fn [bas] (fn [bas]
(map (fn [ba] (map (fn [i ba]
(update ba :bank-account/type :db/ident )) (-> ba
bas))))))) (update :bank-account/type :db/ident )
(update :bank-account/sort-order (fn [so] (or so i)))))
(range) bas)))))
))
(defn get-by-id [id] (defn get-by-id [id]
(->> (->>
(d/query (-> {:query {:find ['(pull ?e [*])] (d/query (-> {:query {:find ['(pull ?e [*])]

View File

@@ -63,6 +63,9 @@
:auto-ap/add-import-status-existing-invoices {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-import-status-existing-invoices :requires [:auto-ap/add-import-status]} :auto-ap/add-import-status-existing-invoices {:txes-fn 'auto-ap.datomic.migrate.invoice-converter/add-import-status-existing-invoices :requires [:auto-ap/add-import-status]}
:auto-ap/fix-check-numbers {:txes-fn 'auto-ap.datomic.migrate.check-numbers/fix-check-numbers :requires [:auto-ap/add-import-status-existing-invoices]} :auto-ap/fix-check-numbers {:txes-fn 'auto-ap.datomic.migrate.check-numbers/fix-check-numbers :requires [:auto-ap/add-import-status-existing-invoices]}
:auto-ap/add-new-vendors {:txes-fn 'auto-ap.datomic.migrate.add-new-vendors/add-new-vendors :requires [:auto-ap/fix-check-numbers]} :auto-ap/add-new-vendors {:txes-fn 'auto-ap.datomic.migrate.add-new-vendors/add-new-vendors :requires [:auto-ap/fix-check-numbers]}
:auto-ap/add-account-visibility-fields {:txes-fn 'auto-ap.datomic.migrate.account-sorting/add-account-visibility-fields :requires [:auto-ap/add-new-vendors]}
:auto-ap/make-every-account-visible {:txes-fn 'auto-ap.datomic.migrate.account-sorting/make-every-account-visible :requires [:auto-ap/add-account-visibility-fields]}
}] }]
(println "Conforming database...") (println "Conforming database...")
(println (c/ensure-conforms conn norms-map)) (println (c/ensure-conforms conn norms-map))

View File

@@ -0,0 +1,27 @@
(ns auto-ap.datomic.migrate.account-sorting
(:require [datomic.api :as d]))
(defn add-account-visibility-fields [conn]
[[
{:db/ident :bank-account/visible
:db/valueType :db.type/boolean
:db/cardinality :db.cardinality/one
:db/doc "Whether this bank account is visible"}
{:db/ident :bank-account/sort-order
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one
:db/doc "The sort order of the bank account"}]])
(defn make-every-account-visible [conn]
(let [all-account-ids (d/query
{:query {:find ['?e]
:in ['$]
:where ['[?e :bank-account/code]]}
:args [(d/db conn)]}
)]
[(map
(fn [[account-id]]
{:db/id account-id :bank-account/visible true}
)
all-account-ids)]))

View File

@@ -56,6 +56,8 @@
{:fields {:id {:type :id } {:fields {:id {:type :id }
:type {:type :ident} :type {:type :ident}
:number {:type 'String} :number {:type 'String}
:sort_order {:type 'Int}
:visible {:type 'Boolean}
:routing {:type 'String} :routing {:type 'String}
:code {:type 'String} :code {:type 'String}
:check_number {:type 'Int} :check_number {:type 'Int}
@@ -295,6 +297,8 @@
:type {:type :bank_account_type} :type {:type :bank_account_type}
:number {:type 'String} :number {:type 'String}
:check_number {:type 'Int} :check_number {:type 'Int}
:visible {:type 'Boolean}
:sort_order {:type 'Int}
:name {:type 'String} :name {:type 'String}
:bank_code {:type 'String} :bank_code {:type 'String}
:routing {:type 'String} :routing {:type 'String}

View File

@@ -24,6 +24,7 @@
(let [client (when (:id edit_client) (d-clients/get-by-id (:id edit_client))) (let [client (when (:id edit_client) (d-clients/get-by-id (:id edit_client)))
id (or (:db/id client) "new-client") id (or (:db/id client) "new-client")
_ (println id) _ (println id)
_ (println edit_client)
transactions [(remove-nils {:db/id id transactions [(remove-nils {:db/id id
:client/code (if (str/blank? (:client/code client)) :client/code (if (str/blank? (:client/code client))
(:code edit_client) (:code edit_client)
@@ -46,8 +47,10 @@
:bank-account/routing (:routing %) :bank-account/routing (:routing %)
:bank-account/name (:name %) :bank-account/name (:name %)
:bank-account/visible (:visible %)
:bank-account/number (:number %) :bank-account/number (:number %)
:bank-account/check-number (:check_number %) :bank-account/check-number (:check_number %)
:bank-account/sort-order (:sort_order %)
:bank-account/yodlee-account-id (:yodlee_account_id %) :bank-account/yodlee-account-id (:yodlee_account_id %)
:bank-account/type (keyword "bank-account-type" (name (:type %))) :bank-account/type (keyword "bank-account-type" (name (:type %)))

View File

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

View File

@@ -75,12 +75,14 @@
:city (:city (:address new-client-data)) :city (:city (:address new-client-data))
:state (:state (:address new-client-data)) :state (:state (:address new-client-data))
:zip (:zip (: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?]}] :bank-accounts (map (fn [{:keys [number name check-number type id code bank-name routing bank-code new? sort-order visible]}]
{:number number {:number number
:name name :name name
:check-number check-number :check-number check-number
:type type :type type
:id id :id id
:sort-order sort-order
:visible visible
:code (if new? :code (if new?
(str (:code new-client-data) "-" code) (str (:code new-client-data) "-" code)
code) code)
@@ -109,7 +111,7 @@
:operation/name "EditClient"} :operation/name "EditClient"}
:venia/queries [{:query/data [:edit-client :venia/queries [{:query/data [:edit-client
{:edit-client new-client-req} {: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]]]]}]} [: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 :sort-order]]]]}]}
:on-success [::save-complete] :on-success [::save-complete]
:on-error [::save-error]}} :on-error [::save-error]}}
{:db new-client-form})))) {:db new-client-form}))))
@@ -149,7 +151,7 @@
::add-new-bank-account ::add-new-bank-account
[(re-frame/path [::forms ::new-client :data])] [(re-frame/path [::forms ::new-client :data])]
(fn [client [_ type]] (fn [client [_ type]]
(update client :bank-accounts conj {:type type :active? true :new? true}))) (update client :bank-accounts conj {:type type :active? true :new? true :visible true :sort-order (count (:bank-accounts client))})))
(re-frame/reg-event-db (re-frame/reg-event-db
::bank-account-activated ::bank-account-activated
@@ -189,6 +191,27 @@
(fn [bas] (fn [bas]
(filter #(not= (:code %) code) bas))))) (filter #(not= (:code %) code) bas)))))
(re-frame/reg-event-db
::sort-swapped
[(re-frame/path [::forms ::new-client :data :bank-accounts ])]
(fn [bank-accounts [_ source dest]]
(->> (-> bank-accounts
(assoc-in [source :sort-order] (get-in bank-accounts [dest :sort-order]))
(assoc-in [dest :sort-order] (get-in bank-accounts [source :sort-order]))
)
(sort-by :sort-order)
vec)))
(re-frame/reg-event-db
::toggle-visible
[(re-frame/path [::forms ::new-client :data :bank-accounts ])]
(fn [bank-accounts [_ account]]
(-> (->> bank-accounts
(sort-by :sort-order)
vec)
(update-in [account :visible] #(not %)))))
(defn clients-table [] (defn clients-table []
(let [clients (re-frame/subscribe [::subs/clients]) (let [clients (re-frame/subscribe [::subs/clients])
editing-client (:client @(re-frame/subscribe [::subs/admin]))] editing-client (:client @(re-frame/subscribe [::subs/admin]))]
@@ -224,8 +247,9 @@
(defn side-bar-form [_ children] (defn side-bar-form [_ children]
[:div [:a.delete.is-pulled-right {:on-click (dispatch-event [::form-closing ::new-client])}] [:div children]]) [:div [:a.delete.is-pulled-right {:on-click (dispatch-event [::form-closing ::new-client])}] [:div children]])
(defn bank-account-card [new-client {:keys [active? new? type code name number check-number id] :as bank-account} index] (defn bank-account-card [new-client {:keys [active? new? type visible code name number check-number id sort-order] :as bank-account} first? last?]
(println new-client)
[:div.card {:style {:margin-bottom "1em"}} [:div.card {:style {:margin-bottom "1em"}}
[:header.card-header [:header.card-header
[:p.card-header-title {:style {:text-overflow "ellipsis"}} [:p.card-header-title {:style {:text-overflow "ellipsis"}}
@@ -234,13 +258,24 @@
[:span.icon-check-payment-sign] [:span.icon-check-payment-sign]
[:span.icon-accounting-bill])] [:span.icon-accounting-bill])]
code ": " name] code ": " name]
[:p {:style {:padding "0.75em 0.25em"}}
[:a.button.is-outlined {:on-click (dispatch-event [::toggle-visible sort-order])} [:span.icon (if visible
[:span.fa.fa-eye]
[:span.fa.fa-eye-slash]
)]]]
(when-not last?
[:p {:style {:padding "0.75em 0.25em"}}
[:a.button.is-primary.is-outlined {:on-click (dispatch-event [::sort-swapped sort-order (inc sort-order)])} [:span.icon [:span.fa.fa-sort-down]]]])
(when-not first?
[:p {:style {:padding "0.75em 0.25em"}}
[:a.button.is-primary.is-outlined {:on-click (dispatch-event [::sort-swapped sort-order (dec sort-order)])} [:span.icon [:span.fa.fa-sort-up]]]])
(if active? (if active?
[:a.card-header-icon [:a.card-header-icon
{:on-click (dispatch-event [::bank-account-deactivated index])} {:on-click (dispatch-event [::bank-account-deactivated sort-order])}
[:span.icon [:span.icon
[:span.fa.fa-angle-up]]] [:span.fa.fa-angle-up]]]
[:a.card-header-icon [:a.card-header-icon
{:on-click (dispatch-event [::bank-account-activated index])} {:on-click (dispatch-event [::bank-account-activated sort-order])}
[:span.icon [:span.icon
[:span.fa.fa-angle-down]]])] [:span.fa.fa-angle-down]]])]
(when active? (when active?
@@ -256,7 +291,7 @@
[:p.control [:p.control
[bind-field [bind-field
[:input.input {:type "code" [:input.input {:type "code"
:field [:bank-accounts index :code] :field [:bank-accounts sort-order :code]
:spec ::entity/code :spec ::entity/code
:event ::change-new :event ::change-new
:subscription new-client}]]]] :subscription new-client}]]]]
@@ -267,10 +302,10 @@
[bind-field [bind-field
[:input.input {:placeholder "BOA Checking #1" [:input.input {:placeholder "BOA Checking #1"
:type "text" :type "text"
:field [:bank-accounts index :name] :field [:bank-accounts sort-order :name]
:event ::change-new :event ::change-new
:subscription new-client}]]]] :subscription new-client}]]]]
(when (#{:check ":check"} (doto type println) ) (when (#{:check ":check"} type )
[:div [:div
[:label.label "Bank"] [:label.label "Bank"]
@@ -281,7 +316,7 @@
[bind-field [bind-field
[:input.input {:placeholder "Bank of America" [:input.input {:placeholder "Bank of America"
:type "text" :type "text"
:field [:bank-accounts index :bank-name] :field [:bank-accounts sort-order :bank-name]
:event ::change-new :event ::change-new
:subscription new-client}]]] :subscription new-client}]]]
[:div.control [:div.control
@@ -289,7 +324,7 @@
[bind-field [bind-field
[:input.input {:placeholder "104819123" [:input.input {:placeholder "104819123"
:type "text" :type "text"
:field [:bank-accounts index :routing] :field [:bank-accounts sort-order :routing]
:event ::change-new :event ::change-new
:subscription new-client}]]] :subscription new-client}]]]
[:div.control [:div.control
@@ -297,7 +332,7 @@
[bind-field [bind-field
[:input.input {:placeholder "12/10123" [:input.input {:placeholder "12/10123"
:type "text" :type "text"
:field [:bank-accounts index :bank-code] :field [:bank-accounts sort-order :bank-code]
:event ::change-new :event ::change-new
:subscription new-client}]]]] :subscription new-client}]]]]
@@ -309,7 +344,7 @@
[bind-field [bind-field
[:input.input {:placeholder "123456789" [:input.input {:placeholder "123456789"
:type "text" :type "text"
:field [:bank-accounts index :number] :field [:bank-accounts sort-order :number]
:event ::change-new :event ::change-new
:subscription new-client}]]] :subscription new-client}]]]
[:div.control [:div.control
@@ -317,7 +352,7 @@
[bind-field [bind-field
[:input.input {:placeholder "10000" [:input.input {:placeholder "10000"
:type "text" :type "text"
:field [:bank-accounts index :check-number] :field [:bank-accounts sort-order :check-number]
:event ::change-new :event ::change-new
:subscription new-client}]]]] :subscription new-client}]]]]
[:div.field [:div.field
@@ -328,17 +363,13 @@
:type "text" :type "text"
:field [:bank-accounts :yodlee-account-id] :field [:bank-accounts :yodlee-account-id]
:event ::change-new :event ::change-new
:subscription new-client}]]] :subscription new-client}]]]]])])
]]
)]
)
(when active? (when active?
[:footer.card-footer [:footer.card-footer
[:a.card-footer-item {:href "#" :on-click (dispatch-event [::bank-account-deactivated index])} "Done"] [:a.card-footer-item {:href "#" :on-click (dispatch-event [::bank-account-deactivated sort-order])} "Done"]
(when new? (when new?
[:a.card-footer-item.is-warning {:href "#" :on-click (dispatch-event [::bank-account-removed index])} "Remove"])])] [:a.card-footer-item.is-warning {:href "#" :on-click (dispatch-event [::bank-account-removed sort-order])} "Remove"])])]
) )
(defn new-client-form [] (defn new-client-form []
@@ -399,9 +430,9 @@
:subscription new-client}]] :subscription new-client}]]
[:h2.subtitle "Bank accounts"] [:h2.subtitle "Bank accounts"]
(for [[bank-account index] (map vector (:bank-accounts new-client) (range))] (for [bank-account (sort-by :sort-order (:bank-accounts new-client))]
^{:key index} ^{:key (:sort-order bank-account)}
[bank-account-card new-client bank-account index]) [bank-account-card new-client bank-account (= 0 (:sort-order bank-account)) (= (:sort-order bank-account) (dec (count (:bank-accounts new-client))))])
[:div.columns [:div.columns
[:div.column.is-half [:div.column.is-half

View File

@@ -465,7 +465,7 @@
:field :bank-account-id :field :bank-account-id
:event ::edit-payment-bank-account :event ::edit-payment-bank-account
:subscription advanced-print-checks} :subscription advanced-print-checks}
(for [{:keys [id number name]} (:bank-accounts current-client)] (for [{:keys [id number name]} (sort-by :sort-order (:bank-accounts current-client))]
^{:key id} [:option {:value id} name])]]]] ^{:key id} [:option {:value id} name])]]]]
[:table.table.is-fullwidth [:table.table.is-fullwidth
@@ -512,7 +512,7 @@
:field :bank-account-id :field :bank-account-id
:event change-event :event change-event
:subscription handwrite-checks} :subscription handwrite-checks}
(for [{:keys [id number name]} (:bank-accounts current-client)] (for [{:keys [id number name]} (->> current-client :bank-accounts (filter #(= (:type %) :check)) (sort-by :sort-order))]
^{:key id} [:option {:value id} name])]]]] ^{:key id} [:option {:value id} name])]]]]
[horizontal-field [horizontal-field
@@ -776,7 +776,7 @@
[:div.dropdown-menu {:role "menu"} [:div.dropdown-menu {:role "menu"}
[:div.dropdown-content [:div.dropdown-content
(list (list
(for [{:keys [id number name type]} (:bank-accounts current-client)] (for [{:keys [id number name type]} (->> (:bank-accounts current-client) (filter :visible) (sort-by :sort-order))]
(if (= :cash type) (if (= :cash type)
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :cash])} "With cash"] ^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :cash])} "With cash"]
(list (list