much better sorting.
This commit is contained in:
@@ -779,30 +779,23 @@
|
||||
(update-in [:query :where] into (get-in query-part-2 [:query :where]))
|
||||
(update-in [:args] into (get-in query-part-2 [:args]))))
|
||||
|
||||
(defn add-sorter-fields [q sort-map args]
|
||||
(reduce
|
||||
(fn [q {:keys [sort-key asc]}]
|
||||
(merge-query q
|
||||
{:query {:find [(symbol (str "?sort-" sort-key))]
|
||||
:where (sort-map
|
||||
sort-key
|
||||
(println "Warning, trying to sort by unsupported field" sort-key))}}))
|
||||
q
|
||||
(:sort args)))
|
||||
|
||||
|
||||
(defn add-sorter-field [q sort-map args]
|
||||
(merge-query q
|
||||
{:query {:find ['?sorter]
|
||||
:where (sort-map
|
||||
(:sort-by args)
|
||||
(println "Warning, trying to sort by unsupported field" (:sort-by args)))}}))
|
||||
|
||||
(defn apply-sort [args sort-fn results ]
|
||||
(cond->> results
|
||||
sort-fn (sort-by sort-fn)
|
||||
(= (:asc args) false) (reverse)))
|
||||
|
||||
(defn apply-sort-2 [args default-sort results ]
|
||||
(let [sort-bys (if (:sort-by args)
|
||||
(conj (seq default-sort) (if (:asc args)
|
||||
:asc
|
||||
:desc))
|
||||
(seq default-sort))
|
||||
(defn apply-sort-3 [args results]
|
||||
(let [sort-bys (or (:sort args) [])
|
||||
comparator (fn [xs ys]
|
||||
(or (->> (map vector sort-bys xs ys)
|
||||
(map (fn [[asc x y]]
|
||||
(if (= :asc asc)
|
||||
(map (fn [[{:keys [asc]} x y]]
|
||||
(if asc
|
||||
(compare x y)
|
||||
(compare y x))))
|
||||
(drop-while #(= 0 %))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(ns auto-ap.datomic.checks
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri merge-query apply-sort-2 apply-pagination add-sorter-field]]
|
||||
[auto-ap.datomic :refer [uri merge-query apply-sort-3 apply-pagination add-sorter-fields]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[auto-ap.utils :refer [dollars=]]
|
||||
[clojure.set :refer [rename-keys]]
|
||||
@@ -28,16 +28,16 @@
|
||||
:in ['$]
|
||||
:where []}
|
||||
:args [db]}
|
||||
(:sort-by args) (add-sorter-field {"client" ['[?e :payment/client ?c]
|
||||
'[?c :client/name ?sorter]]
|
||||
"vendor" ['[?e :payment/vendor ?v]
|
||||
'[?v :vendor/name ?sorter]]
|
||||
"bank-account" ['[?e :payment/bank-account ?c]
|
||||
'[?c :bank-account/name ?sorter]]
|
||||
"check-number" ['[?e :payment/check-number ?sorter]]
|
||||
"date" ['[?e :payment/date ?sorter]]
|
||||
"amount" ['[?e :payment/amount ?sorter]]
|
||||
"status" ['[?e :payment/status ?sorter]]}
|
||||
(:sort args) (add-sorter-fields {"client" ['[?e :payment/client ?c]
|
||||
'[?c :client/name ?sort-client]]
|
||||
"vendor" ['[?e :payment/vendor ?v]
|
||||
'[?v :vendor/name ?sort-vendor]]
|
||||
"bank-account" ['[?e :payment/bank-account ?ba]
|
||||
'[?ba :bank-account/name ?sort-bank-account]]
|
||||
"check-number" ['[?e :payment/check-number ?sort-check-number]]
|
||||
"date" ['[?e :payment/date ?sort-date]]
|
||||
"amount" ['[?e :payment/amount ?sort-amount]]
|
||||
"status" ['[?e :payment/status ?sort-status]]}
|
||||
args)
|
||||
|
||||
(limited-clients (:id args))
|
||||
@@ -113,7 +113,7 @@
|
||||
|
||||
(cond->> query
|
||||
true (d/query)
|
||||
true (apply-sort-2 args [:desc :asc])
|
||||
true (apply-sort-3 args)
|
||||
true (apply-pagination args))))
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(ns auto-ap.datomic.invoices
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri remove-nils merge-query apply-pagination apply-sort-2 add-sorter-field]]
|
||||
[auto-ap.datomic :refer [uri remove-nils merge-query apply-pagination apply-sort-3 add-sorter-fields]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[auto-ap.parse :as parse]
|
||||
[clj-time.coerce :as c]
|
||||
@@ -28,17 +28,19 @@
|
||||
:in ['$]
|
||||
:where ['[?e :invoice/invoice-number]]}
|
||||
:args [(d/db (d/connect uri))]}
|
||||
(:sort-by args) (add-sorter-field {"client" ['[?e :invoice/client ?c]
|
||||
'[?c :client/name ?sorter]]
|
||||
"vendor" ['[?e :invoice/vendor ?v]
|
||||
'[?v :vendor/name ?sorter]]
|
||||
"description-original" ['[?e :transaction/description-original ?sorter]]
|
||||
"date" ['[?e :invoice/date ?sorter]]
|
||||
"due" ['[?e :invoice/due ?sorter]]
|
||||
"invoice-number" ['[?e :invoice/invoice-number ?sorter]]
|
||||
"total" ['[?e :invoice/total ?sorter]]
|
||||
"outstanding" ['[?e :invoice/outstanding-balance ?sorter]]}
|
||||
args)
|
||||
(:sort args) (add-sorter-fields {"client" ['[?e :invoice/client ?c]
|
||||
'[?c :client/name ?sort-client]]
|
||||
"vendor" ['[?e :invoice/vendor ?v]
|
||||
'[?v :vendor/name ?sort-vendor]]
|
||||
"description-original" ['[?e :transaction/description-original ?sort-description-original]]
|
||||
"location" ['[?e :invoice/expense-accounts ?iea]
|
||||
'[?iea :invoice-expense-account/location ?sort-location]]
|
||||
"date" ['[?e :invoice/date ?sort-date]]
|
||||
"due" ['[?e :invoice/due ?sort-due]]
|
||||
"invoice-number" ['[?e :invoice/invoice-number ?sort-invoice-number]]
|
||||
"total" ['[?e :invoice/total ?sort-total]]
|
||||
"outstanding-balance" ['[?e :invoice/outstanding-balance ?sort-outstanding-balance]]}
|
||||
args)
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :invoice/client ?xx]]}
|
||||
@@ -94,7 +96,7 @@
|
||||
(merge-query {:query {:find ['?base-date '?e]
|
||||
:where ['[?e :invoice/date ?base-date]]}}) )
|
||||
(d/query)
|
||||
(apply-sort-2 args [:asc :asc])
|
||||
(apply-sort-3 args)
|
||||
(apply-pagination args)))
|
||||
|
||||
|
||||
|
||||
@@ -1,22 +1,11 @@
|
||||
(ns auto-ap.datomic.ledger
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.graphql.utils :refer [->graphql limited-clients]]
|
||||
[auto-ap.datomic :refer [merge-query apply-sort-2 apply-sort apply-pagination add-sorter-field]]
|
||||
[auto-ap.datomic :refer [merge-query apply-sort-3 apply-pagination add-sorter-fields]]
|
||||
[auto-ap.datomic :refer [uri]]
|
||||
[clj-time.coerce :as c]
|
||||
[clj-time.core :as time]))
|
||||
|
||||
(defn sort-fn [sort-by]
|
||||
(cond
|
||||
(= "client" sort-by)
|
||||
#(-> % :journal-entry/client :client/name)
|
||||
|
||||
(= "vendor" sort-by)
|
||||
#(-> % :journal-entry/vendor :vendor/name)
|
||||
|
||||
:else
|
||||
(keyword "journal-entry" sort-by)))
|
||||
|
||||
(defn raw-graphql-ids [db args]
|
||||
|
||||
(let [query (cond-> {:query {:find []
|
||||
@@ -24,12 +13,12 @@
|
||||
:where []}
|
||||
:args [db]}
|
||||
|
||||
(:sort-by args) (add-sorter-field {"client" ['[?e :journal-entry/client ?c]
|
||||
'[?c :client/name ?sorter]]
|
||||
"date" ['[?e :journal-entry/date ?sorter]]
|
||||
"vendor" ['[?e :journal-entry/vendor ?sorter]]
|
||||
"amount" ['[?e :journal-entry/amount ?sorter]]}
|
||||
args)
|
||||
(:sort args) (add-sorter-fields {"client" ['[?e :journal-entry/client ?c]
|
||||
'[?c :client/name ?sort-client]]
|
||||
"date" ['[?e :journal-entry/date ?sort-date]]
|
||||
"vendor" ['[?e :journal-entry/vendor ?sort-vendor]]
|
||||
"amount" ['[?e :journal-entry/amount ?sort-amount]]}
|
||||
args)
|
||||
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
@@ -85,7 +74,7 @@
|
||||
(merge-query {:query {:find ['?base-date '?e] :where ['[?e :journal-entry/date ?base-date]]}}))]
|
||||
(->> query
|
||||
(d/query)
|
||||
(apply-sort-2 args [:desc :asc])
|
||||
(apply-sort-3 args)
|
||||
(apply-pagination args))))
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(ns auto-ap.datomic.transaction-rules
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri merge-query apply-sort-2 apply-pagination add-sorter-field]]
|
||||
[auto-ap.datomic :refer [uri merge-query apply-sort-3 apply-pagination add-sorter-fields]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[clojure.set :refer [rename-keys]]
|
||||
[clj-time.coerce :as c]))
|
||||
@@ -24,18 +24,17 @@
|
||||
:in ['$]
|
||||
:where []}
|
||||
:args [db]}
|
||||
(:sort-by args) (add-sorter-field {"client" ['[?e :transaction-rule/client ?c]
|
||||
'[?c :client/name ?sorter]]
|
||||
(:sort args) (add-sorter-fields {"client" ['[?e :transaction-rule/client ?c]
|
||||
'[?c :client/name ?sort-client]]
|
||||
|
||||
"yodlee-merchant" ['[?e :transaction-rule/yodlee-merchant ?c]
|
||||
'[?c :yodlee-merchant/name ?sorter]]
|
||||
"bank-account" ['[?e :transaction-rule/bank-account ?c]
|
||||
'[?c :bank-account/name ?sorter]]
|
||||
"description" ['[?e :transaction-rule/description ?sorter]]
|
||||
"note" ['[?e :transaction-rule/note ?sorter]]
|
||||
"amount-lte" ['[?e :transaction-rule/amount-lte ?sorter]]
|
||||
"amount-gte" ['[?e :transaction-rule/amount-gte ?sorter]]
|
||||
}
|
||||
"yodlee-merchant" ['[?e :transaction-rule/yodlee-merchant ?ym]
|
||||
'[?ym :yodlee-merchant/name ?sort-yodlee-merchant]]
|
||||
"bank-account" ['[?e :transaction-rule/bank-account ?ba]
|
||||
'[?ba :bank-account/name ?sort-bank-account]]
|
||||
"description" ['[?e :transaction-rule/description ?sort-description]]
|
||||
"note" ['[?e :transaction-rule/note ?sort-note]]
|
||||
"amount-lte" ['[?e :transaction-rule/amount-lte ?sort-amount-lte]]
|
||||
"amount-gte" ['[?e :transaction-rule/amount-gte ?sort-amount-gte]]}
|
||||
args)
|
||||
|
||||
(limited-clients (:id args))
|
||||
@@ -55,7 +54,7 @@
|
||||
|
||||
(cond->> query
|
||||
true (d/query)
|
||||
true (apply-sort-2 args [:asc])
|
||||
true (apply-sort-3 args)
|
||||
true (apply-pagination args))))
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(ns auto-ap.datomic.transactions
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri merge-query apply-sort-2 apply-sort apply-pagination add-sorter-field]]
|
||||
[auto-ap.datomic :refer [uri merge-query apply-sort-3 apply-pagination add-sorter-fields]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[clj-time.coerce :as c]
|
||||
[clj-time.coerce :as coerce]))
|
||||
@@ -25,25 +25,25 @@
|
||||
:where []}
|
||||
:args [db]}
|
||||
|
||||
(:sort-by args) (add-sorter-field {"client" ['[?e :transaction/client ?c]
|
||||
'[?c :client/name ?sorter]]
|
||||
"account" ['[?e :transaction/date]
|
||||
'(or-join [?e ?sorter]
|
||||
(and [?e :transaction/account ?c]
|
||||
[?c :account/name ?sorter])
|
||||
(and
|
||||
(not [?e :transaction/account])
|
||||
[(ground "") ?sorter]))]
|
||||
"description-original" ['[?e :transaction/description-original ?sorter]]
|
||||
"date" ['[?e :transaction/date ?sorter]]
|
||||
"vendor" ['(or-join [?e ?sorter]
|
||||
(and [(missing? $ ?e :transaction/vendor)]
|
||||
[?e :transaction/description-original ?sorter])
|
||||
(and [?e :transaction/vendor ?v]
|
||||
[?v :vendor/name ?sorter]))]
|
||||
"amount" ['[?e :transaction/amount ?sorter]]
|
||||
"status" ['[?e :transaction/status ?sorter]]}
|
||||
args)
|
||||
(:sort args) (add-sorter-fields {"client" ['[?e :transaction/client ?c]
|
||||
'[?c :client/name ?sort-client]]
|
||||
"account" ['[?e :transaction/date]
|
||||
'(or-join [?e ?sort-account]
|
||||
(and [?e :transaction/account ?c]
|
||||
[?c :account/name ?sort-account])
|
||||
(and
|
||||
(not [?e :transaction/account])
|
||||
[(ground "") ?sort-account]))]
|
||||
"description-original" ['[?e :transaction/description-original ?sort-description-original]]
|
||||
"date" ['[?e :transaction/date ?sort-date]]
|
||||
"vendor" ['(or-join [?e ?sort-vendor]
|
||||
(and [(missing? $ ?e :transaction/vendor)]
|
||||
[?e :transaction/description-original ?sort-vendor])
|
||||
(and [?e :transaction/vendor ?v]
|
||||
[?v :vendor/name ?sort-vendor]))]
|
||||
"amount" ['[?e :transaction/amount ?sort-amount]]
|
||||
"status" ['[?e :transaction/status ?sort-status]]}
|
||||
args)
|
||||
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
@@ -118,7 +118,7 @@
|
||||
'[?e :transaction/date ?base-date]]}}))]
|
||||
(cond->> query
|
||||
true (d/query)
|
||||
true (apply-sort-2 args [:desc :asc])
|
||||
true (apply-sort-3 args)
|
||||
true (apply-pagination args)))))
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
|
||||
@@ -283,6 +283,8 @@
|
||||
:client {:type :client}}}
|
||||
|
||||
|
||||
|
||||
|
||||
:invoice_page {:fields {:invoices {:type '(list :invoice)}
|
||||
:count {:type 'Int}
|
||||
:total {:type 'Int}
|
||||
@@ -375,6 +377,8 @@
|
||||
:to_date {:type :iso_date}}
|
||||
:resolve :get-profit-and-loss}
|
||||
|
||||
|
||||
|
||||
:invoice_page {:type '(list :invoice_page)
|
||||
:args {:import_status {:type 'String}
|
||||
:date_range {:type :date_range}
|
||||
@@ -383,8 +387,7 @@
|
||||
:vendor_id {:type :id}
|
||||
:invoice_number_like {:type 'String}
|
||||
:start {:type 'Int}
|
||||
:sort_by {:type 'String}
|
||||
:asc {:type 'Boolean}}
|
||||
:sort {:type '(list :sort_item)}}
|
||||
|
||||
:resolve :get-invoice-page}
|
||||
|
||||
@@ -419,8 +422,7 @@
|
||||
:amount_gte {:type :money}
|
||||
:description {:type 'String}
|
||||
:start {:type 'Int}
|
||||
:sort_by {:type 'String}
|
||||
:asc {:type 'Boolean}
|
||||
:sort {:type '(list :sort_item)}
|
||||
:approval_status {:type :transaction_approval_status}}
|
||||
|
||||
:resolve :get-transaction-page}
|
||||
@@ -428,7 +430,7 @@
|
||||
:transaction_rule_page {:type :transaction_rule_page
|
||||
:args {:client_id {:type :id}
|
||||
:start {:type 'Int}
|
||||
:sort_by {:type 'String}
|
||||
:sort {:type '(list :sort_item)}
|
||||
:asc {:type 'Boolean}}
|
||||
:resolve :get-transaction-rule-page}
|
||||
|
||||
@@ -441,8 +443,7 @@
|
||||
:from_numeric_code {:type 'Int}
|
||||
:to_numeric_code {:type 'Int}
|
||||
:start {:type 'Int}
|
||||
:sort_by {:type 'String}
|
||||
:asc {:type 'Boolean}}
|
||||
:sort {:type '(list :sort_item)}}
|
||||
|
||||
:resolve :get-ledger-page}
|
||||
|
||||
@@ -452,8 +453,7 @@
|
||||
:date_range {:type :date_range}
|
||||
:check_number_like {:type 'String}
|
||||
:start {:type 'Int}
|
||||
:sort_by {:type 'String}
|
||||
:asc {:type 'Boolean}}
|
||||
:sort {:type '(list :sort_item)}}
|
||||
|
||||
:resolve :get-payment-page}
|
||||
|
||||
@@ -467,6 +467,10 @@
|
||||
|
||||
:input-objects
|
||||
{
|
||||
:sort_item
|
||||
{:fields {:sort_key {:type 'String}
|
||||
:sort_name {:type 'String}
|
||||
:asc {:type 'Boolean}}}
|
||||
:invoice_payment_amount {:fields {:invoice_id {:type :id}
|
||||
:amount {:type 'Float}}}
|
||||
:edit_location_match {:fields {:location {:type 'String}
|
||||
@@ -652,8 +656,7 @@
|
||||
:amount_gte {:type :money}
|
||||
:description {:type 'String}
|
||||
:start {:type 'Int}
|
||||
:sort_by {:type 'String}
|
||||
:asc {:type 'Boolean}
|
||||
:sort {:type '(list :sort_item)}
|
||||
:approval_status {:type :transaction_approval_status}}
|
||||
|
||||
:resolve :mutation/unapprove-transactions}
|
||||
|
||||
@@ -134,12 +134,10 @@
|
||||
retractions (map (fn [[_ e]] [:db/retractEntity [:journal-entry/original-entity e]]) affected-entities)]
|
||||
|
||||
(when (seq retractions)
|
||||
(println "Retracting " retractions)
|
||||
@(d/transact (d/connect uri) retractions))
|
||||
|
||||
|
||||
(doseq [d-tx d-txs]
|
||||
(clojure.pprint/pprint d-tx)
|
||||
#_(println "updating general-ledger " d-tx)
|
||||
@(d/transact (d/connect uri) [d-tx]))))
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
[clj-time.coerce :as c]
|
||||
[clj-time.core :as t]))
|
||||
|
||||
(defn exclude-until-date [client end]
|
||||
(defn mark-until-date [client end]
|
||||
(let [conn (d/connect uri)]
|
||||
(doseq [p (->>
|
||||
(d/query {:query {:find '[?e]
|
||||
@@ -47,5 +47,22 @@
|
||||
@(d/transact conn p)
|
||||
(println "process 100"))))
|
||||
|
||||
(defn unapprove-all []
|
||||
(let [conn (d/connect uri)]
|
||||
(doseq [p (->>
|
||||
(d/query {:query {:find '[?e]
|
||||
:in '[$ ]
|
||||
:where ['[?e :transaction/date ?d ]]}
|
||||
:args [(d/db conn)]})
|
||||
(mapv first)
|
||||
(mapv (fn [i]
|
||||
{:db/id i
|
||||
:transaction/approval-status :transaction-approval-status/unapproved}))
|
||||
(partition-all 100))]
|
||||
|
||||
@(d/transact conn p)
|
||||
(println "process 100"))))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.utils :refer [date->str dispatch-event delayed-dispatch nf]]
|
||||
[auto-ap.views.components.paginator :refer [paginator]]
|
||||
[auto-ap.views.components.sort-by-list :refer [sort-by-list]]
|
||||
[auto-ap.views.components.sorter :refer [sorted-column]]
|
||||
[auto-ap.views.components.dropdown :refer [drop-down drop-down-contents]]
|
||||
[auto-ap.events :as events]
|
||||
@@ -44,8 +45,9 @@
|
||||
|
||||
(defn query [params]
|
||||
{:venia/queries [[:invoice_page
|
||||
(assoc params
|
||||
:client-id (:id @(re-frame/subscribe [::subs/client])))
|
||||
(-> params
|
||||
(assoc
|
||||
:client-id (:id @(re-frame/subscribe [::subs/client]))))
|
||||
[[:invoices [:id :total :outstanding-balance :invoice-number :date :due :status :client-identifier
|
||||
[:vendor [:name :id]]
|
||||
[:expense_accounts [:amount :id :location
|
||||
@@ -64,19 +66,22 @@
|
||||
opc (fn [p]
|
||||
(on-params-change (merge @params p)))]
|
||||
(fn [{:keys [id invoice-page status on-params-change vendors checked params]}]
|
||||
(let [{:keys [sort-by asc]} @params
|
||||
(let [{:keys [sort asc]} @params
|
||||
{:keys [invoices start end count total]} @invoice-page
|
||||
visible-checks @(re-frame/subscribe [::visible-checks])
|
||||
visible-expense-accounts @(re-frame/subscribe [::visible-expense-accounts])
|
||||
selected-client @(re-frame/subscribe [::subs/client])
|
||||
percentage-size (if selected-client "%50%" "33%")
|
||||
]
|
||||
percentage-size (if selected-client "%50%" "33%")]
|
||||
[:div
|
||||
|
||||
|
||||
[paginator {:start start :end end :count count :total total
|
||||
:on-change (fn [p ]
|
||||
(on-params-change (merge @params p) ))}]
|
||||
[:div.level
|
||||
[:div.level-left
|
||||
[:div.level-item
|
||||
[paginator {:start start :end end :count count :total total
|
||||
:on-change (fn [p ]
|
||||
(on-params-change (merge @params p) ))}]]
|
||||
[:div.level-item
|
||||
[sort-by-list {:sort sort
|
||||
:on-change opc}]]]]
|
||||
[:table.table.is-fullwidth
|
||||
[:thead
|
||||
[:tr
|
||||
@@ -86,53 +91,61 @@
|
||||
(when-not selected-client
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-name "Client"
|
||||
:sort-key "client"
|
||||
:sort-by sort-by
|
||||
:sort sort
|
||||
:asc asc}
|
||||
"Client"])
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-name "Vendor"
|
||||
:sort-key "vendor"
|
||||
:sort-by sort-by
|
||||
:sort sort
|
||||
:asc asc}
|
||||
"Vendor"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-name "Invoice Number"
|
||||
:sort-key "invoice-number"
|
||||
:sort-by sort-by
|
||||
:sort sort
|
||||
:asc asc}
|
||||
"Invoice #"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-name "Date"
|
||||
:sort-key "date"
|
||||
:sort-by sort-by
|
||||
:sort sort
|
||||
:asc asc}
|
||||
"Date"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-name "Due"
|
||||
:sort-key "due"
|
||||
:sort-by sort-by
|
||||
:sort sort
|
||||
:asc asc}
|
||||
"Due"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "5em" :cursor "pointer"}
|
||||
:sort-name "Location"
|
||||
:sort-key "location"
|
||||
:sort-by sort-by
|
||||
:sort sort
|
||||
:asc asc}
|
||||
"Loc"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-name "Total"
|
||||
:sort-key "total"
|
||||
:class "has-text-right"
|
||||
:sort-by sort-by
|
||||
:sort sort
|
||||
:asc asc}
|
||||
"Amount"]
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "10em" :cursor "pointer"}
|
||||
:sort-name "Outstanding"
|
||||
:sort-key "outstanding-balance"
|
||||
:class "has-text-right"
|
||||
:sort-by sort-by
|
||||
:sort sort
|
||||
:asc asc}
|
||||
"Outstanding"]
|
||||
|
||||
|
||||
21
src/cljs/auto_ap/views/components/sort_by_list.cljs
Normal file
21
src/cljs/auto_ap/views/components/sort_by_list.cljs
Normal file
@@ -0,0 +1,21 @@
|
||||
(ns auto-ap.views.components.sort-by-list
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.utils :refer [date->str]]
|
||||
[reagent.core :as reagent]
|
||||
[clojure.string :as str]
|
||||
[cljs-time.format :as format]))
|
||||
|
||||
(defn sort-by-list [{:keys [sort on-change]}]
|
||||
[:div.field.is-grouped.is-grouped-multiline
|
||||
(for [{:keys [sort-key sort-name asc]} sort]
|
||||
^{:key sort-key}
|
||||
[:div.control
|
||||
[:div.tags.has-addons
|
||||
[:div.tag.is-medium [:span.icon (if asc
|
||||
[:i.fa.fa-sort-up]
|
||||
[:i.fa.fa-sort-down])]
|
||||
[:span sort-name] ]
|
||||
[:a.tag.is-medium.is-delete {:on-click (fn []
|
||||
(on-change {:sort (filter #(not= sort-key (:sort-key %)) sort)}))}]]])])
|
||||
|
||||
@@ -5,30 +5,45 @@
|
||||
[reagent.core :as reagent]
|
||||
[clojure.string :as str]
|
||||
[cljs-time.format :as format]))
|
||||
(defn toggle-sort-by [params key]
|
||||
(defn toggle-sort-by [params sort-key sort-name asc]
|
||||
(let [[found? sort] (reduce
|
||||
(fn [[found? sort] sort-item]
|
||||
(if (= sort-key (:sort-key sort-item))
|
||||
[true (conj sort
|
||||
(update sort-item :asc not))]
|
||||
[found? (conj sort sort-item)]))
|
||||
[false []]
|
||||
(:sort params))
|
||||
sort (if found?
|
||||
sort
|
||||
(conj sort {:sort-key sort-key
|
||||
:sort-name sort-name
|
||||
:asc true}))]
|
||||
|
||||
(-> params
|
||||
(assoc :sort-by key)
|
||||
(update :asc not)))
|
||||
(-> params
|
||||
(assoc :sort sort))))
|
||||
|
||||
(defn sort-icon [which sort-by asc]
|
||||
(cond
|
||||
(and (= sort-by which) asc)
|
||||
[:span.icon
|
||||
[:i.fa.fa-sort-up]]
|
||||
(defn sort-icon [which sort asc]
|
||||
(let [sort-item (first (filter #(= which (:sort-key %)) sort))]
|
||||
(cond
|
||||
(and sort-item (:asc sort-item))
|
||||
[:span.icon
|
||||
[:i.fa.fa-sort-up]]
|
||||
|
||||
(and (= sort-by which) (not asc))
|
||||
[:span.icon
|
||||
[:i.fa.fa-sort-down]]
|
||||
(and sort-item (not (:asc sort-item)))
|
||||
[:span.icon
|
||||
[:i.fa.fa-sort-down]]
|
||||
|
||||
:else
|
||||
[:span.icon
|
||||
[:i.fa.fa-sort]]))
|
||||
:else
|
||||
[:span.icon
|
||||
[:i.fa.fa-sort]])))
|
||||
|
||||
(defn sorted-column [{:keys [on-sort sort-key sort-by asc style class]} & rest]
|
||||
|
||||
[:th {:on-click (fn [e] (on-sort (toggle-sort-by {:asc asc} sort-key)))
|
||||
|
||||
(defn sorted-column [{:keys [on-sort sort-key sort sort-name asc style class]} & rest]
|
||||
[:th {:on-click (fn [e]
|
||||
(on-sort
|
||||
(toggle-sort-by {:sort sort} sort-key sort-name asc)))
|
||||
:style style
|
||||
:class class}
|
||||
rest
|
||||
(sort-icon sort-key sort-by asc)])
|
||||
(sort-icon sort-key sort asc)])
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
[auto-ap.views.utils :refer [dispatch-event ->$ with-user]]
|
||||
[auto-ap.views.pages.admin.rules.form :as form]
|
||||
[auto-ap.views.components.paginator :refer [paginator]]
|
||||
[auto-ap.views.components.sort-by-list :refer [sort-by-list]]
|
||||
[auto-ap.views.pages.admin.rules.results-modal :as results-modal]
|
||||
[auto-ap.views.components.sorter :refer [sorted-column]]
|
||||
[re-frame.core :as re-frame]))
|
||||
@@ -36,58 +37,62 @@
|
||||
(let [opc (fn [p]
|
||||
(on-params-change (merge @params p )))]
|
||||
(fn [{:keys [id rule-page on-params-change params status]}]
|
||||
(let [{:keys [sort-by asc]} @params
|
||||
(let [{:keys [sort asc]} @params
|
||||
{:keys [transaction-rules start end count total]} @rule-page
|
||||
selected-client @(re-frame/subscribe [::subs/client])]
|
||||
[:div
|
||||
[paginator {:start start :end end :count count :total total
|
||||
:on-change (fn [p ]
|
||||
(on-params-change (merge @params p)))}]
|
||||
[:div.level
|
||||
[:div.level-left
|
||||
[:div.level-item
|
||||
[paginator {:start start :end end :count count :total total
|
||||
:on-change (fn [p ]
|
||||
(on-params-change (merge @params p)))}]]
|
||||
[:div.level-item
|
||||
[sort-by-list {:sort sort
|
||||
:on-change opc}]]]]
|
||||
[:table.table.is-fullwidth.compact
|
||||
[:thead
|
||||
[:tr
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "25%" :cursor "pointer"}
|
||||
:sort-key "client"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Client"
|
||||
:sort sort}
|
||||
"Client"]
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "25%" :cursor "pointer"}
|
||||
:sort-key "bank-account"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Bank Account"
|
||||
:sort sort}
|
||||
"Bank Account"]
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "25%" :cursor "pointer"}
|
||||
:sort-key "description"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Description"
|
||||
:sort sort}
|
||||
"Description"]
|
||||
|
||||
#_[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cukjsor "pointer"}
|
||||
:class "has-text-right"
|
||||
:sort-key "amount-gte"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort sort}
|
||||
"Amount"]
|
||||
[:th.has-text-right {:style {:width "12em"}} "Amount"]
|
||||
#_[sorted-column {:on-sort opc
|
||||
:class "has-text-right"
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "amount-lte"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort sort}
|
||||
"<="]
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "25%" :cursor "pointer"}
|
||||
:sort-key "note"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Note"
|
||||
:sort sort}
|
||||
"Note"]
|
||||
[:th {:style {:width "9em"}}
|
||||
]]]
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
[auto-ap.views.components.layouts :refer [side-bar-layout]]
|
||||
[auto-ap.views.components.typeahead :refer [typeahead]]
|
||||
[auto-ap.views.components.paginator :refer [paginator]]
|
||||
[auto-ap.views.components.sort-by-list :refer [sort-by-list]]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.views.utils :refer [dispatch-event date->str bind-field nf with-user]]
|
||||
[auto-ap.utils :refer [by]]
|
||||
@@ -141,64 +142,70 @@
|
||||
|
||||
(on-params-change (merge @params p)))]
|
||||
(fn [{:keys [id payment-page status on-params-change vendors checked]}]
|
||||
(let [{:keys [sort-by asc]} @params
|
||||
(let [{:keys [sort]} @params
|
||||
{:keys [payments start end count total]} @payment-page
|
||||
selected-client @(re-frame/subscribe [::subs/client])
|
||||
percentage-size (if selected-client "50%" "33%")]
|
||||
[:div
|
||||
[paginator {:start start :end end :count count :total total
|
||||
:on-change (fn [p ]
|
||||
(on-params-change (merge @params p)))}]
|
||||
[:div.level
|
||||
[:div.level-left
|
||||
[:div.level-item
|
||||
[paginator {:start start :end end :count count :total total
|
||||
:on-change (fn [p ]
|
||||
(on-params-change (merge @params p)))}]]
|
||||
[:div.level-item
|
||||
[sort-by-list {:sort sort
|
||||
:on-change opc}]]]]
|
||||
|
||||
[:table.table.is-fullwidth
|
||||
[:thead
|
||||
[:tr
|
||||
|
||||
|
||||
(when-not selected-client
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "client"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Client"
|
||||
:sort sort}
|
||||
"Client"])
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "vendor"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Vendor"
|
||||
:sort sort}
|
||||
"Vendor"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "vendor"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-key "bank-account"
|
||||
:sort-name "Bank Account"
|
||||
:sort sort}
|
||||
"Bank Account"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "check-number"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Check #"
|
||||
:sort sort}
|
||||
"Check #"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "date"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Date"
|
||||
:sort sort}
|
||||
"Date"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:class "has-text-right"
|
||||
:sort-key "amount"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Amount"
|
||||
:sort sort}
|
||||
"Amount"]
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "status"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Status"
|
||||
:sort sort}
|
||||
"Status"]
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
(:require [auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.paginator :refer [paginator]]
|
||||
[auto-ap.views.components.sorter :refer [sorted-column]]
|
||||
[auto-ap.views.components.sort-by-list :refer [sort-by-list]]
|
||||
[auto-ap.views.utils :refer [date->str dispatch-event nf]]
|
||||
[goog.string :as gstring]
|
||||
[re-frame.core :as re-frame]))
|
||||
@@ -11,14 +12,20 @@
|
||||
(on-params-change (merge @params p )))]
|
||||
(fn [{:keys [id ledger-page status on-params-change vendors checked status?]
|
||||
:or {status? true}}]
|
||||
(let [{:keys [sort-by asc]} @params
|
||||
(let [{:keys [sort]} @params
|
||||
{:keys [journal-entries start end count total]} @ledger-page
|
||||
selected-client @(re-frame/subscribe [::subs/client])
|
||||
percentage-size (if selected-client "25%" "33%")]
|
||||
[:div
|
||||
[paginator {:start start :end end :count count :total total
|
||||
:on-change (fn [p ]
|
||||
(on-params-change (merge @params p)))}]
|
||||
[:div.level
|
||||
[:div.level-left
|
||||
[:div.level-item
|
||||
[paginator {:start start :end end :count count :total total
|
||||
:on-change (fn [p ]
|
||||
(on-params-change (merge @params p)))}]]
|
||||
[:div.level-item
|
||||
[sort-by-list {:sort sort
|
||||
:on-change opc}]]]]
|
||||
|
||||
|
||||
[:table.table.is-fullwidth.compact
|
||||
@@ -28,25 +35,22 @@
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "client"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Client"
|
||||
:sort sort}
|
||||
"Client"])
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "vendor"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Vendor"
|
||||
:sort sort}
|
||||
"Vendor"]
|
||||
|
||||
|
||||
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "date"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Date"
|
||||
:sort sort}
|
||||
"Date"]
|
||||
[:th
|
||||
{:style {:width percentage-size }}
|
||||
@@ -54,17 +58,17 @@
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "amount"
|
||||
:sort-name "Amount"
|
||||
:class "has-text-right"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort sort}
|
||||
"Debit"]
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "amount"
|
||||
:sort-name "Amount"
|
||||
:class "has-text-right"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort sort}
|
||||
"Credit"]
|
||||
|
||||
|
||||
@@ -73,8 +77,8 @@
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "status"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Status"
|
||||
:sort sort}
|
||||
"Status"])]]
|
||||
[:tbody
|
||||
(if (:loading @status)
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
[auto-ap.views.components.layouts :refer [appearing-side-bar side-bar-layout]]
|
||||
[auto-ap.views.components.modal :refer [action-modal]]
|
||||
[auto-ap.views.components.paginator :refer [paginator]]
|
||||
[auto-ap.views.components.sort-by-list :refer [sort-by-list]]
|
||||
[auto-ap.views.components.sorter :refer [sorted-column]]
|
||||
[auto-ap.views.pages.transactions.form :as edit]
|
||||
[auto-ap.views.pages.transactions.table :as table]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
(ns auto-ap.views.pages.transactions.table
|
||||
(:require [auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.paginator :refer [paginator]]
|
||||
[auto-ap.views.components.sort-by-list :refer [sort-by-list]]
|
||||
[auto-ap.views.components.sorter :refer [sorted-column]]
|
||||
[auto-ap.views.components.dropdown :refer [drop-down drop-down-contents]]
|
||||
[auto-ap.views.pages.transactions.form :as edit]
|
||||
@@ -39,14 +40,21 @@
|
||||
(let [opc (fn [p]
|
||||
(on-params-change (merge @params p )))]
|
||||
(fn [{:keys [id transaction-page status on-params-change vendors checked]}]
|
||||
(let [{:keys [sort-by asc]} @params
|
||||
(let [{:keys [sort]} @params
|
||||
{:keys [transactions start end count total]} @transaction-page
|
||||
selected-client @(re-frame/subscribe [::subs/client])
|
||||
percentage-size (if selected-client "25%" "33%")]
|
||||
[:div
|
||||
[paginator {:start start :end end :count count :total total
|
||||
:on-change (fn [p ]
|
||||
(on-params-change (merge @params p)))}]
|
||||
[:div.level
|
||||
[:div.level-left
|
||||
[:div.level-item
|
||||
[paginator {:start start :end end :count count :total total
|
||||
:on-change (fn [p ]
|
||||
(on-params-change (merge @params p)))}]]
|
||||
[:div.level-item
|
||||
[sort-by-list {:sort sort
|
||||
:on-change opc}]]]]
|
||||
|
||||
|
||||
[:table.table.is-fullwidth
|
||||
[:thead
|
||||
@@ -55,36 +63,36 @@
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "client"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Client"
|
||||
:sort sort}
|
||||
"Client"])
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "vendor"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Vendor"
|
||||
:sort sort}
|
||||
"Vendor"]
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "date"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Date"
|
||||
:sort sort}
|
||||
"Date"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "amount"
|
||||
:sort-name "Amount"
|
||||
:class "has-text-right"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort sort}
|
||||
"Amount"]
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "status"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
:sort-name "Status"
|
||||
:sort sort}
|
||||
"Status"]
|
||||
[:th {:width percentage-size} "Bank account"]
|
||||
[:th {:style {:width "14em"}} "" ]]]
|
||||
|
||||
Reference in New Issue
Block a user