update
This commit is contained in:
@@ -231,6 +231,8 @@ final class OrdersController
|
||||
$flashSuccess = (string) Flash::get('order.success', '');
|
||||
$flashError = (string) Flash::get('order.error', '');
|
||||
|
||||
$customerRiskInfo = $this->buildCustomerRiskInfo($order, $orderId);
|
||||
|
||||
$html = $this->template->render('orders/show', [
|
||||
'title' => $this->translator->get('orders.details.title') . ' #' . $orderId,
|
||||
'activeMenu' => 'orders',
|
||||
@@ -259,11 +261,69 @@ final class OrdersController
|
||||
'receiptConfigs' => $activeReceiptConfigs,
|
||||
'emailTemplates' => $emailTemplates,
|
||||
'emailMailboxes' => $emailMailboxes,
|
||||
'customerRiskInfo' => $customerRiskInfo,
|
||||
], 'layouts/app');
|
||||
|
||||
return Response::html($html);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sklada informacje o historii zwrotow klienta biezacego zamowienia.
|
||||
*
|
||||
* @param array<string, mixed> $order
|
||||
* @return array{count:int, orders:array<int, array<string, mixed>>, email:string, phone:string, name:string, text:string}
|
||||
*/
|
||||
private function buildCustomerRiskInfo(array $order, int $orderId): array
|
||||
{
|
||||
$count = max(0, (int) ($order['customer_returned_count'] ?? 0));
|
||||
$email = trim((string) ($order['buyer_email'] ?? ''));
|
||||
$phone = trim((string) ($order['buyer_phone'] ?? ''));
|
||||
$name = trim((string) ($order['buyer_name'] ?? ''));
|
||||
|
||||
$returnedOrders = [];
|
||||
if ($count > 0 && $this->shipmentPackages !== null) {
|
||||
$returnedOrders = $this->shipmentPackages->findReturnedByCustomer(
|
||||
['email' => $email, 'phone' => $phone, 'name' => $name],
|
||||
$orderId
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
'count' => $count,
|
||||
'orders' => $returnedOrders,
|
||||
'email' => $email,
|
||||
'phone' => $phone,
|
||||
'name' => $name,
|
||||
'text' => $this->composeCustomerRiskText($count, $email, $phone, $name),
|
||||
];
|
||||
}
|
||||
|
||||
private function composeCustomerRiskText(int $count, string $email, string $phone, string $name): string
|
||||
{
|
||||
if ($count <= 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$hasPhone = $phone !== '';
|
||||
$hasEmail = $email !== '';
|
||||
$hasName = $name !== '';
|
||||
|
||||
if ($hasPhone && $hasEmail) {
|
||||
$subject = 'Osoba o numerze telefonu ' . $phone . ' oraz email ' . $email;
|
||||
} elseif ($hasEmail) {
|
||||
$subject = 'Osoba o emailu ' . $email;
|
||||
} elseif ($hasPhone) {
|
||||
$subject = 'Osoba o numerze telefonu ' . $phone;
|
||||
} elseif ($hasName) {
|
||||
$subject = 'Osoba o imieniu i nazwisku ' . $name;
|
||||
} else {
|
||||
$subject = 'Ten klient';
|
||||
}
|
||||
|
||||
$noun = $count === 1 ? 'przesylke' : 'przesylek';
|
||||
return $subject . ' nie odebrala ' . $count . ' ' . $noun . '.';
|
||||
}
|
||||
|
||||
public function updateDetails(Request $request): Response
|
||||
{
|
||||
$orderId = max(0, (int) $request->input('id', 0));
|
||||
@@ -429,6 +489,10 @@ final class OrdersController
|
||||
$itemsPreview = is_array($row['items_preview'] ?? null) ? $row['items_preview'] : [];
|
||||
$projectsDone = max(0, (int) ($row['projects_done'] ?? 0));
|
||||
$projectsTotal = max(0, (int) ($row['projects_total'] ?? 0));
|
||||
$returnedCount = max(0, (int) ($row['customer_returned_count'] ?? 0));
|
||||
$returnedBadge = $returnedCount >= 1
|
||||
? ' <span class="risk-return-badge" title="Klient nie odebral ' . $returnedCount . ' przesylek w historii">zwroty: ' . $returnedCount . '</span>'
|
||||
: '';
|
||||
|
||||
$previewBtn = '<button type="button" class="btn-icon js-order-preview-btn" data-order-id="' . (int) ($row['id'] ?? 0) . '" title="Podglad">'
|
||||
. '<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>'
|
||||
@@ -446,7 +510,7 @@ final class OrdersController
|
||||
. '</div>'
|
||||
. '</div>',
|
||||
'buyer' => '<div class="orders-buyer">'
|
||||
. '<div class="orders-buyer__name">' . htmlspecialchars($buyerName !== '' ? $buyerName : '-', ENT_QUOTES, 'UTF-8') . '</div>'
|
||||
. '<div class="orders-buyer__name">' . htmlspecialchars($buyerName !== '' ? $buyerName : '-', ENT_QUOTES, 'UTF-8') . $returnedBadge . '</div>'
|
||||
. '<div class="orders-buyer__meta">'
|
||||
. '<span>' . htmlspecialchars($buyerEmail, ENT_QUOTES, 'UTF-8') . '</span>'
|
||||
. '<span>' . htmlspecialchars($buyerCity, ENT_QUOTES, 'UTF-8') . '</span>'
|
||||
@@ -466,7 +530,7 @@ final class OrdersController
|
||||
$documents
|
||||
),
|
||||
'ordered_at' => (string) ($row['ordered_at'] ?? ''),
|
||||
'_row_class' => $this->agedRowClass((string) ($row['ordered_at'] ?? '')),
|
||||
'_row_class' => trim($this->agedRowClass((string) ($row['ordered_at'] ?? '')) . ($returnedCount >= 1 ? ' is-risk-return' : '')),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user