From 05c9fa8fd8ab4f38f5242658f01a01b67a6b090b Mon Sep 17 00:00:00 2001 From: Bryce Date: Sat, 30 Jun 2018 10:24:41 -0700 Subject: [PATCH] Checks now have a status that gets updated --- .../migrations/1530379134-DOWN-add-check-status.sql | 2 ++ .../migrations/1530379134-UP-add-check-status.sql | 2 ++ src/clj/auto_ap/db/checks.clj | 6 ++++++ src/clj/auto_ap/graphql.clj | 3 ++- src/clj/auto_ap/yodlee/import.clj | 9 +++++++-- src/cljs/auto_ap/views/pages/checks.cljs | 12 ++++++++++-- 6 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 migrator/migrations/1530379134-DOWN-add-check-status.sql create mode 100644 migrator/migrations/1530379134-UP-add-check-status.sql diff --git a/migrator/migrations/1530379134-DOWN-add-check-status.sql b/migrator/migrations/1530379134-DOWN-add-check-status.sql new file mode 100644 index 00000000..9e0c86aa --- /dev/null +++ b/migrator/migrations/1530379134-DOWN-add-check-status.sql @@ -0,0 +1,2 @@ +-- 1530379134 DOWN add-check-status +alter table checks drop column status; diff --git a/migrator/migrations/1530379134-UP-add-check-status.sql b/migrator/migrations/1530379134-UP-add-check-status.sql new file mode 100644 index 00000000..5e0a78c1 --- /dev/null +++ b/migrator/migrations/1530379134-UP-add-check-status.sql @@ -0,0 +1,2 @@ +-- 1530379134 UP add-check-status +alter table checks add column status varchar(255) default 'pending'; diff --git a/src/clj/auto_ap/db/checks.clj b/src/clj/auto_ap/db/checks.clj index e9e4e6de..629b32f0 100644 --- a/src/clj/auto_ap/db/checks.clj +++ b/src/clj/auto_ap/db/checks.clj @@ -85,3 +85,9 @@ (defn count-graphql [args] (:count (first (query (assoc (base-graphql args) :select [:%count.*]))))) + +(defn update! [row] + (j/update! (get-conn) + :checks + (-> row (fields->data) (clj->db)) + ["id = ?" (:id row)])) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 03c50544..9e04b030 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -69,7 +69,8 @@ :resolve :get-company-for-check} :date {:type 'String} :s3_url {:type 'String} - :check_number {:type 'Int}}} + :check_number {:type 'Int} + :status {:type 'String}}} :transaction {:fields {:id {:type 'Int} :amount {:type 'String} diff --git a/src/clj/auto_ap/yodlee/import.clj b/src/clj/auto_ap/yodlee/import.clj index d5281abe..d48e0bef 100644 --- a/src/clj/auto_ap/yodlee/import.clj +++ b/src/clj/auto_ap/yodlee/import.clj @@ -52,7 +52,9 @@ transaction check-number (extract-check-number transaction) company-id (account->company account-id) - bank-account-id (yodlee-account-id->bank-account-id account-id)]] + bank-account-id (yodlee-account-id->bank-account-id account-id) + check-id (transaction->check-id transaction check-number company-id bank-account-id) + ]] (try (transactions/upsert! @@ -68,7 +70,10 @@ :company-id company-id :check-number check-number :bank-account-id (yodlee-account-id->bank-account-id account-id) - :check-id (transaction->check-id transaction check-number company-id bank-account-id) + :check-id check-id }) + (when check-id + (checks/update! {:id check-id :status "cleared"})) + (catch Exception e (println e)))))) diff --git a/src/cljs/auto_ap/views/pages/checks.cljs b/src/cljs/auto_ap/views/pages/checks.cljs index 7da4d4b7..532ddae8 100644 --- a/src/cljs/auto_ap/views/pages/checks.cljs +++ b/src/cljs/auto_ap/views/pages/checks.cljs @@ -36,7 +36,7 @@ :graphql {:token (-> cofx :db :user) :query-obj {:venia/queries [[:check_page (assoc params :company-id (:id @(re-frame/subscribe [::subs/company]))) - [[:checks [:id :amount :check_number :s3_url :date [:vendor [:name :id]] [:company [:name :id]]]] + [[:checks [:id :status :amount :check_number :s3_url :date [:vendor [:name :id]] [:company [:name :id]]]] :total :start :end]]]} @@ -104,6 +104,13 @@ :sort-by sort-by :asc asc} "Amount"] + + [sorted-column {:on-sort opc + :style {:width "8em" :cursor "pointer"} + :sort-key "status" + :sort-by sort-by + :asc asc} + "Status"] [:th {:style {:width "10em"}} "" ]]] @@ -112,7 +119,7 @@ [:tr [:td {:col-span 5} [:i.fa.fa-spin.fa-spinner]]] - (for [{:keys [company s3-url checks check-number date amount id vendor] :as i} (:checks @check-page)] + (for [{:keys [company s3-url checks check-number date amount id vendor status] :as i} (:checks @check-page)] ^{:key id} [:tr {:class (:class i)} @@ -121,6 +128,7 @@ [:td check-number] [:td (date->str date) ] [:td (gstring/format "$%.2f" amount )] + [:td status] [:td (if s3-url [:a.tag {:href s3-url :target "_new"} [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " check-number " (" (gstring/format "$%.2f" amount ) ")")]