Fixes issue with JFC import, fixes issue where overriden account ids did not take effect.
This commit is contained in:
@@ -293,52 +293,55 @@
|
|||||||
vec)
|
vec)
|
||||||
[]))
|
[]))
|
||||||
|
|
||||||
(defn code-invoice [invoice]
|
(defn code-invoice
|
||||||
(mu/log ::trying-to-code-invoice
|
([invoice]
|
||||||
:invoice invoice)
|
(code-invoice invoice nil))
|
||||||
(let [db (dc/db auto-ap.datomic/conn)
|
([invoice override-account-id]
|
||||||
client-id (or (:db/id (:invoice/client invoice))
|
(mu/log ::trying-to-code-invoice
|
||||||
(:invoice/client invoice))
|
:invoice invoice)
|
||||||
vendor-id (or (:db/id (:invoice/vendor invoice))
|
(let [db (dc/db auto-ap.datomic/conn)
|
||||||
(:invoice/vendor invoice))
|
client-id (or (:db/id (:invoice/client invoice))
|
||||||
date (:invoice/date invoice)
|
(:invoice/client invoice))
|
||||||
vendor (dc/pull db '[*] vendor-id)
|
vendor-id (or (:db/id (:invoice/vendor invoice))
|
||||||
due (when (:vendor/terms vendor)
|
(:invoice/vendor invoice))
|
||||||
(-> date
|
date (:invoice/date invoice)
|
||||||
(coerce/to-date-time)
|
vendor (dc/pull db '[*] vendor-id)
|
||||||
(time/plus (time/days (d-vendors/terms-for-client-id vendor client-id)))
|
due (when (:vendor/terms vendor)
|
||||||
coerce/to-date))
|
(-> date
|
||||||
automatically-paid? (boolean (seq (map first (dc/q '[:find ?c
|
(coerce/to-date-time)
|
||||||
:in $ ?v ?c
|
(time/plus (time/days (d-vendors/terms-for-client-id vendor client-id)))
|
||||||
:where [?v :vendor/automatically-paid-when-due ?c]]
|
coerce/to-date))
|
||||||
db
|
automatically-paid? (boolean (seq (map first (dc/q '[:find ?c
|
||||||
vendor-id
|
:in $ ?v ?c
|
||||||
client-id))))
|
:where [?v :vendor/automatically-paid-when-due ?c]]
|
||||||
[schedule-payment-dom] (map first (dc/q '[:find ?dom
|
db
|
||||||
:in $ ?v ?c
|
vendor-id
|
||||||
:where [?v :vendor/schedule-payment-dom ?sp ]
|
client-id))))
|
||||||
[?sp :vendor-schedule-payment-dom/client ?c]
|
[schedule-payment-dom] (map first (dc/q '[:find ?dom
|
||||||
[?sp :vendor-schedule-payment-dom/dom ?dom]]
|
:in $ ?v ?c
|
||||||
db
|
:where [?v :vendor/schedule-payment-dom ?sp ]
|
||||||
vendor-id
|
[?sp :vendor-schedule-payment-dom/client ?c]
|
||||||
client-id))
|
[?sp :vendor-schedule-payment-dom/dom ?dom]]
|
||||||
|
db
|
||||||
|
vendor-id
|
||||||
|
client-id))
|
||||||
|
|
||||||
scheduled-payment (cond automatically-paid?
|
scheduled-payment (cond automatically-paid?
|
||||||
due
|
due
|
||||||
|
|
||||||
schedule-payment-dom
|
schedule-payment-dom
|
||||||
(-> date
|
(-> date
|
||||||
coerce/to-date-time
|
coerce/to-date-time
|
||||||
(next-dom schedule-payment-dom)
|
(next-dom schedule-payment-dom)
|
||||||
coerce/to-date)
|
coerce/to-date)
|
||||||
:else nil)
|
:else nil)
|
||||||
default-expense-account #:invoice-expense-account {:db/id (random-tempid)
|
default-expense-account #:invoice-expense-account {:db/id (random-tempid)
|
||||||
:account (d-vendors/account-for-client-id vendor client-id)
|
:account (or override-account-id (d-vendors/account-for-client-id vendor client-id))
|
||||||
:location (:invoice/location invoice)
|
:location (:invoice/location invoice)
|
||||||
:amount (:invoice/total invoice)}]
|
:amount (:invoice/total invoice)}]
|
||||||
(cond-> invoice
|
(cond-> invoice
|
||||||
true (assoc :invoice/expense-accounts [default-expense-account])
|
true (assoc :invoice/expense-accounts [default-expense-account])
|
||||||
due (assoc :invoice/due due)
|
due (assoc :invoice/due due)
|
||||||
scheduled-payment (assoc :invoice/scheduled-payment scheduled-payment))))
|
scheduled-payment (assoc :invoice/scheduled-payment scheduled-payment)))))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -555,8 +555,8 @@
|
|||||||
{:vendor "JFC International"
|
{:vendor "JFC International"
|
||||||
:keywords [#"48490 MILMONT DRIVE"]
|
:keywords [#"48490 MILMONT DRIVE"]
|
||||||
:extract {:date #"([0-9]+/[0-9]+/[0-9]+)"
|
:extract {:date #"([0-9]+/[0-9]+/[0-9]+)"
|
||||||
:customer-identifier #"SOLD\s+([\S ]+?)(?=(\s{2,}|\n))"
|
:customer-identifier #"SOLD\s+(?:TO\s+)?([\S ]+?)(?=(\s{2,}|\n))"
|
||||||
:invoice-number #"(\S+)\s+(?=[0-9]+/[0-9]+/[0-9]+)"
|
:invoice-number #"(\S+)\s+(?:[0-9]+/[0-9]+/[0-9]+)"
|
||||||
:total #"(?:INVOICE|TOTAL|CREDIT)\s+([\d\.,\-]+\.[\d\-]+( CR)?)"}
|
:total #"(?:INVOICE|TOTAL|CREDIT)\s+([\d\.,\-]+\.[\d\-]+( CR)?)"}
|
||||||
:parser {:date [:clj-time "MM/dd/yyyy"]
|
:parser {:date [:clj-time "MM/dd/yyyy"]
|
||||||
:total [:trim-commas-and-negate nil]}}
|
:total [:trim-commas-and-negate nil]}}
|
||||||
|
|||||||
@@ -22,7 +22,8 @@
|
|||||||
[digest]
|
[digest]
|
||||||
[iol-ion.tx :refer [random-tempid]]
|
[iol-ion.tx :refer [random-tempid]]
|
||||||
[ring.middleware.json :refer [wrap-json-response]]
|
[ring.middleware.json :refer [wrap-json-response]]
|
||||||
[unilog.context :as lc])
|
[unilog.context :as lc]
|
||||||
|
[auto-ap.logging :as alog])
|
||||||
(:import
|
(:import
|
||||||
(java.util UUID)))
|
(java.util UUID)))
|
||||||
|
|
||||||
@@ -105,6 +106,8 @@
|
|||||||
(map (c/parse-or-error :invoice-number parse-invoice-number))
|
(map (c/parse-or-error :invoice-number parse-invoice-number))
|
||||||
(map (c/parse-or-error :total c/parse-amount))
|
(map (c/parse-or-error :total c/parse-amount))
|
||||||
(map (c/parse-or-error :date c/parse-date)))]
|
(map (c/parse-or-error :date c/parse-date)))]
|
||||||
|
(alog/info ::parsed
|
||||||
|
:rows (take 10 rows))
|
||||||
|
|
||||||
rows))
|
rows))
|
||||||
|
|
||||||
@@ -179,7 +182,7 @@
|
|||||||
|
|
||||||
(defn invoice-rows->transaction [rows user]
|
(defn invoice-rows->transaction [rows user]
|
||||||
(->> rows
|
(->> rows
|
||||||
(mapcat (fn [{:keys [vendor-id total client-id date invoice-number default-location check automatically-paid-when-due]}]
|
(mapcat (fn [{:keys [vendor-id total client-id date invoice-number default-location check automatically-paid-when-due account-id]}]
|
||||||
(let [payment-id (.toString (java.util.UUID/randomUUID))
|
(let [payment-id (.toString (java.util.UUID/randomUUID))
|
||||||
transaction-id (.toString (java.util.UUID/randomUUID))
|
transaction-id (.toString (java.util.UUID/randomUUID))
|
||||||
invoice #:invoice {:db/id (.toString (java.util.UUID/randomUUID))
|
invoice #:invoice {:db/id (.toString (java.util.UUID/randomUUID))
|
||||||
@@ -234,7 +237,8 @@
|
|||||||
:transaction-account/amount (Math/abs (:invoice/total invoice))}]}]))
|
:transaction-account/amount (Math/abs (:invoice/total invoice))}]}]))
|
||||||
]
|
]
|
||||||
[[:propose-invoice (d-invoices/code-invoice (validate-invoice (remove-nils invoice)
|
[[:propose-invoice (d-invoices/code-invoice (validate-invoice (remove-nils invoice)
|
||||||
user))]
|
user)
|
||||||
|
account-id)]
|
||||||
(some-> payment remove-nils)
|
(some-> payment remove-nils)
|
||||||
transaction])))
|
transaction])))
|
||||||
(filter identity)))
|
(filter identity)))
|
||||||
|
|||||||
Reference in New Issue
Block a user