south bay produce.
This commit is contained in:
@@ -17,23 +17,30 @@
|
|||||||
(defn template-applies? [text {:keys [keywords]}]
|
(defn template-applies? [text {:keys [keywords]}]
|
||||||
(every? #(re-find % text) keywords))
|
(every? #(re-find % text) keywords))
|
||||||
|
|
||||||
(defn extract-template [text template]
|
(defn extract-template
|
||||||
(if (:multi template)
|
([text template]
|
||||||
(mapcat
|
(if (:multi template)
|
||||||
#(extract-template % (dissoc template :multi))
|
(mapcat
|
||||||
(str/split text (:multi template)))
|
#(extract-template % text (dissoc template :multi))
|
||||||
|
(str/split text (:multi template)))
|
||||||
|
|
||||||
(when template
|
(extract-template text text template)))
|
||||||
[(->> template
|
([text full-text template]
|
||||||
:extract
|
(when (and template
|
||||||
(reduce-kv
|
(or (not (:multi-match? template))
|
||||||
(fn [result k v]
|
(re-find (:multi-match? template) text )))
|
||||||
(let [value (some-> (first (map second (re-seq v text)))
|
[(->> template
|
||||||
str/trim )
|
:extract
|
||||||
[value-parser parser-params] (-> template :parser k)]
|
(reduce-kv
|
||||||
(assoc result k (u/parse-value value-parser parser-params value))))
|
(fn [result k v]
|
||||||
{:vendor-code (:vendor template)
|
(let [value (some-> (or (first (map second (re-seq v text)))
|
||||||
:text text}))])))
|
(first (map second (re-seq v full-text))))
|
||||||
|
str/trim )
|
||||||
|
[value-parser parser-params] (-> template :parser k)]
|
||||||
|
(assoc result k (u/parse-value value-parser parser-params value))))
|
||||||
|
{:vendor-code (:vendor template)
|
||||||
|
:text text
|
||||||
|
:full-text full-text}))])))
|
||||||
|
|
||||||
(defn parse [text]
|
(defn parse [text]
|
||||||
(reset! last-text text)
|
(reset! last-text text)
|
||||||
@@ -96,7 +103,7 @@
|
|||||||
ffirst)]
|
ffirst)]
|
||||||
(or fuzzy-match client-word-match)))
|
(or fuzzy-match client-word-match)))
|
||||||
|
|
||||||
(defn best-location-match [client text]
|
(defn best-location-match [client text full-text]
|
||||||
(or (->> client
|
(or (->> client
|
||||||
:client/location-matches
|
:client/location-matches
|
||||||
(mapcat (fn [{:keys [:location-match/location :location-match/matches]}]
|
(mapcat (fn [{:keys [:location-match/location :location-match/matches]}]
|
||||||
@@ -104,5 +111,12 @@
|
|||||||
(filter (fn [[location match]] (re-find (re-pattern (str "(?i)" match)) text)) )
|
(filter (fn [[location match]] (re-find (re-pattern (str "(?i)" match)) text)) )
|
||||||
first
|
first
|
||||||
first)
|
first)
|
||||||
|
(->> client
|
||||||
|
:client/location-matches
|
||||||
|
(mapcat (fn [{:keys [:location-match/location :location-match/matches]}]
|
||||||
|
(map (fn [match] [location match]) matches)))
|
||||||
|
(filter (fn [[location match]] (re-find (re-pattern (str "(?i)" match)) full-text)) )
|
||||||
|
first
|
||||||
|
first)
|
||||||
(:client/default-location client)
|
(:client/default-location client)
|
||||||
(first (:client/locations client))))
|
(first (:client/locations client))))
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
(map (fn [[_ po-number despatch-number invoice-number invoice-date customer value :as row]]
|
(map (fn [[_ po-number despatch-number invoice-number invoice-date customer value :as row]]
|
||||||
{:vendor-code "Mama Lu's Foods"
|
{:vendor-code "Mama Lu's Foods"
|
||||||
:customer-identifier customer
|
:customer-identifier customer
|
||||||
:invoice-number (str invoice-number " " po-number)
|
:invoice-number (str po-number "-" invoice-number )
|
||||||
:date (u/parse-value :clj-time "MM/dd/yy HH:ss" invoice-date)
|
:date (u/parse-value :clj-time "MM/dd/yy HH:ss" invoice-date)
|
||||||
:total value
|
:total value
|
||||||
:text (str/join " " row)})))
|
:text (str/join " " row)})))
|
||||||
|
|||||||
@@ -48,7 +48,16 @@
|
|||||||
:customer-identifier #"Bill To:[^\n]+\n\s*([\w ]+)"
|
:customer-identifier #"Bill To:[^\n]+\n\s*([\w ]+)"
|
||||||
:invoice-number #"Invoice\s([\w\./]+)*"
|
:invoice-number #"Invoice\s([\w\./]+)*"
|
||||||
:total #"Total Invoice\s+([0-9.]+)"}
|
:total #"Total Invoice\s+([0-9.]+)"}
|
||||||
:parser {:date [:clj-time "MM/dd/yy"]}}])
|
:parser {:date [:clj-time "MM/dd/yy"]}}
|
||||||
|
{:vendor "Southbay Fresh Produce"
|
||||||
|
:keywords [#"SOUTH BAY FRESH PRODUCE"]
|
||||||
|
:extract {:date #"^([0-9]+/[0-9]+/[0-9]+)"
|
||||||
|
:customer-identifier #"FAX:[^\n]+\n\s+([A-Za-z ]+)\s{2}"
|
||||||
|
:invoice-number #"^[0-9]+/[0-9]+/[0-9]+\s+(\d+)"
|
||||||
|
:total #"\$([0-9.]+)"}
|
||||||
|
:parser {:date [:clj-time "MM/dd/yyyy"]}
|
||||||
|
:multi #"\n"
|
||||||
|
:multi-match? #"^[0-9]+/[0-9]+/[0-9]+\s+(\d+)"}])
|
||||||
|
|
||||||
(def excel-templates
|
(def excel-templates
|
||||||
[{:vendor "Isp Productions"
|
[{:vendor "Isp Productions"
|
||||||
|
|||||||
@@ -163,7 +163,7 @@
|
|||||||
(let [clients (d-clients/get-all)
|
(let [clients (d-clients/get-all)
|
||||||
_ (println imports)
|
_ (println imports)
|
||||||
|
|
||||||
transactions (reduce (fn [result {:keys [invoice-number customer-identifier total date vendor-code text] :as info}]
|
transactions (reduce (fn [result {:keys [invoice-number customer-identifier total date vendor-code text full-text] :as info}]
|
||||||
(println "searching for" vendor-code)
|
(println "searching for" vendor-code)
|
||||||
(let [[matching-vendor default-expense-account] (->> (d/query
|
(let [[matching-vendor default-expense-account] (->> (d/query
|
||||||
{:query {:find ['?vendor '?default-expense-account]
|
{:query {:find ['?vendor '?default-expense-account]
|
||||||
@@ -175,7 +175,7 @@
|
|||||||
_ (println matching-vendor)
|
_ (println matching-vendor)
|
||||||
matching-client (parse/best-match clients customer-identifier)
|
matching-client (parse/best-match clients customer-identifier)
|
||||||
_ (println "New invoice matches client" matching-client)
|
_ (println "New invoice matches client" matching-client)
|
||||||
matching-location (parse/best-location-match matching-client text )
|
matching-location (parse/best-location-match matching-client text full-text)
|
||||||
[existing-id existing-outstanding-balance existing-status import-status] (when (and matching-client matching-location)
|
[existing-id existing-outstanding-balance existing-status import-status] (when (and matching-client matching-location)
|
||||||
(->> (d/query
|
(->> (d/query
|
||||||
(cond-> {:query {:find ['?e '?outstanding-balance '?status '?import-status2]
|
(cond-> {:query {:find ['?e '?outstanding-balance '?status '?import-status2]
|
||||||
|
|||||||
Reference in New Issue
Block a user