Sets up multi date
This commit is contained in:
@@ -128,6 +128,17 @@ initDatepicker = function(elem) {
|
||||
|
||||
}
|
||||
|
||||
initMultiDatepicker = function(elem) {
|
||||
const modalParent = elem.closest('#modal-content');
|
||||
if (modalParent) {
|
||||
return new Datepicker(elem, {format: "mm/dd/yyyy", autohide: false, container: "#modal-content .modal-card", maxNumberOfDates: 12, dateDelimiter: ", "});
|
||||
} else {
|
||||
return new Datepicker(elem, {format: "mm/dd/yyyy", autohide: false, maxNumberOfDates: 12, dateDelimiter: ", "});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
destroyDatepicker = function(dp) {
|
||||
try {
|
||||
dp.destroy()
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
(def money-input inputs/money-input-)
|
||||
(def int-input inputs/int-input-)
|
||||
(def date-input inputs/date-input-)
|
||||
(def multi-date-input inputs/multi-date-input-)
|
||||
(def hidden inputs/hidden-)
|
||||
(def select inputs/select-)
|
||||
(def typeahead inputs/typeahead-)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
(ns auto-ap.ssr.components.inputs
|
||||
(:require [auto-ap.ssr.components.tags :as tags]
|
||||
(:require
|
||||
[auto-ap.ssr.components.tags :as tags]
|
||||
[auto-ap.ssr.hiccup-helper :as hh]
|
||||
[auto-ap.ssr.hx :as hx :refer [js-fn]]
|
||||
[auto-ap.ssr.svg :as svg]
|
||||
[auto-ap.time :as atime]
|
||||
[clojure.string :as str]
|
||||
[hiccup2.core :as hiccup]))
|
||||
|
||||
@@ -349,6 +351,28 @@
|
||||
(update :class #(str % (use-size size) " w-full"))
|
||||
(dissoc :size))]])
|
||||
|
||||
(defn multi-date-input- [{:keys [size] :as params}]
|
||||
(let [value (str/join ", "
|
||||
(for [v (:value params)
|
||||
:when v]
|
||||
(some-> v (atime/unparse-local atime/normal-date))))]
|
||||
(println "MY VALUE IS" value)
|
||||
[:div.shrink {:x-data (hx/json {:value value})}
|
||||
[:input
|
||||
(-> params
|
||||
(update :class (fnil hh/add-class "") default-input-classes)
|
||||
(assoc :x-modelable "value")
|
||||
(assoc :type "text")
|
||||
(assoc :x-data (hx/json {:dp nil}) )
|
||||
(assoc :value value)
|
||||
(assoc :x-init " dp = initMultiDatepicker($el);")
|
||||
(assoc "@htmx:before-history-save" "destroyDatepicker(dp)" )
|
||||
(assoc "@htmx:before-cleanup-element" "destroyDatepicker(dp)" )
|
||||
(assoc "@change" "value = $event.target.value;")
|
||||
(assoc "hx-on" (hiccup/raw "changeDate: htmx.trigger(this, \"change\") "))
|
||||
(update :class #(str % (use-size size) " w-full"))
|
||||
(dissoc :size))]]))
|
||||
|
||||
|
||||
|
||||
(defn field-errors- [{:keys [source key]} & rest]
|
||||
|
||||
@@ -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,18 +223,15 @@
|
||||
_ (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)]]
|
||||
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
|
||||
@@ -240,42 +241,13 @@
|
||||
: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)))
|
||||
)
|
||||
: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"})
|
||||
|
||||
@@ -794,7 +794,7 @@
|
||||
(for [client (set (map :client-id (:data pnl-data))) ]
|
||||
(cond-> [{:value (str (-> pnl-data :client-codes (get client)))}]
|
||||
|
||||
(:include-comparison (:args pnl-data))
|
||||
(> (count (:periods (:args pnl-data))) 1)
|
||||
(into ["" ""]))))))
|
||||
true
|
||||
(conj (into [{:value "Period Ending"}]
|
||||
@@ -803,7 +803,7 @@
|
||||
(for [client (set (map :client-id (:data pnl-data))) ]
|
||||
(cond-> [{:value (date->str (:date (:args pnl-data)))}]
|
||||
|
||||
(:include-comparison (:args pnl-data))
|
||||
(> (count (:periods (:args pnl-data))) 1)
|
||||
(into [{:value (date->str (:comparison-date (:args pnl-data)))}
|
||||
{:value "+/-"}]))))))))
|
||||
|
||||
@@ -889,7 +889,7 @@
|
||||
(negate #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable}))
|
||||
pnl-datas)
|
||||
"Retained Earnings")))
|
||||
table (if (:include-comparison (:args pnl-data))
|
||||
table (if (> (count (:periods pnl-data)) 1)
|
||||
(append-deltas table)
|
||||
table)]
|
||||
{:warning (warning-message pnl-data)
|
||||
|
||||
Reference in New Issue
Block a user