51 lines
2.8 KiB
Clojure
51 lines
2.8 KiB
Clojure
(ns auto-ap.routes.checks
|
|
(:require [auto-ap.db.companies :as companies]
|
|
[auto-ap.db.vendors :as vendors]
|
|
[auto-ap.db.invoices :as invoices]
|
|
[auto-ap.db.utils :refer [query]]
|
|
[auto-ap.parse :as parse]
|
|
[auto-ap.routes.utils :refer [wrap-secure]]
|
|
[compojure.core :refer [GET POST context defroutes
|
|
wrap-routes]]
|
|
[clojure.string :as str]))
|
|
|
|
(defroutes routes
|
|
(wrap-routes
|
|
(context "/checks" []
|
|
(POST "/" {:keys [edn-params]}
|
|
(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))
|