checks are now stored
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.db.invoices :as invoices]
|
||||
[auto-ap.db.checks :as checks]
|
||||
[auto-ap.db.invoices-checks :as invoices-checks]
|
||||
[auto-ap.db.utils :refer [query]]
|
||||
[auto-ap.parse :as parse]
|
||||
[amazonica.aws.s3 :as s3]
|
||||
@@ -24,7 +25,8 @@
|
||||
[{:left-margin 10 :right-margin 0 :top-margin 0 :bottom-margin 0}
|
||||
(let [{:keys [paid-to company check date amount memo] {vendor-name :name :as vendor} :vendor} check
|
||||
df (DecimalFormat. "#,###.00")
|
||||
amount (str "--" (.format df amount) "--")]
|
||||
_ (println amount (class amount))
|
||||
amount (str "--" (.format df amount) "--")]
|
||||
|
||||
[:table {:num-cols 12 :border false :leading 11}
|
||||
[(let [{:keys [name address1 city state zip bank]} company]
|
||||
@@ -149,6 +151,39 @@
|
||||
: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 companies]
|
||||
(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")
|
||||
:check-number 1234
|
||||
:amount (reduce + 0 (map :total invoices))
|
||||
:memo memo
|
||||
:vendor-id (:id vendor)
|
||||
:company-id (:id company)
|
||||
: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)}))
|
||||
|
||||
|
||||
(defroutes routes
|
||||
(wrap-routes
|
||||
@@ -162,48 +197,24 @@
|
||||
(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
|
||||
: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) ]
|
||||
checks (-> (for [[vendor-id invoices] invoices-grouped-by-vendor]
|
||||
[invoices (checks/insert! (check-for-invoices invoices vendor-id vendors companies))])
|
||||
doall)
|
||||
invoice-checks (invoices-checks/insert-multi!
|
||||
(mapcat
|
||||
(fn [[invoices check]]
|
||||
(map
|
||||
(fn [i]
|
||||
{:invoice-id (:id i)
|
||||
:check-id (:id check)
|
||||
:amount (:total i)})
|
||||
invoices))
|
||||
checks)) ]
|
||||
|
||||
(make-pdfs checks)
|
||||
(make-pdfs (map second checks))
|
||||
|
||||
{:status 200
|
||||
:body (pr-str {:url (merge-pdfs (map :s3-key checks))
|
||||
:body (pr-str {:url (merge-pdfs (map (comp :s3-key second) checks))
|
||||
:checks checks
|
||||
:invoice-checks invoice-checks})
|
||||
:headers {"Content-Type" "application/edn"}})))
|
||||
|
||||
Reference in New Issue
Block a user