improvements for invoices.
This commit is contained in:
@@ -18,6 +18,17 @@
|
||||
:default (fn default [rows]
|
||||
nil))
|
||||
|
||||
(defn parse-date-fallover [d fmts]
|
||||
(if-let [valid-fmt (->> fmts
|
||||
(filter (fn [f]
|
||||
(try
|
||||
(u/parse-value :clj-time f d)
|
||||
(catch Exception e
|
||||
nil))
|
||||
))
|
||||
(first))]
|
||||
(u/parse-value :clj-time valid-fmt d)))
|
||||
|
||||
(defmethod parse-csv :mama-lus
|
||||
[rows]
|
||||
(println "MAMA LU4")
|
||||
@@ -27,9 +38,7 @@
|
||||
{:vendor-code "Mama Lu's Foods"
|
||||
:customer-identifier customer
|
||||
:invoice-number (str po-number "-" invoice-number )
|
||||
:date (try (u/parse-value :clj-time "M/d/yyyy HH:ss" invoice-date)
|
||||
(catch Exception _
|
||||
(u/parse-value :clj-time "M/d/yyyy" invoice-date)))
|
||||
:date (parse-date-fallover invoice-date ["M/d/yyyy HH:ss" "M/d/yyyy HH:mm:ss aa" "M/d/yyyy"])
|
||||
:total (str/replace value #"," "")
|
||||
:text (str/join " " row)
|
||||
:full-text (str/join " " row)})))
|
||||
|
||||
@@ -121,12 +121,12 @@
|
||||
;; Young's Market Co - INVOICE
|
||||
{:vendor "Youngs Market"
|
||||
:keywords [#"P.O.Box 743564"]
|
||||
:extract {:date #"INVOICE DATE\n(?:.*?)(\S+)\n"
|
||||
:customer-identifier #"INVOICE DATE\n [0-9]+\s+(.*?)\s{2,}"
|
||||
:invoice-number #"INVOICE DATE\n(?:.*?)\s{2,}(\d+?)\s+\S+\n"
|
||||
:total #"Net Amount(?:.*\n){4}(?:.*?)([0-9\.]+)\n"}
|
||||
:extract {:date #"(?:INVOICE|CREDIT) DATE\n(?:.*?)(\S+)\n"
|
||||
:customer-identifier #"(?:INVOICE|CREDIT) DATE\n [0-9]+\s+(.*?)\s{2,}"
|
||||
:invoice-number #"(?:INVOICE|CREDIT) DATE\n(?:.*?)\s{2,}(\d+?)\s+\S+\n"
|
||||
:total #"Net Amount(?:.*\n){4}(?:.*?)([\-]?[0-9\.]+)\n"}
|
||||
:parser {:date [:clj-time "dd-MMM-yy"]
|
||||
:total [:trim-commas nil]}}
|
||||
:total [:trim-commas-and-negate nil]}}
|
||||
|
||||
;; WINE WAREHOUSE
|
||||
{:vendor "Wine Warehouse"
|
||||
@@ -168,6 +168,16 @@
|
||||
:parser {:date [:clj-time "MM/dd/yyyy"]
|
||||
:total [:trim-commas nil]}}
|
||||
|
||||
;; P&R
|
||||
{:vendor "P & R PAPER SUPPLY CO"
|
||||
:keywords [#"PAPER SUPPLY COMPANY"]
|
||||
:extract {:date #"Invoiced.*\n\s+\S+\s+(\S+)"
|
||||
:customer-identifier #"Bill To.*\n\s*(.*?)\s{2,}"
|
||||
:invoice-number #"Invoice#.*\n.*\n.*?(\S+)\s+\d+\n"
|
||||
:total #"INVOICE TOTAL\s+([\-]?[\d,]+\.\d+)"}
|
||||
:parser {:date [:clj-time "MM/dd/yy"]
|
||||
:total [:trim-commas-and-negate nil]}}
|
||||
|
||||
;; SUNCREST STATEMENT
|
||||
{:vendor "Suncrest USA Inc"
|
||||
:keywords [#"Suncrest.*\n.*Statement"]
|
||||
@@ -196,8 +206,9 @@
|
||||
:extract {:date #"INVOICE NUMBER[^\n]+\n([^\n]+)\n"
|
||||
:customer-identifier #"INVOICE NUMBER[^\n]+\n[^\n]+\n([\S ]+?)(?=\s{2,})" ;; ([\S ]+)\s{2,}
|
||||
:invoice-number #"INVOICE NUMBER[^\n]+\n[^\n]+\n.*?(?=[\d]{9})(\d{9})"
|
||||
:total #"\s{2,}INVOICE\s{2,}.*?(?=TOTAL)TOTAL\s+([0-9.]+)"}
|
||||
:parser {:date [:clj-time "MM/dd/yyyy"]}}
|
||||
:total #"\s{2,}INVOICE\s{2,}.*?(?=TOTAL)TOTAL\s+([0-9.]+[\-]?)"}
|
||||
:parser {:date [:clj-time "MM/dd/yy"]
|
||||
:total [:trim-commas-and-negate nil]}}
|
||||
|
||||
;; LE BOULANGER
|
||||
{:vendor "Le Boulanger"
|
||||
@@ -263,6 +274,18 @@
|
||||
:multi #"\n"
|
||||
:multi-match? #"^\s+[\d]{6,8}\s+\d+"}
|
||||
|
||||
;; ACME BREAD
|
||||
{:vendor "Acme Bread"
|
||||
:keywords [#"acmebread\.com"]
|
||||
:extract {:date #"([0-9]+/[0-9]+/[0-9]+)"
|
||||
:customer-identifier #"Print Date.*\n.*\n(.*)"
|
||||
:invoice-number #"^\s*(\d+)"
|
||||
:total #"\s{2,}(\d+\.\d{2})\s{2,}"}
|
||||
:parser {:date [:clj-time "MM/dd/yyyy"]
|
||||
:total [:trim-commas-and-negate nil]}
|
||||
:multi #"\n"
|
||||
:multi-match? #"^\s*\d+\s+([0-9]+/[0-9]+/[0-9]+)"}
|
||||
|
||||
;; PFG - ROMA
|
||||
{:vendor "Performance Food Group - ROMA"
|
||||
:keywords [#"Performance Food Group, Inc\n\f"]
|
||||
|
||||
@@ -171,23 +171,36 @@
|
||||
'[?vendor :vendor/default-expense-account ?default-expense-account]]}
|
||||
:args [(d/db (d/connect uri)) vendor-code]})
|
||||
first)
|
||||
_ (when-not matching-vendor
|
||||
(throw (ex-info (str "No vendor with the name " vendor-code " was found.")
|
||||
{:invoice-number invoice-number
|
||||
:customer-identifier customer-identifier
|
||||
:vendor-code vendor-code})))
|
||||
_ (println "matching" customer-identifier "-" matching-vendor)
|
||||
matching-client (parse/best-match clients customer-identifier)
|
||||
_ (println "New invoice matches client" matching-client)
|
||||
matching-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
|
||||
(cond-> {:query {:find ['?e '?outstanding-balance '?status '?import-status2]
|
||||
:in ['$ '?invoice-number '?vendor '?client]
|
||||
:where '[[?e :invoice/invoice-number ?invoice-number]
|
||||
[?e :invoice/vendor ?vendor]
|
||||
[?e :invoice/client ?client]
|
||||
[?e :invoice/outstanding-balance ?outstanding-balance]
|
||||
[?e :invoice/status ?status]
|
||||
[?e :invoice/import-status ?import-status]
|
||||
[?import-status :db/ident ?import-status2]]}
|
||||
:args [(d/db (d/connect uri)) invoice-number matching-vendor (:db/id matching-client)]}))
|
||||
first))]
|
||||
(cond-> {:query {:find ['?e '?outstanding-balance '?status '?import-status2]
|
||||
:in ['$ '?invoice-number '?vendor '?client]
|
||||
:where '[[?e :invoice/invoice-number ?invoice-number]
|
||||
[?e :invoice/vendor ?vendor]
|
||||
[?e :invoice/client ?client]
|
||||
[?e :invoice/outstanding-balance ?outstanding-balance]
|
||||
[?e :invoice/status ?status]
|
||||
[?e :invoice/import-status ?import-status]
|
||||
[?import-status :db/ident ?import-status2]]}
|
||||
:args [(d/db (d/connect uri)) invoice-number matching-vendor (:db/id matching-client)]}))
|
||||
first)
|
||||
(catch Exception e
|
||||
(throw (ex-info (str "Failed to find potential matching invoice with"
|
||||
" invoice " invoice-number
|
||||
" vendor " matching-vendor
|
||||
" client " (:client/name matching-client))
|
||||
{:args [ invoice-number matching-vendor (:db/id matching-client)]})))
|
||||
))]
|
||||
|
||||
(cond
|
||||
(not (and matching-location matching-client))
|
||||
@@ -215,6 +228,9 @@
|
||||
[]
|
||||
imports)]
|
||||
|
||||
(when-not (seq transactions)
|
||||
(throw (ex-info "No invoices found."
|
||||
{:imports imports})))
|
||||
@(d/transact (d/connect uri) (vec (set transactions)))
|
||||
))
|
||||
|
||||
@@ -263,10 +279,17 @@
|
||||
(POST "/upload"
|
||||
{{ files "file"} :params :as params}
|
||||
(let [{:keys [filename tempfile]} files]
|
||||
(import-uploaded-invoice (parse/parse-file (.getPath tempfile) filename))
|
||||
{:status 200
|
||||
:body (pr-str {})
|
||||
:headers {"Content-Type" "application/edn"}}))
|
||||
(try
|
||||
(import-uploaded-invoice (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)
|
||||
:data (ex-data e)})
|
||||
:headers {"Content-Type" "application/edn"}}))
|
||||
))
|
||||
(POST "/upload-integreat"
|
||||
{{:keys [excel-rows]} :edn-params user :identity}
|
||||
(assert-admin user)
|
||||
|
||||
Reference in New Issue
Block a user