Sets up multi date
This commit is contained in:
@@ -73,8 +73,11 @@
|
||||
[:vector {:coerce? true :min 1 }
|
||||
[:entity-map {:pull [:db/id :client/name]}]]
|
||||
]]
|
||||
[:date {:unspecified/fn atime/local-now}
|
||||
clj-date-schema]
|
||||
[:date {:unspecified/fn (fn [] [(atime/local-now)])}
|
||||
[:vector {:coerce? true
|
||||
:decode/string (fn [s] (if (string? s) (str/split s #", ")
|
||||
s))}
|
||||
clj-date-schema]]
|
||||
[:comparison-date {:optional true}
|
||||
[:maybe clj-date-schema]]
|
||||
[:include-comparison {:optional true :default false}
|
||||
@@ -110,7 +113,8 @@
|
||||
(com/link {:hx-get (hu/url investigate-url
|
||||
(cond-> {}
|
||||
(:numeric-code (:filters c)) (assoc :numeric-code (into [] (:numeric-code (:filters c))))
|
||||
(:date-range (:filters c)) (assoc :end-date (atime/unparse-local (:date-range (:filters c))
|
||||
;; TODO
|
||||
#_#_(:date-range (:filters c)) (assoc :end-date (atime/unparse-local (:date-range (:filters c))
|
||||
atime/normal-date))
|
||||
(:client-id (:filters c)) (assoc :client-id (:client-id (:filters c))))
|
||||
)}
|
||||
@@ -219,63 +223,31 @@
|
||||
_ (doseq [client-id client-ids]
|
||||
(assert-can-see-client (:identity request) client-id))
|
||||
|
||||
end-date (coerce/to-date date)
|
||||
comparable-date (coerce/to-date comparison-date)
|
||||
lookup-account (->> client-ids
|
||||
(map (fn build-lookup [client-id]
|
||||
[client-id (build-account-lookup client-id)]))
|
||||
(into {}))
|
||||
data (cond-> {:balance-sheet-accounts (into []
|
||||
(mapcat
|
||||
(fn calculate-accounts [client-id ]
|
||||
(for [
|
||||
[client-id account-id location debits credits balance count] (iol-ion.query/detailed-account-snapshot (dc/db conn) client-id end-date)
|
||||
:let [account ( (or (lookup-account client-id) {}) account-id)]]
|
||||
{:client-id client-id
|
||||
:account-id account-id
|
||||
:location location
|
||||
:debits debits
|
||||
:credits credits
|
||||
:count count
|
||||
:amount balance
|
||||
:account-type (:account_type account)
|
||||
:numeric-code (:numeric_code account)
|
||||
:name (:name account) }))
|
||||
|
||||
client-ids))}
|
||||
(and include-comparison comparison-date)
|
||||
(assoc :comparable-balance-sheet-accounts
|
||||
(into []
|
||||
(mapcat
|
||||
(fn calculate-accounts [client-id ]
|
||||
(for [
|
||||
[client-id account-id location debits credits balance count] (iol-ion.query/detailed-account-snapshot (dc/db conn) client-id comparable-date)
|
||||
:let [account ( (or (lookup-account client-id) {}) account-id)]]
|
||||
{:client-id client-id
|
||||
:account-id account-id
|
||||
:location location
|
||||
:debits debits
|
||||
:credits credits
|
||||
:count count
|
||||
:amount balance
|
||||
:account-type (:account_type account)
|
||||
:numeric-code (:numeric_code account)
|
||||
:name (:name account) }))
|
||||
client-ids)))
|
||||
)
|
||||
data (into []
|
||||
(for [client-id client-ids
|
||||
d date
|
||||
[client-id account-id location debits credits balance count] (iol-ion.query/detailed-account-snapshot (dc/db conn) client-id (coerce/to-date d))
|
||||
:let [account ((or (lookup-account client-id) {}) account-id)]]
|
||||
{:client-id client-id
|
||||
:account-id account-id
|
||||
:location location
|
||||
:debits debits
|
||||
:credits credits
|
||||
:count count
|
||||
:amount balance
|
||||
:account-type (:account_type account)
|
||||
:numeric-code (:numeric_code account)
|
||||
:name (:name account)
|
||||
:period (coerce/to-date d)}))
|
||||
args (assoc (:query-params request)
|
||||
:periods (filter identity (cond-> [date]
|
||||
include-comparison (conj comparison-date))))
|
||||
:periods (map coerce/to-date (filter identity date)))
|
||||
_ (println "ARGS ARE" args)
|
||||
clients (pull-many (dc/db conn) [:client/code :client/name :db/id] client-ids)
|
||||
|
||||
data (concat (->> (:balance-sheet-accounts data)
|
||||
(map (fn [b]
|
||||
(assoc b
|
||||
:period (:date args)))))
|
||||
(->> (:comparable-balance-sheet-accounts data)
|
||||
(map (fn [b]
|
||||
(assoc b
|
||||
:period (:comparison-date args))))))
|
||||
|
||||
pnl-data (l-reports/->PNLData args data (by :db/id :client/code clients))
|
||||
report (l-reports/summarize-balance-sheet pnl-data) ]
|
||||
(alog/info ::balance-sheet :params args)
|
||||
@@ -298,7 +270,7 @@
|
||||
(list
|
||||
[:div.text-2xl.font-bold.text-gray-600 (str "Balance Sheet - " (str/join ", " (map :client/name client))) ]
|
||||
(table {:widths (cond-> (into [30 ] (repeat 13 client-count))
|
||||
(:include-comparison (:args data)) (into (repeat 13 (* 2 client-count))))
|
||||
(> (count date) 1) (into (repeat 13 (* 2 client-count (dec (count date))))))
|
||||
:investigate-url (bidi.bidi/path-for ssr-routes/only-routes ::route/investigate)
|
||||
:table report
|
||||
:warning (not-empty (str/join "\n " (filter not-empty [warning (:warning report)])))} ))))])
|
||||
@@ -330,11 +302,9 @@
|
||||
(fc/with-field :date
|
||||
(com/validated-inline-field {:label "Date"
|
||||
:errors (fc/field-errors)}
|
||||
(com/date-input {:placeholder "12/21/2020"
|
||||
(com/multi-date-input {:placeholder "12/21/2020"
|
||||
:name (fc/field-name)
|
||||
:value (some->
|
||||
(or (fc/field-value) (t/now))
|
||||
(atime/unparse-local atime/normal-date))})))
|
||||
:value (fc/field-value)})))
|
||||
(fc/with-field :include-comparison
|
||||
(com/toggle {:x-model "comparison" :name (fc/field-name) :checked (boolean (fc/field-value))} "Compare"))
|
||||
[:div (hx/alpine-appear {:x-show "comparison"})
|
||||
|
||||
Reference in New Issue
Block a user