You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2018-08-08 16:11:59

titan
Member
Registered: 2007-09-25
Posts: 30

Rapport sur fin de garantie

Amis développeurs, bonjour.

J'aimerais vous emprunter quelques minutes pour jeter un oeil sur mon code.
J'essaie, en vain, de générer un rapport qui afficherait la fin de garantie de mes machines par année.

J'avoue sans hésiter que n'étant, malheureusement, pas de la partie, j'ai copié des bouts de code de droite et gauche pour en arriver là.

Un grand merci d'avance ..


<?php

//    Options for GLPI 0.71 and newer : need slave db to access the report
$USEDBREPLICATE         = 1;
$DBCONNECTION_REQUIRED  = 1;

// Initialization of the variables
define('GLPI_ROOT',  '../../../..');
include (GLPI_ROOT . "/inc/includes.php");

//titre du rapport dans la liste de selection,  soit en dur ici, soit mettre à jour la variable dans les fichiers de traduction;
$report = new PluginReportsAutoReport($LANG['plugin_reports']['fingarantie']);

//critère de selection;
$date = new PluginReportsDateIntervalCriteria($report, 'WARRANTY_ENDDATE', "Fin de garantie");

$report->displayCriteriasForm();

if ($report->criteriasValidated()) {
//Intitulés des colonnes :  nom de la colonne dans la requete sql et nom affiché sur le rapport à l'ecran : mettre à jour la variable dans les fichiers de traduction;

$cols = array(new PluginReportsColumn('Nom_Machine', "Nom Machine"),
              new PluginReportsColumn('Lieu', "Lieu"),
              new PluginReportsColumn('type', "Type"),
              new PluginReportsColumn('modele', "Modéle"),
              new PluginReportsColumn('statut', "Statut"),
              new PluginReportsColumn('osname', "OS"),
              new PluginReportsColumn('serial', "Serial"),
              new PluginReportsColumn('Nom', "Nom"),
              new PluginReportsColumn('Prénom', "Prénom"),
              new PluginReportsColumn('Identifiant', "Identifiant"),
              new PluginReportsColumn('nomgroup', "Structure"),
              new PluginReportsColumn('WARRANTY_ENDDATE', "Fin de garantie"),
              );
   $report->setColumns($cols);

$query = "SELECT `glpi_entities`.`completename` as entite
,      glpi_computers.name as Nom_Machine
,      glpi_locations.completename as Lieu
,      glpi_states.name as statut
,      glpi_computers.`serial`
,      glpi_users.realname as Nom
,      glpi_users.firstname as Prénom
,      glpi_users.name as Identifiant
,      glpi_computers.`is_deleted`as detruit
,      g2.completename as nomgroup
,      glpi_users.id as cptewindows
,      glpi_groups_users.users_id ngroupu
,      glpi_groups_users.groups_id ngroup
,      glpi_computertypes.name as type
,      glpi_computermodels.name as modele
,`glpi_infocoms`.`warranty_date`, `warranty_duration`, DATE_FORMAT(DATE_ADD(`glpi_infocoms`.`warranty_date`, INTERVAL  `glpi_infocoms`.`warranty_duration` MONTH), GET_FORMAT(DATE, 'EUR')) AS WARRANTY_ENDDATE
FROM `glpi_computers`
left join glpi_users on glpi_computers.users_id=glpi_users.id
left join glpi_entities on glpi_computers.entities_id=glpi_entities.id
left join glpi_locations on glpi_computers.locations_id=glpi_locations.id
left join glpi_states on glpi_computers.states_id=glpi_states.id
left join glpi_usercategories on glpi_users.usercategories_id=glpi_usercategories.id
left join glpi_groups on glpi_computers.groups_id=glpi_groups.id
left join glpi_groups_users on glpi_users.id=glpi_groups_users.users_id
left join glpi_groups as g2 on g2.id=glpi_groups_users.groups_id
left join glpi_computertypes on glpi_computers.computertypes_id=glpi_computertypes.id
left join glpi_computermodels on glpi_computers.computermodels_id=glpi_computermodels.id
left join glpi_infocoms on glpi_computers.id=glpi_infocoms.items_id and glpi_infocoms.itemtype='Computer'
Where WARRANTY_ENDDATE.`date`>'" .$date->getStartDate() . " 00:00:00'  AND  WARRANTY_ENDDATE.`date`<'" .$date->getEndDate() . " 23:59:59'

GROUP BY warranty_enddate
";

$report->setSqlRequest($query);
$report->setGroupBy('warranty_enddate');
$report->execute();

}
else {
   Html::footer();
}

GLPI 9.2.1
rapport 1.11.0

Offline

#2 2018-08-08 16:40:06

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 6,167

Re: Rapport sur fin de garantie

votre clause where me parait bizzarre :  WARRANTY_ENDDATE n'est pas une table
je pense que si vous essayez votre requete dans php my admin par exemple vous avez une erreur :

vous devez écrire :
Where DATE_ADD(`glpi_infocoms`.`warranty_date`, INTERVAL  `glpi_infocoms`.`warranty_duration` MONTH) > '" .$date->getStartDate() . " 00:00:00'   AND DATE_ADD(`glpi_infocoms`.`warranty_date`, INTERVAL  `glpi_infocoms`.`warranty_duration` MONTH)<'" .$date->getEndDate() . " 23:59:59'


Trouver la panne avant de réparer...
GLPI10.0.10 (ubuntu 22.04 PHP8.1  Mariadb10.6 ) plugins : comportements 2.7.2 reports 1.16.0 formcreator 2.13.8, datainjection 2.13.4 fields 1.21.6

Offline

#3 2018-08-08 16:49:13

titan
Member
Registered: 2007-09-25
Posts: 30

Re: Rapport sur fin de garantie

Un grand MERCI LaDenrée, cela fonctionne parfaitement.

Offline

Board footer

Powered by FluxBB