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