shows expected deposit totals.

This commit is contained in:
2022-07-04 07:55:10 -07:00
parent 2d5b8eded4
commit be58bcd4a3
6 changed files with 353 additions and 42 deletions

View File

@@ -2,7 +2,8 @@
(:require [auto-ap.datomic :refer [add-sorter-fields apply-pagination apply-sort-3 merge-query conn]]
[auto-ap.graphql.utils :refer [limited-clients]]
[clj-time.coerce :as c]
[datomic.api :as d]))
[datomic.api :as d]
[clj-time.core :as t]))
(defn <-datomic [result]
@@ -97,7 +98,24 @@
payments (->> ids
(map results)
(map first)
(mapv <-datomic))]
(mapv <-datomic)
(map (fn get-totals [ed]
(assoc ed :totals
(->> (d/q '[:find ?d4 (count ?c) (sum ?a)
:in $ ?ed
:where [?ed :expected-deposit/charges ?c]
[?c :charge/total ?a]
[?o :sales-order/charges ?c]
[?o :sales-order/date ?d]
[(clj-time.coerce/from-date ?d) ?d2]
[(auto-ap.time/localize ?d2) ?d3]
[(clj-time.coerce/to-local-date ?d3) ?d4]]
(d/db conn)
(:db/id ed))
(map (fn [[date count amount]]
{:date (c/to-date-time date)
:count count
:amount amount})))))))]
payments))
(defn get-graphql [args]

View File

@@ -27,15 +27,19 @@
(result->page expected-deposits expected-deposit-count :expected_deposits args)))
(def objects
{:expected_deposit {:fields {:id {:type :id}
:location {:type 'String}
:external_id {:type 'String}
:total {:type :money}
:transaction {:type :transaction}
:status {:type :expected_deposit_status}
:fee {:type :money}
:client {:type :client}
:date {:type 'String}}}
{:expected_deposit_total {:fields {:date {:type :iso_date}
:count {:type 'Int}
:amount {:type :money}}}
:expected_deposit {:fields {:id {:type :id}
:location {:type 'String}
:external_id {:type 'String}
:total {:type :money}
:transaction {:type :transaction}
:status {:type :expected_deposit_status}
:fee {:type :money}
:client {:type :client}
:date {:type 'String}
:totals {:type '(list :expected_deposit_total)}}}
:expected_deposit_page {:fields {:expected_deposits {:type '(list :expected_deposit)}
:count {:type 'Int}