Skip to content

Commit

Permalink
Fix Lenono see #125
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmr committed Apr 11, 2024
1 parent e887bd8 commit 3ba80b6
Showing 1 changed file with 125 additions and 132 deletions.
257 changes: 125 additions & 132 deletions inc/lenovo.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,158 +91,151 @@ function getSupplierInfo($compSerial = null, $otherSerial = null, $key = null, $
*/
function getBuyDate($contents) {

// $contents = json_decode($contents, true);


$field = "BaseWarranties";
$search = stristr($contents, $field);

$myDate = substr($search, 27, 10);

$myDate = trim($myDate);
$json=stristr($contents,'window.ds_warranties');
$json = substr($json,strlen('window.ds_warranties || '));
$json = strtok($json, ";");
$data = json_decode($json,true);
$myDate = '';
if (isset($data['BaseWarranties']) && !empty($data['BaseWarranties'])) {
foreach ($data['BaseWarranties'] as $warranty) {
if (!empty($warranty['Category']) && $warranty['Category'] == 'MACHINE') {
$myDate = $warranty["Start"];
}
}
}
if (empty($myDate) && !empty($data['Shiped'])) {
$myDate = $data['Shiped'];
}
$myDate = PluginManufacturersimportsPostImport::checkDate($myDate);

return $myDate;

// if (isset($contents['POPDate'])) {
//
// Toolbox::loginfo($contents['POPDate']);
//
// if (strpos($contents['POPDate'], '0001-01-01') !== false) {
// if (strpos($contents['Shipped'], '0001-01-01') !== false) {
// if (isset($contents['Warranty']) && !empty($contents['Warranty'])) {
// $minStart = 0;
// $start = 0;
// $n = 0;
// foreach ($contents['Warranty'] as $id => $warranty) {
// $myDate = trim($warranty['start']);
// $dateStart = strtotime($myDate);
// if ($n === 0) {
// $minStart = $dateStart;
// $myDate = strtotime(trim($warranty['Start']));
// }
// if ($dateStart > $minStart) {
// $minStart = $dateStart;
// $myDate = strtotime(trim($warranty['Start']));
// }
// $n++;
// }
// }
// } else {
// $myDate = trim($contents['POPDate']);
// }
// } else {
// $myDate = trim($contents['POPDate']);
// }
// Toolbox::loginfo($myDate);
// // $myDate = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year));
// $myDate = date("Y-m-d", strtotime($myDate));
//
//
// return PluginManufacturersimportsPostImport::checkDate($myDate);
// }
}

/**
* @see PluginManufacturersimportsManufacturer::getStartDate()
*/
function getStartDate($contents) {

$field = "BaseWarranties";
$search = stristr($contents, $field);
$myDate = substr($search, 27, 10);
$myDate = trim($myDate);
$myDate = PluginManufacturersimportsPostImport::checkDate($myDate);

return $myDate;

// //TODO change to have good start date with new json
// $contents = json_decode($contents, true);
// if (isset($contents['Warranty']) && !empty($contents['Warranty'])) {
// $maxEnd = 0;
// $start = 0;
// foreach ($contents['Warranty'] as $id => $warranty) {
// $myDate = trim($warranty['End']);
// $dateEnd = strtotime($myDate);
// if ($dateEnd > $maxEnd) {
// $maxEnd = $dateEnd;
// $start = strtotime(trim($warranty['Start']));
// }
// }
//
// }
//
// if (isset($start)) {
// $myDate = date("Y-m-d", $start);
//
// return PluginManufacturersimportsPostImport::checkDate($myDate);
// }

$json=stristr($contents,'window.ds_warranties');
$json = substr($json,strlen('window.ds_warranties || '));
$json = strtok($json, ";");
$data = json_decode($json,true);
$myDate = "";
$maxEnd = 0;
$start = '';
if (isset($data['BaseWarranties']) && !empty($data['BaseWarranties'])) {
foreach ($data['BaseWarranties'] as $warranty) {
if (!empty($warranty['Category']) && $warranty['Category'] == 'MACHINE') {
$myDate = trim($warranty['End']);
$dateEnd = strtotime($myDate);
if ($dateEnd > $maxEnd) {
$maxEnd = $dateEnd;
$start = strtotime(trim($warranty['Start']));
}
}
}

}
if (isset($data['UpmaWarranties']) && !empty($data['UpmaWarranties'])) {
foreach ($data['UpmaWarranties'] as $warranty) {
if (!empty($warranty['Category']) && $warranty['Category'] == 'MACHINE') {
$myDate = trim($warranty['End']);
$dateEnd = strtotime($myDate);
if ($dateEnd > $maxEnd) {
$maxEnd = $dateEnd;
$start = strtotime(trim($warranty['Start']));
}
}
}
}

if (!empty($start)) {
$myDate = date("Y-m-d", $start);
}
return PluginManufacturersimportsPostImport::checkDate($myDate);
}

/**
* @see PluginManufacturersimportsManufacturer::getExpirationDate()
*/
function getExpirationDate($contents) {
// $contents = json_decode($contents, true);
// //TODO change to have good expiration date with new json
// if (isset($contents['Warranty']) && !empty($contents['Warranty'])) {
// $maxEnd = 0;
//
// foreach ($contents['Warranty'] as $id => $warranty) {
// $myDate = trim($warranty['End']);
// $dateEnd = strtotime($myDate);
// if ($dateEnd > $maxEnd) {
// $maxEnd = $dateEnd;
// }
// }
//
// }
//
// if (isset($maxEnd)) {
// $myDate = date("Y-m-d", $maxEnd);
//
// return PluginManufacturersimportsPostImport::checkDate($myDate);
// }

$field = "BaseWarranties";
$search = stristr($contents, $field);

$myEndDate = substr($search, 46, 10);

$myEndDate = trim($myEndDate);
$myEndDate = PluginManufacturersimportsPostImport::checkDate($myEndDate);
return $myEndDate;

$json=stristr($contents,'window.ds_warranties');
$json = substr($json,strlen('window.ds_warranties || '));
$json = strtok($json, ";");
$data = json_decode($json,true);
$myDate = "";
$maxEnd = 0;
$start = '';
if (isset($data['BaseWarranties']) && !empty($data['BaseWarranties'])) {
foreach ($data['BaseWarranties'] as $warranty) {
if (!empty($warranty['Category']) && $warranty['Category'] == 'MACHINE') {
$myDate = trim($warranty['End']);
$dateEnd = strtotime($myDate);
if ($dateEnd > $maxEnd) {
$maxEnd = $dateEnd;
$start = strtotime(trim($warranty['Start']));
}
}
}

}
if (isset($data['UpmaWarranties']) && !empty($data['UpmaWarranties'])) {
foreach ($data['UpmaWarranties'] as $warranty) {
if (!empty($warranty['Category']) && $warranty['Category'] == 'MACHINE') {
$myDate = trim($warranty['End']);
$dateEnd = strtotime($myDate);
if ($dateEnd > $maxEnd) {
$maxEnd = $dateEnd;
$start = strtotime(trim($warranty['Start']));
}
}
}

}
if (!empty($maxEnd)) {
$myDate = date("Y-m-d", $maxEnd);
}
return PluginManufacturersimportsPostImport::checkDate($myDate);
}

/**
* @see PluginManufacturersimportsManufacturer::getWarrantyInfo()
*/
function getWarrantyInfo($contents) {
// $contents = json_decode($contents, true);
//
// //TODO change to have good information with new json
// $warranty_info = false;
// if (isset($contents['Warranty']) && !empty($contents['Warranty'])) {
// $maxEnd = 0;
//
// foreach ($contents['Warranty'] as $id => $warranty) {
// $myDate = trim($warranty['End']);
// $dateEnd = strtotime($myDate);
// if ($dateEnd > $maxEnd) {
// $maxEnd = $dateEnd;
// if (isset($warranty["Description"])) {
// $warranty_info = $warranty["Description"];
// } else {
// $warranty_info = $warranty["Type"] . " - " . $warranty["Name"];
// }
// }
// }
//
// }
// if (strlen($warranty_info) > 255) {
// $warranty_info = substr($warranty_info, 0, 254);
// }
// return $warranty_info;

$json=stristr($contents,'window.ds_warranties');
$json = substr($json,strlen('window.ds_warranties || '));
$json = strtok($json, ";");
$data = json_decode($json,true);
$myDate = "";
$warranty_desc = "";
if (isset($data['BaseWarranties']) && !empty($data['BaseWarranties'])) {
foreach ($data['BaseWarranties'] as $warranty) {
if (!empty($warranty['Category']) && $warranty['Category'] == 'MACHINE') {
#if (!empty($warranty['Description'])) {
# $warranty_desc = $warranty['Description'];
#} else {
$warranty_desc = $warranty["Type"] . " - " . $warranty["Name"];
#}
}
}

}
if (isset($data['UpmaWarranties']) && !empty($data['UpmaWarranties'])) {
foreach ($data['UpmaWarranties'] as $warranty) {
if (!empty($warranty['Category']) && $warranty['Category'] == 'MACHINE') {
#if (!empty($warranty['Description'])) {
# $warranty_desc = $warranty['Description'];
#} else {
$warranty_desc = $warranty["Type"] . " - " . $warranty["Name"];
#}
}
}

}
if (strlen($warranty_desc) > 255) {
$warranty_desc = substr($warranty_desc, 0, 254);
}
return $warranty_desc;
}
}

0 comments on commit 3ba80b6

Please sign in to comment.