several fixes.

This commit is contained in:
Bryce Covert
2020-04-25 08:33:37 -07:00
parent b6696c8c45
commit a8736f351e
5 changed files with 45 additions and 48 deletions

View File

@@ -12,10 +12,13 @@
(update :vendor/terms-overrides (fn [to] (filter #(clients (:db/id (:vendor-terms-override/client %))) to)))) (update :vendor/terms-overrides (fn [to] (filter #(clients (:db/id (:vendor-terms-override/client %))) to))))
vendor))) vendor)))
(def default-read
'[* {:vendor/account-overrides [* {:vendor-account-override/client [:client/name :db/id]
:vendor-account-override/account [:account/name :account/numeric-code :db/id]}]
:vendor/terms-overrides [* {:vendor-terms-override/client [:client/name :db/id]}]}])
(defn get-graphql [args] (defn get-graphql [args]
(->> (cond-> {:query {:find ['(pull ?e [* {:vendor/account-overrides [* {:vendor-account-override/client [:client/name :db/id] (->> (cond-> {:query {:find [(list 'pull '?e default-read)]
:vendor-account-override/account [:account/name :account/numeric-code :db/id]}]
:vendor/terms-overrides [* {:vendor-terms-override/client [:client/name :db/id]}]}])]
:in ['$] :in ['$]
:where ['[?e :vendor/name]]} :where ['[?e :vendor/name]]}
:args [(d/db (d/connect uri))]}) :args [(d/db (d/connect uri))]})

View File

@@ -75,8 +75,7 @@
:invoice/expense-accounts (map expense-account->entity :invoice/expense-accounts (map expense-account->entity
expense_accounts)} expense_accounts)}
(:vendor/terms vendor) (assoc :invoice/due (coerce/to-date (:vendor/terms vendor) (assoc :invoice/due (coerce/to-date
(time/plus date (time/days (or (d-vendors/terms-for-client-id vendor client_id) (time/plus date (time/days (d-vendors/terms-for-client-id vendor client_id)))))
(:vendor/terms vendor))))))
due (assoc :invoice/due (coerce/to-date due))))) due (assoc :invoice/due (coerce/to-date due)))))

View File

