feat: Enhance InPost service selection and handling in Allegro settings

- Added a check for available InPost services and display a message if none are found.
- Updated the InPost service selection dropdown to include additional data attributes for better handling in JavaScript.
- Improved JavaScript event handling for InPost service selection to correctly populate hidden fields with selected service data.

feat: Introduce Cash on Delivery (COD) functionality in shipment preparation

- Added a new input field for specifying the COD amount and currency in the shipment preparation view.
- Updated the shipment creation logic to handle COD amounts correctly when creating shipments.

refactor: Update OrdersController to include shipment package repository

- Modified the OrdersController to accept a ShipmentPackageRepository for better management of shipment-related data.
- Enhanced order details to include shipment package information.

fix: Ensure internal order numbers are generated upon order creation

- Updated the OrderImportRepository to generate and store internal order numbers when a new order is created.

feat: Implement status synchronization for Allegro orders

- Introduced a new service for syncing order statuses from Allegro to the internal system.
- Added logic to fetch and process orders needing status updates, handling errors gracefully.

chore: Clean up InPost service definitions in AllegroIntegrationController

- Removed hardcoded InPost service definitions and replaced them with dynamic fetching based on available services.

feat: Add activity logging for shipment actions

- Implemented activity logging for various shipment actions, including creation, label downloads, and errors, to improve traceability and auditing.
This commit is contained in:
2026-03-06 20:09:59 +01:00
parent 1b5e403c31
commit 3ba6202770
21 changed files with 1888 additions and 226 deletions

View File

@@ -9,6 +9,7 @@ use App\Core\I18n\Translator;
use App\Core\Security\Csrf;
use App\Core\View\Template;
use App\Modules\Auth\AuthService;
use App\Modules\Shipments\ShipmentPackageRepository;
final class OrdersController
{
@@ -16,7 +17,8 @@ final class OrdersController
private readonly Template $template,
private readonly Translator $translator,
private readonly AuthService $auth,
private readonly OrdersRepository $orders
private readonly OrdersRepository $orders,
private readonly ?ShipmentPackageRepository $shipmentPackages = null
) {
}
@@ -153,6 +155,10 @@ final class OrdersController
$allStatuses = $this->buildAllStatusOptions($statusConfig);
$packages = $this->shipmentPackages !== null
? $this->shipmentPackages->findByOrderId($orderId)
: [];
$flashSuccess = (string) ($_SESSION['order_flash_success'] ?? '');
$flashError = (string) ($_SESSION['order_flash_error'] ?? '');
unset($_SESSION['order_flash_success'], $_SESSION['order_flash_error']);
@@ -169,6 +175,7 @@ final class OrdersController
'addresses' => $addresses,
'payments' => $payments,
'shipments' => $shipments,
'packages' => $packages,
'documents' => $documents,
'notes' => $notes,
'history' => $resolvedHistory,
@@ -222,6 +229,7 @@ final class OrdersController
*/
private function toTableRow(array $row, array $statusLabelMap): array
{
$internalOrderNumber = trim((string) ($row['internal_order_number'] ?? ''));
$sourceOrderId = trim((string) ($row['source_order_id'] ?? ''));
$externalOrderId = trim((string) ($row['external_order_id'] ?? ''));
$source = trim((string) ($row['source'] ?? ''));
@@ -232,6 +240,10 @@ final class OrdersController
$currency = trim((string) ($row['currency'] ?? ''));
$totalWithTax = $row['total_with_tax'] !== null ? number_format((float) $row['total_with_tax'], 2, '.', ' ') : '-';
$totalPaid = $row['total_paid'] !== null ? number_format((float) $row['total_paid'], 2, '.', ' ') : '-';
$paymentType = strtoupper(trim((string) ($row['external_payment_type_id'] ?? '')));
$isCod = $paymentType === 'CASH_ON_DELIVERY';
$paymentStatus = isset($row['payment_status']) ? (int) $row['payment_status'] : null;
$isUnpaid = !$isCod && $paymentStatus === 0;
$itemsCount = max(0, (int) ($row['items_count'] ?? 0));
$itemsQty = $this->formatQuantity((float) ($row['items_qty'] ?? 0));
$shipments = max(0, (int) ($row['shipments_count'] ?? 0));
@@ -241,10 +253,10 @@ final class OrdersController
return [
'order_ref' => '<div class="orders-ref">'
. '<div class="orders-ref__main"><a href="/orders/' . (int) ($row['id'] ?? 0) . '">'
. htmlspecialchars($sourceOrderId !== '' ? $sourceOrderId : ('#' . (string) ($row['id'] ?? 0)), ENT_QUOTES, 'UTF-8')
. htmlspecialchars($internalOrderNumber !== '' ? $internalOrderNumber : ('#' . (string) ($row['id'] ?? 0)), ENT_QUOTES, 'UTF-8')
. '</a></div>'
. '<div class="orders-ref__meta">'
. '<span>' . htmlspecialchars($externalOrderId, ENT_QUOTES, 'UTF-8') . '</span>'
. '<span>' . htmlspecialchars($sourceOrderId !== '' ? $sourceOrderId : $externalOrderId, ENT_QUOTES, 'UTF-8') . '</span>'
. '<span>' . htmlspecialchars($source, ENT_QUOTES, 'UTF-8') . '</span>'
. '</div>'
. '</div>',
@@ -260,8 +272,8 @@ final class OrdersController
. '</div>',
'products' => $this->productsHtml($itemsPreview, $itemsCount, $itemsQty),
'totals' => '<div class="orders-money">'
. '<div class="orders-money__main">' . htmlspecialchars($totalWithTax . ' ' . $currency, ENT_QUOTES, 'UTF-8') . '</div>'
. '<div class="orders-money__meta">oplacono: ' . htmlspecialchars($totalPaid . ' ' . $currency, ENT_QUOTES, 'UTF-8') . '</div>'
. '<div class="orders-money__main">' . htmlspecialchars($totalWithTax . ' ' . $currency, ENT_QUOTES, 'UTF-8') . ($isUnpaid ? ' <span class="order-tag is-unpaid">Nieopłacone</span>' : '') . '</div>'
. '<div class="orders-money__meta">' . ($isCod ? '<span class="order-tag is-cod">Za pobraniem</span>' : 'oplacono: ' . htmlspecialchars($totalPaid . ' ' . $currency, ENT_QUOTES, 'UTF-8')) . '</div>'
. '</div>',
'shipping' => $this->shippingHtml(
trim((string) ($row['external_carrier_id'] ?? '')),