Almost finished with invoice page

This commit is contained in:
Bryce Covert
2020-08-16 21:59:41 -07:00
parent 3eae5fa52f
commit 85a110d878
4 changed files with 210 additions and 279 deletions

View File

@@ -10,8 +10,8 @@
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))
(re-frame/reg-sub (re-frame/reg-sub
::can-submit-advanced-print-checks ::can-submit
:<- [::forms/form ::advanced-print-checks] :<- [::forms/form ::form]
(fn [{ {:keys [invoices invoice-amounts]} :data}] (fn [{ {:keys [invoices invoice-amounts]} :data}]
(cond (seq (filter (cond (seq (filter
(fn [{:keys [id outstanding-balance]}] (fn [{:keys [id outstanding-balance]}]
@@ -22,15 +22,15 @@
:else :else
true))) true)))
(def advanced-print-checks-form (forms/vertical-form {:submit-event [::advanced-print-checks-submitted] (def advanced-print-checks-form (forms/vertical-form {:submit-event [::save]
:change-event [::forms/change ::advanced-print-checks] :change-event [::forms/change ::form]
:can-submit [::can-submit-advanced-print-checks] :can-submit [::can-submit]
:id ::advanced-print-checks})) :id ::form}))
(defn print-checks-modal [] (defn form []
(let [real-bank-accounts @(re-frame/subscribe [::subs/real-bank-accounts]) (let [real-bank-accounts @(re-frame/subscribe [::subs/real-bank-accounts])
{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::advanced-print-checks]) {:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::form])
{:keys [form-inline horizontal-field field raw-field error-notification submit-button]} advanced-print-checks-form] {:keys [form-inline horizontal-field field raw-field error-notification submit-button]} advanced-print-checks-form]
(form-inline {} (form-inline {}
@@ -71,16 +71,15 @@
::show ::show
(fn [{:keys [db]} [_ invoices]] (fn [{:keys [db]} [_ invoices]]
{:dispatch [::modal/modal-requested {:title "Print Checks" {:dispatch [::modal/modal-requested {:title "Print Checks"
:body [print-checks-modal] :body [form]
:confirm {:value "Print checks" :confirm {:value "Print checks"
:status-from [::status/single ::advanced-print-checks] :status-from [::status/single ::form]
:class "is-primary" :class "is-primary"
:on-click (dispatch-event [::advanced-print-checks-submitted]) :on-click (dispatch-event [::save])
:can-submit [::can-submit-advanced-print-checks] :can-submit [::can-submit]
:close-event [::status/completed ::advanced-print-checks]}}] :close-event [::status/completed ::form]}}]
:db (-> db :db (-> db
(forms/stop-form ::form/form) (forms/start-form ::form
(forms/start-form ::advanced-print-checks
{:bank-account-id (:id (first @(re-frame/subscribe [::subs/real-bank-accounts]))) {:bank-account-id (:id (first @(re-frame/subscribe [::subs/real-bank-accounts])))
:invoices invoices :invoices invoices
:invoice-amounts (into {} :invoice-amounts (into {}
@@ -90,48 +89,33 @@
(defn print-checks-query [invoice-payments bank-account-id type client-id]
{:venia/operation {:operation/type :mutation
:operation/name "PrintChecks"}
:venia/queries [[:print-checks
{:invoice_payments invoice-payments
:type type
:bank_account_id bank-account-id
:client_id client-id}
[[:invoices invoice-read]
:pdf_url]]]})
(re-frame/reg-event-fx (re-frame/reg-event-fx
::advanced-print-checks-submitted ::save
[with-user (forms/in-form ::advanced-print-checks) ] [with-user (forms/in-form ::form) ]
(fn [{:keys [db user]} [_ bank-account-id]] (fn [{:keys [db user]} [_ bank-account-id]]
(let [type (->> @(re-frame/subscribe [::subs/client]) (let [type (or (->> @(re-frame/subscribe [::subs/client])
:bank-accounts :bank-accounts
(filter #(= bank-account-id (:id %))) (filter #(= bank-account-id (:id %)))
first first
:type) :type)
:check)
{:keys [date invoices invoice-amounts check-number bank-account-id client]} (:data db)] {:keys [date invoices invoice-amounts check-number bank-account-id client]} (:data db)]
{:graphql {:graphql
{:token user {:token user
:owns-state {:single ::advanced-print-checks} :owns-state {:single ::form}
:query-obj (print-checks-query (map (fn [x] :query-obj {:venia/operation {:operation/type :mutation
:operation/name "PrintChecks"}
:venia/queries [[:print-checks
{:invoice_payments (map (fn [x]
{:invoice-id (:id x) {:invoice-id (:id x)
:amount (get-in invoice-amounts [(:id x) :amount])}) :amount (get-in invoice-amounts [(:id x) :amount])})
invoices) invoices)
bank-account-id :type type
(cond (= type :check) :bank_account_id bank-account-id
:check :client_id (->> invoices first :client :id)}
(= type :cash) [[:invoices invoice-read]
:cash :pdf_url]]]}
:else
:check)
(->> invoices first :client :id))
:on-success (fn [result] :on-success (fn [result]
[::checks-printed [::checks-printed
(:invoices (:print-checks result)) (:invoices (:print-checks result))

View File

@@ -176,18 +176,18 @@
(re-frame/reg-event-fx (re-frame/reg-event-fx
::add-and-print ::add-and-print
[with-user (forms/in-form ::form)] [with-user (forms/in-form ::form)]
(fn [{:keys [user] {:keys [data]} :db} [_ params bank-account-id type]] (fn [{:keys [user] {:keys [data]} :db} [_ bank-account-id type]]
{:graphql {:graphql
{:token user {:token user
:owns-state {:single ::form} :owns-state {:single ::form}
:query-obj @(re-frame/subscribe [::add-and-print-query bank-account-id type]) :query-obj @(re-frame/subscribe [::add-and-print-query bank-account-id type])
:on-success [::added-and-printed params] :on-success [::added-and-printed]
:on-error [::forms/save-error ::form]}})) :on-error [::forms/save-error ::form]}}))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::saving ::saving
[with-user (forms/in-form ::form)] [with-user (forms/in-form ::form)]
(fn [{:keys [user] {:keys [data]} :db} [_ params]] (fn [{:keys [user] {:keys [data]} :db} _]
(let [command (if (:id data) (let [command (if (:id data)
:edit :edit
:create)] :create)]
@@ -206,10 +206,15 @@
(re-frame/reg-event-fx (re-frame/reg-event-fx
::added-and-printed ::added-and-printed
(fn [{:keys [db]} [_ {:keys [invoice-printed]} result]] (fn [{:keys [db]} [_ result]]
(let [invoice (first (:invoices (:add-and-print-invoice result)))] (let [invoice (first (:invoices (:add-and-print-invoice result)))]
{:dispatch-n [[::updated (assoc invoice :class "live-added")] {:dispatch-n [[::updated (assoc invoice :class "live-added")]
(conj invoice-printed (:pdf-url (:add-and-print-invoice result)))]}))) [::checks-printed [invoice] (:pdf-url (:add-and-print-invoice result))]]})))
(re-frame/reg-event-db
::checks-printed
(fn [db [_ invoices pdf-url]]
db))
@@ -331,10 +336,10 @@
(list (list
(for [{:keys [id number name type]} (->> (:bank-accounts (:client data)) (filter :visible) (sort-by :sort-order))] (for [{:keys [id number name type]} (->> (:bank-accounts (:client data)) (filter :visible) (sort-by :sort-order))]
(if (= :cash type) (if (= :cash type)
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::add-and-print params id :cash])} "With cash"] ^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::add-and-print id :cash])} "With cash"]
(list (list
^{:key (str id "-check")} [:a.dropdown-item {:on-click (dispatch-event [::add-and-print params id :check])} "Print checks from " name] ^{:key (str id "-check")} [:a.dropdown-item {:on-click (dispatch-event [::add-and-print id :check])} "Print checks from " name]
^{:key (str id "-debit")} [:a.dropdown-item {:on-click (dispatch-event [::add-and-print params id :debit])} "Debit from " name]))))]]]) ^{:key (str id "-debit")} [:a.dropdown-item {:on-click (dispatch-event [::add-and-print id :debit])} "Debit from " name]))))]]])
[:div.column [:div.column
(submit-button "Save")]]]) (submit-button "Save")]]])

View File

@@ -0,0 +1,137 @@
(ns auto-ap.views.pages.invoices.handwritten-checks
(:require [auto-ap.entities.invoice :as invoice]
[auto-ap.forms :as forms]
[auto-ap.status :as status]
[auto-ap.subs :as subs]
[auto-ap.utils :refer [by]]
[auto-ap.views.components.modal :as modal]
[auto-ap.views.pages.data-page :as data-page]
[auto-ap.views.pages.invoices.common
:refer
[does-amount-exceed-outstanding? invoice-read]]
[auto-ap.views.pages.invoices.form :as form]
[auto-ap.views.utils
:refer
[date-picker dispatch-event horizontal-field with-user]]
[clojure.string :as str]
[re-frame.core :as re-frame]))
(def handwrite-checks-form (forms/vertical-form {:submit-event [::save]
:change-event [::forms/change ::form]
:can-submit [::can-submit]
:id ::form}))
(defn form []
(let [real-bank-accounts @(re-frame/subscribe [::subs/real-bank-accounts])
{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::form])
{:keys [form-inline horizontal-field field raw-field error-notification submit-button]} handwrite-checks-form]
(form-inline {}
[:<>
[:div.field
[:label.label "Pay using"]
[:div.control
[:span.select
[raw-field
[:select {:type "select"
:field :bank-account-id}
(for [{:keys [id number name]} real-bank-accounts]
^{:key id} [:option {:value id} name])]]]]]
(field "Date"
[date-picker {:class-name "input"
:class "input"
:format-week-number (fn [] "")
:previous-month-button-label ""
:placeholder "mm/dd/yyyy"
:next-month-button-label ""
:next-month-label ""
:type "date"
:field [:date]
:spec ::invoice/date}])
(field "Check number"
[:input.input {:type "number"
:field [:check-number]}])
[:table.table.is-fullwidth
[:thead
[:tr
[:th "Invoice ID"]
[:th {:style {"width" "14em"}} "Payment"]]]
[:tbody
(doall
(for [{:keys [payment outstanding-balance invoice-number id] :as i} (:invoices data)]
^{:key id}
[:tr
[:td invoice-number]
[:td [:div.field.has-addons.is-extended
[:p.control [:a.button.is-static "$"]]
[:p.control
(raw-field
[:input.input.has-text-right {:type "number"
:field [:invoice-amounts id :amount]
#_#_:max outstanding-balance
:step "0.01"}])]]]]))]]])))
(re-frame/reg-sub
::can-submit
:<- [::forms/form ::form]
(fn [{ {:keys [check-number date invoices invoice-amounts]} :data}]
(boolean (cond (seq (filter
(fn [{:keys [id outstanding-balance]}]
(does-amount-exceed-outstanding? (get-in invoice-amounts [id :amount]) outstanding-balance ))
invoices))
false
:else
(and (not (str/blank? check-number))
(not (str/blank? date)))))))
(re-frame/reg-event-fx
::show
(fn [{:keys [db]} [_ invoices]]
{:dispatch [::modal/modal-requested {:title "Handwrite checks"
:body [form]
:confirm {:value "Save handwritten check"
:status-from [::status/single ::form]
:class "is-primary"
:on-click (dispatch-event [::save])
:can-submit [::can-submit]
:close-event [::status/completed ::form]}}]
:db (-> db
(forms/start-form ::form
{:bank-account-id (:id (first @(re-frame/subscribe [::subs/real-bank-accounts])))
:invoices invoices
:invoice-amounts (into {}
(map (fn [i] [(:id i)
{:amount (:outstanding-balance i)}])
invoices))}))}))
(re-frame/reg-event-fx
::save
[with-user (forms/in-form ::form)]
(fn [{:keys [db user]} _]
(let [{:keys [date invoices invoice-amounts check-number bank-account-id]} (:data db)]
{:graphql
{:token user
:owns-state {:single ::form}
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "AddHandwrittenCheck"}
:venia/queries [{:query/data [:add-handwritten-check
{:date date
:invoice_payments (map (fn [x]
{:invoice-id (:id x)
:amount (get-in invoice-amounts [(:id x) :amount])})
invoices)
:check-number check-number
:bank-account-id bank-account-id}
[[:invoices invoice-read]]]}]}
:on-success (fn [result]
[::succeeded (:invoices (:add-handwritten-check result))])}})))
(re-frame/reg-event-fx
::succeeded
[(forms/triggers-stop ::form)]
(fn [{:keys [db]} [_ invoices]]
{:dispatch [::modal/modal-closed]}))

View File

@@ -22,9 +22,8 @@
[appearing-side-bar side-bar-layout]] [appearing-side-bar side-bar-layout]]
[auto-ap.views.components.modal :as modal :refer [modal]] [auto-ap.views.components.modal :as modal :refer [modal]]
[auto-ap.views.pages.data-page :as data-page] [auto-ap.views.pages.data-page :as data-page]
[auto-ap.views.pages.invoices.advanced-print-checks [auto-ap.views.pages.invoices.advanced-print-checks :as advanced-print-checks]
:as [auto-ap.views.pages.invoices.handwritten-checks :as handwritten-checks]
advanced-print-checks]
[auto-ap.views.pages.invoices.common :refer [invoice-read does-amount-exceed-outstanding?]] [auto-ap.views.pages.invoices.common :refer [invoice-read does-amount-exceed-outstanding?]]
[auto-ap.views.pages.invoices.form :as form] [auto-ap.views.pages.invoices.form :as form]
[auto-ap.views.utils [auto-ap.views.utils
@@ -37,28 +36,11 @@
[reagent.core :as r] [reagent.core :as r]
[vimsical.re-frame.fx.track :as track])) [vimsical.re-frame.fx.track :as track]))
(re-frame/reg-sub
::invoice-page
(fn [db]
(-> (::invoice-page db)
(update :invoices
(fn [is]
(mapv
(fn [i]
(assoc i :checkable? (not (:automatically-paid-when-due i))))
is))))))
(re-frame/reg-sub (re-frame/reg-sub
::change-expense-accounts ::change-expense-accounts
(fn [db] (fn [db]
(-> db ::change-expense-accounts))) (-> db ::change-expense-accounts)))
(re-frame/reg-sub
::check-results
(fn [db]
(-> db ::check-results)))
(re-frame/reg-sub (re-frame/reg-sub
::params ::params
:<- [::subs/client] :<- [::subs/client]
@@ -93,10 +75,10 @@
(re-frame/reg-event-fx (re-frame/reg-event-fx
::unmounted ::unmounted
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
{:db (dissoc db ::invoice-page ::table/table-params ::side-bar/filters ::side-bar/settled-filters ::last-params) {:db (dissoc db ::table/table-params ::side-bar/filters ::side-bar/settled-filters ::last-params)
:dispatch [::data-page/dispose :invoices] :dispatch [::data-page/dispose :invoices]
:forward-events [{:unregister ::updated} :forward-events [{:unregister ::updated}
{:unregister ::advanced-print-checks-printed}] {:unregister ::checks-printed}]
::track/dispose [{:id ::params}]})) ::track/dispose [{:id ::params}]}))
(re-frame/reg-event-fx (re-frame/reg-event-fx
@@ -109,9 +91,8 @@
:forward-events [{:register ::updated :forward-events [{:register ::updated
:events #{::table/invoice-updated ::form/updated} :events #{::table/invoice-updated ::form/updated}
:dispatch-to [::data-page/entity-updated :invoices]} :dispatch-to [::data-page/entity-updated :invoices]}
{:register ::checks-printed {:register ::checks-printed
:events #{::form/checks-printed ::advanced-print-checks/checks-printed} :events #{::form/checks-printed ::advanced-print-checks/checks-printed ::handwritten-checks/succeeded}
:dispatch-to [::checks-printed]}]})) :dispatch-to [::checks-printed]}]}))
@@ -127,7 +108,6 @@
(defn print-checks-query [invoice-payments bank-account-id type client-id] (defn print-checks-query [invoice-payments bank-account-id type client-id]
{:venia/operation {:operation/type :mutation {:venia/operation {:operation/type :mutation
:operation/name "PrintChecks"} :operation/name "PrintChecks"}
:venia/queries [[:print-checks :venia/queries [[:print-checks
{:invoice_payments invoice-payments {:invoice_payments invoice-payments
:type type :type type
@@ -139,9 +119,7 @@
(re-frame/reg-event-fx (re-frame/reg-event-fx
::print-checks ::print-checks
(fn [{:keys [db]} [_ bank-account-id type]] (fn [{:keys [db]} [_ bank-account-id type]]
{:db (-> db {:graphql
(assoc-in [::invoice-page :print-checks-shown?] false ))
:graphql
{:token (-> db :user) {:token (-> db :user)
:owns-state {:single ::print-checks} :owns-state {:single ::print-checks}
@@ -152,27 +130,26 @@
bank-account-id bank-account-id
type type
(:client db)) (:client db))
:on-success [::checks-created]}})) :on-success (fn [result]
[::checks-printed
[nil
(:invoices (:print-checks result))
(:pdf-url (:print-checks result))]])}}))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::checks-printed ::checks-printed
(fn [{:keys [db]} [_ [_ invoices pdf-url]]] (fn [{:keys [db]} [_ [_ invoices pdf-url]]]
(let [invoices-by-id (by :id invoices) ] {:dispatch-n (cond->> (mapv
{:db (-> db
(assoc-in [::check-results :shown?] true)
(assoc-in [::check-results :pdf-url] pdf-url))
:dispatch-n (mapv
(fn [i] (fn [i]
[::data-page/entity-updated :invoices [nil (assoc i :class "live-added")]]) [::data-page/entity-updated :invoices [nil (assoc i :class "live-added")]])
invoices)}))) invoices)
pdf-url (into [[::modal/modal-requested {:title "Your checks are ready!"
:body [:div
[:div "Click " [:a {:href pdf-url :target "_new"} "here"] " to print them."]
[:div [:em "Remember to turn off all scaling and margins."]]]}]]))}))
(re-frame/reg-event-db
::close-check-results
(fn [db _]
(assoc-in db [::check-results :shown?] false )))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::new-invoice-clicked ::new-invoice-clicked
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
@@ -181,171 +158,16 @@
#_#_:date (date->str (c/now) standard) #_#_:date (date->str (c/now) standard)
:location (first (:locations @(re-frame/subscribe [::subs/client])))}]})) :location (first (:locations @(re-frame/subscribe [::subs/client])))}]}))
(re-frame/reg-event-fx
::invoice-edited
[(re-frame/path [::invoice-page :invoices])]
(fn [{:keys [db]} [_ invoice]]
(let [invoice (assoc invoice :class "live-added")]
(let [by-id (by :id db )]
{:db (if (by-id (:id invoice))
(merge-by db :id invoice)
(into [invoice] db))}))))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::expense-accounts-updated ::expense-accounts-updated
(fn [{:keys [db]} [_ data]] (fn [{:keys [db]} [_ data]]
(let [updated (:edit-expense-accounts data)] (let [updated (:edit-expense-accounts data)]
{:dispatch [::events/modal-completed ::expense-accounts-dialog/change-expense-accounts] {:dispatch-n [[::events/modal-completed ::expense-accounts-dialog/change-expense-accounts]
[::data-page/entity-updated :invoices [nil updated]]]
:db (-> db :db (-> db
(update-in [::invoice-page :invoices]
(fn [is]
(replace-if #(= (:id %1) (:id %2)) updated is)))
(dissoc ::change-expense-accounts))}))) (dissoc ::change-expense-accounts))})))
;; HANDWRITE CHECKS
(def handwrite-checks-form (forms/vertical-form {:submit-event [::handwrite-checks-save]
:change-event [::forms/change ::handwrite-checks]
:can-submit [::can-submit-handwrite-checks]
:id ::handwrite-checks}))
(defn handwrite-checks-modal []
(let [{:keys [checked]} @(re-frame/subscribe [::invoice-page])
real-bank-accounts @(re-frame/subscribe [::subs/real-bank-accounts])
{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::handwrite-checks])
{:keys [form-inline horizontal-field field raw-field error-notification submit-button]} handwrite-checks-form]
(form-inline {}
[:<>
[:div.field
[:label.label "Pay using"]
[:div.control
[:span.select
[raw-field
[:select {:type "select"
:field :bank-account-id}
(for [{:keys [id number name]} real-bank-accounts]
^{:key id} [:option {:value id} name])]]]]]
(field "Date"
[date-picker {:class-name "input"
:class "input"
:format-week-number (fn [] "")
:previous-month-button-label ""
:placeholder "mm/dd/yyyy"
:next-month-button-label ""
:next-month-label ""
:type "date"
:field [:date]
:spec ::invoice/date}])
(field "Check number"
[:input.input {:type "number"
:field [:check-number]}])
[:table.table.is-fullwidth
[:thead
[:tr
[:th "Invoice ID"]
[:th {:style {"width" "14em"}} "Payment"]]]
[:tbody
(doall
(for [{:keys [payment outstanding-balance invoice-number id] :as i} (:invoices data)]
^{:key id}
[:tr
[:td invoice-number]
[:td [:div.field.has-addons.is-extended
[:p.control [:a.button.is-static "$"]]
[:p.control
(raw-field
[:input.input.has-text-right {:type "number"
:field [:invoice-amounts id :amount]
#_#_:max outstanding-balance
:step "0.01"}])]]]]))]]])))
(re-frame/reg-sub
::can-submit-handwrite-checks
:<- [::forms/form ::handwrite-checks]
(fn [{ {:keys [check-number date invoices invoice-amounts]} :data}]
(boolean (cond (seq (filter
(fn [{:keys [id outstanding-balance]}]
(does-amount-exceed-outstanding? (get-in invoice-amounts [id :amount]) outstanding-balance ))
invoices))
false
:else
(and (not (str/blank? check-number))
(not (str/blank? date)))))))
(re-frame/reg-event-fx
::handwrite-checks
(fn [{:keys [db]} _]
(let [invoices @(re-frame/subscribe [::checked-invoices])]
{:dispatch [::modal/modal-requested {::handwrite-checks {:visible? true}
:title "Handwrite checks"
:body [handwrite-checks-modal]
:confirm {:value "Save handwritten check"
:status-from [::status/single ::handwrite-checks]
:class "is-primary"
:on-click (dispatch-event [::handwrite-checks-save])
:can-submit [::can-submit-handwrite-checks]
:close-event [::status/completed ::form]}}]
:db (-> db
(forms/stop-form ::form/form)
(forms/start-form ::handwrite-checks
{:bank-account-id (:id (first @(re-frame/subscribe [::subs/real-bank-accounts])))
:invoices invoices
:invoice-amounts (into {}
(map (fn [i] [(:id i)
{:amount (:outstanding-balance i)}])
invoices))}))})))
(re-frame/reg-event-fx
::handwrite-checks-save
[with-user (forms/in-form ::handwrite-checks)]
(fn [{:keys [db user]} _]
(let [{:keys [date invoices invoice-amounts check-number bank-account-id]} (:data db)]
{:graphql
{:token user
:owns-state {:single ::handwrite-checks}
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "AddHandwrittenCheck"}
:venia/queries [{:query/data [:add-handwritten-check
{:date date
:invoice_payments (map (fn [x]
{:invoice-id (:id x)
:amount (get-in invoice-amounts [(:id x) :amount])})
invoices)
:check-number check-number
:bank-account-id bank-account-id}
[[:invoices invoice-read]]]}]}
:on-success [::handwrite-checks-succeeded]}})))
(re-frame/reg-event-fx
::handwrite-checks-succeeded
[(forms/triggers-stop ::handwrite-checks)]
(fn [{:keys [db]} [_ {:keys [add-handwritten-check] :as result}]]
(let [invoices-by-id (by :id (:invoices add-handwritten-check))]
{:dispatch-n (into [[::modal/modal-closed]]
(map
(fn [i]
[::data-page/entity-updated :invoices [_ (assoc i :class "live-added")]])
(:invoices add-handwritten-check)))})))
(defn pay-button [] (defn pay-button []
(let [current-client @(re-frame/subscribe [::subs/client]) (let [current-client @(re-frame/subscribe [::subs/client])
checked-invoices @(re-frame/subscribe [::checked-invoices])] checked-invoices @(re-frame/subscribe [::checked-invoices])]
@@ -386,7 +208,7 @@
^{:key "advanced-divider"} [:hr.dropdown-divider] ^{:key "advanced-divider"} [:hr.dropdown-divider]
(when (= 1 (count (set (map (comp :id :vendor) checked-invoices)))) (when (= 1 (count (set (map (comp :id :vendor) checked-invoices))))
^{:key "handwritten"} [:a.dropdown-item {:on-click (dispatch-event [::handwrite-checks])} "Handwritten Check..."]) ^{:key "handwritten"} [:a.dropdown-item {:on-click (dispatch-event [::handwritten-checks/show checked-invoices])} "Handwritten Check..."])
^{:key "advanced"} [:a.dropdown-item {:on-click (dispatch-event [::advanced-print-checks/show checked-invoices])} "Advanced..."])]])]] ^{:key "advanced"} [:a.dropdown-item {:on-click (dispatch-event [::advanced-print-checks/show checked-invoices])} "Advanced..."])]])]]
[:div.is-pulled-right {:style {:margin-right "0.5rem"}} [:div.is-pulled-right {:style {:margin-right "0.5rem"}}
(into [:div.tags ] (map (fn [{:keys [id invoice-number]}] (into [:div.tags ] (map (fn [{:keys [id invoice-number]}]
@@ -394,29 +216,13 @@
[:button.delete.is-small {:on-click [:button.delete.is-small {:on-click
(dispatch-event [::data-page/remove-check :invoices id])}]]) checked-invoices))]])) (dispatch-event [::data-page/remove-check :invoices id])}]]) checked-invoices))]]))
(defn check-results-dialog []
(let [{check-results-shown? :shown? pdf-url :pdf-url} @(re-frame/subscribe [::check-results])]
(when check-results-shown?
(if pdf-url
[modal
{:title "Your checks are ready!"
:hide-event [::close-check-results]}
[:div "Click " [:a {:href pdf-url :target "_new"} "here"] " to print them."]
[:div [:em "Remember to turn off all scaling and margins."]]
]
[modal
{:title "Payment created!"
:hide-event [::close-check-results]}
[:div [:em "Your payment was created."]]
]))))
(defn unpaid-invoices-content [{:keys [status] :as params}] (defn unpaid-invoices-content [{:keys [status] :as params}]
(let [page @(re-frame/subscribe [::data-page/page :invoices]) (let [page @(re-frame/subscribe [::data-page/page :invoices])
current-client @(re-frame/subscribe [::subs/client])] current-client @(re-frame/subscribe [::subs/client])]
[:div [:div
#_[:h1.title (str (str/capitalize (or status "all")) " invoices")] [:h1.title (str (str/capitalize (name (or status :all))) " invoices")]
[status/status-notification {:statuses [[::status/single ::print-checks]]}] [status/status-notification {:statuses [[::status/single ::print-checks]]}]
(when (= status :unpaid) (when (= status :unpaid)
[pay-button]) [pay-button])
[table/invoice-table {:id (:id page) [table/invoice-table {:id (:id page)
@@ -440,6 +246,5 @@
[side-bar-layout {:side-bar [invoices-side-bar {}] [side-bar-layout {:side-bar [invoices-side-bar {}]
:main [unpaid-invoices-content params] :main [unpaid-invoices-content params]
:bottom [:div :bottom [:div
[check-results-dialog]
[change-expense-accounts-modal {:updated-event [::expense-accounts-updated]}]] [change-expense-accounts-modal {:updated-event [::expense-accounts-updated]}]]
:right-side-bar [appearing-side-bar {:visible? invoice-bar-active?} [form/form {:invoice-printed [::checks-printed]}]]}]))})) :right-side-bar [appearing-side-bar {:visible? invoice-bar-active?} [form/form {}]]}]))}))