glimpse can use locations

This commit is contained in:
2024-06-28 15:20:04 -07:00
parent 4aed529b3f
commit 49aec3ccf5
3 changed files with 52 additions and 22 deletions

View File

@@ -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)])

View File

@@ -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"