adding day of month.
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
[clj-time.core :as time]
|
[clj-time.core :as time]
|
||||||
[clj-time.coerce :as coerce]))
|
[clj-time.coerce :as coerce]))
|
||||||
|
|
||||||
(def uri "datomic:sql://invoices?jdbc:postgresql://database:5432/datomic?user=datomic&password=datomic")
|
(def uri "datomic:sql://invoices-backup?jdbc:postgresql://database:5432/datomic?user=datomic&password=datomic")
|
||||||
|
|
||||||
(defn create-database []
|
(defn create-database []
|
||||||
(d/create-database uri))
|
(d/create-database uri))
|
||||||
|
|||||||
@@ -341,6 +341,15 @@
|
|||||||
:db/cardinality :db.cardinality/one
|
:db/cardinality :db.cardinality/one
|
||||||
:db/doc "Amount has to be greater than or equal to this"}
|
:db/doc "Amount has to be greater than or equal to this"}
|
||||||
|
|
||||||
|
{:db/ident :transaction-rule/dom-lte
|
||||||
|
:db/valueType :db.type/long
|
||||||
|
:db/cardinality :db.cardinality/one
|
||||||
|
:db/doc "Day of month has to be less than or equal to this"}
|
||||||
|
|
||||||
|
{:db/ident :transaction-rule/dom-gte
|
||||||
|
:db/valueType :db.type/long
|
||||||
|
:db/cardinality :db.cardinality/one
|
||||||
|
:db/doc "Day of month has to be greater than or equal to this"}
|
||||||
]])
|
]])
|
||||||
|
|
||||||
(def add-credit-bank-account
|
(def add-credit-bank-account
|
||||||
|
|||||||
@@ -191,6 +191,8 @@
|
|||||||
:description {:type 'String}
|
:description {:type 'String}
|
||||||
:amount_lte {:type 'String}
|
:amount_lte {:type 'String}
|
||||||
:amount_gte {:type 'String}
|
:amount_gte {:type 'String}
|
||||||
|
:dom_lte {:type 'Int}
|
||||||
|
:dom_gte {:type 'Int}
|
||||||
:vendor {:type :vendor}}}
|
:vendor {:type :vendor}}}
|
||||||
|
|
||||||
:invoice_payment
|
:invoice_payment
|
||||||
@@ -512,7 +514,9 @@
|
|||||||
:bank_account_id {:type :id}
|
:bank_account_id {:type :id}
|
||||||
:client_id {:type :id}
|
:client_id {:type :id}
|
||||||
:amount_lte {:type :money}
|
:amount_lte {:type :money}
|
||||||
:amount_gte {:type :money}}}
|
:amount_gte {:type :money}
|
||||||
|
:dom_lte {:type 'Int}
|
||||||
|
:dom_gte {:type 'Int}}}
|
||||||
|
|
||||||
:edit_account
|
:edit_account
|
||||||
{:fields {:id {:type :id}
|
{:fields {:id {:type :id}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
[datomic.api :as d]
|
[datomic.api :as d]
|
||||||
[auto-ap.datomic :refer [remove-nils uri merge-query]]
|
[auto-ap.datomic :refer [remove-nils uri merge-query]]
|
||||||
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page]]
|
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page]]
|
||||||
[clj-time.coerce :as c]))
|
[clj-time.coerce :as c])
|
||||||
|
(:import [java.time.temporal ChronoField]))
|
||||||
|
|
||||||
(defn get-transaction-rule-page [context args value]
|
(defn get-transaction-rule-page [context args value]
|
||||||
(let [args (assoc args :id (:id context))
|
(let [args (assoc args :id (:id context))
|
||||||
@@ -31,7 +32,8 @@
|
|||||||
(defn tr [z x]
|
(defn tr [z x]
|
||||||
(re-find (re-pattern z) x))
|
(re-find (re-pattern z) x))
|
||||||
|
|
||||||
(defn test-transaction-rule [{:keys [id]} {{:keys [description note client_id bank_account_id amount_lte amount_gte ]} :transaction_rule :as z} value]
|
(defn test-transaction-rule [{:keys [id]} {{:keys [description note client_id bank_account_id amount_lte amount_gte dom_lte dom_gte]} :transaction_rule :as z} value]
|
||||||
|
(prn z)
|
||||||
(->>
|
(->>
|
||||||
(d/query
|
(d/query
|
||||||
(cond-> {:query {:find ['(pull ?e [* {:transaction/client [:client/name]
|
(cond-> {:query {:find ['(pull ?e [* {:transaction/client [:client/name]
|
||||||
@@ -69,6 +71,24 @@
|
|||||||
'[(<= ?ta ?amount-lte)]]}
|
'[(<= ?ta ?amount-lte)]]}
|
||||||
:args [amount_lte]})
|
:args [amount_lte]})
|
||||||
|
|
||||||
|
dom_lte
|
||||||
|
(merge-query {:query {:in ['?dom-lte]
|
||||||
|
:where ['[?e :transaction/date ?transaction-date]
|
||||||
|
'[(.toInstant ^java.util.Date ?transaction-date ) ?transaction-instant]
|
||||||
|
'[(.atZone ^java.time.Instant ?transaction-instant (java.time.ZoneId/of "US/Pacific")) ?transaction-local]
|
||||||
|
'[(.get ?transaction-local java.time.temporal.ChronoField/DAY_OF_MONTH) ?dom]
|
||||||
|
'[(<= ?dom ?dom-lte)]]}
|
||||||
|
:args [dom_lte]})
|
||||||
|
|
||||||
|
dom_gte
|
||||||
|
(merge-query {:query {:in ['?dom-gte]
|
||||||
|
:where ['[?e :transaction/date ?transaction-date]
|
||||||
|
'[(.toInstant ^java.util.Date ?transaction-date ) ?transaction-instant]
|
||||||
|
'[(.atZone ^java.time.Instant ?transaction-instant (java.time.ZoneId/of "US/Pacific")) ?transaction-local]
|
||||||
|
'[(.get ?transaction-local java.time.temporal.ChronoField/DAY_OF_MONTH) ?dom]
|
||||||
|
'[(>= ?dom ?dom-gte)]]}
|
||||||
|
:args [dom_gte]})
|
||||||
|
|
||||||
client_id
|
client_id
|
||||||
(merge-query {:query {:in ['?client-id]
|
(merge-query {:query {:in ['?client-id]
|
||||||
:where ['[?e :transaction/client ?client-id]]}
|
:where ['[?e :transaction/client ?client-id]]}
|
||||||
|
|||||||
@@ -5,7 +5,9 @@
|
|||||||
(s/def ::description (s/nilable string?))
|
(s/def ::description (s/nilable string?))
|
||||||
(s/def ::amount-gte (s/nilable double?))
|
(s/def ::amount-gte (s/nilable double?))
|
||||||
(s/def ::amount-lte (s/nilable double?))
|
(s/def ::amount-lte (s/nilable double?))
|
||||||
|
(s/def ::dom-gte (s/nilable int?))
|
||||||
|
(s/def ::dom-lte (s/nilable int?))
|
||||||
(s/def ::note (s/nilable string?))
|
(s/def ::note (s/nilable string?))
|
||||||
(s/def ::bank-account (s/nilable map?))
|
(s/def ::bank-account (s/nilable map?))
|
||||||
|
|
||||||
(s/def ::transaction-rule (s/keys :req-un [::client ::description ::amount-gte ::amount-lte ::note ::bank-account]))
|
(s/def ::transaction-rule (s/keys :req-un [::client ::description ::amount-gte ::amount-lte ::dom-gte ::dom-lte ::note ::bank-account]))
|
||||||
|
|||||||
@@ -37,6 +37,8 @@
|
|||||||
:description
|
:description
|
||||||
:amount-lte
|
:amount-lte
|
||||||
:amount-gte
|
:amount-gte
|
||||||
|
:dom-lte
|
||||||
|
:dom-gte
|
||||||
:note])
|
:note])
|
||||||
(assoc :client-id (:id (:client data)))
|
(assoc :client-id (:id (:client data)))
|
||||||
(assoc :bank-account-id (:id (:bank-account data))))}
|
(assoc :bank-account-id (:id (:bank-account data))))}
|
||||||
@@ -54,6 +56,8 @@
|
|||||||
:description
|
:description
|
||||||
:amount-lte
|
:amount-lte
|
||||||
:amount-gte
|
:amount-gte
|
||||||
|
:dom-lte
|
||||||
|
:dom-gte
|
||||||
:note])
|
:note])
|
||||||
(assoc :client-id (:id (:client data)))
|
(assoc :client-id (:id (:client data)))
|
||||||
(assoc :bank-account-id (:id (:bank-account data))))}
|
(assoc :bank-account-id (:id (:bank-account data))))}
|
||||||
@@ -80,8 +84,7 @@
|
|||||||
:bank-account nil
|
:bank-account nil
|
||||||
:note nil
|
:note nil
|
||||||
:amount-lte nil
|
:amount-lte nil
|
||||||
:amount-gte nil
|
:amount-gte nil)))))
|
||||||
)))))
|
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::editing
|
::editing
|
||||||
@@ -156,14 +159,13 @@
|
|||||||
accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])]
|
accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])]
|
||||||
^{:key id}
|
^{:key id}
|
||||||
[form (assoc params :title "New Transaction Rule")
|
[form (assoc params :title "New Transaction Rule")
|
||||||
(when-not @(re-frame/subscribe [::subs/client])
|
[field "Client"
|
||||||
[field "Client"
|
[typeahead-entity {:matches @(re-frame/subscribe [::subs/clients])
|
||||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/clients])
|
:match->text :name
|
||||||
:match->text :name
|
:type "typeahead-entity"
|
||||||
:type "typeahead-entity"
|
:auto-focus (if @(re-frame/subscribe [::subs/client]) false true)
|
||||||
:auto-focus (if @(re-frame/subscribe [::subs/client]) false true)
|
:field [:client]
|
||||||
:field [:client]
|
:spec ::entity/client}]]
|
||||||
:spec ::entity/client}]])
|
|
||||||
|
|
||||||
[field "Bank account"
|
[field "Bank account"
|
||||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/real-bank-accounts-for-client (:client data)])
|
[typeahead-entity {:matches @(re-frame/subscribe [::subs/real-bank-accounts-for-client (:client data)])
|
||||||
@@ -197,6 +199,27 @@
|
|||||||
:spec ::entity/amount-lte
|
:spec ::entity/amount-lte
|
||||||
:step "0.01"}]]]]]]
|
:step "0.01"}]]]]]]
|
||||||
|
|
||||||
|
[:div.field
|
||||||
|
[:p.help "Day of Month"]
|
||||||
|
[:div.control
|
||||||
|
[:div.columns
|
||||||
|
[:div.column
|
||||||
|
[raw-field
|
||||||
|
[:input.input {:type "number"
|
||||||
|
:placeholder ">="
|
||||||
|
:field [:dom-gte]
|
||||||
|
:spec ::entity/dom-gte
|
||||||
|
:precision 0
|
||||||
|
:step "1"}]]]
|
||||||
|
[:div.column
|
||||||
|
[raw-field
|
||||||
|
[:input.input {:type "number"
|
||||||
|
:placeholder "<="
|
||||||
|
:field [:dom-lte]
|
||||||
|
:spec ::entity/dom-lte
|
||||||
|
:precision 0
|
||||||
|
:step "1"}]]]]]]
|
||||||
|
|
||||||
[field "Note"
|
[field "Note"
|
||||||
[:input.input {:type "text"
|
[:input.input {:type "text"
|
||||||
:field [:note]
|
:field [:note]
|
||||||
|
|||||||
@@ -41,14 +41,15 @@
|
|||||||
:asc asc}
|
:asc asc}
|
||||||
"Description"]
|
"Description"]
|
||||||
|
|
||||||
[sorted-column {:on-sort opc
|
#_[sorted-column {:on-sort opc
|
||||||
:style {:width "8em" :cursor "pointer"}
|
:style {:width "8em" :cursor "pointer"}
|
||||||
:class "has-text-right"
|
:class "has-text-right"
|
||||||
:sort-key "amount-gte"
|
:sort-key "amount-gte"
|
||||||
:sort-by sort-by
|
:sort-by sort-by
|
||||||
:asc asc}
|
:asc asc}
|
||||||
">="]
|
"Amount"]
|
||||||
[sorted-column {:on-sort opc
|
[:th.has-text-right {:style {:width "12em"}} "Amount"]
|
||||||
|
#_[sorted-column {:on-sort opc
|
||||||
:class "has-text-right"
|
:class "has-text-right"
|
||||||
:style {:width "8em" :cursor "pointer"}
|
:style {:width "8em" :cursor "pointer"}
|
||||||
:sort-key "amount-lte"
|
:sort-key "amount-lte"
|
||||||
@@ -75,8 +76,18 @@
|
|||||||
[:td (:name client)]
|
[:td (:name client)]
|
||||||
[:td (:name bank-account)]
|
[:td (:name bank-account)]
|
||||||
[:td description]
|
[:td description]
|
||||||
[:td.has-text-right (some-> amount-gte ->$) ]
|
[:td.has-text-right
|
||||||
[:td.has-text-right (some-> amount-lte ->$)]
|
(cond (and amount-gte amount-lte)
|
||||||
|
(str (->$ amount-gte) " - " (->$ amount-lte))
|
||||||
|
|
||||||
|
amount-gte
|
||||||
|
(str ">=" (->$ amount-gte))
|
||||||
|
|
||||||
|
amount-lte
|
||||||
|
(str "<=" (->$ amount-lte))
|
||||||
|
|
||||||
|
:else
|
||||||
|
"")]
|
||||||
[:td note]
|
[:td note]
|
||||||
[:td
|
[:td
|
||||||
[:a.button {:on-click (dispatch-event [::form/editing r])} [:span.icon [:i.fa.fa-pencil]]]]]))]]]))))
|
[:a.button {:on-click (dispatch-event [::form/editing r])} [:span.icon [:i.fa.fa-pencil]]]]]))]]]))))
|
||||||
|
|||||||
@@ -201,8 +201,13 @@
|
|||||||
(re-frame/dispatch (-> event
|
(re-frame/dispatch (-> event
|
||||||
(conj field)
|
(conj field)
|
||||||
(conj (let [val (.. e -target -value)]
|
(conj (let [val (.. e -target -value)]
|
||||||
(if (and val (not (str/blank? val)))
|
(cond (and val (not (str/blank? val)))
|
||||||
(js/parseFloat val)
|
(js/parseFloat val)
|
||||||
|
|
||||||
|
(str/blank? val )
|
||||||
|
nil
|
||||||
|
|
||||||
|
:else
|
||||||
val))))))
|
val))))))
|
||||||
:value (get-in subscription field)
|
:value (get-in subscription field)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user