Supports more

This commit is contained in:
2024-12-16 21:55:06 -08:00
parent b7826ad6ce
commit da2702f9e8
5 changed files with 83 additions and 35 deletions

View File

@@ -184,6 +184,41 @@ function getFourWeekPeriodsPeriods(endDate) {
]; ];
} }
const getTwelveCalendarMonthsPeriods = (endDate) => {
console.log(endDate)
// If no date is provided, default to today's date
const today = endDate ? parseMMDDYYYY(endDate) : new Date();
// Set the last day of the provided month as the end date
const inputEndDate = new Date(today.getFullYear(), today.getMonth() + 1, 0);
// Calculate the start of the total year range (12 months back from the end of input month)
const totalStartDate = new Date(inputEndDate.getFullYear(), inputEndDate.getMonth() - 11, 1);
// Build the array of months
// Build the array of months
const months = [
{
start: formatDateMMDDYYYY(totalStartDate),
end: formatDateMMDDYYYY(inputEndDate),
title: "Total"
},
...Array.from({ length: 12 }, (_, i) => {
const monthEnd = new Date(inputEndDate.getFullYear(), inputEndDate.getMonth() - (11 - i) + 1, 0); // Last day of the month
const monthStart = new Date(monthEnd.getFullYear(), monthEnd.getMonth(), 1); // First day of the month
return {
start: formatDateMMDDYYYY(monthStart),
end: formatDateMMDDYYYY(monthEnd),
title: monthEnd.toLocaleString('default', { month: 'long', year: 'numeric' })
};
})
];
console.log(months)
return months;
};
const withLastYear = (date) => { const withLastYear = (date) => {
if (!date) { if (!date) {

View File

@@ -338,6 +338,7 @@
[:div.shrink {:x-data (hx/json {:value (:value params) [:div.shrink {:x-data (hx/json {:value (:value params)
:tippy nil :tippy nil
:dp nil}) :dp nil})
"x-effect" "console.log('changed to' +value)"
"@change-date.camel" "$dispatch('change')" "@change-date.camel" "$dispatch('change')"
} }
[:input [:input

View File

@@ -18,8 +18,9 @@
:end :end
(atime/unparse-local atime/normal-date))}) (atime/unparse-local atime/normal-date))})
:x-effect "console.log('periods are', periods)"
:x-init "$watch('periods', ds => source_date= ds.length > 0 ? ds[0].end : null)" } :x-init "$watch('periods', ds => source_date= ds.length > 0 ? ds[0].end : null)" }
[:template {:x-for "(v,n) in periods"} [:template {:x-for "(v,n) in periods" ":key" "n"}
[:div [:div
[:input {:type "hidden" [:input {:type "hidden"
":name" "'periods[' + n + '][start]'" ":name" "'periods[' + n + '][start]'"
@@ -57,6 +58,8 @@
(buttons/a-button- {"@click" "periods=[calendarYearPeriod(source_date)]"} [:span "Calendar year (" (buttons/a-button- {"@click" "periods=[calendarYearPeriod(source_date)]"} [:span "Calendar year ("
[:span {:x-text "parseMMDDYYYY(source_date).getFullYear()"}] [:span {:x-text "parseMMDDYYYY(source_date).getFullYear()"}]
")"]) ")"])
(buttons/a-button- {"@click" "periods=getTwelveCalendarMonthsPeriods(source_date)"} [:span "12 months, ending "
[:span {:x-text "parseMMDDYYYY(source_date).toLocaleString('default', { month: 'long' })"}]])
[:hr {:class "h-px my-1 bg-gray-200 border-0 dark:bg-gray-700"} ] [:hr {:class "h-px my-1 bg-gray-200 border-0 dark:bg-gray-700"} ]
(buttons/a-button- {"@click" "periods=getLastMonthPeriods()"} "Last Month") (buttons/a-button- {"@click" "periods=getLastMonthPeriods()"} "Last Month")
(buttons/a-button- {"@click" "periods=getMonthToDatePeriods()"} "Month to date") (buttons/a-button- {"@click" "periods=getMonthToDatePeriods()"} "Month to date")

View File

@@ -242,6 +242,9 @@
true (wrap-secure) true (wrap-secure)
true (wrap-client-redirect-unauthenticated))) true (wrap-client-redirect-unauthenticated)))
;; TODO oob-render is wonky, requires thinking about accidental side effects. Really only used in a small handful of cases. probably best to just
;; use alpine for those cases, or make it so that date filters issue a change event when they render. for example, when you click on "month",
;; make it so that it rerenders the date range component, along with a hx-trigger change header
(defn csv-route [{:keys [fetch-page headers page->csv-entities]} & {:keys []}] (defn csv-route [{:keys [fetch-page headers page->csv-entities]} & {:keys []}]
(cond-> (fn csv-route [{:keys [identity] :as request}] (cond-> (fn csv-route [{:keys [identity] :as request}]

View File

@@ -5,7 +5,7 @@
:refer [add-sorter-fields apply-pagination apply-sort-4 conn :refer [add-sorter-fields apply-pagination apply-sort-4 conn
merge-query observable-query pull-many]] merge-query observable-query pull-many]]
[auto-ap.graphql.utils :refer [extract-client-ids]] [auto-ap.graphql.utils :refer [extract-client-ids]]
[auto-ap.permissions :refer [can? wrap-must]] [auto-ap.permissions :refer [wrap-must]]
[auto-ap.query-params :refer [wrap-copy-qp-pqp]] [auto-ap.query-params :refer [wrap-copy-qp-pqp]]
[auto-ap.routes.transactions :as route] [auto-ap.routes.transactions :as route]
[auto-ap.routes.utils :refer [wrap-client-redirect-unauthenticated]] [auto-ap.routes.utils :refer [wrap-client-redirect-unauthenticated]]
@@ -19,11 +19,12 @@
[auto-ap.ssr.svg :as svg] [auto-ap.ssr.svg :as svg]
[auto-ap.ssr.utils [auto-ap.ssr.utils
:refer [apply-middleware-to-all-handlers clj-date-schema :refer [apply-middleware-to-all-handlers clj-date-schema
entity-id html-response main-transformer strip entity-id html-response strip wrap-merge-prior-hx
wrap-merge-prior-hx wrap-schema-enforce]] wrap-schema-enforce]]
[auto-ap.time :as atime] [auto-ap.time :as atime]
[bidi.bidi :as bidi] [bidi.bidi :as bidi]
[clj-time.coerce :as coerce] [clj-time.coerce :as coerce]
[clojure.string :as str]
[datomic.api :as dc] [datomic.api :as dc]
[hiccup.util :as hu] [hiccup.util :as hu]
[malli.core :as mc])) [malli.core :as mc]))
@@ -82,8 +83,7 @@
:value (:vendor (:query-params request)) :value (:vendor (:query-params request))
:value-fn :db/id :value-fn :db/id
:content-fn :vendor/name})) :content-fn :vendor/name}))
(com/field {:label "Bank Account"} (bank-account-filter* request)
(bank-account-filter* request))
(date-range-field* request) (date-range-field* request)
@@ -140,8 +140,10 @@
(seq (:description args)) (seq (:description args))
(merge-query {:query {:in ['?description] (merge-query {:query {:in ['?description]
:where ['[?e :transaction/description-original ?description]]} :where ['[?e :transaction/description-original ?do]
:args [(:description args)]}) '[(clojure.string/lower-case ?do) ?do2]
'[(.contains ?do2 ?description)]]}
:args [(str/lower-case (:description args))]})
(:amount-gte args) (:amount-gte args)
(merge-query {:query {:in ['?amount-gte] (merge-query {:query {:in ['?amount-gte]
@@ -259,6 +261,10 @@
:page-specific-nav filters :page-specific-nav filters
:fetch-page fetch-page :fetch-page fetch-page
:query-schema query-schema :query-schema query-schema
:oob-render
(fn [request]
[(assoc-in (date-range-field* request) [1 :hx-swap-oob] true)
(assoc-in (exact-match-id* request) [1 :hx-swap-oob] true)])
:action-buttons (fn [request] :action-buttons (fn [request]
[(com/button {:color :primary [(com/button {:color :primary
:hx-get (bidi/path-for ssr-routes/only-routes :hx-get (bidi/path-for ssr-routes/only-routes
@@ -266,17 +272,17 @@
"Add Transaction")]) "Add Transaction")])
:row-buttons (fn [request entity] :row-buttons (fn [request entity]
[#_(when (and (can? (:identity request) {:subject :transaction :activity :edit})) [#_(when (and (can? (:identity request) {:subject :transaction :activity :edit}))
(com/icon-button {:hx-put (bidi/path-for ssr-routes/only-routes (com/icon-button {:hx-put (bidi/path-for ssr-routes/only-routes
::route/edit-wizard ::route/edit-wizard
:db/id (:db/id entity))} :db/id (:db/id entity))}
svg/pencil)) svg/pencil))
#_(when (and (can? (:identity request) {:subject :transaction :activity :delete})) #_(when (and (can? (:identity request) {:subject :transaction :activity :delete}))
(com/icon-button {:hx-delete (bidi/path-for ssr-routes/only-routes (com/icon-button {:hx-delete (bidi/path-for ssr-routes/only-routes
::route/delete ::route/delete
:db/id (:db/id entity)) :db/id (:db/id entity))
:hx-confirm "Are you sure you want to delete this transaction?"} :hx-confirm "Are you sure you want to delete this transaction?"}
svg/trash))]) svg/trash))])
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes ::route/page)} :breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes ::route/page)}
"Transactions"]] "Transactions"]]
:title (fn [r] :title (fn [r]
@@ -284,15 +290,15 @@
:entity-name "register" :entity-name "register"
:route ::route/table :route ::route/table
:csv-route ::route/csv :csv-route ::route/csv
:break-table (fn [request entity] :break-table (fn [request entity]
(cond (cond
(= (-> request :query-params :sort first :name) "Vendor") (= (-> request :query-params :sort first :name) "Vendor")
(or (-> entity :transaction/vendor :vendor/name) (or (-> entity :transaction/vendor :vendor/name)
"No vendor") "No vendor")
:else nil)) :else nil))
:page->csv-entities (fn [[transactions]] :page->csv-entities (fn [[transactions]]
transactions) transactions)
:headers [{:key "id" :headers [{:key "id"
@@ -310,11 +316,11 @@
{:key "vendor" {:key "vendor"
:name "Vendor" :name "Vendor"
:sort-key "vendor" :sort-key "vendor"
:render (fn [e] :render (fn [e]
#_(alog/peek :vend e) #_(alog/peek :vend e)
(or (or
(-> e :transaction/vendor :vendor/name) (-> e :transaction/vendor :vendor/name)
[:span.italic.text-gray-400 (-> e :transaction/description-simple)])) [:span.italic.text-gray-400 (-> e :transaction/description-simple)]))
:render-csv (fn [e] (or (-> e :transaction/vendor :vendor/name) :render-csv (fn [e] (or (-> e :transaction/vendor :vendor/name)
(-> e :transaction/description-simple)))} (-> e :transaction/description-simple)))}
{:key "description" {:key "description"
@@ -333,7 +339,7 @@
:sort-key "amount" :sort-key "amount"
:class "text-right" :class "text-right"
:render #(format "$%,.2f" (:transaction/amount %)) :render #(format "$%,.2f" (:transaction/amount %))
:render-csv :transaction/amount } :render-csv :transaction/amount}
{:key "links" {:key "links"
:name "Links" :name "Links"
:show-starting "lg" :show-starting "lg"
@@ -348,11 +354,11 @@
{:exact-match-id (:db/id (:transaction/payment i))}) {:exact-match-id (:db/id (:transaction/payment i))})
:color :primary :color :primary
:content (format "Payment '%s'" (-> i :transaction/payment :payment/invoice-number))}) :content (format "Payment '%s'" (-> i :transaction/payment :payment/invoice-number))})
(and (:transaction/client-overrides i) (seq (:transaction/client-overrides i))) (and (:transaction/client-overrides i) (seq (:transaction/client-overrides i)))
{:link (hu/url (bidi/path-for client-routes/routes {:link (hu/url (bidi/path-for client-routes/routes
:transactions) :transactions)
{:exact-match-id (:db/id i)}) {:exact-match-id (:db/id i)})
:color :primary :color :primary
:content "Client Overrides"}))) :content "Client Overrides"})))
:render-for #{:html}}]})) :render-for #{:html}}]}))