invoice tweaks.
This commit is contained in:
@@ -48,6 +48,8 @@
|
|||||||
(catch Exception e
|
(catch Exception e
|
||||||
(alog/warn ::cant-parse-value :error e :raw value))))))
|
(alog/warn ::cant-parse-value :error e :raw value))))))
|
||||||
{:vendor-code (:vendor template)
|
{:vendor-code (:vendor template)
|
||||||
|
:template (str (:vendor template) " - selected because it matched "
|
||||||
|
(pr-str (:keywords template)))
|
||||||
:text text
|
:text text
|
||||||
:full-text full-text}))])))
|
:full-text full-text}))])))
|
||||||
|
|
||||||
@@ -86,7 +88,8 @@
|
|||||||
:vendor-code (-> (vendors/best-match (get i "vendor_identifier") )
|
:vendor-code (-> (vendors/best-match (get i "vendor_identifier") )
|
||||||
(get "label"))
|
(get "label"))
|
||||||
:total (get i "total")
|
:total (get i "total")
|
||||||
:invoice-number (get i "invoice_number")})
|
:invoice-number (get i "invoice_number")
|
||||||
|
:template "None found - defaulting to ChatGPT"})
|
||||||
)
|
)
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(alog/warn ::glimpse2-not-work :error e)
|
(alog/warn ::glimpse2-not-work :error e)
|
||||||
|
|||||||
@@ -118,11 +118,21 @@
|
|||||||
{:vendor "Don Vito Ozuna Food Corp"
|
{:vendor "Don Vito Ozuna Food Corp"
|
||||||
:keywords [#"408-465-2010"]
|
:keywords [#"408-465-2010"]
|
||||||
:extract {:date #"([0-9]+/[0-9]+/[0-9]+)"
|
:extract {:date #"([0-9]+/[0-9]+/[0-9]+)"
|
||||||
:customer-identifier #"To:[^\n]*\n\s+([A-Za-z' ]+)\s{2}"
|
:customer-identifier #"Bill To.*?\n(.*?)\s{2,}"
|
||||||
:invoice-number #"(?:[0-9]+/[0-9]+/[0-9]+)\s{2,}(\d+)"
|
:invoice-number #"(?:[0-9]+/[0-9]+/[0-9]+)\s{2,}(\d+)"
|
||||||
:total #"Please remit payment to\s{2,}\$([\-0-9.]+)"}
|
:total #"Please remit payment to\s{2,}\$([\-0-9.]+)"}
|
||||||
:parser {:date [:clj-time "MM/dd/yyyy"]} }
|
:parser {:date [:clj-time "MM/dd/yyyy"]} }
|
||||||
|
|
||||||
|
;; DON VITO STATEMENT
|
||||||
|
{:vendor "Don Vito Ozuna Food Corp"
|
||||||
|
:keywords [#"Don Vito Ozuna Food Corp.*?\n.*?Statement"]
|
||||||
|
:extract {:date #"([0-9]+/[0-9]+/[0-9]+)"
|
||||||
|
:customer-identifier #"To:.*?\n\s*(.*)?\s{2,}"
|
||||||
|
:invoice-number #"INV #(\d+)"
|
||||||
|
:total #"Amount \$([\d\-\.]+?)\.\s{2,}"}
|
||||||
|
:parser {:date [:clj-time "MM/dd/yyyy"]}
|
||||||
|
:multi #"\n"
|
||||||
|
:multi-match? #"\d+/\d+/\d+.*?INV"}
|
||||||
|
|
||||||
;; PFG - LEDYARD
|
;; PFG - LEDYARD
|
||||||
{:vendor "Performance Food Group - LEDYARD"
|
{:vendor "Performance Food Group - LEDYARD"
|
||||||
@@ -223,7 +233,7 @@
|
|||||||
|
|
||||||
;; Cheetah
|
;; Cheetah
|
||||||
{:vendor "Cheetah"
|
{:vendor "Cheetah"
|
||||||
:keywords [#"Delivery date: [\d\-]+\s{2,}Payment"]
|
:keywords [#"Delivery date: [\d\-]+\s{2,}"]
|
||||||
:extract {:date #"Delivery date: ([0-9\-]+)"
|
:extract {:date #"Delivery date: ([0-9\-]+)"
|
||||||
:customer-identifier #"Shipping.*\n(.*)"
|
:customer-identifier #"Shipping.*\n(.*)"
|
||||||
:invoice-number #"Invoice #: (\d+)"
|
:invoice-number #"Invoice #: (\d+)"
|
||||||
|
|||||||
@@ -46,8 +46,8 @@
|
|||||||
|
|
||||||
value (str "20" year "-" month "-" day) ]
|
value (str "20" year "-" month "-" day) ]
|
||||||
(try
|
(try
|
||||||
(reduced (time/from-time-zone (f/parse (f/formatter format) value)
|
(time/from-time-zone (f/parse (f/formatter format) value)
|
||||||
(time/time-zone-for-id "America/Los_Angeles")))
|
(time/time-zone-for-id "America/Los_Angeles"))
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(alog/warn ::cant-parse-date :error e :raw-value (str value))
|
(alog/warn ::cant-parse-date :error e :raw-value (str value))
|
||||||
nil))))
|
nil))))
|
||||||
|
|||||||
@@ -684,7 +684,7 @@
|
|||||||
(:db-after tx)
|
(:db-after tx)
|
||||||
(map :e (:tx-data tx))))
|
(map :e (:tx-data tx))))
|
||||||
(throw (ex-info "No new invoices found."
|
(throw (ex-info "No new invoices found."
|
||||||
{})))
|
{:template (:template (first imports))})))
|
||||||
tx)))
|
tx)))
|
||||||
|
|
||||||
(defn import-internal [tempfile filename force-client force-location force-vendor identity]
|
(defn import-internal [tempfile filename force-client force-location force-vendor identity]
|
||||||
@@ -707,7 +707,18 @@
|
|||||||
:source-url (str "https://" (:data-bucket env)
|
:source-url (str "https://" (:data-bucket env)
|
||||||
"/"
|
"/"
|
||||||
s3-location))))]
|
s3-location))))]
|
||||||
(import-uploaded-invoice identity imports))
|
(try
|
||||||
|
|
||||||
|
(import-uploaded-invoice identity imports)
|
||||||
|
(catch Exception e
|
||||||
|
(alog/warn ::couldnt-import-upload
|
||||||
|
:error e
|
||||||
|
:template (:template ( first imports)))
|
||||||
|
(throw (ex-info (ex-message e)
|
||||||
|
{:template (:template ( first imports))
|
||||||
|
:sample (first imports)}
|
||||||
|
e))))
|
||||||
|
imports)
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(alog/warn ::couldnt-import-upload
|
(alog/warn ::couldnt-import-upload
|
||||||
:error e)
|
:error e)
|
||||||
@@ -722,14 +733,17 @@
|
|||||||
results (reduce
|
results (reduce
|
||||||
(fn [result {:keys [filename tempfile]}]
|
(fn [result {:keys [filename tempfile]}]
|
||||||
(try
|
(try
|
||||||
(import-internal tempfile filename force-client force-location force-vendor (:identity request) )
|
(let [i (import-internal tempfile filename force-client force-location force-vendor (:identity request) )]
|
||||||
(update result :results conj {:filename filename
|
(update result :results conj {:filename filename
|
||||||
:response "success!"})
|
:response "success!"
|
||||||
|
:template (:template (first i))}))
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(-> result
|
(-> result
|
||||||
(assoc :error? true)
|
(assoc :error? true)
|
||||||
(update :results conj {:filename filename
|
(update :results conj {:filename filename
|
||||||
:response (.getMessage e)})))))
|
:response (.getMessage e)
|
||||||
|
:sample (:sample (ex-data e))
|
||||||
|
:template (:template (ex-data e))})))))
|
||||||
{:error? false :results []}
|
{:error? false :results []}
|
||||||
file)]
|
file)]
|
||||||
(html-response [:div#page-notification.p-4.rounded-lg
|
(html-response [:div#page-notification.p-4.rounded-lg
|
||||||
@@ -737,6 +751,15 @@
|
|||||||
"bg-red-50 text-red-700"
|
"bg-red-50 text-red-700"
|
||||||
"bg-primary-50 text-primary-700")}
|
"bg-primary-50 text-primary-700")}
|
||||||
[:table
|
[:table
|
||||||
|
[:thead
|
||||||
|
[:tr [:td "File"] [:td "Result"]
|
||||||
|
(if (:error? results)
|
||||||
|
[:td "Template"])
|
||||||
|
(if (:error? results)
|
||||||
|
[:td "Sample match"])]
|
||||||
|
#_[:tr "Result"]
|
||||||
|
#_[:tr "Template"]
|
||||||
|
]
|
||||||
(for [r (:results results)]
|
(for [r (:results results)]
|
||||||
[:tr
|
[:tr
|
||||||
[:td.p-2.border
|
[:td.p-2.border
|
||||||
@@ -748,7 +771,19 @@
|
|||||||
{:class (if (:error? results)
|
{:class (if (:error? results)
|
||||||
"bg-red-50 text-red-700 border-red-300"
|
"bg-red-50 text-red-700 border-red-300"
|
||||||
"bg-primary-50 text-primary-700 border-green-500")}
|
"bg-primary-50 text-primary-700 border-green-500")}
|
||||||
(:response r)]])]]
|
(:response r)]
|
||||||
|
(if (:error? results )
|
||||||
|
[:td.p-2.border
|
||||||
|
{:class "bg-red-50 text-red-700 border-red-300"}
|
||||||
|
"Template: " (:template r)])
|
||||||
|
(if (:error? results )
|
||||||
|
[:td.p-2.border
|
||||||
|
{:class "bg-red-50 text-red-700 border-red-300"}
|
||||||
|
|
||||||
|
[:ul
|
||||||
|
(for [[k v] (dissoc (:sample r) :template :source-url)]
|
||||||
|
[:li (name k) ": " (str v)])]
|
||||||
|
#_(:template r)])])]]
|
||||||
:headers
|
:headers
|
||||||
{"hx-trigger" "invalidated"})
|
{"hx-trigger" "invalidated"})
|
||||||
))
|
))
|
||||||
|
|||||||
Reference in New Issue
Block a user