You can now print and pay
This commit is contained in:
@@ -8,10 +8,18 @@
|
||||
(fn [db [_ x]]
|
||||
(-> db ::forms x)))
|
||||
|
||||
|
||||
(re-frame/reg-sub
|
||||
::is-loading?
|
||||
(fn [db [_ x]]
|
||||
(if (#{"loading" :loading} (get-in db [::forms x :status]) )
|
||||
true
|
||||
false)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::loading-class
|
||||
(fn [db [_ x]]
|
||||
(if (= (get-in db [::forms x :status]) "loading")
|
||||
(if (#{"loading" :loading} (get-in db [::forms x :status]) )
|
||||
"is-loading"
|
||||
"")))
|
||||
|
||||
@@ -54,3 +62,8 @@
|
||||
|
||||
(defn side-bar-form [{:keys [form]} children]
|
||||
[:div [:a.delete.is-pulled-right {:on-click (dispatch-event [::form-closing form])}] [:div children]])
|
||||
|
||||
(defn loading [db id]
|
||||
(-> db
|
||||
(assoc-in [::forms id :status] :loading)
|
||||
(assoc-in [::forms id :error] nil)))
|
||||
|
||||
@@ -13,14 +13,19 @@
|
||||
(fn [children]
|
||||
children)})))
|
||||
|
||||
(defn drop-down [{:keys [ header id]} child]
|
||||
(defn drop-down [{:keys [ header id is-right? class]} child]
|
||||
(let [menu-active? (re-frame/subscribe [::subs/menu-active? id])]
|
||||
(r/create-class
|
||||
{:reagent-render (fn [{:keys [header id]} child]
|
||||
{:reagent-render (fn [{:keys [header id is-right? class] :or {:is-right? true}} child]
|
||||
(let [menu-active? @(re-frame/subscribe [::subs/menu-active? id])]
|
||||
[:div.dropdown.is-right {:class (if menu-active?
|
||||
"is-active"
|
||||
"")}
|
||||
[:div.dropdown {:class (str (if menu-active?
|
||||
"is-active"
|
||||
"") " "
|
||||
(if is-right?
|
||||
"is-right"
|
||||
"")
|
||||
" "
|
||||
class)}
|
||||
[:div.dropdown-trigger header]
|
||||
|
||||
[appearing {:visible? menu-active? :enter-class "appear" :exit-class "disappear" :timeout 200}
|
||||
@@ -28,6 +33,5 @@
|
||||
[:div.dropdown-content
|
||||
(when menu-active?
|
||||
[drop-down-contents {:id id}
|
||||
child])]]]
|
||||
]))})))
|
||||
child])]]]]))})))
|
||||
|
||||
|
||||
@@ -289,9 +289,7 @@
|
||||
(fn [{:keys [db]} _]
|
||||
(when @(re-frame/subscribe [::can-submit-edit-invoice])
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::forms/form ::new-invoice])]
|
||||
{:db (-> db
|
||||
(assoc-in [::forms/forms ::new-invoice :status] :loading)
|
||||
(assoc-in [::forms/forms ::new-invoice :error] nil))
|
||||
{:db (forms/loading db ::new-invoice)
|
||||
:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
@@ -309,6 +307,31 @@
|
||||
:on-success [::invoice-created]
|
||||
:on-error [::forms/save-error ::new-invoice]}}))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::save-and-print-invoice
|
||||
(fn [{:keys [db]} [_ bank-account-id type ]]
|
||||
(println bank-account-id type)
|
||||
(when @(re-frame/subscribe [::can-submit-edit-invoice])
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::forms/form ::new-invoice])]
|
||||
{:db (forms/loading db ::new-invoice)
|
||||
:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "AddAndPrintInvoice"}
|
||||
|
||||
:venia/queries [{:query/data [:add-and-print-invoice
|
||||
{:invoice {:date (:date data)
|
||||
:vendor-id (:vendor-id data)
|
||||
:client-id (:client-id data)
|
||||
:invoice-number (:invoice-number data)
|
||||
:location (:location data)
|
||||
:total (:total data)}
|
||||
:bank-account-id bank-account-id
|
||||
:type type}
|
||||
[:pdf-url [:invoices invoice-read]]]}]}
|
||||
:on-success [::invoice-created-and-printed]
|
||||
:on-error [::forms/save-error ::new-invoice]}}))))
|
||||
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
@@ -407,6 +430,23 @@
|
||||
(into [(assoc add-invoice :class "live-added")]
|
||||
is))))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invoice-created-and-printed
|
||||
(fn [{:keys [db]} [_ {:keys [add-and-print-invoice]}]]
|
||||
{:db (-> db
|
||||
(forms/stop-form ::new-invoice)
|
||||
(forms/start-form ::new-invoice {:client-id (:id @(re-frame/subscribe [::subs/client]))
|
||||
:status :unpaid
|
||||
:date (date->str (c/now) standard)
|
||||
:location (first (:locations @(re-frame/subscribe [::subs/client])))})
|
||||
(update-in [::invoice-page :invoices]
|
||||
(fn [is]
|
||||
(into (vec (map #(assoc % :class "live-added")
|
||||
(:invoices add-and-print-invoice)))
|
||||
is)))
|
||||
(assoc-in [::check-results :shown?] true)
|
||||
(assoc-in [::check-results :pdf-url] (:pdf-url add-and-print-invoice)))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invoice-edited
|
||||
(fn [{:keys [db]} [_ {:keys [edit-invoice]}]]
|
||||
@@ -516,11 +556,12 @@
|
||||
(re-frame/reg-sub
|
||||
::can-submit-edit-invoice
|
||||
:<- [::forms/form ::new-invoice]
|
||||
(fn [{:keys [data]} _]
|
||||
(fn [{:keys [data status]} _]
|
||||
(let [min-total (if (= (:total (:original data)) (:outstanding-balance (:original data)))
|
||||
nil
|
||||
(- (:total (:original data)) (:outstanding-balance (:original data))))]
|
||||
(and (s/valid? ::invoice/invoice data)
|
||||
(and (not= :loading status)
|
||||
(s/valid? ::invoice/invoice data)
|
||||
(or (not min-total) (>= (:total data) min-total))
|
||||
(or (not (:id data))
|
||||
(< (.abs js/Math (- (js/parseFloat (:total data)) (reduce + 0 (map (fn [ea] (js/parseFloat (:amount ea))) (:expense-accounts data))))) 0.001))))))
|
||||
@@ -592,6 +633,7 @@
|
||||
[forms/side-bar-form {:form ::new-invoice }
|
||||
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::new-invoice])
|
||||
exists? (:id data)
|
||||
current-client @(re-frame/subscribe [::subs/client])
|
||||
can-change-amount? (#{:unpaid ":unpaid"} (:status data))
|
||||
change-event [::forms/change ::new-invoice]
|
||||
locations (get-in @(re-frame/subscribe [::subs/clients-by-id]) [(:client-id data) :locations])
|
||||
@@ -605,7 +647,6 @@
|
||||
chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])]
|
||||
^{:key id}
|
||||
[:form { :on-submit (fn [e]
|
||||
(println "x")
|
||||
(when (.-stopPropagation e)
|
||||
(.stopPropagation e)
|
||||
(.preventDefault e))
|
||||
@@ -720,13 +761,43 @@
|
||||
^{:key error} [:div.notification.is-warning.animated.fadeInUp
|
||||
error])
|
||||
|
||||
[:div.columns
|
||||
(when-not exists?
|
||||
[:div.column
|
||||
[drop-down {:header [:button.button.is-info.is-outlined.is-medium.is-fullwidth {:aria-haspopup true
|
||||
:type "button"
|
||||
:on-click (dispatch-event [::events/toggle-menu ::save-and-print-invoice ])
|
||||
:disabled (if @(re-frame/subscribe [::can-submit-edit-invoice])
|
||||
""
|
||||
"disabled")
|
||||
|
||||
:class (if false
|
||||
"is-loading"
|
||||
"")}
|
||||
"Save & Pay "
|
||||
[:span " "]
|
||||
[:span.icon.is-small [:i.fa.fa-angle-down {:aria-hidden "true"}]]]
|
||||
:class "is-fullwidth"
|
||||
:id ::save-and-print-invoice}
|
||||
[:div
|
||||
(list
|
||||
(for [{:keys [id number name type]} (->> (:bank-accounts current-client) (filter :visible) (sort-by :sort-order))]
|
||||
(if (= :cash type)
|
||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::save-and-print-invoice id :cash])} "With cash"]
|
||||
(list
|
||||
^{:key (str id "-check")} [:a.dropdown-item {:on-click (dispatch-event [::save-and-print-invoice id :check])} "Print checks from " name]
|
||||
^{:key (str id "-debit")} [:a.dropdown-item {:on-click (dispatch-event [::save-and-print-invoice id :debit])} "Debit from " name]))))]]])
|
||||
[:div.column
|
||||
[:button.button.is-medium.is-primary.is-fullwidth {:disabled (if (doto @(re-frame/subscribe [::can-submit-edit-invoice]) println)
|
||||
""
|
||||
"disabled")
|
||||
:class (str @(re-frame/subscribe [::forms/loading-class ::new-invoice])
|
||||
(when error " animated shake"))} "Save"]]
|
||||
|
||||
]
|
||||
|
||||
|
||||
[:button.button.is-large.is-primary {:disabled (if (doto @(re-frame/subscribe [::can-submit-edit-invoice]) println)
|
||||
""
|
||||
"disabled")
|
||||
:class (str @(re-frame/subscribe [::forms/loading-class ::new-invoice])
|
||||
(when error " animated shake"))} "Save"]])]
|
||||
])]
|
||||
)
|
||||
|
||||
|
||||
@@ -817,14 +888,29 @@
|
||||
(into [:div.tags {:style {:margin-right ".5 rem;"}}] (map (fn [[id invoice]] [:span.tag.is-medium (:invoice-number invoice) [:button.delete.is-small {:on-click (dispatch-event [::toggle-check id invoice])}]]) checked-invoices))]]
|
||||
))
|
||||
|
||||
(defn check-results-dialog []
|
||||
(let [{check-results-shown? :shown? pdf-url :pdf-url} @(re-frame/subscribe [::check-results])]
|
||||
(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."]]
|
||||
]))))
|
||||
|
||||
(defn unpaid-invoices-content [{:keys [status]}]
|
||||
(r/create-class {:display-name "unpaid-invoices-content"
|
||||
:component-will-unmount (fn [this]
|
||||
(re-frame/dispatch [::unmount-invoices]))
|
||||
: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])]
|
||||
current-client @(re-frame/subscribe [::subs/client])]
|
||||
[:div
|
||||
[:h1.title (str (str/capitalize status) " invoices")]
|
||||
|
||||
@@ -855,19 +941,7 @@
|
||||
[print-checks-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."]]
|
||||
]))
|
||||
|
||||
|
||||
]))
|
||||
:component-will-mount #(re-frame/dispatch-sync [::params-change {:status status}]) }))
|
||||
@@ -885,7 +959,8 @@
|
||||
[:div
|
||||
[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}]
|
||||
:bottom [:div [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}]
|
||||
[check-results-dialog]]
|
||||
:right-side-bar [appearing-side-bar {:visible? invoice-bar-active?} [edit-invoice-form]]}]))
|
||||
|
||||
@@ -166,4 +166,4 @@
|
||||
[css-transition-group {:in visible? :class-names {:exit exit-class :enter enter-class} :timeout timeout :onEnter (fn [] (reset! final-state true )) :onExited (fn [] (reset! final-state false))}
|
||||
(if (or @final-state visible?)
|
||||
(first children)
|
||||
[:div])])))
|
||||
[:span])])))
|
||||
|
||||
Reference in New Issue
Block a user