From 5ae36e6ba826ab547fccae55e78bd4a4b1132b29 Mon Sep 17 00:00:00 2001 From: kriddles <54413450+kriddles@users.noreply.github.com> Date: Thu, 15 Oct 2020 12:46:27 -0500 Subject: [PATCH] Value information (#1045) * viewjs stockoverview: add total value to stock overview * view stockoverview.blade: add Value column * refresh stockOverview value column * Removed the total units info * Properly format the total stock value number * Added new localization strings * Resolved merge conflict Co-authored-by: Bernd Bestel --- localization/strings.pot | 6 ++++++ migrations/0105.sql | 2 ++ public/viewjs/stockoverview.js | 28 +++++++++++++++++++++------- views/stockoverview.blade.php | 4 ++++ 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/localization/strings.pot b/localization/strings.pot index f977caea..d6819df5 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -1915,3 +1915,9 @@ msgstr "" msgid "Consume exact amount" msgstr "" + +msgid "Value" +msgstr "" + +msgid "%s total value" +msgstr "" diff --git a/migrations/0105.sql b/migrations/0105.sql index 0bf60899..e3e29366 100644 --- a/migrations/0105.sql +++ b/migrations/0105.sql @@ -6,6 +6,7 @@ SELECT p.tare_weight AS tare_weight, p.enable_tare_weight_handling AS enable_tare_weight_handling, sc.amount AS amount, + sc.value as value, sc.product_id AS product_id, sc.best_before_date AS best_before_date, EXISTS(SELECT id FROM stock_missing_products_including_opened WHERE id = sc.product_id) AS product_missing, @@ -40,6 +41,7 @@ SELECT p.tare_weight AS tare_weight, p.enable_tare_weight_handling AS enable_tare_weight_handling, sc.amount AS amount, + sc.value as value, sc.product_id AS product_id, sc.best_before_date AS best_before_date, EXISTS(SELECT id FROM stock_missing_products_including_opened WHERE id = sc.product_id) AS product_missing, diff --git a/public/viewjs/stockoverview.js b/public/viewjs/stockoverview.js index ec8ad794..a864ff63 100644 --- a/public/viewjs/stockoverview.js +++ b/public/viewjs/stockoverview.js @@ -5,9 +5,9 @@ { 'orderable': false, 'targets': 0 }, { 'searchable': false, "targets": 0 }, { 'searchable': false, "targets": 0 }, - { 'visible': false, 'targets': 5 }, { 'visible': false, 'targets': 6 }, - { 'visible': false, 'targets': 7 } + { 'visible': false, 'targets': 7 }, + { 'visible': false, 'targets': 8 } ], }); $('#stock-overview-table tbody').removeClass("d-none"); @@ -25,7 +25,7 @@ $("#location-filter").on("change", function() value = "xx" + value + "xx"; } - stockOverviewTable.column(5).search(value).draw(); + stockOverviewTable.column(6).search(value).draw(); }); $("#product-group-filter").on("change", function() @@ -40,7 +40,7 @@ $("#product-group-filter").on("change", function() value = "xx" + value + "xx"; } - stockOverviewTable.column(7).search(value).draw(); + stockOverviewTable.column(8).search(value).draw(); }); $("#status-filter").on("change", function() @@ -54,7 +54,7 @@ $("#status-filter").on("change", function() // Transfer CSS classes of selected element to dropdown element (for background) $(this).attr("class", $("#" + $(this).attr("id") + " option[value='" + value + "']").attr("class") + " form-control"); - stockOverviewTable.column(6).search(value).draw(); + stockOverviewTable.column(7).search(value).draw(); }); $(".status-filter-message").on("click", function() @@ -70,9 +70,9 @@ $("#clear-filter-button").on("click", function() $("#status-filter").val("all"); $("#product-group-filter").val("all"); $("#location-filter").val("all"); - stockOverviewTable.column(5).search("").draw(); stockOverviewTable.column(6).search("").draw(); stockOverviewTable.column(7).search("").draw(); + stockOverviewTable.column(8).search("").draw(); stockOverviewTable.search("").draw(); }); @@ -204,7 +204,20 @@ function RefreshStatistics() { amountSum += parseInt(element.amount); }); - $("#info-current-stock").text(__n(result.length, '%s Product', '%s Products')); + + if (!Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) + { + $("#info-current-stock").text(__n(result.length, '%s Product', '%s Products')); + } + else + { + var valueSum = 0; + result.forEach(element => + { + valueSum += parseInt(element.value); + }); + $("#info-current-stock").text(__n(result.length, '%s Product', '%s Products') + ", " + __t('%s total value', valueSum.toLocaleString(undefined, { style: "currency", currency: Grocy.Currency }))); + } }, function(xhr) { @@ -276,6 +289,7 @@ function RefreshProductRow(productId) $('#product-' + productId + '-amount').text(result.stock_amount); $('#product-' + productId + '-consume-all-button').attr('data-consume-amount', result.stock_amount); $('#product-' + productId + '-factor-purchase-amount').text(__t('( %s', result.stock_factor_purchase_amount)); + $('#product-' + productId + '-value').text(result.stock_value); $('#product-' + productId + '-next-best-before-date').text(result.next_best_before_date); $('#product-' + productId + '-next-best-before-date-timeago').attr('datetime', result.next_best_before_date); diff --git a/views/stockoverview.blade.php b/views/stockoverview.blade.php index c61aeb13..d5e3cb5f 100644 --- a/views/stockoverview.blade.php +++ b/views/stockoverview.blade.php @@ -128,6 +128,7 @@ {{ $__t('Product') }} {{ $__t('Product group') }} {{ $__t('Amount') }} + {{ $__t('Value') }} {{ $__t('Next best before date') }} Hidden location Hidden status @@ -308,6 +309,9 @@ @endif @endif + + {{ $currentStockEntry->value }} + {{ $currentStockEntry->best_before_date }}