This commit is contained in:
2022-04-26 17:05:58 -07:00
parent cae28589d2
commit 96a796522c
7 changed files with 48 additions and 71 deletions

View File

@@ -140,7 +140,7 @@
(defn get-by-id [id] (defn get-by-id [id]
(->> (d/q '[:find (pull ?e [* (->> (d/q '[:find (pull ?e [*
{:default-account [:account/name :db/id :account/location] {:vendor/default-account [:account/name :db/id :account/location]
:vendor/legal-entity-tin-type [:db/ident :db/id] :vendor/legal-entity-tin-type [:db/ident :db/id]
:vendor/legal-entity-1099-type [:db/ident :db/id] :vendor/legal-entity-1099-type [:db/ident :db/id]
:vendor/account-overrides [* {:vendor-account-override/client [:client/name :db/id] :vendor/account-overrides [* {:vendor-account-override/client [:client/name :db/id]

View File

@@ -366,7 +366,12 @@
(let [type (keyword "payment-type" (name type)) (let [type (keyword "payment-type" (name type))
invoices (d-invoices/get-multi (map :invoice-id invoice-payments)) invoices (d-invoices/get-multi (map :invoice-id invoice-payments))
client (d-clients/get-by-id client-id) client (d-clients/get-by-id client-id)
vendors (by :db/id (d-vendors/get-graphql {})) vendors (->> (d/q '[:find [?e ...]
:in $
:where [?e :vendor/name]]
(d/db conn))
(d/pull-many (d/db conn) d-vendors/default-read)
(by :db/id))
invoice-amounts (by :invoice-id :amount invoice-payments) invoice-amounts (by :invoice-id :amount invoice-payments)
invoices-grouped-by-vendor (group-by (comp :db/id :invoice/vendor) invoices) invoices-grouped-by-vendor (group-by (comp :db/id :invoice/vendor) invoices)
bank-account (d-bank-accounts/get-by-id bank-account-id) bank-account (d-bank-accounts/get-by-id bank-account-id)

View File

@@ -307,6 +307,7 @@
(assert (:invoice/client invoice)) (assert (:invoice/client invoice))
(assert-can-see-client (:id context) (:db/id (:invoice/client invoice))) (assert-can-see-client (:id context) (:db/id (:invoice/client invoice)))
(assert-not-locked (:db/id (:invoice/client invoice)) (:invoice/date invoice)) (assert-not-locked (:db/id (:invoice/client invoice)) (:invoice/date invoice))
(assert (not (seq (:invoice-payment/_invoice invoice))))
(audit-transact [[:db/add id :invoice/status :invoice-status/unpaid] (audit-transact [[:db/add id :invoice/status :invoice-status/unpaid]
[:db/add id :invoice/outstanding-balance (:invoice/total invoice)] [:db/add id :invoice/outstanding-balance (:invoice/total invoice)]
[:db/retract id :invoice/scheduled-payment (:invoice/scheduled-payment invoice)]] [:db/retract id :invoice/scheduled-payment (:invoice/scheduled-payment invoice)]]

View File

@@ -147,14 +147,22 @@
(d-vendors/get-graphql-by-id (assoc args :id (:id context)) (d-vendors/get-graphql-by-id (assoc args :id (:id context))
(:id args)))) (:id args))))
(defn search [_ args _] (defn search [context args _]
(->> (d/q '[:find ?n ?i ?s (let [data (if (is-admin? (:id context))
:in $ ?q (d/q '[:find ?n ?i ?s
:where [(fulltext $ :vendor/search-terms ?q) [[?i ?n _ ?s]]] :in $ ?q
(not [?i :vendor/hidden true])] :where [(fulltext $ :vendor/search-terms ?q) [[?i ?n _ ?s]]]]
(d/db conn) (d/db conn)
(:query args)) (:query args))
(sort-by last) (d/q '[:find ?n ?i ?s
(map (fn [[n i]] :in $ ?q
{:name n :where [(fulltext $ :vendor/search-terms ?q) [[?i ?n _ ?s]]]
:id i})))) (not [?i :vendor/hidden true])]
(d/db conn)
(:query args)))]
(->> data
(sort-by last)
(map (fn [[n i]]
{:name n
:id i})))))

View File

@@ -228,7 +228,8 @@
:event [::unvoid-invoice i]}]) :event [::unvoid-invoice i]}])
(when (and (get actions :void) (when (and (get actions :void)
(= ":paid" (:status i)) (= ":paid" (:status i))
(:scheduled-payment i)) (:scheduled-payment i)
(not (seq (:payments i))))
[buttons/fa-icon {:icon "fa-undo" [buttons/fa-icon {:icon "fa-undo"
:class (status/class-for (get unautopay-states (:id i))) :class (status/class-for (get unautopay-states (:id i)))
:event [::unautopay i]}])]]])) :event [::unautopay i]}])]]]))

View File

