diff --git a/resources/schema.edn b/resources/schema.edn index ce648d7a..6aeadeee 100644 --- a/resources/schema.edn +++ b/resources/schema.edn @@ -1760,6 +1760,11 @@ :db/tupleTypes [:db.type/string :db.type/double] :db/cardinality :db.cardinality/one} + {:db/ident :textract-invoice/location + :db/valueType :db.type/tuple + :db/tupleTypes [:db.type/string :db.type/string] + :db/cardinality :db.cardinality/one} + {:db/ident :textract-invoice/total-options :db/valueType :db.type/tuple :db/tupleTypes [:db.type/string :db.type/double] diff --git a/src/clj/auto_ap/ssr/invoice/glimpse.clj b/src/clj/auto_ap/ssr/invoice/glimpse.clj index d7df849c..46af3522 100644 --- a/src/clj/auto_ap/ssr/invoice/glimpse.clj +++ b/src/clj/auto_ap/ssr/invoice/glimpse.clj @@ -6,6 +6,7 @@ [auto-ap.datomic :refer [conn pull-attr]] [auto-ap.datomic.clients :as d-clients] [auto-ap.datomic.vendors :as d-vendors] + [auto-ap.datomic.invoices :as d-invoices] [auto-ap.graphql.utils :refer [extract-client-ids]] [auto-ap.logging :as alog] [auto-ap.solr :as solr] @@ -125,6 +126,7 @@ :total-options (seq total-options) :customer-identifier (first customer-identifier-options) :customer-identifier-options (seq customer-identifier-options) + :location [nil ""] :vendor-name (first vendor-name-options) :vendor-name-options (seq vendor-name-options) :date (first date-options) @@ -222,6 +224,21 @@ invoice_dropzone = new Dropzone(\"#invoice\", { (format "%s (%s)" client-name customer-identifier)) :->value (fn [[client-identifier [id client-name]]] id)}) + +[:div.col-span-2.col-start-1 + (com/field {:label "Location (blank will use default location)"} + (com/text-input {:name "location" + :value (-> textract-invoice + :textract-invoice/location + second) + :placeholder "Location"}))] + #_(pill-list* {:selected (:textract-invoice/location textract-invoice) + :options (:textract-invoice/location-options textract-invoice) + :id (:db/id textract-invoice) + :field "location" + :->text (fn [[_ amount]] + (str amount))}) + [:div.col-span-6 (com/field {:label "Vendor"} (com/text-input {:name (path->name [:invoice/vendor]) @@ -342,37 +359,44 @@ invoice_dropzone = new Dropzone(\"#invoice\", { (let [[_ [vendor-id]] (:textract-invoice/vendor-name textract-invoice) [_ [client-id]] (:textract-invoice/customer-identifier textract-invoice) [_ total] (:textract-invoice/total textract-invoice) + [_ location] (:textract-invoice/location textract-invoice) [_ date] (:textract-invoice/date textract-invoice) [_ invoice-number] (:textract-invoice/invoice-number textract-invoice) vendor (dc/pull (dc/db conn) d-vendors/default-read vendor-id) - location (when client-id - (->> (dc/pull (dc/db conn) '[:client/locations] client-id) - :client/locations - first)) + location (when (and client-id) + (or location + (->> (dc/pull (dc/db conn) '[:client/locations] client-id) + :client/locations + first))) due (and (:vendor/terms vendor) (time/plus (coerce/to-date-time date) (time/days (d-vendors/terms-for-client-id vendor client-id)))) scheduled-payment (and (d-vendors/automatically-paid-for-client-id? vendor client-id) due)] + (alog/peek ::temp-textract-invoice textract-invoice) (when (and client-id date invoice-number vendor-id total) - (cond-> {:db/id (random-tempid) - :invoice/client client-id - :invoice/client-identifier (first (:textract-invoice/customer-identifier textract-invoice)) - :invoice/vendor vendor-id - :invoice/invoice-number invoice-number - :invoice/total total - :invoice/date date - - :invoice/location location - :invoice/import-status :import-status/imported - :invoice/outstanding-balance total - :invoice/status :invoice-status/unpaid} - scheduled-payment (assoc :invoice/scheduled-payment (some-> scheduled-payment coerce/to-date)) - (instance? org.joda.time.DateTime due) (assoc :invoice/due (some-> due coerce/to-date)) - (instance? org.joda.time.DateTime scheduled-payment) (assoc :invoice/scheduled-payment (some-> scheduled-payment coerce/to-date))))))) + (alog/peek ::TEMP-invoice + (cond-> {:db/id (random-tempid) + :invoice/client client-id + :invoice/client-identifier (first (:textract-invoice/customer-identifier textract-invoice)) + :invoice/vendor vendor-id + :invoice/invoice-number invoice-number + :invoice/total total + :invoice/date date + + :invoice/location location + :invoice/import-status :import-status/imported + :invoice/outstanding-balance total + :invoice/status :invoice-status/unpaid} + scheduled-payment (assoc :invoice/scheduled-payment (some-> scheduled-payment coerce/to-date)) + (instance? org.joda.time.DateTime due) (assoc :invoice/due (some-> due coerce/to-date)) + (instance? org.joda.time.DateTime scheduled-payment) (assoc :invoice/scheduled-payment (some-> scheduled-payment coerce/to-date)) + true d-invoices/code-invoice)))))) -(defn update-textract-invoice- [id {:strs [date total invoice-number client vendor]}] - @(dc/transact-async conn [[:upsert-entity (cond-> {:db/id id} +(defn update-textract-invoice- [id {:strs [date total invoice-number client vendor location]}] + @(dc/transact-async conn [[:upsert-entity (cond-> {:db/id id + :textract-invoice/location [nil (not-empty location)]} date (assoc :textract-invoice/date [date (coerce/to-date (atime/parse date atime/normal-date))]) + total (assoc :textract-invoice/total [total (Double/parseDouble total)]) invoice-number (assoc :textract-invoice/invoice-number [invoice-number invoice-number]) client (assoc :textract-invoice/customer-identifier [(pull-attr (dc/db conn) :client/name (Long/parseLong client)) (Long/parseLong client)]) diff --git a/src/clj/auto_ap/ssr/invoices.clj b/src/clj/auto_ap/ssr/invoices.clj index 41a924d6..e89347bc 100644 --- a/src/clj/auto_ap/ssr/invoices.clj +++ b/src/clj/auto_ap/ssr/invoices.clj @@ -492,7 +492,8 @@ (and (= (count (:clients args)) 1) (= 1 (count (:client/locations (:client args)))))) :render (fn [x] [:div.flex.items-center.gap-2 (-> x :invoice/client :client/name) - (com/pill {:color :primary} (-> x :invoice/location)) ])} + (map #(com/pill {:color :primary} (-> % :invoice-expense-account/location)) + (:invoice/expense-accounts x)) ])} {:key "vendor" :name "Vendor" :sort-key "vendor"