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/doc "A vendor-specified number for the invoice",
: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/cardinality #:db{:ident :db.cardinality/one},
:db/doc "An identifier found to suggest the customer",

View File

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

View File

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

View File

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

View File

@@ -489,8 +489,11 @@
(and (= (count (:clients args)) 1)
(= 1 (count (:client/locations (:client args))))))
: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"
:name "Vendor"
:sort-key "vendor"
@@ -618,7 +621,7 @@
(throw (ex-info (str "No vendor with the name " vendor-code " was found.")
{: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
(throw (Exception. "Couldn't parse total from file.")))
(when-not date
@@ -646,6 +649,7 @@
text
full-text))]
#:invoice {:db/id (random-tempid)
:invoice/uploader (-> user :db/id)
:invoice/client matching-client
:invoice/client-identifier (or account-number customer-identifier)
:invoice/vendor (:db/id matching-vendor)
@@ -683,7 +687,7 @@
(alog/info ::importing-uploaded :count (count imports)
:bc (or user "NOO"))
(let [potential-invoices (->> imports
(map import->invoice)
(map #(import->invoice % user))
(map #(validate-invoice % user))
admin-only-if-multiple-clients
(mapv d-invoices/code-invoice)