Adds uploaded by for invoices, fixes REEL Produce, adds Mani Produce

This commit is contained in:
2024-09-25 08:36:45 -07:00
parent bcd78e7813
commit dc44233640
5 changed files with 44 additions and 26 deletions

View File

@@ -677,6 +677,10 @@
:db/cardinality #:db{:ident :db.cardinality/one}, :db/cardinality #:db{:ident :db.cardinality/one},
:db/doc "A vendor-specified number for the invoice", :db/doc "A vendor-specified number for the invoice",
:db/ident :invoice/invoice-number} :db/ident :invoice/invoice-number}
{:db/valueType :db.type/ref,
:db/cardinality :db.cardinality/one,
:db/doc "Who uploaded the invoice?",
:db/ident :invoice/uploader}
{:db/valueType #:db{:ident :db.type/string}, {:db/valueType #:db{:ident :db.type/string},
:db/cardinality #:db{:ident :db.cardinality/one}, :db/cardinality #:db{:ident :db.cardinality/one},
:db/doc "An identifier found to suggest the customer", :db/doc "An identifier found to suggest the customer",

View File

@@ -199,5 +199,4 @@
(println v) (println v)
(map (map
(fn [x] (dissoc x :full-text :text)) (fn [x] (dissoc x :full-text :text))
(parse v))) (parse v)))

View File

@@ -1,5 +1,6 @@
(ns auto-ap.parse.templates (ns auto-ap.parse.templates
(:require [auto-ap.parse.util :as u] (:require [auto-ap.parse.util :as u]
[auto-ap.logging :as alog]
[clojure.string :as str])) [clojure.string :as str]))
@@ -700,8 +701,16 @@
:total [:trim-commas-and-negate nil]} :total [:trim-commas-and-negate nil]}
:multi #"\n" :multi #"\n"
:multi-match? #"^\s*Invoice\s{2,}"} :multi-match? #"^\s*Invoice\s{2,}"}
{:vendor "Mani Imports"
:keywords [#"Mani Imports"]
:extract {:date #"Order Date\s+([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"Ship To:\s*(.*?)\n"
:invoice-number #"Invoice Number:\s+(.*?)\n"
:total #"Invoice Total:\s+([\d\-,]+\.\d{2,2}+)"}
:parser {:date [:clj-time "MM/dd/yyyy"]
:total [:trim-commas-and-negate nil]} }
{:vendor "Reel Produce" {:vendor "Reel Produce"
:keywords [#"REEL Produce, Inc" #"Statement"] :keywords [#"REEL Produce, Inc" #"Statem"]
:extract {:date #"\s*([0-9]+/[0-9]+/[0-9]+)" :extract {:date #"\s*([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"To:\s*\n\s+(.*?)\s{2,}" :customer-identifier #"To:\s*\n\s+(.*?)\s{2,}"
:invoice-number #"INV #(\d+)" :invoice-number #"INV #(\d+)"
@@ -749,22 +758,23 @@
{:vendor "Daylight Foods" {:vendor "Daylight Foods"
:keywords [#"CUSTNO"] :keywords [#"CUSTNO"]
:extract (fn [sheet vendor] :extract (fn [sheet vendor]
(transduce (comp (alog/peek ::daylight-invoices
(drop 1) (transduce (comp
(filter (drop 1)
(fn [r] (filter
(and (fn [r]
(seq r) (and
(->> r first not-empty)))) (seq r)
(map (->> r first not-empty))))
(fn [[customer-number _ _ _ invoice-number date amount :as row]] (map
{:customer-identifier customer-number (fn [[customer-number _ _ _ invoice-number date amount :as row]]
:text (str/join " " row) {:customer-identifier customer-number
:full-text (str/join " " row) :text (str/join " " row)
:date (u/parse-value :clj-time "MM/dd/yyyy" (str/trim date)) :full-text (str/join " " row)
:invoice-number invoice-number :date (u/parse-value :clj-time "MM/dd/yyyy" (str/trim date))
:total (str amount) :invoice-number invoice-number
:vendor-code vendor}))) :total (str amount)
conj :vendor-code vendor})))
[] conj
sheet))}]) []
sheet)))}])

View File

@@ -3,6 +3,7 @@
(def default-read '[:db/id (def default-read '[:db/id
:invoice/invoice-number :invoice/invoice-number
:invoice/total :invoice/total
{ :invoice/uploader [:user/name]}
:invoice/outstanding-balance :invoice/outstanding-balance
:invoice/source-url :invoice/source-url
:invoice/location :invoice/location

View File

@@ -489,8 +489,11 @@
(and (= (count (:clients args)) 1) (and (= (count (:clients args)) 1)
(= 1 (count (:client/locations (:client args)))))) (= 1 (count (:client/locations (:client args))))))
:render (fn [x] [:div.flex.items-center.gap-2 (-> x :invoice/client :client/name) :render (fn [x] [:div.flex.items-center.gap-2 (-> x :invoice/client :client/name)
(com/pill {:color :primary} (-> x :invoice/location)) (com/pill {:color :primary} (-> x :invoice/location))])}
])} {:key "uploader"
:name "Uploaded by"
:sort-key "uploader"
:render #(-> % :invoice/uploader :user/name)}
{:key "vendor" {:key "vendor"
:name "Vendor" :name "Vendor"
:sort-key "vendor" :sort-key "vendor"
@@ -618,7 +621,7 @@
(throw (ex-info (str "No vendor with the name " vendor-code " was found.") (throw (ex-info (str "No vendor with the name " vendor-code " was found.")
{:vendor-code vendor-code}))))) {:vendor-code vendor-code})))))
(defn import->invoice [{:keys [invoice-number source-url customer-identifier account-number total date vendor-code text full-text client-override vendor-search vendor-override location-override import-status]}] (defn import->invoice [{:keys [invoice-number source-url customer-identifier account-number total date vendor-code text full-text client-override vendor-search vendor-override location-override import-status]} user]
(when-not total (when-not total
(throw (Exception. "Couldn't parse total from file."))) (throw (Exception. "Couldn't parse total from file.")))
(when-not date (when-not date
@@ -646,6 +649,7 @@
text text
full-text))] full-text))]
#:invoice {:db/id (random-tempid) #:invoice {:db/id (random-tempid)
:invoice/uploader (-> user :db/id)
:invoice/client matching-client :invoice/client matching-client
:invoice/client-identifier (or account-number customer-identifier) :invoice/client-identifier (or account-number customer-identifier)
:invoice/vendor (:db/id matching-vendor) :invoice/vendor (:db/id matching-vendor)
@@ -683,7 +687,7 @@
(alog/info ::importing-uploaded :count (count imports) (alog/info ::importing-uploaded :count (count imports)
:bc (or user "NOO")) :bc (or user "NOO"))
(let [potential-invoices (->> imports (let [potential-invoices (->> imports
(map import->invoice) (map #(import->invoice % user))
(map #(validate-invoice % user)) (map #(validate-invoice % user))
admin-only-if-multiple-clients admin-only-if-multiple-clients
(mapv d-invoices/code-invoice) (mapv d-invoices/code-invoice)