feat(v1.5): complete phases 40-43 workflow cleanup

This commit is contained in:
2026-03-25 22:46:51 +01:00
parent b8dda81e7b
commit 3610571949
37 changed files with 1557 additions and 259 deletions

View File

@@ -8,6 +8,7 @@ $actions = $isEdit ? (is_array($rule['actions'] ?? null) ? $rule['actions'] : []
$eventLabels = [
'receipt.created' => 'Utworzono paragon',
'shipment.status_changed' => 'Zmiana statusu przesylki',
];
$recipientLabels = [
@@ -15,6 +16,7 @@ $recipientLabels = [
'client_and_company' => 'Klient + e-mail z danych firmy',
'company' => 'E-mail z danych firmy',
];
$shipmentStatusOptions = is_array($shipmentStatusOptions ?? null) ? $shipmentStatusOptions : [];
?>
<section class="card">
@@ -62,20 +64,35 @@ $recipientLabels = [
<div class="automation-row__fields">
<select class="form-control automation-row__type" name="conditions[<?= $idx ?>][type]" onchange="window.AutomationForm.onConditionTypeChange(this)">
<option value="integration"<?= ((string) ($cond['condition_type'] ?? '')) === 'integration' ? ' selected' : '' ?>>Integracja (kanal sprzedazy)</option>
<option value="shipment_status"<?= ((string) ($cond['condition_type'] ?? '')) === 'shipment_status' ? ' selected' : '' ?>>Status przesylki</option>
</select>
<div class="automation-row__config">
<?php
$condValue = is_array($cond['condition_value'] ?? null) ? $cond['condition_value'] : [];
$conditionType = (string) ($cond['condition_type'] ?? 'integration');
$selectedIds = is_array($condValue['integration_ids'] ?? null) ? $condValue['integration_ids'] : [];
$selectedStatusKeys = is_array($condValue['status_keys'] ?? null) ? $condValue['status_keys'] : [];
?>
<div class="checkbox-group">
<?php foreach ($integrations as $integ): ?>
<label class="checkbox-label">
<input type="checkbox" name="conditions[<?= $idx ?>][integration_ids][]" value="<?= (int) $integ['id'] ?>"<?= in_array((int) $integ['id'], $selectedIds, true) ? ' checked' : '' ?>>
<?= $e((string) ($integ['name'] ?? '')) ?> <span class="muted">(<?= $e((string) ($integ['type'] ?? '')) ?>)</span>
</label>
<?php endforeach; ?>
</div>
<?php if ($conditionType === 'shipment_status'): ?>
<div class="checkbox-group">
<?php foreach ($shipmentStatusOptions as $statusKey => $statusConfig): ?>
<?php $statusLabel = (string) ($statusConfig['label'] ?? $statusKey); ?>
<label class="checkbox-label">
<input type="checkbox" name="conditions[<?= $idx ?>][shipment_status_keys][]" value="<?= $e((string) $statusKey) ?>"<?= in_array((string) $statusKey, $selectedStatusKeys, true) ? ' checked' : '' ?>>
<?= $e($statusLabel) ?>
</label>
<?php endforeach; ?>
</div>
<?php else: ?>
<div class="checkbox-group">
<?php foreach ($integrations as $integ): ?>
<label class="checkbox-label">
<input type="checkbox" name="conditions[<?= $idx ?>][integration_ids][]" value="<?= (int) $integ['id'] ?>"<?= in_array((int) $integ['id'], $selectedIds, true) ? ' checked' : '' ?>>
<?= $e((string) ($integ['name'] ?? '')) ?> <span class="muted">(<?= $e((string) ($integ['type'] ?? '')) ?>)</span>
</label>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
<button type="button" class="btn btn--sm btn--danger automation-row__remove" onclick="window.AutomationForm.removeRow(this)">&times;</button>
@@ -133,7 +150,8 @@ window.AutomationFormData = {
emailTemplates: <?= json_encode(array_map(function($t) {
return ['id' => (int) $t['id'], 'name' => (string) ($t['name'] ?? '')];
}, $emailTemplates), JSON_UNESCAPED_UNICODE) ?>,
recipientLabels: <?= json_encode($recipientLabels, JSON_UNESCAPED_UNICODE) ?>
recipientLabels: <?= json_encode($recipientLabels, JSON_UNESCAPED_UNICODE) ?>,
shipmentStatusOptions: <?= json_encode($shipmentStatusOptions, JSON_UNESCAPED_UNICODE) ?>
};
</script>
<script src="/assets/js/modules/automation-form.js"></script>

View File

@@ -3,6 +3,7 @@ $rules = is_array($rules ?? null) ? $rules : [];
$eventLabels = [
'receipt.created' => 'Utworzono paragon',
'shipment.status_changed' => 'Zmiana statusu przesylki',
];
?>

View File

@@ -50,54 +50,7 @@
popup.style.left = left + 'px';
popup.style.top = top + 'px';
}, true);
// Bulk print labels
var bulkPrintBtn = document.querySelector('.js-bulk-print-labels');
if (bulkPrintBtn) {
bulkPrintBtn.addEventListener('click', function () {
var checked = document.querySelectorAll('.js-table-select-item:checked');
if (checked.length === 0) {
if (window.OrderProAlerts) {
window.OrderProAlerts.show({ message: 'Zaznacz co najmniej jedno zamowienie.', type: 'warning' });
}
return;
}
var orderIds = [];
checked.forEach(function (cb) { orderIds.push(cb.value); });
var csrf = bulkPrintBtn.getAttribute('data-csrf') || '';
bulkPrintBtn.disabled = true;
bulkPrintBtn.textContent = 'Wysylam...';
fetch('/api/print/jobs/bulk', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ order_ids: orderIds, _token: csrf })
})
.then(function (r) { return r.json(); })
.then(function (data) {
var created = (data.created || []).length;
var skipped = (data.skipped || []).length;
var msg = 'Wyslano ' + created + ' zlecen do drukarki.';
if (skipped > 0) {
msg += ' Pominieto ' + skipped + ' (brak etykiety lub juz w kolejce).';
}
if (window.OrderProAlerts) {
window.OrderProAlerts.show({ message: msg, type: 'success' });
}
bulkPrintBtn.disabled = false;
bulkPrintBtn.textContent = 'Drukuj etykiety';
})
.catch(function () {
if (window.OrderProAlerts) {
window.OrderProAlerts.show({ message: 'Blad sieci — sprobuj ponownie.', type: 'error' });
}
bulkPrintBtn.disabled = false;
bulkPrintBtn.textContent = 'Drukuj etykiety';
});
});
}
})();
</script>

