integrates new page into company section
This commit is contained in:
@@ -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))))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)]))
|
||||
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
#?(:cljs [re-frame.core :as re-frame])
|
||||
#?(:cljs [reagent.core :as r])))
|
||||
|
||||
(defn active-when [active-page f & rest]
|
||||
(when (apply f (into [active-page] rest)) " is-active"))
|
||||
|
||||
(defn deep-merge [v & vs]
|
||||
(letfn [(rec-merge [v1 v2]
|
||||
(if (and (map? v1) (map? v2))
|
||||
|
||||
83
src/cljc/auto_ap/shared_views/company/sidebar.cljc
Normal file
83
src/cljc/auto_ap/shared_views/company/sidebar.cljc
Normal file
@@ -0,0 +1,83 @@
|
||||
(ns auto-ap.shared-views.company.sidebar
|
||||
(:require [bidi.bidi :as bidi]
|
||||
[auto-ap.client-routes :as client-routes]
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
#?(:cljs [re-frame.core :as re-frame])
|
||||
#?(:cljs [reagent.core :as r])))
|
||||
|
||||
|
||||
(defn active-when [active-page f & rest]
|
||||
(when (apply f (into [active-page] rest)) " is-active"))
|
||||
|
||||
(defn deep-merge [v & vs]
|
||||
(letfn [(rec-merge [v1 v2]
|
||||
(if (and (map? v1) (map? v2))
|
||||
(merge-with deep-merge v1 v2)
|
||||
v2))]
|
||||
(when (some identity vs)
|
||||
(reduce #(rec-merge %1 %2) v vs))))
|
||||
|
||||
(def all-client-visible-routes
|
||||
["/" (deep-merge ssr-routes/routes (second client-routes/routes))])
|
||||
|
||||
(defn menu-item [{:keys [label route test-route active-route icon-class icon-style]}]
|
||||
[:p.menu-item
|
||||
[:a.item {:href (bidi/path-for all-client-visible-routes route)
|
||||
:class (when (test-route active-route) "is-active")}
|
||||
(if icon-style
|
||||
[:span {:class icon-class :style icon-style}]
|
||||
[:span {:class "icon"}
|
||||
[:i {:class icon-class}]])
|
||||
[:span {:class "name"} label]]])
|
||||
|
||||
(defn menu-item [{:keys [label route test-route active-route icon-class icon-style]}]
|
||||
[:p.menu-item
|
||||
[:a.item {:href (bidi/path-for all-client-visible-routes route)
|
||||
:class (when (test-route active-route) "is-active")}
|
||||
(if icon-style
|
||||
[:span {:class icon-class :style icon-style}]
|
||||
[:span {:class "icon"}
|
||||
[:i {:class icon-class}]])
|
||||
[:span {:class "name"} label]]])
|
||||
|
||||
(defn company-side-bar-impl [active-route]
|
||||
[:div
|
||||
(menu-item {:label "Reports"
|
||||
:route :reports
|
||||
:test-route #{:reports}
|
||||
:active-route active-route
|
||||
:icon-class "icon icon-receipt"
|
||||
:icon-style {:font-size "25px"}})
|
||||
|
||||
(menu-item {:label "Plaid Link"
|
||||
:route :plaid
|
||||
:test-route #{:plaid}
|
||||
:active-route active-route
|
||||
:icon-class "icon icon-saving-bank-1"
|
||||
:icon-style {:font-size "25px"}})
|
||||
(menu-item {:label "Yodlee Link"
|
||||
:route :yodlee2
|
||||
:test-route #{:yodlee2}
|
||||
:active-route active-route
|
||||
:icon-class "icon icon-saving-bank-1"
|
||||
:icon-style {:font-size "25px"}})
|
||||
|
||||
(menu-item {:label "Other"
|
||||
:route :company-other
|
||||
:test-route #{:company-other}
|
||||
:active-route active-route
|
||||
:icon-class "icon icon-cog-play-1"
|
||||
:icon-style {:font-size "25px"}})
|
||||
(menu-item {:label "1099 Info"
|
||||
:route :company-1099
|
||||
:test-route #{:company-1099}
|
||||
:active-route active-route
|
||||
:icon-class "icon icon-cog-play-1"
|
||||
:icon-style {:font-size "25px"}})])
|
||||
|
||||
#?(:clj
|
||||
(defn company-side-bar [active-page]
|
||||
(company-side-bar-impl active-page))
|
||||
:cljs
|
||||
(defn company-side-bar []
|
||||
(company-side-bar-impl @(re-frame/subscribe [:auto-ap.subs/active-page]))))
|
||||
@@ -9,3 +9,6 @@
|
||||
"/1099/vendor-dialog" {["/" [#"\d+" :vendor-id]] {:get :company-1099-vendor-dialog
|
||||
:post :company-1099-vendor-save}}}})
|
||||
|
||||
|
||||
(def only-routes ["/" routes])
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
[auto-ap.views.utils :refer [dispatch-event with-user]]
|
||||
[auto-ap.views.components.buttons :refer [fa-icon]]
|
||||
[auto-ap.views.components.layouts :refer [side-bar-layout]]
|
||||
[auto-ap.views.pages.company.side-bar :refer [company-side-bar]]
|
||||
[auto-ap.shared-views.company.sidebar :refer [company-side-bar]]
|
||||
[goog.crypt.base64 :as b64]
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.layouts :refer [side-bar-layout]]
|
||||
[auto-ap.views.pages.admin.plaid.table :as table]
|
||||
[auto-ap.views.pages.company.side-bar :refer [company-side-bar]]
|
||||
[auto-ap.shared-views.company.sidebar :refer [company-side-bar]]
|
||||
[auto-ap.views.pages.data-page :as data-page]
|
||||
[auto-ap.views.utils :refer [dispatch-event with-user]]
|
||||
[clojure.set :as set]
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.grid :as grid]
|
||||
[auto-ap.views.components.layouts :refer [side-bar-layout]]
|
||||
[auto-ap.views.pages.company.side-bar :refer [company-side-bar]]
|
||||
[auto-ap.shared-views.company.sidebar :refer [company-side-bar]]
|
||||
[auto-ap.views.pages.company.yodlee2.table :as table]
|
||||
[auto-ap.views.utils :refer [dispatch-event with-user]]
|
||||
[re-frame.core :as re-frame]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.layouts :refer [side-bar-layout]]
|
||||
[auto-ap.views.pages.data-page :as data-page]
|
||||
[auto-ap.views.pages.company.side-bar
|
||||
[auto-ap.shared-views.company.sidebar
|
||||
:as side-bar
|
||||
:refer [company-side-bar]]
|
||||
[auto-ap.views.pages.reports.table :as table]
|
||||
|
||||
Reference in New Issue
Block a user