diff --git a/iol_ion/src/iol_ion/query.clj b/iol_ion/src/iol_ion/query.clj index 097e9fae..7d6cf642 100644 --- a/iol_ion/src/iol_ion/query.clj +++ b/iol_ion/src/iol_ion/query.clj @@ -241,7 +241,7 @@ ([db client-id ^java.util.Date end ^java.util.Date start] (for [running-balance-set (account-sets db client-id) - :let [{:keys [account-id client-id location current-balance debits credits count]} + :let [{:keys [account-id client-id location current-balance debits credits count sample]} (->> running-balance-set (filter (fn until-end [^Line l] (let [^java.util.Date d (.-date l)] @@ -259,13 +259,15 @@ :current-balance (.-running-balance l) :account-id (.-account-id l) :client-id (.-client-id l) - :location (.-location l))) + :location (.-location l) + :sample (.-id l))) (transient {:count 0 :debits 0.0 :credits 0.0 :current-balance 0.0})))] :when client-id] - [client-id account-id location debits credits current-balance count]))) + (do + [client-id account-id location debits credits current-balance count sample])))) (comment diff --git a/src/clj/auto_ap/ssr/ledger/profit_and_loss.clj b/src/clj/auto_ap/ssr/ledger/profit_and_loss.clj index 30e33fe3..f357e181 100644 --- a/src/clj/auto_ap/ssr/ledger/profit_and_loss.clj +++ b/src/clj/auto_ap/ssr/ledger/profit_and_loss.clj @@ -8,7 +8,7 @@ [auto-ap.ledger.reports :as l-reports] [auto-ap.logging :as alog] [auto-ap.pdf.ledger :refer [table->pdf]] - [auto-ap.permissions :refer [wrap-must]] + [auto-ap.permissions :refer [can? wrap-must]] [auto-ap.routes.ledger :as route] [auto-ap.routes.utils :refer [wrap-client-redirect-unauthenticated]] @@ -86,7 +86,7 @@ data (into [] (for [client-id client-ids p periods - [client-id account-id location debits credits balance count] (iol-ion.query/detailed-account-snapshot (dc/db conn) client-id (coerce/to-date (:end p)) (coerce/to-date (:start p))) + [client-id account-id location debits credits balance count sample] (iol-ion.query/detailed-account-snapshot (dc/db conn) client-id (coerce/to-date (:end p)) (coerce/to-date (:start p))) :let [account ((or (lookup-account client-id) {}) account-id)]] {:client-id client-id :account-id account-id @@ -102,6 +102,7 @@ :account-type (:account_type account) :numeric-code (:numeric_code account) :name (:name account) + :sample sample :period {:start ( coerce/to-date (:start p)) :end (coerce/to-date (time/plus (:end p) (time/days 1)))}})) args (assoc (:form-params request) :periods (map (fn [d] {:start ( coerce/to-date (:start d)) :end ( coerce/to-date (:end d))}) periods)) @@ -130,14 +131,26 @@ (list [:div.text-2xl.font-bold.text-gray-600 (str "Profit and loss - " (str/join ", " (map :client/name client)))] (table {:widths (into [20] (take (dec (cell-count table-contents)) - (mapcat identity - (repeat - (if (-> data :args :include-deltas) - [13 6 13] - [13 6]))))) + (mapcat identity + (repeat + (if (-> data :args :include-deltas) + [13 6 13] + [13 6]))))) :investigate-url (bidi.bidi/path-for ssr-routes/only-routes ::route/investigate) :table table-contents - :warning (not-empty (str/join "\n " (filter not-empty [warning (:warning report)])))}))))]) + :warning [:div + (not-empty (str (str/join "\n " (filter not-empty [warning (:warning report)])))) + + (when (can? (:identity request) + {:subject :history + :activity :view}) + (for [n (:invalid-ids report)] + [:div + (com/link {:href (str (bidi/path-for ssr-routes/only-routes + :admin-history) + "/" n)} + "Sample")]))] + }))))]) @@ -215,7 +228,8 @@ :ttf-name "fonts/calibri-light.ttf"}} [:heading (str "Balance Sheet - " (str/join ", " (map :client/name (seq (:client (:form-params request))))))]] - (conj [:paragraph {:color [128 0 0] :size 9} (:warning report)]) + (conj [:paragraph {:color [128 0 0] :size 9} (:warning report) + ]) (conj (table->pdf table (into [20] (take (dec (cell-count table)) diff --git a/src/cljc/auto_ap/ledger/reports.cljc b/src/cljc/auto_ap/ledger/reports.cljc index 7fb2235f..6cf377fa 100644 --- a/src/cljc/auto_ap/ledger/reports.cljc +++ b/src/cljc/auto_ap/ledger/reports.cljc @@ -715,8 +715,17 @@ (:location %))) errors)))))) +(defn invalid-ids [pnl-data] + (let [errors (->> pnl-data + :data + (filter (fn [{:keys [numeric-code]}] + (nil? numeric-code))) + (map :sample)) ] + errors)) + (defn summarize-pnl [pnl-data] {:warning (warning-message pnl-data) + :invalid-ids (invalid-ids pnl-data) :summaries (if (-> pnl-data :args :column-per-location) [(location-summary-table (mapcat identity (for [[period i] (map vector (-> pnl-data :args :periods ) (range))]