adding day of month.

This commit is contained in:
Bryce Covert
2019-05-09 23:32:43 -07:00
parent 0520e2f0f8
commit 16a3b14844
8 changed files with 95 additions and 21 deletions

View File

@@ -12,7 +12,7 @@
[clj-time.core :as time]
[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 []
(d/create-database uri))

View File

@@ -341,6 +341,15 @@
:db/cardinality :db.cardinality/one
: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

View File

@@ -191,6 +191,8 @@
:description {:type 'String}
:amount_lte {:type 'String}
:amount_gte {:type 'String}
:dom_lte {:type 'Int}
:dom_gte {:type 'Int}
:vendor {:type :vendor}}}
:invoice_payment
@@ -512,7 +514,9 @@
:bank_account_id {:type :id}
:client_id {:type :id}
:amount_lte {:type :money}
:amount_gte {:type :money}}}
:amount_gte {:type :money}
:dom_lte {:type 'Int}
:dom_gte {:type 'Int}}}
:edit_account
{:fields {:id {:type :id}

View File

@@ -4,7 +4,8 @@
[datomic.api :as d]
[auto-ap.datomic :refer [remove-nils uri merge-query]]
[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]
(let [args (assoc args :id (:id context))
@@ -31,7 +32,8 @@
(defn tr [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
(cond-> {:query {:find ['(pull ?e [* {:transaction/client [:client/name]
@@ -69,6 +71,24 @@
'[(<= ?ta ?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
(merge-query {:query {:in ['?client-id]
:where ['[?e :transaction/client ?client-id]]}