|
|
|
@ -89,16 +89,28 @@ class Tracking_USPS {
|
|
|
|
|
|
|
|
|
|
$info->setTo($to);
|
|
|
|
|
|
|
|
|
|
foreach ($trackinfo->TrackDetail as $history) {
|
|
|
|
|
|
|
|
|
|
for ($i = 0; $i < count($trackinfo->TrackDetail); $i++) {
|
|
|
|
|
$history = $trackinfo->TrackDetail[$i];
|
|
|
|
|
$location = new Location();
|
|
|
|
|
$location->city = (string) $history->EventCity ?? "";
|
|
|
|
|
$location->state = (string) $history->EventState ?? "";
|
|
|
|
|
$location->zip = (string) $history->EventZIPCode ?? "";
|
|
|
|
|
$location->country = (string) $history->EventCountry ?? "";
|
|
|
|
|
if ((empty($history->EventDate) || empty($history->EventTime)) && $i < count($trackinfo->TrackDetail) - 1) {
|
|
|
|
|
// If there's no date/time for some reason (yes this happens sometimes apparently),
|
|
|
|
|
// just make it 60 seconds after the previous event.
|
|
|
|
|
// This way it'll be in the correct order if the events are displayed
|
|
|
|
|
// after being sorted by date/time.
|
|
|
|
|
// Because events are ordered latest first, we get $i+1 to get the previous event.
|
|
|
|
|
$datetime = date("Y-m-d H:i:s", strtotime($trackinfo->TrackDetail[$i + 1]->EventDate . " " . $trackinfo->TrackDetail[$i + 1]->EventTime) + 60);
|
|
|
|
|
} else {
|
|
|
|
|
$datetime = $history->EventDate . " " . $history->EventTime;
|
|
|
|
|
}
|
|
|
|
|
$info->appendHistoryEntry(new TrackingEntry(
|
|
|
|
|
TrackingStatus::USPSEventCodeToStatus((string) $history->EventCode),
|
|
|
|
|
((string) $history->Event),
|
|
|
|
|
$history->EventDate . " " . $history->EventTime,
|
|
|
|
|
$datetime,
|
|
|
|
|
$location,
|
|
|
|
|
TrackingStatus::isUSPSEventCodeContainerScan((string) $history->EventCode)));
|
|
|
|
|
}
|
|
|
|
|