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
|
||||
|
||||
@@ -131,10 +131,18 @@
|
||||
|
||||
(re-frame/reg-sub
|
||||
::vendor-default-account
|
||||
(fn [db [_ v]]
|
||||
(let [i (if (:default-account v)
|
||||
(-> v :default-account :id)
|
||||
(-> (:vendors db) (get v) :default-account :id))]
|
||||
(fn [db [_ v client]]
|
||||
(let [vendor (if (:default-account v)
|
||||
v
|
||||
(-> (:vendors db) (get v)))
|
||||
client-override (->> (:account-overrides vendor)
|
||||
(filter #(= (:id (:client %)) (:id client))
|
||||
)
|
||||
first
|
||||
:account
|
||||
:id)
|
||||
default-id (:id (:default-account v))
|
||||
i (or client-override default-id)]
|
||||
(first (filter
|
||||
#(= (:id %) i)
|
||||
(:accounts db))))))
|
||||
|
||||
@@ -173,8 +173,6 @@
|
||||
[:td.has-text-right (nf total )]
|
||||
[:td.has-text-right (nf outstanding-balance )]
|
||||
[:td.expandable
|
||||
|
||||
|
||||
[:div.buttons
|
||||
(when (seq expense-accounts)
|
||||
[drop-down {:id [::expense-accounts id ]
|
||||
@@ -182,7 +180,6 @@
|
||||
:aria-haspopup true
|
||||
:on-click (dispatch-event [::events/toggle-menu [::expense-accounts id]])
|
||||
:tab-index "0"
|
||||
|
||||
} "Accounts"]}
|
||||
[drop-down-contents
|
||||
[:div
|
||||
|
||||
@@ -160,10 +160,9 @@
|
||||
(fn [data field value]
|
||||
(cond (and (= [:vendor] field)
|
||||
value
|
||||
(doto (expense-accounts-field/can-replace-with-default? (:accounts data))
|
||||
println))
|
||||
(expense-accounts-field/can-replace-with-default? (:accounts data)))
|
||||
[[:accounts] (expense-accounts-field/default-account (:accounts data)
|
||||
@(re-frame/subscribe [::subs/vendor-default-account value])
|
||||
@(re-frame/subscribe [::subs/vendor-default-account value (:client data)])
|
||||
(:total data)
|
||||
[])]
|
||||
|
||||
|
||||
@@ -91,7 +91,8 @@
|
||||
(re-frame/reg-event-db
|
||||
::errored
|
||||
(fn [db [_ error]]
|
||||
(assoc db ::error (:message (edn/read-string error)))))
|
||||
(assoc db ::error (or (:message (edn/read-string error))
|
||||
"An unknown error has occured."))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::reject-invoices-clicked
|
||||
|
||||
@@ -142,7 +142,7 @@
|
||||
value
|
||||
(expense-accounts-field/can-replace-with-default? (:expense-accounts data)))
|
||||
[[:expense-accounts] (expense-accounts-field/default-account (:expense-accounts data)
|
||||
@(re-frame/subscribe [::subs/vendor-default-account value])
|
||||
@(re-frame/subscribe [::subs/vendor-default-account value (:client data)])
|
||||
(:total data)
|
||||
locations)]
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
value
|
||||
(expense-accounts-field/can-replace-with-default? (:accounts data)))
|
||||
[[:accounts] (expense-accounts-field/default-account (:accounts data)
|
||||
@(re-frame/subscribe [::subs/vendor-default-account value])
|
||||
@(re-frame/subscribe [::subs/vendor-default-account value (:client data)])
|
||||
(:amount data)
|
||||
locations)]
|
||||
[])))))
|
||||
|
||||
Reference in New Issue
Block a user