Supports more
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|||||||
@@ -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}]
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user