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 2010-09-28 22:31:25

GuruNot
Member
Registered: 2010-09-28
Posts: 20

HP Warranty Renewals - Supplier Import

Firstly a thank you, to the contributors and developers of GLPI for a stirling product. I have only just recently discovered the combination of GLPI/OCSNG and I am finding it to be a very competent solution.

I have recently been looking in to the Warranty side of things and in particular and have discovered a couple of issues and wondered if anyone has a better solution than me.

The Supplier Import plugin by default does not seem to handle Carepaq renewals at all, the plugin seems to just use the first instance of "Start Date" and "End Date" to calculate the Warranty details.

We have a number of servers over 3 years old and that first entry is expired. We have another entry on the HP Warranty Webpage which is "Active" and is the current carepaq. For some which we have just renewed and the current warranty is not expired we even have a section called future (ie warranty covers 15th October 2010 to 15th October 2011).

As the first instance of Start Date is used to populate "Date of purchase" that has to be discovered, but I needed the end date in future section to be the warranty end date (if it exists) failing that the end date of the Active section, failing that just the first end date.

To that end I modified the HP Section of the function "plugin_suppliertag_supplierImportWarranty"  in plugin_suppliertag.import.function.php to be as follows:

}elseif($suppliername=="HP" && $warranty == 0){//hp

                if (strpos($contents, "Future") !==false) {
                  $field_fin = "Future";
                  $field_fin_pos = 702;

                }elseif (strpos($contents, "Active") !==false) {
                $field_fin = "Active";
                $field_fin_pos = 702;

                }else {

                $field_fin = "End Date";
                $field_fin_pos = 142;}

                $searchfin = stristr($contents, $field_fin);
                $maDateFin = substr($searchfin,$field_fin_pos,20);

                $maDateFin =trim($maDateFin);
                $maDateFin = str_replace(' ','-',$maDateFin);
                $maDateFin = str_replace('Jan','01',$maDateFin);
                $maDateFin = str_replace('Feb','02',$maDateFin);
                $maDateFin = str_replace('Mar','03',$maDateFin);
                $maDateFin = str_replace('Apr','04',$maDateFin);
                $maDateFin = str_replace('May','05',$maDateFin);
                $maDateFin = str_replace('Jun','06',$maDateFin);
                $maDateFin = str_replace('Jul','07',$maDateFin);
                $maDateFin = str_replace('Aug','08',$maDateFin);
                $maDateFin = str_replace('Sep','09',$maDateFin);
                $maDateFin = str_replace('Oct','10',$maDateFin);
                $maDateFin = str_replace('Nov','11',$maDateFin);
                $maDateFin = str_replace('Dec','12',$maDateFin);

                list($jour,$mois,$annee) = explode('-',$maDateFin);
                $maDateFin = $annee."-".$mois."-".$jour;

                $maDateFin = date ("Y-m-d", strtotime ($maDateFin) + 86400);

                list ($adebut, $mdebut, $jdebut) = explode ('-', $maDate);
                list ($afin, $mfin, $jfin) = explode ('-', $maDateFin);

                $maGarantie = ($afin * 12 + $mfin) - ($adebut * 12 + $mdebut);

                $warranty = ($maGarantie - 1);
        }

Due to the way the warranty end date is calculated ie whole months I often found that the displayed warranty end date was later than the actual end date(mainly for servers where we did not renew straight away).

As I would prefer to think a warranty expires before it does (rather than think a box is under warranty and it is not), i subtracted 1 month in the last line.

It seems to work for me, does any see any holes, I am a php newbie and would not all be surprised if there are some?

I know this will not return accurate info for a server which has had multiple carepaq's but have all expired. I may work on that later.

Offline

#2 2010-09-28 23:37:13

wakesk8
Member
Registered: 2010-03-07
Posts: 47

Re: HP Warranty Renewals - Supplier Import

I've run into the same issues with multiple Carepaq's listed for a specific device.  It seems like we need a Warranty End Date field in the Financial Section where the End Date from Supplier Import can be read/entered instead of using the months calculation.  We have different durations of HP Service levels for equipment from 1 Year renewels to 3 year standard and can't rely on the end date being calculated in GLPI.  Have you looked at leveraging the Custom_Fields plugin with your Supplier_Import updates t populate a Warranty End Date?

Offline

#3 2010-09-29 08:01:41

GuruNot
Member
Registered: 2010-09-28
Posts: 20

Re: HP Warranty Renewals - Supplier Import

