adds total.
This commit is contained in:
@@ -1,12 +1,8 @@
|
|||||||
(ns auto-ap.datomic.invoices
|
(ns auto-ap.datomic.invoices
|
||||||
(:require [datomic.api :as d]
|
(: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.graphql.utils :refer [limited-clients]]
|
||||||
[auto-ap.parse :as parse]
|
|
||||||
[clj-time.coerce :as c]
|
|
||||||
[clojure.set :refer [rename-keys]]
|
[clojure.set :refer [rename-keys]]
|
||||||
[clojure.string :as str]
|
|
||||||
[clojure.tools.logging :as log]
|
|
||||||
[clj-time.coerce :as coerce]
|
[clj-time.coerce :as coerce]
|
||||||
[auto-ap.time-utils :refer [next-dom]]
|
[auto-ap.time-utils :refer [next-dom]]
|
||||||
[clj-time.core :as time]
|
[clj-time.core :as time]
|
||||||
@@ -174,23 +170,39 @@
|
|||||||
:in ['$ '[?id ...]]
|
:in ['$ '[?id ...]]
|
||||||
:where ['[?id :invoice/outstanding-balance ?o]]
|
:where ['[?id :invoice/outstanding-balance ?o]]
|
||||||
}
|
}
|
||||||
:args [(d/db (d/connect uri))
|
:args [(d/db conn)
|
||||||
ids]})
|
ids]})
|
||||||
(map last)
|
(map last)
|
||||||
(reduce
|
(reduce
|
||||||
+
|
+
|
||||||
0.0)))
|
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]
|
(defn get-graphql [args]
|
||||||
|
|
||||||
(let [db (d/db (d/connect uri))
|
(let [db (d/db (d/connect uri))
|
||||||
{ids-to-retrieve :ids matching-count :count} (raw-graphql-ids db args)
|
{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))
|
[(->> (graphql-results ids-to-retrieve db args))
|
||||||
matching-count
|
matching-count
|
||||||
outstanding]))
|
outstanding
|
||||||
|
total-amount]))
|
||||||
|
|
||||||
(defn get-by-id [id]
|
(defn get-by-id [id]
|
||||||
(-> (d/db (d/connect uri))
|
(-> (d/db (d/connect uri))
|
||||||
|
|||||||
@@ -30,13 +30,14 @@
|
|||||||
(defn get-invoice-page [context args _]
|
(defn get-invoice-page [context args _]
|
||||||
|
|
||||||
(let [args (assoc args :id (:id context))
|
(let [args (assoc args :id (:id context))
|
||||||
[invoices invoice-count outstanding] (-> args
|
[invoices invoice-count outstanding total-amount] (-> args
|
||||||
(assoc :id (:id context))
|
(assoc :id (:id context))
|
||||||
(<-graphql)
|
(<-graphql)
|
||||||
(update :status enum->keyword "invoice-status")
|
(update :status enum->keyword "invoice-status")
|
||||||
(d-invoices/get-graphql))]
|
(d-invoices/get-graphql))]
|
||||||
[{:invoices (mapv #(->graphql % (:id context)) invoices)
|
[{:invoices (mapv #(->graphql % (:id context)) invoices)
|
||||||
:outstanding outstanding
|
:outstanding outstanding
|
||||||
|
:total_amount total-amount
|
||||||
:total invoice-count
|
:total invoice-count
|
||||||
:count (count invoices)
|
:count (count invoices)
|
||||||
:start (:start args 0)
|
:start (:start args 0)
|
||||||
@@ -307,6 +308,7 @@
|
|||||||
|
|
||||||
:invoice_page {:fields {:invoices {:type '(list :invoice)}
|
:invoice_page {:fields {:invoices {:type '(list :invoice)}
|
||||||
:outstanding {:type :money}
|
:outstanding {:type :money}
|
||||||
|
:total_amount {:type :money}
|
||||||
:count {:type 'Int}
|
:count {:type 'Int}
|
||||||
:total {:type 'Int}
|
:total {:type 'Int}
|
||||||
:start {:type 'Int}
|
:start {:type 'Int}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
[:payments [:amount :id [:payment [:id :status :amount :s3_url :check_number
|
[:payments [:amount :id [:payment [:id :status :amount :s3_url :check_number
|
||||||
[:transaction [:post_date]]]]]]]]
|
[:transaction [:post_date]]]]]]]]
|
||||||
:outstanding
|
:outstanding
|
||||||
|
:total_amount
|
||||||
:total
|
:total
|
||||||
:start
|
:start
|
||||||
:end]]]})
|
:end]]]})
|
||||||
@@ -254,7 +255,8 @@
|
|||||||
:column-count (if selected-client 8 9)}
|
:column-count (if selected-client 8 9)}
|
||||||
[grid/controls data
|
[grid/controls data
|
||||||
[:div.level-item
|
[:div.level-item
|
||||||
"Outstanding " (nf (:outstanding data))]]
|
"Outstanding " (nf (:outstanding data))
|
||||||
|
" Total " (nf (:total-amount data))]]
|
||||||
(for [invoices invoice-groups]
|
(for [invoices invoice-groups]
|
||||||
^{:key (or (:id (first invoices)) "init")}
|
^{:key (or (:id (first invoices)) "init")}
|
||||||
[grid/table {:fullwidth true}
|
[grid/table {:fullwidth true}
|
||||||
|
|||||||
Reference in New Issue
Block a user