integrates new page into company section

This commit is contained in:
2023-01-14 13:52:09 -08:00
parent 6077c3119e
commit d2189ba460
10 changed files with 164 additions and 80 deletions

View File

@@ -2,15 +2,15 @@
(:require
[auto-ap.graphql.utils :refer [is-admin?]]
[buddy.auth :refer [authenticated?]]
[auto-ap.logging :as alog]))
[auto-ap.logging :as alog]
[cemerick.url :as url]))
(defn wrap-secure [handler]
(fn [request]
(if (authenticated? request)
(handler request)
{:status 401
:headers {"content-type" "text/html"}
:body "not authenticated"})))
{:status 302
:headers {"Location" "/login" }})))
(defn wrap-admin [handler]
(fn [request]
@@ -19,12 +19,11 @@
(do
(alog/warn ::unauthenticated)
{:status 302
:headers "/login"}))))
:headers {"Location" "/login"}}))))
(defn wrap-client-redirect-unauthenticated [handler]
(fn [request]
(let [response (handler request)]
(println )
(if (= 401 (get response :status))
(assoc-in response [:headers "hx-redirect"] "/login/")
response))))

View File

@@ -47,11 +47,16 @@
:attempt attempt
:source "Square 3"
:background-job "Square 3")
(client/request (assoc request
:socket-timeout 10000
:connection-timeout 10000
:as :json
:retry-handler retry-4))))
(try
(client/request (assoc request
:socket-timeout 10000
:connection-timeout 10000
:as :json
:retry-handler retry-4))
(catch Exception e
(log/error ::raw-request-failed
:exception e)
(throw e)))))
(de/catch
(fn [e]
(if (= attempt 5)

View File

@@ -2,48 +2,51 @@
(:require
[auto-ap.datomic :refer [conn remove-nils]]
[auto-ap.graphql.utils :refer [can-see-client?]]
[auto-ap.shared-views.company.sidebar :refer [company-side-bar]]
[auto-ap.ssr-routes :as ssr-routes]
[auto-ap.ssr.ui :refer [base-page html-response]]
[bidi.bidi :as bidi]
[clojure.string :as str]
[datomic.api :as d]
[hiccup2.core :as hiccup]
[clojure.string :as str]))
[hiccup2.core :as hiccup]))
(defn test [x c]
(println x c))
(defn cannot-overwrite? [vendor]
(some? (or (:vendor/legal-entity-1099-type vendor)
(:vendor/legal-entity-tin vendor)
(:vendor/legal-entity-tin-type vendor))))
(defn get-1099-companies [user]
(let [valid-clients (into #{} (map :db/id (:user/clients user)))]
(->> (d/q '[:find
(pull ?c [:client/code])
(pull ?v [:db/id
:vendor/name
{:vendor/legal-entity-1099-type [:db/ident]}
{:vendor/legal-entity-tin-type [:db/ident]}
{:vendor/address [:address/street1
:address/city
:address/state
:address/zip]}
:vendor/legal-entity-first-ein
:vendor/legal-entity-first-name
:vendor/legal-entity-middle-name
:vendor/legal-entity-last-name])
(sum ?a)
:in $ ?user
:where [?p :payment/date ?d ]
[(>= ?d #inst "2018-01-01T08:00")]
[(< ?d #inst "2023-01-01T08:00")]
[?p :payment/client ?c]
[(auto-ap.graphql.utils/can-see-client? ?user ?c)]
[?p :payment/amount ?a]
[?p :payment/type :payment-type/check]
[?p :payment/vendor ?v]]
(d/db conn)
user)
(filter (fn [[_ _ a]]
(>= a 600.0)))
(sort-by #(:client/code (first %)) )
#_(into ))))
(->> (d/q '[:find
(pull ?c [:client/code])
(pull ?v [:db/id
:vendor/name
{:vendor/legal-entity-1099-type [:db/ident]}
{:vendor/legal-entity-tin-type [:db/ident]}
{:vendor/address [:address/street1
:address/city
:address/state
:address/zip]}
:vendor/legal-entity-first-ein
:vendor/legal-entity-first-name
:vendor/legal-entity-middle-name
:vendor/legal-entity-last-name])
(sum ?a)
:in $ ?user
:where [?p :payment/date ?d ]
[(>= ?d #inst "2018-01-01T08:00")]
[(< ?d #inst "2023-01-01T08:00")]
[?p :payment/client ?c]
[(auto-ap.graphql.utils/can-see-client? ?user ?c)]
[?p :payment/amount ?a]
[?p :payment/type :payment-type/check]
[?p :payment/vendor ?v]]
(d/db conn)
user)
(filter (fn [[_ _ a]]
(>= a 600.0)))
(sort-by (fn [[client _ amount]]
[(:client/code client) amount]) )))
(defn dialog [header content footer]
[:div.modal.is-active
@@ -68,7 +71,7 @@
[:th {:style {:width "8em"}} "TIN"]
[:th "Address"]
[:th "Amount Paid"]
[:th {:style {:width "6em"}}]
[:th {:style {:width "10em"}}]
]]
[:tbody
(for [[client vendor amount] (get-1099-companies identity)]
@@ -92,12 +95,14 @@
(-> vendor :vendor/address :address/zip)
[:td amount]
[:td
[:button.button {:hx-get (bidi/path-for auto-ap.handler/all-routes
:company-1099-vendor-dialog
:vendor-id (:db/id vendor))
:hx-target "#modal-holder"
:hx-swap "innerHTML"}
[:span.icon [:i.fa.fa-pencil ]]]]]])]])
(if (cannot-overwrite? vendor)
[:a {:href "mailto:ben@integreatconsult.com"} "Contact Integreat"]
[:button.button {:hx-get (bidi/path-for ssr-routes/only-routes
:company-1099-vendor-dialog
:vendor-id (:db/id vendor))
:hx-target "#modal-holder"
:hx-swap "innerHTML"}
[:span.icon [:i.fa.fa-pencil ]]])]]])]])
(defn form-data->map [form-data]
(reduce-kv
@@ -109,28 +114,19 @@
(defn path->name [k]
(cond (keyword? k)
(str (namespace k) "_" (name k))
(str (namespace k) "/" (name k))
(seq k)
(str/join "_" (map path->name k))
:else k))
(defn vendor-save [{:keys [form-params identity route-params] :as request}]
(clojure.pprint/pprint form-params)
(clojure.pprint/pprint (form-data->map form-params))
@(d/transact conn [(remove-nils {:db/id (Long/parseLong (:vendor-id route-params))
:vendor/address (remove-nils
{:address/street1 (form-params "street1")
:address/street2 (form-params "street2")
:address/city (form-params "city")
:address/state (form-params "state")
:address/zip (form-params "zip")})
:vendor/legal-entity-first-name (form-params "legal-entity-first-name")
:vendor/legal-entity-middle-name (form-params "legal-entity-middle-name")
:vendor/legal-entity-last-name (form-params "legal-entity-last-name")
:vendor/legal-entity-tin (form-params "legal-entity-tin")
:vendor/legal-entity-1099-type (some->> (form-params "legal-entity-1099-type") (keyword "legal-entity-1099-type" ))
:vendor/legal-entity-tin-type (some->> (form-params "legal-entity-tin-type") (keyword "legal-entity-tin-type" ))})])
(when-not (cannot-overwrite? (d/pull (d/db conn) '[*] (Long/parseLong (:vendor-id route-params))))
@(d/transact conn [(remove-nils
(-> (form-data->map form-params)
(assoc :db/id (Long/parseLong (:vendor-id route-params)))
(update :vendor/legal-entity-1099-type #(some->> % (keyword "legal-entity-1099-type")))
(update :vendor/legal-entity-tin-type #(some->> % (keyword "legal-entity-tin-type")))))]))
(html-response
(table request :flash-id (Long/parseLong (:vendor-id route-params)))))
@@ -139,7 +135,7 @@
(let [vendor (d/pull (d/db conn) '[* {:vendor/legal-entity-1099-type [:db/ident]
:vendor/legal-entity-tin-type [:db/ident]}] (Long/parseLong (:vendor-id (:params request))))] ;; TODO perms
(html-response
[:form {:hx-post (bidi/path-for auto-ap.handler/all-routes
[:form {:hx-post (bidi/path-for ssr-routes/only-routes
:company-1099-vendor-save
:request-method :post
:vendor-id (Long/parseLong (:vendor-id (:params request))))
@@ -258,9 +254,10 @@
(defn page [{:keys [identity] :as request}]
(defn page [{:keys [identity matched-route] :as request}]
(base-page
[:div
(table request)]
[:div]))
[:div
(company-side-bar matched-route)]))