switched from auto pay to scheduled payment
This commit is contained in:
@@ -40,7 +40,7 @@
|
||||
:unpaid-invoices :unpaid
|
||||
:paid-invoices :paid
|
||||
:voided-invoices :voided)}
|
||||
[[:invoices [:id :total :outstanding-balance :invoice-number :date :due :status :client-identifier :automatically-paid-when-due
|
||||
[[:invoices [:id :total :outstanding-balance :invoice-number :date :due :status :client-identifier :scheduled-payment
|
||||
[:vendor [:name :id]]
|
||||
[:expense_accounts [:amount :id :location
|
||||
[:account [:id ]]]]
|
||||
|
||||
6
src/cljs/auto_ap/views/components/switch-field.cljs
Normal file
6
src/cljs/auto_ap/views/components/switch-field.cljs
Normal file
@@ -0,0 +1,6 @@
|
||||
(ns auto-ap.views.components.switch-field)
|
||||
|
||||
(defn switch-field [{:keys [id label on-change checked]}]
|
||||
[:<>
|
||||
[:input.switch {:type "checkbox" :id id :on-change on-change :checked checked}]
|
||||
[:label {:for id} label]])
|
||||
@@ -13,7 +13,7 @@
|
||||
(>= amount 0)))))
|
||||
|
||||
(def invoice-read [:id :total :outstanding-balance :date :due :invoice-number :status
|
||||
:automatically-paid-when-due
|
||||
:scheduled-payment
|
||||
[:client [:id :name :locations]]
|
||||
[:payments [:amount [:payment [:amount :s3_url :check_number ]]]]
|
||||
[:vendor [:id :name]]
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
[auto-ap.views.components.expense-accounts-field :as expense-accounts-field :refer [expense-accounts-field recalculate-amounts]]
|
||||
[auto-ap.views.components.layouts :as layouts]
|
||||
[auto-ap.views.components.money-field :refer [money-field]]
|
||||
[auto-ap.views.components.switch-field :refer [switch-field]]
|
||||
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
|
||||
[auto-ap.views.pages.invoices.common :refer [invoice-read]]
|
||||
[auto-ap.status :as status]
|
||||
@@ -35,7 +36,7 @@
|
||||
(re-frame/reg-sub
|
||||
::create-query
|
||||
:<- [::forms/form ::form]
|
||||
(fn [{:keys [data] {:keys [id invoice-number date due location total expense-accounts automatically-paid-when-due vendor client]} :data}]
|
||||
(fn [{:keys [data] {:keys [id invoice-number date due scheduled-payment location total expense-accounts vendor client]} :data}]
|
||||
{:venia/operation {:operation/type :mutation
|
||||
:operation/name "AddInvoice"}
|
||||
:venia/queries [{:query/data [:add-invoice
|
||||
@@ -43,7 +44,7 @@
|
||||
:due due
|
||||
:vendor-id (:id vendor)
|
||||
:client-id (:id client)
|
||||
:automatically-paid-when-due automatically-paid-when-due
|
||||
:scheduled-payment scheduled-payment
|
||||
:invoice-number invoice-number
|
||||
:location location
|
||||
:total total
|
||||
@@ -59,14 +60,14 @@
|
||||
(re-frame/reg-sub
|
||||
::edit-query
|
||||
:<- [::forms/form ::form]
|
||||
(fn [{:keys [data] {:keys [id invoice-number date due location total expense-accounts vendor automatically-paid-when-due client]} :data}]
|
||||
(fn [{:keys [data] {:keys [id invoice-number date due scheduled-payment location total expense-accounts vendor client]} :data}]
|
||||
{:venia/operation {:operation/type :mutation
|
||||
:operation/name "EditInvoice"}
|
||||
:venia/queries [{:query/data [:edit-invoice
|
||||
{:invoice {:id id
|
||||
:invoice-number invoice-number
|
||||
:date date
|
||||
:automatically-paid-when-due automatically-paid-when-due
|
||||
:scheduled-payment scheduled-payment
|
||||
:due due
|
||||
:total total
|
||||
:expense-accounts (map (fn [ea]
|
||||
@@ -81,14 +82,14 @@
|
||||
(re-frame/reg-sub
|
||||
::add-and-print-query
|
||||
(fn [db [_ bank-account-id type]]
|
||||
(let [{:keys [data] {:keys [id invoice-number date location total expense-accounts automatically-paid-when-due vendor client]} :data} @(re-frame/subscribe [::forms/form ::form])]
|
||||
(let [{:keys [data] {:keys [id invoice-number date location total expense-accounts scheduled-payment vendor client]} :data} @(re-frame/subscribe [::forms/form ::form])]
|
||||
{:venia/operation {:operation/type :mutation
|
||||
:operation/name "AddAndPrintInvoice"}
|
||||
:venia/queries [{:query/data [:add-and-print-invoice
|
||||
{:invoice {:date date
|
||||
:vendor-id (:id vendor)
|
||||
:client-id (:id client)
|
||||
:automatically-paid-when-due automatically-paid-when-due
|
||||
:scheduled-payment scheduled-payment
|
||||
:invoice-number invoice-number
|
||||
:location location
|
||||
:total total
|
||||
@@ -134,14 +135,16 @@
|
||||
(let [accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id (:client which)])
|
||||
edit-invoice (update which :date #(date->str % standard))
|
||||
edit-invoice (update edit-invoice :due #(date->str % standard))
|
||||
edit-invoice (update edit-invoice :scheduled-payment #(date->str % standard))
|
||||
edit-invoice (assoc edit-invoice :original edit-invoice)
|
||||
locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client which))])]
|
||||
locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client which))])
|
||||
]
|
||||
(-> db
|
||||
(forms/start-form ::form {:id (:id edit-invoice)
|
||||
:status (:status edit-invoice)
|
||||
:date (:date edit-invoice)
|
||||
:due (:due edit-invoice)
|
||||
:automatically-paid-when-due (:automatically-paid-when-due edit-invoice)
|
||||
:scheduled-payment (:scheduled-payment edit-invoice)
|
||||
:invoice-number (:invoice-number edit-invoice)
|
||||
:total (:total edit-invoice)
|
||||
:original edit-invoice
|
||||
@@ -168,14 +171,28 @@
|
||||
locations)])
|
||||
|
||||
|
||||
true
|
||||
(into [[:automatically-paid-when-due] (boolean ((set (map :id (:automatically-paid-when-due value))) (:id (:client data))))]))
|
||||
(boolean ((set (map :id (:automatically-paid-when-due value))) (:id (:client data))))
|
||||
(into [[:scheduled-payment] (:due data)
|
||||
[:schedule-when-due] true]))
|
||||
|
||||
(= [:total] field)
|
||||
[[:expense-accounts] (recalculate-amounts (:expense-accounts data) value)]
|
||||
|
||||
(and (= [:schedule-when-due] field) value)
|
||||
[[:scheduled-payment] (:due data)]
|
||||
|
||||
(and (= [:due] field) (:schedule-when-due data))
|
||||
[[:scheduled-payment] value]
|
||||
|
||||
:else
|
||||
[])))))
|
||||
(re-frame/reg-event-db
|
||||
::maybe-change-client
|
||||
[ (forms/in-form ::form)]
|
||||
(fn [{:keys [data] :as f} [_ c]]
|
||||
(if (:id data)
|
||||
f
|
||||
(assoc-in f [:data :client] c))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::add-and-print
|
||||
@@ -236,7 +253,8 @@
|
||||
{::track/register [{:id ::client
|
||||
:subscription [::subs/client]
|
||||
:event-fn (fn [c]
|
||||
[::changed [:client] c])}]}))
|
||||
|
||||
[::maybe-change-client c])}]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted
|
||||
@@ -302,13 +320,29 @@
|
||||
:field [:due]
|
||||
:spec ::invoice/due}])
|
||||
|
||||
[:div.field
|
||||
[:label.checkbox
|
||||
(raw-field
|
||||
[:input {:type "checkbox"
|
||||
:field [:automatically-paid-when-due]
|
||||
:spec ::invoice/automatically-paid-when-due}])
|
||||
" Mark as paid on due date"]]
|
||||
[:p.help "Scheduled payment (optional)"]
|
||||
[:div.level
|
||||
[:div.level-left
|
||||
[:div.level-item
|
||||
[:div.control
|
||||
(raw-field
|
||||
[date-picker {:class-name "input"
|
||||
:class "input"
|
||||
:disabled (boolean (:schedule-when-due data))
|
||||
:format-week-number (fn [] "")
|
||||
:previous-month-button-label ""
|
||||
:placeholder "mm/dd/yyyy"
|
||||
:next-month-button-label ""
|
||||
:next-month-label ""
|
||||
:type "date"
|
||||
:field [:scheduled-payment]
|
||||
:spec ::invoice/scheduled-payment}])]]
|
||||
[:div.level-item [:div.control
|
||||
(raw-field
|
||||
[switch-field {:id "schedule-when-due"
|
||||
:field [:schedule-when-due]
|
||||
:label "Same as due date"
|
||||
:type "checkbox"}])]]]]
|
||||
|
||||
(field [:span "Invoice #"
|
||||
[:span.has-text-danger " *"]]
|
||||
|
||||
@@ -193,7 +193,7 @@
|
||||
[table/invoice-table {:id (:id page)
|
||||
:data-page :invoices
|
||||
:check-boxes (= status :unpaid)
|
||||
:checkable-fn (fn [i] (not (:automatically-paid-when-due i)))
|
||||
:checkable-fn (fn [i] (not (:scheduled-payment i)))
|
||||
:actions #{:edit :void :expense-accounts}}]]))
|
||||
|
||||
(defn unpaid-invoices-page [params]
|
||||
|
||||
Reference in New Issue
Block a user