you can now edit invoices.
This commit is contained in:
@@ -55,7 +55,7 @@
|
||||
|
||||
|
||||
|
||||
(defn invoice-table [{:keys [id invoice-page status on-params-change vendors params check-boxes checked on-check-changed expense-event]}]
|
||||
(defn invoice-table [{:keys [id invoice-page status on-params-change vendors params check-boxes checked on-check-changed on-edit-invoice expense-event]}]
|
||||
(let [state (reagent/atom (or @params {}))
|
||||
visible-checks @(re-frame/subscribe [::visible-checks])
|
||||
visible-expense-accounts @(re-frame/subscribe [::visible-expense-accounts])
|
||||
@@ -182,6 +182,7 @@
|
||||
|
||||
[:a.dropdown-item.is-primary {:on-click (dispatch-event (conj expense-event id))} "Change"]]]])
|
||||
[:span {:style {:margin-left "1em"}}]
|
||||
[:button.button {:on-click (fn [] (on-edit-invoice i))} [:span [:span.icon [:i.fa.fa-pencil]] " Edit"]]
|
||||
(when (seq checks)
|
||||
|
||||
[:div.dropdown.is-right {:class (if (= id visible-checks)
|
||||
|
||||
@@ -53,6 +53,11 @@
|
||||
(fn [db]
|
||||
(-> db ::new-invoice)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::edit-invoice
|
||||
(fn [db]
|
||||
(-> db ::edit-invoice)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::params
|
||||
(fn [db]
|
||||
@@ -226,6 +231,14 @@
|
||||
:db (assoc-in db [::new-invoice] {:company-id (:id @(re-frame/subscribe [::subs/company]))
|
||||
:date (date->str (c/now) standard)})}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::edit-invoice
|
||||
(fn [{:keys [db]} [_ which]]
|
||||
(let [edit-invoice (update which :date #(date->str % standard))
|
||||
edit-invoice (assoc edit-invoice :original edit-invoice)]
|
||||
{:dispatch [::events/modal-status ::edit-invoice {:visible? true}]
|
||||
:db (assoc-in db [::edit-invoice] edit-invoice)})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::create-invoice
|
||||
(fn [{:keys [db]} _]
|
||||
@@ -246,6 +259,25 @@
|
||||
]]}]}
|
||||
:on-success [::invoice-created]}})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::edit-invoice-save
|
||||
(fn [{:keys [db]} _]
|
||||
(let [{:keys [date total invoice-number id]} @(re-frame/subscribe [::edit-invoice])]
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "EditInvoice"}
|
||||
|
||||
:venia/queries [{:query/data [:edit-invoice
|
||||
{:invoice {:id id :invoice-number invoice-number :date date :total total}}
|
||||
[:id :total :outstanding-balance :date :invoice-number
|
||||
[:company [:id :name :locations]]
|
||||
[:vendor [:id :name]]
|
||||
[:expense_accounts [:amount :id :expense_account_id
|
||||
:location
|
||||
[:expense_account [:id :name [:parent [:id :name]]]]]]]]}]}
|
||||
:on-success [::invoice-edited]}})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::handwrite-checks-save
|
||||
(fn [{:keys [db]} _]
|
||||
@@ -289,6 +321,19 @@
|
||||
is)))
|
||||
(dissoc ::new-invoice))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invoice-edited
|
||||
(fn [{:keys [db]} [_ {:keys [edit-invoice]}]]
|
||||
{:dispatch [::events/modal-completed ::edit-invoice]
|
||||
:db (-> db
|
||||
(update-in [::invoice-page :invoices]
|
||||
(fn [is]
|
||||
(mapv (fn [i]
|
||||
(if (= (:id i) (:id edit-invoice))
|
||||
(assoc edit-invoice :class "live-added")
|
||||
i)) is)))
|
||||
(dissoc ::edit-invoice))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::change-expense-accounts
|
||||
(fn [{:keys [db]} [_ id]]
|
||||
@@ -612,6 +657,58 @@
|
||||
:step "0.01"}]]]]]
|
||||
]))
|
||||
|
||||
(defn edit-invoice-modal []
|
||||
(let [data @(re-frame/subscribe [::edit-invoice])
|
||||
change-event [::events/change-form [::edit-invoice]]
|
||||
locations (get-in @(re-frame/subscribe [::subs/companies-by-id]) [(:company-id data) :locations])
|
||||
min-total (- (:total (:original data)) (:outstanding-balance (:original data)))
|
||||
|
||||
should-select-location? (and locations
|
||||
(> (count locations) 1))]
|
||||
[action-modal {:id ::edit-invoice
|
||||
:title "Update Invoice"
|
||||
:action-text "Save"
|
||||
:save-event [::edit-invoice-save]
|
||||
:can-submit? (and #_(s/valid? ::invoice/invoice data)
|
||||
(>= (:total data) min-total))}
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Date"]
|
||||
|
||||
|
||||
[bind-field
|
||||
[:input.input {:type "date"
|
||||
:field [:date]
|
||||
:event change-event
|
||||
:spec ::invoice/date
|
||||
:subscription data}]]]
|
||||
|
||||
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Invoice #"]
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field [:invoice-number]
|
||||
:event change-event
|
||||
:spec ::invoice/invoice-number
|
||||
:subscription data}]]]
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Total"]
|
||||
[:div.field.has-addons.is-extended
|
||||
[:p.control [:a.button.is-static "$"]]
|
||||
[:p.control
|
||||
[bind-field
|
||||
[:input.input {:type "number"
|
||||
:field [:total]
|
||||
:event change-event
|
||||
:min min-total
|
||||
:subscription data
|
||||
:spec ::invoice/total
|
||||
:step "0.01"}]]]]]
|
||||
]))
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -656,6 +753,8 @@
|
||||
: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]))
|
||||
:on-params-change (fn [params]
|
||||
(re-frame/dispatch [::params-change params]))
|
||||
:check-boxes true
|
||||
@@ -666,6 +765,7 @@
|
||||
|
||||
[print-checks-modal]
|
||||
[new-invoice-modal]
|
||||
[edit-invoice-modal]
|
||||
[handwrite-checks-modal]
|
||||
[change-expense-accounts-modal]
|
||||
(when check-results-shown?
|
||||
|
||||
Reference in New Issue
Block a user