fixes invoice import issues, fixes issue with too many keys in s3 for general produce.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -225,10 +225,27 @@
|
|||||||
:destination-key invoice-key })
|
:destination-key invoice-key })
|
||||||
invoice-key))
|
invoice-key))
|
||||||
|
|
||||||
|
(defn get-all-keys
|
||||||
|
([]
|
||||||
|
(let [first-page-result (s3/list-objects-v2 {:bucket-name bucket-name
|
||||||
|
:prefix "ntg-invoices/pending"})]
|
||||||
|
(lazy-seq (concat (:object-summaries first-page-result) (get-all-keys (:next-continuation-token first-page-result))))))
|
||||||
|
([next-token ]
|
||||||
|
(when next-token
|
||||||
|
(let [page-result (s3/list-objects-v2 {:bucket-name bucket-name
|
||||||
|
:prefix "ntg-invoices/pending"
|
||||||
|
:continuation-token next-token})]
|
||||||
|
(println "getting next page " next-token)
|
||||||
|
(when (seq (:object-summaries page-result))
|
||||||
|
(lazy-seq (concat (:object-summaries page-result) (get-all-keys (:next-continuation-token page-result)))))))))
|
||||||
|
|
||||||
|
(defn recent? [k]
|
||||||
|
(time/after? (:last-modified k) (time/plus (time/now) (time/days -15)))
|
||||||
|
)
|
||||||
|
|
||||||
(defn import-ntg-invoices
|
(defn import-ntg-invoices
|
||||||
([] (import-ntg-invoices (->> (s3/list-objects-v2 {:bucket-name bucket-name
|
([] (import-ntg-invoices (->> (get-all-keys)
|
||||||
:prefix "ntg-invoices/pending"})
|
(filter recent?)
|
||||||
:object-summaries
|
|
||||||
(map :key))))
|
(map :key))))
|
||||||
([keys]
|
([keys]
|
||||||
(let [clients (map first (d/q '[:find (pull ?c [:client/code
|
(let [clients (map first (d/q '[:find (pull ?c [:client/code
|
||||||
|
|||||||
@@ -27,6 +27,9 @@
|
|||||||
(str/includes? (str header) "DISCOUNT_MESSAGE")
|
(str/includes? (str header) "DISCOUNT_MESSAGE")
|
||||||
:wismettac
|
:wismettac
|
||||||
|
|
||||||
|
(str/includes? (str header) "Status")
|
||||||
|
:ledyard
|
||||||
|
|
||||||
:else
|
:else
|
||||||
nil)]
|
nil)]
|
||||||
(log/info "csv type was determined to be" csv-type)
|
(log/info "csv type was determined to be" csv-type)
|
||||||
@@ -162,6 +165,23 @@
|
|||||||
[]
|
[]
|
||||||
(drop 1 rows)))
|
(drop 1 rows)))
|
||||||
|
|
||||||
|
(defmethod parse-csv :ledyard
|
||||||
|
[rows]
|
||||||
|
(transduce
|
||||||
|
(comp
|
||||||
|
(map (fn [[invoice-number date due amount standard :as row]]
|
||||||
|
{:vendor-code "Performance Food Group - LEDYARD"
|
||||||
|
:invoice-number invoice-number
|
||||||
|
:date (some-> date not-empty (parse-date-fallover ["MM/dd/yyyy"]))
|
||||||
|
:due (some-> due not-empty (parse-date-fallover ["MM/dd/yyyy"]))
|
||||||
|
:total (str/replace amount #"[\$,]" "")
|
||||||
|
:text (str/join " " row)
|
||||||
|
:full-text (str/join " " row)}))
|
||||||
|
)
|
||||||
|
conj
|
||||||
|
[]
|
||||||
|
(drop 1 rows)))
|
||||||
|
|
||||||
#_{:clj-kondo/ignore [:unused-binding]}
|
#_{:clj-kondo/ignore [:unused-binding]}
|
||||||
(defmethod parse-csv nil
|
(defmethod parse-csv nil
|
||||||
[rows]
|
[rows]
|
||||||
|
|||||||
@@ -555,6 +555,7 @@
|
|||||||
{:vendor "JFC International"
|
{:vendor "JFC International"
|
||||||
:keywords [#"48490 MILMONT DRIVE"]
|
:keywords [#"48490 MILMONT DRIVE"]
|
||||||
:extract {:date #"([0-9]+/[0-9]+/[0-9]+)"
|
:extract {:date #"([0-9]+/[0-9]+/[0-9]+)"
|
||||||
|
:account-number #"CUSTOMER #.*?\n\n\s+(.*?)\s{2,}"
|
||||||
:customer-identifier #"SOLD\s+(?:TO\s+)?([\S ]+?)(?=(\s{2,}|\n))"
|
:customer-identifier #"SOLD\s+(?:TO\s+)?([\S ]+?)(?=(\s{2,}|\n))"
|
||||||
:invoice-number #"(\S+)\s+(?:[0-9]+/[0-9]+/[0-9]+)"
|
:invoice-number #"(\S+)\s+(?:[0-9]+/[0-9]+/[0-9]+)"
|
||||||
:total #"(?:INVOICE|TOTAL|CREDIT)\s+([\d\.,\-]+\.[\d\-]+( CR)?)"}
|
:total #"(?:INVOICE|TOTAL|CREDIT)\s+([\d\.,\-]+\.[\d\-]+( CR)?)"}
|
||||||
|
|||||||
Reference in New Issue
Block a user