added validation, fixed count issue.

This commit is contained in:
Bryce Covert
2020-10-08 07:01:57 -07:00
parent 84eedbf56f
commit 6d661ad754
4 changed files with 45 additions and 47 deletions

View File

@@ -1,32 +1,29 @@
(ns auto-ap.graphql.checks (ns auto-ap.graphql.checks
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-client]] (:require [amazonica.aws.s3 :as s3]
[datomic.api :as d] [auto-ap.datomic :refer [audit-transact remove-nils]]
[clojure.edn :as edn]
[com.walmartlabs.lacinia :refer [execute]]
[com.walmartlabs.lacinia.executor :as executor]
[com.walmartlabs.lacinia.resolve :as resolve]
[auto-ap.datomic.checks :as d-checks]
[auto-ap.datomic.invoices :as d-invoices]
[auto-ap.datomic.vendors :as d-vendors]
[auto-ap.datomic.transactions :as d-transactions]
[auto-ap.datomic.clients :as d-clients]
[auto-ap.datomic.bank-accounts :as d-bank-accounts] [auto-ap.datomic.bank-accounts :as d-bank-accounts]
[auto-ap.datomic :refer [uri remove-nils audit-transact]] [auto-ap.datomic.checks :as d-checks]
[auto-ap.utils :refer [by dollars-0?]] [auto-ap.datomic.clients :as d-clients]
[auto-ap.datomic.invoices :as d-invoices]
[auto-ap.datomic.transactions :as d-transactions]
[auto-ap.datomic.vendors :as d-vendors]
[auto-ap.graphql.utils
:refer
[->graphql <-graphql assert-can-see-client]]
[auto-ap.numeric :refer [num->words]] [auto-ap.numeric :refer [num->words]]
[config.core :refer [env]] [auto-ap.time :refer [iso-date local-now parse]]
[auto-ap.time :refer [parse normal-date iso-date local-now]] [auto-ap.utils :refer [by dollars-0?]]
[amazonica.aws.s3 :as s3]
[clojure.string :as str]
[clj-pdf.core :as pdf] [clj-pdf.core :as pdf]
[clj-time.format :as f]
[clj-time.coerce :as c] [clj-time.coerce :as c]
[clj-time.core :as time] [clj-time.core :as time]
[clojure.java.io :as io]) [clj-time.format :as f]
(:import [java.text DecimalFormat] [clojure.edn :as edn]
[java.util UUID] [clojure.java.io :as io]
[java.io ByteArrayOutputStream])) [clojure.string :as str]
[config.core :refer [env]])
(:import java.io.ByteArrayOutputStream
java.text.DecimalFormat
java.util.UUID))
(def parser (f/formatter "MM/dd/YYYY")) (def parser (f/formatter "MM/dd/YYYY"))
(defn date->str [t] (defn date->str [t]
@@ -248,7 +245,7 @@
:payment/type :payment-type/check :payment/type :payment-type/check
:payment/memo memo :payment/memo memo
:payment/status :payment-status/pending :payment/status :payment-status/pending
:payment/pdf-data (doto (pr-str {:vendor vendor :payment/pdf-data (pr-str {:vendor vendor
:paid-to (or (:vendor/paid-to vendor) (:vendor/name vendor)) :paid-to (or (:vendor/paid-to vendor) (:vendor/name vendor))
:amount (reduce + 0 (map (comp invoice-amounts :db/id) invoices)) :amount (reduce + 0 (map (comp invoice-amounts :db/id) invoices))
:check (str (+ index (:bank-account/check-number bank-account))) :check (str (+ index (:bank-account/check-number bank-account)))
@@ -262,8 +259,7 @@
:bank {:name (:bank-account/bank-name bank-account) :bank {:name (:bank-account/bank-name bank-account)
:acct (:bank-account/bank-code bank-account) :acct (:bank-account/bank-code bank-account)
:routing (:bank-account/routing bank-account) :routing (:bank-account/routing bank-account)
:acct-number (:bank-account/number bank-account)}}}) :acct-number (:bank-account/number bank-account)}}})))]
println)))]
(-> [] (-> []
(conj payment) (conj payment)
@@ -314,13 +310,15 @@
invoices (d-invoices/get-multi (map :invoice-id invoice-payments)) invoices (d-invoices/get-multi (map :invoice-id invoice-payments))
client (d-clients/get-by-id client-id) client (d-clients/get-by-id client-id)
vendors (by :db/id (d-vendors/get-graphql {})) vendors (by :db/id (d-vendors/get-graphql {}))
invoice-amounts (by :invoice-id :amount invoice-payments) invoice-amounts (by :invoice-id :amount invoice-payments)
invoices-grouped-by-vendor (group-by (comp :db/id :invoice/vendor) invoices) invoices-grouped-by-vendor (group-by (comp :db/id :invoice/vendor) invoices)
bank-account (d-bank-accounts/get-by-id bank-account-id) bank-account (d-bank-accounts/get-by-id bank-account-id)
_ (validate-belonging client-id invoices bank-account) _ (validate-belonging client-id invoices bank-account)
_ (if (dollars-0? (reduce + 0.0 (filter
#(>= % 0.0)
(map :amount invoice-payments))))
(throw (ex-info "The selected invoices do not have an outstanding balance."
{:validation-error "The selected invoices do not have an outstanding balance."})))
checks (->> (for [[[vendor-id invoices] index] (map vector invoices-grouped-by-vendor (range))] checks (->> (for [[[vendor-id invoices] index] (map vector invoices-grouped-by-vendor (range))]
(invoices->entities invoices (vendors vendor-id) client bank-account type index invoice-amounts)) (invoices->entities invoices (vendors vendor-id) client bank-account type index invoice-amounts))
(reduce into []) (reduce into [])
@@ -330,8 +328,7 @@
checks)] checks)]
(when (= type :payment-type/check) (when (= type :payment-type/check)
(make-pdfs (filter #(and (= :payment-type/check (:payment/type %)) (make-pdfs (filter #(and (= :payment-type/check (:payment/type %))
(> (:payment/amount %) 0.0) (> (:payment/amount %) 0.0))
)
checks))) checks)))
(audit-transact checks id) (audit-transact checks id)

View File

@@ -367,7 +367,7 @@
(audit-transact-batch retraction (:id context)) (audit-transact-batch retraction (:id context))
(log/info (map :tx success)) #_(log/info (map :tx success))
(audit-transact-batch (map :tx success) (:id context)) (audit-transact-batch (map :tx success) (:id context))
{:successful (map (fn [x] {:external_id (:external_id x)}) success) {:successful (map (fn [x] {:external_id (:external_id x)}) success)

View File

@@ -76,7 +76,8 @@
:source "request" :source "request"
:user-role (:user/role (:identity request)) :user-role (:user/role (:identity request))
:user-name (:user/name (:identity request))} :user-name (:user/name (:identity request))}
(log/info "Beginning request" (:uri request)) (when-not (str/includes? (:uri request) "health-check")
(log/info "Beginning request" (:uri request)))
(handler request)))) (handler request))))

View File

@@ -148,7 +148,7 @@
^{:key heading-name} [:th heading-name]))]] ^{:key heading-name} [:th heading-name]))]]
[:tbody [:tbody
(list (list
(for [[index row] (map vector (range ) (take 100 value)) (for [[index row] (map vector (range ) (take 2000 value))
:when (row-filter row)] :when (row-filter row)]
^{:key index} [:tr ^{:key index} [:tr
(list (list