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) {
|
destroyDatepicker = function(dp) {
|
||||||
try {
|
try {
|
||||||
dp.destroy()
|
dp.destroy()
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
(def money-input inputs/money-input-)
|
(def money-input inputs/money-input-)
|
||||||
(def int-input inputs/int-input-)
|
(def int-input inputs/int-input-)
|
||||||
(def date-input inputs/date-input-)
|
(def date-input inputs/date-input-)
|
||||||
|
(def multi-date-input inputs/multi-date-input-)
|
||||||
(def hidden inputs/hidden-)
|
(def hidden inputs/hidden-)
|
||||||
(def select inputs/select-)
|
(def select inputs/select-)
|
||||||
(def typeahead inputs/typeahead-)
|
(def typeahead inputs/typeahead-)
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
(ns auto-ap.ssr.components.inputs
|
(ns auto-ap.ssr.components.inputs
|
||||||
(:require [auto-ap.ssr.components.tags :as tags]
|
(:require
|
||||||
[auto-ap.ssr.hiccup-helper :as hh]
|
[auto-ap.ssr.components.tags :as tags]
|
||||||
[auto-ap.ssr.hx :as hx :refer [js-fn]]
|
[auto-ap.ssr.hiccup-helper :as hh]
|
||||||
[auto-ap.ssr.svg :as svg]
|
[auto-ap.ssr.hx :as hx :refer [js-fn]]
|
||||||
[clojure.string :as str]
|
[auto-ap.ssr.svg :as svg]
|
||||||
[hiccup2.core :as hiccup]))
|
[auto-ap.time :as atime]
|
||||||
|
[clojure.string :as str]
|
||||||
|
[hiccup2.core :as hiccup]))
|
||||||
|
|
||||||
|
|
||||||
(def default-input-classes
|
(def default-input-classes
|
||||||
@@ -349,6 +351,28 @@
|
|||||||
(update :class #(str % (use-size size) " w-full"))
|
(update :class #(str % (use-size size) " w-full"))
|
||||||
(dissoc :size))]])
|
(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]
|
(defn field-errors- [{:keys [source key]} & rest]
|
||||||
|
|||||||
@@ -73,8 +73,11 @@
|
|||||||
[:vector {:coerce? true :min 1 }
|
[:vector {:coerce? true :min 1 }
|
||||||
[:entity-map {:pull [:db/id :client/name]}]]
|
[:entity-map {:pull [:db/id :client/name]}]]
|
||||||
]]
|
]]
|
||||||
[:date {:unspecified/fn atime/local-now}
|
[:date {:unspecified/fn (fn [] [(atime/local-now)])}
|
||||||
clj-date-schema]
|
[:vector {:coerce? true
|
||||||
|
:decode/string (fn [s] (if (string? s) (str/split s #", ")
|
||||||
|
s))}
|
||||||
|
clj-date-schema]]
|
||||||
[:comparison-date {:optional true}
|
[:comparison-date {:optional true}
|
||||||
[:maybe clj-date-schema]]
|
[:maybe clj-date-schema]]
|
||||||
[:include-comparison {:optional true :default false}
|
[:include-comparison {:optional true :default false}
|
||||||
@@ -110,7 +113,8 @@
|
|||||||
(com/link {:hx-get (hu/url investigate-url
|
(com/link {:hx-get (hu/url investigate-url
|
||||||
(cond-> {}
|
(cond-> {}
|
||||||
(:numeric-code (:filters c)) (assoc :numeric-code (into [] (:numeric-code (:filters c))))
|
(: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))
|
atime/normal-date))
|
||||||
(:client-id (:filters c)) (assoc :client-id (:client-id (:filters c))))
|
(:client-id (:filters c)) (assoc :client-id (:client-id (:filters c))))
|
||||||
)}
|
)}
|
||||||
@@ -219,63 +223,31 @@
|
|||||||
_ (doseq [client-id client-ids]
|
_ (doseq [client-id client-ids]
|
||||||
(assert-can-see-client (:identity request) client-id))
|
(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
|
lookup-account (->> client-ids
|
||||||
(map (fn build-lookup [client-id]
|
(map (fn build-lookup [client-id]
|
||||||
[client-id (build-account-lookup client-id)]))
|
[client-id (build-account-lookup client-id)]))
|
||||||
(into {}))
|
(into {}))
|
||||||
data (cond-> {:balance-sheet-accounts (into []
|
data (into []
|
||||||
(mapcat
|
(for [client-id client-ids
|
||||||
(fn calculate-accounts [client-id ]
|
d date
|
||||||
(for [
|
[client-id account-id location debits credits balance count] (iol-ion.query/detailed-account-snapshot (dc/db conn) client-id (coerce/to-date d))
|
||||||
[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)]]
|
||||||
:let [account ( (or (lookup-account client-id) {}) account-id)]]
|
{:client-id client-id
|
||||||
{:client-id client-id
|
:account-id account-id
|
||||||
:account-id account-id
|
:location location
|
||||||
:location location
|
:debits debits
|
||||||
:debits debits
|
:credits credits
|
||||||
:credits credits
|
:count count
|
||||||
:count count
|
:amount balance
|
||||||
:amount balance
|
:account-type (:account_type account)
|
||||||
:account-type (:account_type account)
|
:numeric-code (:numeric_code account)
|
||||||
:numeric-code (:numeric_code account)
|
:name (:name account)
|
||||||
:name (:name account) }))
|
:period (coerce/to-date d)}))
|
||||||
|
|
||||||
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)))
|
|
||||||
)
|
|
||||||
args (assoc (:query-params request)
|
args (assoc (:query-params request)
|
||||||
:periods (filter identity (cond-> [date]
|
:periods (map coerce/to-date (filter identity date)))
|
||||||
include-comparison (conj comparison-date))))
|
_ (println "ARGS ARE" args)
|
||||||
clients (pull-many (dc/db conn) [:client/code :client/name :db/id] client-ids)
|
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))
|
pnl-data (l-reports/->PNLData args data (by :db/id :client/code clients))
|
||||||
report (l-reports/summarize-balance-sheet pnl-data) ]
|
report (l-reports/summarize-balance-sheet pnl-data) ]
|
||||||
(alog/info ::balance-sheet :params args)
|
(alog/info ::balance-sheet :params args)
|
||||||
@@ -298,7 +270,7 @@
|
|||||||
(list
|
(list
|
||||||
[:div.text-2xl.font-bold.text-gray-600 (str "Balance Sheet - " (str/join ", " (map :client/name client))) ]
|
[: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))
|
(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)
|
:investigate-url (bidi.bidi/path-for ssr-routes/only-routes ::route/investigate)
|
||||||
:table report
|
:table report
|
||||||
:warning (not-empty (str/join "\n " (filter not-empty [warning (:warning report)])))} ))))])
|
:warning (not-empty (str/join "\n " (filter not-empty [warning (:warning report)])))} ))))])
|
||||||
@@ -330,11 +302,9 @@
|
|||||||
(fc/with-field :date
|
(fc/with-field :date
|
||||||
(com/validated-inline-field {:label "Date"
|
(com/validated-inline-field {:label "Date"
|
||||||
:errors (fc/field-errors)}
|
:errors (fc/field-errors)}
|
||||||
(com/date-input {:placeholder "12/21/2020"
|
(com/multi-date-input {:placeholder "12/21/2020"
|
||||||
:name (fc/field-name)
|
:name (fc/field-name)
|
||||||
:value (some->
|
:value (fc/field-value)})))
|
||||||
(or (fc/field-value) (t/now))
|
|
||||||
(atime/unparse-local atime/normal-date))})))
|
|
||||||
(fc/with-field :include-comparison
|
(fc/with-field :include-comparison
|
||||||
(com/toggle {:x-model "comparison" :name (fc/field-name) :checked (boolean (fc/field-value))} "Compare"))
|
(com/toggle {:x-model "comparison" :name (fc/field-name) :checked (boolean (fc/field-value))} "Compare"))
|
||||||
[:div (hx/alpine-appear {:x-show "comparison"})
|
[:div (hx/alpine-appear {:x-show "comparison"})
|
||||||
|
|||||||
@@ -794,7 +794,7 @@
|
|||||||
(for [client (set (map :client-id (:data pnl-data))) ]
|
(for [client (set (map :client-id (:data pnl-data))) ]
|
||||||
(cond-> [{:value (str (-> pnl-data :client-codes (get client)))}]
|
(cond-> [{:value (str (-> pnl-data :client-codes (get client)))}]
|
||||||
|
|
||||||
(:include-comparison (:args pnl-data))
|
(> (count (:periods (:args pnl-data))) 1)
|
||||||
(into ["" ""]))))))
|
(into ["" ""]))))))
|
||||||
true
|
true
|
||||||
(conj (into [{:value "Period Ending"}]
|
(conj (into [{:value "Period Ending"}]
|
||||||
@@ -803,7 +803,7 @@
|
|||||||
(for [client (set (map :client-id (:data pnl-data))) ]
|
(for [client (set (map :client-id (:data pnl-data))) ]
|
||||||
(cond-> [{:value (date->str (:date (:args 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)))}
|
(into [{:value (date->str (:comparison-date (:args pnl-data)))}
|
||||||
{:value "+/-"}]))))))))
|
{:value "+/-"}]))))))))
|
||||||
|
|
||||||
@@ -889,7 +889,7 @@
|
|||||||
(negate #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable}))
|
(negate #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable}))
|
||||||
pnl-datas)
|
pnl-datas)
|
||||||
"Retained Earnings")))
|
"Retained Earnings")))
|
||||||
table (if (:include-comparison (:args pnl-data))
|
table (if (> (count (:periods pnl-data)) 1)
|
||||||
(append-deltas table)
|
(append-deltas table)
|
||||||
table)]
|
table)]
|
||||||
{:warning (warning-message pnl-data)
|
{:warning (warning-message pnl-data)
|
||||||
|
|||||||
Reference in New Issue
Block a user