cleans up grids

This commit is contained in:
2024-11-18 19:41:54 -08:00
parent ad06418a69
commit a8c7c7eb8e
31 changed files with 842 additions and 714 deletions

View File

@@ -131,7 +131,7 @@
[:div {:x-data (hx/json { "showTable" false})}
[:form {:hx-post (bidi.bidi/path-for ssr-routes/only-routes ::route/external-import-import)
:autocomplete "off" }
:autocomplete "off"}
(when (:just-parsed? request)
[:div (hx/htmx-transition-appear {:class "bg-green-50 text-green-700 rounded p-4 m-2 max-w-screen-2xl"})
(format "Your data has been parsed. %,d rows found." (count (fc/field-value)))])
@@ -237,20 +237,20 @@
(com/button {:color :primary} "Import")])]]])))])
(defn external-import-text-form* [request]
(fc/start-form
(or (:form-params request) {}) (:form-errors request)
[:form#parse-form {:x-data (hx/json {"clipboard" nil})
:hx-post (bidi.bidi/path-for ssr-routes/only-routes ::route/external-import-parse)
:hx-swap "outerHTML"
:hx-trigger "pasted"}
(fc/with-field :table
[:div
(com/errors {:errors (fc/field-errors)} )
(com/text-area {:x-model "clipboard" :name (fc/field-name) :value (fc/field-value) :class "hidden"})])
(com/button {"@click.prevent" "clipboard = (await getclpboard()); $nextTick(() => $dispatch('pasted'))"
"x-on:paste.document" "clipboard = (await getclpboard()); console.log(clipboard); $nextTick(() => $dispatch('pasted'))" }
"Load from clipboard")])
)
(fc/start-form
(or (:form-params request) {}) (:form-errors request)
[:form#parse-form {:x-data (hx/json {"clipboard" nil})
:hx-post (bidi.bidi/path-for ssr-routes/only-routes ::route/external-import-parse)
:hx-swap "outerHTML"
:hx-trigger "pasted"}
(fc/with-field :table
[:div
(com/errors {:errors (fc/field-errors)})
(com/text-area {:x-model "clipboard" :name (fc/field-name) :value (fc/field-value) :class "hidden"})])
(com/button {"@click.prevent" "clipboard = (await getclpboard()); $nextTick(() => $dispatch('pasted'))"
"x-on:paste.document" "clipboard = (await getclpboard()); console.log(clipboard); $nextTick(() => $dispatch('pasted'))"}
"Load from clipboard")]))
(defn external-import-form* [request]
[:div#forms {:hx-target "this"
:hx-swap "outerHTML"}
@@ -291,8 +291,8 @@
var r = await c[0].getType('text/plain')
console.log(r)
return await r.text()
}")
]
}")]
(external-import-form* request)
[:div #_{:x-data (hx/json {:selected [] :all_selected false :type (:entity-name grid-spec)})
"x-on:copy" "if (selected.length > 0) {$clipboard(JSON.stringify({'type': type, 'selected': selected}))}"
@@ -307,14 +307,14 @@
"External Ledger Import"
#_(if (string? (:title grid-spec))
(:title grid-spec)
((:title grid-spec) request)))
)
((:title grid-spec) request))))
(defn trim-header [t]
(if (->> t
first
(map clojure.string/lower-case )
(map clojure.string/lower-case)
(filter #{"id" "client" "source" "vendor" "date" "account" "location" "debit"})
seq)
(drop 1 t)
@@ -336,34 +336,34 @@
(def parse-form-schema (mc/schema
[:map
[:table {:min 1 :error/message "Clipboard should contain rows to import"
:decode/string tsv->import-data }
:decode/string tsv->import-data}
[:vector {:coerce? true}
[:map { :decode/arbitrary (fn [t]
(if (vector? t)
(into {} (map vector [:external-id :client-code :source :vendor-name :date :account-code :location :debit :credit] t))
t))}
[:external-id [:string {:title "external id"
:min 1
:decode/string strip}]]
[:client-code [:string {:title "client code"
:min 1
:decode/string strip}]]
[:source [:string {:title "source"
:min 1
:decode/string strip}]]
[:vendor-name [:string {:min 1 :decode/string strip}]]
[:date [:and clj-date-schema
[:any {:title "date"}]]]
[:account-code account-schema]
[:external-id [:string {:title "external id"
:min 1
:decode/string strip}]]
[:client-code [:string {:title "client code"
:min 1
:decode/string strip}]]
[:source [:string {:title "source"
:min 1
:decode/string strip}]]
[:vendor-name [:string {:min 1 :decode/string strip}]]
[:date [:and clj-date-schema
[:any {:title "date"}]]]
[:account-code account-schema]
[:location [:string { :min 1
:max 2
:decode/string strip}]]
[:debit [:maybe money]]
[:credit [:maybe money]]]]
[:location [:string { :min 1
:max 2
:decode/string strip}]]
[:debit [:maybe money]]
[:credit [:maybe money]]
]]
#_[:string {:decode/string tsv->import-data
:error/message "Clipboard should contain rows to import"}]] ]))
:error/message "Clipboard should contain rows to import"}]]]))
@@ -407,19 +407,19 @@
(not (t/equal? (:date entry)
(coerce/to-date-time locked-until)))))
(all-row-error (str "Client's data is locked until " locked-until))
(not (dollars= (reduce (fnil + 0.0 0.0) 0.0 (map :debit (:line-items entry)))
(reduce (fnil + 0.0 0.0) 0.0 (map :credit (:line-items entry)))))
(all-row-error (str "Debits '"
(reduce (fnil + 0.0 0.0) 0 (map :debit (:line-items entry)))
"' and credits '"
(reduce (fnil + 0.0 0.0) 0 (map :credit (:line-items entry)))
"' do not add up."))
(dollars= (reduce (fnil + 0.0 0.0) 0.0 (map :debit (:line-items entry)))
0.0)
(all-row-error (str "Cannot have ledger entries that total $0.00") :warn)
(not (dollars= (reduce (fnil + 0.0 0.0) 0.0 (map :debit (:line-items entry)))
(reduce (fnil + 0.0 0.0) 0.0 (map :credit (:line-items entry)))))
(all-row-error (str "Debits '"
(reduce (fnil + 0.0 0.0) 0 (map :debit (:line-items entry)))
"' and credits '"
(reduce (fnil + 0.0 0.0) 0 (map :credit (:line-items entry)))
"' do not add up."))
(dollars= (reduce (fnil + 0.0 0.0) 0.0 (map :debit (:line-items entry)))
0.0)
(all-row-error (str "Cannot have ledger entries that total $0.00") :warn)
:else
entry)]
:else
entry)]
(update
entry
:line-items
@@ -476,7 +476,7 @@
(defn table->entries [table all-vendors all-accounts client-locked-lookup all-client-bank-accounts all-client-locations]
(let [lines-with-indexes (for [[i l] (map vector (range) table)]
(assoc l :index i)) ]
(assoc l :index i))]
(into []
(for [
[_ lines] (group-by line->id lines-with-indexes)
@@ -629,9 +629,9 @@
good-entries (filter (fn [e] (and (not (:error (entry-error-types e))) (not (:warn (entry-error-types e))))) entries)
bad-entries (filter (fn [e] (:error (entry-error-types e))) entries)
form-errors (reduce (fn [acc [path m status]]
(update-in acc path conj [ m status]))
{}
errors)
(update-in acc path conj [ m status]))
{}
errors)
_ (when (seq bad-entries)
(alog/info ::ledger-import-errors :errors errors)
(throw+ (ex-info "ledger import errors"
@@ -690,13 +690,13 @@
(merge
(apply-middleware-to-all-handlers
(->
{::route/all-page (-> (helper/page-route grid-page :parse-query-params? false)
{::route/all-page (-> (helper/page-route grid-page)
(wrap-implied-route-param :external? false))
::route/external-page (-> (helper/page-route grid-page :parse-query-params? false)
::route/external-page (-> (helper/page-route grid-page)
(wrap-implied-route-param :external? true))
::route/table (helper/table-route grid-page :parse-query-params? false)
::route/csv (helper/csv-route grid-page :parse-query-params? false)
::route/table (helper/table-route grid-page)
::route/csv (helper/csv-route grid-page)
::route/external-import-page external-import-page
::route/bank-account-filter bank-account-filter
::route/external-import-parse (-> external-import-parse
@@ -719,8 +719,8 @@
(wrap-schema-enforce :hx-schema query-schema)
(wrap-must {:activity :import :subject :ledger})
(wrap-client-redirect-unauthenticated))))
balance-sheet/key->handler
profit-and-loss/key->handler
cash-flows/key->handler
investigate/key->handler
new/key->handler))
balance-sheet/key->handler
profit-and-loss/key->handler
cash-flows/key->handler
investigate/key->handler
new/key->handler))