adding vendor.

This commit is contained in:
Bryce Covert
2017-12-10 08:26:42 -08:00
parent 59a0c40beb
commit 6f9a497061
2 changed files with 30 additions and 12 deletions

View File

@@ -4,19 +4,22 @@
[clojure.java.shell :as sh])) [clojure.java.shell :as sh]))
(def templates (def templates
[{:keywords [#"CHEF'S WAREHOUSE"] [{:vendor "CHFW"
:keywords [#"CHEF'S WAREHOUSE"]
:extract {:total #"2 WKS C\.C\.\s+([\d.,]+)" :extract {:total #"2 WKS C\.C\.\s+([\d.,]+)"
:customer-identifier #"\n([A-Z][A-Z ]+)\s{2,}" :customer-identifier #"\n([A-Z][A-Z ]+)\s{2,}"
:date #"\s+([0-9]+/[0-9]+/[0-9]+)" :date #"\s+([0-9]+/[0-9]+/[0-9]+)"
:invoice-number #"\s+[0-9]+/[0-9]+/[0-9]+\s+([0-9]+)"}} :invoice-number #"\s+[0-9]+/[0-9]+/[0-9]+\s+([0-9]+)"}}
{:keywords [#"Golden Gate Meat"] {:vendor "GGM"
:keywords [#"Golden Gate Meat"]
:extract {:total #"Invoice Total\:\s+\$([\d.,]+)" :extract {:total #"Invoice Total\:\s+\$([\d.,]+)"
:customer-identifier #"Bill To\s*:\s*([\w ]+)\s{2,}" :customer-identifier #"Bill To\s*:\s*([\w ]+)\s{2,}"
:date #"Printed:\s+([0-9]+/[0-9]+/[0-9]+)" :date #"Printed:\s+([0-9]+/[0-9]+/[0-9]+)"
:invoice-number #"Invoice\s+[^\n]+\n[^\n]+\n\s+([0-9]+)"}} :invoice-number #"Invoice\s+[^\n]+\n[^\n]+\n\s+([0-9]+)"}}
{:keywords [#"CINTAS CORPORATION"] {:vendor "CINTAS"
:keywords [#"CINTAS CORPORATION"]
:extract {:invoice-number #"INVOICE\s#\s+([\d.,]+)" :extract {:invoice-number #"INVOICE\s#\s+([\d.,]+)"
:customer-identifier #"BILL TO\s*:\s{2,}([\w ]+)\s{2,}" :customer-identifier #"BILL TO\s*:\s{2,}([\w ]+)\s{2,}"
:date #"INVOICE DATE\s*\n.*\s+([0-9]+/[0-9]+/[0-9]+)" :date #"INVOICE DATE\s*\n.*\s+([0-9]+/[0-9]+/[0-9]+)"
@@ -38,7 +41,7 @@
(fn [result k v] (fn [result k v]
(assoc result k (some-> (first (map second (re-seq v text))) (assoc result k (some-> (first (map second (re-seq v text)))
str/trim ))) str/trim )))
{}))])) {:vendor (:vendor template)}))]))
(defn parse [text] (defn parse [text]
(->> templates (->> templates

View File

@@ -59,13 +59,15 @@
[:table {:class "table", :style {:width "100%"}} [:table {:class "table", :style {:width "100%"}}
[:thead [:thead
[:tr [:tr
[:th "Vendor"]
[:th "Customer"] [:th "Customer"]
[:th "Invoice #"] [:th "Invoice #"]
[:th "Date"] [:th "Date"]
[:th "Amount"]]] [:th "Amount"]]]
[:tbody (for [{:keys [customer-identifier invoice-number date total id] :as i} @invoices] [:tbody (for [{:keys [customer-identifier invoice-number date total id vendor] :as i} @invoices]
^{:key (str customer-identifier "-" invoice-number "-" date "-" total "-" id)} ^{:key (str customer-identifier "-" invoice-number "-" date "-" total "-" id)}
[:tr [:tr
[:td vendor]
[:td customer-identifier] [:td customer-identifier]
[:td invoice-number] [:td invoice-number]
[:td date] [:td date]
@@ -106,13 +108,15 @@
[:table {:class "table", :style {:width "100%"}} [:table {:class "table", :style {:width "100%"}}
[:thead [:thead
[:tr [:tr
[:th "Vendor"]
[:th "Customer"] [:th "Customer"]
[:th "Invoice #"] [:th "Invoice #"]
[:th "Date"] [:th "Date"]
[:th "Amount"]]] [:th "Amount"]]]
[:tbody (for [{:keys [customer-identifier invoice-number date total id] :as i} @invoices] [:tbody (for [{:keys [vendor customer-identifier invoice-number date total id] :as i} @invoices]
^{:key (str customer-identifier "-" invoice-number "-" date "-" total "-" id)} ^{:key (str customer-identifier "-" invoice-number "-" date "-" total "-" id)}
[:tr [:tr
[:td vendor]
[:td customer-identifier] [:td customer-identifier]
[:td invoice-number] [:td invoice-number]
[:td date] [:td date]
@@ -139,6 +143,16 @@
[:div {:class "inbox-messages"} [:div {:class "inbox-messages"}
[:form [:form
[:h1.title "New Invoice"] [:h1.title "New Invoice"]
[:div.field
[:label.label "Vendor"]
[:div.control
[:input.input {:type "text"
:placeholder "CINTAS"
:value (:vendor @form-data)
:on-change (fn [e]
(re-frame/dispatch [::events/change-form-state
[:new-invoice :vendor]
(.. e -target -value)]))}]]]
[:div.field [:div.field
[:label.label "Customer"] [:label.label "Customer"]
[:div.control [:div.control
@@ -181,13 +195,14 @@
(.. e -target -value)]))}]]] (.. e -target -value)]))}]]]
[:div.control [:div.control
[:submit.button.is-large.is-primary { [:submit.button.is-large.is-primary {
:disabled (if (and (:total @form-data) (:date @form-data) (:customer-identifier @form-data) (:invoice-number @form-data)) :disabled (if (and (:total @form-data) (:date @form-data) (:customer-identifier @form-data) (:invoice-number @form-data)
"" (:vendor @form-data))
"disabled") ""
"disabled")
:on-click :on-click
(fn [x] (fn [x]
(.preventDefault x) (.preventDefault x)
(re-frame/dispatch [::events/submit-new-invoice @form-data]))} (re-frame/dispatch [::events/submit-new-invoice @form-data]))}
[:span [:span
(when (:loading? @form-data) (when (:loading? @form-data)
[:i.fa.fa-spin.fa-spinner]) [:i.fa.fa-spin.fa-spinner])