Adds reports page.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
[auto-ap.datomic.migrate.add-general-ledger :as add-general-ledger]
|
||||
[auto-ap.datomic.migrate.audit :as audit]
|
||||
[auto-ap.datomic.migrate.clients :as clients]
|
||||
[auto-ap.datomic.migrate.reports :as reports]
|
||||
[auto-ap.datomic.migrate.invoice-converter
|
||||
:refer [add-import-status-existing-invoices]]
|
||||
[auto-ap.datomic.migrate.ledger :as ledger]
|
||||
@@ -497,6 +498,7 @@
|
||||
clients/norms-map
|
||||
ledger/norms-map
|
||||
yodlee2/norms-map
|
||||
reports/norms-map
|
||||
plaid/norms-map
|
||||
audit/norms-map
|
||||
vendors/norms-map)]
|
||||
|
||||
27
src/clj/auto_ap/datomic/migrate/reports.clj
Normal file
27
src/clj/auto_ap/datomic/migrate/reports.clj
Normal file
@@ -0,0 +1,27 @@
|
||||
(ns auto-ap.datomic.migrate.reports)
|
||||
|
||||
(def norms-map {::add-reports
|
||||
{:txes [[{:db/ident :report/client
|
||||
:db/doc "Which client(s) this is for"
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/many}
|
||||
|
||||
{:db/ident :report/name
|
||||
:db/doc "A description for the report"
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/one}
|
||||
|
||||
{:db/ident :report/key
|
||||
:db/doc "The s3 key for the report"
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/one}
|
||||
|
||||
{:db/ident :report/created
|
||||
:db/doc "When this report was created"
|
||||
:db/valueType :db.type/instant
|
||||
:db/cardinality :db.cardinality/one}
|
||||
|
||||
{:db/ident :report/url
|
||||
:db/doc "Where to download the report"
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/one}]]}})
|
||||
64
src/clj/auto_ap/datomic/reports.clj
Normal file
64
src/clj/auto_ap/datomic/reports.clj
Normal file
@@ -0,0 +1,64 @@
|
||||
(ns auto-ap.datomic.reports
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer [add-sorter-fields apply-pagination apply-sort-3 conn merge-query]]
|
||||
[auto-ap.graphql.utils :refer [can-see-client? limited-clients]]
|
||||
[clj-time.coerce :as c]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn raw-graphql-ids [db args]
|
||||
(let [query (cond-> {:query {:find []
|
||||
:in ['$ ]
|
||||
:where []}
|
||||
:args [db]}
|
||||
|
||||
|
||||
(:client-id args)
|
||||
(merge-query {:query {:in ['?client-id]
|
||||
:where ['[?e :report/client ?client-id]]}
|
||||
:args [(:client-id args)]})
|
||||
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :report/client ?xx]]}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
||||
(:sort args) (add-sorter-fields {"client" ['[?e :report/client ?c]
|
||||
'[?c :client/name ?sort-client]]
|
||||
"created" ['[?e :report/created ?sort-created]]
|
||||
"name" ['[?e :report/name ?sort-name]
|
||||
]}
|
||||
args)
|
||||
|
||||
true
|
||||
(merge-query {:query {:find ['?sort-default '?e] :where ['[?e :report/created ?sort-default]]}}))]
|
||||
(->> query
|
||||
(d/query)
|
||||
(apply-sort-3 (update args :sort conj {:sort-key "default-2" :asc true}))
|
||||
(apply-pagination args))))
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
(let [results (->> (d/pull-many db '[:db/id :report/client :report/created :report/url :report/name]
|
||||
ids)
|
||||
(map #(update % :report/created c/from-date))
|
||||
(group-by :db/id))]
|
||||
(->> ids
|
||||
(map results)
|
||||
(filter identity)
|
||||
|
||||
(map first)
|
||||
(filter (fn [r]
|
||||
(every?
|
||||
#(can-see-client? (:id args) %)
|
||||
(map :db/id (:report/client r))))))))
|
||||
|
||||
(defn get-graphql [args]
|
||||
(let [db (d/db conn)
|
||||
{ids-to-retrieve :ids matching-count :count} (raw-graphql-ids db args)]
|
||||
|
||||
[(->> (graphql-results ids-to-retrieve db args))
|
||||
matching-count]))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
[auto-ap.graphql.expected-deposit :as gq-expected-deposit]
|
||||
[auto-ap.graphql.import-batch :as gq-import-batches]
|
||||
[auto-ap.graphql.intuit-bank-accounts :as gq-intuit-bank-accounts]
|
||||
[auto-ap.graphql.reports :as gq-reports]
|
||||
[auto-ap.graphql.invoices :as gq-invoices]
|
||||
[auto-ap.graphql.ledger :as gq-ledger]
|
||||
[auto-ap.graphql.requests :as gq-requests]
|
||||
@@ -789,6 +790,7 @@
|
||||
:get-vendor gq-vendors/get-graphql})
|
||||
gq-checks/attach
|
||||
gq-ledger/attach
|
||||
gq-reports/attach
|
||||
gq-plaid/attach
|
||||
gq-import-batches/attach
|
||||
gq-transactions/attach
|
||||
|
||||
81
src/clj/auto_ap/graphql/reports.clj
Normal file
81
src/clj/auto_ap/graphql/reports.clj
Normal file
@@ -0,0 +1,81 @@
|
||||
(ns auto-ap.graphql.reports
|
||||
(:require
|
||||
[amazonica.aws.s3 :as s3]
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.datomic.reports :as r]
|
||||
[auto-ap.graphql.utils :refer [<-graphql assert-admin result->page]]
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[config.core :refer [env]]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn get-report-page [context args _]
|
||||
(let [args (assoc args :id (:id context))
|
||||
[reports reports-count] (r/get-graphql (assoc (<-graphql (:filters args))
|
||||
:id (:id context)))]
|
||||
(result->page reports reports-count :reports (:filters args)))
|
||||
)
|
||||
|
||||
(defn delete-report [context args _]
|
||||
(assert-admin (:id context))
|
||||
(let [[id-to-delete key] (first (d/q '[:find ?i ?k
|
||||
:in $ ?i
|
||||
:where [?i :report/key ?k]]
|
||||
(d/db conn)
|
||||
(:id args)))]
|
||||
(when id-to-delete
|
||||
(s3/delete-object :bucket-name (:data-bucket env)
|
||||
:key key)
|
||||
@(d/transact conn [[:db/retractEntity id-to-delete]]))
|
||||
{:message (format "deleted %s successfully" key)}))
|
||||
|
||||
|
||||
|
||||
|
||||
(def objects
|
||||
{:report
|
||||
{:fields {:url {:type 'String}
|
||||
:name {:type 'String}
|
||||
:created {:type :iso_date}
|
||||
:id {:type :id}}}
|
||||
|
||||
:report_page
|
||||
{:fields {:reports {:type '(list :report)}
|
||||
:count {:type 'Int}
|
||||
:total {:type 'Int}
|
||||
:start {:type 'Int}
|
||||
:end {:type 'Int}}}})
|
||||
|
||||
(def queries
|
||||
{:report_page {:type :report_page
|
||||
:args {:filters {:type :report_filters}}
|
||||
:resolve :get-report-page}})
|
||||
|
||||
(def mutations
|
||||
{:delete_report {:type :message
|
||||
:args {:id {:type :id}}
|
||||
:resolve :mutation/delete-report}})
|
||||
|
||||
(def input-objects
|
||||
{:report_filters
|
||||
{:fields {:client_id {:type :id}
|
||||
:start {:type 'Int}
|
||||
:per_page {:type 'Int}
|
||||
:sort {:type '(list :sort_item)}}}})
|
||||
|
||||
(def enums
|
||||
{})
|
||||
|
||||
(def resolvers
|
||||
{:get-report-page get-report-page
|
||||
:mutation/delete-report delete-report})
|
||||
|
||||
|
||||
(defn attach [schema]
|
||||
(->
|
||||
(merge-with merge schema
|
||||
{:objects objects
|
||||
:queries queries
|
||||
:mutations mutations
|
||||
:input-objects input-objects
|
||||
:enums enums})
|
||||
(attach-resolvers resolvers)))
|
||||
@@ -9,7 +9,8 @@
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
[config.core :refer [env]]
|
||||
[datomic.api :as d])
|
||||
[datomic.api :as d]
|
||||
[clojure.tools.logging :as log])
|
||||
(:import
|
||||
(java.io ByteArrayOutputStream)
|
||||
(java.text DecimalFormat)
|
||||
@@ -498,12 +499,32 @@
|
||||
output-stream)
|
||||
(.toByteArray output-stream)))
|
||||
|
||||
(defn args->name [args]
|
||||
(let [min-date (atime/unparse-local
|
||||
(->> args :periods (map :start) first)
|
||||
atime/iso-date)
|
||||
max-date (atime/unparse-local
|
||||
(->> args :periods (map :end) last)
|
||||
atime/iso-date)
|
||||
names (str/replace (->> args :client_ids (d/pull-many (d/db conn) [:client/name]) (map :client/name) (str/join "-")) #" " "_" )]
|
||||
(format "Profit-and-loss-%s-to-%s-for-%s" min-date max-date names)))
|
||||
|
||||
(defn print-pnl [args data]
|
||||
(let [uuid (str (UUID/randomUUID))
|
||||
pdf-data (make-pnl args data)]
|
||||
pdf-data (make-pnl args data)
|
||||
name (args->name args)
|
||||
key (str "reports/pnl/" uuid "/ " name ".pdf")
|
||||
url (str "http://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/" key)]
|
||||
(s3/put-object :bucket-name (:data-bucket env)
|
||||
:key (str "reports/pnl/" uuid ".pdf")
|
||||
:key key
|
||||
:input-stream (io/make-input-stream pdf-data {})
|
||||
:metadata {:content-length (count pdf-data)
|
||||
:content-type "application/pdf"})
|
||||
(str "https://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/reports/pnl/" uuid ".pdf")))
|
||||
@(d/transact conn
|
||||
[{:report/name name
|
||||
:report/client (:client_ids args)
|
||||
:report/key key
|
||||
:report/url url
|
||||
:report/created (java.util.Date.)}])
|
||||
url
|
||||
))
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
"requires-feedback" :requires-feedback-transactions
|
||||
|
||||
"excluded" :excluded-transactions}
|
||||
"reports/" {"" :reports}
|
||||
"ledger/" {"" :ledger
|
||||
"profit-and-loss" :profit-and-loss
|
||||
"balance-sheet" :balance-sheet
|
||||
|
||||
@@ -46,7 +46,8 @@
|
||||
[navbar-drop-down {:header [:span [:span.icon [:i.fa.fa-user] ]
|
||||
[:span (:user/name @user)]] :id ::account}
|
||||
[:div
|
||||
[:a {:class "navbar-item"} "My profile"]
|
||||
[:a {:class "navbar-item"
|
||||
:href (bidi/path-for routes/routes :reports)} "My company"]
|
||||
(when (= "admin" (:user/role @user))
|
||||
[:a {:class "navbar-item" :href (bidi/path-for routes/routes :admin)} "Administration"])
|
||||
[:hr {:class "navbar-divider"}]
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
(ns auto-ap.views.main
|
||||
(:require
|
||||
[re-frame.core :as re-frame]
|
||||
[bidi.bidi :as bidi]
|
||||
[auto-ap.routes :as routes]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.views.utils :refer [active-when active-when= login-url dispatch-event]]
|
||||
[auto-ap.views.components.layouts :refer [side-bar-layout loading-layout]]
|
||||
[auto-ap.views.components.layouts :refer [loading-layout]]
|
||||
[auto-ap.views.pages.unpaid-invoices :refer [unpaid-invoices-page paid-invoices-page all-invoices-page voided-invoices-page]]
|
||||
[auto-ap.views.pages.import-invoices :refer [import-invoices-page]]
|
||||
[auto-ap.views.pages.needs-activation :refer [needs-activation-page]]
|
||||
[auto-ap.views.pages.transactions :refer [transactions-page]]
|
||||
[auto-ap.views.pages.ledger :refer [ledger-page]]
|
||||
[auto-ap.views.pages.reports :refer [reports-page]]
|
||||
[auto-ap.views.pages.error :refer [error-page]]
|
||||
[auto-ap.views.pages.ledger.balance-sheet :refer [balance-sheet-page]]
|
||||
[auto-ap.views.pages.ledger.external-import :refer [external-import-page]]
|
||||
@@ -32,8 +29,7 @@
|
||||
[auto-ap.views.pages.admin.import-batches :refer [import-batches-page]]
|
||||
[auto-ap.views.pages.admin.yodlee :refer [admin-yodlee-page]]
|
||||
[auto-ap.views.pages.admin.yodlee2 :as yodlee2]
|
||||
[auto-ap.views.pages.admin.plaid :as plaid]
|
||||
[auto-ap.entities.clients :as clients]))
|
||||
[auto-ap.views.pages.admin.plaid :as plaid]))
|
||||
|
||||
(defmulti page (fn [active-page] active-page))
|
||||
(defmethod page :unpaid-invoices [_]
|
||||
@@ -43,6 +39,8 @@
|
||||
(defmethod page :import-invoices [_]
|
||||
(import-invoices-page ))
|
||||
|
||||
(defmethod page :reports [_]
|
||||
(reports-page ))
|
||||
|
||||
(defmethod page :paid-invoices [_]
|
||||
^{:key :paid}
|
||||
|
||||
17
src/cljs/auto_ap/views/pages/company/side_bar.cljs
Normal file
17
src/cljs/auto_ap/views/pages/company/side_bar.cljs
Normal file
@@ -0,0 +1,17 @@
|
||||
(ns auto-ap.views.pages.company.side-bar
|
||||
(:require
|
||||
[auto-ap.routes :as routes]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.utils :refer [active-when]]
|
||||
[bidi.bidi :as bidi]
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
(defn company-side-bar []
|
||||
(let [ap @(re-frame/subscribe [::subs/active-page])]
|
||||
[:div
|
||||
[:ul.menu-list
|
||||
[:li.menu-item
|
||||
[:a.item {:href (bidi/path-for routes/routes :reports)
|
||||
:class [(active-when ap = :reports)]}
|
||||
[:span {:class "icon icon-receipt" :style {:font-size "25px"}}]
|
||||
[:span {:class "name"} "Reports"]]]]]))
|
||||
78
src/cljs/auto_ap/views/pages/reports.cljs
Normal file
78
src/cljs/auto_ap/views/pages/reports.cljs
Normal file
@@ -0,0 +1,78 @@
|
||||
(ns auto-ap.views.pages.reports
|
||||
(:require
|
||||
[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
|
||||
:as side-bar
|
||||
:refer [company-side-bar]]
|
||||
[auto-ap.views.pages.reports.table :as table]
|
||||
[auto-ap.views.utils :refer [with-user]]
|
||||
[clojure.set :as set]
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]
|
||||
[vimsical.re-frame.fx.track :as track]))
|
||||
|
||||
(defn data-params->query-params [params]
|
||||
{:start (:start params 0)
|
||||
:sort (:sort params)
|
||||
:per-page (:per-page params)
|
||||
:client-id (:id @(re-frame/subscribe [::subs/client]))})
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-change
|
||||
[with-user]
|
||||
(fn [{:keys [user]} [_ params]]
|
||||
{:graphql {:token user
|
||||
:owns-state {:single [::data-page/page ::page]}
|
||||
:query-obj {:venia/queries [[:report-page
|
||||
{:filters (data-params->query-params params)}
|
||||
[[:reports [:id
|
||||
:name
|
||||
:created
|
||||
:url]]
|
||||
:total
|
||||
:start
|
||||
:end]]]}
|
||||
:on-success (fn [result]
|
||||
[::data-page/received ::page (set/rename-keys (:report-page result)
|
||||
{:reports :data})])}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted
|
||||
(fn [_ _]
|
||||
{:dispatch [::data-page/dispose ::page]
|
||||
::track/dispose {:id ::params}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::mounted
|
||||
(fn [_ _]
|
||||
{::track/register {:id ::params
|
||||
:subscription [::data-page/params ::page]
|
||||
:event-fn (fn [params] [::params-change params])}}))
|
||||
|
||||
|
||||
|
||||
(defn ledger-content []
|
||||
(let [_ @(re-frame/subscribe [::subs/client])]
|
||||
[:div
|
||||
[:h1.title "Reports"]
|
||||
[table/table {:id :reports
|
||||
:data-page ::page}]]))
|
||||
|
||||
|
||||
(defn reports-page []
|
||||
(let [user (re-frame/subscribe [::subs/user])]
|
||||
(reagent/create-class
|
||||
{:display-name "report-page"
|
||||
:component-did-mount #(re-frame/dispatch [::mounted])
|
||||
:component-will-unmount #(re-frame/dispatch [::unmounted])
|
||||
:reagent-render
|
||||
(fn []
|
||||
(if (not= "manager" (:user/role @user))
|
||||
[side-bar-layout
|
||||
{:side-bar [company-side-bar {:data-page ::page}]
|
||||
:main [ledger-content]}]
|
||||
[:div "Not authorized"]))})))
|
||||
|
||||
64
src/cljs/auto_ap/views/pages/reports/table.cljs
Normal file
64
src/cljs/auto_ap/views/pages/reports/table.cljs
Normal file
@@ -0,0 +1,64 @@
|
||||
(ns auto-ap.views.pages.reports.table
|
||||
(:require
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.buttons :as buttons]
|
||||
[auto-ap.views.components.grid :as grid]
|
||||
[auto-ap.views.pages.data-page :as data-page]
|
||||
[auto-ap.views.utils :refer [action-cell-width date->str dispatch-event]]
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::delete-report
|
||||
(fn [{:keys [db]} [_ {id :id data-page :data-page}]]
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:owns-state {:single ::delete}
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "DeleteReport"}
|
||||
:venia/queries [{:query/data [:delete-report
|
||||
{:id id}
|
||||
[:message]]}]}
|
||||
:on-success (fn [result]
|
||||
[::data-page/updated-entity data-page {:name "deleted"}]
|
||||
#_[::invoice-updated ()(:void-invoice result)])}}))
|
||||
|
||||
(defn row [{{:keys [name created url id] :as i} :row is-admin? :is-admin? data-page :data-page}]
|
||||
[:<>
|
||||
[grid/row {:class (:class i) :id id}
|
||||
[grid/cell {} name]
|
||||
[grid/cell {} (date->str created) ]
|
||||
[grid/button-cell {}
|
||||
[:div.buttons
|
||||
(when (not= "deleted" name)
|
||||
[buttons/fa-icon {:icon "fa-external-link"
|
||||
:href url}])
|
||||
(when (not= "deleted" name)
|
||||
|
||||
(when is-admin?
|
||||
[buttons/fa-icon {:icon "fa-trash"
|
||||
:on-click (dispatch-event [::delete-report {:id id :data-page data-page}])}]))]]]])
|
||||
|
||||
(defn table [{:keys [data-page id]}]
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::data-page/page data-page])
|
||||
is-admin? @(re-frame/subscribe [::subs/is-admin?])]
|
||||
[:div
|
||||
[status/status-notification {:statuses [[::status/single ::delete]]}]
|
||||
[grid/grid {:data-page data-page
|
||||
:column-count 3}
|
||||
[grid/controls data]
|
||||
[grid/table {:fullwidth true :class ["wrappable"]}
|
||||
[grid/header
|
||||
[grid/row {}
|
||||
[grid/sortable-header-cell {:sort-key "name" :sort-name "Name"} "Name"]
|
||||
[grid/sortable-header-cell {:sort-key "created" :sort-name "Created" :style {:width "8em"}} "Created"]
|
||||
[grid/header-cell {:style {:width (action-cell-width (if
|
||||
is-admin?
|
||||
2
|
||||
1))}}]
|
||||
]]
|
||||
[grid/body
|
||||
(for [i (:data data)]
|
||||
^{:key (:id i)}
|
||||
[row {:row i :is-admin? is-admin? :data-page data-page}])]]]]))
|
||||
|
||||
Reference in New Issue
Block a user