From de2a1ab850b2bbe42ad574b0785ad25f60b6c440 Mon Sep 17 00:00:00 2001 From: Bryce Date: Tue, 16 Jun 2026 14:37:13 -0700 Subject: [PATCH] fixes pnl file name --- .../auto_ap/ssr/ledger/profit_and_loss.clj | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/clj/auto_ap/ssr/ledger/profit_and_loss.clj b/src/clj/auto_ap/ssr/ledger/profit_and_loss.clj index eedf9a4c..bc65ddf4 100644 --- a/src/clj/auto_ap/ssr/ledger/profit_and_loss.clj +++ b/src/clj/auto_ap/ssr/ledger/profit_and_loss.clj @@ -102,16 +102,16 @@ :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)) - clients (pull-many (dc/db conn) [:client/code :client/name :db/id :client/feature-flags] client-ids) + args (assoc (:form-params request) + :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)) + 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)] + report (l-reports/summarize-pnl pnl-data)] (alog/info ::profit-and-loss :params args) {:data report :report report}))) @@ -139,7 +139,7 @@ [13 6 13] [13 6]))))) :investigate-url (bidi.bidi/path-for ssr-routes/only-routes ::route/investigate) - :table table-contents + :table table-contents :warning [:div (not-empty (str (str/join "\n " (filter not-empty [warning (:warning report)])))) @@ -169,12 +169,12 @@ (fc/with-field :client (com/validated-inline-field {:label "Customers" :errors (fc/field-errors)} - (com/multi-typeahead {:name (fc/field-name) + (com/multi-typeahead {:name (fc/field-name) :placeholder "Search for companies..." :class "w-64" - :id "client" + :id "client" :url (bidi/path-for ssr-routes/only-routes :company-search) - :value (fc/field-value) + :value (fc/field-value) :value-fn :db/id :content-fn :client/name}))) (fc/with-field :periods @@ -204,12 +204,12 @@ (defn profit-and-loss [request] (base-page request - (com/page {:nav com/main-aside-nav + (com/page {:nav com/main-aside-nav :client-selection (:client-selection request) - :clients (:clients request) - :client (:client request) - :identity (:identity request) + :clients (:clients request) + :client (:client request) + :identity (:identity request) :request request} (apply com/breadcrumbs {} [[:a {:href (bidi/path-for ssr-routes/only-routes ::route/page)} "Ledger"]]) @@ -222,9 +222,9 @@ table (concat-tables (:details report))] (pdf/pdf (-> [{:left-margin 10 :right-margin 10 :top-margin 15 :bottom-margin 15 - :size :letter - :font {:size 6 - :ttf-name "fonts/calibri-light.ttf"}} + :size :letter + :font {:size 6 + :ttf-name "fonts/calibri-light.ttf"}} [: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)]) @@ -254,35 +254,35 @@ (str/replace (->> client-ids (pull-many (dc/db conn) [:client/name]) (map :client/name) (str/join "-")) #"[^\w]" "_")) (defn profit-and-loss-args->name [request] - (let [date (atime/unparse-local - (:date (:query-params request)) - atime/iso-date) - name (->> request :query-params :client (map :db/id) join-names)] + (let [{:keys [client periods]} (:form-params request) + client (if (= :all client) (:clients request) client) + date (some-> periods last :end (atime/unparse-local atime/iso-date)) + name (->> client (map :db/id) join-names)] (format "Profit-and-loss-%s-for-%s" date name))) (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))) - 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))) "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") - url (str "https://" (:data-bucket env) "/" key)] + name (profit-and-loss-args->name request) + key (str "reports/profit-and-loss/" uuid "/" name ".pdf") + url (str "https://" (:data-bucket env) "/" key)] (s3/put-object :bucket-name (:data-bucket env/env) :key key :input-stream (io/make-input-stream pdf-data {}) :metadata {:content-length (count pdf-data) - :content-type "application/pdf"}) + :content-type "application/pdf"}) @(dc/transact conn - [{:report/name name - :report/client (map :db/id client) - :report/key key - :report/url url + [{:report/name name + :report/client (map :db/id client) + :report/key key + :report/url url :report/creator (:user (:identity request)) :report/created (java.util.Date.)}]) {:report/name name - :report/url url})) + :report/url url})) ;; TODO PRINT WARNING (defn export [request]