makes balance sheet with multiple dates easy.
This commit is contained in:
@@ -66,7 +66,7 @@
|
||||
|
||||
|
||||
(def query-schema (mc/schema
|
||||
[:maybe [:and [:map
|
||||
[:maybe [:map
|
||||
[:client {:unspecified/value :all}
|
||||
[:or
|
||||
[:enum :all]
|
||||
@@ -77,19 +77,7 @@
|
||||
[: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}
|
||||
[ :boolean {:decode/string {:enter #(if (= % "on") true
|
||||
(boolean %))}}]]]
|
||||
[:fn {:error/message "required"
|
||||
:error/path [:comparison-date]}
|
||||
(fn [x]
|
||||
(if (and (not (:comparison-date x))
|
||||
(:include-comparison x))
|
||||
false
|
||||
true))]]]))
|
||||
clj-date-schema]] ]]))
|
||||
|
||||
|
||||
|
||||
@@ -216,9 +204,10 @@
|
||||
;; 3. General cleanup of the patterns in run-balance-sheet
|
||||
;; 4. Review ledger dialog
|
||||
|
||||
(defn get-report [{ {:keys [date comparison-date include-comparison client] :as qp} :query-params :as request}]
|
||||
(defn get-report [{ {:keys [date client] :as qp} :query-params :as request}]
|
||||
(when (and date client)
|
||||
(let [client (if (= :all client) (take 5 (:clients request)) client)
|
||||
date (reverse (sort date ))
|
||||
client-ids (map :db/id client)
|
||||
_ (doseq [client-id client-ids]
|
||||
(assert-can-see-client (:identity request) client-id))
|
||||
@@ -245,7 +234,6 @@
|
||||
:period (coerce/to-date d)}))
|
||||
args (assoc (:query-params request)
|
||||
: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)
|
||||
|
||||
pnl-data (l-reports/->PNLData args data (by :db/id :client/code clients))
|
||||
@@ -261,7 +249,7 @@
|
||||
(assoc :warning "You requested a report with more than 20 clients. This report will only contain the first 20."))
|
||||
{:client client}))
|
||||
|
||||
(defn balance-sheet* [{ {:keys [date comparison-date include-comparison client] } :query-params :as request}]
|
||||
(defn balance-sheet* [{ {:keys [date client] } :query-params :as request}]
|
||||
[:div#report
|
||||
(when (and date client)
|
||||
(let [{:keys [client warning]} (maybe-trim-clients request client)
|
||||
@@ -287,7 +275,7 @@
|
||||
:hx-swap "outerHTML"
|
||||
:hx-disabled-elt "find fieldset"}
|
||||
[:fieldset
|
||||
[:div.flex.gap-8 {:x-data (hx/json {:comparison (boolean (:include-comparison params))})}
|
||||
[:div.flex.gap-8 {:x-data (hx/json {})}
|
||||
(fc/with-field :client
|
||||
(com/validated-inline-field
|
||||
{:label "Customers" :errors (fc/field-errors)}
|
||||
@@ -305,16 +293,7 @@
|
||||
(com/multi-date-input {:placeholder "12/21/2020"
|
||||
:name (fc/field-name)
|
||||
: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"})
|
||||
(fc/with-field :comparison-date
|
||||
(com/validated-inline-field {:label "Previous Date"
|
||||
:errors (fc/field-errors)}
|
||||
(com/date-input {:placeholder "12/21/2020"
|
||||
:name (fc/field-name)
|
||||
:value (some-> (or (fc/field-value) (t/plus (t/now) (t/years -1)))
|
||||
(atime/unparse-local atime/normal-date))})))]
|
||||
|
||||
(com/button {:color :primary :class "w-32"}
|
||||
"Run")
|
||||
(com/button {:formaction (bidi.bidi/path-for ssr-routes/only-routes ::route/export-balance-sheet) } "Export PDF")]]] ]
|
||||
@@ -345,7 +324,8 @@
|
||||
|
||||
(let [ output-stream (ByteArrayOutputStream.)
|
||||
client-count (count (or (seq (:client (:query-params request)))
|
||||
(seq (:client (:form-params request)))))]
|
||||
(seq (:client (:form-params request)))))
|
||||
date (:date (:query-params request))]
|
||||
(pdf/pdf
|
||||
(-> [{:left-margin 10 :right-margin 10 :top-margin 15 :bottom-margin 15
|
||||
:size :letter
|
||||
@@ -358,8 +338,7 @@
|
||||
(conj
|
||||
(table->pdf report
|
||||
(cond-> (into [30 ] (repeat client-count 13))
|
||||
(or (:include-comparison (:query-params request))
|
||||
(:include-comparison (:form-params request))) (into (repeat (* 2 client-count) 13))))))
|
||||
(> (count date) 1) (into (repeat (* 2 client-count (dec (count date))) 13 ))))))
|
||||
output-stream)
|
||||
(.toByteArray output-stream)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user