stores checks
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
(:require [auto-ap.db.companies :as companies]
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.db.invoices :as invoices]
|
||||
[auto-ap.db.checks :as checks]
|
||||
[auto-ap.db.utils :refer [query]]
|
||||
[auto-ap.parse :as parse]
|
||||
[amazonica.aws.s3 :as s3]
|
||||
@@ -161,38 +162,49 @@
|
||||
(map (fn [v] [(:id v) v])
|
||||
(vendors/get-all)))
|
||||
invoices-grouped-by-vendor (group-by :vendor-id invoices)
|
||||
uuid (str (UUID/randomUUID))
|
||||
checks (for [[vendor-id invoices] invoices-grouped-by-vendor
|
||||
:let [uuid (str (UUID/randomUUID))
|
||||
vendor (vendors vendor-id)
|
||||
company (companies (:company-id (first invoices)))
|
||||
memo (str "Invoice #'s: "
|
||||
(str/join ", "
|
||||
(map (fn [i]
|
||||
(str (:invoice-number i) "(" (:total i) ")"))
|
||||
invoices)))]]
|
||||
{: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")
|
||||
:pdf-data {:vendor vendor
|
||||
:paid-to (:name vendor)
|
||||
:amount (reduce + 0 (map :total invoices))
|
||||
:check "1234"
|
||||
:memo memo
|
||||
:date "5/10/2018"
|
||||
:company {:name (:name company)
|
||||
:address1 "123 main st"
|
||||
:city "Campbell"
|
||||
:state "CA"
|
||||
:zip "95008"
|
||||
:bank {:name "Bank of America, NA"
|
||||
:acct "11-35/2010"
|
||||
:acct-number "123456789"}}}})]
|
||||
checks (-> (for [[vendor-id invoices] invoices-grouped-by-vendor
|
||||
:let [uuid (str (UUID/randomUUID))
|
||||
vendor (vendors vendor-id)
|
||||
company (companies (:company-id (first invoices)))
|
||||
memo (str "Invoice #'s: "
|
||||
(str/join ", "
|
||||
(map (fn [i]
|
||||
(str (:invoice-number i) "(" (:total i) ")"))
|
||||
invoices)))]]
|
||||
{: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")
|
||||
:pdf-data {:vendor vendor
|
||||
:paid-to (:name vendor)
|
||||
:amount (reduce + 0 (map :total invoices))
|
||||
:check "1234"
|
||||
:memo memo
|
||||
:date "5/10/2018"
|
||||
:company {:name (:name company)
|
||||
:address1 "123 main st"
|
||||
:city "Campbell"
|
||||
:state "CA"
|
||||
:zip "95008"
|
||||
:bank {:name "Bank of America, NA"
|
||||
:acct "11-35/2010"
|
||||
:acct-number "123456789"}}}
|
||||
:invoices (map :id invoices)})
|
||||
(checks/insert-multi!))
|
||||
invoice-checks (mapcat
|
||||
(fn [c]
|
||||
(map
|
||||
(fn [i]
|
||||
{:invoice-id i
|
||||
:check-id (:id c)
|
||||
:amount (:total i)})
|
||||
(:invoices c)))
|
||||
checks) ]
|
||||
|
||||
(make-pdfs checks)
|
||||
|
||||
{:status 200
|
||||
:body (pr-str {:url (merge-pdfs (map :s3-key checks))
|
||||
:checks checks})
|
||||
:checks checks
|
||||
:invoice-checks invoice-checks})
|
||||
:headers {"Content-Type" "application/edn"}})))
|
||||
wrap-secure))
|
||||
|
||||
Reference in New Issue
Block a user