First draft for printable location content sheets (references #341)

This commit is contained in:
Bernd Bestel 2019-08-10 16:34:29 +02:00
parent d6e9dc1b59
commit 28716ed96c
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
6 changed files with 91 additions and 0 deletions

View File

@ -262,4 +262,14 @@ class StockController extends BaseController
'quantityunits' => $this->Database->quantity_units()->orderBy('name') '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()
]);
}
} }

View File

@ -1292,3 +1292,9 @@ msgstr ""
msgid "When enabled the chore can never be overdue, the due date will shift forward each day when due" msgid "When enabled the chore can never be overdue, the due date will shift forward each day when due"
msgstr "" msgstr ""
msgid "Print"
msgstr ""
msgid "Location Content Sheet"
msgstr ""

12
migrations/0079.sql Normal file
View File

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

View File

@ -41,6 +41,7 @@ $app->group('', function()
$this->get('/productgroups', '\Grocy\Controllers\StockController:ProductGroupsList'); $this->get('/productgroups', '\Grocy\Controllers\StockController:ProductGroupsList');
$this->get('/productgroup/{productGroupId}', '\Grocy\Controllers\StockController:ProductGroupEditForm'); $this->get('/productgroup/{productGroupId}', '\Grocy\Controllers\StockController:ProductGroupEditForm');
$this->get('/stockjournal', '\Grocy\Controllers\StockController:Journal'); $this->get('/stockjournal', '\Grocy\Controllers\StockController:Journal');
$this->get('/locationcontentsheet', '\Grocy\Controllers\StockController:LocationContentSheet');
} }
// Shopping list routes // Shopping list routes

View File

@ -20,6 +20,12 @@ class StockService extends BaseService
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ); 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() public function GetCurrentStockLocations()
{ {
$sql = 'SELECT * FROM stock_current_locations'; $sql = 'SELECT * FROM stock_current_locations';

View File

@ -0,0 +1,56 @@
@extends('layout.default')
@section('title', $__t('Location Content Sheet'))
@push('pageStyles')
<style>
@media print
{
.page {
page-break-after: always !important;
}
}
</style>
@endpush
@section('content')
<h1 class="d-print-none">
<a class="btn btn-outline-dark responsive-button" href="javascript:window.print();">
<i class="fas fa-print"></i> {{ $__t('Print') }}
</a>
</h1>
@foreach($locations as $location)
<div class="page">
<h1>{{ $location->name }}</h1>
@php $currentStockEntriesForLocation = FindAllObjectsInArrayByPropertyValue($currentStockLocationContent, 'location_id', $location->id); @endphp
<div class="row w-50">
<div class="col">
<table class="table table-sm table-striped">
<thead>
<tr>
<th>{{ $__t('Product') }}</th>
<th>{{ $__t('Amount') }}</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach($currentStockEntriesForLocation as $currentStockEntry)
<tr>
<td>
{{ FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->name }}
</td>
<td>
<span>{{ $currentStockEntry->amount }}</span> <span id="product-{{ $currentStockEntry->product_id }}-qu-name">{{ $__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) }}</span>
<span class="small font-italic">@if($currentStockEntry->amount_opened > 0){{ $__t('%s opened', $currentStockEntry->amount_opened) }}@endif</span>
</td>
<td class="fit-content">____________________</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
@endforeach
@stop