adds support for bulk voids.
This commit is contained in:
@@ -27,128 +27,130 @@
|
|||||||
{:payment/type [:db/ident]}
|
{:payment/type [:db/ident]}
|
||||||
{:transaction/_payment [:db/id :transaction/date]}])
|
{:transaction/_payment [:db/id :transaction/date]}])
|
||||||
|
|
||||||
(defn raw-graphql-ids [db args]
|
(defn raw-graphql-ids
|
||||||
(let [check-number-like (try (Long/parseLong (:check-number-like args)) (catch Exception _ nil))
|
([args] (raw-graphql-ids (d/db conn) args))
|
||||||
query (cond-> {:query {:find []
|
([db args]
|
||||||
:in ['$]
|
(let [check-number-like (try (Long/parseLong (:check-number-like args)) (catch Exception _ nil))
|
||||||
:where []}
|
query (cond-> {:query {:find []
|
||||||
:args [db]}
|
:in ['$]
|
||||||
(:sort args) (add-sorter-fields {"client" ['[?e :payment/client ?c]
|
:where []}
|
||||||
'[?c :client/name ?sort-client]]
|
:args [db]}
|
||||||
"vendor" ['[?e :payment/vendor ?v]
|
(:sort args) (add-sorter-fields {"client" ['[?e :payment/client ?c]
|
||||||
'[?v :vendor/name ?sort-vendor]]
|
'[?c :client/name ?sort-client]]
|
||||||
"bank-account" ['[?e :payment/bank-account ?ba]
|
"vendor" ['[?e :payment/vendor ?v]
|
||||||
'[?ba :bank-account/name ?sort-bank-account]]
|
'[?v :vendor/name ?sort-vendor]]
|
||||||
"check-number" ['[(get-else $ ?e :payment/check-number 0) ?sort-check-number]]
|
"bank-account" ['[?e :payment/bank-account ?ba]
|
||||||
"date" ['[?e :payment/date ?sort-date]]
|
'[?ba :bank-account/name ?sort-bank-account]]
|
||||||
"amount" ['[?e :payment/amount ?sort-amount]]
|
"check-number" ['[(get-else $ ?e :payment/check-number 0) ?sort-check-number]]
|
||||||
"status" ['[?e :payment/status ?sort-status]]}
|
"date" ['[?e :payment/date ?sort-date]]
|
||||||
args)
|
"amount" ['[?e :payment/amount ?sort-amount]]
|
||||||
(:exact-match-id args)
|
"status" ['[?e :payment/status ?sort-status]]}
|
||||||
(merge-query {:query {:in ['?e]
|
args)
|
||||||
:where []}
|
(:exact-match-id args)
|
||||||
:args [(:exact-match-id args)]})
|
(merge-query {:query {:in ['?e]
|
||||||
|
:where []}
|
||||||
|
:args [(:exact-match-id args)]})
|
||||||
|
|
||||||
(limited-clients (:id args))
|
(limited-clients (:id args))
|
||||||
(merge-query {:query {:in ['[?xx ...]]
|
(merge-query {:query {:in ['[?xx ...]]
|
||||||
:where ['[?e :payment/client ?xx]]}
|
:where ['[?e :payment/client ?xx]]}
|
||||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
:args [(set (map :db/id (limited-clients (:id args))))]})
|
||||||
|
|
||||||
|
|
||||||
(:client-id args)
|
(:client-id args)
|
||||||
(merge-query {:query {:in ['?client-id]
|
(merge-query {:query {:in ['?client-id]
|
||||||
:where ['[?e :payment/client ?client-id]]}
|
:where ['[?e :payment/client ?client-id]]}
|
||||||
:args [(:client-id args)]})
|
:args [(:client-id args)]})
|
||||||
(:client-code args)
|
(:client-code args)
|
||||||
(merge-query {:query {:in ['?client-code]
|
(merge-query {:query {:in ['?client-code]
|
||||||
:where ['[?e :payment/client ?client-id]
|
:where ['[?e :payment/client ?client-id]
|
||||||
'[?client-id :client/code ?client-code]]}
|
'[?client-id :client/code ?client-code]]}
|
||||||
:args [(:client-code args)]})
|
:args [(:client-code args)]})
|
||||||
|
|
||||||
|
|
||||||
(:vendor-id args)
|
(:vendor-id args)
|
||||||
(merge-query {:query {:in ['?vendor-id]
|
(merge-query {:query {:in ['?vendor-id]
|
||||||
:where ['[?e :payment/vendor ?vendor-id]]}
|
:where ['[?e :payment/vendor ?vendor-id]]}
|
||||||
:args [(:vendor-id args)]})
|
:args [(:vendor-id args)]})
|
||||||
|
|
||||||
(:original-id args)
|
(:original-id args)
|
||||||
(merge-query {:query {:in ['?original-id]
|
(merge-query {:query {:in ['?original-id]
|
||||||
:where ['[?e :payment/client ?c]
|
:where ['[?e :payment/client ?c]
|
||||||
'[?c :client/original-id ?original-id]]}
|
'[?c :client/original-id ?original-id]]}
|
||||||
:args [(:original-id args)]})
|
:args [(:original-id args)]})
|
||||||
|
|
||||||
(:check-number args)
|
(:check-number args)
|
||||||
(merge-query {:query {:in ['?check-number]
|
(merge-query {:query {:in ['?check-number]
|
||||||
:where ['[?e :payment/check-number ?check-number]]}
|
:where ['[?e :payment/check-number ?check-number]]}
|
||||||
:args [(:check-number args)]})
|
:args [(:check-number args)]})
|
||||||
|
|
||||||
(not-empty (:invoice-number args))
|
(not-empty (:invoice-number args))
|
||||||
(merge-query {:query {:in ['?invoice-number]
|
(merge-query {:query {:in ['?invoice-number]
|
||||||
:where ['[?e :payment/invoices ?i]
|
:where ['[?e :payment/invoices ?i]
|
||||||
'[?i :invoice/invoice-number ?invoice-number]]}
|
'[?i :invoice/invoice-number ?invoice-number]]}
|
||||||
:args [(:invoice-number args)]})
|
:args [(:invoice-number args)]})
|
||||||
|
|
||||||
(:bank-account-id args)
|
(:bank-account-id args)
|
||||||
(merge-query {:query {:in ['?bank-account-id]
|
(merge-query {:query {:in ['?bank-account-id]
|
||||||
:where ['[?e :payment/bank-account ?bank-account-id]]}
|
:where ['[?e :payment/bank-account ?bank-account-id]]}
|
||||||
:args [(:bank-account-id args)]})
|
:args [(:bank-account-id args)]})
|
||||||
|
|
||||||
(:amount-gte args)
|
(:amount-gte args)
|
||||||
(merge-query {:query {:in ['?amount-gte]
|
(merge-query {:query {:in ['?amount-gte]
|
||||||
:where ['[?e :payment/amount ?a]
|
:where ['[?e :payment/amount ?a]
|
||||||
'[(>= ?a ?amount-gte)]]}
|
'[(>= ?a ?amount-gte)]]}
|
||||||
:args [(:amount-gte args)]})
|
:args [(:amount-gte args)]})
|
||||||
|
|
||||||
(:amount-lte args)
|
(:amount-lte args)
|
||||||
(merge-query {:query {:in ['?amount-lte]
|
(merge-query {:query {:in ['?amount-lte]
|
||||||
:where ['[?e :payment/amount ?a]
|
:where ['[?e :payment/amount ?a]
|
||||||
'[(<= ?a ?amount-lte)]]}
|
'[(<= ?a ?amount-lte)]]}
|
||||||
:args [(:amount-lte args)]})
|
:args [(:amount-lte args)]})
|
||||||
|
|
||||||
(:amount args)
|
(:amount args)
|
||||||
(merge-query {:query {:in ['?amount]
|
(merge-query {:query {:in ['?amount]
|
||||||
:where ['[?e :payment/amount ?transaction-amount]
|
:where ['[?e :payment/amount ?transaction-amount]
|
||||||
'[(auto-ap.utils/dollars= ?transaction-amount ?amount)]]}
|
'[(auto-ap.utils/dollars= ?transaction-amount ?amount)]]}
|
||||||
:args [(:amount args)]})
|
:args [(:amount args)]})
|
||||||
|
|
||||||
|
|
||||||
(:status args)
|
(:status args)
|
||||||
(merge-query {:query {:in ['?status]
|
(merge-query {:query {:in ['?status]
|
||||||
:where ['[?e :payment/status ?status]]}
|
:where ['[?e :payment/status ?status]]}
|
||||||
:args [(:status args)]})
|
:args [(:status args)]})
|
||||||
|
|
||||||
(:start (:date-range args))
|
(:start (:date-range args))
|
||||||
(merge-query {:query {:in '[?start-date]
|
(merge-query {:query {:in '[?start-date]
|
||||||
:where ['[?e :payment/date ?date]
|
:where ['[?e :payment/date ?date]
|
||||||
'[(>= ?date ?start-date)]]}
|
'[(>= ?date ?start-date)]]}
|
||||||
:args [(c/to-date (:start (:date-range args)))]})
|
:args [(c/to-date (:start (:date-range args)))]})
|
||||||
|
|
||||||
(:end (:date-range args))
|
(:end (:date-range args))
|
||||||
(merge-query {:query {:in '[?end-date]
|
(merge-query {:query {:in '[?end-date]
|
||||||
:where ['[?e :payment/date ?date]
|
:where ['[?e :payment/date ?date]
|
||||||
'[(<= ?date ?end-date)]]}
|
'[(<= ?date ?end-date)]]}
|
||||||
:args [(c/to-date (:end (:date-range args)))]})
|
:args [(c/to-date (:end (:date-range args)))]})
|
||||||
|
|
||||||
(:payment-type args)
|
(:payment-type args)
|
||||||
(merge-query {:query {:in '[?payment-type]
|
(merge-query {:query {:in '[?payment-type]
|
||||||
:where ['[?e :payment/type ?payment-type]]}
|
:where ['[?e :payment/type ?payment-type]]}
|
||||||
:args [(:payment-type args)]})
|
:args [(:payment-type args)]})
|
||||||
|
|
||||||
check-number-like
|
check-number-like
|
||||||
(merge-query {:query {:in '[?check-number-like]
|
(merge-query {:query {:in '[?check-number-like]
|
||||||
:where ['[?e :payment/check-number ?check-number-like]]}
|
:where ['[?e :payment/check-number ?check-number-like]]}
|
||||||
:args [check-number-like]})
|
:args [check-number-like]})
|
||||||
|
|
||||||
true
|
true
|
||||||
(merge-query {:query {:find ['?sort-default '?e]
|
(merge-query {:query {:find ['?sort-default '?e]
|
||||||
:where ['[?e :payment/date ?sort-default]]}}))]
|
:where ['[?e :payment/date ?sort-default]]}}))]
|
||||||
|
|
||||||
|
|
||||||
(log/info query)
|
(log/info query)
|
||||||
(cond->> query
|
(cond->> query
|
||||||
true (d/query)
|
true (d/query)
|
||||||
true (apply-sort-3 args)
|
true (apply-sort-3 args)
|
||||||
true (apply-pagination args))))
|
true (apply-pagination args)))))
|
||||||
|
|
||||||
(defn graphql-results [ids db _]
|
(defn graphql-results [ids db _]
|
||||||
(let [results (->> (d/pull-many db default-read ids)
|
(let [results (->> (d/pull-many db default-read ids)
|
||||||
@@ -166,6 +168,17 @@
|
|||||||
[(->> (graphql-results ids-to-retrieve db args))
|
[(->> (graphql-results ids-to-retrieve db args))
|
||||||
matching-count]))
|
matching-count]))
|
||||||
|
|
||||||
|
(defn filter-ids [ids]
|
||||||
|
(if ids
|
||||||
|
(->> {:query {:find ['?e]
|
||||||
|
:in ['$ '[?e ...]]
|
||||||
|
:where ['[?e :payment/date]]}
|
||||||
|
:args [(d/db conn) ids]}
|
||||||
|
(d/query)
|
||||||
|
(map first)
|
||||||
|
vec)
|
||||||
|
[]))
|
||||||
|
|
||||||
(defn get-by-id [id]
|
(defn get-by-id [id]
|
||||||
(->>
|
(->>
|
||||||
(d/pull (d/db conn) default-read id)
|
(d/pull (d/db conn) default-read id)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
(ns auto-ap.graphql.checks
|
(ns auto-ap.graphql.checks
|
||||||
(:require
|
(:require
|
||||||
[amazonica.aws.s3 :as s3]
|
[amazonica.aws.s3 :as s3]
|
||||||
[auto-ap.datomic :refer [audit-transact remove-nils]]
|
[auto-ap.datomic :refer [audit-transact remove-nils conn]]
|
||||||
[auto-ap.datomic.accounts :as a]
|
[auto-ap.datomic.accounts :as a]
|
||||||
[auto-ap.datomic.bank-accounts :as d-bank-accounts]
|
[auto-ap.datomic.bank-accounts :as d-bank-accounts]
|
||||||
[auto-ap.datomic.checks :as d-checks]
|
[auto-ap.datomic.checks :as d-checks]
|
||||||
@@ -22,8 +22,10 @@
|
|||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[clojure.set :as set]
|
[clojure.set :as set]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
|
[clojure.tools.logging :as log]
|
||||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||||
[config.core :refer [env]]
|
[config.core :refer [env]]
|
||||||
|
[datomic.api :as d]
|
||||||
[digest])
|
[digest])
|
||||||
(:import
|
(:import
|
||||||
(java.io ByteArrayOutputStream)
|
(java.io ByteArrayOutputStream)
|
||||||
@@ -396,6 +398,7 @@
|
|||||||
(defn get-payment-page [context args _]
|
(defn get-payment-page [context args _]
|
||||||
(let [args (assoc args :id (:id context))
|
(let [args (assoc args :id (:id context))
|
||||||
[payments checks-count] (d-checks/get-graphql (-> args
|
[payments checks-count] (d-checks/get-graphql (-> args
|
||||||
|
:filters
|
||||||
(<-graphql)
|
(<-graphql)
|
||||||
(update :payment-type enum->keyword "payment-type")
|
(update :payment-type enum->keyword "payment-type")
|
||||||
(update :status enum->keyword "payment-status")))]
|
(update :status enum->keyword "payment-status")))]
|
||||||
@@ -451,7 +454,7 @@
|
|||||||
:invoices (d-invoices/get-multi (map :invoice_id (:invoice_payments args)))})))
|
:invoices (d-invoices/get-multi (map :invoice_id (:invoice_payments args)))})))
|
||||||
|
|
||||||
|
|
||||||
(defn void-check [context {id :payment_id} _]
|
(defn void-payment [context {id :payment_id} _]
|
||||||
(let [check (d-checks/get-by-id id)]
|
(let [check (d-checks/get-by-id id)]
|
||||||
(assert (or (= :payment-status/pending (:payment/status check))
|
(assert (or (= :payment-status/pending (:payment/status check))
|
||||||
(#{:payment-type/cash :payment-type/debit} (:payment/type check))))
|
(#{:payment-type/cash :payment-type/debit} (:payment/type check))))
|
||||||
@@ -470,13 +473,55 @@
|
|||||||
updated-payment {:db/id id
|
updated-payment {:db/id id
|
||||||
:payment/amount 0.0
|
:payment/amount 0.0
|
||||||
:payment/status :payment-status/voided}]
|
:payment/status :payment-status/voided}]
|
||||||
|
|
||||||
(audit-transact (conj removing-payments updated-payment)
|
(audit-transact (conj removing-payments updated-payment)
|
||||||
(:id context)))
|
(:id context)))
|
||||||
|
|
||||||
(-> (d-checks/get-by-id id)
|
(-> (d-checks/get-by-id id)
|
||||||
(->graphql))))
|
(->graphql))))
|
||||||
|
|
||||||
|
(defn void-payments [context args _]
|
||||||
|
(assert-admin (:id context))
|
||||||
|
(let [args (assoc args :id (:id context))
|
||||||
|
ids (some-> args
|
||||||
|
:filters
|
||||||
|
(assoc :id (:id context))
|
||||||
|
(<-graphql)
|
||||||
|
(update :payment-type enum->keyword "payment-type")
|
||||||
|
(update :status enum->keyword "payment-status")
|
||||||
|
(assoc :per-page Integer/MAX_VALUE)
|
||||||
|
d-checks/raw-graphql-ids
|
||||||
|
:ids)
|
||||||
|
specific-ids (d-checks/filter-ids (:ids args))
|
||||||
|
all-ids (into (set ids) specific-ids)]
|
||||||
|
(log/info "Voiding " (count all-ids) args)
|
||||||
|
(audit-transact (->> all-ids
|
||||||
|
(d/q '[:find [(pull ?p [:db/id
|
||||||
|
{:invoice-payment/_payment [:invoice-payment/amount
|
||||||
|
:db/id
|
||||||
|
{:invoice-payment/invoice [:db/id :invoice/outstanding-balance]}]}]) ...]
|
||||||
|
:in $ [?p ...]
|
||||||
|
:where
|
||||||
|
(not [_ :transaction/payment ?p])
|
||||||
|
(not [?p :payment/status :payment-status/voided])]
|
||||||
|
(d/db conn))
|
||||||
|
(mapcat (fn [{:keys [:db/id]
|
||||||
|
invoices :invoice-payment/_payment}]
|
||||||
|
(into
|
||||||
|
[{:db/id id
|
||||||
|
:payment/amount 0.0
|
||||||
|
:payment/status :payment-status/voided}]
|
||||||
|
(->> invoices
|
||||||
|
(mapcat (fn [{:keys [:invoice-payment/invoice :db/id :invoice-payment/amount]}]
|
||||||
|
(let [new-balance (+ (:invoice/outstanding-balance invoice)
|
||||||
|
amount)]
|
||||||
|
[[:db.fn/retractEntity id]
|
||||||
|
{:db/id (:db/id invoice)
|
||||||
|
:invoice/outstanding-balance new-balance
|
||||||
|
:invoice/status (if (dollars-0? new-balance)
|
||||||
|
(:invoice/status invoice)
|
||||||
|
:invoice-status/unpaid)}]))))))))
|
||||||
|
(:id context))
|
||||||
|
{:message (str "Succesfully voided " (count all-ids))}))
|
||||||
|
|
||||||
(defn get-all-payments [context args _]
|
(defn get-all-payments [context args _]
|
||||||
(assert-admin (:id context))
|
(assert-admin (:id context))
|
||||||
(map
|
(map
|
||||||
@@ -484,7 +529,6 @@
|
|||||||
(first (d-checks/get-graphql (assoc (<-graphql args) :count Integer/MAX_VALUE)))))
|
(first (d-checks/get-graphql (assoc (<-graphql args) :count Integer/MAX_VALUE)))))
|
||||||
|
|
||||||
(defn print-checks [context args _]
|
(defn print-checks [context args _]
|
||||||
|
|
||||||
(assert-can-see-client (:id context) (:client_id args))
|
(assert-can-see-client (:id context) (:client_id args))
|
||||||
(->graphql
|
(->graphql
|
||||||
(print-checks-internal (map (fn [i] {:invoice-id (:invoice_id i)
|
(print-checks-internal (map (fn [i] {:invoice-id (:invoice_id i)
|
||||||
@@ -531,19 +575,7 @@
|
|||||||
:statuses {:type '(list String)}}
|
:statuses {:type '(list String)}}
|
||||||
:resolve :get-all-payments}
|
:resolve :get-all-payments}
|
||||||
:payment_page {:type '(list :payment_page)
|
:payment_page {:type '(list :payment_page)
|
||||||
:args {:client_id {:type :id}
|
:args {:filters {:type :payment_filters}}
|
||||||
:vendor_id {:type :id}
|
|
||||||
:payment_type {:type :payment_type}
|
|
||||||
:status {:type :payment_status}
|
|
||||||
:exact_match_id {:type :id}
|
|
||||||
:date_range {:type :date_range}
|
|
||||||
:amount_lte {:type :money}
|
|
||||||
:amount_gte {:type :money}
|
|
||||||
:check_number_like {:type 'String}
|
|
||||||
:invoice_number {:type 'String}
|
|
||||||
:start {:type 'Int}
|
|
||||||
:per_page {:type 'Int}
|
|
||||||
:sort {:type '(list :sort_item)}}
|
|
||||||
:resolve :get-payment-page}
|
:resolve :get-payment-page}
|
||||||
:potential_payment_matches {:type '(list :payment)
|
:potential_payment_matches {:type '(list :payment)
|
||||||
:args {:transaction_id {:type :id}}
|
:args {:transaction_id {:type :id}}
|
||||||
@@ -564,11 +596,29 @@
|
|||||||
:resolve :mutation/add-handwritten-check}
|
:resolve :mutation/add-handwritten-check}
|
||||||
:void_payment {:type :payment
|
:void_payment {:type :payment
|
||||||
:args {:payment_id {:type :id}}
|
:args {:payment_id {:type :id}}
|
||||||
:resolve :mutation/void-payment}})
|
:resolve :mutation/void-payment}
|
||||||
|
|
||||||
|
:void_payments {:type :message
|
||||||
|
:args {:filters {:type :payment_filters}
|
||||||
|
:ids {:type '(list :id)}}
|
||||||
|
:resolve :mutation/void-payments}})
|
||||||
|
|
||||||
(def input-objects
|
(def input-objects
|
||||||
{:invoice_payment_amount {:fields {:invoice_id {:type :id}
|
{:invoice_payment_amount {:fields {:invoice_id {:type :id}
|
||||||
:amount {:type :money}}}})
|
:amount {:type :money}}}
|
||||||
|
:payment_filters {:fields {:client_id {:type :id}
|
||||||
|
:vendor_id {:type :id}
|
||||||
|
:payment_type {:type :payment_type}
|
||||||
|
:status {:type :payment_status}
|
||||||
|
:exact_match_id {:type :id}
|
||||||
|
:date_range {:type :date_range}
|
||||||
|
:amount_lte {:type :money}
|
||||||
|
:amount_gte {:type :money}
|
||||||
|
:check_number_like {:type 'String}
|
||||||
|
:invoice_number {:type 'String}
|
||||||
|
:start {:type 'Int}
|
||||||
|
:per_page {:type 'Int}
|
||||||
|
:sort {:type '(list :sort_item)}}}})
|
||||||
|
|
||||||
(def enums
|
(def enums
|
||||||
{:payment_type {:values [{:enum-value :check}
|
{:payment_type {:values [{:enum-value :check}
|
||||||
@@ -584,7 +634,8 @@
|
|||||||
{:get-potential-payments get-potential-payments
|
{:get-potential-payments get-potential-payments
|
||||||
:get-payment-page get-payment-page
|
:get-payment-page get-payment-page
|
||||||
:get-all-payments get-all-payments
|
:get-all-payments get-all-payments
|
||||||
:mutation/void-payment void-check
|
:mutation/void-payment void-payment
|
||||||
|
:mutation/void-payments void-payments
|
||||||
:mutation/print-checks print-checks
|
:mutation/print-checks print-checks
|
||||||
:mutation/add-handwritten-check add-handwritten-check
|
:mutation/add-handwritten-check add-handwritten-check
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -284,7 +284,7 @@
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
[grid/body
|
[grid/body
|
||||||
(for [{:keys [client payments expense-accounts invoice-number date due total outstanding-balance id vendor] :as i} invoices]
|
(for [{:keys [id] :as i} invoices]
|
||||||
^{:key id}
|
^{:key id}
|
||||||
[row {:invoice i
|
[row {:invoice i
|
||||||
:selected-client selected-client
|
:selected-client selected-client
|
||||||
|
|||||||
@@ -1,59 +1,52 @@
|
|||||||
(ns auto-ap.views.pages.payments
|
(ns auto-ap.views.pages.payments
|
||||||
(:require [re-frame.core :as re-frame]
|
(:require
|
||||||
[auto-ap.entities.clients :as client]
|
[auto-ap.effects.forward :as forward]
|
||||||
[auto-ap.entities.vendors :as vendor]
|
[auto-ap.status :as status]
|
||||||
[reagent.core :as reagent]
|
[auto-ap.subs :as subs]
|
||||||
[goog.string :as gstring]
|
[auto-ap.views.components.layouts :refer [side-bar-layout]]
|
||||||
[clojure.spec.alpha :as s]
|
[auto-ap.views.components.modal :as modal]
|
||||||
[vimsical.re-frame.cofx.inject :as inject]
|
[auto-ap.views.pages.data-page :as data-page]
|
||||||
[auto-ap.views.components.sorter :refer [sorted-column]]
|
[auto-ap.views.pages.payments.side-bar :as side-bar]
|
||||||
[auto-ap.views.components.date-range-filter :refer [date-range-filter]]
|
[auto-ap.views.pages.payments.table :as table]
|
||||||
[auto-ap.views.components.layouts :refer [side-bar-layout]]
|
[auto-ap.views.utils :refer [dispatch-event nf with-user]]
|
||||||
[auto-ap.views.components.paginator :refer [paginator]]
|
[clojure.set :as set]
|
||||||
[auto-ap.views.components.sort-by-list :refer [sort-by-list]]
|
[goog.string :as gstring]
|
||||||
[auto-ap.events :as events]
|
[re-frame.core :as re-frame]
|
||||||
[auto-ap.views.utils :refer [dispatch-event date->str bind-field nf with-user]]
|
[reagent.core :as reagent]
|
||||||
[auto-ap.utils :refer [by]]
|
[vimsical.re-frame.fx.track :as track]))
|
||||||
[auto-ap.views.pages.payments.side-bar :as side-bar]
|
|
||||||
[auto-ap.views.pages.payments.table :as table]
|
|
||||||
[auto-ap.views.pages.check :as check]
|
|
||||||
[auto-ap.subs :as subs]
|
|
||||||
[auto-ap.status :as status]
|
|
||||||
[vimsical.re-frame.fx.track :as track]
|
|
||||||
[auto-ap.effects.forward :as forward]
|
|
||||||
[auto-ap.views.pages.data-page :as data-page]
|
|
||||||
[clojure.set :as set]))
|
|
||||||
|
|
||||||
|
(defn data-params->query-params [params]
|
||||||
|
{:start (:start params 0)
|
||||||
|
:per-page (:per-page params)
|
||||||
|
:sort (:sort params)
|
||||||
|
:client-id (:id @(re-frame/subscribe [::subs/client]))
|
||||||
|
:vendor-id (:id (:vendor params))
|
||||||
|
:payment-type (:payment-type params)
|
||||||
|
:status (:status params)
|
||||||
|
:exact-match-id (some-> (:exact-match-id params) str)
|
||||||
|
:date-range (:date-range params)
|
||||||
|
:amount-gte (:amount-gte (:amount-range params))
|
||||||
|
:amount-lte (:amount-lte (:amount-range params))
|
||||||
|
:check-number-like (str (:check-number-like params))
|
||||||
|
:invoice-number (:invoice-number params)})
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::params-change
|
::params-change
|
||||||
[with-user]
|
[with-user]
|
||||||
(fn [{:keys [user db ]}[_ params]]
|
(fn [{:keys [user]}[_ params]]
|
||||||
{:graphql {:token user
|
{:graphql {:token user
|
||||||
:owns-state {:single [::data-page/page ::page]}
|
:owns-state {:single [::data-page/page ::page]}
|
||||||
:query-obj {:venia/queries [[:payment_page
|
:query-obj {:venia/queries [[:payment_page
|
||||||
{:start (:start params 0)
|
{:filters (data-params->query-params params)}
|
||||||
:per-page (:per-page params)
|
[[:payments [:id :status :amount :type :check_number :s3_url
|
||||||
:sort (:sort params)
|
[:bank-account [:name]]
|
||||||
:client-id (:id @(re-frame/subscribe [::subs/client]))
|
:date [:vendor [:name :id]] [:client [:name :id]]
|
||||||
:vendor-id (:id (:vendor params))
|
[:invoices [:invoice-id [:invoice [:invoice-number :id]]
|
||||||
:payment-type (:payment-type params)
|
:amount]]
|
||||||
:status (:status params)
|
[:transaction [:id :date]]]]
|
||||||
:exact-match-id (some-> (:exact-match-id params) str)
|
:total
|
||||||
:date-range (:date-range params)
|
:start
|
||||||
:amount-gte (:amount-gte (:amount-range params))
|
:end]]]}
|
||||||
:amount-lte (:amount-lte (:amount-range params))
|
|
||||||
:check-number-like (str (:check-number-like params))
|
|
||||||
:invoice-number (:invoice-number params)}
|
|
||||||
[[:payments [:id :status :amount :type :check_number :s3_url
|
|
||||||
[:bank-account [:name]]
|
|
||||||
:date [:vendor [:name :id]] [:client [:name :id]]
|
|
||||||
[:invoices [:invoice-id [:invoice [:invoice-number :id]]
|
|
||||||
:amount]]
|
|
||||||
[:transaction [:id :date]]]]
|
|
||||||
:total
|
|
||||||
:start
|
|
||||||
:end]]]}
|
|
||||||
:on-success (fn [result]
|
:on-success (fn [result]
|
||||||
(let [result (set/rename-keys (first (:payment-page result))
|
(let [result (set/rename-keys (first (:payment-page result))
|
||||||
{:payments :data})]
|
{:payments :data})]
|
||||||
@@ -62,14 +55,14 @@
|
|||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::unmounted
|
::unmounted
|
||||||
(fn [{:keys [db]} _]
|
(fn [_ _]
|
||||||
{:dispatch [::data-page/dispose ::page]
|
{:dispatch [::data-page/dispose ::page]
|
||||||
::track/dispose {:id ::params}
|
::track/dispose {:id ::params}
|
||||||
::forward/dispose {:id ::page}}))
|
::forward/dispose {:id ::page}}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::mounted
|
::mounted
|
||||||
(fn [{:keys [db]} _]
|
(fn [_ _]
|
||||||
{::track/register {:id ::params
|
{::track/register {:id ::params
|
||||||
:subscription [::data-page/params ::page]
|
:subscription [::data-page/params ::page]
|
||||||
:event-fn (fn [params]
|
:event-fn (fn [params]
|
||||||
@@ -79,9 +72,82 @@
|
|||||||
:event-fn (fn [[_ {:keys [void-payment]}]]
|
:event-fn (fn [[_ {:keys [void-payment]}]]
|
||||||
[::data-page/updated-entity ::page (assoc void-payment :class "live-removed")])}}))
|
[::data-page/updated-entity ::page (assoc void-payment :class "live-removed")])}}))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::voided-selected
|
||||||
|
(fn [_ _]
|
||||||
|
{:dispatch-n [[::modal/modal-closed]
|
||||||
|
[::params-change @(re-frame/subscribe [::data-page/params ::page])]
|
||||||
|
[::data-page/reset-checked ::page]]}))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::void-selected
|
||||||
|
(fn [cofx [_ which]]
|
||||||
|
(let [checked-params (get which "header")
|
||||||
|
specific-invoices (map :id (vals (dissoc which "header")))]
|
||||||
|
{:graphql {:token (-> cofx :db :user)
|
||||||
|
:owns-state {:single ::void-selected}
|
||||||
|
:query-obj
|
||||||
|
{:venia/operation {:operation/type :mutation
|
||||||
|
:operation/name "VoidPayments"}
|
||||||
|
:venia/queries [{:query/data
|
||||||
|
[:void-payments
|
||||||
|
{:filters (some-> checked-params data-params->query-params)
|
||||||
|
:ids specific-invoices}
|
||||||
|
[:message]]}]}
|
||||||
|
:on-success (fn [_]
|
||||||
|
[::voided-selected])}})))
|
||||||
|
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::void-selected-requested
|
||||||
|
(fn [_ [_ which]]
|
||||||
|
(let [to-delete (if (get which "header")
|
||||||
|
"all visible payments"
|
||||||
|
(str (count which) " payments"))]
|
||||||
|
{:dispatch [::modal/modal-requested {:title "Confirmation"
|
||||||
|
:body [:div (str "Are you sure you want to void " to-delete "?")]
|
||||||
|
:cancel? true
|
||||||
|
:confirm {:value "Void"
|
||||||
|
:class "is-danger"
|
||||||
|
:status-from [::status/single ::void-selected]
|
||||||
|
:on-click (dispatch-event [::void-selected which] )}
|
||||||
|
:close-event [::status/completed ::void-selected]}]})))
|
||||||
|
|
||||||
|
(defn void-selected-button []
|
||||||
|
(let [status @(re-frame/subscribe [::status/single ::void-selected])
|
||||||
|
checked-payments @(re-frame/subscribe [::data-page/checked ::page])
|
||||||
|
is-admin? @(re-frame/subscribe [::subs/is-admin?])]
|
||||||
|
(when is-admin?
|
||||||
|
[:button.button.is-danger {:on-click (dispatch-event [::void-selected-requested checked-payments])
|
||||||
|
:class (status/class-for status)
|
||||||
|
:disabled (or (status/disabled-for status)
|
||||||
|
(not (seq checked-payments)))}
|
||||||
|
" Void"])))
|
||||||
|
|
||||||
|
(defn action-buttons []
|
||||||
|
(let [checked-payments @(re-frame/subscribe [::data-page/checked ::page])]
|
||||||
|
[:div
|
||||||
|
[:div.is-pulled-right
|
||||||
|
[:div.buttons
|
||||||
|
[void-selected-button]]]
|
||||||
|
[:div.is-pulled-right {:style {:margin-right "0.5rem"}}
|
||||||
|
(into [:div.tags ] (map (fn [[z {:keys [id check-number type amount]}]]
|
||||||
|
(if (= z "header")
|
||||||
|
[:span.tag.is-medium "All visible payments"
|
||||||
|
[:button.delete.is-small {:on-click
|
||||||
|
(dispatch-event [::data-page/remove-check ::page z])}]]
|
||||||
|
[:span.tag.is-medium (cond
|
||||||
|
(= :cash type) (gstring/format "Cash (%s)" (nf amount ))
|
||||||
|
(= :debit type) (gstring/format "Debit (%s)" (nf amount ))
|
||||||
|
:else (gstring/format "Check #%d (%s)" check-number (nf amount )))
|
||||||
|
[:button.delete.is-small {:on-click
|
||||||
|
(dispatch-event [::data-page/remove-check ::page id])}]]))
|
||||||
|
checked-payments))]]))
|
||||||
|
|
||||||
(defn content []
|
(defn content []
|
||||||
[:div
|
[:div
|
||||||
[:h1.title "Payments"]
|
[:h1.title "Payments"]
|
||||||
|
[action-buttons]
|
||||||
[table/table {:id :payments
|
[table/table {:id :payments
|
||||||
:data-page ::page}]])
|
:data-page ::page}]])
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
states :states
|
states :states
|
||||||
}]
|
}]
|
||||||
(let [{:keys [client s3-url bank-account payments type check-number date amount id vendor status invoices transaction] :as check} check]
|
(let [{:keys [client s3-url bank-account payments type check-number date amount id vendor status invoices transaction] :as check} check]
|
||||||
[grid/row {:class (:class check) :id id}
|
[grid/row {:class (:class check) :id id :entity check}
|
||||||
(when-not selected-client
|
(when-not selected-client
|
||||||
[grid/cell {} (:name client)])
|
[grid/cell {} (:name client)])
|
||||||
[grid/cell {} (:name vendor)]
|
[grid/cell {} (:name vendor)]
|
||||||
@@ -95,24 +95,25 @@
|
|||||||
(url/map->query {:exact-match-id (:id transaction)}))}]]])]]]]])
|
(url/map->query {:exact-match-id (:id transaction)}))}]]])]]]]])
|
||||||
[:span {:style {:margin-left "1em"}}]
|
[:span {:style {:margin-left "1em"}}]
|
||||||
|
|
||||||
(when (or (= :pending status)
|
(when (and (not= :cleared status)
|
||||||
(and (#{":cash" :cash ":debit" :debit} type)
|
(not= :voided status)
|
||||||
(not= :voided status)
|
(not transaction))
|
||||||
(not transaction)))
|
|
||||||
[buttons/sl-icon {:event [::void-check check] :icon :icon-bin-2
|
[buttons/sl-icon {:event [::void-check check] :icon :icon-bin-2
|
||||||
:class (status/class-for (get states (:id check)))}]
|
:class (status/class-for (get states (:id check)))}])]]]))
|
||||||
)]]]))
|
|
||||||
|
|
||||||
(defn table [{:keys [data-page]}]
|
(defn table [{:keys [data-page]}]
|
||||||
(let [selected-client @(re-frame/subscribe [::subs/client])
|
(let [selected-client @(re-frame/subscribe [::subs/client])
|
||||||
{:keys [data status]} @(re-frame/subscribe [::data-page/page data-page])
|
{:keys [data params]} @(re-frame/subscribe [::data-page/page data-page])
|
||||||
states @(re-frame/subscribe [::status/multi ::void])]
|
states @(re-frame/subscribe [::status/multi ::void])]
|
||||||
[grid/grid {:data-page data-page
|
[grid/grid {:data-page data-page
|
||||||
|
:check-boxes? true
|
||||||
:column-count (if selected-client 7 8)}
|
:column-count (if selected-client 7 8)}
|
||||||
[grid/controls data]
|
[grid/controls data]
|
||||||
[grid/table {:fullwidth true}
|
[grid/table {:fullwidth true}
|
||||||
[grid/header {}
|
[grid/header {}
|
||||||
[grid/row {}
|
[grid/row {:id "header"
|
||||||
|
:entity params}
|
||||||
(when-not selected-client
|
(when-not selected-client
|
||||||
[grid/sortable-header-cell {:sort-key "client" :sort-name "Client"} "Client"])
|
[grid/sortable-header-cell {:sort-key "client" :sort-name "Client"} "Client"])
|
||||||
[grid/sortable-header-cell {:sort-key "vendor" :sort-name "Vendor"} "Vendor"]
|
[grid/sortable-header-cell {:sort-key "vendor" :sort-name "Vendor"} "Vendor"]
|
||||||
|
|||||||
@@ -132,7 +132,9 @@
|
|||||||
::voided-selected
|
::voided-selected
|
||||||
(fn [cofx [_]]
|
(fn [cofx [_]]
|
||||||
{:dispatch-n [[::modal/modal-closed]
|
{:dispatch-n [[::modal/modal-closed]
|
||||||
[::params-change @(re-frame/subscribe [::data-page/params ::page])]]}))
|
[::params-change @(re-frame/subscribe [::data-page/params ::page])]
|
||||||
|
[::data-page/reset-checked :invoices]]}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::void-selected
|
::void-selected
|
||||||
(fn [cofx [_ which]]
|
(fn [cofx [_ which]]
|
||||||
@@ -142,15 +144,14 @@
|
|||||||
:owns-state {:single ::void-selected}
|
:owns-state {:single ::void-selected}
|
||||||
:query-obj
|
:query-obj
|
||||||
{:venia/operation {:operation/type :mutation
|
{:venia/operation {:operation/type :mutation
|
||||||
:operation/name "DeleteTransactions"}
|
:operation/name "VoidInvoices"}
|
||||||
:venia/queries [{:query/data
|
:venia/queries [{:query/data
|
||||||
[:void-invoices
|
[:void-invoices
|
||||||
{:filters (some-> checked-params table/data-params->query-params)
|
{:filters (some-> checked-params table/data-params->query-params)
|
||||||
:ids specific-invoices}
|
:ids specific-invoices}
|
||||||
[:message]]}]}
|
[:message]]}]}
|
||||||
:on-success (fn [result]
|
:on-success (fn [_]
|
||||||
[::voided-selected])}
|
[::voided-selected])}})))
|
||||||
:dispatch [::data-page/reset-checked ::page]})))
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::void-selected-requested
|
::void-selected-requested
|
||||||
|
|||||||
Reference in New Issue
Block a user