diff --git a/controllers/StockController.php b/controllers/StockController.php index a395d07a..c6f0e82c 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -262,4 +262,14 @@ class StockController extends BaseController 'quantityunits' => $this->Database->quantity_units()->orderBy('name') ]); } + + public function LocationContentSheet(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) + { + return $this->AppContainer->view->render($response, 'locationcontentsheet', [ + 'products' => $this->Database->products()->orderBy('name'), + 'quantityunits' => $this->Database->quantity_units()->orderBy('name'), + 'locations' => $this->Database->locations()->orderBy('name'), + 'currentStockLocationContent' => $this->StockService->GetCurrentStockLocationContent() + ]); + } } diff --git a/localization/strings.pot b/localization/strings.pot index 5148d7b7..ef3ccc2b 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -1292,3 +1292,9 @@ msgstr "" msgid "When enabled the chore can never be overdue, the due date will shift forward each day when due" msgstr "" + +msgid "Print" +msgstr "" + +msgid "Location Content Sheet" +msgstr "" diff --git a/migrations/0079.sql b/migrations/0079.sql new file mode 100644 index 00000000..4c96a198 --- /dev/null +++ b/migrations/0079.sql @@ -0,0 +1,12 @@ +CREATE VIEW stock_current_location_content +AS +SELECT + IFNULL(s.location_id, p.location_id) AS location_id, + s.product_id, + SUM(s.amount) AS amount, + MIN(s.best_before_date) AS best_before_date, + IFNULL((SELECT SUM(amount) FROM stock WHERE product_id = s.product_id AND location_id = s.location_id AND open = 1), 0) AS amount_opened +FROM stock s +JOIN products p + ON s.product_id = p.id +GROUP BY IFNULL(s.location_id, p.location_id), s.product_id; diff --git a/routes.php b/routes.php index 3e9aa669..b99a5e39 100644 --- a/routes.php +++ b/routes.php @@ -41,6 +41,7 @@ $app->group('', function() $this->get('/productgroups', '\Grocy\Controllers\StockController:ProductGroupsList'); $this->get('/productgroup/{productGroupId}', '\Grocy\Controllers\StockController:ProductGroupEditForm'); $this->get('/stockjournal', '\Grocy\Controllers\StockController:Journal'); + $this->get('/locationcontentsheet', '\Grocy\Controllers\StockController:LocationContentSheet'); } // Shopping list routes diff --git a/services/StockService.php b/services/StockService.php index 7bf2cfa2..cf616707 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -20,6 +20,12 @@ class StockService extends BaseService return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ); } + public function GetCurrentStockLocationContent() + { + $sql = 'SELECT * FROM stock_current_location_content'; + return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ); + } + public function GetCurrentStockLocations() { $sql = 'SELECT * FROM stock_current_locations'; diff --git a/views/locationcontentsheet.blade.php b/views/locationcontentsheet.blade.php new file mode 100644 index 00000000..0881d4f1 --- /dev/null +++ b/views/locationcontentsheet.blade.php @@ -0,0 +1,56 @@ +@extends('layout.default') + +@section('title', $__t('Location Content Sheet')) + +@push('pageStyles') + +@endpush + +@section('content') +

+ + {{ $__t('Print') }} + +

+ +@foreach($locations as $location) +
+

{{ $location->name }}

+ @php $currentStockEntriesForLocation = FindAllObjectsInArrayByPropertyValue($currentStockLocationContent, 'location_id', $location->id); @endphp +
+
+ + + + + + + + + + @foreach($currentStockEntriesForLocation as $currentStockEntry) + + + + + + @endforeach + +
{{ $__t('Product') }}{{ $__t('Amount') }}
+ {{ FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->name }} + + {{ $currentStockEntry->amount }} {{ $__n($currentStockEntry->amount, FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->qu_id_stock)->name, FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->qu_id_stock)->name_plural) }} + @if($currentStockEntry->amount_opened > 0){{ $__t('%s opened', $currentStockEntry->amount_opened) }}@endif + ____________________
+
+
+
+@endforeach +@stop