balance sheet prep
This commit is contained in:
@@ -217,7 +217,7 @@
|
|||||||
"@mouseout" "active = -1"
|
"@mouseout" "active = -1"
|
||||||
"@click.prevent" "value.push({value: element.value, label: element.label});"
|
"@click.prevent" "value.push({value: element.value, label: element.label});"
|
||||||
}
|
}
|
||||||
[ :input {:type "checkbox" ":checked" "value.includes(element.value)"} ]
|
[ :input {:type "checkbox" ":checked" "value.map(i=>i.value).includes(element.value)"} ]
|
||||||
[:span {"x-html" "element.label"}]]]]
|
[:span {"x-html" "element.label"}]]]]
|
||||||
[:template {:x-if "elements.length == 0"}
|
[:template {:x-if "elements.length == 0"}
|
||||||
[:li {:class "px-4 py-2 flex gap-2 items-center outline-0 focus:bg-neutral-100 hover:bg-neutral-100 whitespace-nowrap [&.active]:bg-primary-500 text-gray-800 dark:text-gray-100 text-xs "}
|
[:li {:class "px-4 py-2 flex gap-2 items-center outline-0 focus:bg-neutral-100 hover:bg-neutral-100 whitespace-nowrap [&.active]:bg-primary-500 text-gray-800 dark:text-gray-100 text-xs "}
|
||||||
|
|||||||
@@ -252,18 +252,11 @@
|
|||||||
request)
|
request)
|
||||||
:headers {"hx-push-url" (str "?" (url/map->query
|
:headers {"hx-push-url" (str "?" (url/map->query
|
||||||
(dissoc (if (:query-schema grid-spec)
|
(dissoc (if (:query-schema grid-spec)
|
||||||
(do
|
|
||||||
(alog/peek ::setup4
|
|
||||||
(pr-str (update (filter-vals #(not (nil? %))
|
|
||||||
(m/encode (:query-schema grid-spec)
|
|
||||||
(:query-params request)
|
|
||||||
main-transformer))
|
|
||||||
"sort" sort->query)))
|
|
||||||
(update (filter-vals #(not (nil? %))
|
(update (filter-vals #(not (nil? %))
|
||||||
(m/encode (:query-schema grid-spec)
|
(m/encode (:query-schema grid-spec)
|
||||||
(:query-params request)
|
(:query-params request)
|
||||||
main-transformer))
|
main-transformer))
|
||||||
"sort" sort->query))
|
"sort" sort->query)
|
||||||
(unparse-query-params (:parsed-query-params request)))
|
(unparse-query-params (:parsed-query-params request)))
|
||||||
"selected" "all-selected")))} ;; TODO seems hacky to special case selected and all-selected here
|
"selected" "all-selected")))} ;; TODO seems hacky to special case selected and all-selected here
|
||||||
:oob (when-let [oob-render (:oob-render grid-spec)]
|
:oob (when-let [oob-render (:oob-render grid-spec)]
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
[auto-ap.ledger.reports :as l-reports]
|
[auto-ap.ledger.reports :as l-reports]
|
||||||
[auto-ap.logging :as alog]
|
[auto-ap.logging :as alog]
|
||||||
[auto-ap.permissions :refer [wrap-must]]
|
[auto-ap.permissions :refer [wrap-must]]
|
||||||
[auto-ap.query-params :refer [wrap-copy-qp-pqp]]
|
|
||||||
[auto-ap.routes.ledger :as route]
|
[auto-ap.routes.ledger :as route]
|
||||||
[auto-ap.routes.utils
|
[auto-ap.routes.utils
|
||||||
:refer [wrap-client-redirect-unauthenticated]]
|
:refer [wrap-client-redirect-unauthenticated]]
|
||||||
@@ -17,8 +16,9 @@
|
|||||||
[auto-ap.ssr.ui :refer [base-page]]
|
[auto-ap.ssr.ui :refer [base-page]]
|
||||||
[auto-ap.ssr.utils
|
[auto-ap.ssr.utils
|
||||||
:refer [apply-middleware-to-all-handlers clj-date-schema
|
:refer [apply-middleware-to-all-handlers clj-date-schema
|
||||||
entity-id html-response wrap-form-4xx-2
|
field-validation-error html-response wrap-form-4xx-2
|
||||||
wrap-merge-prior-hx wrap-schema-enforce]]
|
wrap-merge-prior-hx wrap-schema-decode
|
||||||
|
wrap-schema-enforce]]
|
||||||
[auto-ap.time :as atime]
|
[auto-ap.time :as atime]
|
||||||
[bidi.bidi :as bidi]
|
[bidi.bidi :as bidi]
|
||||||
[clj-time.coerce :as coerce]
|
[clj-time.coerce :as coerce]
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
|
|
||||||
|
|
||||||
(def query-schema (mc/schema
|
(def query-schema (mc/schema
|
||||||
[:maybe [:map
|
[:maybe [:and [:map
|
||||||
[:client {}
|
[:client {}
|
||||||
[:vector {:coerce? true :min 1 }
|
[:vector {:coerce? true :min 1 }
|
||||||
[:entity-map {:pull [:db/id :client/name]}]]]
|
[:entity-map {:pull [:db/id :client/name]}]]]
|
||||||
@@ -66,7 +66,14 @@
|
|||||||
[:include-comparison {:optional true :default false}
|
[:include-comparison {:optional true :default false}
|
||||||
[ :boolean {:decode/string {:enter #(if (= % "on") true
|
[ :boolean {:decode/string {:enter #(if (= % "on") true
|
||||||
|
|
||||||
(boolean %))}}]]]]))
|
(boolean %))}}]]]
|
||||||
|
[:fn {:error/message "required"
|
||||||
|
:error/path [:comparison-date]}
|
||||||
|
(fn [x]
|
||||||
|
(if (and (not (:comparison-date x))
|
||||||
|
(:include-comparison x))
|
||||||
|
false
|
||||||
|
true))]]]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -187,16 +194,16 @@
|
|||||||
;; 4. Review ledger dialog
|
;; 4. Review ledger dialog
|
||||||
|
|
||||||
|
|
||||||
(defn run-balance-sheet [{:keys [query-params] :as request}]
|
(defn balance-sheet* [{ {:keys [date comparison-date include-comparison client] } :query-params :as request}]
|
||||||
(let [client-ids (map :db/id (:client (:query-params request)))
|
[:div#report
|
||||||
|
(when (and date client)
|
||||||
|
(let [client-ids (map :db/id client)
|
||||||
|
|
||||||
_ (when (not (seq client-ids))
|
|
||||||
(throw (ex-info "Please select a client." {:validation-error "Please select a client."})))
|
|
||||||
_ (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 (:query-params request)))
|
|
||||||
comparable-date (coerce/to-date (:comparison-date (:query-params request)))
|
end-date (coerce/to-date date)
|
||||||
include-comparison (:include-comparison (:query-params request))
|
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)]))
|
||||||
@@ -219,7 +226,8 @@
|
|||||||
:name (:name account) }))
|
:name (:name account) }))
|
||||||
|
|
||||||
client-ids))}
|
client-ids))}
|
||||||
include-comparison (assoc :comparable-balance-sheet-accounts
|
(and include-comparison comparison-date)
|
||||||
|
(assoc :comparable-balance-sheet-accounts
|
||||||
(into []
|
(into []
|
||||||
(mapcat
|
(mapcat
|
||||||
(fn calculate-accounts [client-id ]
|
(fn calculate-accounts [client-id ]
|
||||||
@@ -239,9 +247,9 @@
|
|||||||
|
|
||||||
client-ids)))
|
client-ids)))
|
||||||
)
|
)
|
||||||
args (assoc query-params
|
args (assoc (:query-params request)
|
||||||
:periods (filter identity (cond-> [(:date query-params)]
|
:periods (filter identity (cond-> [date]
|
||||||
include-comparison (conj (:comparison-date query-params)))))
|
include-comparison (conj comparison-date))))
|
||||||
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)
|
data (concat (->> (:balance-sheet-accounts data)
|
||||||
@@ -256,22 +264,25 @@
|
|||||||
client-count (count (set (map :client-id (:data pnl-data))))
|
client-count (count (set (map :client-id (:data pnl-data))))
|
||||||
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)
|
||||||
(html-response
|
|
||||||
(list
|
(list
|
||||||
[:div.text-2xl.font-bold.text-gray-600 (str "Balance Sheet - " (str/join ", " (map :client/name clients))) ]
|
[:div.text-2xl.font-bold.text-gray-600 (str "Balance Sheet - " (str/join ", " (map :client/name clients))) ]
|
||||||
(table {:widths (cond-> (into [30 ] (repeat 13 client-count))
|
(table {:widths (cond-> (into [30 ] (repeat 13 client-count))
|
||||||
(:include-comparison args) (into (repeat 13 (* 2 client-count))))
|
(:include-comparison args) (into (repeat 13 (* 2 client-count))))
|
||||||
:click-event ::investigate-clicked
|
:click-event ::investigate-clicked
|
||||||
:table report} )))))
|
:table report} ))))])
|
||||||
|
|
||||||
(defn form* [request]
|
(defn form* [request]
|
||||||
|
|
||||||
|
(let [params (merge (:query-params request) (:form-params request) {})]
|
||||||
(fc/start-form
|
(fc/start-form
|
||||||
(:form-params request)
|
|
||||||
|
params
|
||||||
(:form-errors request)
|
(:form-errors request)
|
||||||
[:div#balance-sheet-form.flex.flex-col.gap-4.mt-4
|
[:div#balance-sheet-form.flex.flex-col.gap-4.mt-4
|
||||||
[:form {:hx-get (bidi.bidi/path-for ssr-routes/only-routes ::route/run-balance-sheet)
|
[:form {:hx-get (bidi.bidi/path-for ssr-routes/only-routes ::route/run-balance-sheet)
|
||||||
:hx-target "#report"}
|
:hx-target "#balance-sheet-form"
|
||||||
[:div.flex.gap-8 {:x-data (hx/json {:comparison (boolean (:comparison-date (:form-params request)))})}
|
:hx-swap "outerHTML"}
|
||||||
|
[:div.flex.gap-8 {:x-data (hx/json {:comparison (boolean (:include-comparison params))})}
|
||||||
(fc/with-field :client
|
(fc/with-field :client
|
||||||
(com/validated-inline-field
|
(com/validated-inline-field
|
||||||
{:label "Customers" :errors (fc/field-errors)}
|
{:label "Customers" :errors (fc/field-errors)}
|
||||||
@@ -302,11 +313,12 @@
|
|||||||
(atime/unparse-local atime/normal-date))})))]
|
(atime/unparse-local atime/normal-date))})))]
|
||||||
(com/button {:color :primary :class "w-32"}
|
(com/button {:color :primary :class "w-32"}
|
||||||
"Run")]]
|
"Run")]]
|
||||||
[:div#report]]))
|
(balance-sheet* request)])))
|
||||||
|
|
||||||
(defn form [request]
|
(defn form [request]
|
||||||
(html-response (form* request)
|
(html-response (form* request)
|
||||||
:headers {"hx-retarget" "#balance-sheet-form"}))
|
:headers {"hx-retarget" "#balance-sheet-form"
|
||||||
|
"hx-push-url" (str "?" (:query-string request))}))
|
||||||
|
|
||||||
(defn balance-sheet [request]
|
(defn balance-sheet [request]
|
||||||
(base-page
|
(base-page
|
||||||
@@ -326,8 +338,10 @@
|
|||||||
(def key->handler
|
(def key->handler
|
||||||
(apply-middleware-to-all-handlers
|
(apply-middleware-to-all-handlers
|
||||||
(->
|
(->
|
||||||
{::route/balance-sheet balance-sheet
|
{::route/balance-sheet (-> balance-sheet
|
||||||
::route/run-balance-sheet (-> run-balance-sheet
|
(wrap-schema-enforce :query-schema query-schema)
|
||||||
|
(wrap-form-4xx-2 balance-sheet))
|
||||||
|
::route/run-balance-sheet (-> form
|
||||||
(wrap-schema-enforce :query-schema query-schema)
|
(wrap-schema-enforce :query-schema query-schema)
|
||||||
(wrap-form-4xx-2 form))})
|
(wrap-form-4xx-2 form))})
|
||||||
(fn [h]
|
(fn [h]
|
||||||
|
|||||||
@@ -172,7 +172,12 @@
|
|||||||
s))
|
s))
|
||||||
|
|
||||||
(defn keyword->str [k]
|
(defn keyword->str [k]
|
||||||
(subs (str k) 1))
|
(cond (keyword? k)
|
||||||
|
(subs (str k) 1)
|
||||||
|
(string? k)
|
||||||
|
k
|
||||||
|
:else
|
||||||
|
k))
|
||||||
|
|
||||||
|
|
||||||
;; TODO make this bubble the form data automatically
|
;; TODO make this bubble the form data automatically
|
||||||
|
|||||||
Reference in New Issue
Block a user