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