Add vendor pre-population for bulk code and individual edit forms
- Add vendor-changed HTMX handlers for both bulk code and individual edit - Pre-populate default account at 100% when vendor is selected and no accounts exist - Fix render-accounts-section to render from step-params correctly - Change bulk code vendor-changed from hx-get to hx-post to include form data - Add routes for vendor-changed endpoints - Update e2e tests to cover vendor pre-population - Run lein cljfmt fix across codebase
This commit is contained in:
@@ -38,7 +38,6 @@
|
||||
[java.util UUID]
|
||||
[org.apache.commons.io.output ByteArrayOutputStream]))
|
||||
|
||||
|
||||
(def query-schema (mc/schema
|
||||
[:maybe [:map
|
||||
[:client {:unspecified/value :all}
|
||||
@@ -71,14 +70,14 @@
|
||||
;; 4. Review ledger dialog
|
||||
;; 5. pagination and filtering within dialog. looks weird with the full screen refresh
|
||||
|
||||
(defn get-report [{ {:keys [periods client] :as qp} :form-params :as request}]
|
||||
(defn get-report [{{:keys [periods client] :as qp} :form-params :as request}]
|
||||
(when (and (seq periods) client)
|
||||
(let [client (if (= :all client) (take 5 (:clients request)) client)
|
||||
client-ids (map :db/id client)
|
||||
_ (upsert-running-balance (into #{} client-ids))
|
||||
_ (doseq [client-id client-ids]
|
||||
(assert-can-see-client (:identity request) client-id))
|
||||
|
||||
|
||||
lookup-account (->> client-ids
|
||||
(map (fn build-lookup [client-id]
|
||||
[client-id (build-account-lookup client-id)]))
|
||||
@@ -103,13 +102,13 @@
|
||||
:numeric-code (:numeric_code account)
|
||||
:name (:name account)
|
||||
:sample sample
|
||||
:period {:start ( coerce/to-date (:start p)) :end (coerce/to-date (:end p))}}))
|
||||
|
||||
:period {:start (coerce/to-date (:start p)) :end (coerce/to-date (:end p))}}))
|
||||
|
||||
args (assoc (:form-params request)
|
||||
:periods (map (fn [d]
|
||||
{:start ( coerce/to-date (:start d)) :end ( coerce/to-date (:end d))}) periods))
|
||||
:periods (map (fn [d]
|
||||
{:start (coerce/to-date (:start d)) :end (coerce/to-date (:end d))}) periods))
|
||||
clients (pull-many (dc/db conn) [:client/code :client/name :db/id :client/feature-flags] client-ids)
|
||||
|
||||
|
||||
pnl-data (l-reports/->PNLData args data (by :db/id :client/code clients))
|
||||
#_#__ (clojure.pprint/pprint pnl-data)
|
||||
report (l-reports/summarize-pnl pnl-data)]
|
||||
@@ -124,14 +123,14 @@
|
||||
(assoc :warning "You requested a report with more than 20 clients. This report will only contain the first 20."))
|
||||
{:client client}))
|
||||
|
||||
(defn profit-and-loss* [{ {:keys [periods client] } :form-params :as request}]
|
||||
[:div#report
|
||||
(defn profit-and-loss* [{{:keys [periods client]} :form-params :as request}]
|
||||
[:div#report
|
||||
(when (and periods client)
|
||||
(let [{:keys [client warning]} (maybe-trim-clients request client)
|
||||
{:keys [data report]} (get-report (assoc-in request [:form-params :client] client))
|
||||
client-count (count (set (map :client-id (:data data))))
|
||||
client-count (count (set (map :client-id (:data data))))
|
||||
table-contents (concat-tables (concat (:summaries report) (:details report)))]
|
||||
(list
|
||||
(list
|
||||
[:div.text-2xl.font-bold.text-gray-600 (str "Profit and loss - " (str/join ", " (map :client/name client)))]
|
||||
(table {:widths (into [20] (take (dec (cell-count table-contents))
|
||||
(mapcat identity
|
||||
@@ -148,14 +147,11 @@
|
||||
{:subject :history
|
||||
:activity :view})
|
||||
(for [n (:invalid-ids report)]
|
||||
[:div
|
||||
[:div
|
||||
(com/link {:href (str (bidi/path-for ssr-routes/only-routes
|
||||
:admin-history)
|
||||
"/" n)}
|
||||
"Sample")]))]
|
||||
}))))])
|
||||
|
||||
|
||||
"Sample")]))]}))))])
|
||||
|
||||
(defn form* [request & children]
|
||||
(let [params (or (:query-params request) {})]
|
||||
@@ -209,7 +205,7 @@
|
||||
(base-page
|
||||
request
|
||||
(com/page {:nav com/main-aside-nav
|
||||
|
||||
|
||||
:client-selection (:client-selection request)
|
||||
:clients (:clients request)
|
||||
:client (:client request)
|
||||
@@ -259,8 +255,8 @@
|
||||
|
||||
(defn profit-and-loss-args->name [request]
|
||||
(let [date (atime/unparse-local
|
||||
(:date (:query-params request))
|
||||
atime/iso-date)
|
||||
(:date (:query-params request))
|
||||
atime/iso-date)
|
||||
name (->> request :query-params :client (map :db/id) join-names)]
|
||||
(format "Profit-and-loss-%s-for-%s" date name)))
|
||||
|
||||
@@ -268,7 +264,7 @@
|
||||
(let [uuid (str (UUID/randomUUID))
|
||||
{:keys [client warning]} (maybe-trim-clients request (:client (:form-params request)))
|
||||
request (assoc-in request [:form-params :client] client)
|
||||
pdf-data (binding [*report-pedantic* (boolean ((set (:client/feature-flags (first client)))
|
||||
pdf-data (binding [*report-pedantic* (boolean ((set (:client/feature-flags (first client)))
|
||||
"report-pedantic"))] (make-profit-and-loss-pdf request (:report (get-report request))))
|
||||
name (profit-and-loss-args->name request)
|
||||
key (str "reports/profit-and-loss/" uuid "/" name ".pdf")
|
||||
@@ -306,7 +302,7 @@
|
||||
"Click "
|
||||
(com/link {:href (:report/url bs)} "here")
|
||||
" to download"]]))
|
||||
|
||||
|
||||
nil))
|
||||
:headers (-> {}
|
||||
(assoc "hx-retarget" ".modal-stack")
|
||||
@@ -316,15 +312,15 @@
|
||||
(apply-middleware-to-all-handlers
|
||||
(->
|
||||
{::route/profit-and-loss (-> profit-and-loss
|
||||
(wrap-schema-enforce :query-schema query-schema)
|
||||
(wrap-form-4xx-2 profit-and-loss))
|
||||
(wrap-schema-enforce :query-schema query-schema)
|
||||
(wrap-form-4xx-2 profit-and-loss))
|
||||
::route/run-profit-and-loss (-> form
|
||||
(wrap-schema-enforce :form-schema query-schema)
|
||||
(wrap-form-4xx-2 form))
|
||||
(wrap-schema-enforce :form-schema query-schema)
|
||||
(wrap-form-4xx-2 form))
|
||||
::route/export-profit-and-loss (-> export
|
||||
(wrap-schema-enforce :form-schema query-schema)
|
||||
(wrap-form-4xx-2 form))})
|
||||
|
||||
(wrap-schema-enforce :form-schema query-schema)
|
||||
(wrap-form-4xx-2 form))})
|
||||
|
||||
(fn [h]
|
||||
(-> h
|
||||
#_(wrap-merge-prior-hx)
|
||||
|
||||
Reference in New Issue
Block a user