From 3dafdd66c2f06cf39b725556e8062968377a7e66 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sun, 5 May 2019 01:00:30 -0700 Subject: [PATCH] fixing vendors --- src/clj/auto_ap/datomic.clj | 2 +- src/clj/auto_ap/datomic/migrate.clj | 5 ++++- .../datomic/migrate/add_general_ledger.clj | 15 +++++++++++++++ src/clj/auto_ap/graphql.clj | 2 ++ src/clj/auto_ap/graphql/vendors.clj | 3 ++- src/cljc/auto_ap/entities/vendors.cljc | 4 +++- src/cljs/auto_ap/events.cljs | 14 +++++++++++--- src/cljs/auto_ap/events/admin/vendors.cljs | 1 + src/cljs/auto_ap/subs.cljs | 8 ++++++-- .../auto_ap/views/components/vendor_dialog.cljs | 11 +++++++++++ 10 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/clj/auto_ap/datomic.clj b/src/clj/auto_ap/datomic.clj index 395a58d1..185a1718 100644 --- a/src/clj/auto_ap/datomic.clj +++ b/src/clj/auto_ap/datomic.clj @@ -12,7 +12,7 @@ [clj-time.core :as time] [clj-time.coerce :as coerce])) -(def uri "datomic:sql://invoices?jdbc:postgresql://database:5432/datomic?user=datomic&password=datomic") + (def uri "datomic:sql://invoices-backup?jdbc:postgresql://database:5432/datomic?user=datomic&password=datomic") (defn create-database [] (d/create-database uri)) diff --git a/src/clj/auto_ap/datomic/migrate.clj b/src/clj/auto_ap/datomic/migrate.clj index 10a19809..6cc17d68 100644 --- a/src/clj/auto_ap/datomic/migrate.clj +++ b/src/clj/auto_ap/datomic/migrate.clj @@ -120,8 +120,9 @@ :requires [:auto-ap/add-account-to-vendor]} :auto-ap/add-credit-bank-account {:txes add-general-ledger/add-credit-bank-account :requires [:auto-ap/add-location-to-transaction]} + :auto-ap/add-hidden-to-vendor {:txes-fn `add-general-ledger/add-hidden-to-vendor :requires [:auto-ap/add-credit-bank-account]} :auto-ap/convert-vendors {:txes-fn `add-general-ledger/convert-vendors - :requires [:auto-ap/add-location-to-transaction]} + :requires [:auto-ap/add-hidden-to-vendor]} :auto-ap/convert-invoices {:txes-fn `add-general-ledger/convert-invoices :requires [:auto-ap/convert-vendors]} @@ -129,6 +130,8 @@ :auto-ap/add-external-id-to-ledger {:txes add-general-ledger/add-external-id-to-ledger :requires [:auto-ap/add-yodlee-merchant2]} :auto-ap/add-exclude-to-transaction {:txes add-general-ledger/add-exclude-to-transaction :requires [:auto-ap/add-external-id-to-ledger]} :auto-ap/convert-transactions {:txes-fn `add-general-ledger/convert-transactions :requires [:auto-ap/add-external-id-to-ledger]} + + #_#_:auto-ap/bulk-load-invoice-ledger3 {:txes-fn `add-general-ledger/bulk-load-invoice-ledger :requires [:auto-ap/convert-transactions]} #_#_:auto-ap/bulk-load-transaction-ledger3 {:txes-fn `add-general-ledger/bulk-load-transaction-ledger :requires [:auto-ap/convert-transactions]} diff --git a/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj b/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj index 8eac9c8a..8eb4214b 100644 --- a/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj +++ b/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj @@ -308,6 +308,21 @@ (def add-credit-bank-account [[{:db/ident :bank-account-type/credit}]]) +(defn add-hidden-to-vendor [conn] + [[{:db/ident :vendor/hidden + :db/valueType :db.type/boolean + :db/cardinality :db.cardinality/one + :db/doc "Whether or not to exclude the vendor"}] + (let [vendors (d/query {:query {:find '[?v] + :in '[$] + :where ['[?v :vendor/name]]} + :args [(d/db conn)]})] + (mapv + (fn [[v ]] + {:db/id v + :vendor/hidden false}) + vendors))]) + (defn reset-ledger [conn] diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 689d7720..06b379ad 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -90,6 +90,7 @@ {:fields {:id {:type :id} :name {:type 'String} :code {:type 'String} + :hidden {:type 'Boolean} :print_as {:type 'String} :primary_contact {:type :contact} @@ -429,6 +430,7 @@ :name {:type 'String} :code {:type 'String} + :hidden {:type 'Boolean} :print_as {:type 'String} :primary_contact {:type :add_contact} :secondary_contact {:type :add_contact} diff --git a/src/clj/auto_ap/graphql/vendors.clj b/src/clj/auto_ap/graphql/vendors.clj index 4de8a0e4..004d4dbc 100644 --- a/src/clj/auto_ap/graphql/vendors.clj +++ b/src/clj/auto_ap/graphql/vendors.clj @@ -8,13 +8,14 @@ [clojure.set :as set])) -(defn upsert-vendor [context {{:keys [id name code print_as primary_contact secondary_contact address default_account_id invoice_reminder_schedule] :as in} :vendor} value] +(defn upsert-vendor [context {{:keys [id name hidden code print_as primary_contact secondary_contact address default_account_id invoice_reminder_schedule] :as in} :vendor} value] (let [_ (println default_account_id) transaction [(remove-nils #:vendor {:db/id (if id id "vendor") :name name :code code + :hidden hidden :print-as print_as :default-account default_account_id :invoice-reminder-schedule (keyword invoice_reminder_schedule) diff --git a/src/cljc/auto_ap/entities/vendors.cljc b/src/cljc/auto_ap/entities/vendors.cljc index 1bb8cc47..b4766eca 100644 --- a/src/cljc/auto_ap/entities/vendors.cljc +++ b/src/cljc/auto_ap/entities/vendors.cljc @@ -9,6 +9,7 @@ #(not (str/blank? %)))) (s/def ::name ::required-identifier) +(s/def ::hidden boolean?) (s/def ::print-as (s/nilable string?)) (s/def ::invoice-reminder-schedule (s/nilable #{"Weekly" "Never" nil})) @@ -21,7 +22,8 @@ (s/def ::code (s/nilable string?)) (s/def ::vendor (s/keys :req-un [::name - ::default-account-id] + ::default-account-id + ::hidden] :opt-un [::code ::id ::print-as diff --git a/src/cljs/auto_ap/events.cljs b/src/cljs/auto_ap/events.cljs index 87da7859..e4e6ca99 100644 --- a/src/cljs/auto_ap/events.cljs +++ b/src/cljs/auto_ap/events.cljs @@ -45,11 +45,11 @@ [: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] ] [:address [:street1 :street2 :city :state :zip]]]] [:vendor - [:id :name [:default-account [:name :id :location]] [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]] + [: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 :location :name :type :account_set :id]]]} :on-success [::received-initial]}})))) (def vendor-query - [:id :name [:default-account [:name :id :location]] + [: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 @@ -67,7 +67,7 @@ :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] ]]] [:vendor - [:id :name [:default-account [:name :id :location]] [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]] + [: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]]]} :on-success [::received-initial]} @@ -221,6 +221,14 @@ vendor-query]}]} :on-success [::save-complete] :on-error [::save-error]})))) + +(re-frame/reg-event-db + ::save-error + (fn [db [_ vendor]] + (-> db + (assoc-in [:modal-state :auto-ap.views.main/user-editing-vendor :error] true) + (assoc-in [:modal-state :auto-ap.views.main/user-editing-vendor :saving?] false)))) + (re-frame/reg-event-fx ::save-complete (fn [{:keys [db]} [_ vendor]] diff --git a/src/cljs/auto_ap/events/admin/vendors.cljs b/src/cljs/auto_ap/events/admin/vendors.cljs index 105c9611..0b3a2aae 100644 --- a/src/cljs/auto_ap/events/admin/vendors.cljs +++ b/src/cljs/auto_ap/events/admin/vendors.cljs @@ -81,6 +81,7 @@ (re-frame/reg-event-db ::save-error (fn [db [_ vendor]] + (println "ERROR?") (-> db (assoc-in [:admin :vendor :error] true) (assoc-in [:admin :vendor :saving?] false)))) diff --git a/src/cljs/auto_ap/subs.cljs b/src/cljs/auto_ap/subs.cljs index 5827f19a..68b9500a 100644 --- a/src/cljs/auto_ap/subs.cljs +++ b/src/cljs/auto_ap/subs.cljs @@ -98,7 +98,7 @@ (re-frame/reg-sub ::vendors (fn [db] - (vals (:vendors db)))) + (filter #(not (:hidden %)) (vals (:vendors db))))) (re-frame/reg-sub ::vendors-by-id @@ -128,7 +128,11 @@ (re-frame/reg-sub ::user-editing-vendor (fn [db] - (-> db :user-editing-vendor))) + (update (-> db :user-editing-vendor) + :hidden + #(if (nil? %) + false + %)))) (re-frame/reg-sub ::user diff --git a/src/cljs/auto_ap/views/components/vendor_dialog.cljs b/src/cljs/auto_ap/views/components/vendor_dialog.cljs index 7064eb10..928982f0 100644 --- a/src/cljs/auto_ap/views/components/vendor_dialog.cljs +++ b/src/cljs/auto_ap/views/components/vendor_dialog.cljs @@ -45,6 +45,17 @@ :spec ::entity/print-as :event change-event :subscription vendor}]]]] + + [horizontal-field + [:label.label "Hidden"] + [:div.control + [bind-field + [:input {:type "checkbox" + :field :hidden + :spec ::entity/hidden + :event change-event + :subscription vendor}]]]] + [:h2.subtitle "Expense Accounts"] [horizontal-field [:label.label "Default"]