update
This commit is contained in:
@@ -112,9 +112,15 @@ final class ApaczkaShipmentService implements ShipmentProviderInterface
|
||||
}
|
||||
|
||||
if ($codAmount > 0) {
|
||||
$companySettings = $this->companySettings->getSettings();
|
||||
$bankAccount = preg_replace('/[^0-9]/', '', $companySettings['bank_account'] ?? '');
|
||||
if ($bankAccount === '') {
|
||||
throw new ShipmentException('Przesylka COD wymaga numeru konta bankowego. Uzupelnij go w Ustawienia > Firma.');
|
||||
}
|
||||
$apiPayload['cod'] = [
|
||||
'amount' => (int) round($codAmount * 100),
|
||||
'currency' => strtoupper(trim((string) ($formData['cod_currency'] ?? 'PLN'))),
|
||||
'bankaccount' => $bankAccount,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -391,6 +391,63 @@ final class ShipmentController
|
||||
return Response::redirect('/orders/' . $orderId);
|
||||
}
|
||||
|
||||
public function delete(Request $request): Response
|
||||
{
|
||||
$orderId = max(0, (int) $request->input('id', 0));
|
||||
$packageId = max(0, (int) $request->input('packageId', 0));
|
||||
if ($orderId <= 0 || $packageId <= 0) {
|
||||
return Response::html('Not found', 404);
|
||||
}
|
||||
|
||||
$csrfToken = (string) $request->input('_token', '');
|
||||
if (!Csrf::validate($csrfToken)) {
|
||||
Flash::set('order.error', $this->translator->get('auth.errors.csrf_expired'));
|
||||
return Response::redirect('/orders/' . $orderId);
|
||||
}
|
||||
|
||||
$package = $this->packageRepository->findById($packageId);
|
||||
if ($package === null || (int) ($package['order_id'] ?? 0) !== $orderId) {
|
||||
Flash::set('order.error', 'Przesylka nie znaleziona.');
|
||||
return Response::redirect('/orders/' . $orderId);
|
||||
}
|
||||
|
||||
$labelPath = trim((string) ($package['label_path'] ?? ''));
|
||||
if ($labelPath !== '') {
|
||||
$fullLabelPath = $this->storagePath . '/' . $labelPath;
|
||||
if (file_exists($fullLabelPath)) {
|
||||
unlink($fullLabelPath);
|
||||
}
|
||||
}
|
||||
|
||||
$this->packageRepository->delete($packageId);
|
||||
|
||||
$user = $this->auth->user();
|
||||
$actorName = is_array($user) ? trim((string) ($user['name'] ?? $user['email'] ?? '')) : null;
|
||||
$actorName = ($actorName !== null && $actorName !== '') ? $actorName : null;
|
||||
|
||||
$trackingNumber = trim((string) ($package['tracking_number'] ?? ''));
|
||||
$provider = trim((string) ($package['provider'] ?? ''));
|
||||
$description = 'Usunieto przesylke #' . $packageId;
|
||||
if ($trackingNumber !== '') {
|
||||
$description .= ' (tracking: ' . $trackingNumber . ')';
|
||||
}
|
||||
if ($provider !== '') {
|
||||
$description .= ' [' . $provider . ']';
|
||||
}
|
||||
|
||||
$this->ordersRepository->recordActivity(
|
||||
$orderId,
|
||||
'shipment_deleted',
|
||||
$description,
|
||||
['package_id' => $packageId, 'tracking_number' => $trackingNumber, 'provider' => $provider],
|
||||
'user',
|
||||
$actorName
|
||||
);
|
||||
|
||||
Flash::set('order.success', 'Przesylka zostala usunieta.');
|
||||
return Response::redirect('/orders/' . $orderId);
|
||||
}
|
||||
|
||||
private function triggerShipmentCreatedAutomation(int $orderId, int $packageId, string $providerCode): void
|
||||
{
|
||||
if ($orderId <= 0 || $packageId <= 0) {
|
||||
|
||||
@@ -213,6 +213,12 @@ final class ShipmentPackageRepository
|
||||
return $name !== '' ? $name : null;
|
||||
}
|
||||
|
||||
public function delete(int $id): void
|
||||
{
|
||||
$statement = $this->pdo->prepare('DELETE FROM shipment_packages WHERE id = :id');
|
||||
$statement->execute(['id' => $id]);
|
||||
}
|
||||
|
||||
private function nullStr(string $value): ?string
|
||||
{
|
||||
$trimmed = trim($value);
|
||||
|
||||
Reference in New Issue
Block a user