DVW statements

This commit is contained in:
Bryce Covert
2019-10-26 18:00:40 -07:00
parent f0e93ec3cf
commit 332eae2f58
5 changed files with 73 additions and 35 deletions

View File

@@ -108,8 +108,11 @@
(or (->> client (or (->> client
:client/location-matches :client/location-matches
(mapcat (fn [{:keys [:location-match/location :location-match/matches]}] (mapcat (fn [{:keys [:location-match/location :location-match/matches]}]
(map (fn [match] [location match]) matches))) (map (fn [match] [location match]) matches)))
(filter (fn [[location match]] (re-find (re-pattern (str "(?i)" match)) text)) ) (filter (fn [[location match]]
(println "loc " location match text)
(re-find (re-pattern (str "(?i)" match)) text)) )
first first
first) first)
(->> client (->> client

View File

@@ -10,38 +10,40 @@
(every? #(re-find % text) keywords)) (every? #(re-find % text) keywords))
(defn extract [wb {:keys [extract vendor]}] (defn extract [wb {:keys [extract vendor]}]
(reduce-kv (if (fn? extract)
(fn [invoice k [regex offset-row offset-column extract-regex]] (extract wb vendor)
(assoc invoice k [(reduce-kv
(->> wb (fn [invoice k [regex offset-row offset-column extract-regex]]
(d/sheet-seq) (assoc invoice k
first (->> wb
(d/cell-seq) (d/sheet-seq)
(filter (fn [cell] first
(re-find regex (str (d/read-cell cell))))) (d/cell-seq)
(map (fn [cell] (filter (fn [cell]
(let [address (.getAddress cell) (re-find regex (str (d/read-cell cell)))))
cell-value (str (d/read-cell (d/select-cell (.toString (CellAddress. (+ offset-row (.getRow address)) (+ offset-column (.getColumn address)) )) (map (fn [cell]
(first (d/sheet-seq wb)))))] (let [address (.getAddress cell)
(if extract-regex cell-value (str (d/read-cell (d/select-cell (.toString (CellAddress. (+ offset-row (.getRow address)) (+ offset-column (.getColumn address)) ))
(second (re-find extract-regex cell-value)) (first (d/sheet-seq wb)))))]
(if extract-regex
(second (re-find extract-regex cell-value))
cell-value)))) cell-value))))
first))) first)))
{:vendor-code vendor} {:vendor-code vendor}
extract)) extract)]))
(defn parse-file (defn parse-file
[file filename] [file filename]
[(let [wb (d/load-workbook file) (let [wb (d/load-workbook file)
text (->> wb text (->> wb
(d/sheet-seq) (d/sheet-seq)
first first
(d/cell-seq) (d/cell-seq)
(map d/read-cell) (map d/read-cell)
(str/join " "))] (str/join " "))]
(->> t/excel-templates (->> t/excel-templates
(filter (partial template-applies? text)) (filter (partial template-applies? text))
first first
(extract wb) (extract wb)
))]) )))

View File

@@ -1,4 +1,7 @@
(ns auto-ap.parse.templates) (ns auto-ap.parse.templates
(:require [dk.ative.docjure.spreadsheet :as d]
[clojure.string :as str])
(:import (org.apache.poi.ss.util CellAddress)))
(def pdf-templates (def pdf-templates
@@ -80,6 +83,9 @@
:total #"\s{2,}INVOICE\s{2,}.*?(?=TOTAL)TOTAL\s+([0-9.]+)"} :total #"\s{2,}INVOICE\s{2,}.*?(?=TOTAL)TOTAL\s+([0-9.]+)"}
:parser {:date [:clj-time "MM/dd/yyyy"]}}]) :parser {:date [:clj-time "MM/dd/yyyy"]}}])
(defn offset [c x y]
(.toString (CellAddress. (+ y (.getRow (.getAddress c))) (+ x (.getColumn (.getAddress c))) )))
(def excel-templates (def excel-templates
[{:vendor "Isp Productions" [{:vendor "Isp Productions"
:keywords [#"ISP PRODUCTIONS"] :keywords [#"ISP PRODUCTIONS"]
@@ -92,4 +98,27 @@
:extract {:customer-identifier [#"Customer #" 1 0] :extract {:customer-identifier [#"Customer #" 1 0]
: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 "DVW Commercial"
:keywords [#"Thank you!!!"]
:extract (fn [wb vendor]
(let [[sheet] (d/sheet-seq wb)]
(transduce (comp (filter (fn [c]
(re-find #"Invoice" (str (d/read-cell c)))))
(map (fn [c]
(let [customer-identifier (d/read-cell (->> (d/select-cell (offset c -3 0) sheet)
(iterate (fn [c]
(d/select-cell (offset c 0 -1) sheet)))
(filter (fn [c]
(not (str/blank? (d/read-cell c)))))
first))]
{:customer-identifier customer-identifier
:text customer-identifier
:full-text customer-identifier
:date (d/read-cell (d/select-cell (offset c 2 0) sheet))
:invoice-number (d/read-cell (d/select-cell (offset c 4 0) sheet))
:total (str (d/read-cell (d/select-cell (offset c 8 0) sheet)))
:vendor-code vendor}))))
conj
[]
(d/cell-seq sheet))))}])

View File

@@ -161,6 +161,7 @@
(defn import-uploaded-invoice [imports] (defn import-uploaded-invoice [imports]
(let [clients (d-clients/get-all) (let [clients (d-clients/get-all)
_ (clojure.pprint/pprint imports)
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)

View File

@@ -7,6 +7,7 @@
[auto-ap.views.components.layouts :refer [side-bar-layout]] [auto-ap.views.components.layouts :refer [side-bar-layout]]
[auto-ap.views.components.invoices.side-bar :refer [invoices-side-bar]] [auto-ap.views.components.invoices.side-bar :refer [invoices-side-bar]]
[auto-ap.views.utils :refer [dispatch-event]] [auto-ap.views.utils :refer [dispatch-event]]
[auto-ap.utils :refer [by]]
[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]
@@ -67,6 +68,8 @@
(fn [db [_ data]] (fn [db [_ data]]
(-> db (-> db
(assoc ::invoice-page (first (:invoice-page data))) (assoc ::invoice-page (first (:invoice-page data)))
(update-in [::invoice-page] (fn [ip]
(assoc ip :checked (by :id (:invoices ip)))))
(assoc-in [:status :loading] false)))) (assoc-in [:status :loading] false))))
(re-frame/reg-event-fx (re-frame/reg-event-fx