From 17fbcf77cb8cb3e73ed3eab2829a3f2e634797e6 Mon Sep 17 00:00:00 2001 From: Travis Raup Date: Tue, 21 Feb 2023 21:00:41 -0500 Subject: [PATCH] More suggestion edits - locale in javascript - global translations - commit migrations sql file --- controllers/StockController.php | 4 ++- localization/strings.pot | 30 +++++++++++++++++++++++ migrations/0215.sql | 24 ++++++++++++++++++ public/viewjs/metrics.js | 43 +++++++++++++++++++-------------- 4 files changed, 82 insertions(+), 19 deletions(-) create mode 100644 migrations/0215.sql diff --git a/controllers/StockController.php b/controllers/StockController.php index 78b610ec..850d861b 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -539,7 +539,9 @@ class StockController extends BaseController GROUP BY product_group ORDER BY product_group "; - } else { + } + else + { if (isset($request->getQueryParams()['product_group']) AND $request->getQueryParams()['product_group'] != 'all') { $where = $where . ' AND product_group_id = ' . $request->getQueryParams()['product_group']; diff --git a/localization/strings.pot b/localization/strings.pot index 64cb762d..14e94aa3 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -2386,3 +2386,33 @@ msgstr "" msgid "Total" msgstr "" + +msgid "Apply" +msgstr "" + +msgid "Custom Range" +msgstr "" + +msgid "Yesterday" +msgstr "" + +msgid "Last 7 Days" +msgstr "" + +msgid "Last 14 Days" +msgstr "" + +msgid "Last 30 Days" +msgstr "" + +msgid "This Month" +msgstr "" + +msgid "Last Month" +msgstr "" + +msgid "This Year" +msgstr "" + +msgid "Last Year" +msgstr "" diff --git a/migrations/0215.sql b/migrations/0215.sql new file mode 100644 index 00000000..925130ac --- /dev/null +++ b/migrations/0215.sql @@ -0,0 +1,24 @@ +CREATE VIEW product_purchase_history +AS +SELECT + 1 AS id, -- Dummy, LessQL needs an id column + p.id as product_id, + p.name as product_name, + g.id as product_group_id, + g.name as product_group, + s.amount as quantity, + s.price as price, + s.purchased_date as purchased_date +FROM + product_groups as g +INNER JOIN products as p + ON p.product_group_id = g.id +INNER JOIN stock_log as s + ON s.product_id = p.id +WHERE + s.transaction_type = 'purchase' +AND + s.undone = 0 +AND + s.price is not null +ORDER BY p.name ASC diff --git a/public/viewjs/metrics.js b/public/viewjs/metrics.js index 8dc05290..0819277c 100644 --- a/public/viewjs/metrics.js +++ b/public/viewjs/metrics.js @@ -12,8 +12,9 @@ $("#metrics-table tbody tr").each(function () { var itemTotalRaw = parseFloat(self.find("td:eq(1)").attr('data-chart-value')); var itemTotal = parseFloat((Math.round(itemTotalRaw * 100) / 100).toFixed(2)); data.push(itemTotal); - totalAmount = (parseFloat(totalAmount) + parseFloat(itemTotal)).toFixed(2); + totalAmount = (parseFloat(totalAmount) + parseFloat(itemTotal)); }); +totalAmount = totalAmount.toLocaleString(undefined, { style: "currency", currency: Grocy.Currency }); var backgroundColorChoices=['#6C747C', '#BFB8A4', @@ -67,12 +68,12 @@ var metricsChart = new Chart('metrics-chart', { { text: totalAmount, font: { - size: 30, + size: 24, weight: 'bold', }, }, { - text: 'total', + text: __t("Total"), } ] } @@ -100,31 +101,37 @@ metricsTable.columns.adjust().draw(); /* DateRangePicker */ const urlParams = new URLSearchParams(window.location.search); -var start_date = moment().startOf("month").format('MM/DD/YYYY'); -var end_date = moment().endOf("month").format('MM/DD/YYYY'); +var start_date = moment().startOf("month").format('YYYY-MM-DD'); +var end_date = moment().endOf("month").format('YYYY-MM-DD'); if (urlParams.get('start_date')) start_date = moment(urlParams.get('start_date')) ; if (urlParams.get('end_date')) end_date = moment(urlParams.get('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')] + $('#daterange-filter').daterangepicker({ showDropdowns: true, startDate: start_date, endDate: end_date, + showWeekNumbers: Grocy.CalendarShowWeekNumbers, locale: { - "format": 'MM/DD/YYYY', - "firstDay": 1 + "format": 'YYYY-MM-DD', + "firstDay": Grocy.CalendarFirstDayOfWeek }, - ranges: { - 'Today': [moment(), moment()], - 'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')], - 'Last 7 Days': [moment().subtract(6, 'days'), moment()], - 'Last 14 Days': [moment().subtract(13, 'days'), moment()], - 'Last 30 Days': [moment().subtract(29, 'days'), moment()], - 'This Month': [moment().startOf('month'), moment().endOf('month')], - 'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')], - 'This Year': [moment().startOf('year'), moment().endOf('year')], - 'Last Year': [moment().subtract(1, 'year').startOf('year'), moment().subtract(1, 'year').endOf('year')] - }}, function(start, end, label) { + applyLabel: __t("Apply"), + cancelLabel: __t("Cancel"), + customRangeLabel: __t("Custom Range"), + ranges: _ranges + }, function(start, end, label) { UpdateUriParam("start_date", start.format('YYYY-MM-DD')); UpdateUriParam("end_date", end.format('YYYY-MM-DD')) window.location.reload();