adding invoices works correctly again.
This commit is contained in:
@@ -17,9 +17,9 @@
|
||||
|
||||
|
||||
(re-frame/reg-sub
|
||||
::check-page
|
||||
::payment-page
|
||||
(fn [db]
|
||||
(-> db ::check-page)))
|
||||
(-> db ::payment-page)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::params
|
||||
@@ -44,33 +44,33 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::void-check
|
||||
(fn [{:keys [db]} [_ check]]
|
||||
(fn [{:keys [db]} [_ payment]]
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "VoidCheck"}
|
||||
:operation/name "VoidPayment"}
|
||||
|
||||
:venia/queries [{:query/data [:void-check
|
||||
{:payment-id (:id check)}
|
||||
:venia/queries [{:query/data [:void-payment
|
||||
{:payment-id (:id payment)}
|
||||
[:id :status :amount :check_number :s3_url :date [:vendor [:name :id]] [:client [:name :id]]]]}]}
|
||||
:on-success [::check-voided]}}))
|
||||
:on-success [::payment-voided]}}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::check-voided
|
||||
(fn [db [_ {:keys [void-check]}]]
|
||||
::payment-voided
|
||||
(fn [db [_ {:keys [void-payment]}]]
|
||||
(-> db
|
||||
(update-in [::check-page :payments] (fn [checks]
|
||||
(update-in [::payment-page :payments] (fn [payments]
|
||||
(mapv (fn [c]
|
||||
(if (= (:id c) (:id void-check))
|
||||
(assoc void-check :class "live-removed")
|
||||
(if (= (:id c) (:id void-payment))
|
||||
(assoc void-payment :class "live-removed")
|
||||
c))
|
||||
checks))))))
|
||||
payments))))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received
|
||||
(fn [db [_ data]]
|
||||
(-> db
|
||||
(assoc ::check-page (first (:payment-page data)))
|
||||
(assoc ::payment-page (first (:payment-page data)))
|
||||
(assoc-in [:status :loading] false))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
@@ -78,15 +78,15 @@
|
||||
(fn [cofx [_ params]]
|
||||
{:dispatch [::params-change @(re-frame/subscribe [::params])]}))
|
||||
|
||||
(defn check-table [{:keys [id check-page status on-params-change vendors params check-boxes checked on-check-changed expense-event]}]
|
||||
(defn check-table [{:keys [id payment-page status on-params-change vendors params check-boxes checked on-check-changed expense-event]}]
|
||||
(let [state (reagent/atom (or @params {}))
|
||||
selected-company @(re-frame/subscribe [::subs/company])
|
||||
opc (fn [p]
|
||||
(swap! state merge p)
|
||||
(on-params-change p))]
|
||||
(fn [{:keys [id check-page status on-params-change vendors checked]}]
|
||||
(fn [{:keys [id payment-page status on-params-change vendors checked]}]
|
||||
(let [{:keys [sort-by asc]} @state
|
||||
{:keys [payments start end count total]} @check-page
|
||||
{:keys [payments start end count total]} @payment-page
|
||||
selected-company @(re-frame/subscribe [::subs/company])
|
||||
percentage-size (if selected-company "50%" "33%")]
|
||||
[:div
|
||||
@@ -147,7 +147,7 @@
|
||||
[:tr
|
||||
[:td {:col-span 5}
|
||||
[:i.fa.fa-spin.fa-spinner]]]
|
||||
(for [{:keys [client s3-url payments type check-number date amount id vendor status] :as i} (:payments @check-page)]
|
||||
(for [{:keys [client s3-url payments type check-number date amount id vendor status] :as i} (:payments @payment-page)]
|
||||
^{:key id}
|
||||
[:tr {:class (:class i)}
|
||||
|
||||
@@ -179,9 +179,9 @@
|
||||
(let [current-company @(re-frame/subscribe [::subs/company])]
|
||||
[:div
|
||||
[:h1.title "Checks"]
|
||||
[check-table {:id :checks
|
||||
[check-table {:id :payments
|
||||
:params (re-frame/subscribe [::params])
|
||||
:check-page (re-frame/subscribe [::check-page])
|
||||
:payment-page (re-frame/subscribe [::payment-page])
|
||||
:status (re-frame/subscribe [::subs/status])
|
||||
:on-params-change (fn [params]
|
||||
(re-frame/dispatch [::params-change params]))}]]))
|
||||
|
||||
@@ -237,7 +237,7 @@
|
||||
::new-invoice
|
||||
(fn [{:keys [db]} _]
|
||||
{:dispatch [::events/modal-status ::new-invoice {:visible? true}]
|
||||
:db (assoc-in db [::new-invoice] {:company-id (:id @(re-frame/subscribe [::subs/company]))
|
||||
:db (assoc-in db [::new-invoice] {:client-id (:id @(re-frame/subscribe [::subs/company]))
|
||||
:date (date->str (c/now) standard)
|
||||
:location (first (:locations @(re-frame/subscribe [::subs/company])))})}))
|
||||
|
||||
@@ -261,7 +261,7 @@
|
||||
:venia/queries [{:query/data [:add-invoice
|
||||
{:invoice new-invoice}
|
||||
[:id :total :outstanding-balance :date :invoice-number
|
||||
[:company [:id :name :locations]]
|
||||
[:client [:id :name :locations]]
|
||||
[:vendor [:id :name]]
|
||||
[:expense_accounts [:amount :id :expense_account_id
|
||||
:location
|
||||
@@ -645,7 +645,7 @@
|
||||
(defn new-invoice-modal []
|
||||
(let [data @(re-frame/subscribe [::new-invoice])
|
||||
change-event [::events/change-form [::new-invoice]]
|
||||
locations (get-in @(re-frame/subscribe [::subs/companies-by-id]) [(:company-id data) :locations])
|
||||
locations (get-in @(re-frame/subscribe [::subs/companies-by-id]) [(:client-id data) :locations])
|
||||
should-select-location? (and locations
|
||||
(> (count locations) 1))]
|
||||
[action-modal {:id ::new-invoice
|
||||
@@ -656,13 +656,13 @@
|
||||
|
||||
(when-not @(re-frame/subscribe [::subs/company])
|
||||
[horizontal-field
|
||||
[:label.label "Company"]
|
||||
[:label.label "Client"]
|
||||
[bind-field
|
||||
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/companies]))
|
||||
:type "typeahead"
|
||||
:field [:company-id]
|
||||
:field [:client-id]
|
||||
:event [::change-new-invoice-company [::new-invoice]]
|
||||
:spec ::invoice/company-id
|
||||
:spec ::invoice/client-id
|
||||
:subscription data}]]])
|
||||
(when should-select-location?
|
||||
[horizontal-field
|
||||
|
||||
Reference in New Issue
Block a user