adds csv capability

This commit is contained in:
2024-11-11 21:39:36 -08:00
parent aed9113306
commit cb4f88f02a
9 changed files with 136 additions and 65 deletions

View File

@@ -140,6 +140,11 @@
:size :small})])
(exact-match-id* request)]])
;; TODO
;; 1. Sorting in investigate dialog
;; 2. actual date range filtering in investigate dialog
;; 3. CSVs
;; 4. better date range / advanced mode for dialog
(defn fetch-ids [db {:keys [query-params route-params] :as request}]
(let [valid-clients (extract-client-ids (:clients request)
@@ -438,9 +443,9 @@ args
(mc/decode query-schema p main-transformer))
:action-buttons (fn [request]
[(com/button {:color :primary
:hx-get (bidi/path-for ssr-routes/only-routes
:hx-get (bidi/path-for ssr-routes/only-routes
::route/new)}
"Add journal entry")])
"Add journal entry")])
:row-buttons (fn [request entity]
[(when (and (= :invoice-status/unpaid (:invoice/status entity))
(can? (:identity request) {:subject :invoice :activity :delete}))
@@ -470,60 +475,86 @@ args
"Register"))
:entity-name "register"
:route ::route/table
:csv-route ::route/csv
:break-table (fn [request entity]
(cond
(cond
(= (-> request :query-params :sort first :name) "Vendor")
(or (-> entity :journal-entry/vendor :vendor/name)
"No vendor")
(= (-> request :query-params :sort first :name) "Source")
(or (-> entity :journal-entry/source)
"No external source")
:else nil))
:headers [{:key "client"
:page->csv-entities (fn [[journal-entries]]
(for [je journal-entries
jel (:journal-entry/line-items je)]
(merge jel je)))
:headers [{:key "id"
:name "Id"
:render-csv :db/id
:render-for #{:csv}}
{:key "client"
:name "Client"
:sort-key "client"
:hide? (fn [args]
(and (= (count (:clients args)) 1)
(= 1 (count (:client/locations (:client args))))))
:render (fn [x] [:div.flex.items-center.gap-2 (-> x :journal-entry/client :client/name) ])}
:render (fn [x] [:div.flex.items-center.gap-2 (-> x :journal-entry/client :client/name)])
:render-csv (fn [x] (-> x :journal-entry/client :client/name))}
{:key "vendor"
:name "Vendor"
:sort-key "vendor"
:render (fn [e] (or (-> e :journal-entry/vendor :vendor/name)
[:span.italic.text-gray-400 (-> e :journal-entry/alternate-description)]))}
[:span.italic.text-gray-400 (-> e :journal-entry/alternate-description)]))
:render-csv (fn [e] (or (-> e :journal-entry/vendor :vendor/name)
(-> e :journal-entry/alternate-description)))}
{:key "source"
:name "Source"
:sort-key "source"
:hide? (fn [args]
(not (:external? (:route-params args))))
:render :journal-entry/source}
{:key "external-id"
:render :journal-entry/source
:render-csv :journal-entry/source}
{:key "external-id"
:name "External Id"
:sort-key "external-id"
:class "max-w-[12rem]"
:hide? (fn [args]
(not (:external? (:route-params args))))
:render (fn [x] [:p.truncate ( :journal-entry/external-id x)])}
:render (fn [x] [:p.truncate (:journal-entry/external-id x)])
:render-csv :journal-entry/external-id}
{:key "date"
:sort-key "date"
:name "Date"
:show-starting "lg"
:render (fn [{:journal-entry/keys [date]}]
(some-> date (atime/unparse-local atime/normal-date)))}
{:key "account"
:name "Account"
:sort-key "account"
:class "text-right"
:render-csv #(or (-> % :journal-entry-line/account :account/name)
(-> % :journal-entry-line/account :bank-account/name))
:render-for #{:csv}}
{:key "debit"
:name "Debit"
:sort-key "debit"
:class "text-right"
:render (partial render-lines :journal-entry-line/debit)}
:render (partial render-lines :journal-entry-line/debit)
:render-csv :journal-entry-line/debit }
{:key "credit"
:name "Credit"
:sort-key "credit"
:class "text-right"
:render (partial render-lines :journal-entry-line/credit)}
:render (partial render-lines :journal-entry-line/credit)
:render-csv :journal-entry-line/credit }
{:key "links"
:name "Links"
:show-starting "lg"
@@ -542,13 +573,14 @@ args
{:link (-> i :journal-entry/original-entity :invoice/source-url)
:color :secondary
:content (str "File")}
(-> i :journal-entry/original-entity :transaction/description-original)
(conj
{:link (hu/url (bidi/path-for client-routes/routes
:transactions)
{:exact-match-id (:db/id (:journal-entry/original-entity i))})
:color :primary
:content (format "Transaction '%s'" (-> i :journal-entry/original-entity :transaction/description-original))}))))}]}))
:content (format "Transaction '%s'" (-> i :journal-entry/original-entity :transaction/description-original))}))))
:render-for #{:html}}]}))
(def row* (partial helper/row* grid-page))

View File

@@ -70,6 +70,7 @@
;; 2. Don't throw crazy errors when missing a field
;; 3. General cleanup of the patterns in run-balance-sheet
;; 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}]
(when (and (seq periods) client)

View File

@@ -26,17 +26,15 @@
:else
(str (:value c)))
cell-contents (if (:filters c)
(do
(println (:filters c))
(com/link {:hx-get (hu/url investigate-url
(cond-> {}
(:numeric-code (:filters c)) (assoc :numeric-code (into [] (:numeric-code (:filters c))))
(inst? (:date-range (:filters c))) (assoc :end-date (atime/unparse-local (coerce/to-date-time (:date-range (:filters c))) atime/normal-date))
(:end (:date-range (:filters c))) (assoc :end-date (atime/unparse-local (coerce/to-date-time (:end (:date-range (:filters c)))) atime/normal-date))
(:start (:date-range (:filters c))) (assoc :start-date (atime/unparse-local (coerce/to-date-time (:start (:date-range (:filters c)))) atime/normal-date))
(:client-id (:filters c)) (assoc :client-id (:client-id (:filters c))))
)}
cell-contents))
(com/link {:hx-get (hu/url investigate-url
(cond-> {}
(:numeric-code (:filters c)) (assoc :numeric-code (into [] (:numeric-code (:filters c))))
(inst? (:date-range (:filters c))) (assoc :end-date (atime/unparse-local (coerce/to-date-time (:date-range (:filters c))) atime/normal-date))
(:end (:date-range (:filters c))) (assoc :end-date (atime/unparse-local (coerce/to-date-time (:end (:date-range (:filters c)))) atime/normal-date))
(:start (:date-range (:filters c))) (assoc :start-date (atime/unparse-local (coerce/to-date-time (:start (:date-range (:filters c)))) atime/normal-date))
(:client-id (:filters c)) (assoc :client-id (:client-id (:filters c))))
)}
cell-contents)
cell-contents)]
[:td.px-4.py-2
(cond-> {:style (cond-> {:width (str width "em")}