From 1410afe2b37cc48b0b725338c6198fc55623e94c Mon Sep 17 00:00:00 2001 From: fipwmaqzufheoxq92ebc <29818044+fipwmaqzufheoxq92ebc@users.noreply.github.com> Date: Thu, 3 Sep 2020 11:39:06 +0200 Subject: [PATCH] Add "Journal-Summary" --- controllers/StockApiController.php | 5 +++ controllers/StockController.php | 20 ++++++++++++ localization/strings.pot | 6 ++++ migrations/0115.sql | 15 +++++++++ public/viewjs/stockjournalsummary.js | 6 ++++ routes.php | 2 ++ views/stockjournalsummary.blade.php | 47 ++++++++++++++++++++++++++++ views/stockoverview.blade.php | 9 ++++++ 8 files changed, 110 insertions(+) create mode 100644 public/viewjs/stockjournalsummary.js create mode 100644 views/stockjournalsummary.blade.php diff --git a/controllers/StockApiController.php b/controllers/StockApiController.php index 94fd5ade..1830f943 100644 --- a/controllers/StockApiController.php +++ b/controllers/StockApiController.php @@ -720,6 +720,11 @@ class StockApiController extends BaseApiController return $this->FilteredApiResponse($response, $this->getDatabase()->uihelper_stock_journal(), $request->getQueryParams()); } + public function JournalSummary(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) + { + return $this->FilteredApiResponse($response, $this->getDatabase()->uihelper_stock_journal_summary(), $request->getQueryParams()); + } + public function __construct(\DI\Container $container) { parent::__construct($container); diff --git a/controllers/StockController.php b/controllers/StockController.php index 016bb41b..1de5e420 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -440,4 +440,24 @@ class StockController extends BaseController { parent::__construct($container); } + + public function JournalSummary(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) + { + $entries = $this->getDatabase()->uihelper_stock_journal_summary(); + if (isset($request->getQueryParams()['product_id'])) + { + $entries = $entries->where('product_id', $request->getQueryParams()['product_id']); + } + if (isset($request->getQueryParams()['user_id'])) + { + $entries = $entries->where('user_id', $request->getQueryParams()['user_id']); + } + if (isset($request->getQueryParams()['transaction_type'])) + { + $entries = $entries->where('transaction_type', $request->getQueryParams()['transaction_type']); + } + return $this->renderPage($response, 'stockjournalsummary', [ + 'entries' => $entries + ]); + } } diff --git a/localization/strings.pot b/localization/strings.pot index e76abe32..66e5dd37 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -1900,3 +1900,9 @@ msgstr "" msgid "Default" msgstr "" + +msgid "Journal-Summary" +msgstr "" + +msgid "Stock journal summary" +msgstr "" diff --git a/migrations/0115.sql b/migrations/0115.sql index 9eda39a5..543ad7e6 100644 --- a/migrations/0115.sql +++ b/migrations/0115.sql @@ -72,3 +72,18 @@ FROM stock_log JOIN products p on stock_log.product_id = p.id JOIN locations l on p.location_id = l.id JOIN quantity_units qu ON p.qu_id_stock = qu.id; + + +CREATE VIEW uihelper_stock_journal_summary +AS +SELECT user_id AS id, -- dummy, LessQL needs an id column + user_id, u.display_name AS user_display_name, p.name AS product_name, product_id, transaction_type, + qu.name AS qu_name, + qu.name_plural AS qu_name_plural, + SUM(amount) AS amount +FROM stock_log + JOIN users_dto u on stock_log.user_id = u.id + JOIN products p on stock_log.product_id = p.id + JOIN quantity_units qu ON p.qu_id_stock = qu.id +WHERE undone = 0 + GROUP BY user_id, product_id,transaction_type; diff --git a/public/viewjs/stockjournalsummary.js b/public/viewjs/stockjournalsummary.js new file mode 100644 index 00000000..1fae9a18 --- /dev/null +++ b/public/viewjs/stockjournalsummary.js @@ -0,0 +1,6 @@ +var journalSummaryTable = $('#journal-summary-table').DataTable({ + 'paginate': true, + 'order': [[0, 'desc']] +}); +$('#journal-summary-table tbody').removeClass("d-none"); +journalSummaryTable.columns.adjust().draw(); diff --git a/routes.php b/routes.php index ff463c9f..ab1377af 100644 --- a/routes.php +++ b/routes.php @@ -57,6 +57,7 @@ $app->group('', function (RouteCollectorProxy $group) { $group->get('/stockjournal', '\Grocy\Controllers\StockController:Journal'); $group->get('/locationcontentsheet', '\Grocy\Controllers\StockController:LocationContentSheet'); $group->get('/quantityunitpluraltesting', '\Grocy\Controllers\StockController:QuantityUnitPluralFormTesting'); + $group->get('/stockjournal/summary', '\Grocy\Controllers\StockController:JournalSummary'); } // Stock price tracking @@ -204,6 +205,7 @@ $app->group('/api', function (RouteCollectorProxy $group) { $group->get('/stock/barcodes/external-lookup/{barcode}', '\Grocy\Controllers\StockApiController:ExternalBarcodeLookup'); $group->get('/productbarcodedetails/{barcode}', '\Grocy\Controllers\StockApiController:ProductBarcodeDetails'); $group->get('/stock/journal', '\Grocy\Controllers\StockApiController:Journal'); + $group->get('/stock/journal/summary', '\Grocy\Controllers\StockApiController:JournalSummary'); } // Shopping list diff --git a/views/stockjournalsummary.blade.php b/views/stockjournalsummary.blade.php new file mode 100644 index 00000000..ba3e2b5f --- /dev/null +++ b/views/stockjournalsummary.blade.php @@ -0,0 +1,47 @@ +@extends('layout.default') + +@section('title', $__t('Stock journal summary')) +@section('activeNav', '') +@section('viewJsName', 'stockjournalsummary') + +@section('content') +
| {{ $__t('Product') }} | +{{ $__t('Booking type') }} | +{{ $__t('User') }} | +{{ $__t('Amount') }} | +
|---|---|---|---|
| + {{ $journalEntry->product_name }} + | ++ {{ $__t($journalEntry->transaction_type) }} + | ++ {{ $journalEntry->user_display_name }} + | ++ {{ $journalEntry->amount }} {{ $__n($journalEntry->amount, $journalEntry->qu_name, $journalEntry->qu_name_plural) }} + | +