looking good.
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
(map db->clj (j/query conn "SELECT * FROM invoices")))
|
||||
|
||||
|
||||
(defn get-unpaid []
|
||||
(map db->clj (j/query conn "SELECT * FROM invoices WHERE imported=true")))
|
||||
|
||||
(defn get-pending []
|
||||
(println conn)
|
||||
(map db->clj (j/query conn "SELECT * FROM invoices WHERE imported=0")))
|
||||
(map db->clj (j/query conn "SELECT * FROM invoices WHERE imported=false or imported is null")))
|
||||
|
||||
@@ -21,14 +21,19 @@
|
||||
[(keyword (kebab->snake (name k))) v])
|
||||
x)))
|
||||
|
||||
(def conn {:classname "org.postgresql.Driver" ; must be in classpath
|
||||
:dbtype "postgresql"
|
||||
:ssl true
|
||||
:sslfactory "org.postgresql.ssl.NonValidatingFactory"
|
||||
:host "ec2-54-235-123-153.compute-1.amazonaws.com"
|
||||
:port 5342
|
||||
:dbname "dbfemhppkdksfp"
|
||||
; Any additional keys are passed to the driver
|
||||
(let [db-host "ec2-54-235-123-153.compute-1.amazonaws.com"
|
||||
db-port 5432
|
||||
db-name "dbfemhppkdksfp"]
|
||||
|
||||
(def conn {:classname "org.postgresql.Driver" ; must be in classpath
|
||||
:ssl true
|
||||
:sslfactory "org.postgresql.ssl.NonValidatingFactory"
|
||||
:subprotocol "postgresql"
|
||||
:subname (str "//" db-host ":" db-port "/" db-name)
|
||||
; Any additional
|
||||
; keys are passed
|
||||
; to the driver
|
||||
; as driver-specific properties.
|
||||
:user "tkilrhrhzlumol"
|
||||
:password "de6117f8551364ac84ed31c1231941f53ab0b5470c9956f478b2025ab5a0fb8b"})
|
||||
:user "tkilrhrhzlumol"
|
||||
:password "de6117f8551364ac84ed31c1231941f53ab0b5470c9956f478b2025ab5a0fb8b"}))
|
||||
|
||||
|
||||
@@ -20,6 +20,11 @@
|
||||
:body (pr-str (invoices/get-all))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(GET "/api/invoices/unpaid" []
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-unpaid))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(GET "/api/invoices/pending" []
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-pending))
|
||||
@@ -33,12 +38,13 @@
|
||||
(POST "/pdf-upload"
|
||||
{{ files "file"} :params :as params}
|
||||
(let [{:keys [filename tempfile]} files]
|
||||
(for [{:keys [total date invoice-number customer-identifier]}
|
||||
(parse/parse-file (.getPath tempfile))]
|
||||
{"customer-identifier" customer-identifier
|
||||
"invoice-number" invoice-number
|
||||
"date" date
|
||||
"total" total})))
|
||||
(invoices/insert-multi!
|
||||
(for [{:keys [total date invoice-number customer-identifier] :as row}
|
||||
(parse/parse-file (.getPath tempfile))]
|
||||
(assoc row :imported false)))
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-pending))
|
||||
:headers {"Content-Type" "application/edn"}}))
|
||||
(route/resources "/")
|
||||
(routes (ANY "*" [] (response/resource-response "index.html" {:root "public"})))
|
||||
(route/not-found "Not Found"))
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
(def default-db
|
||||
{:company {:name "Campbell brewery"}
|
||||
:invoices #{}
|
||||
:unpaid-invoices #{}
|
||||
:invoices {:pending #{}
|
||||
:unpaid #{}}
|
||||
})
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
(re-frame/reg-event-db
|
||||
::imported-invoices
|
||||
(fn [db [_ new-invoices]]
|
||||
(update-in db [:invoices] into new-invoices)))
|
||||
(assoc-in db [:invoices] new-invoices)))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received-invoices
|
||||
(fn [db [_ new-invoices]]
|
||||
(update-in db [:unpaid-invoices] into new-invoices)))
|
||||
(fn [db [_ type new-invoices]]
|
||||
(assoc-in db [:invoices type] new-invoices)))
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
(:active-page db)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::invoices
|
||||
::pending-invoices
|
||||
(fn [db]
|
||||
(:invoices db)))
|
||||
(:pending (:invoices db))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::unpaid-invoices
|
||||
(fn [db]
|
||||
(:unpaid-invoices db)))
|
||||
(:unpaid (:invoices db))))
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
[reagent.core :as reagent]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.events :as events]
|
||||
[cljs.reader :as edn]
|
||||
[auto-ap.routes :as routes]
|
||||
[bidi.bidi :as bidi]
|
||||
[cljs-http.client :as http]
|
||||
@@ -23,14 +24,12 @@
|
||||
[:span
|
||||
[:span {:class "icon"}
|
||||
[:i {:class "fa fa-cloud-download"}]]
|
||||
|
||||
"Drop any invoices you want to process here"]]]])
|
||||
{:component-did-mount (fn [this]
|
||||
(js/Dropzone. (reagent/dom-node this)
|
||||
(clj->js {:init (fn []
|
||||
(.on (js-this) "success" (fn [_ files]
|
||||
(re-frame/dispatch [::events/imported-invoices (js->clj (.parse js/JSON files))])
|
||||
)))
|
||||
(re-frame/dispatch [::events/received-invoices :pending (edn/read-string files)]))))
|
||||
:paramName "file"
|
||||
:url "/pdf-upload"
|
||||
:previewsContainer "#dz-hidden"
|
||||
@@ -71,9 +70,9 @@
|
||||
[:td total]])]]]))
|
||||
{:component-did-mount (fn []
|
||||
(go
|
||||
(->> (<! (http/get "/api/invoices"))
|
||||
(->> (<! (http/get "/api/invoices/unpaid"))
|
||||
:body
|
||||
(conj [::events/received-invoices])
|
||||
(conj [::events/received-invoices :unpaid])
|
||||
(re-frame/dispatch))))})])
|
||||
|
||||
(defmethod active-page :paid-invoices []
|
||||
@@ -87,34 +86,42 @@
|
||||
[:h1.title "All invoices"]])
|
||||
{:component-did-mount (fn []
|
||||
(go
|
||||
(re-frame/dispatch [::events/received-invoices (<! (http/get "/api/invoices"))]))
|
||||
(re-frame/dispatch [::events/received-invoices (:body (<! (http/get "/api/invoices")))]))
|
||||
)})])
|
||||
|
||||
(defmethod active-page :import-invoices []
|
||||
(let [invoices (re-frame/subscribe [::subs/invoices])]
|
||||
[:div {:class "inbox-messages"}
|
||||
[:h1.title "Upload invoices"]
|
||||
[dropzone]
|
||||
|
||||
[:div {:class "section"}]
|
||||
[:div {:class "card found-invoices", :style {:display (if (seq @invoices) "block" "none")}}
|
||||
[:div {:class "card-header"}
|
||||
[:span {:class "card-header-title"} "Found Invoices"]]
|
||||
[:div {:class "card-content"}
|
||||
[:table {:class "table", :style {:width "100%"}}
|
||||
[:thead
|
||||
[:tr
|
||||
[:th "Customer"]
|
||||
[:th "Invoice #"]
|
||||
[:th "Date"]
|
||||
[:th "Amount"]]]
|
||||
[:tbody (for [{:strs [customer-identifier invoice-number date total]} @invoices]
|
||||
^{:key (str customer-identifier "-" invoice-number)}
|
||||
[:tr
|
||||
[:td customer-identifier]
|
||||
[:td invoice-number]
|
||||
[:td date]
|
||||
[:td total]])]]]]]))
|
||||
[(with-meta
|
||||
(fn []
|
||||
(let [invoices (re-frame/subscribe [::subs/pending-invoices])]
|
||||
[:div {:class "inbox-messages"}
|
||||
[:h1.title "Upload invoices"]
|
||||
[dropzone]
|
||||
|
||||
[:div {:class "section"}]
|
||||
[:div {:class "card found-invoices", :style {:display (if (seq @invoices) "block" "none")}}
|
||||
[:div {:class "card-header"}
|
||||
[:span {:class "card-header-title"} "Found Invoices"]]
|
||||
[:div {:class "card-content"}
|
||||
[:table {:class "table", :style {:width "100%"}}
|
||||
[:thead
|
||||
[:tr
|
||||
[:th "Customer"]
|
||||
[:th "Invoice #"]
|
||||
[:th "Date"]
|
||||
[:th "Amount"]]]
|
||||
[:tbody (for [{:keys [customer-identifier invoice-number date total id] :as i} @invoices]
|
||||
^{:key (str customer-identifier "-" invoice-number "-" date "-" total "-" id)}
|
||||
[:tr
|
||||
[:td customer-identifier]
|
||||
[:td invoice-number]
|
||||
[:td date]
|
||||
[:td total]])]]]]]))
|
||||
{:component-did-mount (fn []
|
||||
(go
|
||||
(->> (<! (http/get "/api/invoices/pending"))
|
||||
:body
|
||||
(conj [::events/received-invoices :pending])
|
||||
(re-frame/dispatch))))})])
|
||||
|
||||
(defn main-panel []
|
||||
(let [name (re-frame/subscribe [::subs/name])
|
||||
|
||||
Reference in New Issue
Block a user