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:
@@ -106,7 +106,12 @@ final class OrderImportRepository
|
||||
);
|
||||
$statement->execute($this->orderParams($orderData));
|
||||
|
||||
return (int) $this->pdo->lastInsertId();
|
||||
$newId = (int) $this->pdo->lastInsertId();
|
||||
$this->pdo->prepare(
|
||||
"UPDATE orders SET internal_order_number = CONCAT('OP', LPAD(id, 9, '0')) WHERE id = :id AND (internal_order_number IS NULL OR internal_order_number = '')"
|
||||
)->execute(['id' => $newId]);
|
||||
|
||||
return $newId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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'] ?? '')),
|
||||
|
||||
@@ -99,6 +99,7 @@ final class OrdersRepository
|
||||
|
||||
$listSql = 'SELECT
|
||||
o.id,
|
||||
o.internal_order_number,
|
||||
o.source,
|
||||
o.source_order_id,
|
||||
o.external_order_id,
|
||||
@@ -119,6 +120,7 @@ final class OrdersRepository
|
||||
a.email AS buyer_email,
|
||||
a.city AS buyer_city,
|
||||
o.external_carrier_id,
|
||||
o.external_payment_type_id,
|
||||
(SELECT COUNT(*) FROM order_items oi WHERE oi.order_id = o.id) AS items_count,
|
||||
(SELECT COALESCE(SUM(oi.quantity), 0) FROM order_items oi WHERE oi.order_id = o.id) AS items_qty,
|
||||
(SELECT COUNT(*) FROM order_shipments sh WHERE sh.order_id = o.id) AS shipments_count,
|
||||
@@ -156,6 +158,7 @@ final class OrdersRepository
|
||||
$orderId = (int) ($row['id'] ?? 0);
|
||||
return [
|
||||
'id' => $orderId,
|
||||
'internal_order_number' => (string) ($row['internal_order_number'] ?? ''),
|
||||
'source' => (string) ($row['source'] ?? ''),
|
||||
'source_order_id' => (string) ($row['source_order_id'] ?? ''),
|
||||
'external_order_id' => (string) ($row['external_order_id'] ?? ''),
|
||||
@@ -172,6 +175,7 @@ final class OrdersRepository
|
||||
'is_invoice' => (int) ($row['is_invoice'] ?? 0) === 1,
|
||||
'is_canceled_by_buyer' => (int) ($row['is_canceled_by_buyer'] ?? 0) === 1,
|
||||
'external_carrier_id' => (string) ($row['external_carrier_id'] ?? ''),
|
||||
'external_payment_type_id' => (string) ($row['external_payment_type_id'] ?? ''),
|
||||
'buyer_name' => (string) ($row['buyer_name'] ?? ''),
|
||||
'buyer_email' => (string) ($row['buyer_email'] ?? ''),
|
||||
'buyer_city' => (string) ($row['buyer_city'] ?? ''),
|
||||
|
||||
Reference in New Issue
Block a user