ryxeo-glpi-git / htdocs / inc / infocom.function.php @ 1c14bcc4
Historique | Voir | Annoter | Télécharger (20 ko)
1 |
<?php
|
---|---|
2 |
/*
|
3 |
* @version $Id: infocom.function.php 7763 2009-01-06 18:44:50Z moyo $
|
4 |
-------------------------------------------------------------------------
|
5 |
GLPI - Gestionnaire Libre de Parc Informatique
|
6 |
Copyright (C) 2003-2009 by the INDEPNET Development Team.
|
7 |
|
8 |
http://indepnet.net/ http://glpi-project.org
|
9 |
-------------------------------------------------------------------------
|
10 |
|
11 |
LICENSE
|
12 |
|
13 |
This file is part of GLPI.
|
14 |
|
15 |
GLPI is free software; you can redistribute it and/or modify
|
16 |
it under the terms of the GNU General Public License as published by
|
17 |
the Free Software Foundation; either version 2 of the License, or
|
18 |
(at your option) any later version.
|
19 |
|
20 |
GLPI is distributed in the hope that it will be useful,
|
21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
GNU General Public License for more details.
|
24 |
|
25 |
You should have received a copy of the GNU General Public License
|
26 |
along with GLPI; if not, write to the Free Software
|
27 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
28 |
--------------------------------------------------------------------------
|
29 |
*/
|
30 |
|
31 |
// ----------------------------------------------------------------------
|
32 |
// Original Author of file: Julien Dombre
|
33 |
// Purpose of file:
|
34 |
// ----------------------------------------------------------------------
|
35 |
|
36 |
if (!defined('GLPI_ROOT')){ |
37 |
die("Sorry. You can't access directly to this file"); |
38 |
} |
39 |
|
40 |
|
41 |
/** Show Infocom form for an item
|
42 |
* @param $target string: where to go on action
|
43 |
* @param $device_type integer: item type
|
44 |
* @param $dev_ID integer: item ID
|
45 |
* @param $show_immo boolean: show immobilisation infos
|
46 |
* @param $withtemplate integer: template or basic item
|
47 |
*/
|
48 |
function showInfocomForm($target,$device_type,$dev_ID,$show_immo=true,$withtemplate='') { |
49 |
// Show Infocom or blank form
|
50 |
|
51 |
global $CFG_GLPI,$LANG; |
52 |
if (!haveRight("contract_infocom","r")) return false; |
53 |
$date_fiscale=$CFG_GLPI["date_fiscale"]; |
54 |
|
55 |
$ic = new Infocom; |
56 |
$ci=new CommonItem(); |
57 |
$option=""; |
58 |
if ($withtemplate==2) |
59 |
$option=" readonly "; |
60 |
|
61 |
if (!ereg("infocoms-show",$_SERVER['PHP_SELF'])&&($device_type==SOFTWARE_TYPE||$device_type==CARTRIDGE_TYPE||$device_type==CONSUMABLE_TYPE)){ |
62 |
echo "<div class='center'>".$LANG["financial"][84]."</div>"; |
63 |
} |
64 |
|
65 |
echo "<br>"; |
66 |
if ($ci->getFromDB($device_type,$dev_ID)) |
67 |
if (!$ic->getFromDBforDevice($device_type,$dev_ID)){ |
68 |
if (haveRight("contract_infocom","w")&&$withtemplate!=2){ |
69 |
echo "<div class='center'>"; |
70 |
echo "<strong><a href='$target?device_type=$device_type&FK_device=$dev_ID&add=add'>".$LANG["financial"][68]."</a></strong>"; |
71 |
echo "</div><br>"; |
72 |
} |
73 |
} else {
|
74 |
if ($withtemplate!=2) |
75 |
echo "<form name='form_ic' method='post' action=\"$target\">"; |
76 |
|
77 |
echo "<div class='center'>"; |
78 |
echo "<table class='tab_cadre".(!ereg("infocoms-show",$_SERVER['PHP_SELF'])?"_fixe":"")."'>"; |
79 |
|
80 |
echo "<tr><th colspan='4'>".$LANG["financial"][3]."</th></tr>"; |
81 |
|
82 |
echo "<tr class='tab_bg_1'><td>".$LANG["financial"][26].": </td>"; |
83 |
echo "<td class='center'>"; |
84 |
if ($withtemplate==2) { |
85 |
echo getDropdownName("glpi_enterprises",$ic->fields["FK_enterprise"]); |
86 |
} else {
|
87 |
dropdownValue("glpi_enterprises","FK_enterprise",$ic->fields["FK_enterprise"],1,$ci->getField('FK_entities')); |
88 |
} |
89 |
|
90 |
echo "</td>"; |
91 |
echo "<td>".$LANG["financial"][82].": </td>"; |
92 |
echo "<td >"; |
93 |
autocompletionTextField("facture","glpi_infocoms","facture",$ic->fields["facture"],25,-1,$option); |
94 |
echo "</td></tr>"; |
95 |
|
96 |
echo "<tr class='tab_bg_1'><td>".$LANG["financial"][18].": </td>"; |
97 |
echo "<td >"; |
98 |
autocompletionTextField("num_commande","glpi_infocoms","num_commande",$ic->fields["num_commande"],25,-1,$option); |
99 |
echo "</td>"; |
100 |
|
101 |
echo "<td>".$LANG["financial"][19].": </td><td>"; |
102 |
autocompletionTextField("bon_livraison","glpi_infocoms","bon_livraison",$ic->fields["bon_livraison"],25,-1,$option); |
103 |
echo "</td></tr>"; |
104 |
|
105 |
// Can edit calendar ?
|
106 |
$editcalendar=($withtemplate!=2); |
107 |
|
108 |
echo "<tr class='tab_bg_1'><td>".$LANG["financial"][14].": </td><td>"; |
109 |
showCalendarForm("form_ic","buy_date",$ic->fields["buy_date"],$editcalendar); |
110 |
echo "</td>"; |
111 |
|
112 |
|
113 |
echo "<td>".$LANG["financial"][76].": </td><td>"; |
114 |
showCalendarForm("form_ic","use_date",$ic->fields["use_date"],$editcalendar); |
115 |
echo "</td>"; |
116 |
echo "</tr>"; |
117 |
|
118 |
if ($show_immo){ |
119 |
|
120 |
echo "<tr class='tab_bg_1'><td>".$LANG["financial"][15].": </td><td>"; |
121 |
if ($withtemplate==2){ |
122 |
// -1 = life
|
123 |
if ($ic->fields["warranty_duration"]==-1){ |
124 |
echo $LANG["financial"][2]; |
125 |
} else {
|
126 |
echo $ic->fields["warranty_duration"]; |
127 |
} |
128 |
} else {
|
129 |
dropdownInteger("warranty_duration",$ic->fields["warranty_duration"],0,120,1,array(-1=>$LANG["financial"][2])); |
130 |
} |
131 |
if ($ic->fields["warranty_duration"]>=0){ |
132 |
echo " ".$LANG["financial"][57]; |
133 |
} |
134 |
echo " ".$LANG["financial"][88]." "; |
135 |
echo getWarrantyExpir($ic->fields["buy_date"],$ic->fields["warranty_duration"]); |
136 |
echo "</td>"; |
137 |
|
138 |
echo "<td>".$LANG["financial"][87].": </td><td >"; |
139 |
|
140 |
dropdownValue("glpi_dropdown_budget","budget",$ic->fields["budget"]); |
141 |
|
142 |
echo "</td></tr>"; |
143 |
|
144 |
|
145 |
echo "<tr class='tab_bg_1'><td>".$LANG["financial"][78].": </td>"; |
146 |
echo "<td ><input type='text' $option name='warranty_value' value=\"".formatNumber($ic->fields["warranty_value"],true)."\" size='16'></td>"; |
147 |
|
148 |
|
149 |
echo "<td>".$LANG["financial"][16].": </td>"; |
150 |
echo "<td >"; |
151 |
autocompletionTextField("warranty_info","glpi_infocoms","warranty_info",$ic->fields["warranty_info"],25,-1,$option); |
152 |
|
153 |
echo "</td></tr>"; |
154 |
} |
155 |
|
156 |
echo "<tr class='tab_bg_1'><td>".$LANG["financial"][21].": </td><td ".($show_immo?"":" colspan='3'")."><input type='text' name='value' $option value=\"".formatNumber($ic->fields["value"],true)."\" size='16'></td>"; |
157 |
if ($show_immo){ |
158 |
echo "<td>".$LANG["financial"][81]." :</td><td>"; |
159 |
|
160 |
echo formatNumber(TableauAmort($ic->fields["amort_type"],$ic->fields["value"],$ic->fields["amort_time"],$ic->fields["amort_coeff"],$ic->fields["buy_date"],$ic->fields["use_date"],$date_fiscale,"n")); |
161 |
|
162 |
echo "</td>"; |
163 |
} |
164 |
echo "</tr>"; |
165 |
|
166 |
if ($show_immo){ |
167 |
echo "<tr class='tab_bg_1'><td>".$LANG["financial"][20]."*: </td>"; |
168 |
echo "<td >"; |
169 |
$objectName = autoName($ic->fields["num_immo"], "num_immo", ($withtemplate==2), INFOCOM_TYPE,$ci->getField('FK_entities')); |
170 |
autocompletionTextField("num_immo","glpi_infocoms","num_immo",$objectName,25,-1,$option); |
171 |
|
172 |
echo "</td>"; |
173 |
|
174 |
|
175 |
|
176 |
|
177 |
echo "<td>".$LANG["financial"][22].": </td><td >"; |
178 |
if ($withtemplate==2){ |
179 |
echo getAmortTypeName($ic->fields["amort_type"]); |
180 |
} else {
|
181 |
dropdownAmortType("amort_type",$ic->fields["amort_type"]); |
182 |
} |
183 |
|
184 |
echo "</td></tr>"; |
185 |
|
186 |
echo "<tr class='tab_bg_1'><td>".$LANG["financial"][23].": </td><td>"; |
187 |
if ($withtemplate==2){ |
188 |
echo $ic->fields["amort_time"]; |
189 |
} else {
|
190 |
dropdownInteger("amort_time",$ic->fields["amort_time"],0,15); |
191 |
} |
192 |
echo " ".$LANG["financial"][9]; |
193 |
echo "</td>"; |
194 |
|
195 |
echo "<td>".$LANG["financial"][77].": </td>"; |
196 |
echo "<td >"; |
197 |
autocompletionTextField("amort_coeff","glpi_infocoms","amort_coeff",$ic->fields["amort_coeff"],10,-1,$option); |
198 |
echo "</td></tr>"; |
199 |
} |
200 |
//TCO
|
201 |
if ($device_type!=SOFTWARE_TYPE&&$device_type!=CARTRIDGE_TYPE&&$device_type!=CONSUMABLE_TYPE&&$device_type!=CONSUMABLE_ITEM_TYPE&&$device_type!=LICENSE_TYPE&&$device_type!=CARTRIDGE_ITEM_TYPE){ |
202 |
echo "<tr class='tab_bg_1'><td>"; |
203 |
echo $LANG["financial"][89]." : </td><td>"; |
204 |
echo showTco($ci->getField('ticket_tco'),$ic->fields["value"]); |
205 |
echo "</td><td>".$LANG["financial"][90]." : </td><td>"; |
206 |
echo showTco($ci->getField('ticket_tco'),$ic->fields["value"],$ic->fields["buy_date"]); |
207 |
echo "</td></tr>"; |
208 |
} |
209 |
|
210 |
if ($CFG_GLPI['mailing']){ |
211 |
echo "<tr class='tab_bg_1'><td>".$LANG["setup"][247].": </td>"; |
212 |
echo "<td>"; |
213 |
echo dropdownAlertInfocoms("alert",$ic->fields["alert"]); |
214 |
|
215 |
echo "</td>"; |
216 |
|
217 |
|
218 |
echo "<td> </td>"; |
219 |
echo "<td > "; |
220 |
echo "</td></tr>"; |
221 |
} |
222 |
|
223 |
// commment
|
224 |
echo "<tr class='tab_bg_1'><td valign='top'>"; |
225 |
echo $LANG["common"][25].": </td>"; |
226 |
echo "<td align='center' colspan='3'><textarea cols='80' $option rows='2' name='comments' >".$ic->fields["comments"]."</textarea>"; |
227 |
echo "</td></tr>"; |
228 |
if (haveRight("contract_infocom","w")&&$withtemplate!=2){ |
229 |
echo "<tr>"; |
230 |
|
231 |
echo "<td class='tab_bg_2' colspan='2' align='center'>"; |
232 |
echo "<input type='hidden' name='ID' value=\"".$ic->fields['ID']."\">\n"; |
233 |
echo "<input type='submit' name='update' value=\"".$LANG["buttons"][7]."\" class='submit'>"; |
234 |
echo "</td>\n\n"; |
235 |
echo "<td class='tab_bg_2' colspan='2' align='center'>\n"; |
236 |
echo "<input type='submit' name='delete' value=\"".$LANG["buttons"][6]."\" class='submit'>"; |
237 |
|
238 |
echo "</td>"; |
239 |
echo "</tr>"; |
240 |
} |
241 |
|
242 |
echo "</table></div>"; |
243 |
if ($withtemplate!=2) echo "</form>"; |
244 |
|
245 |
} |
246 |
} |
247 |
|
248 |
|
249 |
|
250 |
|
251 |
/**
|
252 |
* Calculate amortissement for an item
|
253 |
*
|
254 |
*
|
255 |
*
|
256 |
*@param $type_amort type d'amortisssment "lineaire=2" ou "degressif=1"
|
257 |
*@param $va valeur d'acquisition
|
258 |
*@param $duree duree d'amortissement
|
259 |
*@param $coef coefficient d'amortissement
|
260 |
*@param $date_achat Date d'achat
|
261 |
*@param $date_use Date d'utilisation
|
262 |
*@param $date_fiscale date du debut de l'annee fiscale
|
263 |
*@param $view "n" pour l'annee en cours ou "all" pour le tableau complet
|
264 |
*
|
265 |
*@return float or array
|
266 |
*
|
267 |
**/
|
268 |
function TableauAmort($type_amort,$va,$duree,$coef,$date_achat,$date_use,$date_fiscale,$view="n") { |
269 |
// By Jean-Mathieu Doleans qui s'est un peu pris le chou :p
|
270 |
global $CFG_GLPI; |
271 |
|
272 |
// Attention date mise en service/dateachat ->amort lineaire et $prorata en jour !!
|
273 |
// amort degressif au prorata du nombre de mois. Son point de depart est le 1er jour du mois d'acquisition et non date de mise en service
|
274 |
|
275 |
if ($type_amort=="2"){ |
276 |
if ($date_use!="0000-00-00") { |
277 |
$date_achat=$date_use; |
278 |
} |
279 |
} |
280 |
|
281 |
$prorata=0; |
282 |
$ecartfinmoiscourant=0; |
283 |
$ecartmoisexercice=0; |
284 |
|
285 |
sscanf($date_achat, "%4s-%2s-%2s %2s:%2s:%2s", |
286 |
$date_Y, $date_m, $date_d, |
287 |
$date_H, $date_i, $date_s); // un traitement sur la date mysql pour recuperer l'annee |
288 |
|
289 |
// un traitement sur la date mysql pour les infos necessaires
|
290 |
sscanf($date_fiscale, "%4s-%2s-%2s %2s:%2s:%2s", |
291 |
$date_Y2, $date_m2, $date_d2, |
292 |
$date_H2, $date_i2, $date_s2); |
293 |
$date_Y2=date("Y"); |
294 |
|
295 |
switch ($type_amort) { |
296 |
case "2" : |
297 |
########################### Calcul amortissement lineaire ###########################
|
298 |
if($va>0 &&$duree>0 &&$date_achat!="0000-00-00") { |
299 |
## calcul du prorata temporis en jour ##
|
300 |
$ecartfinmoiscourant=(30-$date_d); // calcul ecart entre jour date acquis ou mise en service et fin du mois courant |
301 |
|
302 |
// en lineaire on calcule en jour
|
303 |
if ($date_d2<30) { |
304 |
$ecartmoisexercice=(30-$date_d2); |
305 |
} |
306 |
if ($date_m>$date_m2) { |
307 |
$date_m2=$date_m2+12; |
308 |
} // si l'annee fiscale debute au dela de l'annee courante
|
309 |
$ecartmois=(($date_m2-$date_m)*30); // calcul ecart etre mois d'acquisition et debut ann� fiscale |
310 |
$prorata=$ecartfinmoiscourant+$ecartmois-$ecartmoisexercice; |
311 |
|
312 |
## calcul tableau d'amortissement ##
|
313 |
$txlineaire = (100/$duree); // calcul du taux lineaire |
314 |
$annuite = ($va*$txlineaire)/100; // calcul de l'annuitee |
315 |
$mrt=$va; // |
316 |
// si prorata temporis la derniere annnuite cours sur la duree n+1
|
317 |
if ($prorata>0){ |
318 |
$duree=$duree+1; |
319 |
} |
320 |
for($i=1;$i<=$duree;$i++) { |
321 |
$tab['annee'][$i]=$date_Y+$i-1; |
322 |
$tab['annuite'][$i]=$annuite; |
323 |
$tab['vcnetdeb'][$i]=$mrt; // Pour chaque annee on calcul la valeur comptable nette de debut d'exercice |
324 |
$tab['vcnetfin'][$i]=abs(($mrt - $annuite)); // Pour chaque annee on calcul la valeur comptable nette de fin d'exercice |
325 |
// calcul de la premiere annuite si prorata temporis
|
326 |
if ($prorata>0){ |
327 |
$tab['annuite'][1]=$annuite*($prorata/360); |
328 |
$tab['vcnetfin'][1]=abs($va - $tab['annuite'][1]); |
329 |
} |
330 |
$mrt=$tab['vcnetfin'][$i]; |
331 |
} // end for
|
332 |
// calcul de la derniere annuite si prorata temporis
|
333 |
if ($prorata>0){ |
334 |
$tab['annuite'][$duree]=$tab['vcnetdeb'][$duree]; |
335 |
$tab['vcnetfin'][$duree]=$tab['vcnetfin'][$duree-1]- $tab['annuite'][$duree]; |
336 |
} |
337 |
}else{
|
338 |
return "-"; break; |
339 |
} |
340 |
break;
|
341 |
|
342 |
case "1" : |
343 |
########################### Calcul amortissement degressif ###########################
|
344 |
|
345 |
if($va>0 &&$duree>0 &&$coef>1 &&$date_achat!="0000-00-00") { |
346 |
## calcul du prorata temporis en mois ##
|
347 |
// si l'annee fiscale debute au dela de l'annee courante
|
348 |
if ($date_m>$date_m2) { |
349 |
$date_m2=$date_m2+12; |
350 |
} |
351 |
$ecartmois=($date_m2-$date_m)+1; // calcul ecart etre mois d'acquisition et debut annee fiscale |
352 |
$prorata=$ecartfinmoiscourant+$ecartmois-$ecartmoisexercice; |
353 |
|
354 |
## calcul tableau d'amortissement ##
|
355 |
$txlineaire = (100/$duree); // calcul du taux lineaire virtuel |
356 |
$txdegressif=$txlineaire*$coef; // calcul du taux degressif |
357 |
$dureelineaire= (int) (100/$txdegressif); // calcul de la duree de l'amortissement en mode lineaire |
358 |
$dureedegressif=$duree-$dureelineaire;// calcul de la duree de l'amortissement en mode degressif |
359 |
$mrt=$va; // |
360 |
|
361 |
// amortissement degressif pour les premieres annees
|
362 |
for($i=1;$i<=$dureedegressif;$i++) { |
363 |
$tab['annee'][$i]=$date_Y+$i-1; |
364 |
$tab['vcnetdeb'][$i]=$mrt; // Pour chaque annee on calcul la valeur comptable nette de debut d'exercice |
365 |
$tab['annuite'][$i]=$tab['vcnetdeb'][$i]*$txdegressif/100; |
366 |
$tab['vcnetfin'][$i]=$mrt - $tab['annuite'][$i]; // Pour chaque annee on calcul la valeur comptable nette de fin d'exercice |
367 |
// calcul de la premiere annuite si prorata temporis
|
368 |
if ($prorata>0){ |
369 |
$tab['annuite'][1]=($va*$txdegressif/100)*($prorata/12); |
370 |
$tab['vcnetfin'][1]=$va - $tab['annuite'][1]; |
371 |
} |
372 |
$mrt=$tab['vcnetfin'][$i]; |
373 |
} // end for
|
374 |
|
375 |
// amortissement en lineaire pour les derneres annees
|
376 |
if ($dureelineaire!=0){ |
377 |
$txlineaire = (100/$dureelineaire); // calcul du taux lineaire |
378 |
} else {
|
379 |
$txlineaire = 100; |
380 |
} |
381 |
$annuite = ($tab['vcnetfin'][$dureedegressif]*$txlineaire)/100; // calcul de l'annuite |
382 |
$mrt=$tab['vcnetfin'][$dureedegressif]; |
383 |
|
384 |
for($i=$dureedegressif+1;$i<=$dureedegressif+$dureelineaire;$i++) { |
385 |
$tab['annee'][$i]=$date_Y+$i-1; |
386 |
$tab['annuite'][$i]=$annuite; |
387 |
$tab['vcnetdeb'][$i]=$mrt; // Pour chaque annee on calcul la valeur comptable nette de debut d'exercice |
388 |
$tab['vcnetfin'][$i]=abs(($mrt - $annuite)); // Pour chaque annee on calcul la valeur comptable nette de fin d'exercice |
389 |
$mrt=$tab['vcnetfin'][$i]; |
390 |
} // end for
|
391 |
// calcul de la derniere annuite si prorata temporis
|
392 |
if ($prorata>0){ |
393 |
$tab['annuite'][$duree]=$tab['vcnetdeb'][$duree]; |
394 |
if (isset($tab['vcnetfin'][$duree-1])){ |
395 |
$tab['vcnetfin'][$duree]=$tab['vcnetfin'][$duree-1]- $tab['annuite'][$duree]; |
396 |
} else {
|
397 |
$tab['vcnetfin'][$duree]=0; |
398 |
} |
399 |
} |
400 |
}else{
|
401 |
return "-"; break; |
402 |
} |
403 |
break;
|
404 |
default :
|
405 |
return "-"; break; |
406 |
} |
407 |
|
408 |
// le return
|
409 |
if ($view=="all") { |
410 |
// on retourne le tableau complet
|
411 |
return $tab; |
412 |
}else{
|
413 |
// on retourne juste la valeur residuelle
|
414 |
// si on ne trouve pas l'annee en cours dans le tableau d'amortissement dans le tableau, le materiel est amorti
|
415 |
if (!array_search(date("Y"),$tab["annee"])){ |
416 |
$vnc=0; |
417 |
}elseif (mktime(0 , 0 , 0, $date_m2, $date_d2, date("Y")) - mktime(0 , 0 , 0 , date("m") , date("d") , date("Y")) < 0 ){ |
418 |
// on a depasse la fin d'exercice de l'annee en cours
|
419 |
//on prend la valeur residuelle de l'annee en cours
|
420 |
$vnc= $tab["vcnetfin"][array_search(date("Y"),$tab["annee"])]; |
421 |
} else {
|
422 |
// on se situe avant la fin d'exercice
|
423 |
// on prend la valeur residuelle de l'annee n-1
|
424 |
$vnc=$tab["vcnetdeb"][array_search(date("Y"),$tab["annee"])]; |
425 |
} |
426 |
return $vnc; |
427 |
} |
428 |
} |
429 |
|
430 |
/**
|
431 |
* Calculate TCO and TCO by month for an item
|
432 |
*
|
433 |
*
|
434 |
*
|
435 |
*@param $ticket_tco Tco part of tickets
|
436 |
*@param $value
|
437 |
*@param $date_achat
|
438 |
*
|
439 |
*@return float
|
440 |
*
|
441 |
**/
|
442 |
function showTco($ticket_tco,$value,$date_achat=""){ |
443 |
global $CFG_GLPI; |
444 |
// Affiche le TCO ou le TCO mensuel pour un matériel
|
445 |
//
|
446 |
$totalcost=$ticket_tco; |
447 |
|
448 |
if ($date_achat){ // on veut donc le TCO mensuel |
449 |
|
450 |
sscanf($date_achat, "%4s-%2s-%2s",$date_Y, $date_m, $date_d); |
451 |
|
452 |
$timestamp2 = mktime(0,0,0, $date_m, $date_d, $date_Y); |
453 |
$timestamp = mktime(0,0,0, date("m"), date("d"), date("Y")); |
454 |
|
455 |
$diff = floor(($timestamp - $timestamp2) / (MONTH_TIMESTAMP)); // Mois d'utilisation |
456 |
|
457 |
if ($diff) |
458 |
return formatNumber((($totalcost+$value)/$diff)); // TCO mensuel |
459 |
else return ""; |
460 |
|
461 |
}else {
|
462 |
return formatNumber(($totalcost+$value)); // TCO |
463 |
} |
464 |
|
465 |
}// fin showTCO
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
/**
|
471 |
* Show infocom link to display popup
|
472 |
*
|
473 |
*@param $device_type integer: item type
|
474 |
*@param $device_id integer: item ID
|
475 |
*@param $update integer:
|
476 |
*
|
477 |
*@return float
|
478 |
**/
|
479 |
function showDisplayInfocomLink($device_type,$device_id,$update=0){ |
480 |
global $DB,$CFG_GLPI,$LANG; |
481 |
|
482 |
if (!haveRight("contract_infocom","r")) return false; |
483 |
|
484 |
$query="SELECT COUNT(*) FROM glpi_infocoms WHERE FK_device='$device_id' AND device_type='$device_type'"; |
485 |
|
486 |
$add="add"; |
487 |
$text=$LANG["buttons"][8]; |
488 |
$result=$DB->query($query); |
489 |
if ($DB->result($result,0,0)>0) { |
490 |
$add=""; |
491 |
$text=$LANG["buttons"][23]; |
492 |
} |
493 |
if (haveTypeRight($device_type,"w")){ |
494 |
echo "<span onClick=\"window.open('".$CFG_GLPI["root_doc"]."/front/infocom.show.php?device_type=$device_type&device_id=$device_id&update=$update','infocoms','location=infocoms,width=1000,height=400,scrollbars=no')\" style='cursor:pointer'><img src=\"".$CFG_GLPI["root_doc"]."/pics/dollar$add.png\" alt=\"$text\" title=\"$text\"></span>"; |
495 |
} |
496 |
} |
497 |
|
498 |
|
499 |
/**
|
500 |
* Cron action on infocom : alert on expired warranty
|
501 |
* @param $display display informations instead or log in file ?
|
502 |
* @return 0 : nothing to do 1 : done with success
|
503 |
**/
|
504 |
function cron_infocom($display=false){ |
505 |
global $DB,$CFG_GLPI,$LANG; |
506 |
|
507 |
if (!$CFG_GLPI["mailing"]){ |
508 |
return false; |
509 |
} |
510 |
|
511 |
loadLanguage($CFG_GLPI["default_language"]); |
512 |
|
513 |
$message=array(); |
514 |
$items=array(); |
515 |
|
516 |
// Check notice
|
517 |
$query="SELECT glpi_infocoms.* |
518 |
FROM glpi_infocoms
|
519 |
LEFT JOIN glpi_alerts ON (glpi_infocoms.ID = glpi_alerts.FK_device
|
520 |
AND glpi_alerts.device_type='".INFOCOM_TYPE."' |
521 |
AND glpi_alerts.type='".ALERT_END."') |
522 |
WHERE (glpi_infocoms.alert & ".pow(2,ALERT_END).") >0 |
523 |
AND glpi_infocoms.warranty_duration>0
|
524 |
AND glpi_infocoms.buy_date<>'0000-00-00'
|
525 |
AND DATEDIFF( ADDDATE(glpi_infocoms.buy_date, INTERVAL (glpi_infocoms.warranty_duration) MONTH),CURDATE() )<0
|
526 |
AND glpi_alerts.date IS NULL;";
|
527 |
|
528 |
$result=$DB->query($query); |
529 |
if ($DB->numrows($result)>0){ |
530 |
|
531 |
$ci=new CommonItem(); |
532 |
$needed=array("computer","device","printer","networking","peripheral","monitor","software","infocom","phone","state","tracking","enterprise"); |
533 |
foreach ($needed as $item){ |
534 |
if (file_exists(GLPI_ROOT . "/inc/$item.class.php")) |
535 |
include_once (GLPI_ROOT . "/inc/$item.class.php"); |
536 |
if (file_exists(GLPI_ROOT . "/inc/$item.function.php")) |
537 |
include_once (GLPI_ROOT . "/inc/$item.function.php"); |
538 |
} |
539 |
|
540 |
while ($data=$DB->fetch_array($result)){ |
541 |
if ($ci->getFromDB($data["device_type"],$data["FK_device"])){ |
542 |
$entity=$ci->getField('FK_entities'); |
543 |
if (!isset($message[$entity])){ |
544 |
$message[$entity]=""; |
545 |
} |
546 |
if (!isset($items[$entity])){ |
547 |
$items[$entity]=array(); |
548 |
} |
549 |
|
550 |
// define message alert / Not for template items
|
551 |
if (!$ci->getField('is_template')){ |
552 |
$message[$entity].=$LANG["mailing"][40]." ".$ci->getType()." - ".$ci->getName().": ".getWarrantyExpir($data["buy_date"],$data["warranty_duration"])."<br>\n"; |
553 |
$items[$entity][]=$data["ID"]; |
554 |
} |
555 |
} |
556 |
|
557 |
} |
558 |
if (count($message)>0){ |
559 |
// Mark alert as done
|
560 |
$alert=new Alert(); |
561 |
|
562 |
foreach ($message as $entity => $msg){ |
563 |
$mail=new MailingAlert("alertinfocom",$msg,$entity); |
564 |
if ($mail->send()){ |
565 |
if ($display){ |
566 |
addMessageAfterRedirect(getDropdownName("glpi_entities",$entity).": $msg"); |
567 |
} |
568 |
logInFile("cron",getDropdownName("glpi_entities",$entity).": $msg\n"); |
569 |
|
570 |
|
571 |
$input["type"]=ALERT_END; |
572 |
$input["device_type"]=INFOCOM_TYPE; |
573 |
|
574 |
//// add alerts
|
575 |
foreach ($items[$entity] as $ID){ |
576 |
$input["FK_device"]=$ID; |
577 |
$alert->add($input); |
578 |
unset($alert->fields['ID']); |
579 |
} |
580 |
|
581 |
} else {
|
582 |
if ($display){ |
583 |
addMessageAfterRedirect(getDropdownName("glpi_entities",$entity).": Send infocom alert failed"); |
584 |
} |
585 |
logInFile("cron",getDropdownName("glpi_entities",$entity).": Send infocom alert failed\n"); |
586 |
} |
587 |
} |
588 |
return 1; |
589 |
} |
590 |
|
591 |
} |
592 |
|
593 |
|
594 |
|
595 |
return 0; |
596 |
|
597 |
|
598 |
} |
599 |
|
600 |
|
601 |
?>
|