several fixes.
This commit is contained in:
@@ -12,10 +12,13 @@
|
||||
(update :vendor/terms-overrides (fn [to] (filter #(clients (:db/id (:vendor-terms-override/client %))) to))))
|
||||
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]
|
||||
(->> (cond-> {:query {:find ['(pull ?e [* {: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]}]}])]
|
||||
(->> (cond-> {:query {:find [(list 'pull '?e default-read)]
|
||||
:in ['$]
|
||||
:where ['[?e :vendor/name]]}
|
||||
:args [(d/db (d/connect uri))]})
|
||||
|
||||
@@ -75,8 +75,7 @@
|
||||
:invoice/expense-accounts (map expense-account->entity
|
||||
expense_accounts)}
|
||||
(:vendor/terms vendor) (assoc :invoice/due (coerce/to-date
|
||||
(time/plus date (time/days (or (d-vendors/terms-for-client-id vendor client_id)
|
||||
(:vendor/terms vendor))))))
|
||||
(time/plus date (time/days (d-vendors/terms-for-client-id vendor client_id)))))
|
||||
due (assoc :invoice/due (coerce/to-date due)))))
|
||||
|
||||
|
||||
|
||||
@@ -36,19 +36,22 @@
|
||||
(defmethod parse-csv :sysco
|
||||
[rows]
|
||||
(println "Importing Sysco")
|
||||
(transduce
|
||||
(comp (drop 1)
|
||||
(map (fn [[invoice-number invoice-date _ amount :as row]]
|
||||
{:vendor-code "Sysco"
|
||||
:customer-identifier nil
|
||||
:invoice-number invoice-number
|
||||
:date (parse-date-fallover invoice-date ["M/d/yyyy"])
|
||||
:total (str/replace amount #"[,\$]" "")
|
||||
:text (str/join " " row)
|
||||
:full-text (str/join " " row)})))
|
||||
conj
|
||||
[]
|
||||
rows))
|
||||
(let [header (first rows)]
|
||||
(transduce
|
||||
(comp (drop 1)
|
||||
(map (fn [row]
|
||||
(into {} (map vector header row))))
|
||||
(map (fn [row]
|
||||
{:vendor-code "Sysco"
|
||||
:customer-identifier nil
|
||||
:invoice-number (get row "Inv #")
|
||||
:date (parse-date-fallover (get row "Invoice Date") ["M/d/yyyy"])
|
||||
:total (str/replace (get row "Orig Amt") #"[,\$]" "")
|
||||
:text (str/join " " (vals row))
|
||||
:full-text (str/join " " (vals row))})))
|
||||
conj
|
||||
[]
|
||||
rows)))
|
||||
|
||||
(defmethod parse-csv :mama-lus
|
||||
[rows]
|
||||
|
||||
@@ -111,11 +111,11 @@
|
||||
:extract {:date #"([0-9]+/[0-9]+/[0-9]+)"
|
||||
:customer-identifier #"Bill To:(?:.*?(?=\s{2,}))(.*)-"
|
||||
:invoice-number #"Invoice\s+([0-9]+)"
|
||||
:total #"\$([0-9\.,]+)"}
|
||||
:total #"([0-9\.,]+)$"}
|
||||
:parser {:date [:clj-time "MM/dd/yyyy"]
|
||||
:total [:trim-commas nil]}
|
||||
:multi #"\n"
|
||||
:multi-match? #"^ [0-9]+"}
|
||||
:multi-match? #"^\s{1,2}[0-9]+"}
|
||||
|
||||
;; Royal Hawaiian
|
||||
{:vendor "Royal Hawaiian"
|
||||
|
||||
@@ -184,22 +184,12 @@
|
||||
:customer-identifier customer-identifier
|
||||
:vendor-code vendor-code})))
|
||||
|
||||
[matching-vendor default-account] (->> (d/query
|
||||
{:query {:find ['?vendor '?default-account]
|
||||
[matching-vendor] (->> (d/query
|
||||
{:query {:find [(list 'pull '?vendor d-vendors/default-read)]
|
||||
:in ['$ '?vendor-name]
|
||||
:where ['[?vendor :vendor/name ?vendor-name]
|
||||
'[?vendor :vendor/default-account ?default-account]]}
|
||||
:where ['[?vendor :vendor/name ?vendor-name]]}
|
||||
:args [(d/db (d/connect uri)) vendor-code]})
|
||||
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
|
||||
(throw (ex-info (str "No vendor with the name " vendor-code " was found.")
|
||||
{:invoice-number invoice-number
|
||||
@@ -221,7 +211,7 @@
|
||||
[?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)]}))
|
||||
:args [(d/db (d/connect uri)) invoice-number (:db/id matching-vendor) (:db/id matching-client)]}))
|
||||
first)
|
||||
(catch Exception e
|
||||
(throw (ex-info (str "Failed to find potential matching invoice with"
|
||||
@@ -239,20 +229,22 @@
|
||||
result
|
||||
|
||||
:else
|
||||
(conj result (remove-nils #:invoice {:invoice/client (:db/id matching-client)
|
||||
:invoice/client-identifier customer-identifier
|
||||
:invoice/vendor matching-vendor
|
||||
:invoice/invoice-number invoice-number
|
||||
:invoice/total (Double/parseDouble total)
|
||||
:invoice/date (to-date date)
|
||||
:invoice/import-status :import-status/pending
|
||||
:invoice/outstanding-balance (or existing-outstanding-balance (Double/parseDouble total))
|
||||
:invoice/status (or existing-status :invoice-status/unpaid)
|
||||
:invoice/expense-accounts (when-not existing-id [#:invoice-expense-account {:account (or account-override default-account)
|
||||
:location matching-location
|
||||
:amount (Double/parseDouble total)}])
|
||||
:db/id existing-id
|
||||
})))
|
||||
(conj result (cond-> (remove-nils #:invoice {:invoice/client (:db/id matching-client)
|
||||
:invoice/client-identifier customer-identifier
|
||||
:invoice/vendor matching-vendor
|
||||
:invoice/invoice-number invoice-number
|
||||
:invoice/total (Double/parseDouble total)
|
||||
:invoice/date (to-date date)
|
||||
:invoice/import-status :import-status/pending
|
||||
:invoice/outstanding-balance (or existing-outstanding-balance (Double/parseDouble total))
|
||||
:invoice/status (or existing-status :invoice-status/unpaid)
|
||||
: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
|
||||
:amount (Double/parseDouble total)}])
|
||||
: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)]
|
||||
|
||||
Reference in New Issue
Block a user