you can check off individual invoices

This commit is contained in:
Bryce Covert
2018-05-10 21:30:50 -07:00
parent 5fb5b2d412
commit 7d5ae173f3
3 changed files with 176 additions and 161 deletions

View File

@@ -13,9 +13,38 @@
(wrap-routes
(context "/checks" []
(POST "/" {:keys [edn-params]}
(invoices/get-multi (:invoice-ids edn-params))
{:status 200
:body (pr-str (invoices/get-multi (:invoice-ids edn-params)))
:headers {"Content-Type" "application/edn"}}))
(let [invoices (invoices/get-multi (:invoice-ids edn-params))
companies (into {}
(map (fn [c] [(:id c) c])
(companies/get-all)))
vendors (into {}
(map (fn [v] [(:id v) v])
(vendors/get-all)))
invoices-grouped-by-vendor (group-by :vendor-id invoices)]
{:status 200
:body (pr-str (for [[vendor-id invoices] invoices-grouped-by-vendor
:let [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)
))]]
{:vendor-name (:name vendor)
:paid-to (:name company)
: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"}}}))
:headers {"Content-Type" "application/edn"}})))
wrap-secure))