Now overrides actually make an impact
This commit is contained in:
@@ -23,3 +23,13 @@
|
||||
id)
|
||||
(map first)
|
||||
(first)))
|
||||
|
||||
(defn terms-for-client-id [vendor client-id]
|
||||
(->>
|
||||
(filter
|
||||
(fn [to]
|
||||
(= (:db/id (:vendor-terms-override/client to))
|
||||
client-id))
|
||||
(:vendor/terms-overrides vendor))
|
||||
first
|
||||
:vendor-terms-override/terms))
|
||||
|
||||
@@ -75,8 +75,9 @@
|
||||
:invoice/expense-accounts (map expense-account->entity
|
||||
expense_accounts)}
|
||||
(:vendor/terms vendor) (assoc :invoice/due (coerce/to-date
|
||||
(time/plus date (time/days (:vendor/terms vendor)))))
|
||||
due (assoc :invoice/due (doto (coerce/to-date due) println)))))
|
||||
(time/plus date (time/days (or (d-vendors/terms-for-client-id vendor client_id)
|
||||
(:vendor/terms vendor))))))
|
||||
due (assoc :invoice/due (coerce/to-date due)))))
|
||||
|
||||
|
||||
(defn deleted-expense-accounts [invoice expense-accounts]
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
|
||||
(defn template-applies? [text {:keys [keywords]}]
|
||||
(println text)
|
||||
(every? #(re-find % text) keywords))
|
||||
|
||||
(defn extract-template
|
||||
|
||||
@@ -142,9 +142,8 @@
|
||||
:invoice-status/unpaid)
|
||||
:invoice-number invoice-number
|
||||
:date (to-date date)
|
||||
:expense-accounts [#:invoice-expense-account {:account (doto (or account-id
|
||||
:expense-accounts [#:invoice-expense-account {:account (or account-id
|
||||
(-> vendor :vendor/default-account :db/id))
|
||||
println)
|
||||
:location default-location
|
||||
:amount total}]}
|
||||
payment (if (= :invoice-status/paid (:invoice/status invoice))
|
||||
@@ -168,19 +167,7 @@
|
||||
(let [clients (d-clients/get-all)
|
||||
transactions (reduce (fn [result {:keys [invoice-number customer-identifier total date vendor-code text full-text] :as info}]
|
||||
(println "searching for" vendor-code)
|
||||
(let [[matching-vendor default-account] (->> (d/query
|
||||
{:query {:find ['?vendor '?default-account]
|
||||
:in ['$ '?vendor-name]
|
||||
:where ['[?vendor :vendor/name ?vendor-name]
|
||||
'[?vendor :vendor/default-account ?default-account]]}
|
||||
:args [(d/db (d/connect uri)) vendor-code]})
|
||||
first)
|
||||
_ (when-not matching-vendor
|
||||
(throw (ex-info (str "No vendor with the name " vendor-code " was found.")
|
||||
{:invoice-number invoice-number
|
||||
:customer-identifier customer-identifier
|
||||
:vendor-code vendor-code})))
|
||||
_ (println "matching" customer-identifier "-" matching-vendor)
|
||||
(let [ _ (println "matching" customer-identifier)
|
||||
matching-client (or (and customer-identifier
|
||||
(parse/best-match clients customer-identifier))
|
||||
(if client
|
||||
@@ -192,7 +179,28 @@
|
||||
{:invoice-number invoice-number
|
||||
:customer-identifier customer-identifier
|
||||
:vendor-code vendor-code})))
|
||||
_ (println "invoice \"" invoice-number "\"matches client " (:client/name matching-client) " (" (:db/id matching-client) ")")
|
||||
|
||||
[matching-vendor default-account] (->> (d/query
|
||||
{:query {:find ['?vendor '?default-account]
|
||||
:in ['$ '?vendor-name]
|
||||
:where ['[?vendor :vendor/name ?vendor-name]
|
||||
'[?vendor :vendor/default-account ?default-account]]}
|
||||
: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
|
||||
:customer-identifier customer-identifier
|
||||
:vendor-code vendor-code})))
|
||||
_ (println "invoice \"" invoice-number "\"matches client " (:client/name matching-client) " (" (:db/id matching-client) ")")
|
||||
matching-location (or (when-not (str/blank? forced-location)
|
||||
forced-location)
|
||||
(parse/best-location-match matching-client text full-text))
|
||||
@@ -235,7 +243,7 @@
|
||||
: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 default-account
|
||||
: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
|
||||
@@ -289,11 +297,12 @@
|
||||
|
||||
(context "/invoices" []
|
||||
(POST "/upload"
|
||||
{{ files "file"
|
||||
client "client"
|
||||
location "location"} :params :as params}
|
||||
{{ files :file
|
||||
client :client
|
||||
location :location} :params :as params}
|
||||
(let [{:keys [filename tempfile]} files]
|
||||
(println params)
|
||||
(clojure.pprint/pprint params)
|
||||
#_(println params (.getPath tempfile) filename)
|
||||
(try
|
||||
(import-uploaded-invoice client location (parse/parse-file (.getPath tempfile) filename))
|
||||
{:status 200
|
||||
|
||||
Reference in New Issue
Block a user