diff --git a/resources/public/css/main.css b/resources/public/css/main.css index 5c010de3..2f605a11 100644 --- a/resources/public/css/main.css +++ b/resources/public/css/main.css @@ -1,4 +1,4 @@ - form.dz { border: 2px dashed lightgray;} + form.dz .notification { border: 2px dashed lightgray;} html,body { font-family: 'Open Sans', serif; diff --git a/src/clj/auto_ap/parse.clj b/src/clj/auto_ap/parse.clj index c68b3c8b..c09fb54e 100644 --- a/src/clj/auto_ap/parse.clj +++ b/src/clj/auto_ap/parse.clj @@ -91,7 +91,7 @@ (sort-by second) ffirst) - word-set (set (str/split (.toLowerCase invoice-client-name) #"\s" )) + word-set (set (filter (complement str/blank?) (str/split (.toLowerCase invoice-client-name) #"[\s:\-]" ))) client-word-match (->> clients (map (fn [{:keys [:db/id :client/matches :client/name] :as client :or {matches []}}] diff --git a/src/clj/auto_ap/parse/csv.clj b/src/clj/auto_ap/parse/csv.clj index 82247043..cc830b9e 100644 --- a/src/clj/auto_ap/parse/csv.clj +++ b/src/clj/auto_ap/parse/csv.clj @@ -7,11 +7,15 @@ (defn determine [[header :as z]] (prn header) - (cond (str/includes? (second header) "Customer's PO No.") - :mama-lus + (doto (cond (str/includes? (second header) "Customer's PO No.") + :mama-lus - :else - nil)) + (str/includes? (str header) "Closed Date") + :sysco + + :else + nil) + println)) (defmulti parse-csv determine @@ -29,6 +33,23 @@ (first))] (u/parse-value :clj-time valid-fmt d))) +(defmethod parse-csv :sysco + [rows] + (println "Importing Sysco") + (transduce + (comp (drop 1) + (map (fn [[invoice-number invoice-date _ amount :as row]] + {:vendor-code "Sysco" + :customer-identifier nil + :invoice-number invoice-number + :date (parse-date-fallover invoice-date ["M/d/yyyy"]) + :total (str/replace amount #"[,\$]" "") + :text (str/join " " row) + :full-text (str/join " " row)}))) + conj + [] + rows)) + (defmethod parse-csv :mama-lus [rows] (println "MAMA LU4") @@ -51,7 +72,6 @@ nil) (defn parse-file [file filename] - (println "HEREERE") (with-open [reader (io/reader file)] (let [rows (csv/read-csv reader :separator \,)] (parse-csv rows)))) diff --git a/src/clj/auto_ap/parse/templates.clj b/src/clj/auto_ap/parse/templates.clj index b3e7f1af..e31fa267 100644 --- a/src/clj/auto_ap/parse/templates.clj +++ b/src/clj/auto_ap/parse/templates.clj @@ -105,18 +105,61 @@ :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\.,]+$"} + ;; Del Monte Meats + {:vendor "Del Monte Meat Co" + :keywords [#"Del Monte"] + :extract {:date #"([0-9]+/[0-9]+/[0-9]+)" + :customer-identifier #"Bill To:(?:.*?(?=\s{2,}))(.*)-" + :invoice-number #"Invoice\s+([0-9]+)" + :total #"\$([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 "} + :multi-match? #"^ [0-9]+"} + + ;; Royal Hawaiian + {:vendor "Royal Hawaiian" + :keywords [#"ROYAL HAWAIIAN"] + :extract {:date #"([0-9]+/[0-9]+/[0-9]+)" + :customer-identifier #"BILL TO.*\n\s+(.*?(?=(\s{2,}|\()))" + :invoice-number #"Invoice#:\s+([0-9]+)" + :total #"INV TOTAL:\s+([0-9\.,]+)"} + :parser {:date [:clj-time "MM/dd/yyyy"] + :total [:trim-commas nil]}} + + ;; AUTO-CHLOR + {:vendor "Auto-Chlor" + :keywords [#"AUTO-CHLOR"] + :extract {:date #"DATE : ([0-9]+/[0-9]+/[0-9]+)" + :customer-identifier #"(.*?)\s{2,}.*CUSTOMER#" + :invoice-number #"INVOICE# :\s+([0-9]+)" + :total #"TOTAL SALE :\s+([0-9,.]+)"} + :parser {:date [:clj-time "MM/dd/yyyy"] + :total [:trim-commas nil]}} + + ;; Classic Wines + {:vendor "Classic Wines" + :keywords [#"585-9463"] + :extract {:date #"([0-9]+/[0-9]+/[0-9]+)" + :customer-identifier #"Customer Id:.*\n.*\n.*\n(.*)" + :invoice-number #"^.{23}\s+(\w+)" + :total #"\$([0-9\.,]+)"} + :parser {:date [:clj-time "MM/dd/yy"] + :total [:trim-commas nil]} + :multi #"\n" + :multi-match? #"^\s+.*?\d{6,}.*?\$"} + + ;; Young's Market Co new statement + {:vendor "Youngs Market" + :keywords [#"YOUNG'S MARKET COMPANY"] + :extract {:date #"([0-9]+/[0-9]+/[0-9]+)" + :customer-identifier #"SHIP TO SITE: ([\w ]+)" + :invoice-number #"^([0-9]+)" + :total #"\$([0-9\.,]+)"} + :parser {:date [:clj-time "MM/dd/yyyy"] + :total [:trim-commas nil]} + :multi #"\n" + :multi-match? #"^[0-9]+"} ;; Young's Market Co - INVOICE {:vendor "Youngs Market" @@ -168,6 +211,16 @@ :parser {:date [:clj-time "MM/dd/yyyy"] :total [:trim-commas nil]}} + ;; PACIFIC SEAFOOD + {:vendor "Pacific Seafood" + :keywords [#"pacseafood"] + :extract {:date #"DATE(?:.*\n.*(?=([0-9]+/[0-9]+/[0-9]+)))([0-9]+/[0-9]+/[0-9]+)" + :customer-identifier #"DELIVER TO:(?:.*\n)(.*?)(?=\s{2})" + :invoice-number #"INVOICE NO\.\n(?:.*?(?= [0-9]+\n)) ([0-9]+)" + :total #"TOTAL\n\s+([0-9,\.]+)"} + :parser {:date [:clj-time "MM/dd/yyyy"] + :total [:trim-commas nil]}} + ;; P&R {:vendor "P & R PAPER SUPPLY CO" :keywords [#"PAPER SUPPLY COMPANY"] @@ -324,6 +377,30 @@ :total [#"Total Invoice" 0 5] :date [#"Date" 0 0 #"Date: (.*)"] :invoice-number [#"Invoice #" 0 0 #"Invoice #: (.*)"]}} + {:vendor "Mama Lu's Foods" + :keywords [#"Mama Lu's Foods"] + :extract (fn [wb vendor] + (let [[sheet] (d/sheet-seq wb)] + (transduce (comp + (drop 5) + (filter + (fn [r] + (and + r + (->> r d/cell-seq second d/read-cell)))) + (map + (fn [r] + (let [[_ customer-order-number num date name amount] (map d/read-cell (d/cell-seq r))] + {:customer-identifier (second (re-find #"([^:]*):" name)) + :text name + :full-text name + :date (u/parse-value :clj-time "MM/dd/yyyy" (str/trim date)) + :invoice-number (str customer-order-number "-" (int num)) + :total (str amount) + :vendor-code vendor})))) + conj + [] + (d/row-seq sheet))))} {:vendor "DVW Commercial" :keywords [#"Total for" #"Num"] :extract (fn [wb vendor] @@ -351,30 +428,6 @@ :keywords [#"Alt_invoice_number"] :extract (fn [wb vendor] (let [[sheet] (d/sheet-seq wb)] - (println "COUNT" (count (transduce (comp - (drop-while (fn [c] - (not (re-find #"Customer_id" (str (d/read-cell c)))))) - (drop 9) - (filter (fn [c] - (= 0 (.getColumnIndex c)))) - (filter (fn [c] - (not (str/blank? (str/trim (or (d/read-cell (d/select-cell (offset c 1 0) sheet)) "")))))) - (map (fn [c] - {: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 2 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 - [] - (d/cell-seq sheet)))) (transduce (comp (drop-while (fn [c] (not (re-find #"Customer_id" (str (d/read-cell c)))))) diff --git a/src/clj/auto_ap/routes/invoices.clj b/src/clj/auto_ap/routes/invoices.clj index 0980562a..10b7fa95 100644 --- a/src/clj/auto_ap/routes/invoices.clj +++ b/src/clj/auto_ap/routes/invoices.clj @@ -164,9 +164,8 @@ )) -(defn import-uploaded-invoice [imports] +(defn import-uploaded-invoice [client forced-location imports] (let [clients (d-clients/get-all) - transactions (reduce (fn [result {:keys [invoice-number customer-identifier total date vendor-code text full-text] :as info}] (println "searching for" vendor-code) (let [[matching-vendor default-account] (->> (d/query @@ -182,9 +181,21 @@ :customer-identifier customer-identifier :vendor-code vendor-code}))) _ (println "matching" customer-identifier "-" matching-vendor) - matching-client (parse/best-match clients customer-identifier) - _ (println "invoice \"" invoice-number "\"matches client" (:client/name matching-client)) - matching-location (parse/best-location-match matching-client text full-text) + matching-client (or (and customer-identifier + (parse/best-match clients customer-identifier)) + (if client + (first (filter (fn [c] + (= (:db/id c) (Long/parseLong client))) + clients)))) + _ (when-not matching-client + (throw (ex-info (str "No client found in file. Select a client first.") + {:invoice-number invoice-number + :customer-identifier customer-identifier + :vendor-code vendor-code}))) + _ (println "invoice \"" invoice-number "\"matches client " (:client/name matching-client) " (" (:db/id matching-client) ")") + matching-location (or (when-not (str/blank? forced-location) + forced-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) (try (->> (d/query @@ -278,16 +289,20 @@ (context "/invoices" [] (POST "/upload" - {{ files "file"} :params :as params} + {{ files "file" + client "client" + location "location"} :params :as params} (let [{:keys [filename tempfile]} files] + (println params) (try - (import-uploaded-invoice (parse/parse-file (.getPath tempfile) filename)) + (import-uploaded-invoice client location (parse/parse-file (.getPath tempfile) filename)) {:status 200 :body (pr-str {}) :headers {"Content-Type" "application/edn"}} (catch Exception e {:status 500 :body (pr-str {:message (.getMessage e) + :error (.toString e) :data (ex-data e)}) :headers {"Content-Type" "application/edn"}})) )) diff --git a/src/cljs/auto_ap/views/components/invoice_table.cljs b/src/cljs/auto_ap/views/components/invoice_table.cljs index 40af5457..74ab4e9c 100644 --- a/src/cljs/auto_ap/views/components/invoice_table.cljs +++ b/src/cljs/auto_ap/views/components/invoice_table.cljs @@ -32,7 +32,6 @@ (re-frame/reg-event-fx ::toggle-expense-accounts (fn [{:keys [db] } [_ invoice-id]] - (println "toggling") {:db (update-in db [::visible-expense-accounts] (fn [i] (if (= i invoice-id) nil invoice-id) ))})) diff --git a/src/cljs/auto_ap/views/components/invoices/side_bar.cljs b/src/cljs/auto_ap/views/components/invoices/side_bar.cljs index 985ee5ea..282319fe 100644 --- a/src/cljs/auto_ap/views/components/invoices/side_bar.cljs +++ b/src/cljs/auto_ap/views/components/invoices/side_bar.cljs @@ -17,6 +17,11 @@ [:div [:div [:p.menu-label "Type"] [:ul.menu-list + [:li.menu-item + [:a.item {:href (bidi/path-for routes/routes :invoices) + :class [(active-when ap = :invoices)]} + [:span {:class "icon icon-accounting-invoice-mail" :style {:font-size "25px"}}] + [:span {:class "name"} "All Invoices"]]] [:li.menu-item [:a.item {:href (bidi/path-for routes/routes :unpaid-invoices) :class [(active-when ap = :unpaid-invoices)]} diff --git a/src/cljs/auto_ap/views/main.cljs b/src/cljs/auto_ap/views/main.cljs index db3035a6..ae9f352d 100644 --- a/src/cljs/auto_ap/views/main.cljs +++ b/src/cljs/auto_ap/views/main.cljs @@ -44,6 +44,8 @@ (defmethod page :voided-invoices [_] (unpaid-invoices-page {:status "voided"})) +(defmethod page :invoices [_] + (unpaid-invoices-page {})) (defmethod page :checks [_] (checks-page)) diff --git a/src/cljs/auto_ap/views/pages/import_invoices.cljs b/src/cljs/auto_ap/views/pages/import_invoices.cljs index 974677e8..b228fde3 100644 --- a/src/cljs/auto_ap/views/pages/import_invoices.cljs +++ b/src/cljs/auto_ap/views/pages/import_invoices.cljs @@ -11,14 +11,21 @@ [auto-ap.entities.vendors :as vendor] [auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table] [cljsjs.dropzone :as dropzone] - [cljs.reader :as edn])) + [cljs.reader :as edn] + [clojure.string :as str])) (def dropzone (let [client (re-frame/subscribe [::subs/client]) token (re-frame/subscribe [::subs/token])] (with-meta (fn [] [:form.dz {:action "/api/invoices/upload"} + [:div.field.has-addons + [:p.control + [:a.button.is-static "Force Location"]] + [:p.control + [:input.input {:name "location" :placeholder "SG" :size "4" :maxlength "2" :style {:display "inline"}}]]] [:div.tile.notification + [:div.has-text-centered {:style {:padding "80px 0px" :width "100%"}} [:span [:span {:class "icon"} @@ -30,7 +37,7 @@ (.on (js-this) "success" (fn [_ files] (re-frame/dispatch [::invalidated]))) (.on (js-this) "error" (fn [_ error] - (re-frame/dispatch [::errored error])))) + (re-frame/dispatch [::errored error])))) :paramName "file" :headers {"Authorization" (str "Token " @token)} :url (str "/api/invoices/upload" @@ -39,6 +46,7 @@ :previewsContainer "#dz-hidden" :previewTemplate "
"})))}))) + (re-frame/reg-sub ::invoice-page (fn [db] @@ -171,6 +179,7 @@ error (re-frame/subscribe [::error])] [:div [:h1.title "Upload invoices"] + [dropzone] @@ -191,9 +200,7 @@ :invoice-page invoice-page :overrides {:client (fn [row] [:p (:name (:client row)) - [:p [:i.is-size-7 (:client-identifier row)]]] - - )} + [:p [:i.is-size-7 (:client-identifier row)]]])} :check-boxes true :checked (:checked @invoice-page) :on-check-changed (fn [which invoice] diff --git a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs index 93a02af5..af0e4a80 100644 --- a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs +++ b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs @@ -666,7 +666,7 @@ [:div [:em "Your payment was created."]] ])))) -(defn unpaid-invoices-content [{:keys [status]}] +(defn unpaid-invoices-content [{:keys [status] :as params}] (r/create-class {:display-name "unpaid-invoices-content" :component-will-unmount (fn [this] (re-frame/dispatch [::unmount-invoices])) @@ -674,7 +674,7 @@ (let [{:keys [checked print-checks-shown? print-checks-loading? advanced-print-shown? vendor-filter]} @(re-frame/subscribe [::invoice-page]) current-client @(re-frame/subscribe [::subs/client])] [:div - [:h1.title (str (str/capitalize status) " invoices")] + [:h1.title (str (str/capitalize (or status "all")) " invoices")] (when (= status "unpaid") [pay-button {:print-checks-shown? print-checks-shown? :checked-invoices checked :print-checks-loading? print-checks-loading?}]) @@ -704,9 +704,9 @@ ])) - :component-will-mount #(re-frame/dispatch-sync [::params-change {:status status}]) })) + :component-will-mount #(re-frame/dispatch-sync [::params-change params]) })) -(defn unpaid-invoices-page [{:keys [status]}] +(defn unpaid-invoices-page [params] (let [{invoice-bar-active? :active?} @(re-frame/subscribe [::forms/form ::form/form])] [side-bar-layout {:side-bar [invoices-side-bar {} ^{:key "extra-filter"} @@ -723,9 +723,8 @@ [:p.menu-label "Invoice #"] [:div [invoice-number-filter]]]] - :main [unpaid-invoices-content {:status status}] + :main [unpaid-invoices-content params] :bottom [:div - [check-results-dialog] [print-checks-modal] [handwrite-checks-modal]