@@ -36,19 +36,22 @@
(defmethod parse-csv :sysco (defmethod parse-csv :sysco
[rows] [rows]
(println "Importing Sysco") (println "Importing Sysco")
(transduce (let [header (first rows)]
(comp (drop 1) (transduce
(map (fn [[invoice-number invoice-date _ amount :as row]] (comp (drop 1)
{:vendor-code "Sysco" (map (fn [row]
:customer-identifier nil (into {} (map vector header row))))
:invoice-number invoice-number (map (fn [row]
:date (parse-date-fallover invoice-date ["M/d/yyyy"]) {:vendor-code "Sysco"
:total (str/replace amount #"[,\$]" "") :customer-identifier nil
:text (str/join " " row) :invoice-number (get row "Inv #")
:full-text (str/join " " row)}))) :date (parse-date-fallover (get row "Invoice Date") ["M/d/yyyy"])
conj :total (str/replace (get row "Orig Amt") #"[,\$]" "")
[] :text (str/join " " (vals row))
rows)) :full-text (str/join " " (vals row))})))
conj
[]
rows)))
(defmethod parse-csv :mama-lus (defmethod parse-csv :mama-lus
[rows] [rows]

View File

@@ -111,11 +111,11 @@
:extract {:date #"([0-9]+/[0-9]+/[0-9]+)" :extract {:date #"([0-9]+/[0-9]+/[0-9]+)"
:customer-identifier #"Bill To:(?:.*?(?=\s{2,}))(.*)-" :customer-identifier #"Bill To:(?:.*?(?=\s{2,}))(.*)-"
:invoice-number #"Invoice\s+([0-9]+)" :invoice-number #"Invoice\s+([0-9]+)"
:total #"\$([0-9\.,]+)"} :total #"([0-9\.,]+)$"}
:parser {:date [:clj-time "MM/dd/yyyy"] :parser {:date [:clj-time "MM/dd/yyyy"]
:total [:trim-commas nil]} :total [:trim-commas nil]}
:multi #"\n" :multi #"\n"
:multi-match? #"^ [0-9]+"} :multi-match? #"^\s{1,2}[0-9]+"}
;; Royal Hawaiian ;; Royal Hawaiian
{:vendor "Royal Hawaiian" {:vendor "Royal Hawaiian"

View File

@@ -184,22 +184,12 @@
:customer-identifier customer-identifier :customer-identifier customer-identifier
:vendor-code vendor-code}))) :vendor-code vendor-code})))
[matching-vendor default-account] (->> (d/query [matching-vendor] (->> (d/query
{:query {:find ['?vendor '?default-account] {:query {:find [(list 'pull '?vendor d-vendors/default-read)]
:in ['$ '?vendor-name] :in ['$ '?vendor-name]
:where ['[?vendor :vendor/name ?vendor-name] :where ['[?vendor :vendor/name ?vendor-name]]}
'[?vendor :vendor/default-account ?default-account]]}
:args [(d/db (d/connect uri)) vendor-code]}) :args [(d/db (d/connect uri)) vendor-code]})
first) first)
[account-override] (->> (d/query
{:query {:find ['?account-override-account]
:in ['$ '?vendor '?client]
:where ['[?vendor :vendor/account-overrides ?account-override]
'[?account-override :vendor-account-override/client ?client]
'[?account-override :vendor-account-override/account ?account-override-account]]}
:args [(d/db (d/connect uri)) matching-vendor (:db/id matching-client)]})
first)
_ (when-not matching-vendor _ (when-not matching-vendor
(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.")
{:invoice-number invoice-number {:invoice-number invoice-number
@@ -221,7 +211,7 @@
[?e :invoice/status ?status] [?e :invoice/status ?status]
[?e :invoice/import-status ?import-status] [?e :invoice/import-status ?import-status]
[?import-status :db/ident ?import-status2]]} [?import-status :db/ident ?import-status2]]}
:args [(d/db (d/connect uri)) invoice-number matching-vendor (:db/id matching-client)]})) :args [(d/db (d/connect uri)) invoice-number (:db/id matching-vendor) (:db/id matching-client)]}))
first) first)
(catch Exception e (catch Exception e
(throw (ex-info (str "Failed to find potential matching invoice with" (throw (ex-info (str "Failed to find potential matching invoice with"
@@ -239,20 +229,22 @@
result result
:else :else
(conj result (remove-nils #:invoice {:invoice/client (:db/id matching-client) (conj result (cond-> (remove-nils #:invoice {:invoice/client (:db/id matching-client)
:invoice/client-identifier customer-identifier :invoice/client-identifier customer-identifier
:invoice/vendor matching-vendor :invoice/vendor matching-vendor
:invoice/invoice-number invoice-number :invoice/invoice-number invoice-number
:invoice/total (Double/parseDouble total) :invoice/total (Double/parseDouble total)
:invoice/date (to-date date) :invoice/date (to-date date)
:invoice/import-status :import-status/pending :invoice/import-status :import-status/pending
:invoice/outstanding-balance (or existing-outstanding-balance (Double/parseDouble total)) :invoice/outstanding-balance (or existing-outstanding-balance (Double/parseDouble total))
:invoice/status (or existing-status :invoice-status/unpaid) :invoice/status (or existing-status :invoice-status/unpaid)
:invoice/expense-accounts (when-not existing-id [#:invoice-expense-account {:account (or account-override default-account) :invoice/expense-accounts (when-not existing-id [#:invoice-expense-account {:account (d-vendors/account-for-client-id matching-vendor (:db/id matching-client))
:location matching-location :location matching-location
:amount (Double/parseDouble total)}]) :amount (Double/parseDouble total)}])
:db/id existing-id :db/id existing-id
}))) })
(:vendor/terms matching-vendor) (assoc :invoice/due (coerce/to-date
(time/plus date (time/days (d-vendors/terms-for-client-id matching-vendor (:db/id matching-client)))))))))
)) ))
[] []
imports)] imports)]