From b00e2c5b60110f39bcc00cbae44f8fa66b46ac1d Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sat, 23 Jan 2021 10:24:55 -0800 Subject: [PATCH] Started added direct linkage --- src/clj/auto_ap/datomic/checks.clj | 5 +++ src/clj/auto_ap/datomic/invoices.clj | 6 ++- src/clj/auto_ap/graphql.clj | 4 ++ .../views/components/invoice_table.cljs | 39 ++++++++++++------- .../views/components/invoices/side_bar.cljs | 9 ++++- src/cljs/auto_ap/views/pages/payments.cljs | 3 +- .../views/pages/payments/side_bar.cljs | 22 ++++++----- .../auto_ap/views/pages/payments/table.cljs | 5 ++- 8 files changed, 63 insertions(+), 30 deletions(-) diff --git a/src/clj/auto_ap/datomic/checks.clj b/src/clj/auto_ap/datomic/checks.clj index 1c78a903..e38ebbae 100644 --- a/src/clj/auto_ap/datomic/checks.clj +++ b/src/clj/auto_ap/datomic/checks.clj @@ -40,11 +40,16 @@ "amount" ['[?e :payment/amount ?sort-amount]] "status" ['[?e :payment/status ?sort-status]]} args) + (:exact-match-id args) + (merge-query {:query {:in ['?e] + :where []} + :args [(:exact-match-id args)]}) (limited-clients (:id args)) (merge-query {:query {:in ['[?xx ...]] :where ['[?e :payment/client ?xx]]} :args [(set (map :db/id (limited-clients (:id args))))]}) + (:client-id args) (merge-query {:query {:in ['?client-id] diff --git a/src/clj/auto_ap/datomic/invoices.clj b/src/clj/auto_ap/datomic/invoices.clj index a34e1399..b8c3cdcc 100644 --- a/src/clj/auto_ap/datomic/invoices.clj +++ b/src/clj/auto_ap/datomic/invoices.clj @@ -30,7 +30,11 @@ :in ['$] :where ['[?e :invoice/client]]} :args [(d/db (d/connect uri))]} - + + (:exact-match-id args) + (merge-query {:query {:in ['?e] + :where []} + :args [(:exact-match-id args)]}) (limited-clients (:id args)) (merge-query {:query {:in ['[?xx ...]] :where ['[?e :invoice/client ?xx]]} diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 20d72b9f..149999a3 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -536,6 +536,7 @@ :invoice_page {:type '(list :invoice_page) :args {:import_status {:type 'String} + :exact_match_id {:type :id} :date_range {:type :date_range} :due_range {:type :date_range} :status {:type :invoice_status} @@ -618,6 +619,7 @@ :payment_page {:type '(list :payment_page) :args {:client_id {:type :id} :vendor_id {:type :id} + :exact_match_id {:type :id} :date_range {:type :date_range} :amount_lte {:type :money} :amount_gte {:type :money} @@ -646,6 +648,8 @@ :asc {:type 'Boolean}}} :transaction_filters {:fields {:client_id {:type :id} + :exact_match_id {:type :id} + :vendor_id {:type :id} :bank_account_id {:type :id} :account_id {:type :id} diff --git a/src/cljs/auto_ap/views/components/invoice_table.cljs b/src/cljs/auto_ap/views/components/invoice_table.cljs index afb4dfa7..fa0232fb 100644 --- a/src/cljs/auto_ap/views/components/invoice_table.cljs +++ b/src/cljs/auto_ap/views/components/invoice_table.cljs @@ -22,6 +22,7 @@ (defn query [params] {:venia/queries [[:invoice_page { + :exact-match-id (some-> params :exact-match-id str) :start (:start params 0) :sort (:sort params) :per-page (:per-page params) @@ -96,7 +97,7 @@ {:db db})) (defn row [{:keys [invoice check-boxes selected-client overrides checkable? expense-event actions]}] - (let [{:keys [client payments expense-accounts invoice-number date due total outstanding-balance id vendor] :as i} invoice + (let [{:keys [client status payments expense-accounts invoice-number date due total outstanding-balance id vendor] :as i} invoice accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id client]) account->name #(:name (accounts-by-id (:id %)))] [grid/row {:class (:class i) :id id :checkable? checkable? :entity invoice} @@ -110,11 +111,13 @@ [grid/cell {} (date->str date) ] [grid/cell {} (when due - (let [due-in (days-until due)] - (if (> due-in 0) - [:span.has-text-success due-in " days"] - [:span.has-text-danger due-in " days"]) - ))] + (if (#{":paid" :paid ":voided" :voided} status) + nil + (let [due-in (days-until due)] + (if (> due-in 0) + [:span.has-text-success due-in " days"] + [:span.has-text-danger due-in " days"]) + )))] [grid/cell {} (str/join ", " (set (map :location expense-accounts)))] [grid/cell {:class "has-text-right"} (nf total )] @@ -153,18 +156,24 @@ ^{:key (:id payment)} [:a.dropdown-item {:href (str (bidi/path-for routes/routes :payments ) "?" - (url/map->query {:check-number-like (:check-number (:payment payment))})) + (url/map->query {:exact-match-id (:id (:payment payment))})) :target "_new"} [:i.fa.fa-money-check] - [:span.icon [:i.fa.fa-money]] - (str " " (:check-number (:payment payment)) " (" (gstring/format "$%.2f" (:amount payment) ) ")")] + [:span.icon {:class [(when (= :cleared (:status (:payment payment))) + "has-text-success")]} + [:i.fa.fa-money]] - ^{:key (:id payment)} - [:span.dropdown-item [:span.icon {:class [(when (= :cleared (:status (:payment payment))) - "has-text-success")]} - [:i.fa.fa-money]] (str " " (:check-number (:payment payment)) " (" (gstring/format "$%.2f" (:amount payment) ) ") " - (when (= :cleared (:status (:payment payment))) - (str " - " (:post-date (:transaction (:payment payment))))))]))]] + (if (:check-number (:payment payment)) + (str "Check " (:check-number (:payment payment)) + " (" (gstring/format "$%.2f" (:amount payment) ) ")" + (when (= :cleared (:status (:payment payment))) + (str " - " (:post-date (:transaction (:payment payment)))))) + + (str "Debit (" (gstring/format "$%.2f" (:amount payment) ) ") " + (when (= :cleared (:status (:payment payment))) + (str " - " (:post-date (:transaction (:payment payment))))) + (when (= :cleared (:status (:payment payment))) + (str " - " (:post-date (:transaction (:payment payment))))))) ]))]] [:span {:style {:margin-right "1em"}}]]) (when (and (get actions :edit) (not= ":voided" (:status i))) diff --git a/src/cljs/auto_ap/views/components/invoices/side_bar.cljs b/src/cljs/auto_ap/views/components/invoices/side_bar.cljs index d74aa193..6a95a3fe 100644 --- a/src/cljs/auto_ap/views/components/invoices/side_bar.cljs +++ b/src/cljs/auto_ap/views/components/invoices/side_bar.cljs @@ -6,7 +6,7 @@ [auto-ap.views.components.switch-field :refer [switch-field]] [auto-ap.views.components.typeahead :refer [typeahead-entity]] [auto-ap.views.pages.data-page :as data-page] - [auto-ap.views.utils :refer [active-when dispatch-value-change]] + [auto-ap.views.utils :refer [active-when dispatch-event dispatch-value-change]] [bidi.bidi :as bidi] [re-frame.core :as re-frame])) @@ -106,6 +106,13 @@ [:div [invoice-number-filter params]] + (when-let [exact-match-id @(re-frame/subscribe [::data-page/filter data-page :exact-match-id])] + [:div + [:p.menu-label "Specific Invoice"] + [:span.tag.is-medium exact-match-id " " + [:button.delete.is-small {:on-click + (dispatch-event [::data-page/filter-changed data-page :exact-match-id nil])}]]]) + (when (= "admin" (:user/role user)) [:<> [:p.menu-label "Admin only"] diff --git a/src/cljs/auto_ap/views/pages/payments.cljs b/src/cljs/auto_ap/views/pages/payments.cljs index 38292cd5..b63a2120 100644 --- a/src/cljs/auto_ap/views/pages/payments.cljs +++ b/src/cljs/auto_ap/views/pages/payments.cljs @@ -38,6 +38,7 @@ :sort (:sort params) :client-id (:id @(re-frame/subscribe [::subs/client])) :vendor-id (:id (:vendor params)) + :exact-match-id (some-> (:exact-match-id params) str) :date-range (:date-range params) :amount-gte (:amount-gte (:amount-range params)) :amount-lte (:amount-lte (:amount-range params)) @@ -46,7 +47,7 @@ [[:payments [:id :status :amount :type :check_number :s3_url [:bank-account [:name]] :date [:vendor [:name :id]] [:client [:name :id]] - [:invoices [:invoice-id [:invoice [:invoice-number]]]]]] + [:invoices [:invoice-id [:invoice [:invoice-number :id]]]]]] :total :start :end]]]} diff --git a/src/cljs/auto_ap/views/pages/payments/side_bar.cljs b/src/cljs/auto_ap/views/pages/payments/side_bar.cljs index 14423b09..171ac5d2 100644 --- a/src/cljs/auto_ap/views/pages/payments/side_bar.cljs +++ b/src/cljs/auto_ap/views/pages/payments/side_bar.cljs @@ -1,16 +1,11 @@ (ns auto-ap.views.pages.payments.side-bar - (:require [auto-ap.routes :as routes] - [auto-ap.subs :as subs] - [auto-ap.views.utils :refer [active-when dispatch-value-change]] - [auto-ap.views.components.vendor-filter :refer [vendor-filter]] + (:require [auto-ap.subs :as subs] [auto-ap.views.components.date-range-filter :refer [date-range-filter]] [auto-ap.views.components.number-filter :refer [number-filter]] - [auto-ap.views.components.bank-account-filter :refer [bank-account-filter]] [auto-ap.views.components.typeahead :refer [typeahead-entity]] - [bidi.bidi :as bidi] - [re-frame.core :as re-frame] - [auto-ap.views.pages.data-page :as data-page])) - + [auto-ap.views.pages.data-page :as data-page] + [auto-ap.views.utils :refer [dispatch-event dispatch-value-change]] + [re-frame.core :as re-frame])) (defn side-bar [{:keys [data-page]}] (let [ap @(re-frame/subscribe [::subs/active-page]) @@ -48,4 +43,11 @@ [:div.field [:div.control [:input.input {:placeholder "SJ-12345" :value @(re-frame/subscribe [::data-page/filter data-page :invoice-number]) - :on-change (dispatch-value-change [::data-page/filter-changed data-page :invoice-number])} ]]]]])) + :on-change (dispatch-value-change [::data-page/filter-changed data-page :invoice-number])} ]]] + + (when-let [exact-match-id @(re-frame/subscribe [::data-page/filter data-page :exact-match-id])] + [:div + [:p.menu-label "Specific Payment"] + [:span.tag.is-medium exact-match-id " " + [:button.delete.is-small {:on-click + (dispatch-event [::data-page/filter-changed data-page :exact-match-id nil])}]]])]])) diff --git a/src/cljs/auto_ap/views/pages/payments/table.cljs b/src/cljs/auto_ap/views/pages/payments/table.cljs index 615400ec..47b3eb7b 100644 --- a/src/cljs/auto_ap/views/pages/payments/table.cljs +++ b/src/cljs/auto_ap/views/pages/payments/table.cljs @@ -76,8 +76,9 @@ ^{:key (:invoice-number (:invoice invoice))} [:a.dropdown-item {:href (str (bidi/path-for routes/routes :invoices ) "?" - (url/map->query {:invoice-number-like (str "\"" (:invoice-number (:invoice invoice)) "\"")})) - :target "_new"} (str " " (:invoice-number (:invoice invoice)))])]]) + (url/map->query {:exact-match-id (:id (:invoice invoice))})) + :target "_new"} + (str " " (:invoice-number (:invoice invoice)))])]]) [:span {:style {:margin-left "1em"}}] (when (or (= :pending status)