From ad29a19ff330e61e0b1390469015a65f9176e448 Mon Sep 17 00:00:00 2001 From: Bryce Date: Tue, 23 Apr 2024 22:22:12 -0700 Subject: [PATCH] Adds lock icon for locked transactions. --- src/clj/auto_ap/datomic/transactions.clj | 20 ++++++++++++++++--- src/clj/auto_ap/graphql/transactions.clj | 1 + src/cljs/auto_ap/views/components/grid.cljs | 3 ++- .../views/pages/transactions/common.cljs | 2 ++ .../views/pages/transactions/table.cljs | 15 +++++++++++++- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/clj/auto_ap/datomic/transactions.clj b/src/clj/auto_ap/datomic/transactions.clj index 9e9120e7..7ddce3df 100644 --- a/src/clj/auto_ap/datomic/transactions.clj +++ b/src/clj/auto_ap/datomic/transactions.clj @@ -12,7 +12,8 @@ [auto-ap.graphql.utils :refer [extract-client-ids]] [clj-time.coerce :as coerce] [clojure.string :as str] - [datomic.api :as dc])) + [datomic.api :as dc] + [clj-time.core :as time])) (defn potential-duplicate-ids [db args] (when (and (:potential-duplicates args) @@ -171,10 +172,22 @@ true (apply-sort-3 (assoc args :default-asc? false)) true (apply-pagination args))))) +(defn is-locked? [transaction] + (let [transaction-date (some-> transaction :transaction/date coerce/to-date-time) + bank-account-start-date (some-> transaction :transaction/bank-account :bank-account/start-date coerce/to-date-time) + client-locked-until (some-> transaction :transaction/client :client/locked-until coerce/to-date-time) + locked-by-client? (cond (not transaction-date) false + (not client-locked-until) false + :else (time/before? transaction-date client-locked-until)) + locked-by-bank-account? (cond (not transaction-date) false + (not bank-account-start-date) false + :else (time/before? transaction-date bank-account-start-date))] + (or locked-by-bank-account? locked-by-client?))) + (defn graphql-results [ids db _] - (let [results (->> (pull-many db '[* {:transaction/client [:client/name :db/id :client/code] + (let [results (->> (pull-many db '[* {:transaction/client [:client/name :db/id :client/code :client/locked-until] :transaction/approval-status [:db/ident :db/id] - :transaction/bank-account [:bank-account/name :bank-account/code :bank-account/yodlee-account-id :db/id :bank-account/locations :bank-account/current-balance] + :transaction/bank-account [:bank-account/name :bank-account/code :bank-account/yodlee-account-id :db/id :bank-account/locations :bank-account/current-balance :bank-account/start-date] :transaction/forecast-match [:db/id :forecasted-transaction/identifier] :transaction/vendor [:db/id :vendor/name] :transaction/matched-rule [:db/id :transaction-rule/note] @@ -190,6 +203,7 @@ :transaction/yodlee-merchant [:db/id :yodlee-merchant/yodlee-id :yodlee-merchant/name] :transaction/plaid-merchant [:db/id :plaid-merchant/name]}] ids) + (map #(assoc % :transaction/is-locked (is-locked? %))) (map #(update % :transaction/date coerce/from-date)) (map #(update % :transaction/post-date coerce/from-date)) (map #(update % :transaction/accounts diff --git a/src/clj/auto_ap/graphql/transactions.clj b/src/clj/auto_ap/graphql/transactions.clj index ff92785c..bba835f5 100644 --- a/src/clj/auto_ap/graphql/transactions.clj +++ b/src/clj/auto_ap/graphql/transactions.clj @@ -571,6 +571,7 @@ (def objects {:transaction {:fields {:id {:type :id} :amount {:type 'String} + :is_locked {:type 'Boolean} :description_original {:type 'String} :description_simple {:type 'String} :location {:type 'String} diff --git a/src/cljs/auto_ap/views/components/grid.cljs b/src/cljs/auto_ap/views/components/grid.cljs index 04948b0a..f70cbad5 100644 --- a/src/cljs/auto_ap/views/components/grid.cljs +++ b/src/cljs/auto_ap/views/components/grid.cljs @@ -222,8 +222,9 @@ (map r/as-element (r/children (r/current-component))))) (defn cell [params] - (apply r/create-element "td" #js {:className (:class params)} + (apply r/create-element "td" #js {:className (:class params) :style (some-> (:style params) clj->js)} (map r/as-element (r/children (r/current-component)))) + ) (defn body [] diff --git a/src/cljs/auto_ap/views/pages/transactions/common.cljs b/src/cljs/auto_ap/views/pages/transactions/common.cljs index 59956a17..5eb56b9b 100644 --- a/src/cljs/auto_ap/views/pages/transactions/common.cljs +++ b/src/cljs/auto_ap/views/pages/transactions/common.cljs @@ -9,6 +9,8 @@ :location :approval-status :check-number + :is-locked + [:matched-rule [:note :id]] [:vendor [:name :id]] [:accounts [:id :amount :location [:account [:name :id :location :numeric-code]]]] diff --git a/src/cljs/auto_ap/views/pages/transactions/table.cljs b/src/cljs/auto_ap/views/pages/transactions/table.cljs index f5f00c46..adb2bee6 100644 --- a/src/cljs/auto_ap/views/pages/transactions/table.cljs +++ b/src/cljs/auto_ap/views/pages/transactions/table.cljs @@ -59,6 +59,12 @@ (fn [db] (::table-params db))) +(defn lock-icon [] + [:div {:style {:position "absolute" :width "1em" :height "1em" :left "-1.25rem" :background-color "#E0E0E0" :padding "5px" :box-sizing "content-box" :border-radius "999px" :display "flex" :justify-content "center" :align-content "center" :text-align "center"}} + [:div + [:i.fa.fa-lock {:style {:color "#333"}}]]]) + + (defn table [{:keys [data-page check-boxes? action-buttons]}] (let [selected-client @(re-frame/subscribe [::subs/client]) {:keys [data params]} @(re-frame/subscribe [::data-page/page data-page]) @@ -85,9 +91,16 @@ ^{:key id} [grid/row {:class (:class i) :id id :entity i} (when-not selected-client - [grid/cell {} (:name client)]) + [grid/cell {:style {:overflow "visible" :position "relative" }} + + (when (:is-locked i) + [lock-icon]) + (:name client)]) #_[:td description-original] [grid/cell {} + + (when (and selected-client (:is-locked i)) + [lock-icon]) (:name bank-account)] [grid/cell {} (cond vendor (:name vendor)