From 2cc193a66fc4394735b2fabc5e06c9ebe6dae091 Mon Sep 17 00:00:00 2001 From: BC Date: Tue, 31 Jul 2018 17:55:57 -0700 Subject: [PATCH 1/5] adding more validation. --- docker-compose.prod.yml | 2 ++ project.clj | 2 +- src/clj/auto_ap/graphql/invoices.clj | 6 ++++-- src/clj/auto_ap/routes/graphql.clj | 15 ++++++++++----- src/cljs/auto_ap/views/pages/unpaid_invoices.cljs | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index c9160508..0b2539f6 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -5,6 +5,8 @@ services: ports: - "80:80" - "443:443" + labels: + - com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - /opt/integreat/prod/certs/:/etc/nginx/certs:ro diff --git a/project.clj b/project.clj index 970bdd0c..9c7a8c13 100644 --- a/project.clj +++ b/project.clj @@ -71,7 +71,7 @@ :plugins [[lein-figwheel "0.5.13"] [lein-pdo "0.1.1"] [cider/cider-nrepl "0.16.0"]] - :jvm-opts ["-Dconfig=config/dev.edn" #_#_"--add-modules" "java.xml.bind"]} + :jvm-opts ["-Dconfig=config/dev.edn" "--add-modules" "java.xml.bind"]} :uberjar {:prep-tasks [["cljsbuild" "once" "min"] "compile"]} :provided {:dependencies [[org.clojure/clojurescript "1.10.238"] [reagent "0.7.0"] diff --git a/src/clj/auto_ap/graphql/invoices.clj b/src/clj/auto_ap/graphql/invoices.clj index ad246094..34d4e827 100644 --- a/src/clj/auto_ap/graphql/invoices.clj +++ b/src/clj/auto_ap/graphql/invoices.clj @@ -16,9 +16,11 @@ (when (seq (invoices/find-conflicting {:invoice-number invoice_number :vendor-id vendor_id :company-id company_id})) - (throw (ex-info "that invoice already exists" {:invoice-number invoice_number}))) + (throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number}))) (let [vendor (-create-or-get-vendor vendor_id vendor_name) _ (assert-can-see-company (:id context) company_id) + _ (when-not (:default-expense-account vendor) + (throw (ex-info (str "Vendor '" (:name vendor) "' does not have a default expense acount.") {:vendor-id vendor_id} ))) company (companies/get-by-id company_id) [invoice] (invoices/insert-multi! [{:invoice-number invoice_number @@ -44,7 +46,7 @@ :invoice-number invoice_number :vendor-id (:vendor-id invoice) :company-id (:company-id invoice)})) - (throw (ex-info "that invoice already exists" {:invoice-number invoice_number}))) + (throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number}))) paid-amount (- (:total invoice) (:outstanding-balance invoice)) _ (assert-can-see-company (:id context) (:company-id invoice)) updated-invoice (invoices/update (-> in diff --git a/src/clj/auto_ap/routes/graphql.clj b/src/clj/auto_ap/routes/graphql.clj index 6081d471..be8323e2 100644 --- a/src/clj/auto_ap/routes/graphql.clj +++ b/src/clj/auto_ap/routes/graphql.clj @@ -16,9 +16,14 @@ (when (= "none" (:role (:identity r))) (throw-unauthorized)) - (let [variables (some-> (query-params "variables") - edn/read-string)] - {:status 200 - :body (pr-str (ql/query (:identity r) (query-params "query") variables )) - :headers {"Content-Type" "application/edn"}}))) + (try + (let [variables (some-> (query-params "variables") + edn/read-string)] + {:status 200 + :body (pr-str (ql/query (:identity r) (query-params "query") variables )) + :headers {"Content-Type" "application/edn"}}) + (catch Exception e + {:status 400 + :body (pr-str {:data (merge {:message (.getMessage e)} (ex-data e))}) + :headers {"Content-Type" "application/edn"}})))) wrap-secure)) diff --git a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs index 485fa9c0..74de3da9 100644 --- a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs +++ b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs @@ -344,7 +344,7 @@ (re-frame/reg-event-fx ::invoice-create-failed (fn [{:keys [db]} [_ data]] - {:dispatch [::events/modal-failed ::new-invoice "That invoice already exists."]})) + {:dispatch [::events/modal-failed ::new-invoice (:message data)]})) (re-frame/reg-event-fx ::invoice-created From fe4d492fa73b89faef8b4fa6f447baf3a1bd577d Mon Sep 17 00:00:00 2001 From: BC Date: Tue, 31 Jul 2018 17:57:35 -0700 Subject: [PATCH 2/5] you must enter a default expense account. --- src/cljc/auto_ap/entities/vendors.cljc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cljc/auto_ap/entities/vendors.cljc b/src/cljc/auto_ap/entities/vendors.cljc index c44a0c66..b0805117 100644 --- a/src/cljc/auto_ap/entities/vendors.cljc +++ b/src/cljc/auto_ap/entities/vendors.cljc @@ -29,7 +29,8 @@ (s/def ::code (s/nilable string?)) -(s/def ::vendor (s/keys :req-un [::name] +(s/def ::vendor (s/keys :req-un [::name + ::default-expense-account] :opt-un [::code ::id ::print-as @@ -41,7 +42,7 @@ ::secondary-email ::secondary-phone ::address - ::default-expense-account + ])) From f893bfde0f15862c0149988a907fd30356368891 Mon Sep 17 00:00:00 2001 From: BC Date: Tue, 31 Jul 2018 18:19:18 -0700 Subject: [PATCH 3/5] ignores checkcard --- src/clj/auto_ap/yodlee/import.clj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/clj/auto_ap/yodlee/import.clj b/src/clj/auto_ap/yodlee/import.clj index df2b0a2d..9ce0bd9c 100644 --- a/src/clj/auto_ap/yodlee/import.clj +++ b/src/clj/auto_ap/yodlee/import.clj @@ -33,7 +33,8 @@ nil)) (defn extract-check-number [{{description-original :original} :description}] - (if-let [[_ check-number] (re-find #"(?i)check[^0-9]+([0-9]*)" description-original)] + + (if-let [[_ _ check-number] (re-find #"(?i)check(card|[^0-9]+([0-9]*))" description-original)] (try (Integer/parseInt check-number) (catch NumberFormatException e From 56fa0655d527e4e75848405cf5437cedf3ae02dd Mon Sep 17 00:00:00 2001 From: BC Date: Tue, 31 Jul 2018 19:03:18 -0700 Subject: [PATCH 4/5] improving the appear problem. --- resources/public/index.html | 12 ++++++++---- src/clj/auto_ap/yodlee/import.clj | 2 +- src/cljs/auto_ap/views/components/invoice_table.cljs | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/resources/public/index.html b/resources/public/index.html index 8fb393e7..c6dfd850 100644 --- a/resources/public/index.html +++ b/resources/public/index.html @@ -55,31 +55,35 @@ @keyframes flashWarning { from { + background-color: #00d1b2; } to { + background-color: inherit; - background-color: #00d1b2; } } @keyframes flashPrimary { from { - transform: translateY(100%); - opacity: 0; + background-color: #00d1b2; } to { - background-color: #00d1b2; + background-color: inherit; + + } } tbody tr.live-removed { animation: flashWarning 1.0s ease both; + animation-fill-mode: forwards; } tbody tr.live-added { animation: flashPrimary 1.0s ease both; + animation-fill-mode: forwards; } .left-nav { width: 300px; diff --git a/src/clj/auto_ap/yodlee/import.clj b/src/clj/auto_ap/yodlee/import.clj index 9ce0bd9c..44949bb0 100644 --- a/src/clj/auto_ap/yodlee/import.clj +++ b/src/clj/auto_ap/yodlee/import.clj @@ -98,7 +98,7 @@ (mapcat (fn [transaction-group] (map (fn [index {:keys [date description-original high-level-category amount account-id] :as transaction}] - {:id (str date "-" description-original "-" amount "-" index) + {:id (str date "-" description-original "-" amount "-" index "-" company-id) :bank-account-id account-id :date (time/unparse date "YYYY-MM-dd") :amount {:amount amount} diff --git a/src/cljs/auto_ap/views/components/invoice_table.cljs b/src/cljs/auto_ap/views/components/invoice_table.cljs index af1855e4..6cefe61e 100644 --- a/src/cljs/auto_ap/views/components/invoice_table.cljs +++ b/src/cljs/auto_ap/views/components/invoice_table.cljs @@ -169,7 +169,7 @@ :aria-haspopup true :tab-index "0" - :on-blur (delayed-dispatch [::toggle-expense-accounts id]) + #_#_:on-blur (delayed-dispatch [::toggle-expense-accounts id]) :on-focus (dispatch-event [::toggle-expense-accounts id]) } "Accounts"]] [:div.dropdown-menu {:role "menu"} From 4a6f3bc12242c321408fbf1ac19f7442dd2f7e94 Mon Sep 17 00:00:00 2001 From: BC Date: Tue, 31 Jul 2018 19:12:34 -0700 Subject: [PATCH 5/5] doesnt allow advanced overpay. --- project.clj | 2 +- src/cljs/auto_ap/views/pages/unpaid_invoices.cljs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 9c7a8c13..970bdd0c 100644 --- a/project.clj +++ b/project.clj @@ -71,7 +71,7 @@ :plugins [[lein-figwheel "0.5.13"] [lein-pdo "0.1.1"] [cider/cider-nrepl "0.16.0"]] - :jvm-opts ["-Dconfig=config/dev.edn" "--add-modules" "java.xml.bind"]} + :jvm-opts ["-Dconfig=config/dev.edn" #_#_"--add-modules" "java.xml.bind"]} :uberjar {:prep-tasks [["cljsbuild" "once" "min"] "compile"]} :provided {:dependencies [[org.clojure/clojurescript "1.10.238"] [reagent "0.7.0"] diff --git a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs index 74de3da9..a9d1abcc 100644 --- a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs +++ b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs @@ -531,6 +531,14 @@ (when shown? [modal {:title "Print Checks" :foot [:button.button.is-primary {:on-click (dispatch-event [::advanced-print-checks-submitted]) + :disabled (cond printing? + "disabled" + + (seq (filter #(> (js/parseFloat (:amount %)) (js/parseFloat (:outstanding-balance %))) invoices)) + "disabled" + + :else + "") :class (if printing? "is-loading" "")} [:span "Print"]] :hide-event [::cancel-advanced-print]}