update
This commit is contained in:
@@ -10,14 +10,17 @@ use App\Core\Security\Csrf;
|
||||
use App\Core\Support\Flash;
|
||||
use App\Core\View\Template;
|
||||
use App\Modules\Auth\AuthService;
|
||||
use App\Modules\Settings\ReceiptConfigRepository;
|
||||
use Throwable;
|
||||
|
||||
final class AutomationController
|
||||
{
|
||||
private const ALLOWED_EVENTS = ['receipt.created', 'shipment.status_changed'];
|
||||
private const ALLOWED_CONDITION_TYPES = ['integration', 'shipment_status'];
|
||||
private const ALLOWED_ACTION_TYPES = ['send_email'];
|
||||
private const ALLOWED_ACTION_TYPES = ['send_email', 'issue_receipt'];
|
||||
private const ALLOWED_RECIPIENTS = ['client', 'client_and_company', 'company'];
|
||||
private const ALLOWED_RECEIPT_ISSUE_DATE_MODES = ['today', 'order_date', 'payment_date'];
|
||||
private const ALLOWED_RECEIPT_DUPLICATE_POLICIES = ['skip_if_exists', 'allow_duplicates'];
|
||||
private const SHIPMENT_STATUS_OPTIONS = [
|
||||
'registered' => ['label' => 'Przesylka zarejestrowana', 'statuses' => ['created', 'confirmed']],
|
||||
'ready_for_pickup' => ['label' => 'Przesylka do odbioru', 'statuses' => ['ready_for_pickup']],
|
||||
@@ -32,7 +35,8 @@ final class AutomationController
|
||||
private readonly Template $template,
|
||||
private readonly Translator $translator,
|
||||
private readonly AuthService $auth,
|
||||
private readonly AutomationRepository $repository
|
||||
private readonly AutomationRepository $repository,
|
||||
private readonly ReceiptConfigRepository $receiptConfigs
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -194,6 +198,9 @@ final class AutomationController
|
||||
'conditionTypes' => self::ALLOWED_CONDITION_TYPES,
|
||||
'actionTypes' => self::ALLOWED_ACTION_TYPES,
|
||||
'recipientOptions' => self::ALLOWED_RECIPIENTS,
|
||||
'receiptConfigs' => $this->listActiveReceiptConfigs(),
|
||||
'receiptIssueDateModes' => self::ALLOWED_RECEIPT_ISSUE_DATE_MODES,
|
||||
'receiptDuplicatePolicies' => self::ALLOWED_RECEIPT_DUPLICATE_POLICIES,
|
||||
'shipmentStatusOptions' => self::SHIPMENT_STATUS_OPTIONS,
|
||||
'errorMessage' => Flash::get('settings.automation.error', ''),
|
||||
], 'layouts/app');
|
||||
@@ -366,6 +373,51 @@ final class AutomationController
|
||||
return ['template_id' => $templateId, 'recipient' => $recipient];
|
||||
}
|
||||
|
||||
if ($type === 'issue_receipt') {
|
||||
$configId = (int) ($action['receipt_config_id'] ?? 0);
|
||||
$issueDateMode = (string) ($action['issue_date_mode'] ?? '');
|
||||
$duplicatePolicy = (string) ($action['duplicate_policy'] ?? '');
|
||||
|
||||
if (
|
||||
$configId <= 0
|
||||
|| !in_array($issueDateMode, self::ALLOWED_RECEIPT_ISSUE_DATE_MODES, true)
|
||||
|| !in_array($duplicatePolicy, self::ALLOWED_RECEIPT_DUPLICATE_POLICIES, true)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'receipt_config_id' => $configId,
|
||||
'issue_date_mode' => $issueDateMode,
|
||||
'duplicate_policy' => $duplicatePolicy,
|
||||
];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{id:int,name:string,number_format:string}>
|
||||
*/
|
||||
private function listActiveReceiptConfigs(): array
|
||||
{
|
||||
$all = $this->receiptConfigs->listAll();
|
||||
$result = [];
|
||||
foreach ($all as $config) {
|
||||
if ((int) ($config['is_active'] ?? 0) !== 1) {
|
||||
continue;
|
||||
}
|
||||
$configId = (int) ($config['id'] ?? 0);
|
||||
if ($configId <= 0) {
|
||||
continue;
|
||||
}
|
||||
$result[] = [
|
||||
'id' => $configId,
|
||||
'name' => (string) ($config['name'] ?? ''),
|
||||
'number_format' => (string) ($config['number_format'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user