diff --git a/src/clj/auto_ap/datomic/ledger.clj b/src/clj/auto_ap/datomic/ledger.clj index 69ec5729..58f71902 100644 --- a/src/clj/auto_ap/datomic/ledger.clj +++ b/src/clj/auto_ap/datomic/ledger.clj @@ -59,12 +59,29 @@ '[(<= ?date ?end-date)]]} :args [(c/to-date (:end (:date-range args)))]}) + (or (:from-numeric-code args) + (:to-numeric-code args) + (:bank-account-id args) + (not-empty (:location args))) + (merge-query {:query {:where ['[?e :journal-entry/line-items ?li]]}}) + + (or (:from-numeric-code args) + (:to-numeric-code args)) + (merge-query {:query {:in [] + :where ['[?li :journal-entry-line/account ?a] + '(or-join [?c] + [?a :account/numeric-code ?c] + (and [?a :bank-account/type :bank-account-type/check] + [?c 11100]) + (and [?a :bank-account/type :bank-account-type/cash] + [?c 11100]) + (and [?a :bank-account/type :bank-account-type/credit] + [?c 28000]))]} + :args []}) + (:from-numeric-code args) (merge-query {:query {:in ['?from-numeric-code] - :where ['[?e :journal-entry/line-items ?li] - '[?li :journal-entry-line/account ?a] - '[?a :account/numeric-code ?c] - '[(>= ?c ?from-numeric-code)]]} + :where ['[(>= ?c ?from-numeric-code)]]} :args [(:from-numeric-code args)]}) (:amount-gte args) @@ -81,8 +98,7 @@ (:bank-account-id args) (merge-query {:query {:in ['?a] - :where ['[?e :journal-entry/line-items ?li] - '[?li :journal-entry-line/account ?a]]} + :where ['[?li :journal-entry-line/account ?a]]} :args [(:bank-account-id args)]}) (:account-id args) @@ -93,17 +109,14 @@ (:to-numeric-code args) (merge-query {:query {:in ['?to-numeric-code] - :where ['[?e :journal-entry/line-items ?li] - '[?li :journal-entry-line/account ?a] - '[?a :account/numeric-code ?c] - '[(<= ?c ?to-numeric-code)]]} + :where ['[(<= ?c ?to-numeric-code)]]} :args [(:to-numeric-code args)]}) (not-empty (:location args)) (merge-query {:query {:in ['?location] - :where ['[?e :journal-entry/line-items ?li] - '[?li :journal-entry-line/location ?location]]} + :where ['[?li :journal-entry-line/location ?location]]} :args [(:location args)]}) + (limited-clients (:id args)) (merge-query {:query {:in ['[?xx ...]] :where ['[?e :journal-entry/client ?xx]]}