diff --git a/src/clj/auto_ap/square/core.clj b/src/clj/auto_ap/square/core.clj index 9bab40b9..ea245a60 100644 --- a/src/clj/auto_ap/square/core.clj +++ b/src/clj/auto_ap/square/core.clj @@ -238,7 +238,11 @@ :total (amount->money (:total_money settlement)) :client [:client/code client] :location loc - :fee (- (reduce + 0 (map (comp amount->money :fee_money) (:entries settlement)))) + :fee (- (reduce + 0 (map (fn [entry] + (if (= (:type entry) "REFUND") + (- (amount->money (:fee_money entry))) + (amount->money (:fee_money entry)))) + (:entries settlement)))) :date (-> (:initiated_at settlement) (coerce/to-date))}))))) diff --git a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs index 2c8f67f8..11b91250 100644 --- a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs +++ b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs @@ -25,7 +25,7 @@ [auto-ap.views.pages.invoices.common :refer [invoice-read]] [auto-ap.views.pages.invoices.form :as form] [auto-ap.views.pages.invoices.handwritten-checks :as handwritten-checks] - [auto-ap.views.utils :refer [dispatch-event with-user]] + [auto-ap.views.utils :refer [dispatch-event dispatch-event-with-propagation with-user]] [clojure.set :as set] [clojure.string :as str] [goog.string :as gstring] @@ -135,7 +135,8 @@ (defn pay-button [] (let [current-client @(re-frame/subscribe [::subs/client]) - checked-invoices (vals @(re-frame/subscribe [::data-page/checked :invoices]))] + checked-invoices (vals @(re-frame/subscribe [::data-page/checked :invoices])) + print-checks-status @(re-frame/subscribe [::status/single ::print-checks])] [:div [:div.is-pulled-right [:div.buttons @@ -146,10 +147,7 @@ (when current-client [drop-down {:header [:button.button.is-primary {:aria-haspopup true :on-click (dispatch-event [::events/toggle-menu ::print-checks ]) - :disabled (if (and (seq checked-invoices)) - "" - "disabled") - + :disabled (or (status/disabled-for print-checks-status) (not (seq checked-invoices))) :class (status/class-for @(re-frame/subscribe [::status/single ::print-checks]))} "Pay " (when (> (count checked-invoices )) @@ -169,15 +167,20 @@ (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 [::print-checks id :cash])} "With cash"] + ^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :cash]) + :disabled (status/disabled-for print-checks-status)} "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 (str id "-check")} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::print-checks id :check]) + :disabled (doto (status/disabled-for print-checks-status) println)} "Print checks from " name] + ^{:key (str id "-debit")} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::print-checks id :debit]) + :disabled (status/disabled-for print-checks-status)} "Debit from " name]))) ^{:key "advanced-divider"} [:hr.dropdown-divider] (when (= 1 (count (set (map (comp :id :vendor) checked-invoices)))) - ^{:key "handwritten"} [:a.dropdown-item {:on-click (dispatch-event [::handwritten-checks/show checked-invoices])} "Handwritten Check..."]) - ^{:key "advanced"} [:a.dropdown-item {:on-click (dispatch-event [::advanced-print-checks/show checked-invoices])} "Advanced..."])]])]] + ^{:key "handwritten"} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::handwritten-checks/show checked-invoices]) + :disabled (status/disabled-for print-checks-status)} "Handwritten Check..."]) + ^{:key "advanced"} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::advanced-print-checks/show checked-invoices]) + :disabled (status/disabled-for print-checks-status)} "Advanced..."])]])]] [:div.is-pulled-right {:style {:margin-right "0.5rem"}} (into [:div.tags ] (map (fn [{:keys [id invoice-number]}] [:span.tag.is-medium invoice-number