From c781bb4ff1c80c48cee7e5827b89017f15198523 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 1 Apr 2023 16:57:37 +0200 Subject: [PATCH] Final cleanup --- localization/strings.pot | 24 +++-------- package.json | 3 +- public/viewjs/stockreportspendings.js | 62 ++++++++++----------------- views/stockreportspendings.blade.php | 61 ++++++++++++++------------ yarn.lock | 17 ++++++-- 5 files changed, 77 insertions(+), 90 deletions(-) diff --git a/localization/strings.pot b/localization/strings.pot index 7f47c1bc..473adf16 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -2375,43 +2375,31 @@ msgstr "" msgid "Track chore execution now" msgstr "" -msgid "by Product" -msgstr "" - -msgid "by Group" -msgstr "" - msgid "Total" msgstr "" msgid "Apply" msgstr "" -msgid "Custom Range" +msgid "Custom range" msgstr "" msgid "Yesterday" msgstr "" -msgid "Last 7 Days" +msgid "Last %1$s days" msgstr "" -msgid "Last 14 Days" +msgid "This month" msgstr "" -msgid "Last 30 Days" +msgid "Last month" msgstr "" -msgid "This Month" +msgid "This year" msgstr "" -msgid "Last Month" -msgstr "" - -msgid "This Year" -msgstr "" - -msgid "Last Year" +msgid "Last year" msgstr "" msgid "Reports" diff --git a/package.json b/package.json index 9bb792ab..6f9cd97b 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "bootstrap-select": "^1.13.18", "bwip-js": "^3.0.1", "chart.js": "^2.8.0", + "chartjs-plugin-colorschemes": "^0.4.0", "chartjs-plugin-doughnutlabel": "^2.0.3", "chartjs-plugin-piechart-outlabels": "^0.1.4", "datatables.net": "^1.10.22", @@ -23,7 +24,7 @@ "datatables.net-rowgroup-bs4": "^1.1.2", "datatables.net-select": "^1.3.1", "datatables.net-select-bs4": "^1.3.1", - "daterangepicker": "dangrossman/daterangepicker", + "daterangepicker": "^3.1.0", "fullcalendar": "^3.10.1", "gettext-translator": "2.1.0", "jquery": "^3.6.0", diff --git a/public/viewjs/stockreportspendings.js b/public/viewjs/stockreportspendings.js index 7360bb35..bb332bcf 100644 --- a/public/viewjs/stockreportspendings.js +++ b/public/viewjs/stockreportspendings.js @@ -1,44 +1,26 @@ -/* Charting */ var labels = []; var data = []; -var totalAmount = 0; +var totalAmount = 0.0; $("#metrics-table tbody tr").each(function() { var self = $(this); labels.push(self.find("td:eq(0)").attr("data-chart-label")); - var itemTotalRaw = Number.parseFloat(self.find("td:eq(1)").attr("data-chart-value")); - var itemTotal = Number.parseFloat((Math.round(itemTotalRaw * 100) / 100).toFixed(2)); + var itemTotal = Number.parseFloat(self.find("td:eq(1)").attr("data-chart-value")); data.push(itemTotal); - totalAmount = (Number.parseFloat(totalAmount) + Number.parseFloat(itemTotal)); + totalAmount += + itemTotal; }); totalAmount = totalAmount.toLocaleString(undefined, { style: "currency", currency: Grocy.Currency }); -var backgroundColorChoices = [ - "#6C747C", - "#BFB8A4", - "#BFADA4", - "#4F575E", - "#918B78", - "#343A40", - "#635E4F", - "#63554F", - "#1A1F24", - "#383426", - "#382C26", - "#121B25", - "#383119", - "#382319" -] var backgroundColors = []; var colorChoiceIndex = 0; for (i = 0; i < data.length; i++) { - if ((i + 1) == (backgroundColorChoices.length)) + if (i + 1 == Chart.colorschemes.brewer.Paired12.length) { - // restart background color choices + // Restart background color choices colorChoiceIndex = 1; } - backgroundColors.push(backgroundColorChoices[colorChoiceIndex]); + backgroundColors.push(Chart.colorschemes.brewer.Paired12[colorChoiceIndex]); colorChoiceIndex++; } @@ -51,15 +33,14 @@ var metricsChart = new Chart("metrics-chart", { "tooltips": { "enabled": false }, - "tooltips": { enabled: false }, + "tooltips": { + "enabled": false + }, "plugins": { "outlabels": { "text": "%l %p", "backgroundColor": "#343a40", - "color": "white", - "stretch": 45, "font": { - "resizable": true, "minSize": 12, "maxSize": 18 } @@ -90,7 +71,6 @@ var metricsChart = new Chart("metrics-chart", { }); -/* DataTables */ var metricsTable = $("#metrics-table").DataTable({ "columnDefs": [ { "type": "num", "targets": 1 } @@ -99,10 +79,8 @@ var metricsTable = $("#metrics-table").DataTable({ $("#metrics-table tbody").removeClass("d-none"); metricsTable.columns.adjust().draw(); -/* DateRangePicker */ var startDate = moment().startOf("month").format("YYYY-MM-DD"); var endDate = moment().endOf("month").format("YYYY-MM-DD"); - if (GetUriParam("start_date")) { startDate = moment(GetUriParam("start_date")); @@ -115,16 +93,20 @@ if (GetUriParam("end_date")) var ranges = {}; ranges[__t("Today")] = [moment(), moment()]; ranges[__t("Yesterday")] = [moment().subtract(1, "days"), moment().subtract(1, "days")]; -ranges[__t("Last 7 Days")] = [moment().subtract(6, "days"), moment()]; -ranges[__t("Last 14 Days")] = [moment().subtract(13, "days"), moment()]; -ranges[__t("Last 30 Days")] = [moment().subtract(29, "days"), moment()]; -ranges[__t("This Month")] = [moment().startOf("month"), moment().endOf("month")]; -ranges[__t("Last Month")] = [moment().subtract(1, "month").startOf("month"), moment().subtract(1, "month").endOf("month")]; -ranges[__t("This Year")] = [moment().startOf("year"), moment().endOf("year")]; -ranges[__t("Last Year")] = [moment().subtract(1, "year").startOf("year"), moment().subtract(1, "year").endOf("year")]; +ranges[__t("Last %1$s days", "7")] = [moment().subtract(6, "days"), moment()]; +ranges[__t("Last %1$s days", "14")] = [moment().subtract(13, "days"), moment()]; +ranges[__t("Last %1$s days", "30")] = [moment().subtract(29, "days"), moment()]; +ranges[__t("This month")] = [moment().startOf("month"), moment().endOf("month")]; +ranges[__t("Last month")] = [moment().subtract(1, "month").startOf("month"), moment().subtract(1, "month").endOf("month")]; +ranges[__t("This year")] = [moment().startOf("year"), moment().endOf("year")]; +ranges[__t("Last year")] = [moment().subtract(1, "year").startOf("year"), moment().subtract(1, "year").endOf("year")]; $("#daterange-filter").daterangepicker({ "showDropdowns": true, + "alwaysShowCalendars": true, + "buttonClasses": "btn", + "applyButtonClasses": "btn-primary", + "cancelButtonClasses": "btn-secondary", "startDate": startDate, "endDate": endDate, "showWeekNumbers": Grocy.CalendarShowWeekNumbers, @@ -134,7 +116,7 @@ $("#daterange-filter").daterangepicker({ }, "applyLabel": __t("Apply"), "cancelLabel": __t("Cancel"), - "customRangeLabel": __t("Custom Range"), + "customRangeLabel": __t("Custom range"), "ranges": ranges }, function(start, end, label) { @@ -145,7 +127,7 @@ $("#daterange-filter").daterangepicker({ $("#daterange-filter").on("cancel.daterangepicker", function(ev, picker) { - $(this).val(start_date + " - " + end_date); + $(this).val(startDate + " - " + endDate); }); $("#clear-filter-button").on("click", function() diff --git a/views/stockreportspendings.blade.php b/views/stockreportspendings.blade.php index d68e2126..cc011a98 100644 --- a/views/stockreportspendings.blade.php +++ b/views/stockreportspendings.blade.php @@ -5,8 +5,9 @@ @push('pageScripts') + - + @endpush @@ -22,28 +23,33 @@

@yield('title')

-

- -

- - @@ -54,16 +60,16 @@
-
+
 {{ $__t('Date range') }} -
+
@if(!$byGroup) @@ -84,7 +90,7 @@
@endif
-
+