This commit is contained in:
Bryce Covert
2020-01-24 18:18:31 -08:00
parent 2e9659557d
commit fe8256a488
4 changed files with 79 additions and 28 deletions

View File

@@ -38,7 +38,9 @@
(first (map second (re-seq v full-text))))
str/trim )
[value-parser parser-params] (-> template :parser k)]
(assoc result k (try (u/parse-value value-parser parser-params value)
(assoc result k (try
(println "applying parser" value-parser "to value" value)
(u/parse-value value-parser parser-params value)
(catch Exception e
(println e))))))
{:vendor-code (:vendor template)

View File

@@ -98,13 +98,36 @@
;; GOLDEN BRANDS
{:vendor "Golden Brands San Jose"
:keywords [#"GOLDEN BRANDS"]
:extract {:date #"0430\n(.*)"
:extract {:date #"(?:.*\n){4}(.*)" ;; HOW TO GO TO SPCIFIC LINE
:customer-identifier #"Account:(?:.*\n)(.*(?=\s{2,}))"
:invoice-number #"Invoice#: (\d+)"
:total #"Invoice Total\s+([0-9,]+\.[0-9]{2})"}
:parser {:date [:clj-time "EEE MMM dd, yyyy HH:mm aa"]
:total [:trim-commas nil]}}
;; Young's Market Co
{:vendor "Youngs Market"
:keywords [#"Young's Market Co"]
:extract {:date #"^([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"Customer Name\s+(.*)"
:invoice-number #"^(?:.*?)\s{2,}([0-9]+)"
:total #"([0-9\.,]+)\s+[0-9\.,]+$"}
:parser {:date [:clj-time "MM/dd/yyyy"]
:total [:trim-commas nil]}
:multi #"\n"
:multi-match? #"^[0-9]+/[0-9]+/[0-9]+\s+[0-9]+\s+INV "}
;; Young's Market Co - INVOICE
{:vendor "Youngs Market"
:keywords [#"P.O.Box 743564"]
:extract {:date #"INVOICE DATE\n(?:.*?)(\S+)\n"
:customer-identifier #"INVOICE DATE\n [0-9]+\s+(.*?)\s{2,}"
:invoice-number #"INVOICE DATE\n(?:.*?)\s{2,}(\d+?)\s+\S+\n"
:total #"Net Amount(?:.*\n){4}(?:.*?)([0-9\.]+)\n"}
:parser {:date [:clj-time "dd-MMM-yy"]
:total [:trim-commas nil]}}
;; WINE WAREHOUSE
{:vendor "Wine Warehouse"
:keywords [#"WINE WAREHOUSE"]
@@ -228,17 +251,6 @@
:total #"Balance Due\s+\$([0-9\.]+)"}
:parser {:date [:clj-time "MM/dd/yyyy"]}}
;; PFG - ROMA
{:vendor "Performance Food Group - ROMA"
:keywords [#"Performance Food Group, Inc\n\f"]
:extract {:date #"Date: ([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"BILL TO:\s+([\S ]+?)(?=\s{2,})"
:invoice-number #"INVOICE NO.\s+ ([\d]+)"
:total #"([\d\.,]+)\s+INVOICE TOTAL"}
:parser {:date [:clj-time "MM/dd/yy"]
:total [:trim-commas nil]}}
;; PFG - ROMA LOOK 1
{:vendor "Performance Food Group - ROMA"
:keywords [#"inquiries call 1-800-233-6211"]
@@ -249,7 +261,19 @@
:parser {:date [:clj-time "MM/dd/yyyy"]
:total [:trim-commas-and-negate nil]}
:multi #"\n"
:multi-match? #"^\s+[\d]{6,8}\s+\d+"}
:multi-match? #"^\s+[\d]{6,8}\s+\d+"}
;; PFG - ROMA
{:vendor "Performance Food Group - ROMA"
:keywords [#"Performance Food Group, Inc\n\f"]
:extract {:date #"Date: ([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"BILL TO:\s+([\S ]+?)(?=\s{2,})"
:invoice-number #"INVOICE NO.\s+ ([\d]+)"
:total #"([\d\.,]+)\s+INVOICE TOTAL"}
:parser {:date [:clj-time "MM/dd/yy"]
:total [:trim-commas nil]}}
;; JFC
{:vendor "JFC International"
@@ -313,14 +337,17 @@
(filter (fn [c]
(not (str/blank? (str/trim (or (d/read-cell (d/select-cell (offset c 1 0) sheet)) ""))))))
(map (fn [c]
(doto {:customer-identifier (str/trim (d/read-cell (d/select-cell (offset c 1 0) sheet)))
:text (d/read-cell (d/select-cell (offset c 1 0) sheet))
:full-text (d/read-cell (d/select-cell (offset c 1 0) sheet))
:date (u/parse-value :clj-time "MM/dd/yyyy" (str/trim (d/read-cell (d/select-cell (offset c 5 0) sheet))))
:invoice-number (str/trim (d/read-cell (d/select-cell (offset c 3 0) sheet)))
:total (str (d/read-cell (d/select-cell (offset c 7 0) sheet)))
:vendor-code vendor}
println)))
{:customer-identifier (str/trim (d/read-cell (d/select-cell (offset c 1 0) sheet)))
:text (d/read-cell (d/select-cell (offset c 1 0) sheet))
:full-text (d/read-cell (d/select-cell (offset c 1 0) sheet))
:date (u/parse-value :clj-time "MM/dd/yyyy" (str/trim (d/read-cell (d/select-cell (offset c 5 0) sheet))))
:invoice-number (->>
(re-find #"^(?:0+([A-Z0-9]+))|([A-Z]+[A-Z0-9]+)" (str/trim (d/read-cell (d/select-cell (offset c 3 0) sheet))))
(drop 1 )
(filter identity)
first)
:total (str (d/read-cell (d/select-cell (offset c 7 0) sheet)))
:vendor-code vendor}))
(filter :customer-identifier))
conj
[]

View File

@@ -21,7 +21,7 @@
[:footer.modal-card-foot
foot])]])
(defn action-modal [{:keys [title action-text id save-event can-submit? status-from] :or {can-submit? true}} & rest]
(defn action-modal [{:keys [title warning action-text id save-event can-submit? status-from] :or {can-submit? true}} & rest]
(let [{:keys [visible? saving? error-message]} @(re-frame/subscribe [::subs/modal-state id status-from])]
(when visible?
[:form {:id id
@@ -41,6 +41,8 @@
:id id
:hide-event [::events/modal-status id {:visible? false}]}
(when error-message
[:div.notification.is-warning error-message])]
[:div.notification.is-warning error-message])
(when warning
[:div.notification.is-info warning])]
(into (r/children (r/current-component)))
(into [(when saving? [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]))])))

View File

@@ -6,14 +6,34 @@
[auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.expense-accounts :refer [chooseable-expense-accounts]]
[clj-fuzzy.metrics :refer [jaccard]]
[clojure.spec.alpha :as s]
[clojure.string :as str]
[auto-ap.entities.vendors :as entity]
[auto-ap.entities.contact :as contact]
[auto-ap.subs :as subs]))
(defn ngrams [text len]
(mapv #(.toLowerCase (str/join "" %))
(partition len 1 text)))
(defn partial-matches-vendor? [text vendors]
(when (> (count text) 4)
(let [text (.toLowerCase text)]
(->> vendors
(map :name)
(mapcat
(fn [v] (mapv
(fn [n] [v (jaccard text n )])
(ngrams v (count text)))))
#_(sort-by second)
(filter #(< (second %) 0.3))
(map first)
first))))
(defn vendor-dialog [{:keys [vendor save-event change-event id] {:keys [name]} :vendor}]
(println (s/explain ::entity/vendor vendor) )
(let [clients-by-id @(re-frame/subscribe [::subs/clients-by-id])]
(let [clients-by-id @(re-frame/subscribe [::subs/clients-by-id])
all-vendors @(re-frame/subscribe [::subs/vendors])]
[action-modal {:id id
:title [:span (if (:id vendor)
(str "Edit " (or name "<vendor>"))
@@ -21,12 +41,12 @@
(when (:error vendor)
[:span.icon.has-text-danger
[:i.fa.fa-exclamation-triangle]])]
:warning (when-let [vendor (partial-matches-vendor? (:name vendor) all-vendors)]
(str "Are you sure you don't mean " vendor "?"))
:action-text "Save"
:save-event save-event
:can-submit? (s/valid? ::entity/vendor vendor)}
[horizontal-field
[:label.label "Name"]
[:div.control