@@ -22,30 +22,30 @@
children)}))) children)})))
(defn navbar-drop-down [{:keys [ header id class]} child] (defn navbar-drop-down [{:keys [ header id class]} child]
(let [menu-active? (re-frame/subscribe [::subs/menu-active? id])] (r/create-class
(r/create-class {:reagent-render (fn [{:keys [header id]} child]
{:reagent-render (fn [{:keys [header id]} child] (let [menu-active? @(re-frame/subscribe [::subs/menu-active? id])]
(let [menu-active? @(re-frame/subscribe [::subs/menu-active? id])] [:div { :class (str "navbar-item has-dropdown " (when menu-active? "is-active " ) " " class)}
[:div { :class (str "navbar-item has-dropdown " (when menu-active? "is-active " ) " " class)} [:a {:class "navbar-link login" :on-click (fn [e]
[:a {:class "navbar-link login" :on-click (fn [e] (.preventDefault e)
(.preventDefault e) (.stopPropagation e)
(.stopPropagation e) (re-frame/dispatch [::events/toggle-menu id])
(re-frame/dispatch [::events/toggle-menu id]) true)} header]
true)} header] [appearing {:visible? menu-active? :enter-class "appear" :exit-class "disappear" :timeout 200}
[appearing {:visible? menu-active? :enter-class "appear" :exit-class "disappear" :timeout 200} [:div {:class "navbar-dropdown"}
[:div {:class "navbar-dropdown"} [navbar-drop-down-contents {:id id}
[navbar-drop-down-contents {:id id} [:div child]]]]]))}))
[:div child]]]]]))})))
(defn login-dropdown [] (defn login-dropdown []
(let [user (re-frame/subscribe [::subs/user]) (let [user (re-frame/subscribe [::subs/user])]
menu (re-frame/subscribe [::subs/menu])]
(if @user (if @user
[navbar-drop-down {:header [:span [:span.icon [:i.fa.fa-user] ] [navbar-drop-down {:header [:span [:span.icon [:i.fa.fa-user] ]
[:span (:user/name @user)]] :id ::account} [:span (:user/name @user)]] :id ::account}
[:div [:div
[:a {:class "navbar-item" [:a {:class "navbar-item"
:href (bidi/path-for routes/routes :reports)} "My company"] :href (bidi/path-for routes/routes :reports)} "My company"]
[:a.dropdown-item {:on-click (dispatch-event-with-propagation [::vendor-dialog/started {}])} "New Vendor"]
[:a.dropdown-item {:on-click (dispatch-event-with-propagation [::vendor-dialog/edit {}])} "Edit Vendor"]
(when (= "admin" (:user/role @user)) (when (= "admin" (:user/role @user))
[:a {:class "navbar-item" :href (bidi/path-for routes/routes :admin)} "Administration"]) [:a {:class "navbar-item" :href (bidi/path-for routes/routes :admin)} "Administration"])
[:hr {:class "navbar-divider"}] [:hr {:class "navbar-divider"}]
@@ -131,18 +131,6 @@
(when-not is-initial-loading (when-not is-initial-loading
[:div.navbar-end [:div.navbar-end
[:div.navbar-item
[drop-down {:header [:a.button.is-outlined {:aria-haspopup true
:type "button"
:on-click (dispatch-event-with-propagation [::events/toggle-menu ::vendor ])}
"Vendors "
[:span " "]
[:span.icon [:i.fa.fa-angle-down {:aria-hidden "true"}]]]
:id ::vendor}
[:<>
[:a.dropdown-item {:on-click (dispatch-event-with-propagation [::vendor-dialog/started {}])} "New"]
[:a.dropdown-item {:on-click (dispatch-event-with-propagation [::vendor-dialog/edit {}])} "Edit"]]]]
(when (> (count @clients) 1) (when (> (count @clients) 1)
[navbar-drop-down {:header (str "Company: " (if @client (:name @client) [navbar-drop-down {:header (str "Company: " (if @client (:name @client)
@@ -193,8 +181,7 @@
(defn side-bar-layout [{:keys [side-bar main ap bottom right-side-bar]}] (defn side-bar-layout [{:keys [side-bar main ap bottom right-side-bar]}]
(let [ap @(re-frame/subscribe [::subs/active-page]) (let [ap @(re-frame/subscribe [::subs/active-page])
client @(re-frame/subscribe [::subs/client]) client @(re-frame/subscribe [::subs/client])]
is-initial-loading @(re-frame/subscribe [::subs/is-initial-loading?])]
[:div [:div
[modal/global-modal] [modal/global-modal]
[navbar ap] [navbar ap]

View File

@@ -48,34 +48,9 @@
{:db/id "client" {:db/id "client"
:client/code "DEF"}]))] :client/code "DEF"}]))]
(testing "it should find vendors" (testing "it should find vendors"
(let [result (sut2/get-graphql {} {} {})]
(is (= 1 (count result)))))
(testing "It should count invoice usages for each client"
@(d/transact (d/connect uri)
[{:invoice/client client
:invoice/invoice-number "123"
:invoice/vendor vendor}])
(let [result (sut2/get-graphql {:id (admin-token)} {} {})] (let [result (sut2/get-graphql {:id (admin-token)} {} {})]
(is (= [{:client_id client (is ((into #{} (map :id (:vendors result))) vendor ))))
:count 1}] (-> result first :usage)))))
(testing "It should count transaction usages for each client" )))
@(d/transact (d/connect uri)
[{:transaction/client client
:transaction/vendor vendor}])
(let [result (sut2/get-graphql {:id (admin-token)} {} {})]
(is (= [{:client_id client
:count 2}] (-> result first :usage)))))
(testing "It should limit usages to visible clients"
(let [result (sut2/get-graphql {:id (user-token client)} {} {})]
(is (= [{:client_id client
:count 2}] (-> result first :usage))))
(let [result (sut2/get-graphql {:id (user-token 0)} {} {})]
(is (= nil (-> result first :usage))))))))