made invoice import back to working, mostly

This commit is contained in:
Bryce Covert
2019-02-11 22:00:36 -08:00
parent 7c01a04ee8
commit 46a5d4cbfd
7 changed files with 132 additions and 53 deletions

View File

@@ -19,20 +19,20 @@
[:li.menu-item
[:a.item {:href (bidi/path-for routes/routes :unpaid-invoices)
:class [(active-when ap = :unpaid-invoices)]}
[:span {:class "icon icon-accounting-document" :style {:font-size "25px"}}]
[:span {:class "icon icon-accounting-invoice-mail" :style {:font-size "25px"}}]
[:span {:class "name"} "Unpaid Invoices"]]]
[:li.menu-item
[:a.item {:href (bidi/path-for routes/routes :paid-invoices)
:class [(active-when ap = :paid-invoices)]}
[:span {:class "icon icon-accounting-invoice-mail" :style {:font-size "25px"}}]
[:span {:class "icon icon-check-payment-give" :style {:font-size "25px"}}]
[:span {:class "name"} "Paid Invoices"]]]
[:li.menu-item
[:a.item {:href (bidi/path-for routes/routes :import-invoices)
:class [(active-when ap = :import-invoices)]}
[:span {:class "icon icon-accounting-invoice-mail" :style {:font-size "25px"}}]
[:span {:class "icon icon-accounting-document" :style {:font-size "25px"}}]
[:span {:class "name"} "Import Invoices"]]]]]
[:div

View File

@@ -6,6 +6,7 @@
[auto-ap.entities.clients :as client]
[auto-ap.views.components.layouts :refer [side-bar-layout]]
[auto-ap.views.components.invoices.side-bar :refer [invoices-side-bar]]
[auto-ap.views.utils :refer [dispatch-event]]
[auto-ap.entities.vendors :as vendor]
[auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table]
[cljsjs.dropzone :as dropzone]
@@ -69,15 +70,32 @@
(assoc-in [:status :loading] false))))
(re-frame/reg-event-fx
::reject-invoices
(fn [cofx [_ on-success]]
{:http {:method :post
:token (-> cofx :db :user)
:uri (str "/api/invoices/reject"
(when-let [client-id (:id @(re-frame/subscribe [::subs/client]))]
(str "?client=" client-id)))
:on-success on-success
}}))
::reject-invoices-clicked
(fn [{:keys [db]} [_ invoices on-success]]
{:graphql
{:token (-> db :user)
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "RejectInvoices"}
:venia/queries [[:reject-invoices
{:invoices (keys invoices)}
[]]]}
:on-success [::invalidated]}
}))
(re-frame/reg-event-fx
::approve-invoices-clicked
(fn [{:keys [db]} [_ invoices on-success]]
{:graphql
{:token (-> db :user)
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "ApproveInvoices"}
:venia/queries [[:approve-invoices
{:invoices (keys invoices)}
[]]]}
:on-success [::invalidated]}
}))
(re-frame/reg-event-fx
::approve-invoices
@@ -90,6 +108,45 @@
:on-success on-success
}}))
(re-frame/reg-event-db
::toggle-check
(fn [db [_ id invoice]]
(-> db
(update-in [::invoice-page :checked] (fn [x]
(let [x (or x {})]
(if (x id)
(dissoc x id)
(assoc x id invoice))))))))
(defn approve-reject-button [checked]
[:div.is-pulled-right
[:button.button.is-success {:on-click (dispatch-event [::approve-invoices-clicked checked])
:disabled (if (seq checked)
""
"disabled")}
"Approve "
(when (> (count checked ))
(str
(count checked)
" invoices"))
[:span " "]]
[:button.button.is-danger {:on-click (dispatch-event [::reject-invoices-clicked checked])
:disabled (if (seq checked)
""
"disabled")}
"Reject "
(when (> (count checked ))
(str
(count checked)
" invoices"))
[:span " "]
]])
(def import-invoices-content
(with-meta
(fn []
@@ -104,31 +161,22 @@
[:div {:class "card-header"}
[:span {:class "card-header-title"} "Found Invoices"]]
[:div {:class "card-content"}
[approve-reject-button (:checked @invoice-page)]
(if (:loading @status)
[:h1.title
[:i.fa.fa-spin.fa-spinner]]
(if (seq (:invoices @invoice-page))
[invoice-table {:id :approved
:invoice-page invoice-page
:check-boxes true
:checked (:checked @invoice-page)
:on-check-changed (fn [which invoice]
(re-frame/dispatch [::toggle-check which invoice]))
:status (re-frame/subscribe [::subs/status])
:params (re-frame/subscribe [::params])
:on-params-change (fn [params]
(re-frame/dispatch [::params-change params])) }]
[:span "No pending invoices"]))]
(if (and (seq (:invoices @invoice-page)) (not (:loading @status)))
[:div.card-footer
[:a.card-footer-item
{:on-click (fn [e]
(.preventDefault e)
(re-frame/dispatch [::approve-invoices
[::invalidated]]))}
"Accept all"]
[:a.card-footer-item
{:on-click (fn [e]
(.preventDefault e)
(re-frame/dispatch [::reject-invoices
[::invalidated]]))}
"Reject all"]])]]))
[:span "No pending invoices"]))]]]))
{:component-will-mount (fn []
(re-frame/dispatch-sync [::invalidated]))}))