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]
(->> (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-1099-type [:db/ident :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))
invoices (d-invoices/get-multi (map :invoice-id invoice-payments))
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)
invoices-grouped-by-vendor (group-by (comp :db/id :invoice/vendor) invoices)
bank-account (d-bank-accounts/get-by-id bank-account-id)

View File

@@ -307,6 +307,7 @@
(assert (: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 (seq (:invoice-payment/_invoice invoice))))
(audit-transact [[:db/add id :invoice/status :invoice-status/unpaid]
[:db/add id :invoice/outstanding-balance (:invoice/total 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))
(:id args))))
(defn search [_ args _]
(->> (d/q '[:find ?n ?i ?s
:in $ ?q
:where [(fulltext $ :vendor/search-terms ?q) [[?i ?n _ ?s]]]
(not [?i :vendor/hidden true])]
(d/db conn)
(:query args))
(sort-by last)
(map (fn [[n i]]
{:name n
:id i}))))
(defn search [context args _]
(let [data (if (is-admin? (:id context))
(d/q '[:find ?n ?i ?s
:in $ ?q
:where [(fulltext $ :vendor/search-terms ?q) [[?i ?n _ ?s]]]]
(d/db conn)
(:query args))
(d/q '[:find ?n ?i ?s
:in $ ?q
:where [(fulltext $ :vendor/search-terms ?q) [[?i ?n _ ?s]]]
(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]}])
(when (and (get actions :void)
(= ":paid" (:status i))
(:scheduled-payment i))
(:scheduled-payment i)
(not (seq (:payments i))))
[buttons/fa-icon {:icon "fa-undo"
:class (status/class-for (get unautopay-states (:id i)))
:event [::unautopay i]}])]]]))

View File

@@ -22,30 +22,30 @@
children)})))
(defn navbar-drop-down [{:keys [ header id class]} child]
(let [menu-active? (re-frame/subscribe [::subs/menu-active? id])]
(r/create-class
{:reagent-render (fn [{:keys [header id]} child]
(let [menu-active? @(re-frame/subscribe [::subs/menu-active? id])]
[:div { :class (str "navbar-item has-dropdown " (when menu-active? "is-active " ) " " class)}
[:a {:class "navbar-link login" :on-click (fn [e]
(.preventDefault e)
(.stopPropagation e)
(re-frame/dispatch [::events/toggle-menu id])
true)} header]
[appearing {:visible? menu-active? :enter-class "appear" :exit-class "disappear" :timeout 200}
[:div {:class "navbar-dropdown"}
[navbar-drop-down-contents {:id id}
[:div child]]]]]))})))
(r/create-class
{:reagent-render (fn [{:keys [header id]} child]
(let [menu-active? @(re-frame/subscribe [::subs/menu-active? id])]
[:div { :class (str "navbar-item has-dropdown " (when menu-active? "is-active " ) " " class)}
[:a {:class "navbar-link login" :on-click (fn [e]
(.preventDefault e)
(.stopPropagation e)
(re-frame/dispatch [::events/toggle-menu id])
true)} header]
[appearing {:visible? menu-active? :enter-class "appear" :exit-class "disappear" :timeout 200}
[:div {:class "navbar-dropdown"}
[navbar-drop-down-contents {:id id}
[:div child]]]]]))}))
(defn login-dropdown []
(let [user (re-frame/subscribe [::subs/user])
menu (re-frame/subscribe [::subs/menu])]
(let [user (re-frame/subscribe [::subs/user])]
(if @user
[navbar-drop-down {:header [:span [:span.icon [:i.fa.fa-user] ]
[:span (:user/name @user)]] :id ::account}
[:div
[:a {:class "navbar-item"
: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))
[:a {:class "navbar-item" :href (bidi/path-for routes/routes :admin)} "Administration"])
[:hr {:class "navbar-divider"}]
@@ -131,18 +131,6 @@
(when-not is-initial-loading
[: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)
[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]}]
(let [ap @(re-frame/subscribe [::subs/active-page])
client @(re-frame/subscribe [::subs/client])
is-initial-loading @(re-frame/subscribe [::subs/is-initial-loading?])]
client @(re-frame/subscribe [::subs/client])]
[:div
[modal/global-modal]
[navbar ap]

View File

@@ -48,34 +48,9 @@
{:db/id "client"
:client/code "DEF"}]))]
(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)} {} {})]
(is (= [{:client_id client
:count 1}] (-> result first :usage)))))
(is ((into #{} (map :id (:vendors result))) vendor ))))
(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))))))))
)))