Dropdown works well
This commit is contained in:
@@ -1,40 +1,42 @@
|
||||
(ns auto-ap.ssr.ledger.balance-sheet
|
||||
(:require [amazonica.aws.s3 :as s3]
|
||||
[auto-ap.datomic
|
||||
(:require
|
||||
[amazonica.aws.s3 :as s3]
|
||||
[auto-ap.datomic
|
||||
:refer [conn pull-many]]
|
||||
[auto-ap.graphql.utils :refer [assert-can-see-client]]
|
||||
[auto-ap.ledger :refer [build-account-lookup]]
|
||||
[auto-ap.ledger.reports :as l-reports]
|
||||
[auto-ap.logging :as alog]
|
||||
[auto-ap.pdf.ledger :refer [table->pdf]]
|
||||
[auto-ap.permissions :refer [wrap-must]]
|
||||
[auto-ap.routes.ledger :as route]
|
||||
[auto-ap.routes.utils
|
||||
[auto-ap.graphql.utils :refer [assert-can-see-client]]
|
||||
[auto-ap.ledger :refer [build-account-lookup]]
|
||||
[auto-ap.ledger.reports :as l-reports]
|
||||
[auto-ap.logging :as alog]
|
||||
[auto-ap.pdf.ledger :refer [table->pdf]]
|
||||
[auto-ap.permissions :refer [wrap-must]]
|
||||
[auto-ap.routes.ledger :as route]
|
||||
[auto-ap.routes.utils
|
||||
:refer [wrap-client-redirect-unauthenticated]]
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
[auto-ap.ssr.components :as com]
|
||||
[auto-ap.ssr.form-cursor :as fc]
|
||||
[auto-ap.ssr.hx :as hx]
|
||||
[auto-ap.ssr.svg :as svg]
|
||||
[auto-ap.ssr.ui :refer [base-page]]
|
||||
[auto-ap.ssr.utils
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
[auto-ap.ssr.components :as com]
|
||||
[auto-ap.ssr.form-cursor :as fc]
|
||||
[auto-ap.ssr.hx :as hx]
|
||||
[auto-ap.ssr.svg :as svg]
|
||||
[auto-ap.ssr.ui :refer [base-page]]
|
||||
[auto-ap.ssr.utils
|
||||
:refer [apply-middleware-to-all-handlers clj-date-schema
|
||||
html-response modal-response wrap-form-4xx-2
|
||||
wrap-merge-prior-hx wrap-schema-enforce]]
|
||||
[auto-ap.time :as atime]
|
||||
[bidi.bidi :as bidi]
|
||||
[clj-pdf.core :as pdf]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as t]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
[config.core :refer [env] :as env]
|
||||
[datomic.api :as dc]
|
||||
[hiccup.util :as hu]
|
||||
[iol-ion.utils :refer [by]]
|
||||
[malli.core :as mc])
|
||||
(:import [java.util UUID]
|
||||
[org.apache.commons.io.output ByteArrayOutputStream]))
|
||||
html-response modal-response unspecified-transformer
|
||||
wrap-form-4xx-2 wrap-merge-prior-hx wrap-schema-enforce]]
|
||||
[auto-ap.time :as atime]
|
||||
[bidi.bidi :as bidi]
|
||||
[clj-pdf.core :as pdf]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as t]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
[config.core :refer [env] :as env]
|
||||
[datomic.api :as dc]
|
||||
[hiccup.util :as hu]
|
||||
[iol-ion.utils :refer [by]]
|
||||
[malli.core :as mc])
|
||||
(:import
|
||||
[java.util UUID]
|
||||
[org.apache.commons.io.output ByteArrayOutputStream]))
|
||||
|
||||
|
||||
|
||||
@@ -65,16 +67,18 @@
|
||||
|
||||
(def query-schema (mc/schema
|
||||
[:maybe [:and [:map
|
||||
[:client {}
|
||||
[:vector {:coerce? true :min 1 }
|
||||
[:entity-map {:pull [:db/id :client/name]}]]]
|
||||
[:date {}
|
||||
[:client {:unspecified/value :all}
|
||||
[:or
|
||||
[:enum :all]
|
||||
[:vector {:coerce? true :min 1 }
|
||||
[:entity-map {:pull [:db/id :client/name]}]]
|
||||
]]
|
||||
[:date {:unspecified/fn atime/local-now}
|
||||
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]}
|
||||
@@ -86,8 +90,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(defn cell [{:keys [width investigate-url other-style]} c]
|
||||
(let [cell-contents (cond
|
||||
|
||||
@@ -212,7 +214,8 @@
|
||||
|
||||
(defn get-report [{ {:keys [date comparison-date include-comparison client] :as qp} :query-params :as request}]
|
||||
(when (and date client)
|
||||
(let [client-ids (map :db/id client)
|
||||
(let [client (if (= :all client) (take 5 (:clients request)) client)
|
||||
client-ids (map :db/id client)
|
||||
_ (doseq [client-id client-ids]
|
||||
(assert-can-see-client (:identity request) client-id))
|
||||
|
||||
@@ -258,7 +261,6 @@
|
||||
:account-type (:account_type account)
|
||||
:numeric-code (:numeric_code account)
|
||||
:name (:name account) }))
|
||||
|
||||
client-ids)))
|
||||
)
|
||||
args (assoc (:query-params request)
|
||||
@@ -280,10 +282,18 @@
|
||||
{:data report
|
||||
:report report})))
|
||||
|
||||
(defn maybe-trim-clients [request client ]
|
||||
(if (= :all client)
|
||||
(cond-> {:client (take 5 (:clients request))}
|
||||
(> (count (:clients request)) 20)
|
||||
(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}]
|
||||
[:div#report
|
||||
(when (and date client)
|
||||
(let [{:keys [data report]} (get-report request)
|
||||
(let [{:keys [client warning]} (maybe-trim-clients request client)
|
||||
{:keys [data report]} (get-report (assoc-in request [:query-params :client] client))
|
||||
client-count (count (set (map :client-id (:data data)))) ]
|
||||
(list
|
||||
[:div.text-2xl.font-bold.text-gray-600 (str "Balance Sheet - " (str/join ", " (map :client/name client))) ]
|
||||
@@ -291,7 +301,7 @@
|
||||
(:include-comparison (:args data)) (into (repeat 13 (* 2 client-count))))
|
||||
:investigate-url (bidi.bidi/path-for ssr-routes/only-routes ::route/investigate)
|
||||
:table report
|
||||
:warning (:warning report)} ))))])
|
||||
:warning (not-empty (str/join "\n " (filter not-empty [warning (:warning report)])))} ))))])
|
||||
|
||||
(defn form* [request]
|
||||
(let [params (merge (:query-params request) (:form-params request) {})]
|
||||
@@ -314,8 +324,7 @@
|
||||
:class "w-64"
|
||||
:id "client"
|
||||
:url (bidi/path-for ssr-routes/only-routes :company-search)
|
||||
:value (or (fc/field-value)
|
||||
(take 5 (:clients request)))
|
||||
:value (fc/field-value)
|
||||
:value-fn :db/id
|
||||
:content-fn :client/name})))
|
||||
(fc/with-field :date
|
||||
@@ -332,7 +341,6 @@
|
||||
(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)))
|
||||
@@ -453,6 +461,6 @@
|
||||
)
|
||||
(fn [h]
|
||||
(-> h
|
||||
(wrap-merge-prior-hx)
|
||||
(wrap-must {:activity :import :subject :ledger})
|
||||
(wrap-client-redirect-unauthenticated)))))
|
||||
#_(wrap-merge-prior-hx)
|
||||
(wrap-must {:activity :read :subject :balance-sheet})
|
||||
(wrap-client-redirect-unauthenticated)))))
|
||||
|
||||
Reference in New Issue
Block a user