View File

@@ -354,6 +354,25 @@ foreach ($addressesList as $address) {
if ($eventTypeLabel === $eventTypeKey) {
$eventTypeLabel = $eventType;
}
$activitySummary = (string) ($activity['summary'] ?? '');
if ($eventType === 'import') {
$importDetailsRaw = (string) ($activity['details_json'] ?? '');
$importDetails = json_decode($importDetailsRaw, true);
if (is_array($importDetails)) {
$meta = [];
$triggerLabel = trim((string) ($importDetails['trigger_label'] ?? ''));
$sourceUpdatedAt = trim((string) ($importDetails['source_updated_at'] ?? ''));
if ($triggerLabel !== '') {
$meta[] = $triggerLabel;
}
if ($sourceUpdatedAt !== '') {
$meta[] = 'source_updated_at: ' . $sourceUpdatedAt;
}
if ($meta !== []) {
$activitySummary .= ' [' . implode('; ', $meta) . ']';
}
}
}
$actorType = (string) ($activity['actor_type'] ?? 'system');
$actorName = trim((string) ($activity['actor_name'] ?? ''));
if ($actorName !== '') {
@@ -369,7 +388,7 @@ foreach ($addressesList as $address) {
<tr>
<td class="text-nowrap"><?= $e((string) ($activity['created_at'] ?? '')) ?></td>
<td><span class="activity-type-badge activity-type-badge--<?= $e($eventType) ?>"><?= $e($eventTypeLabel) ?></span></td>
<td><?= $e((string) ($activity['summary'] ?? '')) ?></td>
<td><?= $e($activitySummary) ?></td>
<td class="muted"><?= $e($actorLabel) ?></td>
</tr>
<?php endforeach; ?>

View File

@@ -144,12 +144,23 @@ $currentStatusFilter = (string) ($printStatusFilter ?? '');
<td><span class="print-status-badge <?= $e($badgeClass) ?>"><?= $e($badgeLabel) ?></span></td>
<td class="text-nowrap"><?= $e($jobCompletedAt !== '' ? $jobCompletedAt : '-') ?></td>
<td>
<?php if ($jobStatus === 'failed' && $jobPackageId > 0): ?>
<button type="button"
class="btn btn--sm btn--secondary btn-retry-print"
data-package-id="<?= $e((string) $jobPackageId) ?>"
data-csrf="<?= $e((string) ($csrfToken ?? '')) ?>">Ponow</button>
<?php endif; ?>
<div class="print-queue-actions">
<?php if ($jobStatus === 'failed' && $jobPackageId > 0): ?>
<button type="button"
class="btn btn--sm btn--secondary btn-retry-print"
data-package-id="<?= $e((string) $jobPackageId) ?>"
data-csrf="<?= $e((string) ($csrfToken ?? '')) ?>">Ponow</button>
<?php endif; ?>
<form method="post" action="/settings/printing/jobs/delete" class="print-queue-delete-form">
<input type="hidden" name="_token" value="<?= $e((string) ($csrfToken ?? '')) ?>">
<input type="hidden" name="id" value="<?= $e((string) $jobId) ?>">
<button
type="button"
class="btn btn--sm btn--danger js-delete-print-job"
data-job-id="<?= $e((string) $jobId) ?>"
>Usun</button>
</form>
</div>
</td>
</tr>
<?php endforeach; ?>
@@ -161,6 +172,20 @@ $currentStatusFilter = (string) ($printStatusFilter ?? '');
<script>
(function () {
document.querySelectorAll('.js-delete-print-job').forEach(function (btn) {
btn.addEventListener('click', function () {
var form = btn.closest('form');
if (!form) return;
if (window.OrderProAlerts && window.OrderProAlerts.confirm) {
window.OrderProAlerts.confirm(
'Usuwanie wpisu z kolejki',
'Czy na pewno chcesz usunac ten wpis kolejki wydruku?',
function () { form.submit(); }
);
}
});
});
document.querySelectorAll('.btn-retry-print').forEach(function (btn) {
btn.addEventListener('click', function () {
var packageId = btn.getAttribute('data-package-id');