Add the ability to unautopay
This commit is contained in:
@@ -1056,6 +1056,10 @@
|
||||
:args {:invoice_id {:type :id}}
|
||||
:resolve :mutation/unvoid-invoice}
|
||||
|
||||
:unautopay_invoice {:type :invoice
|
||||
:args {:invoice_id {:type :id}}
|
||||
:resolve :mutation/unautopay-invoice}
|
||||
|
||||
:void_payment {:type :payment
|
||||
:args {:payment_id {:type :id}}
|
||||
:resolve :mutation/void-payment}
|
||||
@@ -1343,6 +1347,7 @@
|
||||
:mutation/merge-vendors gq-vendors/merge-vendors
|
||||
:mutation/void-invoice gq-invoices/void-invoice
|
||||
:mutation/unvoid-invoice gq-invoices/unvoid-invoice
|
||||
:mutation/unautopay-invoice gq-invoices/unautopay-invoice
|
||||
:mutation/void-payment gq-checks/void-check
|
||||
:mutation/edit-expense-accounts gq-invoices/edit-expense-accounts
|
||||
:mutation/import-ledger gq-ledger/import-ledger
|
||||
|
||||
@@ -239,6 +239,18 @@
|
||||
(-> (d-invoices/get-by-id id)
|
||||
(->graphql))))
|
||||
|
||||
(defn unautopay-invoice [context {id :invoice_id} value]
|
||||
(let [invoice (d/entity (d/db conn) id)
|
||||
_ (assert (:invoice/client invoice))
|
||||
_ (assert-can-see-client (:id context) (:db/id (:invoice/client invoice)))]
|
||||
(audit-transact [[:db/add id :invoice/status :invoice-status/unpaid]
|
||||
[:db/add id :invoice/outstanding-balance (:invoice/total invoice)]
|
||||
[:db/retract id :invoice/scheduled-payment (:invoice/scheduled-payment invoice)]]
|
||||
(:id context))
|
||||
|
||||
(-> (d-invoices/get-by-id id)
|
||||
(->graphql))))
|
||||
|
||||
(defn edit-expense-accounts [context args value]
|
||||
(assert-can-see-client (:id context) (:db/id (:invoice/client (d-invoices/get-by-id (:invoice_id args)))))
|
||||
(let [invoice-id (:invoice_id args)
|
||||
|
||||
@@ -192,8 +192,8 @@
|
||||
:returns (+ (- (-> order :return_amounts :total_money amount->money)
|
||||
(-> order :return_amounts :tax_money amount->money)
|
||||
(-> order :return_amounts :tip_money amount->money)
|
||||
(-> order :return_amounts :service_charge_money amount->money)
|
||||
(-> order :return_amounts :discount_money amount->money)))
|
||||
(-> order :return_amounts :service_charge_money amount->money))
|
||||
(-> order :return_amounts :discount_money amount->money))
|
||||
:charges (->> (:tenders order)
|
||||
(map (fn [t]
|
||||
(remove-nils
|
||||
@@ -242,13 +242,13 @@
|
||||
|
||||
(defn settlements [l]
|
||||
(log/info "Searching for" l)
|
||||
(let [settlements (->> (client/get (str "https://connect.squareup.com/v1/" l "/settlements")
|
||||
(let [settlements (->> (client/get (str "https://connect.squareup.com/v1/" l "/settlements?limit=10")
|
||||
{:headers {"Authorization" "Bearer EAAAEO2xSqesDutZz71hz3eulKmrlKTiEqG3uZ4j25x5GYlOluQ2cj2JxNUXqXD7"
|
||||
"Content-Type" "application/json"}
|
||||
:as :json})
|
||||
:body
|
||||
(map :id))]
|
||||
(loop [[s & xs] (take 5 settlements)
|
||||
(loop [[s & xs] (take 10 settlements)
|
||||
result []]
|
||||
(log/info "Looking up settlement " s " for location " l)
|
||||
(let [n (:body (retry #(client/get (str "https://connect.squareup.com/v1/" l "/settlements/" s)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
(:require [auto-ap.events :as events]
|
||||
[auto-ap.routes :as routes]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.views.components.buttons :as buttons]
|
||||
[auto-ap.views.components.dropdown
|
||||
:refer
|
||||
@@ -90,6 +91,21 @@
|
||||
invoice-read]}]}
|
||||
:on-success (fn [result]
|
||||
[::invoice-updated (:unvoid-invoice result)])}}))
|
||||
(re-frame/reg-event-fx
|
||||
::unautopay
|
||||
(fn [{:keys [db]} [_ {id :id}]]
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:owns-state {:multi ::unautopay
|
||||
:which id}
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "UnautopayInvoice"}
|
||||
|
||||
:venia/queries [{:query/data [:unautopay-invoice
|
||||
{:invoice-id id}
|
||||
invoice-read]}]}
|
||||
:on-success (fn [result]
|
||||
[::invoice-updated (:unautopay-invoice result)])}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invoice-updated
|
||||
@@ -99,6 +115,7 @@
|
||||
(defn row [{:keys [invoice check-boxes selected-client overrides checkable? expense-event actions]}]
|
||||
(let [{:keys [client status payments expense-accounts invoice-number date due total outstanding-balance id vendor] :as i} invoice
|
||||
accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id client])
|
||||
unautopay-states @(re-frame/subscribe [::status/multi ::unautopay])
|
||||
account->name #(:name (accounts-by-id (:id %)))]
|
||||
[grid/row {:class (:class i) :id id :checkable? checkable? :entity invoice}
|
||||
(when-not selected-client
|
||||
@@ -121,7 +138,11 @@
|
||||
[grid/cell {} (str/join ", " (set (map :location expense-accounts)))]
|
||||
|
||||
[grid/cell {:class "has-text-right"} (nf total )]
|
||||
[grid/cell {:class "has-text-right"} (nf outstanding-balance )]
|
||||
[grid/cell {:class "has-text-right"}
|
||||
(if (:scheduled-payment i)
|
||||
[:<> [:div.tag.is-info.is-light "Autopay"] " "]
|
||||
)
|
||||
(nf outstanding-balance )]
|
||||
[grid/button-cell {}
|
||||
[:div.buttons
|
||||
(when (seq expense-accounts)
|
||||
@@ -185,7 +206,13 @@
|
||||
(when (and (get actions :void)
|
||||
(= ":voided" (:status i)))
|
||||
[buttons/fa-icon {:icon "fa-undo"
|
||||
:event [::unvoid-invoice i]}])]]]))
|
||||
:event [::unvoid-invoice i]}])
|
||||
(when (and (get actions :void)
|
||||
(= ":paid" (:status i))
|
||||
(:scheduled-payment i))
|
||||
[buttons/fa-icon {:icon "fa-undo"
|
||||
:class (status/class-for (get unautopay-states (:id i)))
|
||||
:event [::unautopay i]}])]]]))
|
||||
|
||||
(defn invoice-table [{:keys [id check-boxes overrides actions data-page checkable-fn]}]
|
||||
(let [selected-client @(re-frame/subscribe [::subs/client])
|
||||
|
||||
Reference in New Issue
Block a user