I will look in to the Custom_Fields plugin and see what can be done. The warranty does need to be separate to the Purchase Date as further down the line the two are not really linked.

Offline

#4 2010-09-29 17:25:32

GuruNot
Member
Registered: 2010-09-28
Posts: 20

Re: HP Warranty Renewals - Supplier Import

Ok, I have two new functions for HP only, one to obtain the warranty start date, the other to obtain the end date:

function plugin_suppliertag_warrantyStartDate($suppliername,$finduhtml,$contents,$warranty){

        if ($suppliername=="Dell"){//dell

        }elseif($suppliername=="HP"){//hp

                $searchst = stristr($contents, "Active");
                $warstartDate = substr($searchst,352,20);
                $warstartDate =trim($warstartDate);
                $warstartDate = str_replace(' ','-',$warstartDate);
                $warstartDate = str_replace('Jan','01',$warstartDate);
                $warstartDate = str_replace('Feb','02',$warstartDate);
                $warstartDate = str_replace('Mar','03',$warstartDate);
                $warstartDate = str_replace('Apr','04',$warstartDate);
                $warstartDate = str_replace('May','05',$warstartDate);
                $warstartDate = str_replace('Jun','06',$warstartDate);
                $warstartDate = str_replace('Jul','07',$warstartDate);
                $warstartDate = str_replace('Aug','08',$warstartDate);
                $warstartDate = str_replace('Sep','09',$warstartDate);
                $warstartDate = str_replace('Oct','10',$warstartDate);
                $warstartDate = str_replace('Nov','11',$warstartDate);
                $warstartDate = str_replace('Dec','12',$warstartDate);
                list($jour,$mois,$annee) = explode('-',$warstartDate);
                $warstartDate = date("Y-m-d",mktime(0,0,0,$mois,$jour,$annee));

        }elseif($suppliername=="Fujitsu-Siemens"){//Fujitsu : 08/09/2001


        }elseif($suppliername=="IBM"){//IBM : 2008-09-03


        }elseif($suppliername=="Toshiba"){//toshiba : 6/29/04


        }

        return $warstartDate;

}



-----------------------------------------------------------------------------------------------------------------------


function plugin_suppliertag_warrantyendDate($suppliername,$maDate,$contents,$warranty){

        if ($suppliername=="Dell" && $warranty == 0){//dell


        }elseif($suppliername=="HP" && $warranty == 0){//hp

                if (strpos($contents, "Future") !==false) {
                  $field_wend = "Future";
                  $field_wend_pos = 702;

                }elseif (strpos($contents, "Active") !==false) {
                $field_wend = "Active";
                $field_wend_pos = 702;

                }else {

                $field_wend = "End Date";
                $field_wend_pos = 142;}

                $searchfin = stristr($contents, $field_wend);
                $warendDate = substr($searchfin,$field_wend_pos,20);

                $warendDate =trim($warendDate);
                $warendDate = str_replace(' ','-',$warendDate);
                $warendDate = str_replace('Jan','01',$warendDate);
                $warendDate = str_replace('Feb','02',$warendDate);
                $warendDate = str_replace('Mar','03',$warendDate);
                $warendDate = str_replace('Apr','04',$warendDate);
                $warendDate = str_replace('May','05',$warendDate);
                $warendDate = str_replace('Jun','06',$warendDate);
                $warendDate = str_replace('Jul','07',$warendDate);
                $warendDate = str_replace('Aug','08',$warendDate);
                $warendDate = str_replace('Sep','09',$warendDate);
                $warendDate = str_replace('Oct','10',$warendDate);
                $warendDate = str_replace('Nov','11',$warendDate);
                $warendDate = str_replace('Dec','12',$warendDate);

                list($jour,$mois,$annee) = explode('-',$warendDate);
                $warendDate = date("Y-m-d",mktime(0,0,0,$mois,$jour,$annee));

                }

        return $warendDate;

}

These return $warstartdate and $warenddate respectively. I have added the customs field plugin, applied the financial patch. Created and enabled two custom field in financial information:

Label                   Warranty Start Date   
System Name      warrantystartdate   
Type                       Date

Label                   Warranty End Date   
System Name      warrantyenddate   
Type                       Date


Now my lack of php shows as I do not know how to write the variables into the appropriate field in the database table.

Can anyone help?

Last edited by GuruNot (2010-09-29 17:42:10)

Offline

#5 2010-09-29 23:19:45

GuruNot
Member
Registered: 2010-09-28
Posts: 20

Re: HP Warranty Renewals - Supplier Import

