diff --git a/src/clj/auto_ap/datomic/migrate/reports.clj b/src/clj/auto_ap/datomic/migrate/reports.clj index 87d25b98..5e4e4cb5 100644 --- a/src/clj/auto_ap/datomic/migrate/reports.clj +++ b/src/clj/auto_ap/datomic/migrate/reports.clj @@ -24,4 +24,8 @@ {:db/ident :report/url :db/doc "Where to download the report" :db/valueType :db.type/string - :db/cardinality :db.cardinality/one}]]}}) + :db/cardinality :db.cardinality/one}]]} + ::add-creator {:txes [[{:db/ident :report/creator + :db/doc "Creator of the report's name" + :db/valueType :db.type/string + :db/cardinality :db.cardinality/one}]]}}) diff --git a/src/clj/auto_ap/datomic/reports.clj b/src/clj/auto_ap/datomic/reports.clj index 3486344a..e4e383dd 100644 --- a/src/clj/auto_ap/datomic/reports.clj +++ b/src/clj/auto_ap/datomic/reports.clj @@ -25,6 +25,7 @@ (:sort args) (add-sorter-fields {"client" ['[?e :report/client ?c] '[?c :client/name ?sort-client]] "created" ['[?e :report/created ?sort-created]] + "creator" ['[?e :report/creator ?sort-creator]] "name" ['[?e :report/name ?sort-name] ]} args) @@ -37,7 +38,7 @@ (apply-pagination args)))) (defn graphql-results [ids db args] - (let [results (->> (d/pull-many db '[:db/id :report/client :report/created :report/url :report/name] + (let [results (->> (d/pull-many db '[:db/id :report/client :report/created :report/url :report/name :report/creator] ids) (map #(update % :report/created c/from-date)) (group-by :db/id))] diff --git a/src/clj/auto_ap/graphql/ledger.clj b/src/clj/auto_ap/graphql/ledger.clj index ef12862c..4c94d875 100644 --- a/src/clj/auto_ap/graphql/ledger.clj +++ b/src/clj/auto_ap/graphql/ledger.clj @@ -210,31 +210,9 @@ (defn profit-and-loss-pdf [context args value] (let [data (get-profit-and-loss context args value) - result (print-pnl args data)] + result (print-pnl (:id context) args data)] - (->graphql {:report_url result})) - #_(let [client-id (:client_id args) - client-ids (or (some-> client-id vector) - (filter identity (:client_ids args))) - _ (when (not (seq client-ids)) - (throw (ex-info "Please select a client." {:validation-error "Please select a client."}))) - _ (doseq [client-id client-ids] - (assert-can-see-client (:id context) client-id)) - all-ledger-entries (->> client-ids - (map (fn [client-id] - [client-id (full-ledger-for-client client-id)])) - (into {})) - lookup-account (->> client-ids - (map (fn [client-id] - [client-id (build-account-lookup client-id)])) - (into {}))] - (->graphql - {:periods - (->> (:periods args) - (mapv (fn [{:keys [start end]}] - {:accounts (mapcat - #(roll-up-until (lookup-account %) (all-ledger-entries %) (coerce/to-date end) (coerce/to-date start) ) - client-ids)})))}))) + (->graphql {:report_url result}))) (defn assoc-error [f] diff --git a/src/clj/auto_ap/graphql/reports.clj b/src/clj/auto_ap/graphql/reports.clj index 0d1f1def..3a774ee3 100644 --- a/src/clj/auto_ap/graphql/reports.clj +++ b/src/clj/auto_ap/graphql/reports.clj @@ -36,6 +36,7 @@ {:fields {:url {:type 'String} :name {:type 'String} :created {:type :iso_date} + :creator {:type 'String} :id {:type :id}}} :report_page diff --git a/src/clj/auto_ap/pdf/ledger.clj b/src/clj/auto_ap/pdf/ledger.clj index d84420be..c72d40a8 100644 --- a/src/clj/auto_ap/pdf/ledger.clj +++ b/src/clj/auto_ap/pdf/ledger.clj @@ -29,14 +29,7 @@ (.format (DecimalFormat. "0%") (:value cell)) :else - (str (:value cell))) - cell-contents (if (:filters cell) - (do - (println (:filters cell)) - cell-contents) - - - cell-contents)] + (str (:value cell)))] [:pdf-cell (cond-> {} @@ -205,7 +198,7 @@ names (str/replace (->> args :client_ids (d/pull-many (d/db conn) [:client/name]) (map :client/name) (str/join "-")) #" " "_" )] (format "Profit-and-loss-%s-to-%s-for-%s" min-date max-date names))) -(defn print-pnl [args data] +(defn print-pnl [user args data] (let [uuid (str (UUID/randomUUID)) pdf-data (make-pnl args data) name (args->name args) @@ -221,5 +214,6 @@ :report/client (:client_ids args) :report/key key :report/url url + :report/creator (:user user) :report/created (java.util.Date.)}]) url)) diff --git a/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs b/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs index 64f0cf75..546ef3d8 100644 --- a/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs +++ b/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs @@ -540,10 +540,7 @@ Please download it by clicking this link: " report-url))) (fn [table] (-> (:header table) (into (:rows table)) - (conj [])) - #_(println "table 1" table) - #_[(:header table) - (:rows table)]) + (conj []))) rest))})) (defn pnl-report [{:keys [args report-data]}] diff --git a/src/cljs/auto_ap/views/pages/reports.cljs b/src/cljs/auto_ap/views/pages/reports.cljs index c805af17..d8d4411b 100644 --- a/src/cljs/auto_ap/views/pages/reports.cljs +++ b/src/cljs/auto_ap/views/pages/reports.cljs @@ -31,6 +31,7 @@ [[:reports [:id :name :created + :creator :url]] :total :start diff --git a/src/cljs/auto_ap/views/pages/reports/table.cljs b/src/cljs/auto_ap/views/pages/reports/table.cljs index aad286fa..b6c30e9f 100644 --- a/src/cljs/auto_ap/views/pages/reports/table.cljs +++ b/src/cljs/auto_ap/views/pages/reports/table.cljs @@ -23,10 +23,11 @@ [::data-page/updated-entity data-page {:name "deleted"}] #_[::invoice-updated ()(:void-invoice result)])}})) -(defn row [{{:keys [name created url id] :as i} :row is-admin? :is-admin? data-page :data-page}] +(defn row [{{:keys [name creator created url id] :as i} :row is-admin? :is-admin? data-page :data-page}] [:<> [grid/row {:class (:class i) :id id} [grid/cell {} name] + [grid/cell {} creator] [grid/cell {} (date->str created) ] [grid/button-cell {} [:div.buttons @@ -51,6 +52,7 @@ [grid/header [grid/row {} [grid/sortable-header-cell {:sort-key "name" :sort-name "Name"} "Name"] + [grid/sortable-header-cell {:sort-key "creator" :sort-name "Created by"} "Created by"] [grid/sortable-header-cell {:sort-key "created" :sort-name "Created" :style {:width "8em"}} "Created"] [grid/header-cell {:style {:width (action-cell-width (if is-admin?