basic partition by company.
This commit is contained in:
@@ -17,8 +17,12 @@
|
|||||||
(defn reject []
|
(defn reject []
|
||||||
(j/delete! conn :invoices ["imported = false"]))
|
(j/delete! conn :invoices ["imported = false"]))
|
||||||
|
|
||||||
(defn get-unpaid []
|
(defn get-unpaid [company]
|
||||||
(map db->clj (j/query conn "SELECT * FROM invoices WHERE imported=true")))
|
(if company
|
||||||
|
(map db->clj (j/query conn ["SELECT * FROM invoices WHERE imported=true AND company = ?" company]))
|
||||||
|
(map db->clj (j/query conn "SELECT * FROM invoices WHERE imported=true"))))
|
||||||
|
|
||||||
(defn get-pending []
|
(defn get-pending [company]
|
||||||
(map db->clj (j/query conn "SELECT * FROM invoices WHERE imported=false or imported is null")))
|
(if company
|
||||||
|
(map db->clj (j/query conn ["SELECT * FROM invoices WHERE (imported=false or imported is null) AND company = ?" company]))
|
||||||
|
(map db->clj (j/query conn"SELECT * FROM invoices WHERE imported=false or imported is null"))))
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
[ring.middleware.multipart-params :as mp]
|
[ring.middleware.multipart-params :as mp]
|
||||||
[ring.util.response :as response]
|
[ring.util.response :as response]
|
||||||
[ring.middleware.defaults :refer [wrap-defaults site-defaults]]
|
[ring.middleware.defaults :refer [wrap-defaults site-defaults]]
|
||||||
|
[ring.middleware.params :refer [wrap-params]]
|
||||||
[ring.middleware.reload :refer [wrap-reload]]
|
[ring.middleware.reload :refer [wrap-reload]]
|
||||||
[ring.middleware.json :refer [wrap-json-response]]
|
[ring.middleware.json :refer [wrap-json-response]]
|
||||||
[ring.middleware.edn :refer [wrap-edn-params]]
|
[ring.middleware.edn :refer [wrap-edn-params]]
|
||||||
@@ -30,14 +31,14 @@
|
|||||||
: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" []
|
(GET "/api/invoices/unpaid" {:keys [query-params]}
|
||||||
{:status 200
|
{:status 200
|
||||||
:body (pr-str (invoices/get-unpaid))
|
:body (pr-str (invoices/get-unpaid (query-params "company")))
|
||||||
:headers {"Content-Type" "application/edn"}})
|
:headers {"Content-Type" "application/edn"}})
|
||||||
|
|
||||||
(GET "/api/invoices/pending" []
|
(GET "/api/invoices/pending" {:keys [query-params]}
|
||||||
{:status 200
|
{:status 200
|
||||||
:body (pr-str (invoices/get-pending))
|
:body (pr-str (invoices/get-pending (query-params "company")))
|
||||||
:headers {"Content-Type" "application/edn"}})
|
:headers {"Content-Type" "application/edn"}})
|
||||||
|
|
||||||
(POST "/api/invoices" {:keys [edn-params]}
|
(POST "/api/invoices" {:keys [edn-params]}
|
||||||
@@ -45,15 +46,15 @@
|
|||||||
{: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" []
|
(POST "/api/invoices/approve" {:keys [query-params]}
|
||||||
(invoices/approve)
|
(invoices/approve)
|
||||||
{:status 200
|
{:status 200
|
||||||
:body (pr-str (invoices/get-pending))
|
:body (pr-str (invoices/get-pending (query-params "company")))
|
||||||
:headers {"Content-Type" "application/edn"}})
|
:headers {"Content-Type" "application/edn"}})
|
||||||
(POST "/api/invoices/reject" []
|
(POST "/api/invoices/reject" {:keys [query-params]}
|
||||||
(invoices/reject)
|
(invoices/reject)
|
||||||
{:status 200
|
{:status 200
|
||||||
:body (pr-str (invoices/get-pending))
|
:body (pr-str (invoices/get-pending (query-params "company")))
|
||||||
:headers {"Content-Type" "application/edn"}})
|
:headers {"Content-Type" "application/edn"}})
|
||||||
(POST "/pdf-upload"
|
(POST "/pdf-upload"
|
||||||
{{ files "file"} :params :as params}
|
{{ files "file"} :params :as params}
|
||||||
@@ -72,11 +73,11 @@
|
|||||||
existing-invoices)))
|
existing-invoices)))
|
||||||
)))
|
)))
|
||||||
{:status 200
|
{:status 200
|
||||||
:body (pr-str (invoices/get-pending))
|
:body (pr-str (invoices/get-pending ((:query-params params ) "company")))
|
||||||
:headers {"Content-Type" "application/edn"}}))
|
: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"))
|
||||||
|
|
||||||
(def app
|
(def app
|
||||||
(wrap-edn-params (mp/wrap-multipart-params (wrap-reload #'app-routes))))
|
(wrap-edn-params (mp/wrap-multipart-params (wrap-params (wrap-reload #'app-routes)))))
|
||||||
|
|||||||
@@ -2,8 +2,15 @@
|
|||||||
|
|
||||||
(def default-db
|
(def default-db
|
||||||
{:company {:name "Campbell brewery"}
|
{:company {:name "Campbell brewery"}
|
||||||
|
:companies [{:name "Campbell Brewing Company"
|
||||||
|
:matches ["campbell brewing company" "campbell brewery company" "campbell brewing"]}
|
||||||
|
{:name "Brown Chicken Brown Cow"
|
||||||
|
:matches ["brown chicken brown cow"]}
|
||||||
|
{:name "Naschmarkt Restaurant"
|
||||||
|
:matches ["naschmarkt" "naschmarkt restaurant"]}]
|
||||||
:invoices {:pending #{}
|
:invoices {:pending #{}
|
||||||
:unpaid #{}}
|
:unpaid #{}}
|
||||||
:status {:loading false}
|
:status {:loading false}
|
||||||
:new-invoice {}
|
:new-invoice {}
|
||||||
|
:menu {:active? false}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -11,6 +11,16 @@
|
|||||||
(assoc db/default-db
|
(assoc db/default-db
|
||||||
:active-page (:handler (bidi/match-route routes/routes (.. js/window -location -pathname))))))
|
:active-page (:handler (bidi/match-route routes/routes (.. js/window -location -pathname))))))
|
||||||
|
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
::toggle-company-menu
|
||||||
|
(fn [db [_ active-page]]
|
||||||
|
(update-in db [:menu :active?] #(not %))))
|
||||||
|
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
::swap-company
|
||||||
|
(fn [db [_ company]]
|
||||||
|
(assoc db :company company)))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::set-active-page
|
::set-active-page
|
||||||
(fn [db [_ active-page]]
|
(fn [db [_ active-page]]
|
||||||
@@ -25,7 +35,9 @@
|
|||||||
::approve-invoices
|
::approve-invoices
|
||||||
(fn [cofx [_]]
|
(fn [cofx [_]]
|
||||||
{:http {:method :post
|
{:http {:method :post
|
||||||
:uri "/api/invoices/approve"
|
:uri (str "/api/invoices/approve"
|
||||||
|
(when-let [company-name (-> cofx :db :company :name)]
|
||||||
|
(str "?company=" company-name)))
|
||||||
:on-success [::received-invoices :pending]
|
:on-success [::received-invoices :pending]
|
||||||
}}))
|
}}))
|
||||||
|
|
||||||
@@ -34,7 +46,9 @@
|
|||||||
(fn [cofx []]
|
(fn [cofx []]
|
||||||
{:db (assoc-in (:db cofx) [:status :loading] true)
|
{:db (assoc-in (:db cofx) [:status :loading] true)
|
||||||
:http {:method :get
|
:http {:method :get
|
||||||
:uri "/api/invoices/pending"
|
:uri (str "/api/invoices/pending"
|
||||||
|
(when-let [company-name (-> cofx :db :company :name)]
|
||||||
|
(str "?company=" company-name)))
|
||||||
:on-success [::received-invoices :pending]}}))
|
:on-success [::received-invoices :pending]}}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
@@ -42,14 +56,18 @@
|
|||||||
(fn [cofx []]
|
(fn [cofx []]
|
||||||
{:db (assoc-in (:db cofx) [:status :loading] true)
|
{:db (assoc-in (:db cofx) [:status :loading] true)
|
||||||
:http {:method :get
|
:http {:method :get
|
||||||
:uri "/api/invoices/unpaid"
|
:uri (str "/api/invoices/unpaid"
|
||||||
|
(when-let [company-name (-> cofx :db :company :name)]
|
||||||
|
(str "?company=" company-name)))
|
||||||
:on-success [::received-invoices :unpaid]}}))
|
:on-success [::received-invoices :unpaid]}}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::reject-invoices
|
::reject-invoices
|
||||||
(fn [cofx [_]]
|
(fn [cofx [_]]
|
||||||
{:http {:method :post
|
{:http {:method :post
|
||||||
:uri "/api/invoices/reject"
|
:uri (str "/api/invoices/reject"
|
||||||
|
(when-let [company-name (-> cofx :db :company :name)]
|
||||||
|
(str "?company=" company-name)))
|
||||||
:on-success [::received-invoices :pending]
|
:on-success [::received-invoices :pending]
|
||||||
}}))
|
}}))
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
|
|||||||
@@ -2,9 +2,19 @@
|
|||||||
(:require [re-frame.core :as re-frame]))
|
(:require [re-frame.core :as re-frame]))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::name
|
::company
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(:name (:company db))))
|
(:company db)))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::companies
|
||||||
|
(fn [db]
|
||||||
|
(:companies db)))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::menu
|
||||||
|
(fn [db]
|
||||||
|
(:menu db)))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::active-page
|
::active-page
|
||||||
|
|||||||
@@ -15,24 +15,27 @@
|
|||||||
(when (= active-page candidate) " active"))
|
(when (= active-page candidate) " active"))
|
||||||
|
|
||||||
(def dropzone
|
(def dropzone
|
||||||
(with-meta
|
(let [company (re-frame/subscribe [::subs/company])]
|
||||||
(fn []
|
(with-meta
|
||||||
[:form.dz {:action "/pdf-upload"}
|
(fn []
|
||||||
[:div.tile.notification
|
[:form.dz {:action "/pdf-upload"}
|
||||||
[:div.has-text-centered {:style {:padding "80px 0px" :width "100%"}}
|
[:div.tile.notification
|
||||||
[:span
|
[:div.has-text-centered {:style {:padding "80px 0px" :width "100%"}}
|
||||||
[:span {:class "icon"}
|
[:span
|
||||||
[:i {:class "fa fa-cloud-download"}]]
|
[:span {:class "icon"}
|
||||||
"Drop any invoices you want to process here"]]]])
|
[:i {:class "fa fa-cloud-download"}]]
|
||||||
{:component-did-mount (fn [this]
|
"Drop any invoices you want to process here"]]]])
|
||||||
(js/Dropzone. (reagent/dom-node this)
|
{:component-did-mount (fn [this]
|
||||||
(clj->js {:init (fn []
|
(js/Dropzone. (reagent/dom-node this)
|
||||||
(.on (js-this) "success" (fn [_ files]
|
(clj->js {:init (fn []
|
||||||
(re-frame/dispatch [::events/received-invoices :pending (edn/read-string files)]))))
|
(.on (js-this) "success" (fn [_ files]
|
||||||
:paramName "file"
|
(re-frame/dispatch [::events/received-invoices :pending (edn/read-string files)]))))
|
||||||
:url "/pdf-upload"
|
:paramName "file"
|
||||||
:previewsContainer "#dz-hidden"
|
:url (str "/pdf-upload"
|
||||||
:previewTemplate "<div class='dz-hidden-preview'></div>"})))}))
|
(when-let [company-name (-> @company :name)]
|
||||||
|
(str "?company=" company-name)))
|
||||||
|
:previewsContainer "#dz-hidden"
|
||||||
|
:previewTemplate "<div class='dz-hidden-preview'></div>"})))})))
|
||||||
|
|
||||||
(defmulti active-page identity)
|
(defmulti active-page identity)
|
||||||
|
|
||||||
@@ -163,11 +166,11 @@
|
|||||||
[:label.label "Customer"]
|
[:label.label "Customer"]
|
||||||
[:div.control
|
[:div.control
|
||||||
[:input.input {:type "text"
|
[:input.input {:type "text"
|
||||||
:placeholder "Campbell's Brewery"
|
:placeholder "Brown Chicken Brown Cow"
|
||||||
:value (:customer-identifier @form-data)
|
:value (:company @form-data)
|
||||||
:on-change (fn [e]
|
:on-change (fn [e]
|
||||||
(re-frame/dispatch [::events/change-form-state
|
(re-frame/dispatch [::events/change-form-state
|
||||||
[:new-invoice :customer-identifier]
|
[:new-invoice :company]
|
||||||
(.. e -target -value)]))}]]]
|
(.. e -target -value)]))}]]]
|
||||||
[:div.field
|
[:div.field
|
||||||
[:label.label "Invoice #"]
|
[:label.label "Invoice #"]
|
||||||
@@ -201,7 +204,7 @@
|
|||||||
(.. e -target -value)]))}]]]
|
(.. e -target -value)]))}]]]
|
||||||
[:div.control
|
[:div.control
|
||||||
[:submit.button.is-large.is-primary {
|
[:submit.button.is-large.is-primary {
|
||||||
:disabled (if (and (:total @form-data) (:date @form-data) (:customer-identifier @form-data) (:invoice-number @form-data)
|
:disabled (if (and (:total @form-data) (:date @form-data) (:company @form-data) (:invoice-number @form-data)
|
||||||
(:vendor @form-data))
|
(:vendor @form-data))
|
||||||
""
|
""
|
||||||
"disabled")
|
"disabled")
|
||||||
@@ -215,22 +218,40 @@
|
|||||||
"Save"]]]]]))
|
"Save"]]]]]))
|
||||||
|
|
||||||
(defn main-panel []
|
(defn main-panel []
|
||||||
(let [name (re-frame/subscribe [::subs/name])
|
(let [company (re-frame/subscribe [::subs/company])
|
||||||
ap (re-frame/subscribe [::subs/active-page])]
|
ap (re-frame/subscribe [::subs/active-page])
|
||||||
|
companies (re-frame/subscribe [::subs/companies])
|
||||||
|
menu (re-frame/subscribe [::subs/menu])]
|
||||||
[:div
|
[:div
|
||||||
[:nav {:class "navbar has-shadow"}
|
[:nav {:class "navbar has-shadow"}
|
||||||
[:div {:class "container"}
|
[:div {:class "container"}
|
||||||
[:div {:class "navbar-brand"}
|
[:div {:class "navbar-brand"}
|
||||||
[:a {:class "navbar-item", :href "../"}
|
[:a {:class "navbar-item", :href "../"}
|
||||||
[:h1 (str "Auto-ap - " @name)]]
|
[:h1 (str "Auto-ap")]]]
|
||||||
[:div {:class "navbar-burger burger", :data-target "navMenu"}
|
[:div {:id "navMenu", :class "navbar-menu "
|
||||||
[:span]
|
:on-click (fn [] (re-frame/dispatch [::events/toggle-company-menu]))}
|
||||||
[:span]
|
[:div.navbar-start
|
||||||
[:span]]]
|
[:div { :class (str "navbar-item has-dropdown " (when (:active? @menu) "is-active"))}
|
||||||
|
[:a {:class "navbar-link login"} "Company: " (if @company (:name @company)
|
||||||
|
"All")]
|
||||||
|
[:div {:class "navbar-dropdown"}
|
||||||
|
[:a {:class "navbar-item"
|
||||||
|
:on-click (fn [] (re-frame/dispatch [::events/swap-company nil]))
|
||||||
|
} "All"]
|
||||||
|
[:hr {:class "navbar-divider"}]
|
||||||
|
(for [{:keys [name] :as company} @companies]
|
||||||
|
^{:key name }
|
||||||
|
[:a {:class "navbar-item"
|
||||||
|
:on-click (fn [] (re-frame/dispatch [::events/swap-company company]))
|
||||||
|
} name])]]]]
|
||||||
|
[:div {:class "navbar-burger burger", :data-target "navMenu"}
|
||||||
|
[:span]
|
||||||
|
[:span]
|
||||||
|
[:span]]
|
||||||
[:div {:id "navMenu", :class "navbar-menu"}
|
[:div {:id "navMenu", :class "navbar-menu"}
|
||||||
[:div {:class "navbar-end"}
|
[:div {:class "navbar-end"}
|
||||||
[:div {:class "navbar-item has-dropdown is-active"}
|
[:div {:class "navbar-item has-dropdown is-active"}
|
||||||
[:a {:class "navbar-link login"} ]
|
[:a {:class "navbar-link login"} "Login"]
|
||||||
[:div {:class "navbar-dropdown", :style {:display "none"}}
|
[:div {:class "navbar-dropdown", :style {:display "none"}}
|
||||||
[:a {:class "navbar-item"} ]
|
[:a {:class "navbar-item"} ]
|
||||||
[:a {:class "navbar-item"} ]
|
[:a {:class "navbar-item"} ]
|
||||||
@@ -274,7 +295,7 @@
|
|||||||
[:a {:class "button is-danger is-block is-bold" :href (bidi/path-for routes/routes :new-invoice)}
|
[:a {:class "button is-danger is-block is-bold" :href (bidi/path-for routes/routes :new-invoice)}
|
||||||
[:span {:class "compose"} "New Invoice"]]]]]
|
[:span {:class "compose"} "New Invoice"]]]]]
|
||||||
[:div {:class "column messages hero is-fullheight", :id "message-feed"}
|
[:div {:class "column messages hero is-fullheight", :id "message-feed"}
|
||||||
[active-page @ap]]]
|
^{:key (str "active-page-" (:name @company))} [active-page @ap]]]
|
||||||
[:footer {:class "footer"}
|
[:footer {:class "footer"}
|
||||||
[:div {:class "container"}
|
[:div {:class "container"}
|
||||||
[:div {:class "content has-text-centered"}
|
[:div {:class "content has-text-centered"}
|
||||||
|
|||||||
Reference in New Issue
Block a user