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}

View File

@@ -28,8 +28,9 @@
:date-range (:date-range params)
:client-id (:id @(re-frame/subscribe [::subs/client]))}
[[:expected-deposits [:id :total :fee :location :date :status
[:totals [:date :count :amount]]
[:transaction [:id :date]]
[:client [:name :id]]]]
[:client [:name :id]]]]
:total
:start
:end]]]}

View File

@@ -2,24 +2,23 @@
(ns auto-ap.views.pages.pos.expected-deposits.table
(:require
[auto-ap.events :as events]
[auto-ap.routes :as routes]
[auto-ap.subs :as subs]
[auto-ap.views.components.buttons :as buttons]
[auto-ap.views.components.dropdown
:refer [drop-down drop-down-contents]]
[auto-ap.views.components.grid :as grid]
[auto-ap.views.pages.data-page :as data-page]
[auto-ap.views.pages.pos.form :as form]
[auto-ap.views.utils :refer [date->str nf dispatch-event-with-propagation pretty str->date standard]]
[auto-ap.views.components.dropdown
:refer
[drop-down drop-down-contents]]
[auto-ap.views.utils
:refer [date->str dispatch-event-with-propagation nf pretty ->$]]
[bidi.bidi :as bidi]
[cemerick.url :as url]
[re-frame.core :as re-frame]
[auto-ap.routes :as routes]))
[re-frame.core :as re-frame]))
(defn row [{sales-order :sales-order
selected-client :selected-client}]
(let [{:keys [client transaction status location date total fee id]} sales-order]
(let [{:keys [client transaction status location date total fee id totals]} sales-order]
[grid/row {:class (:class sales-order) :id id}
(when-not selected-client
[grid/cell {} (:name client)])
@@ -30,28 +29,39 @@
[grid/cell {:class "has-text-right"} (nf fee )]
[grid/button-cell {}
[:div.buttons
[buttons/fa-icon {:event [::form/editing sales-order] :icon "fa-pencil"}]]
(when transaction
[drop-down {:id [::links id]
:is-right? true
:header [buttons/fa-icon {:class "badge"
:on-click (dispatch-event-with-propagation [::events/toggle-menu [::links id]])
:data-badge (str 1)
:icon "fa-paperclip"}]}
[drop-down-contents
[:div.dropdown-item
[:table.table.grid.compact
[:tbody
(when transaction
[:tr
[:td
"Transaction"]
[:td (some-> transaction :date (date->str pretty))]
[:td
[buttons/fa-icon {:icon "fa-external-link"
:href (str (bidi/path-for routes/routes :transactions )
"?"
(url/map->query {:exact-match-id (:id transaction)}))}]]])]]]]])]]))
[buttons/fa-icon {:event [::form/editing sales-order] :icon "fa-pencil"}]
(when (or transaction
(seq totals))
[drop-down {:id [::links id]
:is-right? true
:header [buttons/fa-icon {:class "badge"
:on-click (dispatch-event-with-propagation [::events/toggle-menu [::links id]])
:data-badge (str 1)
:icon "fa-paperclip"}]}
[drop-down-contents
[:div.dropdown-item
[:table.table.grid.compact
[:tbody
(when transaction
[:tr
[:td
"Transaction"]
[:td (some-> transaction :date (date->str pretty))]
[:td
[buttons/fa-icon {:icon "fa-external-link"
:href (str (bidi/path-for routes/routes :transactions )
"?"
(url/map->query {:exact-match-id (:id transaction)}))}]]])
(when (seq totals)
(into
[:<>]
(for [t totals]
[:tr
[:td
"Sales"]
[:td (some-> t :date (date->str pretty))]
[:td (str (some-> t :count ) " (" (some-> t :amount ->$) ")")
]])))]]]]])]]]))
(defn table [{:keys [data-page]}]
(let [selected-client @(re-frame/subscribe [::subs/client])