You are not logged in.
Pages: 1
Hey there
ive been trying to get this mreporting plugin working but i totally suck at php any help would be awesome! ive figured out how to list the custom report in */locales/reports_locales/en_GB.php and add a new report in its class file i just cant figure out how the report handles data itself. im trying to get the following code to sort by warranty age and device type. it would be a awesome addition to help figure out device cycles with a glance.
the original php file is located below also includes a working example of type above the age report.
https://github.com/pluginsGLPI/mreporti … .class.php
how to use it is located here but didnt help me too much as i dont know too much php
https://github.com/pluginsGLPI/mreporti … op-reports
/* ==== COMPUTER'S AGE REPORTS ==== */
function reportPieComputersByAge($config = array()) {
$_SESSION['mreporting_selector']['reportPieComputersByAge'] = array('multiplestates');
return $this->computersByAge($config);
}
function reportHbarComputersByAge($config = array()) {
$_SESSION['mreporting_selector']['reportHbarComputersByAge'] = array('multiplestates');
return $this->computersByAge($config);
}
function computersByAge($config = array()) {
global $DB;
$sql_entities = " AND c.`entities_id` IN ({$this->where_entities})";
$sql_states = self::getStateCondition('c.states_id');
$datas = array();
$query = "SELECT '< 1 year' Age, count(*) Total, count(*) * 100 / (SELECT count(*)
FROM glpi_computers as c,
glpi_infocoms as i
WHERE c.`id` = i.`items_id`
AND c.`is_deleted` = 0
AND c.`is_template` = 0
AND itemtype = 'Computer'
$sql_entities
$sql_states) Percent
FROM glpi_computers as c,
glpi_infocoms as i
WHERE c.`id` = i.`items_id`
AND c.`is_deleted` = 0
AND c.`is_template` = 0
AND itemtype = 'Computer'
AND i.`warranty_date` > CURRENT_DATE - INTERVAL 1 YEAR
$sql_entities
$sql_states
UNION
SELECT '1-3 years' Age, count(*) Total, count(*) * 100 / (SELECT count(*)
FROM glpi_computers c, glpi_infocoms i
WHERE c.`id` = i.`items_id`
AND c.`is_deleted` = 0
AND c.`is_template` = 0
AND itemtype = 'Computer'
$sql_entities
$sql_states) Percent
FROM glpi_computers as c,
glpi_infocoms as i
WHERE c.`id` = i.`items_id`
AND c.`is_deleted` = 0
AND c.`is_template` = 0
AND itemtype = 'Computer'
AND i.`warranty_date` <= CURRENT_DATE - INTERVAL 1 YEAR
AND i.`warranty_date` > CURRENT_DATE - INTERVAL 3 YEAR
$sql_entities
$sql_states
UNION
SELECT '3-5 years' Age, count(*) Total, count(*) * 100 / (SELECT count(*)
FROM glpi_computers c, glpi_infocoms i
WHERE c.`id` = i.`items_id`
AND c.`is_deleted` = 0
AND c.`is_template` = 0
AND itemtype = 'Computer'
$sql_entities
$sql_states) Percent
FROM glpi_computers as c,
glpi_infocoms as i
WHERE c.`id` = i.`items_id`
AND c.`is_deleted` = 0
AND c.`is_template` = 0
AND itemtype = 'Computer'
AND i.`warranty_date` <= CURRENT_DATE - INTERVAL 3 YEAR
AND i.`warranty_date` > CURRENT_DATE - INTERVAL 5 YEAR
$sql_entities
$sql_states
UNION
SELECT '> 5 years' Age, count(*) Total, count(*) * 100 / (SELECT count(*)
FROM glpi_computers c, glpi_infocoms i
WHERE c.`id` = i.`items_id`
AND c.`is_deleted` = 0
AND c.`is_template` = 0
AND itemtype = 'Computer'
$sql_entities
$sql_states) Percent
FROM glpi_computers as c,
glpi_infocoms as i
WHERE c.`id` = i.`items_id`
AND c.`is_deleted` = 0
AND c.`is_template` = 0
AND itemtype = 'Computer'
AND i.`warranty_date` <= CURRENT_DATE - INTERVAL 5 YEAR
$sql_entities
$sql_states
UNION
SELECT 'Undefined' Age, count(*) Total, count(*) * 100 / (SELECT count(*)
FROM glpi_computers c, glpi_infocoms i
WHERE c.`id` = i.`items_id`
AND c.`is_deleted` = 0
AND c.`is_template` = 0
AND itemtype = 'Computer'
$sql_entities
$sql_states) Percent
FROM glpi_computers as c,
glpi_infocoms as i
WHERE c.`id` = i.`items_id`
AND c.`is_deleted` = 0
AND c.`is_template` = 0
AND itemtype = 'Computer'
AND i.`warranty_date` IS NULL
$sql_entities
$sql_states
ORDER BY Total DESC";
$result = $DB->query($query);
while ($computer = $DB->fetch_assoc($result)) {
$percent = round($computer['Percent'], 2);
$datas['datas'][__($computer['Age'], 'mreporting')." ($percent %)"] = $computer['Total'];
}
return $datas;
}
Thanks again!
Last edited by giddyk0ng (2017-06-06 14:50:05)
Offline
Pages: 1