refactoring to support grouping simply.

This commit is contained in:
Bryce Covert
2018-05-14 13:33:04 -07:00
parent 431645ad42
commit d9994b988c
7 changed files with 59 additions and 37 deletions

View File

@@ -21,7 +21,7 @@
:user token)
:graphql {:token token
:query-obj {:venia/queries [[:company
[:id :name [:bank-accounts [:id :number :check-number]]]]]}
[:id :name [:bank-accounts [:id :number :check-number :name]]]]]}
:on-success [::received-companies]}}))))

View File

@@ -13,7 +13,6 @@
;; TODO partial payments
;; TODO invoice status = paid when complete
;; TODO performance
;; TODO psql transactions
;; TODO refactor graphql
@@ -102,4 +101,4 @@
[:td (gstring/format "$%.2f" total )]
[:td (for [check checks]
^{:key (:id check)}
[:a.tag {:href (:s3-url (:check check)) :target "_new"} [:i.fa.fa-money-check] (str " " (:check-number (:check check)) " (" (gstring/format "$%.2f" (:amount check) ) ")")])]]))]]]))))
[:a.tag {:href (:s3-url (:check check)) :target "_new"} [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " (:check-number (:check check)) " (" (gstring/format "$%.2f" (:amount check) ) ")")])]]))]]]))))

View File

@@ -4,6 +4,7 @@
[auto-ap.entities.vendors :as vendor]
[auto-ap.events :as events]
[auto-ap.views.utils :refer [dispatch-event]]
[auto-ap.utils :refer [by]]
[auto-ap.views.pages.check :as check]
[auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table]
[auto-ap.subs :as subs]
@@ -54,32 +55,32 @@
(re-frame/reg-event-fx
::print-checks
(fn [{:keys [db]} [_ bank-account-id]]
{
:db (assoc-in db [::invoice-page :print-checks-shown?] false )
:graphql
{:token (-> db :user)
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "PrintChecks"}
:venia/queries [[:print-checks
{:invoice_ids (vec (get-in db [::invoice-page :checked]))
:bank_account_id bank-account-id
:company_id (:company db)}
[[:invoices [:id [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]]
:pdf_url]]]}
(let [invoice-amounts (by :id :total (get-in db [::invoice-page :invoices]))]
{
:db (assoc-in db [::invoice-page :print-checks-shown?] false )
:graphql
{:token (-> db :user)
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "PrintChecks"}
:venia/queries [[:print-checks
{:invoice_payments (map (fn [id]
{:invoice-id id
:amount (invoice-amounts id)})
(get-in db [::invoice-page :checked]))
:bank_account_id bank-account-id
:company_id (:company db)}
[[:invoices [:id [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]]
:pdf_url]]]}
:on-success [::checks-created]}}))
:on-success [::checks-created]}})))
(re-frame/reg-event-fx
::checks-created
(fn [{:keys [db]} [_ data]]
(let [{{:keys [pdf-url invoices]} :print-checks} data
invoices-by-id (reduce
(fn [x a]
(assoc x (:id a) a))
{}
invoices)]
invoices-by-id (by :id invoices) ]
{:new-window pdf-url
:db (-> db
(update-in [::invoice-page :invoices]
@@ -116,8 +117,8 @@
[:span.icon.is-small [:i.fa.fa-angle-down {:aria-hidden "true"}]]]]
[:div.dropdown-menu {:role "menu"}
[:div.dropdown-content
(for [{:keys [id number]} (:bank-accounts current-company)]
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id])} number])]]])]
(for [{:keys [id number name]} (:bank-accounts current-company)]
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id])} name])]]])]
[invoice-table {:id :unpaid
:params (re-frame/subscribe [::params])