Uploading invoices now attaches the file.

This commit is contained in:
2022-01-12 20:53:12 -08:00
parent 4d6b3b1e2e
commit 30bbf51011
7 changed files with 260 additions and 198 deletions

View File

@@ -6,7 +6,11 @@
[clj-time.coerce :as c]
[clojure.set :refer [rename-keys]]
[clojure.string :as str]
[clojure.tools.logging :as log]))
[clojure.tools.logging :as log]
[clj-time.coerce :as coerce]
[auto-ap.time-utils :refer [next-dom]]
[clj-time.core :as time]
[auto-ap.datomic.vendors :as d-vendors]))
(def default-read '[*
{:invoice/client [:client/name :db/id :client/locations :client/code]}
@@ -246,3 +250,45 @@
(into vendored-results vendorless-results)))
(defn code-invoice [invoice]
(let [db (d/db auto-ap.datomic/conn)
client-id (:invoice/client invoice)
vendor-id (:invoice/vendor invoice)
date (:invoice/date invoice)
vendor (d/pull db '[*] vendor-id)
due (when (:vendor/terms vendor)
(-> date
(coerce/to-date-time)
(time/plus (time/days (d-vendors/terms-for-client-id vendor client-id)))
coerce/to-date))
automatically-paid? (boolean (seq (d/q '[:find [?c ...]
:in $ ?v
:where [?v :vendor/automatically-paid-when-due ?c]]
db
vendor-id
client-id)))
[schedule-payment-dom] (d/q '[:find [?dom ...]
:in $ ?v ?c
:where [?v :vendor/schedule-payment-dom ?sp ]
[?sp :vendor-schedule-payment-dom/client ?c]
[?sp :vendor-schedule-payment-dom/dom ?dom]]
db
vendor-id
client-id)
scheduled-payment (cond automatically-paid?
due
schedule-payment-dom
(-> date
(next-dom schedule-payment-dom)
coerce/to-date)
:else nil)
default-expense-account #:invoice-expense-account {:account (d-vendors/account-for-client-id vendor client-id)
:location (:invoice/location invoice)
:amount (:invoice/total invoice)}]
(cond-> invoice
true (assoc :invoice/expense-accounts [default-expense-account])
due (assoc :invoice/due due)
scheduled-payment (assoc :invoice/scheduled-payment scheduled-payment))))