fixes new wine warehouse format.
This commit is contained in:
@@ -45,8 +45,8 @@
|
||||
[value-parser parser-params] (-> template :parser k)]
|
||||
(assoc result k (try
|
||||
(u/parse-value value-parser parser-params value)
|
||||
(catch Exception e
|
||||
(alog/warn ::cant-parse-value :error e :raw value))))))
|
||||
(catch Exception e
|
||||
(alog/warn ::cant-parse-value :error e :raw value))))))
|
||||
{:vendor-code (:vendor template)
|
||||
:text text
|
||||
:full-text full-text}))])))
|
||||
@@ -62,14 +62,12 @@
|
||||
(defmulti parse-file (fn [_ filename] (.toLowerCase (last (str/split filename #"\." )))))
|
||||
|
||||
(defn invoke-glimpse2 [f]
|
||||
(doto
|
||||
(-> (lambda/invoke {:function-name "glimpse2" :payload
|
||||
(json/write-str
|
||||
(alog/peek ::x {"url" (str "https://" "data.prod.app.integreatconsult.com" "/" f ) }))})
|
||||
:payload
|
||||
slurp
|
||||
json/read-str)
|
||||
println))
|
||||
(-> (lambda/invoke {:function-name "glimpse2" :payload
|
||||
(json/write-str
|
||||
(alog/peek ::x {"url" (str "https://" "data.prod.app.integreatconsult.com" "/" f ) }))})
|
||||
:payload
|
||||
slurp
|
||||
json/read-str))
|
||||
|
||||
(defn glimpse2 [file]
|
||||
(try
|
||||
@@ -78,14 +76,17 @@
|
||||
(s3/put-object {:bucket-name "data.prod.app.integreatconsult.com"
|
||||
:key tmp-key
|
||||
:input-stream f}))
|
||||
g (invoke-glimpse2 tmp-key) ]
|
||||
[ {:date (u/parse-value :clj-time "yyyy-MM-dd" (str/trim (get g "date")))
|
||||
:customer-identifier (get g "customer_identifier")
|
||||
:account-number (not-empty (get g "account_number"))
|
||||
:vendor-code (-> (vendors/best-match (get g "vendor_identifier") )
|
||||
is (invoke-glimpse2 tmp-key) ]
|
||||
(alog/peek ::glimpse2-result is)
|
||||
(for [i is]
|
||||
{:date (u/parse-value :clj-time "yyyy-MM-dd" (str/trim (get i "date")))
|
||||
:customer-identifier (get i "customer_identifier")
|
||||
:account-number (not-empty (get i "account_number"))
|
||||
:vendor-search (get i "vendor_identifier")
|
||||
:vendor-code (-> (vendors/best-match (get i "vendor_identifier") )
|
||||
(get "label"))
|
||||
:total (get g "total")
|
||||
:invoice-number (get g "invoice_number")}]
|
||||
:total (get i "total")
|
||||
:invoice-number (get i "invoice_number")})
|
||||
)
|
||||
(catch Exception e
|
||||
(alog/warn ::glimpse2-not-work :error e)
|
||||
|
||||
@@ -280,10 +280,10 @@
|
||||
;; WINE WAREHOUSE
|
||||
{:vendor "Wine Warehouse"
|
||||
:keywords [#"WINE WAREHOUSE" #"Bottle prices include"]
|
||||
:extract {:date #"INVOICE DATE\s+([0-9]+/[0-9]+/[0-9]+)"
|
||||
:invoice-number #"INV #\s+(\d+)"
|
||||
:total #"PLEASE PAY THIS AMOUNT\s+([0-9,]+\.[0-9]{2})"
|
||||
:account-number #"CUSTOMER NUMBER\s+(\d+)"}
|
||||
:extract {:date #"Invoice Date:\s+([0-9]+/[0-9]+/[0-9]+)"
|
||||
:invoice-number #"Invoice #: \s+(\d+)"
|
||||
:total #"Total\s+([\-0-9,]+\.[0-9]{2})"
|
||||
:account-number #"Customer #:\s+(\d+)"}
|
||||
:parser {:date [:clj-time "MM/dd/yyyy"]
|
||||
:total [:trim-commas nil]}}
|
||||
|
||||
@@ -321,10 +321,10 @@
|
||||
;; Breakthru Bev
|
||||
{:vendor "Wine Warehouse"
|
||||
:keywords [#"BREAKTHRU BEVERAGE"]
|
||||
:extract {:date #"INVOICE DATE\s+([0-9]+/[0-9]+/[0-9]+)"
|
||||
:account-number #"CUSTOMER NUMBER\s+(\d+)"
|
||||
:invoice-number #"INV #\s+(.*?)\n"
|
||||
:total #"INVOICE AMOUNT\s+\$\s*([\d,\.\-]+)"}
|
||||
:extract {:date #"Invoice Date:\s+([0-9]+/[0-9]+/[0-9]+)"
|
||||
:invoice-number #"Invoice #: \s+(\d+)"
|
||||
:total #"Total\s+([\-0-9,]+\.[0-9]{2})"
|
||||
:account-number #"Customer #:\s+(\d+)"}
|
||||
:parser {:date [:clj-time "MM/dd/yyyy"]
|
||||
:total [:trim-commas nil]}}
|
||||
|
||||
|
||||
@@ -575,10 +575,14 @@
|
||||
]
|
||||
))
|
||||
|
||||
(defn match-vendor [vendor-code forced-vendor]
|
||||
(defn match-vendor [vendor-code forced-vendor vendor-search]
|
||||
(when (and (not forced-vendor) (str/blank? vendor-code))
|
||||
(throw (ex-info (str "No vendor found. Please supply an forced vendor.")
|
||||
{:vendor-code vendor-code})))
|
||||
(if vendor-search
|
||||
(throw (ex-info (format "No vendor found. Searched for '%s'. Please supply an forced vendor."
|
||||
vendor-search)
|
||||
{:vendor-code vendor-code}))
|
||||
(throw (ex-info (str "No vendor found. Please supply an forced vendor.")
|
||||
{:vendor-code vendor-code}))))
|
||||
(let [vendor-id (or forced-vendor
|
||||
(->> (dc/q
|
||||
{:find ['?vendor]
|
||||
@@ -601,7 +605,11 @@
|
||||
(throw (ex-info (str "No vendor with the name " vendor-code " was found.")
|
||||
{:vendor-code vendor-code})))))
|
||||
|
||||
(defn import->invoice [{:keys [invoice-number source-url customer-identifier account-number total date vendor-code text full-text client-override vendor-override location-override import-status]}]
|
||||
(defn import->invoice [{:keys [invoice-number source-url customer-identifier account-number total date vendor-code text full-text client-override vendor-search vendor-override location-override import-status]}]
|
||||
(when-not total
|
||||
(throw (Exception. "Couldn't parse total from file.")))
|
||||
(when-not date
|
||||
(throw (Exception. "Couldn't parse date from file.")))
|
||||
(let [matching-client (cond
|
||||
client-override client-override
|
||||
account-number (:db/id (d-clients/exact-match account-number))
|
||||
@@ -613,7 +621,8 @@
|
||||
:matching (when matching-client
|
||||
(dc/pull (dc/db conn) [:client/name :client/code] matching-client)))
|
||||
|
||||
matching-vendor (match-vendor vendor-code vendor-override)
|
||||
matching-vendor (match-vendor vendor-code vendor-override vendor-search)
|
||||
|
||||
matching-location (or (when-not (str/blank? location-override)
|
||||
location-override)
|
||||
(parse/best-location-match (dc/pull (dc/db conn)
|
||||
|
||||
@@ -46,6 +46,8 @@
|
||||
(when (= :auto-ap.logging/peek (:mulog/event-name item))
|
||||
(println "\u001B[31mTEST")
|
||||
)
|
||||
(when (:error item)
|
||||
(println (:error item)))
|
||||
(puget/cprint (reduce
|
||||
(fn [acc [k v]]
|
||||
(assoc acc k v))
|
||||
|
||||
Reference in New Issue
Block a user