check numbers increase with bank accounts.
This commit is contained in:
@@ -151,10 +151,11 @@
|
||||
:content-type "application/pdf"})
|
||||
(str "http://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/merged-checks/" uuid ".pdf")))
|
||||
|
||||
(defn check-for-invoices [invoices vendor-id vendors company bank-account-id]
|
||||
(defn check-for-invoices [invoices vendor-id vendors company bank-account-id index]
|
||||
(let [uuid (str (UUID/randomUUID))
|
||||
vendor (vendors vendor-id)
|
||||
bank-account (first (filter #(= (:id %) bank-account-id) (:bank-accounts company)))
|
||||
|
||||
memo (str "Invoice #'s: "
|
||||
(str/join ", "
|
||||
(map (fn [i]
|
||||
@@ -163,7 +164,7 @@
|
||||
{:s3-uuid uuid
|
||||
:s3-key (str "checks/" uuid ".pdf")
|
||||
:s3-url (str "http://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/checks/" uuid ".pdf")
|
||||
:check-number 1234
|
||||
:check-number (+ index (:check-number bank-account))
|
||||
:amount (reduce + 0 (map :total invoices))
|
||||
:memo memo
|
||||
:vendor-id (:id vendor)
|
||||
@@ -171,7 +172,7 @@
|
||||
:pdf-data {:vendor vendor
|
||||
:paid-to (:name vendor)
|
||||
:amount (reduce + 0 (map :total invoices))
|
||||
:check (str (inc (:check-number bank-account)))
|
||||
:check (str (+ index (:check-number bank-account)))
|
||||
:memo memo
|
||||
:date "5/10/2018"
|
||||
:company {:name (:name company)
|
||||
@@ -192,8 +193,8 @@
|
||||
(map (fn [v] [(:id v) v])
|
||||
(vendors/get-all)))
|
||||
invoices-grouped-by-vendor (group-by :vendor-id invoices)
|
||||
checks (-> (for [[vendor-id invoices] invoices-grouped-by-vendor]
|
||||
[invoices (checks/insert! (check-for-invoices invoices vendor-id vendors company bank-account-id))])
|
||||
checks (-> (for [[[vendor-id invoices] index] (map vector invoices-grouped-by-vendor (range))]
|
||||
[invoices (checks/insert! (check-for-invoices invoices vendor-id vendors company bank-account-id index))])
|
||||
doall)
|
||||
invoice-checks (invoices-checks/insert-multi!
|
||||
(mapcat
|
||||
@@ -204,9 +205,18 @@
|
||||
:check-id (:id check)
|
||||
:amount (:total i)})
|
||||
invoices))
|
||||
checks)) ]
|
||||
checks))
|
||||
updated-company (update company :bank-accounts
|
||||
(fn [bas]
|
||||
(map (fn [ba]
|
||||
(if (= bank-account-id (:id ba))
|
||||
(update ba :check-number + (count checks))
|
||||
ba))
|
||||
bas)))
|
||||
]
|
||||
|
||||
(make-pdfs (map second checks))
|
||||
(companies/upsert company-id updated-company)
|
||||
{:invoices (mapcat first checks)
|
||||
:pdf-url (merge-pdfs (map (comp :s3-key second) checks))}))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user