mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Fix blank/missing items in spending report (#2432)
* Fixes blank/missing items in spending report Use left (outer) join when connecting product to optional product group * Properly display ungrouped items in table and chart --------- Co-authored-by: Bernd Bestel <bernd@berrnd.de>
This commit is contained in:
parent
99f448dd64
commit
151bd7f025
@ -29,10 +29,17 @@ class StockReportsController extends BaseController
|
|||||||
|
|
||||||
if ($groupBy == 'product')
|
if ($groupBy == 'product')
|
||||||
{
|
{
|
||||||
if (isset($request->getQueryParams()['product-group']) and $request->getQueryParams()['product-group'] != 'all')
|
if (isset($request->getQueryParams()['product-group']))
|
||||||
|
{
|
||||||
|
if ($request->getQueryParams()['product-group'] == 'ungrouped')
|
||||||
|
{
|
||||||
|
$where .= ' AND pg.id IS NULL';
|
||||||
|
}
|
||||||
|
elseif ($request->getQueryParams()['product-group'] != 'all')
|
||||||
{
|
{
|
||||||
$where .= ' AND pg.id = ' . $request->getQueryParams()['product-group'];
|
$where .= ' AND pg.id = ' . $request->getQueryParams()['product-group'];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT
|
SELECT
|
||||||
@ -44,7 +51,7 @@ class StockReportsController extends BaseController
|
|||||||
FROM products_price_history pph
|
FROM products_price_history pph
|
||||||
JOIN products p
|
JOIN products p
|
||||||
ON pph.product_id = p.id
|
ON pph.product_id = p.id
|
||||||
JOIN product_groups pg
|
LEFT JOIN product_groups pg
|
||||||
ON p.product_group_id = pg.id
|
ON p.product_group_id = pg.id
|
||||||
WHERE $where
|
WHERE $where
|
||||||
GROUP BY p.id, p.name, pg.id, pg.name
|
GROUP BY p.id, p.name, pg.id, pg.name
|
||||||
@ -61,7 +68,7 @@ class StockReportsController extends BaseController
|
|||||||
FROM products_price_history pph
|
FROM products_price_history pph
|
||||||
JOIN products p
|
JOIN products p
|
||||||
ON pph.product_id = p.id
|
ON pph.product_id = p.id
|
||||||
JOIN product_groups pg
|
LEFT JOIN product_groups pg
|
||||||
ON p.product_group_id = pg.id
|
ON p.product_group_id = pg.id
|
||||||
WHERE $where
|
WHERE $where
|
||||||
GROUP BY pg.id, pg.name
|
GROUP BY pg.id, pg.name
|
||||||
|
@ -4,7 +4,7 @@ var totalAmount = 0.0;
|
|||||||
$("#metrics-table tbody tr").each(function()
|
$("#metrics-table tbody tr").each(function()
|
||||||
{
|
{
|
||||||
var self = $(this);
|
var self = $(this);
|
||||||
labels.push(self.find("td:eq(0)").attr("data-chart-label"));
|
labels.push(self.find("td:eq(0)").text().trim());
|
||||||
var itemTotal = Number.parseFloat(self.find("td:eq(1)").attr("data-chart-value"));
|
var itemTotal = Number.parseFloat(self.find("td:eq(1)").attr("data-chart-value"));
|
||||||
data.push(itemTotal);
|
data.push(itemTotal);
|
||||||
totalAmount += + itemTotal;
|
totalAmount += + itemTotal;
|
||||||
|
@ -77,6 +77,8 @@
|
|||||||
<option @if($productGroup->id == $selectedGroup) selected="selected" @endif
|
<option @if($productGroup->id == $selectedGroup) selected="selected" @endif
|
||||||
value="{{ $productGroup->id }}">{{ $productGroup->name }}</option>
|
value="{{ $productGroup->id }}">{{ $productGroup->name }}</option>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
<option class="font-italic font-weight-light"
|
||||||
|
value="ungrouped">{{ $__t('Ungrouped') }}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -112,8 +114,16 @@
|
|||||||
<tbody class="d-none">
|
<tbody class="d-none">
|
||||||
@foreach($metrics as $metric)
|
@foreach($metrics as $metric)
|
||||||
<tr>
|
<tr>
|
||||||
<td data-chart-label="{{ $metric->name }}">
|
<td>
|
||||||
|
@if($groupBy == 'productgroup')
|
||||||
|
@if(empty($metric->name))
|
||||||
|
<span class="font-italic font-weight-light">{{ $__t('Ungrouped') }}</span>
|
||||||
|
@else
|
||||||
{{ $metric->name }}
|
{{ $metric->name }}
|
||||||
|
@endif
|
||||||
|
@else
|
||||||
|
{{ $metric->name }}
|
||||||
|
@endif
|
||||||
</td>
|
</td>
|
||||||
<td data-chart-value="{{ $metric->total }}"
|
<td data-chart-value="{{ $metric->total }}"
|
||||||
data-order="{{ $metric->total }}">
|
data-order="{{ $metric->total }}">
|
||||||
@ -121,7 +131,11 @@
|
|||||||
</td>
|
</td>
|
||||||
@if($groupBy == 'product')
|
@if($groupBy == 'product')
|
||||||
<td>
|
<td>
|
||||||
|
@if(empty($metric->group_name))
|
||||||
|
<span class="font-italic font-weight-light">{{ $__t('Ungrouped') }}</span>
|
||||||
|
@else
|
||||||
{{ $metric->group_name }}
|
{{ $metric->group_name }}
|
||||||
|
@endif
|
||||||
</td>
|
</td>
|
||||||
@endif
|
@endif
|
||||||
</tr>
|
</tr>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user