partial.
This commit is contained in:
@@ -3,10 +3,11 @@
|
||||
[auto-ap.entities.companies :as company]
|
||||
[auto-ap.entities.vendors :as vendor]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.views.utils :refer [dispatch-event]]
|
||||
[auto-ap.views.utils :refer [dispatch-event bind-field]]
|
||||
[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.views.components.modal :refer [modal]]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.events :as events]))
|
||||
|
||||
@@ -15,6 +16,12 @@
|
||||
(fn [db]
|
||||
(-> db ::invoice-page)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::advanced-print-checks
|
||||
(fn [db]
|
||||
(-> db ::advanced-print-checks)))
|
||||
|
||||
|
||||
(re-frame/reg-sub
|
||||
::params
|
||||
(fn [db]
|
||||
@@ -52,29 +59,86 @@
|
||||
(fn [db _]
|
||||
(update-in db [::invoice-page :print-checks-shown?] #(not %) )))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::advanced-print-checks
|
||||
(fn [db _]
|
||||
(let [{:keys [checked invoices]} (get-in db [::invoice-page])]
|
||||
(-> db
|
||||
(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/company]))))
|
||||
:invoices (->> invoices
|
||||
(filter (comp checked :id))
|
||||
(map #(assoc % :amount (:outstanding-balance %))))} )))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::cancel-advanced-print
|
||||
(fn [db _]
|
||||
(assoc-in db [::advanced-print-checks :shown?] false )))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::edit-payment-bank-account
|
||||
(fn [db [_ f v]]
|
||||
(assoc-in db [::advanced-print-checks :bank-account-id] v)))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::edit-payment
|
||||
(fn [db [_ which f v]]
|
||||
(update-in db [::advanced-print-checks :invoices]
|
||||
(fn [is]
|
||||
(for [i is]
|
||||
(if (= which (:id i))
|
||||
(assoc-in i f v)
|
||||
i))))))
|
||||
|
||||
(defn print-checks-query [invoice-payments bank-account-id company-id]
|
||||
{:venia/operation {:operation/type :mutation
|
||||
:operation/name "PrintChecks"}
|
||||
|
||||
:venia/queries [[:print-checks
|
||||
{:invoice_payments invoice-payments
|
||||
:bank_account_id bank-account-id
|
||||
:company_id company-id}
|
||||
[[:invoices [:id :outstanding-balance [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]]
|
||||
:pdf_url]]]})
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::print-checks
|
||||
(fn [{:keys [db]} [_ bank-account-id]]
|
||||
(let [invoice-amounts (by :id :total (get-in db [::invoice-page :invoices]))]
|
||||
{
|
||||
:db (-> db
|
||||
(let [invoice-amounts (by :id :outstanding-balance (get-in db [::invoice-page :invoices]))]
|
||||
|
||||
{:db (-> db
|
||||
(assoc-in [::invoice-page :print-checks-shown?] false )
|
||||
(assoc-in [::invoice-page :print-checks-loading?] true ))
|
||||
: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 :outstanding-balance [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]]
|
||||
:pdf_url]]]}
|
||||
:query-obj (print-checks-query (map (fn [id]
|
||||
{:invoice-id id
|
||||
:amount (invoice-amounts id)})
|
||||
(get-in db [::invoice-page :checked]))
|
||||
bank-account-id
|
||||
(:company db))
|
||||
:on-success [::checks-created]}})))
|
||||
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::advanced-print-checks-submitted
|
||||
(fn [{:keys [db]} [_ bank-account-id]]
|
||||
(let [invoice-amounts (by :id (comp js/parseFloat :amount) (get-in db [::advanced-print-checks :invoices]))
|
||||
bank-account-id (get-in db [::advanced-print-checks :bank-account-id])]
|
||||
{:db (-> db
|
||||
(assoc-in [::advanced-print-checks :printing?] true ))
|
||||
:graphql
|
||||
{:token (-> db :user)
|
||||
|
||||
:query-obj (print-checks-query (map (fn [x]
|
||||
{:invoice-id (:id x)
|
||||
:amount (invoice-amounts (:id x))})
|
||||
(get-in db [::advanced-print-checks :invoices]))
|
||||
bank-account-id
|
||||
(:company db))
|
||||
|
||||
:on-success [::checks-created]}})))
|
||||
|
||||
@@ -91,23 +155,74 @@
|
||||
(merge i (invoices-by-id (:id i))))
|
||||
invoices)))
|
||||
(assoc-in [::invoice-page :checked] nil)
|
||||
(assoc-in [::invoice-page :print-checks-loading?] false))})))
|
||||
(assoc-in [::invoice-page :print-checks-loading?] false)
|
||||
(assoc-in [::advanced-print-checks :printing?] false)
|
||||
(assoc-in [::advanced-print-checks :shown?] false)
|
||||
)})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invalidated
|
||||
(fn [cofx [_ params]]
|
||||
{:dispatch [::params-change @(re-frame/subscribe [::params])]}))
|
||||
|
||||
(defn modal-dialog []
|
||||
(let [{:keys [checked]} @(re-frame/subscribe [::invoice-page])
|
||||
{:keys [shown? invoices printing?] :as advanced-print-checks} @(re-frame/subscribe [::advanced-print-checks])
|
||||
current-company @(re-frame/subscribe [::subs/company])]
|
||||
|
||||
(when shown?
|
||||
[modal {:title "Print Checks"
|
||||
:foot [:button.button.is-primary {:on-click (dispatch-event [::advanced-print-checks-submitted])
|
||||
:class (if printing? "is-loading" "")}
|
||||
[:span "Print"]]
|
||||
:hide-event [::cancel-advanced-print]}
|
||||
"Print using"
|
||||
[:span.field
|
||||
[:span.select
|
||||
[bind-field
|
||||
|
||||
[:select {:type "select"
|
||||
:field :bank-account-id
|
||||
:event ::edit-payment-bank-account
|
||||
:subscription advanced-print-checks}
|
||||
(for [{:keys [id number name]} (:bank-accounts current-company)]
|
||||
^{:key id} [:option {:value id} name])]]]]
|
||||
|
||||
[:table.table
|
||||
[:thead
|
||||
[:tr
|
||||
[:th "Vendor"]
|
||||
[:th "Invoice ID"]
|
||||
[:th {:style {"width" "10em"}} "Payment"]]]
|
||||
[:tbody
|
||||
(for [{:keys [vendor payment outstanding-balance invoice-number id] :as i} invoices]
|
||||
^{:key id}
|
||||
[:tr
|
||||
[:td (:name vendor)]
|
||||
[:td invoice-number]
|
||||
|
||||
[:td [:div.field.has-addons.is-extended
|
||||
[:p.control [:a.button.is-static "$"]]
|
||||
[:p.control
|
||||
[bind-field
|
||||
[:input.input {:type "number"
|
||||
:field :amount
|
||||
:event [::edit-payment id]
|
||||
:subscription i
|
||||
:value payment
|
||||
:max outstanding-balance
|
||||
:step "0.01"}]]]]]])]]])))
|
||||
|
||||
(def unpaid-invoices-page
|
||||
(with-meta
|
||||
(fn []
|
||||
(let [{:keys [checked print-checks-shown? print-checks-loading?]} @(re-frame/subscribe [::invoice-page])
|
||||
(let [{:keys [checked print-checks-shown? print-checks-loading? advanced-print-shown?]} @(re-frame/subscribe [::invoice-page])
|
||||
current-company @(re-frame/subscribe [::subs/company])]
|
||||
[:div
|
||||
[:h1.title "Unpaid invoices"]
|
||||
[:div.is-pulled-right
|
||||
(when current-company
|
||||
[:div.dropdown {:class (if print-checks-shown?
|
||||
[:div.dropdown.is-right {:class (if print-checks-shown?
|
||||
"is-active"
|
||||
"")}
|
||||
[:div.dropdown-trigger
|
||||
@@ -119,15 +234,16 @@
|
||||
|
||||
:class (if print-checks-loading?
|
||||
"is-loading"
|
||||
"")
|
||||
}
|
||||
"")}
|
||||
"Print checks "
|
||||
[:span.icon.is-small [:i.fa.fa-angle-down {:aria-hidden "true"}]]]]
|
||||
[:div.dropdown-menu {:role "menu"}
|
||||
[:div.dropdown-content
|
||||
(for [{:keys [id number name]} (:bank-accounts current-company)]
|
||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id])} name])]]])]
|
||||
|
||||
(list
|
||||
(for [{:keys [id number name]} (:bank-accounts current-company)]
|
||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id])} name])
|
||||
^{:key "advanced-divider"} [:hr.dropdown-divider]
|
||||
^{:key "advanced"} [:a.dropdown-item {:on-click (dispatch-event [::advanced-print-checks])} "Advanced..."])]]])]
|
||||
[invoice-table {:id :unpaid
|
||||
:params (re-frame/subscribe [::params])
|
||||
:invoice-page (re-frame/subscribe [::invoice-page])
|
||||
@@ -137,5 +253,8 @@
|
||||
:check-boxes true
|
||||
:checked checked
|
||||
:on-check-changed (fn [which]
|
||||
(re-frame/dispatch [::toggle-check which]))}]]))
|
||||
(re-frame/dispatch [::toggle-check which]))}]
|
||||
|
||||
[modal-dialog]
|
||||
]))
|
||||
{:component-will-mount #(re-frame/dispatch-sync [::params-change {}]) }))
|
||||
|
||||
Reference in New Issue
Block a user