cash payments add transactions
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
(: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]]
|
||||||
|
[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]
|
||||||
[auto-ap.datomic.clients :as d-clients]
|
[auto-ap.datomic.clients :as d-clients]
|
||||||
@@ -22,7 +23,8 @@
|
|||||||
[clojure.set :as set]
|
[clojure.set :as set]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||||
[config.core :refer [env]])
|
[config.core :refer [env]]
|
||||||
|
[digest])
|
||||||
(:import
|
(:import
|
||||||
(java.io ByteArrayOutputStream)
|
(java.io ByteArrayOutputStream)
|
||||||
(java.text DecimalFormat)
|
(java.text DecimalFormat)
|
||||||
@@ -203,8 +205,7 @@
|
|||||||
:content-type "application/pdf"})
|
:content-type "application/pdf"})
|
||||||
(str "http://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/merged-checks/" uuid ".pdf")))
|
(str "http://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/merged-checks/" uuid ".pdf")))
|
||||||
|
|
||||||
|
#_{:clj-kondo/ignore [:unused-binding]}
|
||||||
|
|
||||||
(defmulti invoices->entities (fn [invoices vendor-id client bank-account type index invoice-amounts]
|
(defmulti invoices->entities (fn [invoices vendor-id client bank-account type index invoice-amounts]
|
||||||
type))
|
type))
|
||||||
(defn invoice-payments [invoices invoice-amounts]
|
(defn invoice-payments [invoices invoice-amounts]
|
||||||
@@ -216,7 +217,7 @@
|
|||||||
[:pay (:db/id invoice) invoice-amount]])
|
[:pay (:db/id invoice) invoice-amount]])
|
||||||
(reduce into [])))
|
(reduce into [])))
|
||||||
|
|
||||||
(defn base-payment [invoices vendor client bank-account type index invoice-amounts]
|
(defn base-payment [invoices vendor client bank-account _ _ invoice-amounts]
|
||||||
{:db/id (str (:db/id vendor))
|
{:db/id (str (:db/id vendor))
|
||||||
:payment/bank-account (:db/id bank-account)
|
:payment/bank-account (:db/id bank-account)
|
||||||
:payment/amount (reduce + 0 (map (comp invoice-amounts :db/id) invoices))
|
:payment/amount (reduce + 0 (map (comp invoice-amounts :db/id) invoices))
|
||||||
@@ -315,16 +316,34 @@
|
|||||||
0.001)
|
0.001)
|
||||||
(throw (ex-info "The selected invoices do not have an outstanding balance."
|
(throw (ex-info "The selected invoices do not have an outstanding balance."
|
||||||
{:validation-error "The selected invoices do not have an outstanding balance."})))
|
{:validation-error "The selected invoices do not have an outstanding balance."})))
|
||||||
(let [payment (assoc (base-payment invoices vendor client bank-account type index invoice-amounts)
|
(let [base-payment (base-payment invoices vendor client bank-account type index invoice-amounts)
|
||||||
|
transaction-id (str (UUID/randomUUID))
|
||||||
|
memo (str "Cash Invoice #'s: "
|
||||||
|
(str/join ", "
|
||||||
|
(map (fn [i]
|
||||||
|
(str (:invoice/invoice-number i) "(" (invoice-amounts (:db/id i)) ")"))
|
||||||
|
invoices)))
|
||||||
|
payment (assoc base-payment
|
||||||
:payment/type :payment-type/cash
|
:payment/type :payment-type/cash
|
||||||
:payment/memo (str "Cash Invoice #'s: "
|
:payment/memo memo
|
||||||
(str/join ", "
|
:payment/status :payment-status/cleared)
|
||||||
(map (fn [i]
|
transaction {:db/id (str "transaction-" (:db/id vendor))
|
||||||
(str (:invoice/invoice-number i) "(" (invoice-amounts (:db/id i)) ")"))
|
:transaction/amount (:payment/amount base-payment)
|
||||||
invoices)))
|
:transaction/payment (str (:db/id vendor))
|
||||||
:payment/status :payment-status/cleared)]
|
:transaction/client (:db/id client)
|
||||||
|
:transaction/bank-account (:db/id bank-account)
|
||||||
|
:transaction/id #_{:clj-kondo/ignore [:unresolved-var]} (digest/sha-256 transaction-id)
|
||||||
|
:transaction/raw-id transaction-id
|
||||||
|
:transaction/vendor (:db/id vendor)
|
||||||
|
:transaction/description-original memo
|
||||||
|
:transaction/date (:payment/date base-payment)
|
||||||
|
:transaction/approval-status :transaction-approval-status/approved
|
||||||
|
:transaction/accounts [{:transaction-account/account (:db/id (a/get-account-by-numeric-code-and-sets 21000 ["default"]))
|
||||||
|
:transaction-account/location "A"
|
||||||
|
:transaction-account/amount (Math/abs (:payment/amount base-payment))}]}]
|
||||||
(-> []
|
(-> []
|
||||||
(conj payment)
|
(conj payment)
|
||||||
|
(conj transaction)
|
||||||
(into (invoice-payments invoices invoice-amounts)))))
|
(into (invoice-payments invoices invoice-amounts)))))
|
||||||
|
|
||||||
(defn validate-belonging [client-id invoices bank-account]
|
(defn validate-belonging [client-id invoices bank-account]
|
||||||
@@ -373,7 +392,7 @@
|
|||||||
(merge-pdfs (filter identity (map :payment/s3-key checks)))
|
(merge-pdfs (filter identity (map :payment/s3-key checks)))
|
||||||
nil)}))
|
nil)}))
|
||||||
|
|
||||||
(defn get-payment-page [context args value]
|
(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
|
||||||
(<-graphql)
|
(<-graphql)
|
||||||
@@ -393,16 +412,16 @@
|
|||||||
:start (:start args 0)
|
:start (:start args 0)
|
||||||
:end (+ (:start args 0) (count payments))}]))
|
:end (+ (:start args 0) (count payments))}]))
|
||||||
|
|
||||||
(defn get-potential-payments [context args value]
|
(defn get-potential-payments [context args _]
|
||||||
(let [transaction (d-transactions/get-by-id (:transaction_id args))
|
(let [transaction (d-transactions/get-by-id (:transaction_id args))
|
||||||
_ (assert-can-see-client (:id context) (:transaction/client transaction))
|
_ (assert-can-see-client (:id context) (:transaction/client transaction))
|
||||||
[payments payments-count] (d-checks/get-graphql {:client-id (:db/id (:transaction/client transaction))
|
[payments _] (d-checks/get-graphql {:client-id (:db/id (:transaction/client transaction))
|
||||||
:bank-account-id (:db/id (:transaction/bank-account transaction))
|
:bank-account-id (:db/id (:transaction/bank-account transaction))
|
||||||
:amount (- (:transaction/amount transaction))
|
:amount (- (:transaction/amount transaction))
|
||||||
:status :payment-status/pending})]
|
:status :payment-status/pending})]
|
||||||
(map ->graphql payments)))
|
(map ->graphql payments)))
|
||||||
|
|
||||||
(defn add-handwritten-check [context args value]
|
(defn add-handwritten-check [context args _]
|
||||||
(let [invoices (d-invoices/get-multi (map :invoice_id (:invoice_payments args)))
|
(let [invoices (d-invoices/get-multi (map :invoice_id (:invoice_payments args)))
|
||||||
bank-account-id (:bank_account_id args)
|
bank-account-id (:bank_account_id args)
|
||||||
bank-account (d-bank-accounts/get-by-id bank-account-id)
|
bank-account (d-bank-accounts/get-by-id bank-account-id)
|
||||||
@@ -431,7 +450,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} value]
|
(defn void-check [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))))
|
||||||
@@ -457,13 +476,13 @@
|
|||||||
(-> (d-checks/get-by-id id)
|
(-> (d-checks/get-by-id id)
|
||||||
(->graphql))))
|
(->graphql))))
|
||||||
|
|
||||||
(defn get-all-payments [context args value]
|
(defn get-all-payments [context args _]
|
||||||
(assert-admin (:id context))
|
(assert-admin (:id context))
|
||||||
(map
|
(map
|
||||||
->graphql
|
->graphql
|
||||||
(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 value]
|
(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
|
||||||
|
|||||||
@@ -92,5 +92,5 @@
|
|||||||
:stop (scheduler/stop import-worker))
|
:stop (scheduler/stop import-worker))
|
||||||
|
|
||||||
(mount/defstate account-worker
|
(mount/defstate account-worker
|
||||||
:start (scheduler/every (* 1000 60 60 24) upsert-accounts)
|
:start (scheduler/every (* 1000 60 30) upsert-accounts)
|
||||||
:stop (scheduler/stop account-worker))
|
:stop (scheduler/stop account-worker))
|
||||||
|
|||||||
Reference in New Issue
Block a user