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