Adds invoices

This commit is contained in:
2024-06-21 21:53:37 -07:00
parent 7ad017cbce
commit d9beac361f
3 changed files with 52 additions and 6 deletions

View File

@@ -14,7 +14,7 @@
[clojure.set :as set]
[clojure.string :as str]))
(def last-text (atom nil))
(defonce last-text (atom nil))
(defn template-applies? [text {:keys [keywords]}]

View File

@@ -41,7 +41,17 @@
:total #"INVOICE TOTAL\s+([0-9.]+)"}
:parser {:date [:clj-time "MM/dd/yy"]}
:multi #"\f\f"}
;; IMPACT PAPER
{:vendor "Impact Paper & Ink LTD"
:keywords [#"650-692-5598"]
:extract {:total #"Total Amount\s+\$([\d\.\,\-]+)"
:account-number #"CUST. #\n.*?/\d{4,}\s+(.*?)\n"
:date #"([0-9]+/[0-9]+/[0-9]+)"
:invoice-number #"[0-9]+/[0-9]+/[0-9]+\s+(\d+)"}
:parser {:date [:clj-time "MM/dd/yyyy"]
:total [:trim-commas nil]}}
;; CARBONIC
{:vendor "Carbonic Service Inc"
:keywords [#"CARBONIC SERVICE INC"]
@@ -82,10 +92,19 @@
:total #"Total Invoice\s+([\-]?[0-9.]+)"}
:parser {:date [:clj-time "MM/dd/yy"]
:total [:trim-commas-and-negate nil]}}
{:vendor "Ben E. Keith"
:keywords [#"BEN E. KEITH"]
:extract {:date #"Customer No Mo Day Yr.*?\n.*?\d{5,}\s{2,}(\d+\s+\d+\s+\d+)"
:customer-identifier #"Customer No Mo Day Yr.*?\n.*?(\d{5,})"
:invoice-number #"Invoice No.*?\n.*?(\d{8,})"
:total #"Total Invoice.*?\n.*?([\-]?[0-9]+\.[0-9]{2,})"}
:parser {:date [:month-day-year nil]
:total [:trim-commas-and-negate nil]}}
;; SOUTHBAY FRESH
{:vendor "Southbay Fresh Produce"
:keywords [#"SOUTH BAY FRESH PRODUCE"]
:keywords [#"(SOUTH BAY FRESH PRODUCE|SOUTH BAY PRODUCE)"]
:extract {:date #"^([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"To:[^\n]*\n\s+([A-Za-z' ]+)\s{2}"
:invoice-number #"INV #\/(\d+)"
@@ -94,6 +113,16 @@
:multi #"\n"
:multi-match? #"^[0-9]+/[0-9]+/[0-9]+\s+INV "}
;; DON VITO
{:vendor "Don Vito Ozuna Food Corp"
:keywords [#"408-465-2010"]
:extract {:date #"([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"To:[^\n]*\n\s+([A-Za-z' ]+)\s{2}"
:invoice-number #"(?:[0-9]+/[0-9]+/[0-9]+)\s{2,}(\d+)"
:total #"Please remit payment to\s{2,}\$([\-0-9.]+)"}
:parser {:date [:clj-time "MM/dd/yyyy"]} }
;; PFG - LEDYARD
{:vendor "Performance Food Group - LEDYARD"
:keywords [#"performancefoodservice"]
@@ -171,7 +200,7 @@
;; WORLDWIDE PRODUCE
{:vendor "Worldwide Produce"
:keywords [#"WORLDWIDE PRODUCE"]
:keywords [#"WORLDWIDE\s+PRODUCE"]
:extract {:date #"([0-9]+/[0-9]+/[0-9]+)"
:invoice-number #"(?:Invoice|Adjustment) No\.\s+(\d+)"
:total #"Total \S*\s+([0-9\.,\-]+)"
@@ -180,7 +209,7 @@
:total [:trim-commas nil]}
:multi (. java.util.regex.Pattern (compile (-> \formfeed str) java.util.regex.Pattern/CASE_INSENSITIVE))
:multi-match? #"(Total\s+[0-9\.]+|Total Order)"}
;; AUTO-CHLOR
{:vendor "Auto-Chlor"
:keywords [#"AUTO-CHLOR"]
@@ -193,7 +222,7 @@
;; Cheetah
{:vendor "Cheetah"
:keywords [#"Truck name" #"Stop number"]
:keywords [#"Delivery date: [\d\-]+\s{2,}Payment"]
:extract {:date #"Delivery date: ([0-9\-]+)"
:customer-identifier #"Shipping.*\n(.*)"
:invoice-number #"Invoice #: (\d+)"

View File

@@ -35,6 +35,23 @@
(str (- (Double/parseDouble raw-value)))
(str raw-value))))
(defmethod parse-value :month-day-year
[_ _ value]
(let [format "yyyy-MM-dd"
[month day year] (str/split (-> value
(str/replace #"\s+" " ")
)
#"\s")
value (str "20" year "-" month "-" day) ]
(try
(reduced (time/from-time-zone (f/parse (f/formatter format) value)
(time/time-zone-for-id "America/Los_Angeles")))
(catch Exception e
(alog/warn ::cant-parse-date :error e :raw-value (str value))
nil))))
(defmethod parse-value :clj-time
[_ format value]
(let [format (if (sequential? format)