adds total.

This commit is contained in:
2022-02-07 19:06:52 -08:00
parent 4ad0e13c27
commit 24cc03ccd2
3 changed files with 30 additions and 14 deletions

View File

@@ -1,12 +1,8 @@
(ns auto-ap.datomic.invoices
(:require [datomic.api :as d]
[auto-ap.datomic :refer [uri remove-nils merge-query apply-pagination apply-sort-3 add-sorter-fields]]
[auto-ap.datomic :refer [uri merge-query apply-pagination apply-sort-3 add-sorter-fields conn]]
[auto-ap.graphql.utils :refer [limited-clients]]
[auto-ap.parse :as parse]
[clj-time.coerce :as c]
[clojure.set :refer [rename-keys]]
[clojure.string :as str]
[clojure.tools.logging :as log]
[clj-time.coerce :as coerce]
[auto-ap.time-utils :refer [next-dom]]
[clj-time.core :as time]
@@ -174,23 +170,39 @@
:in ['$ '[?id ...]]
:where ['[?id :invoice/outstanding-balance ?o]]
}
:args [(d/db (d/connect uri))
:args [(d/db conn)
ids]})
(map last)
(reduce
+
0.0)))
(defn sum-total-amount [ids]
(->>
(d/query {:query {:find ['?id '?o]
:in ['$ '[?id ...]]
:where ['[?id :invoice/total ?o]]
}
:args [(d/db conn)
ids]})
(map last)
(reduce
+
0.0)))
(defn get-graphql [args]
(let [db (d/db (d/connect uri))
{ids-to-retrieve :ids matching-count :count} (raw-graphql-ids db args)
outstanding (sum-outstanding ids-to-retrieve)]
outstanding (sum-outstanding ids-to-retrieve)
total-amount (sum-total-amount ids-to-retrieve)]
[(->> (graphql-results ids-to-retrieve db args))
matching-count
outstanding]))
outstanding
total-amount]))
(defn get-by-id [id]
(-> (d/db (d/connect uri))

View File

@@ -30,13 +30,14 @@
(defn get-invoice-page [context args _]
(let [args (assoc args :id (:id context))
[invoices invoice-count outstanding] (-> args
(assoc :id (:id context))
(<-graphql)
(update :status enum->keyword "invoice-status")
(d-invoices/get-graphql))]
[invoices invoice-count outstanding total-amount] (-> args
(assoc :id (:id context))
(<-graphql)
(update :status enum->keyword "invoice-status")
(d-invoices/get-graphql))]
[{:invoices (mapv #(->graphql % (:id context)) invoices)
:outstanding outstanding
:total_amount total-amount
:total invoice-count
:count (count invoices)
:start (:start args 0)
@@ -307,6 +308,7 @@
:invoice_page {:fields {:invoices {:type '(list :invoice)}
:outstanding {:type :money}
:total_amount {:type :money}
:count {:type 'Int}
:total {:type 'Int}
:start {:type 'Int}

View File

@@ -53,6 +53,7 @@
[:payments [:amount :id [:payment [:id :status :amount :s3_url :check_number
[:transaction [:post_date]]]]]]]]
:outstanding
:total_amount
:total
:start
:end]]]})
@@ -254,7 +255,8 @@
:column-count (if selected-client 8 9)}
[grid/controls data
[:div.level-item
"Outstanding " (nf (:outstanding data))]]
"Outstanding " (nf (:outstanding data))
" Total " (nf (:total-amount data))]]
(for [invoices invoice-groups]
^{:key (or (:id (first invoices)) "init")}
[grid/table {:fullwidth true}