ability to approve
This commit is contained in:
@@ -11,6 +11,9 @@
|
|||||||
(map db->clj (j/query conn "SELECT * FROM invoices")))
|
(map db->clj (j/query conn "SELECT * FROM invoices")))
|
||||||
|
|
||||||
|
|
||||||
|
(defn approve []
|
||||||
|
(map db->clj (j/update! conn :invoices {:imported true} [] )))
|
||||||
|
|
||||||
(defn get-unpaid []
|
(defn get-unpaid []
|
||||||
(map db->clj (j/query conn "SELECT * FROM invoices WHERE imported=true")))
|
(map db->clj (j/query conn "SELECT * FROM invoices WHERE imported=true")))
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,12 @@
|
|||||||
{:status 200
|
{:status 200
|
||||||
:body (pr-str (invoices/get-all))
|
:body (pr-str (invoices/get-all))
|
||||||
:headers {"Content-Type" "application/edn"}})
|
:headers {"Content-Type" "application/edn"}})
|
||||||
|
(POST "/api/invoices/approve" []
|
||||||
|
(invoices/approve)
|
||||||
|
(println (invoices/get-pending))
|
||||||
|
{:status 200
|
||||||
|
:body (pr-str (invoices/get-pending))
|
||||||
|
:headers {"Content-Type" "application/edn"}})
|
||||||
(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]
|
||||||
|
|||||||
@@ -5,11 +5,11 @@
|
|||||||
[auto-ap.views :as views]
|
[auto-ap.views :as views]
|
||||||
[auto-ap.config :as config]
|
[auto-ap.config :as config]
|
||||||
[auto-ap.routes :as routes]
|
[auto-ap.routes :as routes]
|
||||||
|
[auto-ap.effects :as effects]
|
||||||
[pushy.core :as pushy]
|
[pushy.core :as pushy]
|
||||||
[bidi.bidi :as bidi]))
|
[bidi.bidi :as bidi]))
|
||||||
|
|
||||||
(defn- parse-url [url]
|
(defn- parse-url [url]
|
||||||
(.log js/console "test" (bidi/match-route routes/routes url))
|
|
||||||
(bidi/match-route routes/routes url))
|
(bidi/match-route routes/routes url))
|
||||||
|
|
||||||
(defn- dispatch-route [matched-route]
|
(defn- dispatch-route [matched-route]
|
||||||
|
|||||||
24
src/cljs/auto_ap/effects.cljs
Normal file
24
src/cljs/auto_ap/effects.cljs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
(ns auto-ap.effects
|
||||||
|
(:require-macros [cljs.core.async.macros :refer [go]])
|
||||||
|
(:require [re-frame.core :as re-frame]
|
||||||
|
[reagent.core :as reagent]
|
||||||
|
[auto-ap.subs :as subs]
|
||||||
|
[auto-ap.events :as events]
|
||||||
|
[cljs.reader :as edn]
|
||||||
|
[cljsjs.dropzone :as dz]
|
||||||
|
[auto-ap.routes :as routes]
|
||||||
|
[bidi.bidi :as bidi]
|
||||||
|
[cljs-http.client :as http]
|
||||||
|
[cljs.core.async :refer [<!]]))
|
||||||
|
|
||||||
|
|
||||||
|
(re-frame/reg-fx
|
||||||
|
:http
|
||||||
|
(fn [{:keys [method uri on-success]}]
|
||||||
|
(go
|
||||||
|
(->> (http/request {:method method
|
||||||
|
:url uri})
|
||||||
|
(<! )
|
||||||
|
:body
|
||||||
|
(conj [on-success])
|
||||||
|
(re-frame/dispatch)))))
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
(:require [re-frame.core :as re-frame]
|
(:require [re-frame.core :as re-frame]
|
||||||
[auto-ap.db :as db]
|
[auto-ap.db :as db]
|
||||||
[auto-ap.routes :as routes]
|
[auto-ap.routes :as routes]
|
||||||
|
|
||||||
[bidi.bidi :as bidi]))
|
[bidi.bidi :as bidi]))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
@@ -20,6 +21,19 @@
|
|||||||
(fn [db [_ new-invoices]]
|
(fn [db [_ new-invoices]]
|
||||||
(assoc-in db [:invoices] new-invoices)))
|
(assoc-in db [:invoices] new-invoices)))
|
||||||
|
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
::invoices-approved
|
||||||
|
(fn [db [_ new-invoices]]
|
||||||
|
(assoc-in db [:invoices :pending] new-invoices)))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::approve-invoices
|
||||||
|
(fn [cofx [_]]
|
||||||
|
{:http {:method :post
|
||||||
|
:uri "/api/invoices/approve"
|
||||||
|
:on-success ::invoices-approved
|
||||||
|
}}))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::received-invoices
|
::received-invoices
|
||||||
(fn [db [_ type new-invoices]]
|
(fn [db [_ type new-invoices]]
|
||||||
|
|||||||
@@ -85,8 +85,7 @@
|
|||||||
[:h1.title "All invoices"]])
|
[:h1.title "All invoices"]])
|
||||||
{:component-did-mount (fn []
|
{:component-did-mount (fn []
|
||||||
(go
|
(go
|
||||||
(re-frame/dispatch [::events/received-invoices (:body (<! (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 []
|
||||||
[(with-meta
|
[(with-meta
|
||||||
@@ -114,7 +113,16 @@
|
|||||||
[:td customer-identifier]
|
[:td customer-identifier]
|
||||||
[:td invoice-number]
|
[:td invoice-number]
|
||||||
[:td date]
|
[:td date]
|
||||||
[:td total]])]]]]]))
|
[:td total]])]]]
|
||||||
|
[:div.card-footer
|
||||||
|
[:a.card-footer-item
|
||||||
|
{:on-click (fn [e]
|
||||||
|
(.preventDefault e)
|
||||||
|
(re-frame/dispatch [::events/approve-invoices]))}
|
||||||
|
"Approve all"]
|
||||||
|
[:a.card-footer-item
|
||||||
|
"Reject all"]
|
||||||
|
]]]))
|
||||||
{:component-did-mount (fn []
|
{:component-did-mount (fn []
|
||||||
(go
|
(go
|
||||||
(->> (<! (http/get "/api/invoices/pending"))
|
(->> (<! (http/get "/api/invoices/pending"))
|
||||||
|
|||||||
Reference in New Issue
Block a user