tweaks
This commit is contained in:
@@ -9,7 +9,8 @@
|
|||||||
:refer [entity-id ref->enum-schema wrap-schema-enforce]]
|
:refer [entity-id ref->enum-schema wrap-schema-enforce]]
|
||||||
[com.brunobonacci.mulog :as mu]
|
[com.brunobonacci.mulog :as mu]
|
||||||
[datomic.api :as dc]
|
[datomic.api :as dc]
|
||||||
[ring.middleware.json :refer [wrap-json-response]]))
|
[ring.middleware.json :refer [wrap-json-response]]
|
||||||
|
[auto-ap.datomic.accounts :as d-accounts]))
|
||||||
|
|
||||||
;; TODO this is basically duplicative of graphql version, make sure to keep in sync
|
;; TODO this is basically duplicative of graphql version, make sure to keep in sync
|
||||||
;; TODO use valid clients from request rather than stuff like assert-can-see-client
|
;; TODO use valid clients from request rather than stuff like assert-can-see-client
|
||||||
@@ -17,9 +18,13 @@
|
|||||||
(def search-pattern [:db/id
|
(def search-pattern [:db/id
|
||||||
:account/numeric-code
|
:account/numeric-code
|
||||||
:account/location
|
:account/location
|
||||||
|
:account/name
|
||||||
{:account/vendor-allowance [:db/ident]
|
{:account/vendor-allowance [:db/ident]
|
||||||
:account/default-allowance [:db/ident]
|
:account/default-allowance [:db/ident]
|
||||||
:account/invoice-allowance [:db/ident]}])
|
:account/invoice-allowance [:db/ident]
|
||||||
|
:account/client-overrides [:db/id
|
||||||
|
:account-client-override/name
|
||||||
|
{:account-client-override/client [:db/id :client/name]}]} ])
|
||||||
|
|
||||||
(defn search- [id query client]
|
(defn search- [id query client]
|
||||||
(let [client-part (if (some->> client (can-see-client? id))
|
(let [client-part (if (some->> client (can-see-client? id))
|
||||||
@@ -67,7 +72,9 @@
|
|||||||
(valid-allowances (-> a allowance :db/ident))
|
(valid-allowances (-> a allowance :db/ident))
|
||||||
(= (:db/id a) vendor-account))))
|
(= (:db/id a) vendor-account))))
|
||||||
(map (fn [[n a]]
|
(map (fn [[n a]]
|
||||||
{:label (str (:account/numeric-code a) " - " n)
|
{:label (str (:account/numeric-code a) " - " (if client-id
|
||||||
|
(:account/name (d-accounts/clientize a client-id))
|
||||||
|
n))
|
||||||
:value (:db/id a)
|
:value (:db/id a)
|
||||||
:location (:account/location a)
|
:location (:account/location a)
|
||||||
:warning (when (= :allowance/warn (-> a allowance :db/ident))
|
:warning (when (= :allowance/warn (-> a allowance :db/ident))
|
||||||
|
|||||||
@@ -17,15 +17,16 @@
|
|||||||
[auto-ap.ssr.svg :as svg]
|
[auto-ap.ssr.svg :as svg]
|
||||||
[auto-ap.ssr.utils :refer [apply-middleware-to-all-handlers check-allowance
|
[auto-ap.ssr.utils :refer [apply-middleware-to-all-handlers check-allowance
|
||||||
check-location-belongs clj-date-schema entity-id
|
check-location-belongs clj-date-schema entity-id
|
||||||
html-response modal-response money
|
html-response main-transformer modal-response
|
||||||
wrap-form-4xx-2 wrap-schema-enforce]]
|
money wrap-form-4xx-2 wrap-schema-enforce]]
|
||||||
[auto-ap.time :as atime]
|
[auto-ap.time :as atime]
|
||||||
[bidi.bidi :as bidi]
|
[bidi.bidi :as bidi]
|
||||||
[clj-time.coerce :as coerce]
|
[clj-time.coerce :as coerce]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[datomic.api :as dc]
|
[datomic.api :as dc]
|
||||||
[iol-ion.query :refer [dollars=]]
|
[iol-ion.query :refer [dollars=]]
|
||||||
[iol-ion.utils :refer [remove-nils]])
|
[iol-ion.utils :refer [remove-nils]]
|
||||||
|
[malli.core :as m])
|
||||||
(:import
|
(:import
|
||||||
[java.util UUID]))
|
[java.util UUID]))
|
||||||
|
|
||||||
@@ -33,20 +34,20 @@
|
|||||||
[:and
|
[:and
|
||||||
[:map
|
[:map
|
||||||
[:db/id {:optional true} [:maybe entity-id]]
|
[:db/id {:optional true} [:maybe entity-id]]
|
||||||
[:journal-entry/client [:entity-map {:pull [:db/id :client/name :client/locations]}]]
|
[:journal-entry/client {:optional false} [:entity-map {:pull [:db/id :client/name :client/locations] }]]
|
||||||
[:journal-entry/date clj-date-schema]
|
[:journal-entry/date clj-date-schema]
|
||||||
[:journal-entry/vendor {:optional true :default nil}
|
[:journal-entry/vendor {:optional false :default nil}
|
||||||
[:entity-map {:pull [:db/id :vendor/name]}]]
|
[:entity-map {:pull [:db/id :vendor/name] }]]
|
||||||
[:journal-entry/amount {:min 0.01}
|
[:journal-entry/amount {:min 0.01}
|
||||||
money]
|
money]
|
||||||
[:journal-entry/line-items
|
[:journal-entry/line-items
|
||||||
[:vector {:coerce? true}
|
[:vector {:coerce? true}
|
||||||
[:and
|
[:and
|
||||||
[:map
|
[:map
|
||||||
[:journal-entry-line/account [:and [:entity-map {:pull a/default-read}]
|
[:journal-entry-line/account [:and [:entity-map {:pull a/default-read }]
|
||||||
[:fn {:error/message "Not an allowed account."}
|
[:fn {:error/message "Not an allowed account."}
|
||||||
(fn check-allow [x]
|
(fn check-allow [x]
|
||||||
(check-allowance x :account/default-allowance))]]]
|
(check-allowance (:db/id x) :account/default-allowance))]]]
|
||||||
[:journal-entry-line/debit {:optional true :default nil} [:maybe money]]
|
[:journal-entry-line/debit {:optional true :default nil} [:maybe money]]
|
||||||
[:journal-entry-line/credit {:optional true :default nil} [:maybe money]]
|
[:journal-entry-line/credit {:optional true :default nil} [:maybe money]]
|
||||||
[:journal-entry-line/location :string]]
|
[:journal-entry-line/location :string]]
|
||||||
@@ -69,7 +70,6 @@
|
|||||||
(map :journal-entry-line/credit)
|
(map :journal-entry-line/credit)
|
||||||
(filter identity)
|
(filter identity)
|
||||||
(reduce + 0.0)))))]])
|
(reduce + 0.0)))))]])
|
||||||
|
|
||||||
(defn- account-typeahead*
|
(defn- account-typeahead*
|
||||||
[{:keys [name value client-id x-model]}]
|
[{:keys [name value client-id x-model]}]
|
||||||
[:div.flex.flex-col
|
[:div.flex.flex-col
|
||||||
@@ -92,7 +92,7 @@
|
|||||||
(com/select {:options (into [["" ""]]
|
(com/select {:options (into [["" ""]]
|
||||||
(cond account-location
|
(cond account-location
|
||||||
[[account-location account-location]]
|
[[account-location account-location]]
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(for [c (seq client-locations)]
|
(for [c (seq client-locations)]
|
||||||
[c c])))
|
[c c])))
|
||||||
@@ -109,7 +109,7 @@
|
|||||||
(pull-attr (dc/db conn) :client/locations))})))
|
(pull-attr (dc/db conn) :client/locations))})))
|
||||||
|
|
||||||
(defn- line-item-row*
|
(defn- line-item-row*
|
||||||
[account client-id client-locations]
|
[account client client-locations]
|
||||||
(com/data-grid-row
|
(com/data-grid-row
|
||||||
(-> {:x-data (hx/json {:accountId (or (:db/id (fc/field-value (:journal-entry-line/account account)))
|
(-> {:x-data (hx/json {:accountId (or (:db/id (fc/field-value (:journal-entry-line/account account)))
|
||||||
(fc/field-value (:journal-entry-line/account account)))
|
(fc/field-value (:journal-entry-line/account account)))
|
||||||
@@ -134,7 +134,7 @@
|
|||||||
:hx-get (str (bidi/path-for ssr-routes/only-routes ::route/account-typeahead))
|
:hx-get (str (bidi/path-for ssr-routes/only-routes ::route/account-typeahead))
|
||||||
:x-init "$watch('clientId', cid => $dispatch('changed', $data));"}]
|
:x-init "$watch('clientId', cid => $dispatch('changed', $data));"}]
|
||||||
(account-typeahead* {:value (fc/field-value)
|
(account-typeahead* {:value (fc/field-value)
|
||||||
:client-id client-id
|
:client-id (:db/id client)
|
||||||
:name (fc/field-name)
|
:name (fc/field-name)
|
||||||
:x-model "accountId"}))))
|
:x-model "accountId"}))))
|
||||||
(fc/with-field :journal-entry-line/location
|
(fc/with-field :journal-entry-line/location
|
||||||
@@ -149,9 +149,10 @@
|
|||||||
:hx-swap "outerHTML"
|
:hx-swap "outerHTML"
|
||||||
:hx-vals (format "js:{name: '%s', 'client-id': event.detail.clientId || '', 'account-id': event.detail.accountId || '', value: event.detail.location || ''}" (fc/field-name))
|
:hx-vals (format "js:{name: '%s', 'client-id': event.detail.clientId || '', 'account-id': event.detail.accountId || '', value: event.detail.location || ''}" (fc/field-name))
|
||||||
:hx-get (bidi/path-for ssr-routes/only-routes ::route/location-select)
|
:hx-get (bidi/path-for ssr-routes/only-routes ::route/location-select)
|
||||||
:x-init "$watch('clientId', cid => $dispatch('changed', $data)); $watch('accountId', cid => $dispatch('changed', $data) )"}]
|
:x-dispatch:changed "[clientId, accountId]"
|
||||||
|
#_#_:x-init "$watch('clientId', cid => $dispatch('changed', $data)); $watch('accountId', cid => $dispatch('changed', $data) )"}]
|
||||||
(location-select* {:name (fc/field-name)
|
(location-select* {:name (fc/field-name)
|
||||||
:account-location (:account/location (:account/location (:journal-entry-line/account @account)))
|
:account-location (:account/location (:journal-entry-line/account @account))
|
||||||
:client-locations client-locations
|
:client-locations client-locations
|
||||||
:x-model "location"
|
:x-model "location"
|
||||||
:value (fc/field-value)}))))
|
:value (fc/field-value)}))))
|
||||||
@@ -176,8 +177,8 @@
|
|||||||
|
|
||||||
(defn account-typeahead [{{:keys [name value client-id] :as qp} :query-params}]
|
(defn account-typeahead [{{:keys [name value client-id] :as qp} :query-params}]
|
||||||
(html-response (account-typeahead* {:name name
|
(html-response (account-typeahead* {:name name
|
||||||
:value value
|
:value (dc/pull (dc/db conn) a/default-read value)
|
||||||
:client-id client-id
|
:client-id client-id
|
||||||
:x-model "accountId"})))
|
:x-model "accountId"})))
|
||||||
|
|
||||||
(defn form* [request]
|
(defn form* [request]
|
||||||
@@ -260,7 +261,6 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn new [request]
|
(defn new [request]
|
||||||
(alog/peek ::FP (:form-params request))
|
|
||||||
(modal-response
|
(modal-response
|
||||||
(com/modal {:hx-target "this"
|
(com/modal {:hx-target "this"
|
||||||
:hx-indicator "this"}
|
:hx-indicator "this"}
|
||||||
|
|||||||
@@ -285,7 +285,7 @@
|
|||||||
(def pull-transformer
|
(def pull-transformer
|
||||||
(mt2/transformer {:decoders
|
(mt2/transformer {:decoders
|
||||||
{:entity-map
|
{:entity-map
|
||||||
{:compile (fn [schema _]
|
{:compile (fn [schema g]
|
||||||
(let [pull-expr (:pull (mc/properties schema))]
|
(let [pull-expr (:pull (mc/properties schema))]
|
||||||
(if pull-expr
|
(if pull-expr
|
||||||
(fn pull-data [m]
|
(fn pull-data [m]
|
||||||
@@ -469,7 +469,14 @@
|
|||||||
main-transformer)))
|
main-transformer)))
|
||||||
|
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(alog/warn ::validation-error :error e)
|
(alog/warn ::validation-error
|
||||||
|
:error e
|
||||||
|
::errors (-> e
|
||||||
|
(ex-data)
|
||||||
|
:data
|
||||||
|
:explain
|
||||||
|
(me/humanize {:errors (assoc me/default-errors
|
||||||
|
::mc/missing-key {:error/message {:en "required"}})})))
|
||||||
(throw (ex-info (->> (-> e
|
(throw (ex-info (->> (-> e
|
||||||
(ex-data)
|
(ex-data)
|
||||||
:data
|
:data
|
||||||
@@ -643,7 +650,8 @@
|
|||||||
{:entity-id entity-id
|
{:entity-id entity-id
|
||||||
:entity-map
|
:entity-map
|
||||||
(mc/-simple-schema {:type :entity-map
|
(mc/-simple-schema {:type :entity-map
|
||||||
:pred map?})
|
:pred map?
|
||||||
|
:type-properties { :error/message "required"}})
|
||||||
#_[:map {:name :entity-map} [:db/id nat-int?]]}))
|
#_[:map {:name :entity-map} [:db/id nat-int?]]}))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
@@ -666,15 +674,21 @@
|
|||||||
(handler (update-in request [:route-params] merge route-params))))
|
(handler (update-in request [:route-params] merge route-params))))
|
||||||
|
|
||||||
(defn check-allowance [account-id allowance-key]
|
(defn check-allowance [account-id allowance-key]
|
||||||
(let [allowance (allowance-key (dc/pull (dc/db conn) '[{[:account/invoice-allowance :xform iol-ion.query/ident] [:db/ident]
|
(let [account-id (if (map? account-id)
|
||||||
|
(:db/id account-id)
|
||||||
|
account-id)
|
||||||
|
allowance (allowance-key (dc/pull (dc/db conn) '[{[:account/invoice-allowance :xform iol-ion.query/ident] [:db/ident]
|
||||||
[:account/vendor-allowance :xform iol-ion.query/ident] [:db/ident]
|
[:account/vendor-allowance :xform iol-ion.query/ident] [:db/ident]
|
||||||
[:account/default-allowance :xform iol-ion.query/ident] [:db/ident]}]
|
[:account/default-allowance :xform iol-ion.query/ident] [:db/ident]}]
|
||||||
account-id))]
|
account-id))]
|
||||||
(not= :allowance/denied
|
(not= :allowance/denied
|
||||||
allowance)))
|
allowance)))
|
||||||
|
|
||||||
(defn check-location-belongs [location account]
|
(defn check-location-belongs [location account-id]
|
||||||
(let [account-location (pull-attr (dc/db conn) :account/location account)]
|
(let [account (if (map? account-id)
|
||||||
|
(:db/id account-id)
|
||||||
|
account-id)
|
||||||
|
account-location (pull-attr (dc/db conn) :account/location account)]
|
||||||
(when (and (seq account-location)
|
(when (and (seq account-location)
|
||||||
(not= location
|
(not= location
|
||||||
account-location))
|
account-location))
|
||||||
|
|||||||
Reference in New Issue
Block a user