Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Make the plugin compatible with the Content Security Policy

### Fixed

- Inventory percentage reports failing with an SQL placeholder count error

## [1.11.1] - 2026-11-04

### Added
Expand Down
24 changes: 17 additions & 7 deletions inc/inventory.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ public static function getCriteriaStateCondition($field)
return [];
}

/**
* Build a "COUNT(*) * 100 / (total subquery)" expression keeping the subquery parameters.
*/
private static function getPercentExpression(array $subquery, string $alias): QueryExpression
{
$total = new QuerySubQuery($subquery, $alias);

return new QueryExpression('COUNT(*) * 100 / ' . $total, null, $total->getParams());
}

/* ==== MANUFACTURERS REPORTS ==== */
public function reportPieComputersByFabricant($config = [])
{
Expand Down Expand Up @@ -164,7 +174,7 @@ public function computersByFabricant($config = [])
$query = [
'SELECT' => [
Manufacturer::getTable() . '.name as Manufacturer',
new QueryExpression("COUNT(*) * 100 / " . new QuerySubQuery($subquery, 'Percent')),
self::getPercentExpression($subquery, 'Percent'),
],
'COUNT' => 'Total',
'FROM' => Computer::getTable(),
Expand Down Expand Up @@ -249,7 +259,7 @@ public function computersByType($config = [])
$query = [
'SELECT' => [
ComputerType::getTable() . '.name as Type',
new QueryExpression("COUNT(*) * 100 / " . new QuerySubQuery($subquery, 'Percent')),
self::getPercentExpression($subquery, 'Percent'),
],
'COUNT' => 'Total',
'FROM' => Computer::getTable(),
Expand Down Expand Up @@ -358,7 +368,7 @@ public function computersByAge($config = [])
$query_union = [
'SELECT' => [
new QueryExpression($label),
new QueryExpression("COUNT(*) * 100 / " . new QuerySubQuery($subquery, 'Percent')),
self::getPercentExpression($subquery, 'Percent'),
],
'COUNT' => 'Total',
'FROM' => Computer::getTable(),
Expand Down Expand Up @@ -460,7 +470,7 @@ public function computersByOS($config = [])
$queries[] = [
'SELECT' => [
new QueryExpression("'$os'" . " AS OS"),
new QueryExpression("COUNT(*) * 100 / " . new QuerySubQuery($subquery, 'Percent')),
self::getPercentExpression($subquery, 'Percent'),
],
'COUNT' => 'Total',
'FROM' => Computer::getTable(),
Expand Down Expand Up @@ -493,7 +503,7 @@ public function computersByOS($config = [])
$queries[] = [
'SELECT' => [
new QueryExpression("'" . __s('Others') . "' AS OS"),
new QueryExpression("COUNT(*) * 100 / " . new QuerySubQuery($subquery, 'Percent')),
self::getPercentExpression($subquery, 'Percent'),
],
'COUNT' => 'Total',
'FROM' => Computer::getTable(),
Expand Down Expand Up @@ -995,7 +1005,7 @@ public function reportHbarComputersByStatus($config = [])
$query = [
'SELECT' => [
State::getTable() . '.name as status',
new QueryExpression("COUNT(*) * 100 / " . new QuerySubQuery($subquery, 'Percent')),
self::getPercentExpression($subquery, 'Percent'),
],
'COUNT' => 'Total',
'FROM' => Computer::getTable(),
Expand Down Expand Up @@ -1055,7 +1065,7 @@ public function reportHbarPrintersByStatus($config = [])
$query = [
'SELECT' => [
State::getTable() . '.name as status',
new QueryExpression("COUNT(*) * 100 / " . new QuerySubQuery($subquery, 'Pourcentage')),
self::getPercentExpression($subquery, 'Pourcentage'),
],
'COUNT' => 'Total',
'FROM' => Printer::getTable(),
Expand Down