Start of adding the 1099 self service feature

This commit is contained in:
2023-01-13 09:45:52 -08:00
parent 46dd191391
commit f93c7fd9d0
5 changed files with 147 additions and 5 deletions

View File

@@ -0,0 +1,56 @@
;; This buffer is for Clojure experiments and evaluation.
;; Press C-j to evaluate the last expression.
;; You can also press C-u C-j to evaluate the expression and pretty-print its result.
(user/init-repl)
(clojure.data.csv/write-csv *out*
(->> (d/q '[:find
(pull ?c [:client/code])
(pull ?v [: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 $
:where [?p :payment/date ?d ]
[(>= ?d #inst "2022-01-01T08:00")]
[(< ?d #inst "2023-01-01T08:00")]
[?p :payment/client ?c]
[?p :payment/amount ?a]
[?p :payment/type :payment-type/check]
[?p :payment/vendor ?v]]
(d/db auto-ap.datomic/conn))
(filter (fn [[_ _ a]]
(>= a 600.0)))
(map (fn [[client vendor amount]]
[(:client/code client)
(:vendor/name vendor)
(some-> vendor :vendor/legal-entity-1099-type :db/ident name)
(-> vendor :vendor/legal-entity-first-name)
(-> vendor :vendor/legal-entity-middle-name)
(-> vendor :vendor/legal-entity-last-name)
(some-> vendor :vendor/legal-entity-tin-type :db/ident name)
(-> vendor :vendor/legal-entity-tin)
(-> vendor :vendor/address :address/street1)
(-> vendor :vendor/address :address/street2)
(-> vendor :vendor/address :address/city)
(-> vendor :vendor/address :address/state)
(-> vendor :vendor/address :address/zip)
amount
]))
(sort )
(into [["Client" "Vendor Name" "1099 Type" "First Name" "Middle Name" "Last Name" "TIN type" "TIN" "Street" "Street 2" "City" "State" "Zip"]]))
:quote? (constantly true))

View File

@@ -9,6 +9,7 @@
(if (authenticated? request)
(handler request)
{:status 401
:headers {"content-type" "text/html"}
:body "not authenticated"})))
(defn wrap-admin [handler]

View File

@@ -0,0 +1,85 @@
(ns auto-ap.ssr.company.company-1099
(:require
[auto-ap.datomic :refer [conn]]
[auto-ap.ssr.ui :refer [base-page]]
[auto-ap.graphql.utils :refer [can-see-client?]]
[datomic.api :as d]))
(defn test [x c]
(println x c))
(defn get-1099-companies [user]
(let [valid-clients (into #{} (map :db/id (:user/clients user)))]
(->> (d/q '[:find
(pull ?c [:client/code])
(pull ?v [: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 ))))
#_(map (fn [[client vendor amount]]
))
(defn page [{:keys [identity]}]
(println identity)
(get-1099-companies identity)
(base-page
[:div
[:table.table.grid.compact.is-fullwidth
[:thead
[:tr
[:td {:style {:width "5em"}}"Client"]
[:td "Vendor Name"]
[:td "Name"]
[:td {:style {:width "9em"}} "1099 Type"]
[:td {:style {:width "8em"}} "TIN"]
[:td "Address"]
[:td "Amount Paid"]
[:td {:style {:width "6em"}}]
]]
[:tbody
(for [[client vendor amount] (get-1099-companies identity)]
[:tr
[:td (:client/code client)]
[:td (:vendor/name vendor)]
[:td (-> vendor :vendor/legal-entity-first-name) " "
(-> vendor :vendor/legal-entity-middle-name) " "
(-> vendor :vendor/legal-entity-last-name)]
[:td (some-> vendor :vendor/legal-entity-1099-type :db/ident name)] " "
[:td
(some-> vendor :vendor/legal-entity-tin-type :db/ident name)
(-> vendor :vendor/legal-entity-tin)]
[:td
(-> vendor :vendor/address :address/street1) " "
(-> vendor :vendor/address :address/street2) " "
(-> vendor :vendor/address :address/city) " "
(-> vendor :vendor/address :address/state) " "
(-> vendor :vendor/address :address/zip)
[:td amount]
[:td]]])
]]]
[:div]))

View File

@@ -3,12 +3,11 @@
[auto-ap.routes.utils
:refer [wrap-admin wrap-client-redirect-unauthenticated wrap-secure]]
[auto-ap.ssr.admin :as admin]
[auto-ap.ssr-routes]))
[auto-ap.ssr.company.company-1099 :as company-1099]))
;; from auto-ap.ssr-routes, because they're shared
(def key->handler {:admin-history (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin admin/history)))
:admin-history-search (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin admin/history-search)))
:admin-history-inspect (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin admin/inspect)))})
:admin-history-inspect (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin admin/inspect)))
:company-1099 (wrap-client-redirect-unauthenticated (wrap-secure (wrap-admin company-1099/page)))})

View File

@@ -4,5 +4,6 @@
"/" :admin-history
#"/search/?" :admin-history-search
["/" [#"\d+" :entity-id] #"/?"] :admin-history-search
["/inspect/" [#"\d+" :entity-id] #"/?"] :admin-history-inspect}}})
["/inspect/" [#"\d+" :entity-id] #"/?"] :admin-history-inspect}}
"company" {"/1099" :company-1099}})