lots of improvements to editing invoices.
This commit is contained in:
@@ -354,6 +354,7 @@
|
||||
:edit_invoice
|
||||
{:fields {:id {:type :id}
|
||||
:invoice_number {:type 'String}
|
||||
:expense_accounts {:type '(list :edit_expense_account)}
|
||||
:date {:type 'String}
|
||||
:total {:type 'Float}}}}
|
||||
|
||||
|
||||
@@ -260,7 +260,11 @@
|
||||
(defmethod invoices->entities :payment-type/debit [invoices vendor client bank-account type index invoice-amounts]
|
||||
(let [payment (assoc (base-payment invoices vendor client bank-account type index invoice-amounts)
|
||||
:payment/type :payment-type/debit
|
||||
:payment/memo "Debit"
|
||||
:payment/memo (str "Debit Invoice #'s: "
|
||||
(str/join ", "
|
||||
(map (fn [i]
|
||||
(str (:invoice/invoice-number i) "(" (invoice-amounts (:db/id i)) ")"))
|
||||
invoices)))
|
||||
:payment/status :payment-status/cleared)]
|
||||
(-> []
|
||||
(conj payment)
|
||||
@@ -269,7 +273,11 @@
|
||||
(defmethod invoices->entities :payment-type/cash [invoices vendor client bank-account type index invoice-amounts]
|
||||
(let [payment (assoc (base-payment invoices vendor client bank-account type index invoice-amounts)
|
||||
:payment/type :payment-type/cash
|
||||
:payment/memo "Cash"
|
||||
:payment/memo (str "Cash Invoice #'s: "
|
||||
(str/join ", "
|
||||
(map (fn [i]
|
||||
(str (:invoice/invoice-number i) "(" (invoice-amounts (:db/id i)) ")"))
|
||||
invoices)))
|
||||
:payment/status :payment-status/cleared)]
|
||||
(-> []
|
||||
(conj payment)
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
(->graphql))))
|
||||
|
||||
|
||||
(defn edit-invoice [context {{:keys [id invoice_number total vendor_id date client_id] :as in} :invoice} value]
|
||||
(defn edit-invoice [context {{:keys [id invoice_number total vendor_id date client_id expense_accounts] :as in} :invoice} value]
|
||||
|
||||
|
||||
(let [invoice (d-invoices/get-by-id id)
|
||||
@@ -90,7 +90,11 @@
|
||||
:invoice/invoice-number invoice_number
|
||||
:invoice/date (coerce/to-date (parse date iso-date))
|
||||
:invoice/total total
|
||||
:invoice/outstanding-balance (- total paid-amount)})]
|
||||
:invoice/outstanding-balance (- total paid-amount)
|
||||
:invoice/expense-accounts (map (fn [ea]
|
||||
{:db/id (:id ea)
|
||||
:invoice-expense-account/amount (Double/parseDouble (:amount ea))})
|
||||
expense_accounts)})]
|
||||
(-> updated-invoice
|
||||
(->graphql))))
|
||||
|
||||
|
||||
@@ -96,7 +96,11 @@
|
||||
::modal-status
|
||||
(fn [db [_ id state]]
|
||||
(println "changing modal status" id "to")
|
||||
(update-in db [:modal-state id] #(merge % state))))
|
||||
(println (:auto-ap.forms/forms db))
|
||||
(-> db
|
||||
(update-in [:modal-state id] #(merge % state))
|
||||
(dissoc :auto-ap.forms/forms)
|
||||
)))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::modal-failed
|
||||
@@ -108,7 +112,10 @@
|
||||
(re-frame/reg-event-db
|
||||
::modal-completed
|
||||
(fn [db [_ id state]]
|
||||
(update-in db [:modal-state] #(dissoc % id))))
|
||||
(println (:auto-ap.forms/forms db))
|
||||
(-> db
|
||||
(update-in [:modal-state] #(dissoc % id))
|
||||
(dissoc :auto-ap.forms/forms))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::set-active-page
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
:location (:location ea)
|
||||
:expense-account-id (:expense-account-id ea)})
|
||||
expense-accounts)}
|
||||
[:id :total :outstanding-balance :invoice-number :date
|
||||
[:id :total :outstanding-balance :invoice-number :date :status
|
||||
[:vendor [:name :id]]
|
||||
[:expense_accounts [:amount :id :location :expense_account_id
|
||||
[:expense_account [:id :name [:parent [:id :name]]]]]]
|
||||
|
||||
@@ -190,8 +190,6 @@
|
||||
[clients-table]])])
|
||||
|
||||
|
||||
|
||||
|
||||
(defn bank-account-card [new-client {:keys [active? new? type visible code name number check-number id sort-order] :as bank-account} first? last?]
|
||||
(let [change-event [::forms/change ::new-client]]
|
||||
[:div.card {:style {:margin-bottom "1em"}}
|
||||
|
||||
@@ -112,6 +112,7 @@
|
||||
(fn [db _]
|
||||
(let [{:keys [checked invoices]} (get-in db [::invoice-page])]
|
||||
(-> db
|
||||
(forms/stop-form ::new-invoice)
|
||||
(update-in [::invoice-page :print-checks-shown?] #(not %) )
|
||||
(assoc-in [::advanced-print-checks] {:shown? true
|
||||
:bank-account-id (:id (first (:bank-accounts @(re-frame/subscribe [::subs/clients]))))
|
||||
@@ -130,6 +131,7 @@
|
||||
|
||||
{:dispatch [::events/modal-status ::handwrite-checks {:visible? true}]
|
||||
:db (-> db
|
||||
(forms/stop-form ::new-invoice)
|
||||
(update-in [::invoice-page :print-checks-shown?] #(not %) )
|
||||
(assoc-in [::handwrite-checks] {:bank-account-id (:id (first (:bank-accounts @(re-frame/subscribe [::subs/client]))))
|
||||
:amount (:outstanding-balance invoice)
|
||||
@@ -275,6 +277,7 @@
|
||||
:vendor-id (:id (:vendor edit-invoice))
|
||||
:vendor-name (:name (:vendor edit-invoice))
|
||||
:client-id (:id (:client edit-invoice))
|
||||
:expense-accounts (:expense-accounts edit-invoice)
|
||||
:client-name (:name (:client edit-invoice))})))))
|
||||
|
||||
|
||||
@@ -305,14 +308,17 @@
|
||||
(re-frame/reg-event-fx
|
||||
::edit-invoice-saving
|
||||
(fn [{:keys [db]} _]
|
||||
(let [{{:keys [date total invoice-number id]} :data} @(re-frame/subscribe [::forms/form ::new-invoice])]
|
||||
(let [{{:keys [date total invoice-number id expense-accounts]} :data} @(re-frame/subscribe [::forms/form ::new-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}}
|
||||
{:invoice {:id id :invoice-number invoice-number :date date :total total :expense-accounts (map (fn [ea]
|
||||
{:id (:id ea)
|
||||
:amount (:amount ea)})
|
||||
expense-accounts)}}
|
||||
invoice-read]}]}
|
||||
:on-success [::invoice-edited]
|
||||
:on-error [::forms/save-error ::new-invoice]}})))
|
||||
@@ -559,16 +565,18 @@
|
||||
(defn edit-invoice-form [{:keys [can-change-amount?]}]
|
||||
[forms/side-bar-form {:form ::new-invoice }
|
||||
(let [{:keys [data active? error]} @(re-frame/subscribe [::forms/form ::new-invoice])
|
||||
_ (println data)
|
||||
exists? (:id data)
|
||||
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])
|
||||
multi-location? (> (count locations) 1)
|
||||
|
||||
min-total (if (= (:total (:original data)) (:outstanding-balance (:original data)))
|
||||
nil
|
||||
(- (:total (:original data)) (:outstanding-balance (:original data))))
|
||||
should-select-location? (and locations
|
||||
(> (count locations) 1))]
|
||||
(> (count locations) 1))
|
||||
chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])]
|
||||
^{:key (or (:id data) "new")}
|
||||
[:form
|
||||
[:h1.title.is-2 "New Invoice"]
|
||||
@@ -646,14 +654,44 @@
|
||||
:subscription data
|
||||
:spec ::invoice/total
|
||||
:step "0.01"}]]]]]]
|
||||
|
||||
(when exists?
|
||||
[:div
|
||||
[:h2.subtitle "Expense Accounts"]
|
||||
|
||||
(for [[index {:keys [id location expense-account-id] :as expense-account}] (map vector (range) (:expense-accounts data))]
|
||||
^{:key id}
|
||||
[:div.columns
|
||||
[:div.column expense-account-id]
|
||||
|
||||
(when multi-location?
|
||||
[:div.column location])
|
||||
|
||||
[:div.column
|
||||
[:div.control
|
||||
[:div.field.has-addons.is-extended
|
||||
[:p.control [:a.button.is-static "$"]]
|
||||
[:p.control
|
||||
[bind-field
|
||||
[:input.input {:type "number"
|
||||
:field [:expense-accounts index :amount]
|
||||
:style {:text-align "right"}
|
||||
:event [::forms/change ::new-invoice]
|
||||
:subscription data
|
||||
:value (get-in expense-account [:amount])
|
||||
:max (:total data)
|
||||
:step "0.01"}]]]]]]])])
|
||||
|
||||
(when error
|
||||
[:div.notification.is-warning.animated.fadeInUp
|
||||
error])
|
||||
|
||||
|
||||
|
||||
[:submit.button.is-large.is-primary {:disabled (if (and (s/valid? ::invoice/invoice data)
|
||||
(or (not min-total) (>= (:total data) min-total)))
|
||||
(or (not min-total) (>= (:total data) min-total))
|
||||
(or (not exists?)
|
||||
(< (.abs js/Math (- (js/parseFloat (:total data)) (reduce + 0 (map (fn [ea] (js/parseFloat (:amount ea))) (:expense-accounts data))))) 0.001)))
|
||||
""
|
||||
"disabled")
|
||||
:on-click (fn [e]
|
||||
@@ -704,16 +742,9 @@
|
||||
(defn pay-button [{:keys [print-checks-shown? checked-invoices print-checks-loading?]}]
|
||||
(let [current-client @(re-frame/subscribe [::subs/client])]
|
||||
[:div
|
||||
|
||||
|
||||
|
||||
[:div.is-pulled-right
|
||||
|
||||
|
||||
[:div.buttons
|
||||
[:button.button.is-success {:on-click (dispatch-event [::new-invoice-clicked])} "New Invoice"]
|
||||
|
||||
|
||||
(when current-client
|
||||
[:div.dropdown.is-right {:class (if print-checks-shown?
|
||||
"is-active"
|
||||
@@ -746,8 +777,6 @@
|
||||
(reduce + 0)
|
||||
(gstring/format "$%.2f" ))
|
||||
")"))
|
||||
|
||||
|
||||
[:span " "]
|
||||
[:span.icon.is-small [:i.fa.fa-angle-down {:aria-hidden "true"}]]]]
|
||||
[:div.dropdown-menu {:role "menu"}
|
||||
|
||||
Reference in New Issue
Block a user