making sysco and mama lus work.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
form.dz { border: 2px dashed lightgray;}
|
form.dz .notification { border: 2px dashed lightgray;}
|
||||||
|
|
||||||
html,body {
|
html,body {
|
||||||
font-family: 'Open Sans', serif;
|
font-family: 'Open Sans', serif;
|
||||||
|
|||||||
@@ -91,7 +91,7 @@
|
|||||||
(sort-by second)
|
(sort-by second)
|
||||||
ffirst)
|
ffirst)
|
||||||
|
|
||||||
word-set (set (str/split (.toLowerCase invoice-client-name) #"\s" ))
|
word-set (set (str/split (.toLowerCase invoice-client-name) #"[\s:]" ))
|
||||||
client-word-match (->> clients
|
client-word-match (->> clients
|
||||||
(map
|
(map
|
||||||
(fn [{:keys [:db/id :client/matches :client/name] :as client :or {matches []}}]
|
(fn [{:keys [:db/id :client/matches :client/name] :as client :or {matches []}}]
|
||||||
|
|||||||
@@ -7,11 +7,15 @@
|
|||||||
(defn determine
|
(defn determine
|
||||||
[[header :as z]]
|
[[header :as z]]
|
||||||
(prn header)
|
(prn header)
|
||||||
(cond (str/includes? (second header) "Customer's PO No.")
|
(doto (cond (str/includes? (second header) "Customer's PO No.")
|
||||||
:mama-lus
|
:mama-lus
|
||||||
|
|
||||||
:else
|
(str/includes? (str header) "Closed Date")
|
||||||
nil))
|
:sysco
|
||||||
|
|
||||||
|
:else
|
||||||
|
nil)
|
||||||
|
println))
|
||||||
|
|
||||||
(defmulti parse-csv
|
(defmulti parse-csv
|
||||||
determine
|
determine
|
||||||
@@ -29,6 +33,23 @@
|
|||||||
(first))]
|
(first))]
|
||||||
(u/parse-value :clj-time valid-fmt d)))
|
(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
|
(defmethod parse-csv :mama-lus
|
||||||
[rows]
|
[rows]
|
||||||
(println "MAMA LU4")
|
(println "MAMA LU4")
|
||||||
@@ -51,7 +72,6 @@
|
|||||||
nil)
|
nil)
|
||||||
|
|
||||||
(defn parse-file [file filename]
|
(defn parse-file [file filename]
|
||||||
(println "HEREERE")
|
|
||||||
(with-open [reader (io/reader file)]
|
(with-open [reader (io/reader file)]
|
||||||
(let [rows (csv/read-csv reader :separator \,)]
|
(let [rows (csv/read-csv reader :separator \,)]
|
||||||
(parse-csv rows))))
|
(parse-csv rows))))
|
||||||
|
|||||||
@@ -324,6 +324,30 @@
|
|||||||
:total [#"Total Invoice" 0 5]
|
:total [#"Total Invoice" 0 5]
|
||||||
:date [#"Date" 0 0 #"Date: (.*)"]
|
:date [#"Date" 0 0 #"Date: (.*)"]
|
||||||
:invoice-number [#"Invoice #" 0 0 #"Invoice #: (.*)"]}}
|
: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 date
|
||||||
|
:invoice-number (str customer-order-number "-" (int num))
|
||||||
|
:total (str amount)
|
||||||
|
:vendor-code vendor}))))
|
||||||
|
conj
|
||||||
|
[]
|
||||||
|
(d/row-seq sheet))))}
|
||||||
{:vendor "DVW Commercial"
|
{:vendor "DVW Commercial"
|
||||||
:keywords [#"Total for" #"Num"]
|
:keywords [#"Total for" #"Num"]
|
||||||
:extract (fn [wb vendor]
|
:extract (fn [wb vendor]
|
||||||
@@ -351,30 +375,6 @@
|
|||||||
:keywords [#"Alt_invoice_number"]
|
:keywords [#"Alt_invoice_number"]
|
||||||
:extract (fn [wb vendor]
|
:extract (fn [wb vendor]
|
||||||
(let [[sheet] (d/sheet-seq wb)]
|
(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
|
(transduce (comp
|
||||||
(drop-while (fn [c]
|
(drop-while (fn [c]
|
||||||
(not (re-find #"Customer_id" (str (d/read-cell c))))))
|
(not (re-find #"Customer_id" (str (d/read-cell c))))))
|
||||||
|
|||||||
@@ -159,9 +159,8 @@
|
|||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
(defn import-uploaded-invoice [imports]
|
(defn import-uploaded-invoice [client forced-location imports]
|
||||||
(let [clients (d-clients/get-all)
|
(let [clients (d-clients/get-all)
|
||||||
|
|
||||||
transactions (reduce (fn [result {:keys [invoice-number customer-identifier total date vendor-code text full-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
|
||||||
@@ -177,9 +176,21 @@
|
|||||||
:customer-identifier customer-identifier
|
:customer-identifier customer-identifier
|
||||||
:vendor-code vendor-code})))
|
:vendor-code vendor-code})))
|
||||||
_ (println "matching" customer-identifier "-" matching-vendor)
|
_ (println "matching" customer-identifier "-" matching-vendor)
|
||||||
matching-client (parse/best-match clients customer-identifier)
|
matching-client (or (and customer-identifier
|
||||||
_ (println "invoice \"" invoice-number "\"matches client" (:client/name matching-client))
|
(parse/best-match clients customer-identifier))
|
||||||
matching-location (parse/best-location-match matching-client text full-text)
|
(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)
|
[existing-id existing-outstanding-balance existing-status import-status] (when (and matching-client matching-location)
|
||||||
(try
|
(try
|
||||||
(->> (d/query
|
(->> (d/query
|
||||||
@@ -277,16 +288,20 @@
|
|||||||
|
|
||||||
(context "/invoices" []
|
(context "/invoices" []
|
||||||
(POST "/upload"
|
(POST "/upload"
|
||||||
{{ files "file"} :params :as params}
|
{{ files "file"
|
||||||
|
client "client"
|
||||||
|
location "location"} :params :as params}
|
||||||
(let [{:keys [filename tempfile]} files]
|
(let [{:keys [filename tempfile]} files]
|
||||||
|
(println params)
|
||||||
(try
|
(try
|
||||||
(import-uploaded-invoice (parse/parse-file (.getPath tempfile) filename))
|
(import-uploaded-invoice client location (parse/parse-file (.getPath tempfile) filename))
|
||||||
{:status 200
|
{:status 200
|
||||||
:body (pr-str {})
|
:body (pr-str {})
|
||||||
:headers {"Content-Type" "application/edn"}}
|
:headers {"Content-Type" "application/edn"}}
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
{:status 500
|
{:status 500
|
||||||
:body (pr-str {:message (.getMessage e)
|
:body (pr-str {:message (.getMessage e)
|
||||||
|
:error (.toString e)
|
||||||
:data (ex-data e)})
|
:data (ex-data e)})
|
||||||
:headers {"Content-Type" "application/edn"}}))
|
:headers {"Content-Type" "application/edn"}}))
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -11,14 +11,21 @@
|
|||||||
[auto-ap.entities.vendors :as vendor]
|
[auto-ap.entities.vendors :as vendor]
|
||||||
[auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table]
|
[auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table]
|
||||||
[cljsjs.dropzone :as dropzone]
|
[cljsjs.dropzone :as dropzone]
|
||||||
[cljs.reader :as edn]))
|
[cljs.reader :as edn]
|
||||||
|
[clojure.string :as str]))
|
||||||
(def dropzone
|
(def dropzone
|
||||||
(let [client (re-frame/subscribe [::subs/client])
|
(let [client (re-frame/subscribe [::subs/client])
|
||||||
token (re-frame/subscribe [::subs/token])]
|
token (re-frame/subscribe [::subs/token])]
|
||||||
(with-meta
|
(with-meta
|
||||||
(fn []
|
(fn []
|
||||||
[:form.dz {:action "/api/invoices/upload"}
|
[: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.tile.notification
|
||||||
|
|
||||||
[:div.has-text-centered {:style {:padding "80px 0px" :width "100%"}}
|
[:div.has-text-centered {:style {:padding "80px 0px" :width "100%"}}
|
||||||
[:span
|
[:span
|
||||||
[:span {:class "icon"}
|
[:span {:class "icon"}
|
||||||
@@ -30,7 +37,7 @@
|
|||||||
(.on (js-this) "success" (fn [_ files]
|
(.on (js-this) "success" (fn [_ files]
|
||||||
(re-frame/dispatch [::invalidated])))
|
(re-frame/dispatch [::invalidated])))
|
||||||
(.on (js-this) "error" (fn [_ error]
|
(.on (js-this) "error" (fn [_ error]
|
||||||
(re-frame/dispatch [::errored error]))))
|
(re-frame/dispatch [::errored error]))))
|
||||||
:paramName "file"
|
:paramName "file"
|
||||||
:headers {"Authorization" (str "Token " @token)}
|
:headers {"Authorization" (str "Token " @token)}
|
||||||
:url (str "/api/invoices/upload"
|
:url (str "/api/invoices/upload"
|
||||||
@@ -39,6 +46,7 @@
|
|||||||
:previewsContainer "#dz-hidden"
|
:previewsContainer "#dz-hidden"
|
||||||
:previewTemplate "<div class='dz-hidden-preview'></div>"})))})))
|
:previewTemplate "<div class='dz-hidden-preview'></div>"})))})))
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::invoice-page
|
::invoice-page
|
||||||
(fn [db]
|
(fn [db]
|
||||||
@@ -171,6 +179,7 @@
|
|||||||
error (re-frame/subscribe [::error])]
|
error (re-frame/subscribe [::error])]
|
||||||
[:div
|
[:div
|
||||||
[:h1.title "Upload invoices"]
|
[:h1.title "Upload invoices"]
|
||||||
|
|
||||||
[dropzone]
|
[dropzone]
|
||||||
|
|
||||||
|
|
||||||
@@ -191,9 +200,7 @@
|
|||||||
:invoice-page invoice-page
|
:invoice-page invoice-page
|
||||||
:overrides {:client (fn [row]
|
:overrides {:client (fn [row]
|
||||||
[:p (:name (:client row))
|
[:p (:name (:client row))
|
||||||
[:p [:i.is-size-7 (:client-identifier row)]]]
|
[:p [:i.is-size-7 (:client-identifier row)]]])}
|
||||||
|
|
||||||
)}
|
|
||||||
:check-boxes true
|
:check-boxes true
|
||||||
:checked (:checked @invoice-page)
|
:checked (:checked @invoice-page)
|
||||||
:on-check-changed (fn [which invoice]
|
:on-check-changed (fn [which invoice]
|
||||||
|
|||||||
Reference in New Issue
Block a user