fixes pnl file name

This commit is contained in:
2026-06-16 14:37:13 -07:00
parent 85aaf7b759
commit de2a1ab850

View File

@@ -102,16 +102,16 @@
:numeric-code (:numeric_code account) :numeric-code (:numeric_code account)
:name (:name account) :name (:name account)
:sample sample :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) args (assoc (:form-params request)
:periods (map (fn [d] :periods (map (fn [d]
{:start (coerce/to-date (:start d)) :end (coerce/to-date (:end d))}) periods)) {: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) 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)) pnl-data (l-reports/->PNLData args data (by :db/id :client/code clients))
#_#__ (clojure.pprint/pprint pnl-data) #_#__ (clojure.pprint/pprint pnl-data)
report (l-reports/summarize-pnl pnl-data)] report (l-reports/summarize-pnl pnl-data)]
(alog/info ::profit-and-loss :params args) (alog/info ::profit-and-loss :params args)
{:data report {:data report
:report report}))) :report report})))
@@ -139,7 +139,7 @@
[13 6 13] [13 6 13]
[13 6]))))) [13 6])))))
: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 table-contents :table table-contents
:warning [:div :warning [:div
(not-empty (str (str/join "\n " (filter not-empty [warning (:warning report)])))) (not-empty (str (str/join "\n " (filter not-empty [warning (:warning report)]))))
@@ -169,12 +169,12 @@
(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)}
(com/multi-typeahead {:name (fc/field-name) (com/multi-typeahead {:name (fc/field-name)
:placeholder "Search for companies..." :placeholder "Search for companies..."
:class "w-64" :class "w-64"
:id "client" :id "client"
:url (bidi/path-for ssr-routes/only-routes :company-search) :url (bidi/path-for ssr-routes/only-routes :company-search)
:value (fc/field-value) :value (fc/field-value)
:value-fn :db/id :value-fn :db/id
:content-fn :client/name}))) :content-fn :client/name})))
(fc/with-field :periods (fc/with-field :periods
@@ -204,12 +204,12 @@
(defn profit-and-loss [request] (defn profit-and-loss [request]
(base-page (base-page
request request
(com/page {:nav com/main-aside-nav (com/page {:nav com/main-aside-nav
:client-selection (:client-selection request) :client-selection (:client-selection request)
:clients (:clients request) :clients (:clients request)
:client (:client request) :client (:client request)
:identity (:identity request) :identity (:identity request)
:request request} :request request}
(apply com/breadcrumbs {} [[:a {:href (bidi/path-for ssr-routes/only-routes ::route/page)} (apply com/breadcrumbs {} [[:a {:href (bidi/path-for ssr-routes/only-routes ::route/page)}
"Ledger"]]) "Ledger"]])
@@ -222,9 +222,9 @@
table (concat-tables (:details report))] table (concat-tables (:details report))]
(pdf/pdf (pdf/pdf
(-> [{:left-margin 10 :right-margin 10 :top-margin 15 :bottom-margin 15 (-> [{:left-margin 10 :right-margin 10 :top-margin 15 :bottom-margin 15
:size :letter :size :letter
:font {:size 6 :font {:size 6
:ttf-name "fonts/calibri-light.ttf"}} :ttf-name "fonts/calibri-light.ttf"}}
[:heading (str "Profit and Loss - " (str/join ", " (map :client/name (seq (:client (:form-params request))))))]] [:heading (str "Profit and Loss - " (str/join ", " (map :client/name (seq (:client (:form-params request))))))]]
(conj [:paragraph {:color [128 0 0] :size 9} (:warning report)]) (conj [:paragraph {:color [128 0 0] :size 9} (:warning report)])
@@ -254,35 +254,35 @@
(str/replace (->> client-ids (pull-many (dc/db conn) [:client/name]) (map :client/name) (str/join "-")) #"[^\w]" "_")) (str/replace (->> client-ids (pull-many (dc/db conn) [:client/name]) (map :client/name) (str/join "-")) #"[^\w]" "_"))
(defn profit-and-loss-args->name [request] (defn profit-and-loss-args->name [request]
(let [date (atime/unparse-local (let [{:keys [client periods]} (:form-params request)
(:date (:query-params request)) client (if (= :all client) (:clients request) client)
atime/iso-date) date (some-> periods last :end (atime/unparse-local atime/iso-date))
name (->> request :query-params :client (map :db/id) join-names)] name (->> client (map :db/id) join-names)]
(format "Profit-and-loss-%s-for-%s" date name))) (format "Profit-and-loss-%s-for-%s" date name)))
(defn print-profit-and-loss [request] (defn print-profit-and-loss [request]
(let [uuid (str (UUID/randomUUID)) (let [uuid (str (UUID/randomUUID))
{:keys [client warning]} (maybe-trim-clients request (:client (:form-params request))) {:keys [client warning]} (maybe-trim-clients request (:client (:form-params request)))
request (assoc-in request [:form-params :client] client) 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)))) "report-pedantic"))] (make-profit-and-loss-pdf request (:report (get-report request))))
name (profit-and-loss-args->name request) name (profit-and-loss-args->name request)
key (str "reports/profit-and-loss/" uuid "/" name ".pdf") key (str "reports/profit-and-loss/" uuid "/" name ".pdf")
url (str "https://" (:data-bucket env) "/" key)] url (str "https://" (:data-bucket env) "/" key)]
(s3/put-object :bucket-name (:data-bucket env/env) (s3/put-object :bucket-name (:data-bucket env/env)
:key key :key key
:input-stream (io/make-input-stream pdf-data {}) :input-stream (io/make-input-stream pdf-data {})
:metadata {:content-length (count pdf-data) :metadata {:content-length (count pdf-data)
:content-type "application/pdf"}) :content-type "application/pdf"})
@(dc/transact conn @(dc/transact conn
[{:report/name name [{:report/name name
:report/client (map :db/id client) :report/client (map :db/id client)
:report/key key :report/key key
:report/url url :report/url url
:report/creator (:user (:identity request)) :report/creator (:user (:identity request))
:report/created (java.util.Date.)}]) :report/created (java.util.Date.)}])
{:report/name name {:report/name name
:report/url url})) :report/url url}))
;; TODO PRINT WARNING ;; TODO PRINT WARNING
(defn export [request] (defn export [request]