now checks get created and uploaded!
This commit is contained in:
@@ -4,168 +4,119 @@
|
||||
[auto-ap.db.invoices :as invoices]
|
||||
[auto-ap.db.utils :refer [query]]
|
||||
[auto-ap.parse :as parse]
|
||||
[amazonica.aws.s3 :as s3]
|
||||
[hiccup.core :refer [html]]
|
||||
[auto-ap.routes.utils :refer [wrap-secure]]
|
||||
[config.core :refer [env]]
|
||||
[compojure.core :refer [GET POST context defroutes
|
||||
wrap-routes]]
|
||||
[clojure.string :as str]))
|
||||
[clojure.string :as str]
|
||||
[clj-pdf.core :as pdf])
|
||||
(:import [java.text DecimalFormat]
|
||||
[java.util UUID]))
|
||||
|
||||
(defn check-page [checks]
|
||||
(html
|
||||
[:html
|
||||
[:head
|
||||
[:link {:rel "stylesheet"
|
||||
:href "resources/public/css/bulma.min.css"}]
|
||||
[:link {:rel "stylesheet"
|
||||
:href "resources/public/css/check.css"}]]
|
||||
[:body
|
||||
|
||||
[:div
|
||||
(for [{:keys [vendor-name paid-to company check date amount memo]} checks
|
||||
|
||||
|
||||
:let [amount (str "--%.2f--" amount)]]
|
||||
[:div
|
||||
[:div.columns
|
||||
(let [{:keys [name address1 city state zip bank]} company]
|
||||
(list
|
||||
[:div.column.is-4
|
||||
[:p name]
|
||||
[:p address1]
|
||||
[:p city ", " state zip]]
|
||||
[:div.column.is-7
|
||||
(defn check-page [checks uuid]
|
||||
(pdf/pdf
|
||||
[{:left-margin 10 :right-margin 0 :top-margin 0 :bottom-margin 0}
|
||||
(for [{:keys [paid-to company check date amount memo] {vendor-name :name :as vendor} :vendor} checks
|
||||
:let [df (DecimalFormat. "#,###.00")
|
||||
amount (str "--" (.format df amount) "--")]]
|
||||
[:table {:num-cols 12 :border false :leading 11}
|
||||
[(let [{:keys [name address1 city state zip bank]} company]
|
||||
[:cell {:colspan 4 } [:paragraph {:leading 14} name "\n" address1 "\n" (str city ", " state zip)] ])
|
||||
(let [{{:keys [name acct]} :bank} company]
|
||||
[:cell {:colspan 6 :align :center} [:paragraph {:style :bold} name] [:paragraph acct]])
|
||||
[:cell {:colspan 2 :size 13}
|
||||
check]]
|
||||
|
||||
[:p.has-text-centered (:name bank)]
|
||||
[:p.has-text-centered (:acct bank)]
|
||||
]))
|
||||
[[:cell {:colspan 9}]
|
||||
[:cell {:colspan 3} date]]
|
||||
|
||||
[:div.column
|
||||
check]
|
||||
]
|
||||
[:div.columns
|
||||
[:div.column.is-11]
|
||||
[:div.column date]
|
||||
]
|
||||
[:div.columns
|
||||
[:div.column
|
||||
"PAY"
|
||||
]
|
||||
[:div.column
|
||||
"TO THE ORDER OF"]
|
||||
[:div.column.is-9
|
||||
vendor-name]
|
||||
[:div.column
|
||||
|
||||
amount]]
|
||||
[[:cell {:size 16 :leading 16} "PAY"]
|
||||
[:cell {:size 6 :leading 6 } "TO THE ORDER OF"]
|
||||
[:cell {:colspan 7} vendor-name]
|
||||
[:cell {:colspan 3} amount]]
|
||||
|
||||
[:div.columns
|
||||
[:div.column]
|
||||
[:div.column.is-8 {:style {"border-bottom" "1px solid black"}} "One thousand two hundred thirty four and fifty six cents"]
|
||||
[:div.column.is-3]]
|
||||
[[:cell {}]
|
||||
[:cell {:colspan 8} "One thousand two hundred thirty four and fifty six cents" [:line]]
|
||||
[:cell {:colspan 3}]]
|
||||
|
||||
[:div.columns
|
||||
[:div.column ""]]
|
||||
[:div.columns
|
||||
[:div.column " "]]
|
||||
|
||||
[[:cell {:colspan 12} [:spacer]]]
|
||||
[[:cell {:colspan 12} [:spacer]]]
|
||||
[[:cell {:colspan 12} [:spacer]]]
|
||||
|
||||
[:div.columns
|
||||
[:div.column
|
||||
"MEMO"]
|
||||
[:div.column.is-7 {:style {"border-bottom" "1px solid black"}}
|
||||
memo]
|
||||
[:div.column.is-4]]
|
||||
[[:cell "MEMO"]
|
||||
[:cell {:colspan 7} memo [:line]]
|
||||
[:cell {:colspan 4}]]
|
||||
|
||||
[:div.columns
|
||||
[:div.column.is-2 ]
|
||||
[:div.column.is-10 {:style {"font-family" "MICR" "font-size" "20pt"}}
|
||||
(str "c" check "c a" (:acct-number (:bank company)) "a 10302c")]]
|
||||
[[:cell {:colspan 2}]
|
||||
[:cell {:colspan 10 :leading 30}
|
||||
[:phrase {:size 18 :ttf-name "public/micrenc.ttf"} (str "c" check "c a" (:acct-number (:bank company)) "a 10302c")]]]
|
||||
|
||||
[[:cell {:colspan 12} [:spacer]]]
|
||||
[[:cell {:colspan 12} [:spacer]]]
|
||||
[[:cell {:colspan 12} [:spacer]]]
|
||||
[[:cell]
|
||||
(into
|
||||
[:cell {:colspan 9}]
|
||||
(let [{:keys [name address1 city state zip bank]} company]
|
||||
(list
|
||||
[:paragraph name]
|
||||
[:paragraph address1]
|
||||
[:paragraph city ", " state zip]
|
||||
)))
|
||||
[:cell {:colspan 2 :size 13}
|
||||
check]]
|
||||
|
||||
[[:cell {:colspan 12} [:spacer]]]
|
||||
[[:cell {:colspan 12} [:spacer]]]
|
||||
[[:cell {:colspan 12} [:spacer]]]
|
||||
|
||||
[:div.columns
|
||||
[:div.column " "]]
|
||||
[[:cell]
|
||||
[:cell {:colspan 5} [:paragraph
|
||||
vendor-name "\n"
|
||||
(:address1 vendor) "\n"
|
||||
(:city vendor) ", " (:state vendor) " " (:zip vendor)]]
|
||||
[:cell {:align :right}
|
||||
"Paid to:\n"
|
||||
"Amount:\n"
|
||||
"Date:\n"]
|
||||
|
||||
[:div.columns
|
||||
[:div.column " "]]
|
||||
[:cell {:colspan 5}
|
||||
[:paragraph paid-to]
|
||||
[:paragraph amount]
|
||||
[:paragraph date]]]
|
||||
|
||||
[:div.columns
|
||||
[:div.column " "]]
|
||||
[[:cell {:colspan 3} "Memo:"]
|
||||
[:cell {:colspan 9} memo]]
|
||||
|
||||
[:div.columns
|
||||
[:div.column " "]]
|
||||
[[:cell {:colspan 12} [:spacer]]]
|
||||
[[:cell {:colspan 12} [:spacer]]]
|
||||
[[:cell {:colspan 12} [:spacer]]]
|
||||
[[:cell {:colspan 12} [:spacer]]]
|
||||
[[:cell {:colspan 12} [:spacer]]]
|
||||
[[:cell {:colspan 12} [:spacer]]]
|
||||
|
||||
[:div.columns
|
||||
[:div.column]
|
||||
[:div.column.is-10
|
||||
(let [{:keys [name address1 city state zip bank]} company]
|
||||
(list
|
||||
[:p name]
|
||||
[:p address1]
|
||||
[:p city ", " state zip]
|
||||
))
|
||||
|
||||
|
||||
|
||||
]
|
||||
[:div.column
|
||||
check]]
|
||||
[[:cell {:colspan 5}]
|
||||
[:cell {:align :right :colspan 2}
|
||||
"Check:\n"
|
||||
"Vendor:\n"
|
||||
"Bank Account:\n"
|
||||
"Paid To:\n"
|
||||
"Amount:\n"
|
||||
"Date:\n"]
|
||||
|
||||
[:div.columns
|
||||
[:div.column " "]]
|
||||
[:div.columns
|
||||
[:div.column " "]]
|
||||
[:div.columns
|
||||
[:div.column " "]]
|
||||
[:div.columns
|
||||
[:div.column " "]]
|
||||
[:div.columns
|
||||
[:div.column " "]]
|
||||
|
||||
[:div.columns
|
||||
[:div.column]
|
||||
[:div.column.is-5
|
||||
vendor-name]
|
||||
[:div.column
|
||||
[:p.has-text-right "Paid to:"]
|
||||
[:p.has-text-right "Amount:"]
|
||||
[:p.has-text-right "Date:"]]
|
||||
|
||||
[:div.column.is-5
|
||||
[:p paid-to]
|
||||
[:p amount]
|
||||
[:p date]]]
|
||||
|
||||
[:div.columns
|
||||
[:div.column "MEMO"]
|
||||
[:div.column.is-11
|
||||
memo
|
||||
]]
|
||||
|
||||
[:div.columns
|
||||
[:div.column " "]]
|
||||
|
||||
[:div.columns
|
||||
[:div.column.is-6]
|
||||
[:div.column
|
||||
[:p.has-text-right "Check:"]
|
||||
[:p.has-text-right "Vendor:"]
|
||||
[:p.has-text-right "Bank Account:"]
|
||||
[:p.has-text-right "Paid To:"]
|
||||
[:p.has-text-right "Amount:"]
|
||||
[:p.has-text-right "Date:"]]
|
||||
|
||||
[:div.column.is-5
|
||||
[:p check]
|
||||
[:p vendor-name]
|
||||
[:p (:name (:bank company))]
|
||||
[:p paid-to]
|
||||
[:p amount]
|
||||
[:p date]]]
|
||||
[:div.columns
|
||||
[:div.column "MEMO"]
|
||||
[:div.column.is-11
|
||||
memo]]
|
||||
[:footer]])]]]))
|
||||
[:cell {:colspan 5}
|
||||
[:paragraph check]
|
||||
[:paragraph vendor-name]
|
||||
[:paragraph (:name (:bank company))]
|
||||
[:paragraph paid-to]
|
||||
[:paragraph amount]
|
||||
[:paragraph date]]]
|
||||
[[:cell {:colspan 3} "Memo:"]
|
||||
[:cell {:colspan 9} memo]]
|
||||
])]
|
||||
(doto (str "/tmp/" uuid ".pdf") println)))
|
||||
|
||||
(defroutes routes
|
||||
(wrap-routes
|
||||
@@ -178,7 +129,10 @@
|
||||
vendors (into {}
|
||||
(map (fn [v] [(:id v) v])
|
||||
(vendors/get-all)))
|
||||
invoices-grouped-by-vendor (group-by :vendor-id invoices)]
|
||||
invoices-grouped-by-vendor (group-by :vendor-id invoices)
|
||||
uuid (str (UUID/randomUUID))]
|
||||
|
||||
|
||||
(check-page (for [[vendor-id invoices] invoices-grouped-by-vendor
|
||||
:let [vendor (vendors vendor-id)
|
||||
company (companies (:company-id (first invoices)))
|
||||
@@ -188,8 +142,8 @@
|
||||
(str (:invoice-number i) "(" (:total i) ")"))
|
||||
invoices)
|
||||
))]]
|
||||
{:vendor-name (:name vendor)
|
||||
:paid-to (:name company)
|
||||
{:vendor vendor
|
||||
:paid-to (:name vendor)
|
||||
:amount (reduce + 0 (map :total invoices))
|
||||
:check "1234"
|
||||
:memo memo
|
||||
@@ -201,10 +155,14 @@
|
||||
:zip "95008"
|
||||
:bank {:name "Bank of America, NA"
|
||||
:acct "11-35/2010"
|
||||
:acct-number "123456789"}}}))
|
||||
:acct-number "123456789"}}})
|
||||
uuid)
|
||||
|
||||
(s3/put-object :bucket-name (:data-bucket env)
|
||||
:key (str "checks/" uuid ".pdf")
|
||||
:file (str "/tmp/" uuid ".pdf"))
|
||||
|
||||
{:status 200
|
||||
:body "{}"
|
||||
#_(pr-str )
|
||||
:body (pr-str {:url (str "http://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/checks/" uuid ".pdf")})
|
||||
:headers {"Content-Type" "application/edn"}})))
|
||||
wrap-secure))
|
||||
|
||||
@@ -17,6 +17,11 @@
|
||||
(fn [uri]
|
||||
(pushy/set-token! p/history uri)))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:new-window
|
||||
(fn [url]
|
||||
(.open js/window url)))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:set-local-storage
|
||||
(fn [[name value]]
|
||||
|
||||
@@ -61,9 +61,8 @@
|
||||
(re-frame/reg-event-fx
|
||||
::checks-created
|
||||
(fn [{:keys [db]} [_ data]]
|
||||
{:dispatch [:auto-ap.events/set-active-page :check]
|
||||
:db (-> db
|
||||
(assoc ::check/checks data))}))
|
||||
{:new-window (:url data)
|
||||
}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invalidated
|
||||
|
||||
Reference in New Issue
Block a user