.
* ---------------------------------------------------------------------
*/
include ('../inc/includes.php');
Session::checkRight("reports", READ);
Html::header(Report::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "tools", "report");
Report::title();
$items = $CFG_GLPI["contract_types"];
// Titre
echo "
";
echo "".__('List of the hardware under contract')."
";
echo "
";
// Request All
if ((isset($_POST["item_type"][0]) && ($_POST["item_type"][0] == '0'))
|| !isset($_POST["item_type"])) {
$_POST["item_type"] = $items;
}
if (isset($_POST["item_type"]) && is_array($_POST["item_type"])) {
$query = [];
$all_criteria = [];
foreach ($_POST["item_type"] as $key => $val) {
if (!in_array($val, $items)) {
continue;
}
$itemtable = getTableForItemType($val);
$criteria = [
'SELECT' => [
'glpi_contracttypes.name AS type',
'glpi_contracts.duration',
'glpi_entities.completename AS entname',
'glpi_entities.id AS entID',
'glpi_contracts.begin_date'
],
'FROM' => 'glpi_contracts_items',
'INNER JOIN' => [
'glpi_contracts' => [
'ON' => [
'glpi_contracts_items' => 'contracts_id',
'glpi_contracts' => 'id'
]
],
$itemtable => [
'ON' => [
$itemtable => 'id',
'glpi_contracts_items' => 'items_id', [
'AND' => [
'glpi_contracts_items.itemtype' => $val
]
]
]
]
],
'LEFT JOIN' => [
'glpi_contracttypes' => [
'ON' => [
'glpi_contracts' => 'contracttypes_id',
'glpi_contracttypes' => 'id'
]
],
'glpi_entities' => [
'ON' => [
$itemtable => 'entities_id',
'glpi_entities' => 'id'
]
]
],
'WHERE' => getEntitiesRestrictCriteria($itemtable),
'ORDERBY' => ["entname ASC", 'itemdeleted DESC', "itemname ASC"]
];
if ($DB->fieldExists($itemtable, 'name')) {
$criteria['SELECT'][] = "$itemtable.name AS itemname";
} else {
$criteria['SELECT'][] = new QueryExpression("'' AS ".$DB->quoteName('itemname'));
}
if (($val == 'Project')
|| ($val == 'SoftwareLicense')) {
if ($val == 'SoftwareLicense') {
$criteria['ORDERBY'] = ["entname ASC", "itemname ASC"];
$criteria['SELECT'] = array_merge(
$criteria['SELECT'],
['glpi_infocoms.buy_date', 'glpi_infocoms.warranty_duration']
);
$criteria['LEFT JOIN']['glpi_infocoms'] = [
'ON' => [
'glpi_infocoms' => 'items_id',
$itemtable => 'id', [
'AND' => [
'glpi_infocoms.itemtype' => $val
]
]
]
];
}
if ($val == 'Project') {
$criteria['SELECT'][] = "$itemtable.is_deleted AS itemdeleted";
}
if (isset($_POST["year"][0]) && ($_POST["year"][0] != 0)) {
$ors = [];
foreach ($_POST["year"] as $val2) {
$ors[] = new QueryExpression('YEAR('.$DB->quoteName('glpi_contracts.begin_date').') = '.$DB->quote($val2));
if ($val == 'SoftwareLicense') {
$ors[] = new QueryExpression('YEAR('.$DB->quoteName('glpi_infocoms.buy_date').') = '.$DB->quote($val2));
}
}
if (count($ors)) {
$criteria['WHERE'][] = ['OR' => $ors];
}
}
} else {
$criteria['SELECT'] = array_merge($criteria['SELECT'], [
"$itemtable.is_deleted AS itemdeleted",
'glpi_locations.completename AS location',
'glpi_infocoms.buy_date',
'glpi_infocoms.warranty_duration'
]);
$criteria['LEFT JOIN']['glpi_infocoms'] = [
'ON' => [
$itemtable => 'id',
'glpi_infocoms' => 'items_id', [
'AND' => [
'glpi_infocoms.itemtype' => $val
]
]
]
];
$criteria['LEFT JOIN']['glpi_locations'] = [
'ON' => [
$itemtable => 'locations_id',
'glpi_locations' => 'id'
]
];
if ($DB->fieldExists($itemtable, 'is_template')) {
$criteria['WHERE'][] = ["$itemtable.is_template" => 0];
}
if (isset($_POST["year"][0]) && ($_POST["year"][0] != 0)) {
foreach ($_POST["year"] as $val2) {
$ors[] = new QueryExpression('YEAR('.$DB->quoteName('glpi_infocoms.buy_date').') = '.$DB->quoteValue($val2));
$ors[] = new QueryExpression('YEAR('.$DB->quoteName('glpi_contracts.begin_date').') = '.$DB->quoteValue($val2));
}
if (count($ors)) {
$criteria['WHERE'][] = ['OR' => $ors];
}
}
}
$all_criteria[$val] = $criteria;
}
}
$display_entity = Session::isMultiEntitiesMode();
if (count($all_criteria)) {
foreach ($all_criteria as $key => $criteria) {
$iterator = $DB->request($criteria);
if (count($iterator)) {
$item = new $key();
echo "".$item->getTypeName(1)."
";
echo "";
echo "| ".__('Name')." | ";
echo "".__('Deleted')." | ";
if ($display_entity) {
echo "".Entity::getTypeName(1)." | ";
}
echo "".Location::getTypeName(1)." | ";
echo "".__('Date of purchase')." | ";
echo "".__('Warranty expiration date')." | ";
echo "".ContractType::getTypeName(1)." | ";
echo "".__('Start date')." | ";
echo "".__('End date')." | ";
echo "
";
while ($data = $iterator->next()) {
echo "";
if ($data['itemname']) {
echo "| ".$data['itemname']." | ";
} else {
echo " ".NOT_AVAILABLE." | ";
}
if (!isset($data['itemdeleted'])) {
$data['itemdeleted'] = 0;
}
if (!isset($data['buy_date'])) {
$data['buy_date'] = '';
}
if (!isset($data['warranty_duration'])) {
$data['warranty_duration'] = 0;
}
echo " ".Dropdown::getYesNo($data['itemdeleted'])." | ";
if ($display_entity) {
echo "".$data['entname']." | ";
}
if ($data['location']) {
echo " ".$data['location']." | ";
} else {
echo " ".NOT_AVAILABLE." | ";
}
if ($data['buy_date']) {
echo " ".Html::convDate($data['buy_date'])." | ";
if ($data["warranty_duration"]) {
echo " ".Infocom::getWarrantyExpir($data["buy_date"],
$data["warranty_duration"])." | ";
} else {
echo " ".NOT_AVAILABLE." | ";
}
} else {
echo " ".NOT_AVAILABLE." | ".NOT_AVAILABLE." | ";
}
if ($data['type']) {
echo " ".$data['type']." | ";
} else {
echo " ".NOT_AVAILABLE." | ";
}
if ($data['begin_date']) {
echo " ".Html::convDate($data['begin_date'])." | ";
if ($data["duration"]) {
echo " ".Infocom::getWarrantyExpir($data["begin_date"],
$data["duration"])." | ";
} else {
echo " ".NOT_AVAILABLE." | ";
}
} else {
echo " ".NOT_AVAILABLE." | ".NOT_AVAILABLE." | ";
}
echo "
\n";
}
echo "
";
}
}
}
Html::footer();