Allows upload of CSV of sysco with line item parsing
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
[auto-ap.graphql.utils :refer [assert-can-see-client assert-not-locked
|
||||
can-see-client? exception->notification
|
||||
extract-client-ids]]
|
||||
[auto-ap.jobs.sysco :as sysco]
|
||||
[auto-ap.logging :as alog]
|
||||
[auto-ap.parse :as parse]
|
||||
[auto-ap.permissions :refer [can? wrap-must]]
|
||||
@@ -597,7 +598,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]} user]
|
||||
(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 line-items]} user]
|
||||
(when-not total
|
||||
(throw (Exception. "Couldn't parse total from file.")))
|
||||
(when-not date
|
||||
@@ -624,19 +625,20 @@
|
||||
matching-client)
|
||||
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)
|
||||
:invoice/source-url source-url
|
||||
:invoice/invoice-number invoice-number
|
||||
:invoice/total (Double/parseDouble total)
|
||||
:invoice/date (to-date date)
|
||||
:invoice/location matching-location
|
||||
:invoice/import-status (or import-status :import-status/pending)
|
||||
:invoice/outstanding-balance (Double/parseDouble total)
|
||||
:invoice/status :invoice-status/unpaid}))
|
||||
(cond-> #: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)
|
||||
:invoice/source-url source-url
|
||||
:invoice/invoice-number invoice-number
|
||||
:invoice/total (Double/parseDouble total)
|
||||
:invoice/date (to-date date)
|
||||
:invoice/location matching-location
|
||||
:invoice/import-status (or import-status :import-status/pending)
|
||||
:invoice/outstanding-balance (Double/parseDouble total)
|
||||
:invoice/status :invoice-status/unpaid}
|
||||
(seq line-items) (assoc :line-items line-items))))
|
||||
|
||||
(defn validate-invoice [invoice user]
|
||||
(let [missing-keys (for [k [:invoice/invoice-number :invoice/client :invoice/vendor :invoice/total :invoice/outstanding-balance :invoice/date]
|
||||
@@ -681,6 +683,7 @@
|
||||
proposed-invoices (->> potential-invoices
|
||||
(filter #(not (:error-message %)))
|
||||
(mapv d-invoices/code-invoice)
|
||||
(mapv sysco/maybe-code-line-items)
|
||||
(mapv (fn [i] [:propose-invoice i])))]
|
||||
|
||||
(alog/info ::creating-invoice :invoices proposed-invoices)
|
||||
|
||||
Reference in New Issue
Block a user