InfotelGLPI / printercounters

Plugin Printercounters for GLPI
http://blogglpi.infotel.com
GNU General Public License v2.0
14 stars 9 forks source link

Budget doesn't work with Printers into 'Root Entity' #69

Open eduardomozart opened 3 years ago

eduardomozart commented 3 years ago

Plug-in doesn't show printer budgets for printers located at 'Root Entity'.

Budget from printers of 'Root Entity' should be calculated.

The printer page cost and other informations related to "Budget" isn't calculated.

https://glpi.example.com/plugins/printercounters/front/budget.php

The error happens because the 'Default Root' entity has ID '0'. The 'parseData' function (search.class.php) into the line 2176 compares the results with "Search::NULLVALUE", but this comparision also considerates '0' ('Default Root' ID) as a NULL value, so when glpi_plugin_printercounters_budgets.entities_id = 0, this function will set it as a null value and when the function getRecordAmount call it's sons it will fail because entities_id is null.

Changing the line 2176 from search.class.php from:

if ($val == Search::NULLVALUE) {

To:

if ($val !== 0 && $val == Search::NULLVALUE) {

fixed the problem and the entity ID from 'Default Root' entity returned as expected ('0'). I'll send a Pull Request with the bugfix above.

Here's the full debug function paths, for anyone interesting:

inc\search.class.php
   parseData

inc\budget.class.php
    formatSearchData -> getRecordsAmountForBudget -> getRecordAmount