unpaid and paid invoices use the same underlying page, now.
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
[io.forward/clojure-mail "1.0.7"]
|
||||
[ring/ring-json "0.4.0"
|
||||
:exclusions [cheshire]]
|
||||
[com.cemerick/url "0.1.1"]
|
||||
[amazonica "0.3.121"
|
||||
:exclusions [com.amazonaws/aws-java-sdk
|
||||
com.amazonaws/amazon-kinesis-client]]
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
[auto-ap.utils :refer [by]]
|
||||
[venia.core :as v]
|
||||
[bidi.bidi :as bidi]
|
||||
[cemerick.url :refer [url]]
|
||||
[goog.crypt.base64 :as b64]
|
||||
[clojure.string :as str]))
|
||||
|
||||
@@ -33,6 +34,9 @@
|
||||
:else
|
||||
{:db (assoc db/default-db
|
||||
:active-page handler
|
||||
:query-params (->> (:query (url (.-location js/window)))
|
||||
(map (fn [[k v]] [(keyword k) v]))
|
||||
(into {}))
|
||||
:user token)
|
||||
:graphql {:token token
|
||||
:query-obj {:venia/queries [[:client
|
||||
@@ -106,11 +110,13 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::set-active-page
|
||||
(fn [{:keys [db]} [_ handler]]
|
||||
(fn [{:keys [db]} [_ handler params]]
|
||||
(println "PARAMS" params)
|
||||
(if (and (not= :login handler) (not (:user db)))
|
||||
{:redirect "/login"
|
||||
:db (assoc db :active-page :login)}
|
||||
{:db (assoc db :active-page handler)})))
|
||||
{:db (assoc db :active-page handler
|
||||
:query-params params)})))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::imported-invoices
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
(:require [bidi.bidi :as bidi]
|
||||
[pushy.core :as pushy]
|
||||
[auto-ap.routes :as routes]
|
||||
[cemerick.url :refer [url]]
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
(defn- parse-url [url]
|
||||
@@ -10,7 +11,9 @@
|
||||
|
||||
(defn- dispatch-route [matched-route]
|
||||
(println "Matched route" matched-route)
|
||||
(re-frame/dispatch [:auto-ap.events/set-active-page (:handler matched-route)]))
|
||||
(re-frame/dispatch [:auto-ap.events/set-active-page (:handler matched-route) (->> (:query (url (.-location js/window)))
|
||||
(map (fn [[k v]] [(keyword k) v]))
|
||||
(into {}))]))
|
||||
|
||||
|
||||
(def history (pushy/pushy dispatch-route parse-url))
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
(def routes ["/" {"" :index
|
||||
"login/" :login
|
||||
"needs-activation/" :needs-activation
|
||||
"needs-activation" :needs-activation
|
||||
"checks/" :checks
|
||||
"admin/" {"" :admin
|
||||
"clients" :admin-clients
|
||||
|
||||
@@ -85,6 +85,11 @@
|
||||
(map (fn [[k v]] (assoc v :id k))
|
||||
expense-accounts)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::query-params
|
||||
(fn [db]
|
||||
(:query-params db)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::chooseable-expense-accounts
|
||||
(fn [db]
|
||||
|
||||
@@ -19,15 +19,14 @@
|
||||
[auto-ap.views.pages.admin.users :refer [admin-users-page]]
|
||||
[auto-ap.views.pages.admin.yodlee :refer [admin-yodlee-page]]
|
||||
[auto-ap.entities.clients :as clients]
|
||||
[auto-ap.views.pages :as pages]
|
||||
[auto-ap.views.components.vendor-dialog :refer [vendor-dialog]]))
|
||||
|
||||
(defmulti page (fn [active-page] active-page))
|
||||
(defmethod page :unpaid-invoices [_]
|
||||
(unpaid-invoices-page))
|
||||
(unpaid-invoices-page {:status "unpaid"}))
|
||||
|
||||
(defmethod page :paid-invoices [_]
|
||||
(paid-invoices-page))
|
||||
(unpaid-invoices-page {:status "paid"}))
|
||||
|
||||
(defmethod page :checks [_]
|
||||
(checks-page))
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
(ns auto-ap.views.pages
|
||||
(: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]
|
||||
[auto-ap.views.pages.login :refer [login-page]]
|
||||
[auto-ap.views.pages.index :refer [index-page]]
|
||||
[auto-ap.views.pages.admin :refer [admin-page]]
|
||||
[auto-ap.views.pages.needs-activation :refer [needs-activation-page]]
|
||||
[auto-ap.views.pages.check :refer [check-page]]
|
||||
[auto-ap.views.pages.admin.clients :refer [admin-clients-page]]
|
||||
[auto-ap.views.pages.admin.yodlee :refer [admin-yodlee-page]]
|
||||
[auto-ap.views.pages.admin.users :refer [admin-users-page]]
|
||||
[auto-ap.views.pages.admin.vendors :refer [admin-vendors-page]]
|
||||
[auto-ap.views.pages.admin.reminders :refer [admin-reminders-page]]
|
||||
[auto-ap.views.pages.unpaid-invoices :refer [unpaid-invoices-page]]
|
||||
[auto-ap.views.pages.checks :refer [checks-page]]
|
||||
[auto-ap.views.pages.transactions :refer [transactions-page]]
|
||||
[auto-ap.views.pages.new-invoice :refer [new-invoice-page]]
|
||||
[auto-ap.views.pages.import-invoices :refer [import-invoices-page]]
|
||||
[auto-ap.views.pages.admin.excel-import :refer [admin-excel-import-page]]
|
||||
[auto-ap.views.pages.paid-invoices :refer [paid-invoices-page]]
|
||||
[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 [<!]]))
|
||||
|
||||
|
||||
(defmulti active-page identity)
|
||||
|
||||
(defmethod active-page :login []
|
||||
login-page)
|
||||
|
||||
(defmethod active-page :index []
|
||||
index-page)
|
||||
|
||||
(defmethod active-page :admin []
|
||||
[admin-page])
|
||||
|
||||
(defmethod active-page :needs-activation []
|
||||
[needs-activation-page])
|
||||
|
||||
(defmethod active-page :check []
|
||||
[check-page])
|
||||
|
||||
(defmethod active-page :admin-clients []
|
||||
[admin-clients-page])
|
||||
|
||||
(defmethod active-page :admin-vendors []
|
||||
[admin-vendors-page])
|
||||
|
||||
(defmethod active-page :admin-reminders []
|
||||
[admin-reminders-page])
|
||||
|
||||
(defmethod active-page :admin-yodlee []
|
||||
[admin-yodlee-page])
|
||||
|
||||
(defmethod active-page :admin-excel-import []
|
||||
[admin-excel-import-page])
|
||||
|
||||
(defmethod active-page :admin-users []
|
||||
[admin-users-page])
|
||||
|
||||
(defmethod active-page :unpaid-invoices []
|
||||
[unpaid-invoices-page])
|
||||
|
||||
(defmethod active-page :paid-invoices []
|
||||
[paid-invoices-page])
|
||||
|
||||
(defmethod active-page :checks []
|
||||
[checks-page])
|
||||
|
||||
(defmethod active-page :transactions []
|
||||
[transactions-page])
|
||||
|
||||
(defmethod active-page :invoices []
|
||||
[(with-meta
|
||||
(fn []
|
||||
[:div
|
||||
[:h1.title "All invoices"]])
|
||||
{:component-did-mount (fn []
|
||||
(go
|
||||
(re-frame/dispatch [::events/received-invoices (:body (<! (http/get "/api/invoices")))])))})])
|
||||
|
||||
(defmethod active-page :import-invoices []
|
||||
[import-invoices-page])
|
||||
|
||||
|
||||
(defmethod active-page :new-invoice [] new-invoice-page)
|
||||
@@ -78,7 +78,7 @@
|
||||
(assoc-in [:status :loading] true)
|
||||
(assoc-in [::params] params))
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:query-obj (invoice-table/query (doto (assoc params :imported true :status "unpaid") println))
|
||||
:query-obj (invoice-table/query (doto (assoc params :imported true) println))
|
||||
:on-success [::received]}}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
@@ -614,7 +614,7 @@
|
||||
:step "0.01"}]]]]]
|
||||
]))
|
||||
|
||||
(defn edit-invoice-modal []
|
||||
(defn edit-invoice-modal [{:keys [can-change-amount?]}]
|
||||
(let [data @(re-frame/subscribe [::edit-invoice])
|
||||
change-event [::events/change-form [::edit-invoice]]
|
||||
locations (get-in @(re-frame/subscribe [::subs/clients-by-id]) [(:client-id data) :locations])
|
||||
@@ -659,12 +659,12 @@
|
||||
[bind-field
|
||||
[:input.input {:type "number"
|
||||
:field [:total]
|
||||
:disabled (if can-change-amount? "" "disabled")
|
||||
:event change-event
|
||||
:min min-total
|
||||
:subscription data
|
||||
:spec ::invoice/total
|
||||
:step "0.01"}]]]]]
|
||||
]))
|
||||
:step "0.01"}]]]]]]))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::change-selected-vendor
|
||||
@@ -702,88 +702,94 @@
|
||||
(re-frame/dispatch [::params-change (assoc params :invoice-number-like (.. x -target -value)) ])
|
||||
)} ]]]))
|
||||
|
||||
(def unpaid-invoices-content
|
||||
(with-meta
|
||||
(fn [_]
|
||||
(let [{:keys [checked print-checks-shown? print-checks-loading? advanced-print-shown? vendor-filter]} @(re-frame/subscribe [::invoice-page])
|
||||
current-client @(re-frame/subscribe [::subs/client])
|
||||
{check-results-shown? :shown? pdf-url :pdf-url} @(re-frame/subscribe [::check-results])]
|
||||
[:div
|
||||
[:h1.title "Unpaid invoices"]
|
||||
(defn pay-button [{:keys [print-checks-shown? checked-invoices print-checks-loading?]}]
|
||||
(let [current-client @(re-frame/subscribe [::subs/client])]
|
||||
[:div.is-pulled-right
|
||||
[:button.button.is-danger {:on-click (dispatch-event [::new-invoice])} "New Invoice"]
|
||||
(when current-client
|
||||
[:div.dropdown.is-right {:class (if print-checks-shown?
|
||||
"is-active"
|
||||
"")}
|
||||
[:div.dropdown-trigger
|
||||
[:button.button.is-success {:aria-haspopup true
|
||||
:on-click (dispatch-event [::print-checks-clicked ])
|
||||
:disabled (if (seq checked-invoices)
|
||||
""
|
||||
"disabled")
|
||||
|
||||
[:div.is-pulled-right
|
||||
[:button.button.is-danger {:on-click (dispatch-event [::new-invoice])} "New Invoice"]
|
||||
(when current-client
|
||||
[:div.dropdown.is-right {:class (if print-checks-shown?
|
||||
"is-active"
|
||||
"")}
|
||||
[:div.dropdown-trigger
|
||||
[:button.button.is-success {:aria-haspopup true
|
||||
:on-click (dispatch-event [::print-checks-clicked ])
|
||||
:disabled (if (seq checked)
|
||||
""
|
||||
"disabled")
|
||||
|
||||
:class (if print-checks-loading?
|
||||
"is-loading"
|
||||
"")}
|
||||
"Pay "
|
||||
[:span " "]
|
||||
[:span.icon.is-small [:i.fa.fa-angle-down {:aria-hidden "true"}]]]]
|
||||
[:div.dropdown-menu {:role "menu"}
|
||||
[:div.dropdown-content
|
||||
:class (if print-checks-loading?
|
||||
"is-loading"
|
||||
"")}
|
||||
"Pay "
|
||||
[:span " "]
|
||||
[:span.icon.is-small [:i.fa.fa-angle-down {:aria-hidden "true"}]]]]
|
||||
[:div.dropdown-menu {:role "menu"}
|
||||
[:div.dropdown-content
|
||||
(list
|
||||
(for [{:keys [id number name type]} (:bank-accounts current-client)]
|
||||
(if (= :cash type)
|
||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :cash])} "With cash"]
|
||||
(list
|
||||
(for [{:keys [id number name type]} (:bank-accounts current-client)]
|
||||
(if (= :cash type)
|
||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :cash])} "With cash"]
|
||||
(list
|
||||
^{:key (str id "-check")} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :check])} "Print checks from " name]
|
||||
^{:key (str id "-debit")} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :debit])} "Debit from " name])))
|
||||
^{:key "advanced-divider"} [:hr.dropdown-divider]
|
||||
^{:key (str id "-check")} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :check])} "Print checks from " name]
|
||||
^{:key (str id "-debit")} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :debit])} "Debit from " name])))
|
||||
^{:key "advanced-divider"} [:hr.dropdown-divider]
|
||||
|
||||
(when (= 1 (count checked))
|
||||
^{:key "handwritten"} [:a.dropdown-item {:on-click (dispatch-event [::handwrite-checks])} "Handwritten Check..."])
|
||||
^{:key "advanced"} [:a.dropdown-item {:on-click (dispatch-event [::advanced-print-checks])} "Advanced..."])]]])]
|
||||
[invoice-table {:id :unpaid
|
||||
:params (re-frame/subscribe [::params])
|
||||
:invoice-page (re-frame/subscribe [::invoice-page])
|
||||
:status (re-frame/subscribe [::subs/status])
|
||||
:on-edit-invoice (fn [which]
|
||||
(re-frame/dispatch [::edit-invoice which]))
|
||||
(when (= 1 (count checked-invoices))
|
||||
^{:key "handwritten"} [:a.dropdown-item {:on-click (dispatch-event [::handwrite-checks])} "Handwritten Check..."])
|
||||
^{:key "advanced"} [:a.dropdown-item {:on-click (dispatch-event [::advanced-print-checks])} "Advanced..."])]]])]))
|
||||
|
||||
:on-void-invoice (fn [which]
|
||||
(re-frame/dispatch [::void-invoice which]))
|
||||
:on-params-change (fn [params]
|
||||
(re-frame/dispatch [::params-change params]))
|
||||
:check-boxes true
|
||||
:checked checked
|
||||
:on-check-changed (fn [which]
|
||||
(re-frame/dispatch [::toggle-check which]))
|
||||
:expense-event [::expense-accounts-dialog/change-expense-accounts]}]
|
||||
(defn unpaid-invoices-content [{:keys [status]}]
|
||||
(r/create-class {:display-name "unpaid-invoices-content"
|
||||
:reagent-render (fn [{:keys [status]}]
|
||||
(let [{:keys [checked print-checks-shown? print-checks-loading? advanced-print-shown? vendor-filter]} @(re-frame/subscribe [::invoice-page])
|
||||
current-client @(re-frame/subscribe [::subs/client])
|
||||
{check-results-shown? :shown? pdf-url :pdf-url} @(re-frame/subscribe [::check-results])]
|
||||
[:div
|
||||
[:h1.title (str (str/capitalize status) " invoices")]
|
||||
(when (= status "unpaid")
|
||||
[pay-button {:print-checks-shown? print-checks-shown? :checked-invoices checked :print-checks-loading? print-checks-loading?}])
|
||||
|
||||
[print-checks-modal]
|
||||
[new-invoice-modal]
|
||||
[edit-invoice-modal]
|
||||
[handwrite-checks-modal]
|
||||
[change-expense-accounts-modal {:updated-event [::expense-accounts-updated]}]
|
||||
(when check-results-shown?
|
||||
(if pdf-url
|
||||
[modal
|
||||
{:title "Your checks are ready!"
|
||||
:hide-event [::close-check-results]}
|
||||
[:div "Click " [:a {:href pdf-url :target "_new"} "here"] " to print them."]
|
||||
[:div [:em "Remember to turn off all scaling and margins."]]
|
||||
]
|
||||
[modal
|
||||
{:title "Payment created!"
|
||||
:hide-event [::close-check-results]}
|
||||
[:div [:em "Your payment was created."]]
|
||||
]))
|
||||
|
||||
[invoice-table {:id :unpaid
|
||||
:params (re-frame/subscribe [::params])
|
||||
:invoice-page (re-frame/subscribe [::invoice-page])
|
||||
:status (re-frame/subscribe [::subs/status])
|
||||
:on-edit-invoice (fn [which]
|
||||
(re-frame/dispatch [::edit-invoice which]))
|
||||
|
||||
]))
|
||||
{:component-will-mount #(re-frame/dispatch-sync [::params-change {}]) }))
|
||||
:on-void-invoice (fn [which]
|
||||
(re-frame/dispatch [::void-invoice which]))
|
||||
:on-params-change (fn [params]
|
||||
(re-frame/dispatch [::params-change params]))
|
||||
:check-boxes (= status "unpaid")
|
||||
:checked checked
|
||||
:on-check-changed (fn [which]
|
||||
(re-frame/dispatch [::toggle-check which]))
|
||||
:expense-event [::expense-accounts-dialog/change-expense-accounts]}]
|
||||
|
||||
(defn unpaid-invoices-page []
|
||||
[print-checks-modal]
|
||||
[new-invoice-modal]
|
||||
[edit-invoice-modal {:can-change-amount? (= status "unpaid")}]
|
||||
[handwrite-checks-modal]
|
||||
[change-expense-accounts-modal {:updated-event [::expense-accounts-updated]}]
|
||||
(when check-results-shown?
|
||||
(if pdf-url
|
||||
[modal
|
||||
{:title "Your checks are ready!"
|
||||
:hide-event [::close-check-results]}
|
||||
[:div "Click " [:a {:href pdf-url :target "_new"} "here"] " to print them."]
|
||||
[:div [:em "Remember to turn off all scaling and margins."]]
|
||||
]
|
||||
[modal
|
||||
{:title "Payment created!"
|
||||
:hide-event [::close-check-results]}
|
||||
[:div [:em "Your payment was created."]]
|
||||
]))
|
||||
|
||||
]))
|
||||
:component-will-mount #(re-frame/dispatch-sync [::params-change {:status status}]) }))
|
||||
|
||||
(defn unpaid-invoices-page [{:keys [status]}]
|
||||
[side-bar-layout {:side-bar [invoices-side-bar {}
|
||||
^{:key "extra-filter"}
|
||||
[:div
|
||||
@@ -791,10 +797,8 @@
|
||||
[:div [vendor-filter]]
|
||||
[:p.menu-label "Invoice #"]
|
||||
[:div
|
||||
[invoice-number-filter]
|
||||
]]
|
||||
]
|
||||
:main [unpaid-invoices-content]
|
||||
[invoice-number-filter]]]]
|
||||
:main [unpaid-invoices-content {:status status}]
|
||||
:bottom [vendor-dialog {:vendor @(re-frame/subscribe [::subs/user-editing-vendor])
|
||||
:save-event [::events/save-vendor]
|
||||
:change-event [::events/change-nested-form-state [:user-editing-vendor]] :id :auto-ap.views.main/user-editing-vendor}]}])
|
||||
|
||||
Reference in New Issue
Block a user