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 {
|
||||
font-family: 'Open Sans', serif;
|
||||
|
||||
@@ -91,7 +91,7 @@
|
||||
(sort-by second)
|
||||
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
|
||||
(map
|
||||
(fn [{:keys [:db/id :client/matches :client/name] :as client :or {matches []}}]
|
||||
|
||||
@@ -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))))
|
||||
|
||||
@@ -324,6 +324,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 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 +375,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))))))
|
||||
|
||||
@@ -159,9 +159,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-expense-account] (->> (d/query
|
||||
@@ -177,9 +176,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
|
||||
@@ -277,16 +288,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"}}))
|
||||
))
|
||||
|
||||
@@ -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 "<div class='dz-hidden-preview'></div>"})))})))
|
||||
|
||||
|
||||
(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]
|
||||
|
||||
Reference in New Issue
Block a user