From 864ecec1b2d893f16ecb3b2c9e6c7172addc6ee0 Mon Sep 17 00:00:00 2001 From: Bryce Date: Thu, 24 Oct 2024 22:27:29 -0700 Subject: [PATCH] balance sheet --- resources/public/js/htmx-disable.js | 17 +++++++++++++++++ src/clj/auto_ap/ssr/components/buttons.clj | 11 +++++++---- src/clj/auto_ap/ssr/components/inputs.clj | 2 +- src/clj/auto_ap/ssr/ledger/balance_sheet.clj | 4 +++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/resources/public/js/htmx-disable.js b/resources/public/js/htmx-disable.js index 98cbff52..f77fe9ad 100644 --- a/resources/public/js/htmx-disable.js +++ b/resources/public/js/htmx-disable.js @@ -161,6 +161,23 @@ const getFourWeekPeriods = endDate => { return periods; }; +const withLastYear = (date) => { + + if (!date) { + date= new Date() + } else { + date = parseMMDDYYYY(date) + } + const originalYear = date.getFullYear(); + const priorYear = originalYear - 1; + + // Create new Date objects for both years + const originalDate = new Date(originalYear, date.getMonth(), date.getDate()); + const priorYearDate = new Date(priorYear, date.getMonth(), date.getDate()); + + return [formatDateMMDDYYYY(originalDate), formatDateMMDDYYYY(priorYearDate)]; +} + initMultiDatepicker = function(elem, startingValue) { const modalParent = elem.closest('#modal-content'); if (modalParent) { diff --git a/src/clj/auto_ap/ssr/components/buttons.clj b/src/clj/auto_ap/ssr/components/buttons.clj index 7efaa576..3192588e 100644 --- a/src/clj/auto_ap/ssr/components/buttons.clj +++ b/src/clj/auto_ap/ssr/components/buttons.clj @@ -116,10 +116,13 @@ (str " bg-white dark:bg-gray-600 border-gray-300 dark:border-gray-700 text-gray-500 hover:text-gray-800 dark:text-gray-400 dark:hover:text-gray-100 font-medium border border-gray-300 dark:border-gray-700"))) (assoc :tabindex 0) (assoc :href (:href params "#"))) - [:div.htmx-indicator.flex.items-center - (svg/spinner {:class "inline w-4 h-4 text-white"}) - [:div.ml-3 "Loading..."]] - (into [:div.htmx-indicator-hidden.inline-flex.gap-2.items-center.justify-center] children)]) + (when (:indicator? params true) + [:div.htmx-indicator.flex.items-center + (svg/spinner {:class "inline w-4 h-4 text-white"}) + [:div.ml-3 "Loading..."]]) + (into [:div.inline-flex.gap-2.items-center.justify-center {:class (when (:indicator? params true) + "htmx-indicator-hidden")}] + children)]) (defn icon-button- [params & children] (into diff --git a/src/clj/auto_ap/ssr/components/inputs.clj b/src/clj/auto_ap/ssr/components/inputs.clj index 3a76f128..c19ea5f5 100644 --- a/src/clj/auto_ap/ssr/components/inputs.clj +++ b/src/clj/auto_ap/ssr/components/inputs.clj @@ -369,7 +369,7 @@ (assoc :value value) ;; the data-date field has to be bound before the datepicker can be initialized (assoc :x-init "$nextTick(() => { dp = initMultiDatepicker($el, value); ;}); ") - (assoc "x-effect" "setTimeout(()=> { if(dp) { dp.setDate(Array.from(value), {clear: true}); }}, 2000) ") + (assoc "x-effect" "if(dp) { dp.setDate(Array.from(value), {clear: true}); } ") (assoc ":data-date" "Array.prototype.join.call(value, ', ')") (assoc "@htmx:before-history-save" "destroyDatepicker(dp)" ) (assoc "@htmx:before-cleanup-element" "destroyDatepicker(dp)" ) diff --git a/src/clj/auto_ap/ssr/ledger/balance_sheet.clj b/src/clj/auto_ap/ssr/ledger/balance_sheet.clj index f90b4d3a..0a177cfa 100644 --- a/src/clj/auto_ap/ssr/ledger/balance_sheet.clj +++ b/src/clj/auto_ap/ssr/ledger/balance_sheet.clj @@ -295,7 +295,8 @@ [:input {:type "hidden" :name (fc/field-name) :x-model "v"}] ] - (com/a-button {"x-tooltip.on.click.theme.dropdown.placement.bottom.interactive" "{content: ()=> $refs.tooltip.innerHTML, allowHTML: true, appendTo: $root}"} + (com/a-button {"x-tooltip.on.click.theme.dropdown.placement.bottom.interactive" "{content: ()=> $refs.tooltip.innerHTML, allowHTML: true, appendTo: $root}" + :indicator? false} [:template {:x-if "dates.length == 0"} [:span.text-left.text-gray-400 "None selected"]] @@ -316,6 +317,7 @@ (com/multi-date-input {:placeholder "12/21/2020" :x-model "dates" }) (com/a-button {"@click" "dates=getFourWeekPeriods(dates[dates.length -1])"} "13 periods") + (com/a-button {"@click" "dates=withLastYear(dates[dates.length -1])"} "Add prior year") (com/a-button {"@click" "dates=[]"} "Clear")]]]])) (com/button {:color :primary :class "w-32"}