diff --git a/controllers/StockController.php b/controllers/StockController.php index 6648928b..26ec8527 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -515,55 +515,6 @@ class StockController extends BaseController ]); } - public function StockMetricsPurchases(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) - { - if (isset($request->getQueryParams()['start_date']) and isset($request->getQueryParams()['end_date'])) - { - $startDate = $request->getQueryParams()['start_date']; - $endDate = $request->getQueryParams()['end_date']; - $where = "purchased_date >= '$startDate' AND purchased_date <= '$endDate'"; - } - else - { - // Default this month - $where = "purchased_date >= DATE(DATE('now', 'localtime'), 'start of month')"; - } - - - if (isset($request->getQueryParams()['byGroup'])) - { - $sql = " - SELECT product_group_id as id, product_group as name, sum(quantity * price) as total - FROM product_purchase_history - WHERE $where - GROUP BY product_group - ORDER BY product_group - "; - } - else - { - if (isset($request->getQueryParams()['product_group']) and $request->getQueryParams()['product_group'] != 'all') - { - $where = $where . ' AND product_group_id = ' . $request->getQueryParams()['product_group']; - } - - $sql = " - SELECT product_id as id, product_name as name, product_group_id as group_id, product_group as group_name, sum(quantity * price) as total - FROM product_purchase_history - WHERE $where - GROUP BY product_name - ORDER BY product_name - "; - } - - return $this->renderPage($response, 'stockmetricspurchases', [ - 'metrics' => $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ), - 'productGroups' => $this->getDatabase()->product_groups()->orderBy('name', 'COLLATE NOCASE'), - 'selectedGroup' => isset($request->getQueryParams()['product_group']) ? $request->getQueryParams()['product_group'] : null, - 'byGroup' => isset($request->getQueryParams()['byGroup']) ? $request->getQueryParams()['byGroup'] : null - ]); - } - public function Transfer(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) { return $this->renderPage($response, 'transfer', [ diff --git a/controllers/StockReportsController.php b/controllers/StockReportsController.php new file mode 100644 index 00000000..7b00ef36 --- /dev/null +++ b/controllers/StockReportsController.php @@ -0,0 +1,55 @@ +getQueryParams()['start_date']) and isset($request->getQueryParams()['end_date'])) + { + $startDate = $request->getQueryParams()['start_date']; + $endDate = $request->getQueryParams()['end_date']; + $where = "purchased_date >= '$startDate' AND purchased_date <= '$endDate'"; + } + else + { + // Default this month + $where = "purchased_date >= DATE(DATE('now', 'localtime'), 'start of month')"; + } + + + if (isset($request->getQueryParams()['byGroup'])) + { + $sql = " + SELECT product_group_id as id, product_group as name, sum(quantity * price) as total + FROM product_purchase_history + WHERE $where + GROUP BY product_group + ORDER BY product_group + "; + } + else + { + if (isset($request->getQueryParams()['product_group']) and $request->getQueryParams()['product_group'] != 'all') + { + $where = $where . ' AND product_group_id = ' . $request->getQueryParams()['product_group']; + } + + $sql = " + SELECT product_id as id, product_name as name, product_group_id as group_id, product_group as group_name, sum(quantity * price) as total + FROM product_purchase_history + WHERE $where + GROUP BY product_name + ORDER BY product_name + "; + } + + return $this->renderPage($response, 'stockreportspendings', [ + 'metrics' => $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ), + 'productGroups' => $this->getDatabase()->product_groups()->orderBy('name', 'COLLATE NOCASE'), + 'selectedGroup' => isset($request->getQueryParams()['product_group']) ? $request->getQueryParams()['product_group'] : null, + 'byGroup' => isset($request->getQueryParams()['byGroup']) ? $request->getQueryParams()['byGroup'] : null + ]); + } +} diff --git a/localization/strings.pot b/localization/strings.pot index 0a441cd7..7f47c1bc 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -2375,12 +2375,6 @@ msgstr "" msgid "Track chore execution now" msgstr "" -msgid "Metrics" -msgstr "" - -msgid "Stock Metrics: Purchases" -msgstr "" - msgid "by Product" msgstr "" @@ -2419,3 +2413,12 @@ msgstr "" msgid "Last Year" msgstr "" + +msgid "Reports" +msgstr "" + +msgid "Spendings" +msgstr "" + +msgid "Stock report" +msgstr "" diff --git a/public/viewjs/metrics.js b/public/viewjs/stockreportspendings.js similarity index 100% rename from public/viewjs/metrics.js rename to public/viewjs/stockreportspendings.js diff --git a/routes.php b/routes.php index 00c1ad81..aa73dbdf 100644 --- a/routes.php +++ b/routes.php @@ -56,7 +56,6 @@ $app->group('', function (RouteCollectorProxy $group) { $group->get('/locations', '\Grocy\Controllers\StockController:LocationsList'); $group->get('/location/{locationId}', '\Grocy\Controllers\StockController:LocationEditForm'); $group->get('/stockjournal', '\Grocy\Controllers\StockController:Journal'); - $group->get('/stockmetricspurchases', '\Grocy\Controllers\StockController:StockMetricsPurchases'); $group->get('/locationcontentsheet', '\Grocy\Controllers\StockController:LocationContentSheet'); $group->get('/quantityunitpluraltesting', '\Grocy\Controllers\StockController:QuantityUnitPluralFormTesting'); $group->get('/stockjournal/summary', '\Grocy\Controllers\StockController:JournalSummary'); @@ -64,6 +63,8 @@ $app->group('', function (RouteCollectorProxy $group) { $group->get('/stockentry/{entryId}/grocycode', '\Grocy\Controllers\StockController:StockEntryGrocycodeImage'); $group->get('/stockentry/{entryId}/label', '\Grocy\Controllers\StockController:StockEntryGrocycodeLabel'); $group->get('/quantityunitconversionsresolved', '\Grocy\Controllers\StockController:QuantityUnitConversionsResolved'); + + $group->get('/stockreports/spendings', '\Grocy\Controllers\StockReportsController:Spendings'); } // Stock price tracking diff --git a/views/stockoverview.blade.php b/views/stockoverview.blade.php index 699bcc61..6fbd0ae0 100755 --- a/views/stockoverview.blade.php +++ b/views/stockoverview.blade.php @@ -40,16 +40,25 @@ href="{{ $U('/stockentries') }}"> {{ $__t('Stock entries') }} - - {{ $__t('Metrics') }} - @if(GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) {{ $__t('Location Content Sheet') }} @endif + @if(GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) +
+ @endif