Adds ability to filter by category, adds invoice allowance as an account option

This commit is contained in:
2023-01-31 08:51:10 -08:00
parent d94aac317e
commit e13a32b0aa
12 changed files with 199 additions and 134 deletions

View File

@@ -7,10 +7,13 @@
[clojure.tools.logging :as log])) [clojure.tools.logging :as log]))
(defn <-datomic [a] (defn <-datomic [a]
(update a :account/applicability :db/ident)) (-> a
(update :account/applicability :db/ident)
(update :account/invoice-allowance :db/ident)))
(def default-read ['* {:account/type [:db/ident :db/id] (def default-read ['* {:account/type [:db/ident :db/id]
:account/applicability [:db/ident :db/id] :account/applicability [:db/ident :db/id]
:account/invoice-allowance [:db/ident :db/id]
:account/client-overrides [:db/id :account/client-overrides [:db/id
:account-client-override/name :account-client-override/name
{:account-client-override/client [:db/id :client/name]}]}]) {:account-client-override/client [:db/id :client/name]}]}])

View File

@@ -166,6 +166,17 @@
{:db/id i {:db/id i
:account-client-override/search-terms n})))]) :account-client-override/search-terms n})))])
(defn backfill-account-options [conn]
[(->> (d/q '[:find [?a ...]
:in $
:where [?a :account/name]]
(d/db conn))
(map (fn [i]
{:db/id i
:account/invoice-allowance :allowance/allowed})))
])
(defn migrate [conn] (defn migrate [conn]
(let [ (let [
norms-map (merge {:auto-ap/base-schema {:txes auto-ap.datomic/base-schema} norms-map (merge {:auto-ap/base-schema {:txes auto-ap.datomic/base-schema}
@@ -529,7 +540,23 @@
:db/fulltext true}]] :db/fulltext true}]]
:requires [:auto-ap/add-account-overrides]} :requires [:auto-ap/add-account-overrides]}
:auto-ap/add-search-terms-accounts {:txes-fn `add-account-search-terms :auto-ap/add-search-terms-accounts {:txes-fn `add-account-search-terms
:requires [:auto-ap/fulltext-accounts]}} :requires [:auto-ap/fulltext-accounts]}
:auto-ap/add-account-options {:txes [[{:db/ident :account/invoice-allowance
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "Whether this account can be used for invoices"}
{:db/ident :allowance/allowed
:db/doc "Allowed to be used"}
{:db/ident :allowance/denied
:db/doc "Denied usage"}
{:db/ident :allowance/warn
:db/doc "Warn on usage"}
{:db/ident :allowance/admin-only
:db/doc "Only admins can use it"}
:requires [:auto-ap/add-search-terms-accounts]]]}
:auto-ap/backfill-account-options {:txes-fn `backfill-account-options
:requires [:auto-ap/add-account-options]}}

View File

@@ -63,6 +63,12 @@
'[?client-id :client/code ?client-code]]} '[?client-id :client/code ?client-code]]}
:args [(:client-code args)]}) :args [(:client-code args)]})
(:category args)
(merge-query {:query {:in ['?category]
:where ['[?e :sales-order/line-items ?li]
'[?li :order-line-item/category ?category]]}
:args [(:category args)]})
(:processor args) (:processor args)
(merge-query {:query {:in ['?processor] (merge-query {:query {:in ['?processor]
:where ['[?e :sales-order/charges ?chg] :where ['[?e :sales-order/charges ?chg]

View File

@@ -246,6 +246,7 @@
:account {:fields {:id {:type :id} :account {:fields {:id {:type :id}
:numeric_code {:type 'Int} :numeric_code {:type 'Int}
:invoice_allowance {:type :allowance}
:type {:type :ident} :type {:type :ident}
:applicability {:type :applicability} :applicability {:type :applicability}
:account_set {:type 'String} :account_set {:type 'String}
@@ -500,6 +501,7 @@
{:fields {:id {:type :id} {:fields {:id {:type :id}
:type {:type :account_type} :type {:type :account_type}
:applicability {:type :applicability} :applicability {:type :applicability}
:invoice_allowance {:type :allowance}
:numeric_code {:type 'Int} :numeric_code {:type 'Int}
:location {:type 'String} :location {:type 'String}
:account_set {:type 'String} :account_set {:type 'String}
@@ -517,6 +519,10 @@
:integration_state {:values [{:enum-value :failed} :integration_state {:values [{:enum-value :failed}
{:enum-value :success} {:enum-value :success}
{:enum-value :unauthorized}]} {:enum-value :unauthorized}]}
:allowance {:values [{:enum-value :allowed}
{:enum-value :denied}
{:enum-value :warn}
{:enum-value :admin_only}]}
:tin_type {:values [{:enum-value :ein} :tin_type {:values [{:enum-value :ein}
{:enum-value :ssn}]} {:enum-value :ssn}]}
:type_1099 {:values [{:enum-value :none} :type_1099 {:values [{:enum-value :none}

View File

@@ -30,7 +30,7 @@
(->graphql (d-accounts/clientize result (:client_id args))))) (->graphql (d-accounts/clientize result (:client_id args)))))
(defn upsert-account [context args _] (defn upsert-account [context args _]
(let [{{:keys [id client-overrides numeric-code location applicability account-set name type]} :account} (<-graphql args)] (let [{{:keys [id client-overrides numeric-code location applicability account-set name invoice-allowance type]} :account} (<-graphql args)]
(when-not id (when-not id
(when (seq (d/query {:query {:find ['?e] (when (seq (d/query {:query {:find ['?e]
:in '[$ ?account-set ?numeric-code] :in '[$ ?account-set ?numeric-code]
@@ -51,6 +51,8 @@
:account/type (keyword "account-type" (clojure.core/name type)) :account/type (keyword "account-type" (clojure.core/name type))
:account/applicability (or (enum->keyword applicability "account-applicability") :account/applicability (or (enum->keyword applicability "account-applicability")
:account-applicability/global) :account-applicability/global)
:account/invoice-allowance (some-> invoice-allowance (enum->keyword "allowance"))
:account/account-set account-set :account/account-set account-set
:account/location location :account/location location
:account/numeric-code (when-not id :account/numeric-code (when-not id

View File

@@ -76,6 +76,7 @@
:total_gte {:type :money} :total_gte {:type :money}
:type_name {:type 'String} :type_name {:type 'String}
:processor {:type :processor} :processor {:type :processor}
:category {:type 'String}
:start {:type 'Int} :start {:type 'Int}
:per_page {:type 'Int} :per_page {:type 'Int}
:sort {:type '(list :sort_item)}} :sort {:type '(list :sort_item)}}

View File

@@ -381,11 +381,12 @@
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn tx-detail [i] (defn tx-detail [i]
(map (juxt :e #(d/ident (d/db (d/connect uri)) (:a %)) :v :added?) (map (juxt :e #(d/ident (d/db (d/connect uri)) (:a %)) :v :added)
(:data (first (:data (first
(d/tx-range (d/log (d/connect uri)) (d/tx-range (d/log (d/connect uri))
i i
(inc i)))))) (inc i))))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn tx-range-detail [i] (defn tx-range-detail [i]
(map (juxt :e #(d/ident (d/db (d/connect uri)) (:a %)) :v) (map (juxt :e #(d/ident (d/db (d/connect uri)) (:a %)) :v)

View File

@@ -171,8 +171,7 @@
"1099 data entry is now ready!"]] "1099 data entry is now ready!"]]
(when (> (count @clients) 1) (when (> (count @clients) 1)
[client-dropdown] [client-dropdown])])]
)])]
(when-not is-initial-loading (when-not is-initial-loading
[login-dropdown])] [login-dropdown])]

View File

@@ -16,7 +16,7 @@
[reagent.core :as reagent] [reagent.core :as reagent]
[vimsical.re-frame.fx.track :as track])) [vimsical.re-frame.fx.track :as track]))
(def default-read [:numeric-code :name :location :type :account_set :applicability :id [:client-overrides [:name [:client [:name :id]]]]]) (def default-read [:numeric-code :name :location :type :account_set :applicability :invoice-allowance :id [:client-overrides [:name [:client [:name :id]]]]])

View File

@@ -15,14 +15,16 @@
(def types [:dividend :expense :asset :liability :equity :revenue]) (def types [:dividend :expense :asset :liability :equity :revenue])
(def applicabilities [:global :optional :customized]) (def applicabilities [:global :optional :customized])
(def allowances [:allowed :denied :warn :admin-only])
(re-frame/reg-sub (re-frame/reg-sub
::request ::request
:<- [::forms/form ::form] :<- [::forms/form ::form]
(fn [{{:keys [id location type client-overrides applicability numeric-code name account-set]} :data}] (fn [{{:keys [id location type client-overrides applicability invoice-allowance numeric-code name account-set]} :data}]
{:id id {:id id
:type (keyword type) :type (keyword type)
:applicability (keyword applicability) :applicability (keyword applicability)
:invoice-allowance (keyword invoice-allowance)
:location (if (clojure.string/blank? location) :location (if (clojure.string/blank? location)
nil nil
location) location)
@@ -64,7 +66,7 @@
:operation/name "UpsertAccount"} :operation/name "UpsertAccount"}
:venia/queries [{:query/data [:upsert-account :venia/queries [{:query/data [:upsert-account
{:account request} {:account request}
[:id :type :name :account-set :numeric-code :location :applicability [:client-overrides [:name :id [:client [:id :name]]]]]]}]} [:id :type :name :account-set :numeric-code :location :applicability :invoice-allowance [:client-overrides [:name :id [:client [:id :name]]]]]]}]}
:on-success [::edited] :on-success [::edited]
:on-error [::forms/save-error ::form]}}))) :on-error [::forms/save-error ::form]}})))
@@ -81,6 +83,7 @@
[:type [:enum :dividend :expense :asset :liability :equity :revenue]] [:type [:enum :dividend :expense :asset :liability :equity :revenue]]
[:location {:optional true} [:maybe :string]] [:location {:optional true} [:maybe :string]]
[:applicability [:enum :global :optional :customized]] [:applicability [:enum :global :optional :customized]]
[:invoice-allowance [:enum :allowed :denied :warn :admin-only]]
[:client-overrides {:optional true} [:client-overrides {:optional true}
[:maybe [:sequential account-customization-schema]]]])) [:maybe [:sequential account-customization-schema]]]]))
@@ -119,6 +122,15 @@
"Location" "Location"
[:input.input.known-field.location {:type "text"}]] [:input.input.known-field.location {:type "text"}]]
[form-builder/field-v2 {:field :invoice-allowance}
"Invoice Allowance"
[com/select-field {:options (map (fn [l]
[l
(str/capitalize (name l))])
allowances)
:allow-nil? true
:keywordize? true}]]
[form-builder/section {:title "Client"} [form-builder/section {:title "Client"}
[:h2.subtitle "Client"] [:h2.subtitle "Client"]
[form-builder/field-v2 {:field :applicability} [form-builder/field-v2 {:field :applicability}

View File

@@ -26,6 +26,7 @@
:sort (:sort params) :sort (:sort params)
:per-page (:per-page params) :per-page (:per-page params)
:type-name (:type-name params) :type-name (:type-name params)
:category (:category params)
:total-gte (:amount-gte (:total-range params)) :total-gte (:amount-gte (:total-range params))
:total-lte (:amount-lte (:total-range params)) :total-lte (:amount-lte (:total-range params))
:date-range (:date-range params) :date-range (:date-range params)

View File

@@ -1,12 +1,14 @@
(ns auto-ap.views.pages.pos.side-bar (ns auto-ap.views.pages.pos.side-bar
(:require [auto-ap.routes :as routes] (:require
[auto-ap.routes :as routes]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.views.utils :refer [active-when dispatch-event]]
[auto-ap.views.components.date-range-filter :refer [date-range-filter]] [auto-ap.views.components.date-range-filter :refer [date-range-filter]]
[auto-ap.views.components.number-filter :refer [number-filter]] [auto-ap.views.components.number-filter :refer [number-filter]]
[auto-ap.views.pages.data-page :as data-page]
[auto-ap.views.utils
:refer [active-when dispatch-event dispatch-value-change]]
[bidi.bidi :as bidi] [bidi.bidi :as bidi]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]))
[auto-ap.views.pages.data-page :as data-page]))
(defn side-bar [{:keys [data-page]}] (defn side-bar [{:keys [data-page]}]
(let [ap @(re-frame/subscribe [::subs/active-page])] (let [ap @(re-frame/subscribe [::subs/active-page])]
@@ -92,7 +94,12 @@
[:a.panel-block {:on-click (dispatch-event [::data-page/filter-changed data-page :processor "na"])} [:a.panel-block {:on-click (dispatch-event [::data-page/filter-changed data-page :processor "na"])}
[:span.panel-icon #_[:img.level-item {:src "/img/grubhub.png"}]] [:span.panel-icon #_[:img.level-item {:src "/img/grubhub.png"}]]
"No Processor"] "No Processor"]
]]]) ]]
[:p.menu-label "Category"]
[:div.field
[:div.control [:input.input {:placeholder "Fries"
:value @(re-frame/subscribe [::data-page/filter data-page :category])
:on-change (dispatch-value-change [::data-page/filter-changed data-page :category])} ]]]])
(when-let [exact-match-id @(re-frame/subscribe [::data-page/filter data-page :exact-match-id])] (when-let [exact-match-id @(re-frame/subscribe [::data-page/filter data-page :exact-match-id])]
[:div [:div