mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-11-14 20:17:14 +01:00
Merge e3488040ec
into 390a2054ec
This commit is contained in:
commit
0745cc19c2
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022 Andreas Palm
|
* SPDX-FileCopyrightText: 2022-2024 Andreas Palm
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
@ -14,6 +14,7 @@ use Xentral\Carrier\SendCloud\Data\ParcelCreation;
|
|||||||
use Xentral\Carrier\SendCloud\Data\ParcelResponse;
|
use Xentral\Carrier\SendCloud\Data\ParcelResponse;
|
||||||
use Xentral\Carrier\SendCloud\Data\SenderAddress;
|
use Xentral\Carrier\SendCloud\Data\SenderAddress;
|
||||||
use Xentral\Carrier\SendCloud\Data\ShippingProduct;
|
use Xentral\Carrier\SendCloud\Data\ShippingProduct;
|
||||||
|
use Xentral\Modules\ShippingMethod\Model\ShipmentStatus;
|
||||||
|
|
||||||
class SendCloudApi
|
class SendCloudApi
|
||||||
{
|
{
|
||||||
@ -118,6 +119,31 @@ class SendCloudApi
|
|||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws SendcloudApiException
|
||||||
|
*/
|
||||||
|
public function GetTrackingStatus(string $trackingNumber): ShipmentStatus|null
|
||||||
|
{
|
||||||
|
$uri = self::PROD_BASE_URI . '/tracking/' . $trackingNumber;
|
||||||
|
$response = $this->sendRequest($uri);
|
||||||
|
$highest = null;
|
||||||
|
foreach ($response['body']->statuses as $status) {
|
||||||
|
switch ($status->parent_status) {
|
||||||
|
case 'announcing':
|
||||||
|
case 'ready-to-send':
|
||||||
|
if ($highest === null) $highest = ShipmentStatus::Announced;
|
||||||
|
break;
|
||||||
|
case 'to-sorting':
|
||||||
|
case 'at-sorting-centre':
|
||||||
|
case 'shipment-on-route':
|
||||||
|
case 'driver-on-route':
|
||||||
|
$highest = ShipmentStatus::EnRoute;
|
||||||
|
case 'delivered': return ShipmentStatus::Delivered;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $highest;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws SendcloudApiException
|
* @throws SendcloudApiException
|
||||||
*/
|
*/
|
||||||
|
14
classes/Modules/ShippingMethod/Model/ShipmentStatus.php
Normal file
14
classes/Modules/ShippingMethod/Model/ShipmentStatus.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// SPDX-FileCopyrightText: 2024 Andreas Palm
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
namespace Xentral\Modules\ShippingMethod\Model;
|
||||||
|
|
||||||
|
enum ShipmentStatus
|
||||||
|
{
|
||||||
|
case Announced;
|
||||||
|
case EnRoute;
|
||||||
|
case Delivered;
|
||||||
|
}
|
43
cronjobs/shipment_tracking.php
Normal file
43
cronjobs/shipment_tracking.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// SPDX-FileCopyrightText: 2024 Andreas Palm
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: LicenseRef-EGPL-3.1
|
||||||
|
|
||||||
|
use Xentral\Components\Database\Database;
|
||||||
|
use Xentral\Modules\ShippingMethod\Model\ShipmentStatus;
|
||||||
|
|
||||||
|
error_reporting(E_ERROR);
|
||||||
|
|
||||||
|
include_once dirname(__DIR__) . '/xentral_autoloader.php';
|
||||||
|
|
||||||
|
if(empty($app) || !($app instanceof ApplicationCore)){
|
||||||
|
$app = new ApplicationCore();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** @var Database $db */
|
||||||
|
$db = $app->Container->get('Database');
|
||||||
|
|
||||||
|
$shipments_sql = "SELECT CONCAT(va.id, ';', va.modul) module, vp.id, vp.tracking, vp.status
|
||||||
|
FROM versandpakete vp
|
||||||
|
JOIN versandarten va ON vp.versandart = va.type
|
||||||
|
WHERE status IN ('neu', 'versendet')";
|
||||||
|
$shipments = $db->fetchGroup($shipments_sql);
|
||||||
|
|
||||||
|
foreach ($shipments as $module => $vps) {
|
||||||
|
list($moduleId, $moduleName) = explode(';', $module,2);
|
||||||
|
$module = $app->erp->LoadVersandModul($moduleName, $moduleName);
|
||||||
|
|
||||||
|
foreach ($vps as $vp) {
|
||||||
|
$status = match ($module->GetShipmentStatus($vp['tracking'])) {
|
||||||
|
ShipmentStatus::Announced => 'neu',
|
||||||
|
ShipmentStatus::EnRoute => 'versendet',
|
||||||
|
ShipmentStatus::Delivered => 'abgeschlossen',
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
if ($status === null || $status === $vp['status']) continue;
|
||||||
|
$db->perform('UPDATE versandpakete SET status = :status WHERE id = :id',
|
||||||
|
[':status' => $status, ':id' => $vp['id']]);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022 Andreas Palm
|
* SPDX-FileCopyrightText: 2022-2024 Andreas Palm
|
||||||
* SPDX-FileCopyrightText: 2019 Xentral (c) Xentral ERP Software GmbH, Fuggerstrasse 11, D-86150 Augsburg, Germany
|
* SPDX-FileCopyrightText: 2019 Xentral (c) Xentral ERP Software GmbH, Fuggerstrasse 11, D-86150 Augsburg, Germany
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: LicenseRef-EGPL-3.1
|
* SPDX-License-Identifier: LicenseRef-EGPL-3.1
|
||||||
@ -9,6 +9,7 @@
|
|||||||
use Xentral\Modules\ShippingMethod\Model\CreateShipmentResult;
|
use Xentral\Modules\ShippingMethod\Model\CreateShipmentResult;
|
||||||
use Xentral\Modules\ShippingMethod\Model\CustomsInfo;
|
use Xentral\Modules\ShippingMethod\Model\CustomsInfo;
|
||||||
use Xentral\Modules\ShippingMethod\Model\Product;
|
use Xentral\Modules\ShippingMethod\Model\Product;
|
||||||
|
use Xentral\Modules\ShippingMethod\Model\ShipmentStatus;
|
||||||
|
|
||||||
abstract class Versanddienstleister
|
abstract class Versanddienstleister
|
||||||
{
|
{
|
||||||
@ -504,4 +505,6 @@ abstract class Versanddienstleister
|
|||||||
* @return Product[]
|
* @return Product[]
|
||||||
*/
|
*/
|
||||||
public abstract function GetShippingProducts(): array;
|
public abstract function GetShippingProducts(): array;
|
||||||
|
|
||||||
|
public abstract function GetShipmentStatus(string $tracking): ShipmentStatus|null;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022 Andreas Palm
|
* SPDX-FileCopyrightText: 2022-2024 Andreas Palm
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: LicenseRef-EGPL-3.1
|
* SPDX-License-Identifier: LicenseRef-EGPL-3.1
|
||||||
*/
|
*/
|
||||||
@ -17,6 +17,7 @@ use Xentral\Carrier\Dhl\Data\ShipmentItem;
|
|||||||
use Xentral\Carrier\Dhl\DhlApi;
|
use Xentral\Carrier\Dhl\DhlApi;
|
||||||
use Xentral\Modules\ShippingMethod\Model\CreateShipmentResult;
|
use Xentral\Modules\ShippingMethod\Model\CreateShipmentResult;
|
||||||
use Xentral\Modules\ShippingMethod\Model\Product;
|
use Xentral\Modules\ShippingMethod\Model\Product;
|
||||||
|
use Xentral\Modules\ShippingMethod\Model\ShipmentStatus;
|
||||||
|
|
||||||
require_once(dirname(__DIR__).'/class.versanddienstleister.php');
|
require_once(dirname(__DIR__).'/class.versanddienstleister.php');
|
||||||
class Versandart_dhl extends Versanddienstleister{
|
class Versandart_dhl extends Versanddienstleister{
|
||||||
@ -245,4 +246,11 @@ class Versandart_dhl extends Versanddienstleister{
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function GetShipmentStatus(string $tracking): ShipmentStatus|null
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022 Andreas Palm
|
* SPDX-FileCopyrightText: 2022-2024 Andreas Palm
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: LicenseRef-EGPL-3.1
|
* SPDX-License-Identifier: LicenseRef-EGPL-3.1
|
||||||
*/
|
*/
|
||||||
@ -17,6 +17,7 @@ use Xentral\Carrier\SendCloud\Data\ShippingMethod;
|
|||||||
use Xentral\Carrier\SendCloud\SendcloudApiException;
|
use Xentral\Carrier\SendCloud\SendcloudApiException;
|
||||||
use Xentral\Modules\ShippingMethod\Model\CreateShipmentResult;
|
use Xentral\Modules\ShippingMethod\Model\CreateShipmentResult;
|
||||||
use Xentral\Modules\ShippingMethod\Model\Product;
|
use Xentral\Modules\ShippingMethod\Model\Product;
|
||||||
|
use Xentral\Modules\ShippingMethod\Model\ShipmentStatus;
|
||||||
|
|
||||||
require_once dirname(__DIR__) . '/class.versanddienstleister.php';
|
require_once dirname(__DIR__) . '/class.versanddienstleister.php';
|
||||||
|
|
||||||
@ -190,5 +191,14 @@ class Versandart_sendcloud extends Versanddienstleister
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function GetShipmentStatus(string $tracking): ShipmentStatus|null
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->api->GetTrackingStatus($tracking);
|
||||||
|
} catch (SendcloudApiException) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user