Now overrides actually make an impact
This commit is contained in:
@@ -23,3 +23,13 @@
|
|||||||
id)
|
id)
|
||||||
(map first)
|
(map first)
|
||||||
(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
|
: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 (:vendor/terms vendor)))))
|
(time/plus date (time/days (or (d-vendors/terms-for-client-id vendor client_id)
|
||||||
due (assoc :invoice/due (doto (coerce/to-date due) println)))))
|
(:vendor/terms vendor))))))
|
||||||
|
due (assoc :invoice/due (coerce/to-date due)))))
|
||||||
|
|
||||||
|
|
||||||
(defn deleted-expense-accounts [invoice expense-accounts]
|
(defn deleted-expense-accounts [invoice expense-accounts]
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn template-applies? [text {:keys [keywords]}]
|
(defn template-applies? [text {:keys [keywords]}]
|
||||||
|
(println text)
|
||||||
(every? #(re-find % text) keywords))
|
(every? #(re-find % text) keywords))
|
||||||
|
|
||||||
(defn extract-template
|
(defn extract-template
|
||||||
|
|||||||
@@ -142,9 +142,8 @@
|
|||||||
:invoice-status/unpaid)
|
:invoice-status/unpaid)
|
||||||
:invoice-number invoice-number
|
:invoice-number invoice-number
|
||||||
:date (to-date date)
|
: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))
|
(-> vendor :vendor/default-account :db/id))
|
||||||
println)
|
|
||||||
:location default-location
|
:location default-location
|
||||||
:amount total}]}
|
:amount total}]}
|
||||||
payment (if (= :invoice-status/paid (:invoice/status invoice))
|
payment (if (= :invoice-status/paid (:invoice/status invoice))
|
||||||
@@ -168,19 +167,7 @@
|
|||||||
(let [clients (d-clients/get-all)
|
(let [clients (d-clients/get-all)
|
||||||
transactions (reduce (fn [result {:keys [invoice-number customer-identifier total date vendor-code text full-text] :as info}]
|
transactions (reduce (fn [result {:keys [invoice-number customer-identifier total date vendor-code text full-text] :as info}]
|
||||||
(println "searching for" vendor-code)
|
(println "searching for" vendor-code)
|
||||||
(let [[matching-vendor default-account] (->> (d/query
|
(let [ _ (println "matching" customer-identifier)
|
||||||
{: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)
|
|
||||||
matching-client (or (and customer-identifier
|
matching-client (or (and customer-identifier
|
||||||
(parse/best-match clients customer-identifier))
|
(parse/best-match clients customer-identifier))
|
||||||
(if client
|
(if client
|
||||||
@@ -192,7 +179,28 @@
|
|||||||
{:invoice-number invoice-number
|
{:invoice-number invoice-number
|
||||||
:customer-identifier customer-identifier
|
:customer-identifier customer-identifier
|
||||||
:vendor-code vendor-code})))
|
: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)
|
matching-location (or (when-not (str/blank? forced-location)
|
||||||
forced-location)
|
forced-location)
|
||||||
(parse/best-location-match matching-client text full-text))
|
(parse/best-location-match matching-client text full-text))
|
||||||
@@ -235,7 +243,7 @@
|
|||||||
: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 default-account
|
:invoice/expense-accounts (when-not existing-id [#:invoice-expense-account {:account (or account-override default-account)
|
||||||
:location matching-location
|
:location matching-location
|
||||||
:amount (Double/parseDouble total)}])
|
:amount (Double/parseDouble total)}])
|
||||||
:db/id existing-id
|
:db/id existing-id
|
||||||
@@ -289,11 +297,12 @@
|
|||||||
|
|
||||||
(context "/invoices" []
|
(context "/invoices" []
|
||||||
(POST "/upload"
|
(POST "/upload"
|
||||||
{{ files "file"
|
{{ files :file
|
||||||
client "client"
|
client :client
|
||||||
location "location"} :params :as params}
|
location :location} :params :as params}
|
||||||
(let [{:keys [filename tempfile]} files]
|
(let [{:keys [filename tempfile]} files]
|
||||||
(println params)
|
(clojure.pprint/pprint params)
|
||||||
|
#_(println params (.getPath tempfile) filename)
|
||||||
(try
|
(try
|
||||||
(import-uploaded-invoice client location (parse/parse-file (.getPath tempfile) filename))
|
(import-uploaded-invoice client location (parse/parse-file (.getPath tempfile) filename))
|
||||||
{:status 200
|
{:status 200
|
||||||
|
|||||||
@@ -131,10 +131,18 @@
|
|||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::vendor-default-account
|
::vendor-default-account
|
||||||
(fn [db [_ v]]
|
(fn [db [_ v client]]
|
||||||
(let [i (if (:default-account v)
|
(let [vendor (if (:default-account v)
|
||||||
(-> v :default-account :id)
|
v
|
||||||
(-> (:vendors db) (get v) :default-account :id))]
|
(-> (: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
|
(first (filter
|
||||||
#(= (:id %) i)
|
#(= (:id %) i)
|
||||||
(:accounts db))))))
|
(:accounts db))))))
|
||||||
|
|||||||
@@ -173,8 +173,6 @@
|
|||||||
[:td.has-text-right (nf total )]
|
[:td.has-text-right (nf total )]
|
||||||
[:td.has-text-right (nf outstanding-balance )]
|
[:td.has-text-right (nf outstanding-balance )]
|
||||||
[:td.expandable
|
[:td.expandable
|
||||||
|
|
||||||
|
|
||||||
[:div.buttons
|
[:div.buttons
|
||||||
(when (seq expense-accounts)
|
(when (seq expense-accounts)
|
||||||
[drop-down {:id [::expense-accounts id ]
|
[drop-down {:id [::expense-accounts id ]
|
||||||
@@ -182,7 +180,6 @@
|
|||||||
:aria-haspopup true
|
:aria-haspopup true
|
||||||
:on-click (dispatch-event [::events/toggle-menu [::expense-accounts id]])
|
:on-click (dispatch-event [::events/toggle-menu [::expense-accounts id]])
|
||||||
:tab-index "0"
|
:tab-index "0"
|
||||||
|
|
||||||
} "Accounts"]}
|
} "Accounts"]}
|
||||||
[drop-down-contents
|
[drop-down-contents
|
||||||
[:div
|
[:div
|
||||||
|
|||||||
@@ -160,10 +160,9 @@
|
|||||||
(fn [data field value]
|
(fn [data field value]
|
||||||
(cond (and (= [:vendor] field)
|
(cond (and (= [:vendor] field)
|
||||||
value
|
value
|
||||||
(doto (expense-accounts-field/can-replace-with-default? (:accounts data))
|
(expense-accounts-field/can-replace-with-default? (:accounts data)))
|
||||||
println))
|
|
||||||
[[:accounts] (expense-accounts-field/default-account (: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)
|
(:total data)
|
||||||
[])]
|
[])]
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,8 @@
|
|||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::errored
|
::errored
|
||||||
(fn [db [_ error]]
|
(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
|
(re-frame/reg-event-fx
|
||||||
::reject-invoices-clicked
|
::reject-invoices-clicked
|
||||||
|
|||||||
@@ -142,7 +142,7 @@
|
|||||||
value
|
value
|
||||||
(expense-accounts-field/can-replace-with-default? (:expense-accounts data)))
|
(expense-accounts-field/can-replace-with-default? (:expense-accounts data)))
|
||||||
[[:expense-accounts] (expense-accounts-field/default-account (: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)
|
(:total data)
|
||||||
locations)]
|
locations)]
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@
|
|||||||
value
|
value
|
||||||
(expense-accounts-field/can-replace-with-default? (:accounts data)))
|
(expense-accounts-field/can-replace-with-default? (:accounts data)))
|
||||||
[[:accounts] (expense-accounts-field/default-account (: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)
|
(:amount data)
|
||||||
locations)]
|
locations)]
|
||||||
[])))))
|
[])))))
|
||||||
|
|||||||
Reference in New Issue
Block a user