I reckon the write to sql is around here :

    //valeurs d'origine
                                $buy_date="";
                                $warranty_duration="";
                                $FK_enterprise="";
                                $ic_comments="";
                                //nouvelles valeurs
                                $date=date("Y-m-d");
                                $input_infocom=array();
                                if ($supplierId!=0)
                                        $input_infocom["FK_enterprise"]=$supplierId;
                                $input_infocom["FK_device"]=$compId;
                                $input_infocom["device_type"]=$type;
                                $input_infocom["buy_date"]=$maDate;
                                $input_infocom["warranty_duration"]=$warranty;
                                if ($addcomments)
                                        $input_infocom["comments"]=$LANG['plugin_suppliertag']['import'][28]." ".$suppliername." ".$LANG['plugin_suppliertag']['import'][29]." (".convdate($date).")";

                                $infocom = new infocom;
                                $infocom->add($input_infocom);


Can anyone enlighten me as to how this works? and how to reference another field in another table?

Last edited by GuruNot (2010-09-29 23:20:39)

Offline

#6 2010-10-04 15:30:54

GuruNot
Member
Registered: 2010-09-28
Posts: 20

Re: HP Warranty Renewals - Supplier Import

Can anyone help me with this ? I need to write a value obtained from the suppliertag plugin to a table created by the Custom Fields Plugin and I have little or no php skills.

I have done some digging and even have tried creating my own class/function but I do not seem to have done this in the right place.

Offline

#7 2010-10-05 20:57:19

GuruNot
Member
Registered: 2010-09-28
Posts: 20

Re: HP Warranty Renewals - Supplier Import

Ok, I am almost there.

I resorted to basic sql and have added the following after the section above:

Global $DB;
$RealID = "SELECT `glpi_infocoms`.`ID` FROM glpi_infocoms WHERE `glpi_infocoms`.`FK_device` = '$ID' AND `glpi_infocoms`.`device_type` = '$type";
$Idnum = $DB->query($RealID);
mysql_query("UPDATE glpi_plugin_customfields_infocoms SET warrantyenddate = '$warendDate' WHERE ID = '$Idnum'");

$f = fopen("/tmp/sql.txt", "w+");
fwrite($f, $ID."\t");
fwrite($f, $Idnum."\t");
fwrite($f, $warstartDate."\t");
fwrite($f, $warendDate."\t");
fwrite($f, $type);
fclose($f);

The purpose is to get the correct value of ID for the object (using FK_device and device_type) and the amend the corresponding field in the customfields_infocoms table.

But it does not work! What am I missing ? I put in the fwrites at the end to help troubleshoot and display the outputs of variables and got the following:

1       Resource id #314        2010-09-30      2011-09-29      1

Where did "Resource id # 314" come from ? This is the value returned for Idnum and should be an integer ie 5 (for the machine i was testing the import with).

The others are all as expected.

Offline

#8 2010-10-08 14:01:21

GuruNot
Member
Registered: 2010-09-28
Posts: 20

Re: HP Warranty Renewals - Supplier Import

Well I finally got there and resolved the issue myself. It would seem that when you use PHP to do the query there are some other commands you need to run to get the end result. The MySQL tools would seem to do this for you automatically.

Consequently my revised code is:

$RealID = "SELECT `glpi_infocoms`.`ID` FROM glpi.glpi_infocoms WHERE `glpi_infocoms`.`FK_device` = '$ID' AND `glpi_infocoms`.`device_type` = '$type'";

// Perform Query
$Idresult = mysql_query($RealID);
$Idnum = mysql_fetch_row($Idresult);
$Idnum = $Idnum[0];

mysql_query("UPDATE glpi_plugin_customfields_infocoms SET warrantyenddate = '$warendDate' WHERE ID = '$Idnum'");
mysql_query("UPDATE glpi_plugin_customfields_infocoms SET warrantystartdate = '$warstartDate' WHERE ID = '$Idnum'");

Not the neatest solution but it does what I need.

Offline

#9 2010-10-13 10:06:31

GuruNot
Member
Registered: 2010-09-28
Posts: 20

Re: HP Warranty Renewals - Supplier Import

would anyone fine it useful if I summarised what I had to do? All the above may seem a bit disjointed.

Offline

#10 2010-10-13 20:33:03

wakesk8
Member
Registered: 2010-03-07
Posts: 47

Re: HP Warranty Renewals - Supplier Import

I would, I've been looking for a similar solution to get the info as well.

Thanks

Offline

Board footer

Powered by FluxBB