update
This commit is contained in:
@@ -12,6 +12,9 @@ use App\Core\Support\Flash;
|
||||
use App\Core\Support\StringHelper;
|
||||
use App\Modules\Accounting\ReceiptRepository;
|
||||
use App\Modules\Auth\AuthService;
|
||||
use App\Modules\Email\EmailSendingService;
|
||||
use App\Modules\Settings\EmailMailboxRepository;
|
||||
use App\Modules\Settings\EmailTemplateRepository;
|
||||
use App\Modules\Settings\ReceiptConfigRepository;
|
||||
use App\Modules\Shipments\ShipmentPackageRepository;
|
||||
|
||||
@@ -24,7 +27,10 @@ final class OrdersController
|
||||
private readonly OrdersRepository $orders,
|
||||
private readonly ?ShipmentPackageRepository $shipmentPackages = null,
|
||||
private readonly ?ReceiptRepository $receiptRepo = null,
|
||||
private readonly ?ReceiptConfigRepository $receiptConfigRepo = null
|
||||
private readonly ?ReceiptConfigRepository $receiptConfigRepo = null,
|
||||
private readonly ?EmailSendingService $emailService = null,
|
||||
private readonly ?EmailTemplateRepository $emailTemplateRepo = null,
|
||||
private readonly ?EmailMailboxRepository $emailMailboxRepo = null
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -178,6 +184,9 @@ final class OrdersController
|
||||
);
|
||||
}
|
||||
|
||||
$emailTemplates = $this->emailTemplateRepo !== null ? $this->emailTemplateRepo->listActive() : [];
|
||||
$emailMailboxes = $this->emailMailboxRepo !== null ? $this->emailMailboxRepo->listActive() : [];
|
||||
|
||||
$flashSuccess = (string) Flash::get('order.success', '');
|
||||
$flashError = (string) Flash::get('order.error', '');
|
||||
|
||||
@@ -206,6 +215,8 @@ final class OrdersController
|
||||
'flashError' => $flashError,
|
||||
'receipts' => $receipts,
|
||||
'receiptConfigs' => $activeReceiptConfigs,
|
||||
'emailTemplates' => $emailTemplates,
|
||||
'emailMailboxes' => $emailMailboxes,
|
||||
], 'layouts/app');
|
||||
|
||||
return Response::html($html);
|
||||
@@ -676,4 +687,51 @@ final class OrdersController
|
||||
return $entry;
|
||||
}, $history);
|
||||
}
|
||||
|
||||
public function sendEmail(Request $request): Response
|
||||
{
|
||||
$orderId = max(0, (int) $request->input('id', 0));
|
||||
if ($orderId <= 0) {
|
||||
return Response::json(['success' => false, 'message' => 'Nieprawidlowe zamowienie'], 400);
|
||||
}
|
||||
|
||||
$csrfToken = (string) $request->input('_token', '');
|
||||
if (!Csrf::validate($csrfToken)) {
|
||||
return Response::json(['success' => false, 'message' => 'Sesja wygasla, odswiez strone'], 403);
|
||||
}
|
||||
|
||||
if ($this->emailService === null) {
|
||||
return Response::json(['success' => false, 'message' => 'Modul e-mail nie jest skonfigurowany'], 500);
|
||||
}
|
||||
|
||||
$templateId = max(0, (int) $request->input('template_id', 0));
|
||||
if ($templateId <= 0) {
|
||||
return Response::json(['success' => false, 'message' => 'Wybierz szablon'], 400);
|
||||
}
|
||||
|
||||
$mailboxId = (int) $request->input('mailbox_id', 0);
|
||||
$user = $this->auth->user();
|
||||
$userName = is_array($user) ? trim((string) ($user['name'] ?? $user['email'] ?? '')) : '';
|
||||
$result = $this->emailService->send($orderId, $templateId, $mailboxId > 0 ? $mailboxId : null, $userName !== '' ? $userName : null);
|
||||
|
||||
return Response::json([
|
||||
'success' => $result['success'],
|
||||
'message' => $result['success'] ? 'E-mail wyslany pomyslnie' : ('Blad wysylki: ' . ($result['error'] ?? 'nieznany')),
|
||||
]);
|
||||
}
|
||||
|
||||
public function emailPreview(Request $request): Response
|
||||
{
|
||||
$orderId = max(0, (int) $request->input('id', 0));
|
||||
$templateId = max(0, (int) $request->input('template_id', 0));
|
||||
|
||||
if ($orderId <= 0 || $templateId <= 0 || $this->emailService === null) {
|
||||
return Response::json(['subject' => '', 'body_html' => '', 'attachments' => []], 400);
|
||||
}
|
||||
|
||||
$preview = $this->emailService->preview($orderId, $templateId);
|
||||
|
||||
return Response::json($preview);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -95,8 +95,13 @@ final class OrdersRepository
|
||||
|
||||
$search = trim((string) ($filters['search'] ?? ''));
|
||||
if ($search !== '') {
|
||||
$where[] = '(o.source_order_id LIKE :search OR o.external_order_id LIKE :search OR o.customer_login LIKE :search OR a.name LIKE :search OR a.email LIKE :search)';
|
||||
$params['search'] = '%' . $search . '%';
|
||||
$where[] = '(o.source_order_id LIKE :s1 OR o.external_order_id LIKE :s2 OR o.customer_login LIKE :s3 OR a.name LIKE :s4 OR a.email LIKE :s5)';
|
||||
$searchVal = '%' . $search . '%';
|
||||
$params['s1'] = $searchVal;
|
||||
$params['s2'] = $searchVal;
|
||||
$params['s3'] = $searchVal;
|
||||
$params['s4'] = $searchVal;
|
||||
$params['s5'] = $searchVal;
|
||||
}
|
||||
|
||||
$source = trim((string) ($filters['source'] ?? ''));
|
||||
|
||||
Reference in New Issue
Block a user