undoing commit.
This commit is contained in:
@@ -3,9 +3,7 @@
|
||||
[auto-ap.forms :as forms]
|
||||
[auto-ap.ledger.reports :as l-reports]
|
||||
[auto-ap.status :as status]
|
||||
[clojure.string :as str]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.modal :as modal]
|
||||
[auto-ap.views.components.layouts
|
||||
:refer [appearing-side-bar side-bar-layout]]
|
||||
[auto-ap.views.components.switch-field :refer [switch-field]]
|
||||
@@ -24,7 +22,6 @@
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]
|
||||
[vimsical.re-frame.fx.track :as track]
|
||||
[vimsical.re-frame.cofx.inject :as inject]
|
||||
[auto-ap.views.pages.ledger.report-table :as rtable]))
|
||||
|
||||
(defn data-params->query-params [params]
|
||||
@@ -72,68 +69,25 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::report-requested
|
||||
[with-user (forms/in-form ::form) (re-frame/inject-cofx ::inject/sub [::subs/client])]
|
||||
(fn [{:keys [db user ::subs/client]} [_]]
|
||||
[with-user (forms/in-form ::form)]
|
||||
(fn [{:keys [db user]} [_]]
|
||||
{:db (dissoc db :report)
|
||||
:graphql {:token user
|
||||
:query-obj {:venia/queries [[:balance-sheet
|
||||
(-> (:data db)
|
||||
(assoc :client-id (:id client))
|
||||
(update :date (fnil #(date->str % standard) nil))
|
||||
(update :comparison-date (fnil #(date->str % standard) nil)))
|
||||
(assoc (:data db)
|
||||
:client-id (:id @(re-frame/subscribe [::subs/client])))
|
||||
[[:balance-sheet-accounts [:name :amount :account-type :id :numeric-code]]
|
||||
[:comparable-balance-sheet-accounts [:name :amount :account-type :id :numeric-code]]]]]}
|
||||
|
||||
:owns-state {:single ::page}
|
||||
:on-success [::received]}}))
|
||||
|
||||
(defn email-body [report-url]
|
||||
(js/encodeURIComponent
|
||||
(str
|
||||
"Hello,
|
||||
Click here (" report-url ") to download your financial reports. We have not finished reviewing and reconciling these numbers with you. Please review and let us know if anything seems missing or in need of correction.
|
||||
Click here (http://app.integreatconsult.com/) to login to the Financials app to review the details here.
|
||||
Click here (https://share.vidyard.com/watch/MHTo5PyXPxXUpVH93RWFM9?) for a video on how to run a P&L on your own.
|
||||
To see a history of past financial reports, click here: https://app.integreatconsult.com/reports/
|
||||
|
||||
NOTE: Please review the transactions we may have question for you here: https://app.integreatconsult.com/transactions/requires-feedback. You can either edit the transaction to what expense account it should be or email back what it should be.")))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::received-pdf
|
||||
[(re-frame/inject-cofx ::inject/sub [::subs/client])]
|
||||
(fn [{:keys [::subs/client]} [_ result]]
|
||||
{:dispatch [::modal/modal-requested {:title "Your report is ready"
|
||||
:body [:div
|
||||
[:div "Click "
|
||||
[:a {:href (-> result :balance-sheet-pdf :url) :target "_new"} "here"] " to view it."]
|
||||
(when (seq (:emails client))
|
||||
[:div "Once you've confirmed you're happy with it, click "
|
||||
[:a {:href (str "mailto:" (str/join ";" (map :email (:emails client))) "?body=" (email-body (-> result :balance-sheet-pdf :url))
|
||||
"&subject=" (-> result :balance-sheet-pdf :name) " is ready")}
|
||||
"here"] " to open your email client and to send it to " (str/join "," (map (fn [e]
|
||||
(str (:email e) " (" (:description e) ")"))
|
||||
(:emails client))) "."])]}]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::export-pdf
|
||||
[with-user (forms/in-form ::form) (re-frame/inject-cofx ::inject/sub [::subs/client])]
|
||||
(fn [{:keys [db user ::subs/client]} [_]]
|
||||
{:db (dissoc db :report)
|
||||
:graphql {:token user
|
||||
:query-obj {:venia/queries [[:balance-sheet-pdf
|
||||
(-> (:data db)
|
||||
(assoc :client-id (:id client))
|
||||
(update :date (fnil #(date->str % standard) nil))
|
||||
(update :comparison-date (fnil #(date->str % standard) nil)))
|
||||
[:url :name]]]}
|
||||
|
||||
:owns-state {:single ::page}
|
||||
:on-success [::received-pdf]}}))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::investigate-clicked
|
||||
(fn [{:keys [db]} [_ {:keys [from-numeric-code to-numeric-code date-range]}]]
|
||||
(fn [{:keys [db]} [_ {:keys [from-numeric-code to-numeric-code date-range] :as g}]]
|
||||
(println g)
|
||||
|
||||
{:db (-> db (assoc ::ledger-list-active? true))
|
||||
:dispatch [::data-page/additional-params-changed ::ledger {:client-id (:id @(re-frame/subscribe [::subs/client]))
|
||||
:from-numeric-code from-numeric-code
|
||||
@@ -172,17 +126,15 @@ NOTE: Please review the transactions we may have question for you here: https://
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted-balance-sheet
|
||||
(fn [{:keys [db]} _]
|
||||
{
|
||||
:db (dissoc db ::ledger-list-active?)
|
||||
:dispatch [::data-page/dispose ::ledger]
|
||||
(fn [_ _]
|
||||
{:dispatch [::data-page/dispose ::ledger]
|
||||
::track/dispose {:id ::ledger-params}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::mounted-balance-sheet
|
||||
(fn [{:keys [db]} _]
|
||||
{:db (forms/start-form db ::form {:date (local-now)
|
||||
:comparison-date (t/minus (local-now) (t/years 1))
|
||||
{:db (forms/start-form db ::form {:date (date->str (local-now) standard)
|
||||
:comparison-date (date->str (t/minus (local-now) (t/years 1)) standard)
|
||||
:include-comparison true})
|
||||
::track/register {:id ::ledger-params
|
||||
:subscription [::data-page/params ::ledger]
|
||||
@@ -199,6 +151,7 @@ NOTE: Please review the transactions we may have question for you here: https://
|
||||
{:keys [data]} @(re-frame/subscribe [::forms/form ::form])]
|
||||
(form-inline {}
|
||||
[:div
|
||||
[status/status-notification {:statuses [[::status/single ::page]]}]
|
||||
[:div.report-controls
|
||||
[:div.level
|
||||
[:div.level-left
|
||||
@@ -206,8 +159,7 @@ NOTE: Please review the transactions we may have question for you here: https://
|
||||
[:div.control
|
||||
[:p.help "Date"]
|
||||
(raw-field
|
||||
[date-picker-friendly {:cljs-date? true
|
||||
:type "date"
|
||||
[date-picker-friendly {:type "date"
|
||||
:field [:date]}])]]
|
||||
[:div.level-item
|
||||
[:div.control
|
||||
@@ -224,9 +176,8 @@ NOTE: Please review the transactions we may have question for you here: https://
|
||||
[:div.control
|
||||
[:p.help "Comparison Date"]
|
||||
(raw-field
|
||||
[date-picker-friendly {:cljs-date? true
|
||||
:type "date"
|
||||
:field [:comparison-date]}])])]]
|
||||
[date-picker-friendly {:type "date"
|
||||
:field [:comparison-date]}])])]]
|
||||
[:div.level-right
|
||||
[:div.buttons
|
||||
|
||||
@@ -245,14 +196,18 @@ NOTE: Please review the transactions we may have question for you here: https://
|
||||
(assoc b
|
||||
:period (:comparison-date args)
|
||||
:amount (js/parseFloat (:amount b)))))))
|
||||
|
||||
client-names (->> @(re-frame/subscribe [::subs/clients-by-id])
|
||||
(map (fn [[k v]]
|
||||
[k (:name v)]))
|
||||
(into {}))
|
||||
pnl-data (l-reports/->PNLData args pnl-data client-names)
|
||||
report (l-reports/summarize-balance-sheet pnl-data)]
|
||||
[rtable/table {:widths (cond-> [30 13]
|
||||
(:include-comparison args) (into [13 13]))
|
||||
[rtable/table {:widths (into [30 13
|
||||
(when (:include-comparison args)
|
||||
13)
|
||||
(when (:include-comparison args)
|
||||
13)])
|
||||
:click-event ::investigate-clicked
|
||||
:table report}]))
|
||||
|
||||
@@ -265,6 +220,7 @@ NOTE: Please review the transactions we may have question for you here: https://
|
||||
[status/status-notification {:statuses [[::status/single ::page]]}]
|
||||
[report-form]
|
||||
|
||||
|
||||
[status/big-loader status]
|
||||
(when (and (not= :loading (:state status))
|
||||
report)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.pages.ledger.report-table :as rtable]
|
||||
[auto-ap.utils :refer [dollars-0?]]
|
||||
[auto-ap.views.components.buttons :as buttons]
|
||||
[auto-ap.views.components.layouts
|
||||
:refer [appearing-side-bar side-bar-layout]]
|
||||
@@ -17,6 +18,8 @@
|
||||
[auto-ap.views.utils
|
||||
:refer [date->str
|
||||
date-picker-friendly
|
||||
->$
|
||||
->%
|
||||
dispatch-event
|
||||
local-today
|
||||
multi-field
|
||||
@@ -68,7 +71,7 @@
|
||||
(re-frame/reg-event-fx
|
||||
::report-requested
|
||||
[with-user (forms/in-form ::form)]
|
||||
(fn [{:keys [db user]}]
|
||||
(fn [{:keys [db user] :as cofx}]
|
||||
(cond-> {:graphql {:token user
|
||||
:owns-state {:single ::page}
|
||||
:query-obj {:venia/queries [[:profit-and-loss
|
||||
@@ -135,7 +138,7 @@ NOTE: Please review the transactions we may have question for you here: https://
|
||||
(re-frame/reg-event-db
|
||||
::change-internal
|
||||
(forms/change-handler ::form
|
||||
(fn [_ field value]
|
||||
(fn [data field value]
|
||||
(cond
|
||||
(= [:periods] field)
|
||||
[field value]
|
||||
@@ -203,7 +206,8 @@ NOTE: Please review the transactions we may have question for you here: https://
|
||||
(re-frame/reg-event-fx
|
||||
::investigate-clicked
|
||||
(fn [{:keys [db]} [_ {:keys [location from-numeric-code to-numeric-code client-id]
|
||||
{:keys [start end]} :date-range}]]
|
||||
{:keys [start end]} :date-range
|
||||
:as g}]]
|
||||
{:db (-> db (assoc ::ledger-list-active? true))
|
||||
:dispatch [::data-page/additional-params-changed ::ledger {:client-id client-id
|
||||
:from-numeric-code from-numeric-code
|
||||
@@ -215,7 +219,7 @@ NOTE: Please review the transactions we may have question for you here: https://
|
||||
|
||||
(re-frame/reg-sub
|
||||
::can-submit
|
||||
(fn [_]
|
||||
(fn [db]
|
||||
true))
|
||||
|
||||
(def pnl-form (forms/vertical-form {:can-submit [::can-submit]
|
||||
@@ -233,12 +237,12 @@ NOTE: Please review the transactions we may have question for you here: https://
|
||||
])
|
||||
@box)))
|
||||
|
||||
(defn report-controls [_]
|
||||
(defn report-controls [pnl-form]
|
||||
(let [!box (reagent/atom nil)
|
||||
active (reagent/atom nil)]
|
||||
(fn [pnl-form]
|
||||
(let [{:keys [raw-field]} pnl-form
|
||||
{:keys [data]} @(re-frame/subscribe [::forms/form ::form])
|
||||
(let [{:keys [form-inline field raw-field error-notification submit-button ]} pnl-form
|
||||
{:keys [data report active? error id]} @(re-frame/subscribe [::forms/form ::form])
|
||||
{:keys [periods selected-period include-deltas]} data]
|
||||
[:div.report-controls
|
||||
[:div.level.mb-2
|
||||
|
||||
@@ -100,13 +100,6 @@
|
||||
e
|
||||
(date->str (time/from-default-time-zone (c/from-date e)) standard))))))
|
||||
|
||||
(defn dispatch-cljs-date-change [event]
|
||||
(fn [e g]
|
||||
(re-frame/dispatch (conj event
|
||||
(if (str/blank? e)
|
||||
e
|
||||
(time/from-default-time-zone (c/from-date e)))))))
|
||||
|
||||
;; TODO inline on-changes causes each field to be rerendered each time. When we fix this
|
||||
;; let's make sure that we find away not to trigger a re-render for every component any time any form field
|
||||
;; changes
|
||||
@@ -312,10 +305,10 @@
|
||||
(let [field (if (keyword? field) [field] field)
|
||||
event (if (keyword? event) [event] event)
|
||||
selected (get-in subscription field)
|
||||
|
||||
selected (cond (string? selected)
|
||||
(c/to-date (time/to-default-time-zone (time/from-default-time-zone (str->date selected standard))))
|
||||
|
||||
|
||||
(instance? goog.date.DateTime selected)
|
||||
(c/to-date (time/to-default-time-zone (time/from-default-time-zone selected)))
|
||||
|
||||
@@ -324,10 +317,9 @@
|
||||
|
||||
:else
|
||||
selected )
|
||||
|
||||
keys (assoc keys
|
||||
:on-change (when (:cljs-date? keys)
|
||||
(dispatch-date-change (conj event field))
|
||||
(dispatch-cljs-date-change (conj event field)))
|
||||
:on-change (dispatch-date-change (conj event field))
|
||||
:selected selected
|
||||
:class (str class
|
||||
(when (and spec (not (s/valid? spec (get-in subscription field))))
|
||||
@@ -459,6 +451,8 @@
|
||||
:next-month-label ""
|
||||
:type "date")])
|
||||
|
||||
|
||||
|
||||
(defn local-now []
|
||||
(t/to-default-time-zone (t/now)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user