Rename this to "Spendings" / name it more generically "Stock reports"

This commit is contained in:
Bernd Bestel 2023-04-01 14:58:11 +02:00
parent 00cb7d44f9
commit 132dfb8e6b
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
7 changed files with 83 additions and 64 deletions

View File

@ -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', [

View File

@ -0,0 +1,55 @@
<?php
namespace Grocy\Controllers;
class StockReportsController extends BaseController
{
public function Spendings(\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, '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
]);
}
}

View File

@ -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 ""

View File

@ -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

View File

@ -40,16 +40,25 @@
href="{{ $U('/stockentries') }}">
{{ $__t('Stock entries') }}
</a>
<a class="btn btn-outline-dark responsive-button m-1 mt-md-0 mb-md-0 float-right"
href="{{ $U('/stockmetricspurchases') }}">
{{ $__t('Metrics') }}
</a>
@if(GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)
<a class="btn btn-outline-dark responsive-button m-1 mt-md-0 mb-md-0 float-right"
href="{{ $U('/locationcontentsheet') }}">
{{ $__t('Location Content Sheet') }}
</a>
@endif
@if(GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
<div class="dropdown">
<a class="btn btn-outline-dark responsive-button m-1 mt-md-0 mb-md-0 float-right dropdown-toggle"
href="#"
data-toggle="dropdown">
{{ $__t('Reports') }}
</a>
<div class="dropdown-menu">
<a class="dropdown-item"
href="{{ $U('/stockreports/spendings') }}">{{ $__t('Spendings') }}</a>
</div>
</div>
@endif
</div>
</div>
<div class="border-top border-bottom my-2 py-1">

View File

@ -1,7 +1,7 @@
@extends('layout.default')
@section('title', $__t('Stock Metrics: Purchases'))
@section('viewJsName', 'metrics')
@section('title', $__t('Stock report') . ' / ' . $__t('Spendings'))
@section('viewJsName', 'stockreportspendings')
@push('pageScripts')
<script src="{{ $U('/node_modules/chart.js/dist/Chart.min.js?v=', true) }}{{ $version }}"></script>
@ -35,14 +35,14 @@
<div class="related-links collapse d-md-flex order-2 width-xs-sm-100"
id="related-links">
<a class="btn btn-outline-dark responsive-button @if(!$byGroup) active @endif m-1 mt-md-0 mb-md-0 float-right"
href="{{ $U('/stockmetricspurchases') }}">
href="{{ $U('/stockreports/spendings') }}">
{{ $__t('by Product') }}
</a>
</div>
<div class="related-links collapse d-md-flex order-2 width-xs-sm-100"
id="related-links">
<a class="btn btn-outline-dark responsive-button @if($byGroup) active @endif m-1 mt-md-0 mb-md-0 float-right"
href="{{ $U('/stockmetricspurchases?byGroup=true') }}">
href="{{ $U('/stockreports/spendings?byGroup=true') }}">
{{ $__t('by Group') }}
</a>
</div>