Now you can add manual checks.
This commit is contained in:
@@ -130,5 +130,9 @@
|
||||
^{:key (:id e)}
|
||||
[:a.tag {:on-click (dispatch-event (conj expense-event id))} (:name (:expense-account e)) " "(gstring/format "$%.2f" (:amount e) ) ])]
|
||||
[:td (for [check checks]
|
||||
^{:key (:id 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) ) ")")])]]))]]]))))
|
||||
(if (:s3-url (:check check))
|
||||
^{:key (:id 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) ) ")")]
|
||||
|
||||
^{:key (:id check)}
|
||||
[:span.tag [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " (:check-number (:check check)) " (" (gstring/format "$%.2f" (:amount check) ) ")")]))]]))]]]))))
|
||||
|
||||
@@ -121,7 +121,11 @@
|
||||
[:td check-number]
|
||||
[:td (date->str date) ]
|
||||
[:td (gstring/format "$%.2f" amount )]
|
||||
[:td [:a.tag {:href s3-url :target "_new"} [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " check-number " (" (gstring/format "$%.2f" amount ) ")")]]
|
||||
[:td
|
||||
(if s3-url
|
||||
[:a.tag {:href s3-url :target "_new"} [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " check-number " (" (gstring/format "$%.2f" amount ) ")")]
|
||||
[:span.tag [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " check-number " (" (gstring/format "$%.2f" amount ) ")")])
|
||||
]
|
||||
]))]]]))))
|
||||
|
||||
|
||||
|
||||
@@ -32,6 +32,11 @@
|
||||
(fn [db]
|
||||
(-> db ::advanced-print-checks)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::handwrite-checks
|
||||
(fn [db]
|
||||
(-> db ::handwrite-checks)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::change-expense-accounts
|
||||
(fn [db]
|
||||
@@ -96,6 +101,22 @@
|
||||
(filter (comp checked :id))
|
||||
(map #(assoc % :amount (:outstanding-balance %))))} )))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::handwrite-checks
|
||||
(fn [{:keys [db]} _]
|
||||
(let [{:keys [checked invoices]} (get-in db [::invoice-page])
|
||||
invoice (->> invoices
|
||||
(filter (comp checked :id))
|
||||
first)
|
||||
]
|
||||
|
||||
{:dispatch [::events/modal-status ::handwrite-checks {:visible? true}]
|
||||
:db (-> db
|
||||
(update-in [::invoice-page :print-checks-shown?] #(not %) )
|
||||
(assoc-in [::handwrite-checks] {:bank-account-id (:id (first (:bank-accounts @(re-frame/subscribe [::subs/company]))))
|
||||
:amount (:outstanding-balance invoice)
|
||||
:invoice invoice } ))})))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::cancel-advanced-print
|
||||
(fn [db _]
|
||||
@@ -221,6 +242,39 @@
|
||||
]]}]}
|
||||
:on-success [::invoice-created]}})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::handwrite-checks-save
|
||||
(fn [{:keys [db]} _]
|
||||
(let [{:keys [date invoice amount check-number bank-account-id]} @(re-frame/subscribe [::handwrite-checks])]
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "AddHandwrittenCheck"}
|
||||
|
||||
:venia/queries [{:query/data [:add-handwritten-check
|
||||
{:date date
|
||||
:amount amount
|
||||
:check-number check-number
|
||||
:bank-account-id bank-account-id
|
||||
:invoice_id (:id invoice)
|
||||
}
|
||||
[[:invoices [:id :outstanding-balance [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]]]]}]}
|
||||
:on-success [::handwrite-checks-succeeded]}})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::handwrite-checks-succeeded
|
||||
(fn [{:keys [db]} [_ {:keys [add-handwritten-check] :as result}]]
|
||||
(let [invoices-by-id (by :id (:invoices add-handwritten-check))]
|
||||
{:dispatch [::events/modal-completed ::handwrite-checks]
|
||||
:db (-> db
|
||||
(update-in [::invoice-page :invoices]
|
||||
(fn [invoices]
|
||||
(println invoices-by-id)
|
||||
(map (fn [i]
|
||||
(merge i (invoices-by-id (:id i))))
|
||||
invoices)))
|
||||
(dissoc ::handwrite-checks))})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invoice-created
|
||||
(fn [{:keys [db]} [_ {:keys [add-invoice]}]]
|
||||
@@ -411,6 +465,59 @@
|
||||
:max outstanding-balance
|
||||
:step "0.01"}]]]]]])]]])))
|
||||
|
||||
(defn handwrite-checks-modal []
|
||||
(let [{:keys [checked]} @(re-frame/subscribe [::invoice-page])
|
||||
{:keys [invoice] :as handwrite-checks} @(re-frame/subscribe [::handwrite-checks])
|
||||
change-event [::events/change-form [::handwrite-checks]]
|
||||
current-company @(re-frame/subscribe [::subs/company])]
|
||||
|
||||
[action-modal {:id ::handwrite-checks
|
||||
:title "Handwrite Check"
|
||||
:action-text "Save"
|
||||
:save-event [::handwrite-checks-save]
|
||||
#_#_:can-submit? (s/valid? ::invoice/invoice data)}
|
||||
[horizontal-field
|
||||
[:label.label "Pay using"]
|
||||
[:span.select
|
||||
[bind-field
|
||||
[:select {:type "select"
|
||||
:field :bank-account-id
|
||||
:event change-event
|
||||
:subscription handwrite-checks}
|
||||
(for [{:keys [id number name]} (:bank-accounts current-company)]
|
||||
^{:key id} [:option {:value id} name])]]]]
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Paid amount"]
|
||||
[:div.field.has-addons.is-extended
|
||||
[:p.control [:a.button.is-static "$"]]
|
||||
[:p.control
|
||||
[bind-field
|
||||
[:input.input {:type "number"
|
||||
:field [:amount]
|
||||
:event change-event
|
||||
:subscription handwrite-checks
|
||||
:spec ::invoice/total
|
||||
:step "0.01"}]]]]]
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Date"]
|
||||
[bind-field
|
||||
[:input.input {:type "date"
|
||||
:field [:date]
|
||||
:event change-event
|
||||
:spec ::invoice/date
|
||||
:subscription handwrite-checks}]]]
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Check number"]
|
||||
[bind-field
|
||||
[:input.input {:type "number"
|
||||
:field [:check-number]
|
||||
:event change-event
|
||||
#_#_:spec ::check/date
|
||||
:subscription handwrite-checks}]]]]))
|
||||
|
||||
|
||||
(defn new-invoice-modal []
|
||||
(let [data @(re-frame/subscribe [::new-invoice])
|
||||
@@ -502,14 +609,18 @@
|
||||
:class (if print-checks-loading?
|
||||
"is-loading"
|
||||
"")}
|
||||
"Print checks "
|
||||
"Pay "
|
||||
[:span " "]
|
||||
[:span.icon.is-small [:i.fa.fa-angle-down {:aria-hidden "true"}]]]]
|
||||
[:div.dropdown-menu {:role "menu"}
|
||||
[:div.dropdown-content
|
||||
(list
|
||||
(for [{:keys [id number name]} (:bank-accounts current-company)]
|
||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id])} name])
|
||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id])} "Print checks from " name])
|
||||
^{:key "advanced-divider"} [:hr.dropdown-divider]
|
||||
|
||||
(when (= 1 (count checked))
|
||||
^{:key "handwritten"} [:a.dropdown-item {:on-click (dispatch-event [::handwrite-checks])} "Handwritten Check..."])
|
||||
^{:key "advanced"} [:a.dropdown-item {:on-click (dispatch-event [::advanced-print-checks])} "Advanced..."])]]])]
|
||||
[invoice-table {:id :unpaid
|
||||
:params (re-frame/subscribe [::params])
|
||||
@@ -525,6 +636,7 @@
|
||||
|
||||
[print-checks-modal]
|
||||
[new-invoice-modal]
|
||||
[handwrite-checks-modal]
|
||||
[change-expense-accounts-modal]
|
||||
(when check-results-shown?
|
||||
[modal
|
||||
|
||||
Reference in New Issue
Block a user