added new types.

This commit is contained in:
Bryce Covert
2021-04-05 14:14:23 -07:00
parent 05663e65a7
commit 4645cbddec
3 changed files with 44 additions and 1 deletions

View File

@@ -7,6 +7,7 @@
(defn determine
[[header :as z]]
(log/info "Importing with header" header)
(let [csv-type (cond (str/includes? (second header) "Customer's PO No.")
:mama-lus
@@ -22,6 +23,10 @@
(str/includes? (str header) "Document Number")
:philz
(str/includes? (str header) "DISCOUNT_MESSAGE")
:wismettac
:else
nil)]
(log/info "csv type was determined to be" csv-type)
@@ -140,6 +145,22 @@
[]
(drop 1 rows)))
(defmethod parse-csv :wismettac
[rows]
(transduce
(comp
(map (fn [[inv_number inv_dt total :as row]]
{:vendor-code "Wismettac"
:invoice-number inv_number
:date (some-> inv_dt not-empty (parse-date-fallover ["MM/dd/yyyy"]))
:total (str/replace total #"," "")
:text (str/join " " row)
:full-text (str/join " " row)}))
)
conj
[]
(drop 1 rows)))
(defmethod parse-csv nil
[rows]
nil)

View File

@@ -380,6 +380,28 @@
:parser {:date [:clj-time "MM/dd/yyyy"]
:total [:trim-commas-and-negate nil]}}
;; American Provisions
{:vendor "American Paper & Provisions"
:keywords [#"imperialdade"]
:extract {:date #"([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"Bill To.*\n\s*(.*?)\s{2,}"
:invoice-number #"INVOICE\n(?:.*?)(\s{2,}\d+)"
:total #"AMOUNT DUE:\s+([\d\.,\-]+)"}
:parser {:date [:clj-time "MM/dd/yyyy"]
:total [:trim-commas-and-negate nil]}}
;; Ocean Queen statement
{:vendor "Ocean Queen"
:keywords [#"Ocean Queen USA" #"Statement"]
:extract {:date #"^([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"To:.*\n\s*(.*?)\s{2,}"
:invoice-number #"INV #(\d+)"
:total #" ([\d\.,\-]+)"}
:multi #"\n"
:multi-match? #"^([0-9]+/[0-9]+/[0-9]+).*INV"
:parser {:date [:clj-time "MM/dd/yyyy"]
:total [:trim-commas-and-negate nil]}}
;; Ocean Queen
{:vendor "Ocean Queen"
:keywords [#"Ocean Queen USA"]

View File

@@ -304,7 +304,7 @@
[]
imports)]
(when-not (seq transactions)
(throw (ex-info "No invoices found."
(throw (ex-info "No new invoices found."
{:imports (str imports)})))
(log/info "creating invoice" transactions)
@(d/transact (d/connect uri) (vec (set transactions))))))