mirror of
https://github.com/grocy/grocy.git
synced 2026-04-08 21:46:16 +02:00
Rename this to "Spendings" / name it more generically "Stock reports"
This commit is contained in:
parent
00cb7d44f9
commit
132dfb8e6b
|
|
@ -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)
|
public function Transfer(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||||
{
|
{
|
||||||
return $this->renderPage($response, 'transfer', [
|
return $this->renderPage($response, 'transfer', [
|
||||||
|
|
|
||||||
55
controllers/StockReportsController.php
Normal file
55
controllers/StockReportsController.php
Normal 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
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2375,12 +2375,6 @@ msgstr ""
|
||||||
msgid "Track chore execution now"
|
msgid "Track chore execution now"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
msgid "Metrics"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
msgid "Stock Metrics: Purchases"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
msgid "by Product"
|
msgid "by Product"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
@ -2419,3 +2413,12 @@ msgstr ""
|
||||||
|
|
||||||
msgid "Last Year"
|
msgid "Last Year"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Reports"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Spendings"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "Stock report"
|
||||||
|
msgstr ""
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,6 @@ $app->group('', function (RouteCollectorProxy $group) {
|
||||||
$group->get('/locations', '\Grocy\Controllers\StockController:LocationsList');
|
$group->get('/locations', '\Grocy\Controllers\StockController:LocationsList');
|
||||||
$group->get('/location/{locationId}', '\Grocy\Controllers\StockController:LocationEditForm');
|
$group->get('/location/{locationId}', '\Grocy\Controllers\StockController:LocationEditForm');
|
||||||
$group->get('/stockjournal', '\Grocy\Controllers\StockController:Journal');
|
$group->get('/stockjournal', '\Grocy\Controllers\StockController:Journal');
|
||||||
$group->get('/stockmetricspurchases', '\Grocy\Controllers\StockController:StockMetricsPurchases');
|
|
||||||
$group->get('/locationcontentsheet', '\Grocy\Controllers\StockController:LocationContentSheet');
|
$group->get('/locationcontentsheet', '\Grocy\Controllers\StockController:LocationContentSheet');
|
||||||
$group->get('/quantityunitpluraltesting', '\Grocy\Controllers\StockController:QuantityUnitPluralFormTesting');
|
$group->get('/quantityunitpluraltesting', '\Grocy\Controllers\StockController:QuantityUnitPluralFormTesting');
|
||||||
$group->get('/stockjournal/summary', '\Grocy\Controllers\StockController:JournalSummary');
|
$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}/grocycode', '\Grocy\Controllers\StockController:StockEntryGrocycodeImage');
|
||||||
$group->get('/stockentry/{entryId}/label', '\Grocy\Controllers\StockController:StockEntryGrocycodeLabel');
|
$group->get('/stockentry/{entryId}/label', '\Grocy\Controllers\StockController:StockEntryGrocycodeLabel');
|
||||||
$group->get('/quantityunitconversionsresolved', '\Grocy\Controllers\StockController:QuantityUnitConversionsResolved');
|
$group->get('/quantityunitconversionsresolved', '\Grocy\Controllers\StockController:QuantityUnitConversionsResolved');
|
||||||
|
|
||||||
|
$group->get('/stockreports/spendings', '\Grocy\Controllers\StockReportsController:Spendings');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stock price tracking
|
// Stock price tracking
|
||||||
|
|
|
||||||
|
|
@ -40,16 +40,25 @@
|
||||||
href="{{ $U('/stockentries') }}">
|
href="{{ $U('/stockentries') }}">
|
||||||
{{ $__t('Stock entries') }}
|
{{ $__t('Stock entries') }}
|
||||||
</a>
|
</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)
|
@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"
|
<a class="btn btn-outline-dark responsive-button m-1 mt-md-0 mb-md-0 float-right"
|
||||||
href="{{ $U('/locationcontentsheet') }}">
|
href="{{ $U('/locationcontentsheet') }}">
|
||||||
{{ $__t('Location Content Sheet') }}
|
{{ $__t('Location Content Sheet') }}
|
||||||
</a>
|
</a>
|
||||||
@endif
|
@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>
|
</div>
|
||||||
<div class="border-top border-bottom my-2 py-1">
|
<div class="border-top border-bottom my-2 py-1">
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
@extends('layout.default')
|
@extends('layout.default')
|
||||||
|
|
||||||
@section('title', $__t('Stock Metrics: Purchases'))
|
@section('title', $__t('Stock report') . ' / ' . $__t('Spendings'))
|
||||||
@section('viewJsName', 'metrics')
|
@section('viewJsName', 'stockreportspendings')
|
||||||
|
|
||||||
@push('pageScripts')
|
@push('pageScripts')
|
||||||
<script src="{{ $U('/node_modules/chart.js/dist/Chart.min.js?v=', true) }}{{ $version }}"></script>
|
<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"
|
<div class="related-links collapse d-md-flex order-2 width-xs-sm-100"
|
||||||
id="related-links">
|
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"
|
<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') }}
|
{{ $__t('by Product') }}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="related-links collapse d-md-flex order-2 width-xs-sm-100"
|
<div class="related-links collapse d-md-flex order-2 width-xs-sm-100"
|
||||||
id="related-links">
|
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"
|
<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') }}
|
{{ $__t('by Group') }}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
Loading…
Reference in New Issue
Block a user