From b9f639e0378dbaf2268115941b447dc13bfa0fdd Mon Sep 17 00:00:00 2001 From: Jacek Pyziak Date: Wed, 18 Mar 2026 00:39:47 +0100 Subject: [PATCH] =?UTF-8?q?feat(16-automated-tasks):=20modu=C5=82=20zada?= =?UTF-8?q?=C5=84=20automatycznych=20=E2=80=94=20CRUD=20+=20watcher/execut?= =?UTF-8?q?or?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reguły automatyzacji oparte na zdarzeniach (receipt.created) z warunkami (integracja/kanał sprzedaży, AND logic) i akcjami (wyślij e-mail z 3 trybami odbiorcy: klient / firma / klient+firma). Trigger w ReceiptController po utworzeniu paragonu — błąd automatyzacji nie blokuje sukcesu paragonu. Co-Authored-By: Claude Opus 4.6 (1M context) --- .paul/PROJECT.md | 9 +- .paul/ROADMAP.md | 23 +- .paul/STATE.md | 29 +- .paul/phases/16-automated-tasks/16-01-PLAN.md | 307 ++ .../16-automated-tasks/16-01-SUMMARY.md | 135 + .paul/phases/16-automated-tasks/16-02-PLAN.md | 235 ++ .../16-automated-tasks/16-02-SUMMARY.md | 107 + DOCS/ARCHITECTURE.md | 11 + DOCS/DB_SCHEMA.md | 37 + DOCS/TECH_CHANGELOG.md | 19 + ...260318_000057_create_automation_tables.sql | 32 + public/assets/css/app.css | 2813 ++++++++++++++++- public/assets/js/modules/automation-form.js | 132 + resources/scss/app.scss | 1 + resources/scss/modules/_automation.scss | 65 + resources/views/automation/form.php | 139 + resources/views/automation/index.php | 96 + resources/views/layouts/app.php | 3 + routes/web.php | 26 +- src/Modules/Accounting/ReceiptController.php | 10 +- .../Automation/AutomationController.php | 346 ++ .../Automation/AutomationRepository.php | 277 ++ src/Modules/Automation/AutomationService.php | 165 + src/Modules/Email/EmailSendingService.php | 12 +- 24 files changed, 4997 insertions(+), 32 deletions(-) create mode 100644 .paul/phases/16-automated-tasks/16-01-PLAN.md create mode 100644 .paul/phases/16-automated-tasks/16-01-SUMMARY.md create mode 100644 .paul/phases/16-automated-tasks/16-02-PLAN.md create mode 100644 .paul/phases/16-automated-tasks/16-02-SUMMARY.md create mode 100644 database/migrations/20260318_000057_create_automation_tables.sql create mode 100644 public/assets/js/modules/automation-form.js create mode 100644 resources/scss/modules/_automation.scss create mode 100644 resources/views/automation/form.php create mode 100644 resources/views/automation/index.php create mode 100644 src/Modules/Automation/AutomationController.php create mode 100644 src/Modules/Automation/AutomationRepository.php create mode 100644 src/Modules/Automation/AutomationService.php diff --git a/.paul/PROJECT.md b/.paul/PROJECT.md index ade1fe3..93558f1 100644 --- a/.paul/PROJECT.md +++ b/.paul/PROJECT.md @@ -12,9 +12,9 @@ Sprzedawca może obsługiwać zamówienia ze wszystkich kanałów sprzedaży i n | Attribute | Value | |-----------|-------| -| Version | 0.4.0 | -| Status | v0.4 Complete | -| Last Updated | 2026-03-17 | +| Version | 0.5.0 | +| Status | v0.5 Complete | +| Last Updated | 2026-03-18 | ## Requirements @@ -36,10 +36,11 @@ Sprzedawca może obsługiwać zamówienia ze wszystkich kanałów sprzedaży i n - [x] Skrzynki pocztowe SMTP (CRUD + test połączenia) — Phase 13 - [x] Szablony wiadomości e-mail (CRUD + Quill.js + system zmiennych + załączniki) — Phase 14 - [x] Wysyłka e-mail z zamówień (resolwer zmiennych, załączniki, log) — Phase 15 +- [x] Zadania automatyczne — reguły zdarzenie/warunki/akcje (CRUD + watcher/executor) — Phase 16 ### Active (In Progress) -- (brak — v0.5 do zaplanowania) +- (brak — v0.6 do zaplanowania) ### Planned (Next) diff --git a/.paul/ROADMAP.md b/.paul/ROADMAP.md index e950cfe..e12bef2 100644 --- a/.paul/ROADMAP.md +++ b/.paul/ROADMAP.md @@ -6,18 +6,29 @@ orderPRO to narzędzie do wielokanałowego zarządzania sprzedażą. Projekt prz ## Current Milestone -### v0.4 Moduł E-mail — Complete ✓ (2026-03-17) +### v0.5 Moduł Automatyzacji — Complete ✓ (2026-03-18) -Skrzynki pocztowe SMTP, szablony wiadomości z systemem zmiennych (Quill.js), wysyłka maili z zamówień z załącznikami. +Zadania automatyczne: reguły oparte na zdarzeniach (receipt.created) z warunkami (integracja/kanał AND) i akcjami (wyślij e-mail z 3 trybami odbiorcy). Watcher w ReceiptController ewaluujący warunki i wykonujący akcje. | Phase | Name | Plans | Status | |-------|------|-------|--------| -| 13 | DB + Skrzynki pocztowe | 1/1 | Complete ✓ | -| 14 | Szablony wiadomości | 2/2 | Complete ✓ | -| 15 | Wysyłka e-mail z zamówień | 1/1 | Complete ✓ | +| 16 | Zadania automatyczne | 2/2 | Complete ✓ | ## Completed Milestones +
+v0.4 Moduł E-mail — 2026-03-17 (3 phases, 4 plans) + +| Phase | Name | Plans | Completed | +|-------|------|-------|-----------| +| 13 | DB + Skrzynki pocztowe | 1/1 | 2026-03-17 | +| 14 | Szablony wiadomości | 2/2 | 2026-03-17 | +| 15 | Wysyłka e-mail z zamówień | 1/1 | 2026-03-17 | + +Archive: `.paul/milestones/v0.4-ROADMAP.md` + +
+
v0.3 Moduł Paragonów — 2026-03-15 (5 phases, 5 plans) @@ -69,4 +80,4 @@ Archive: `.paul/milestones/v0.1-ROADMAP.md` --- *Roadmap created: 2026-03-12* -*Last updated: 2026-03-16 — phase 14 complete* +*Last updated: 2026-03-18 — v0.5 milestone complete* diff --git a/.paul/STATE.md b/.paul/STATE.md index cdd4ac6..d5a2668 100644 --- a/.paul/STATE.md +++ b/.paul/STATE.md @@ -5,31 +5,30 @@ See: .paul/PROJECT.md (updated 2026-03-12) **Core value:** Sprzedawca może obsługiwać zamówienia ze wszystkich kanałów sprzedaży i nadawać przesyłki bez przełączania się między platformami. -**Current focus:** v0.4 Moduł E-mail — COMPLETE ✓. Następny milestone do zaplanowania. +**Current focus:** v0.5 Moduł Automatyzacji — Phase 16 Planning ## Current Position -Milestone: v0.4 Moduł E-mail — COMPLETE ✓ -Phase: [3] of [3] (Wysyłka e-mail z zamówień) — Complete ✓ -Plan: 15-01 complete -Status: Phase 15 complete, milestone v0.4 complete -Last activity: 2026-03-17 — UNIFY complete, Phase 15 + milestone v0.4 closed +Milestone: v0.5 Moduł Automatyzacji +Phase: [1] of [1] (Zadania automatyczne) — Complete ✓ +Plan: 16-02 complete — Phase 16 complete, milestone v0.5 complete +Status: Phase 16 complete, milestone v0.5 complete +Last activity: 2026-03-18 — UNIFY complete, Phase 16 + milestone v0.5 closed Progress: - v0.1 Initial Release: [██████████] 100% ✓ - v0.2 Pre-Expansion Fixes: [██████████] 100% ✓ - v0.3 Moduł Paragonów: [██████████] 100% ✓ - v0.4 Moduł E-mail: [██████████] 100% ✓ - - Phase 13: [██████████] 100% ✓ - - Phase 14: [██████████] 100% ✓ - - Phase 15: [██████████] 100% ✓ +- v0.5 Moduł Automatyzacji: [██████████] 100% ✓ + - Phase 16: [██████████] 100% ✓ (2/2 plans) ## Loop Position Current loop state: ``` PLAN ──▶ APPLY ──▶ UNIFY - ✓ ✓ ✓ [Loop complete — milestone v0.4 done] + ✓ ✓ ✓ [Loop complete — milestone v0.5 done] ``` ## Accumulated Context @@ -171,16 +170,16 @@ Brak. ## Session Continuity -Last session: 2026-03-17 -Stopped at: Milestone v0.4 complete -Next action: /paul:complete-milestone or /paul:discuss-milestone for v0.5 -Resume file: .paul/phases/15-email-sending/15-01-SUMMARY.md +Last session: 2026-03-18 +Stopped at: Milestone v0.5 complete +Next action: /paul:complete-milestone or /paul:discuss-milestone for v0.6 +Resume file: .paul/phases/16-automated-tasks/16-02-SUMMARY.md Resume context: - v0.1: COMPLETE ✓ (6 phases, 15 plans) - v0.2: COMPLETE ✓ (1 phase, 5 plans) - v0.3: COMPLETE ✓ (5 phases, 5 plans) — Moduł Paragonów - v0.4: COMPLETE ✓ (3 phases, 4 plans) — Moduł E-mail -- Gotowe: skrzynki SMTP, szablony Quill.js, wysyłka z zamówień + załączniki + activity_log +- v0.5: IN PROGRESS — Plan 16-01 (DB + CRUD) created, awaiting approval --- *STATE.md — Updated after every significant action* diff --git a/.paul/phases/16-automated-tasks/16-01-PLAN.md b/.paul/phases/16-automated-tasks/16-01-PLAN.md new file mode 100644 index 0000000..b6877ce --- /dev/null +++ b/.paul/phases/16-automated-tasks/16-01-PLAN.md @@ -0,0 +1,307 @@ +--- +phase: 16-automated-tasks +plan: 01 +type: execute +wave: 1 +depends_on: [] +files_modified: + - database/migrations/20260318_000057_create_automation_tables.sql + - src/Modules/Automation/AutomationController.php + - src/Modules/Automation/AutomationRepository.php + - resources/views/automation/index.php + - resources/views/automation/form.php + - resources/scss/modules/_automation.scss + - public/assets/js/modules/automation-form.js + - src/Core/Application.php +autonomous: false +--- + + +## Goal +Stworzyć moduł "Zadania automatyczne" — tabele DB, backend CRUD i widoki UI do zarządzania regułami automatyzacji (tworzenie, edycja, lista, usuwanie). Reguły składają się z: zdarzenia wyzwalającego, warunków (AND) i akcji do wykonania. + +## Purpose +Użytkownik może definiować reguły automatyzacji, np. "Gdy utworzono paragon dla zamówienia z Allegro → wyślij e-mail z szablonu X do klienta". To fundament pod automatyzację procesów sprzedażowych. + +## Output +- 3 nowe tabele DB: `automation_rules`, `automation_conditions`, `automation_actions` +- Moduł `App\Modules\Automation` z kontrolerem i repozytorium +- Widoki: lista reguł + formularz tworzenia/edycji z dynamicznym dodawaniem warunków i akcji +- Nowa sekcja w menu nawigacji + + + +## Project Context +@.paul/PROJECT.md +@.paul/ROADMAP.md +@.paul/STATE.md + +## Prior Work +@.paul/phases/15-email-sending/15-01-SUMMARY.md — EmailSendingService (reuse w akcji "wyślij e-mail") +@.paul/phases/14-email-templates/14-02-SUMMARY.md — Szablony e-mail (wybór szablonu w akcji) + +## Source Files +@src/Modules/Email/EmailSendingService.php — send(orderId, templateId, ?mailboxId, ?actorName) +@src/Modules/Accounting/ReceiptController.php — trigger point (receipt.created) +@src/Core/Application.php — routing registration +@DOCS/DB_SCHEMA.md — existing schema reference +@DOCS/ARCHITECTURE.md — module patterns + + + +## Required Skills (from SPECIAL-FLOWS.md) + +No SPECIAL-FLOWS.md found — skills section omitted. + + + + +## AC-1: Tabele DB istnieją z poprawnymi relacjami +```gherkin +Given migracja 000057 uruchomiona +When sprawdzam strukturę bazy +Then tabele automation_rules, automation_conditions, automation_actions istnieją + And automation_conditions.rule_id ma FK do automation_rules.id z ON DELETE CASCADE + And automation_actions.rule_id ma FK do automation_rules.id z ON DELETE CASCADE +``` + +## AC-2: Lista reguł automatyzacji +```gherkin +Given istnieją reguły automatyzacji w DB +When użytkownik wchodzi na stronę Ustawienia > Zadania automatyczne +Then widzi listę reguł z kolumnami: nazwa, zdarzenie, status, akcje (edytuj/usuń) + And może przełączać status (aktywna/nieaktywna) przyciskiem toggle +``` + +## AC-3: Tworzenie reguły z warunkami i akcjami +```gherkin +Given użytkownik jest na formularzu tworzenia reguły +When wypełnia nazwę, wybiera zdarzenie "Utworzono paragon" + And dodaje warunek "Integracja" z wybranym kanałem sprzedaży + And dodaje akcję "Wyślij e-mail" z wybranym szablonem i odbiorcą + And zapisuje formularz +Then reguła zostaje zapisana w DB z powiązanymi warunkami i akcjami + And użytkownik wraca na listę z komunikatem sukcesu +``` + +## AC-4: Edycja i usuwanie reguły +```gherkin +Given istnieje reguła automatyzacji +When użytkownik edytuje regułę (zmienia warunki/akcje) i zapisuje +Then zmiany są zapisane w DB (stare warunki/akcje usunięte, nowe wstawione) +When użytkownik klika usuń i potwierdza +Then reguła i powiązane warunki/akcje są usunięte z DB +``` + +## AC-5: Dynamiczny formularz — warunki i akcje +```gherkin +Given użytkownik jest na formularzu reguły +When klika "Dodaj warunek" +Then pojawia się nowy wiersz z wyborem typu warunku i wartości +When klika "Dodaj akcję" +Then pojawia się nowy wiersz z wyborem typu akcji i konfiguracji +When klika X przy warunku/akcji +Then wiersz jest usuwany z formularza +``` + + + + + + + Task 1: Migracja DB — tabele automation + database/migrations/20260318_000057_create_automation_tables.sql, DOCS/DB_SCHEMA.md + + Utworzyć migrację z 3 tabelami: + + **automation_rules:** + - `id` int unsigned PK AI + - `name` varchar(128) NOT NULL + - `event_type` varchar(64) NOT NULL (na razie: 'receipt.created') + - `is_active` tinyint(1) NOT NULL DEFAULT 1 + - `created_at` datetime DEFAULT CURRENT_TIMESTAMP + - `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + + **automation_conditions:** + - `id` int unsigned PK AI + - `rule_id` int unsigned NOT NULL, FK → automation_rules.id ON DELETE CASCADE + - `condition_type` varchar(64) NOT NULL (na razie: 'integration') + - `condition_value` json NOT NULL (np. {"integration_ids": [1, 3]}) + - `sort_order` smallint unsigned NOT NULL DEFAULT 0 + - Indeks: `auto_cond_rule_idx` (rule_id) + + **automation_actions:** + - `id` int unsigned PK AI + - `rule_id` int unsigned NOT NULL, FK → automation_rules.id ON DELETE CASCADE + - `action_type` varchar(64) NOT NULL (na razie: 'send_email') + - `action_config` json NOT NULL (np. {"template_id": 5, "recipient": "client"}) + - `sort_order` smallint unsigned NOT NULL DEFAULT 0 + - Indeks: `auto_act_rule_idx` (rule_id) + + Zaktualizować DOCS/DB_SCHEMA.md o nowe tabele. + Używać InnoDB, utf8mb4_unicode_ci — jak istniejące tabele. + + Migracja wykonuje się bez błędów na lokalnej bazie. Tabele istnieją z poprawnymi FK. + AC-1 satisfied: 3 tabele istnieją z poprawnymi relacjami i indeksami + + + + Task 2: Backend CRUD — AutomationController + AutomationRepository + + src/Modules/Automation/AutomationController.php, + src/Modules/Automation/AutomationRepository.php, + src/Core/Application.php, + DOCS/ARCHITECTURE.md + + + **AutomationRepository:** + - `findAll(): array` — lista reguł z count warunków/akcji + - `findById(int $id): ?array` — reguła + warunki + akcje (eager load) + - `create(array $data, array $conditions, array $actions): int` — INSERT rule + conditions + actions w jednej transakcji + - `update(int $id, array $data, array $conditions, array $actions): bool` — UPDATE rule, DELETE old conditions/actions, INSERT new (transakcja) + - `delete(int $id): bool` — DELETE rule (CASCADE usunie warunki/akcje) + - `toggleActive(int $id): bool` — przełącz is_active + - `findActiveByEvent(string $eventType): array` — pobierz aktywne reguły dla danego zdarzenia (z warunkami i akcjami) — potrzebne w planie 16-02 + + **AutomationController:** + - `index()` — lista reguł + - `create()` — formularz nowej reguły + - `store(Request)` — walidacja + zapis, Flash sukces, redirect do index + - `edit(Request)` — formularz edycji (load istniejącej reguły) + - `update(Request)` — walidacja + update, Flash sukces, redirect + - `destroy(Request)` — usunięcie z potwierdzeniem CSRF + - `toggleStatus(Request)` — AJAX toggle is_active + + Walidacja w store/update: + - Nazwa wymagana (1-128 znaków) + - Event type wymagany (whitelist: ['receipt.created']) + - Min 1 warunek, min 1 akcja + - Walidacja typów warunków i akcji (whitelist) + - CSRF + + Dane do formularza (getFormData helper): + - Lista integracji z `integrations` (id, type, name) WHERE type IN ('allegro', 'shoppro') AND is_active = 1 + - Lista szablonów e-mail z `email_templates` (id, name) + + Routing w Application.php: + - GET /settings/automation → index + - GET /settings/automation/create → create + - POST /settings/automation/store → store + - GET /settings/automation/edit/{id} → edit + - POST /settings/automation/update/{id} → update + - POST /settings/automation/delete/{id} → destroy + - POST /settings/automation/toggle/{id} → toggleStatus (AJAX) + + Zaktualizować DOCS/ARCHITECTURE.md o nowy moduł. + + Routing działa — GET /settings/automation zwraca stronę listy. POST store tworzy regułę w DB. + AC-2, AC-3, AC-4 satisfied: CRUD działa end-to-end + + + + Task 3: Widoki UI — lista + formularz z dynamicznymi warunkami/akcjami + + resources/views/automation/index.php, + resources/views/automation/form.php, + resources/scss/modules/_automation.scss, + public/assets/js/modules/automation-form.js + + + **index.php — lista reguł:** + - Tabela: nazwa, zdarzenie (label), liczba warunków, liczba akcji, status (toggle switch), akcje (edytuj/usuń) + - Toggle switch zmienia status via AJAX POST /settings/automation/toggle/{id} + - Przycisk "Dodaj zadanie automatyczne" → /settings/automation/create + - Usuwanie przez OrderProAlerts.confirm() + POST + - Layout spójny z innymi listami w Ustawienia (email_mailboxes, email_templates, receipt_configs) + + **form.php — formularz tworzenia/edycji:** + - Pola: nazwa (input text), zdarzenie (select — na razie 1 opcja "Utworzono paragon") + - Sekcja "Warunki" z przyciskiem "Dodaj warunek": + - Typ warunku: select (na razie "Integracja / kanał sprzedaży") + - Wartość: multi-select z listą aktywnych integracji allegro/shoppro (checkbox dropdown lub multi-select) + - Przycisk X do usunięcia warunku + - Sekcja "Akcje" z przyciskiem "Dodaj akcję": + - Typ akcji: select (na razie "Wyślij e-mail") + - Konfiguracja "Wyślij e-mail": + - Szablon: select z listy email_templates + - Wyślij do: select z opcjami: "Klient", "Klient + e-mail z danych firmy", "E-mail z danych firmy" + - Przycisk X do usunięcia akcji + - Przyciski: Zapisz / Anuluj + - Formularz POST z CSRF (_token) + + **automation-form.js:** + - Dodawanie/usuwanie wierszy warunków (template clone) + - Dodawanie/usuwanie wierszy akcji (template clone) + - Nazewnictwo pól: conditions[0][type], conditions[0][value], actions[0][type], actions[0][config][template_id], actions[0][config][recipient] + - Numeracja indeksów po dodaniu/usunięciu + + **_automation.scss:** + - Style dla formularza dynamicznego (warunki/akcje bloki) + - Kompaktowy layout (jak reszta aplikacji) + - Importować w głównym pliku SCSS + + Nie używać natywnych alert()/confirm() — tylko OrderProAlerts. + Nie pisać CSS w widokach — tylko SCSS. + + Formularz pozwala dodawać/usuwać warunki i akcje dynamicznie. Zapis tworzy regułę z warunkami i akcjami w DB. + AC-2, AC-3, AC-4, AC-5 satisfied: UI lista + formularz dynamiczny działają + + + + Moduł Zadania automatyczne — CRUD z dynamicznym formularzem warunków i akcji + + 1. Uruchom migrację 000057 na lokalnej bazie + 2. Wejdź na /settings/automation — powinna być pusta lista + 3. Kliknij "Dodaj zadanie automatyczne" + 4. Wypełnij nazwę, wybierz zdarzenie "Utworzono paragon" + 5. Dodaj warunek "Integracja" → wybierz kanały sprzedaży + 6. Dodaj akcję "Wyślij e-mail" → wybierz szablon i odbiorcę + 7. Zapisz — powinna pojawić się na liście + 8. Edytuj regułę — warunki i akcje powinny się załadować + 9. Przełącz status toggle — powinien się zmienić + 10. Usuń regułę — potwierdzenie + usunięcie + + Type "approved" to continue to plan 16-02 (watcher/executor), or describe issues to fix + + + + + + +## DO NOT CHANGE +- src/Modules/Email/* (reuse, nie modyfikuj) +- src/Modules/Accounting/* (trigger point będzie w planie 16-02) +- database/migrations/000001-000056 (istniejące migracje) +- src/Modules/Cron/* (integracja w planie 16-02) + +## SCOPE LIMITS +- Ten plan to tylko CRUD (zarządzanie regułami) — BEZ wykonywania reguł +- Watcher/executor będzie w planie 16-02 +- Nie dodawać nowych typów zdarzeń/warunków/akcji poza zdefiniowanymi +- Nie modyfikować ReceiptController (trigger w planie 16-02) + + + + +Before declaring plan complete: +- [ ] Migracja 000057 wykonuje się bez błędów +- [ ] GET /settings/automation wyświetla listę reguł +- [ ] Tworzenie reguły z warunkami i akcjami zapisuje do DB poprawnie +- [ ] Edycja ładuje istniejące warunki/akcje i zapisuje zmiany +- [ ] Usunięcie reguły usuwa kaskadowo warunki i akcje +- [ ] Toggle status zmienia is_active via AJAX +- [ ] Formularz dynamicznie dodaje/usuwa warunki i akcje +- [ ] CSRF walidacja działa +- [ ] DOCS/DB_SCHEMA.md i DOCS/ARCHITECTURE.md zaktualizowane + + + +- Wszystkie taski ukończone +- Wszystkie verification checks przechodzą +- Brak błędów PHP / JS w konsoli +- UI spójne z resztą aplikacji (Ustawienia) + + + +After completion, create `.paul/phases/16-automated-tasks/16-01-SUMMARY.md` + diff --git a/.paul/phases/16-automated-tasks/16-01-SUMMARY.md b/.paul/phases/16-automated-tasks/16-01-SUMMARY.md new file mode 100644 index 0000000..6397626 --- /dev/null +++ b/.paul/phases/16-automated-tasks/16-01-SUMMARY.md @@ -0,0 +1,135 @@ +--- +phase: 16-automated-tasks +plan: 01 +subsystem: automation +tags: [automation, rules, crud, json-conditions, json-actions] + +requires: + - phase: 14-email-templates + provides: email_templates table (reuse w akcji send_email) + - phase: 13-email-mailboxes + provides: email_mailboxes table (reuse w EmailSendingService) +provides: + - automation_rules / automation_conditions / automation_actions DB tables + - AutomationController CRUD (7 routes) + - AutomationRepository with findActiveByEvent() for watcher + - Dynamic form UI (conditions + actions JS) +affects: [16-02-watcher-executor] + +tech-stack: + added: [] + patterns: [dynamic-form-rows-js, json-conditions-actions, rule-engine-schema] + +key-files: + created: + - database/migrations/20260318_000057_create_automation_tables.sql + - src/Modules/Automation/AutomationController.php + - src/Modules/Automation/AutomationRepository.php + - resources/views/automation/index.php + - resources/views/automation/form.php + - resources/scss/modules/_automation.scss + - public/assets/js/modules/automation-form.js + modified: + - routes/web.php + - resources/views/layouts/app.php + - resources/scss/app.scss + - public/assets/css/app.css + - DOCS/DB_SCHEMA.md + - DOCS/ARCHITECTURE.md + - DOCS/TECH_CHANGELOG.md + +key-decisions: + - "JSON columns for condition_value/action_config: extensible without schema changes" + - "Whitelist validation for event/condition/action types in controller constants" + - "Transactional create/update: rule + conditions + actions atomically" + +patterns-established: + - "Dynamic form rows pattern: JS template clone with index management" + - "Rule engine schema: rules → conditions (AND) → actions pattern" + +duration: ~30min +completed: 2026-03-18 +--- + +# Phase 16 Plan 01: Automation Rules DB + CRUD Summary + +**CRUD modulu zadania automatyczne: 3 tabele DB, kontroler z 7 route'ami, dynamiczny formularz z warunkami/akcjami.** + +## Performance + +| Metric | Value | +|--------|-------| +| Duration | ~30min | +| Completed | 2026-03-18 | +| Tasks | 4 completed (3 auto + 1 checkpoint) | +| Files created | 7 | +| Files modified | 6 | + +## Acceptance Criteria Results + +| Criterion | Status | Notes | +|-----------|--------|-------| +| AC-1: Tabele DB z relacjami | Pass | 3 tabele z FK CASCADE, indeksy | +| AC-2: Lista regul | Pass | Tabela z nazwa, zdarzenie, status, toggle, edytuj/usun | +| AC-3: Tworzenie reguly | Pass | Formularz z warunkami + akcjami, zapis transakcyjny | +| AC-4: Edycja i usuwanie | Pass | Edit laduje dane, delete z CASCADE | +| AC-5: Dynamiczny formularz | Pass | JS dodaje/usuwa wiersze warunkow i akcji | + +## Accomplishments + +- 3 tabele DB z JSON columns dla elastycznej konfiguracji warunkow/akcji +- Pelny CRUD z transakcyjnym zapisem (rule + conditions + actions atomowo) +- Dynamiczny formularz JS z template pattern — dodawanie/usuwanie wierszy bez przeladowania +- `findActiveByEvent()` gotowy do uzycia przez watcher w planie 16-02 + +## Files Created/Modified + +| File | Change | Purpose | +|------|--------|---------| +| `database/migrations/20260318_000057_create_automation_tables.sql` | Created | 3 tabele automation | +| `src/Modules/Automation/AutomationController.php` | Created | CRUD + walidacja + whitelist | +| `src/Modules/Automation/AutomationRepository.php` | Created | DB operations + findActiveByEvent | +| `resources/views/automation/index.php` | Created | Lista regul z toggle/edit/delete | +| `resources/views/automation/form.php` | Created | Formularz dynamiczny | +| `resources/scss/modules/_automation.scss` | Created | Style formularza | +| `public/assets/js/modules/automation-form.js` | Created | Logika dodawania/usuwania wierszy | +| `routes/web.php` | Modified | 7 nowych route'ow + DI | +| `resources/views/layouts/app.php` | Modified | Menu link "Zadania automatyczne" | +| `resources/scss/app.scss` | Modified | Import _automation.scss | +| `public/assets/css/app.css` | Modified | Rebuilt | +| `DOCS/DB_SCHEMA.md` | Modified | Dokumentacja 3 nowych tabel | +| `DOCS/ARCHITECTURE.md` | Modified | Nowy modul + route'y + klasy | +| `DOCS/TECH_CHANGELOG.md` | Modified | Wpis Phase 16 Plan 01 | + +## Decisions Made + +| Decision | Rationale | Impact | +|----------|-----------|--------| +| JSON columns dla condition_value/action_config | Nowe typy warunkow/akcji bez migracji DB | Rozszerzalnosc modulu | +| Whitelist w controller constants | Bezpieczenstwo — tylko dozwolone typy | Nowy typ = 1 linia w ALLOWED_ array | +| Transakcyjny create/update | Atomowosc — brak czesciowych zapisow | Spójnosc danych | + +## Deviations from Plan + +None — plan executed exactly as written. + +## Issues Encountered + +None. + +## Next Phase Readiness + +**Ready:** +- `AutomationRepository::findActiveByEvent('receipt.created')` gotowe do uzycia +- Schema DB gotowa — watcher moze odczytywac reguly +- CRUD dzialajacy — uzytkownik moze definiowac reguly + +**Concerns:** +- Brak + +**Blockers:** +- None — gotowe do planu 16-02 (Watcher/Executor) + +--- +*Phase: 16-automated-tasks, Plan: 01* +*Completed: 2026-03-18* diff --git a/.paul/phases/16-automated-tasks/16-02-PLAN.md b/.paul/phases/16-automated-tasks/16-02-PLAN.md new file mode 100644 index 0000000..623582e --- /dev/null +++ b/.paul/phases/16-automated-tasks/16-02-PLAN.md @@ -0,0 +1,235 @@ +--- +phase: 16-automated-tasks +plan: 02 +type: execute +wave: 2 +depends_on: ["16-01"] +files_modified: + - src/Modules/Automation/AutomationService.php + - src/Modules/Accounting/ReceiptController.php + - src/Modules/Email/EmailSendingService.php + - routes/web.php + - DOCS/ARCHITECTURE.md + - DOCS/TECH_CHANGELOG.md +autonomous: false +--- + + +## Goal +Zaimplementowac watcher/executor regul automatyzacji: po utworzeniu paragonu system sprawdza aktywne reguly, ewaluuje warunki (integracja zamowienia) i wykonuje akcje (wyslij e-mail do odpowiedniego odbiorcy). + +## Purpose +Reguly automatyzacji zdefiniowane w planie 16-01 zaczynaja dzialac — system automatycznie reaguje na zdarzenia (receipt.created) i wykonuje skonfigurowane akcje bez interwencji uzytkownika. + +## Output +- `AutomationService` — ewaluacja warunkow + wykonanie akcji +- Trigger w `ReceiptController::store()` po utworzeniu paragonu +- Rozszerzenie `EmailSendingService::send()` o opcjonalnego odbiorce (company email) + + + +## Project Context +@.paul/PROJECT.md +@.paul/ROADMAP.md +@.paul/STATE.md + +## Prior Work +@.paul/phases/16-automated-tasks/16-01-SUMMARY.md — AutomationRepository z findActiveByEvent() + +## Source Files +@src/Modules/Automation/AutomationRepository.php — findActiveByEvent('receipt.created') zwraca reguly z warunkami i akcjami +@src/Modules/Accounting/ReceiptController.php — store() metoda, trigger point po linii 189 (recordActivity) +@src/Modules/Email/EmailSendingService.php — send(orderId, templateId, ?mailboxId, ?actorName) + findRecipientEmail() +@routes/web.php — DI wiring, ReceiptController instantiation (linia 223-231) + + + +No SPECIAL-FLOWS.md — skills section omitted. + + + + +## AC-1: AutomationService ewaluuje warunki poprawnie +```gherkin +Given aktywna regula z warunkiem integration_ids: [1, 3] dla zdarzenia receipt.created +When utworzono paragon dla zamowienia z integration_id = 1 +Then regula jest dopasowana i akcje sa wykonywane +When utworzono paragon dla zamowienia z integration_id = 5 +Then regula NIE jest dopasowana i akcje NIE sa wykonywane +``` + +## AC-2: Akcja send_email wywoluje EmailSendingService +```gherkin +Given aktywna regula z akcja send_email (template_id: 5, recipient: "client") +When regula jest dopasowana po utworzeniu paragonu +Then EmailSendingService::send() jest wywolane z orderId i templateId + And wynik jest logowany w order_activity_log jako 'automation_email_sent' lub 'automation_email_failed' +``` + +## AC-3: Odbiorca e-mail respektuje konfiguracje +```gherkin +Given akcja send_email z recipient: "client" +Then e-mail wysylany do adresu kupujacego (domyslne zachowanie) +Given akcja send_email z recipient: "company" +Then e-mail wysylany na adres z company_settings.email +Given akcja send_email z recipient: "client_and_company" +Then e-mail wysylany do kupujacego ORAZ na adres firmy (2 wywolania send) +``` + +## AC-4: Trigger w ReceiptController dziala +```gherkin +Given ReceiptController::store() tworzy paragon pomyslnie +When metoda store() konczy zapis +Then AutomationService::trigger('receipt.created', orderId) jest wywolane + And blad w automatyzacji NIE blokuje sukcesu tworzenia paragonu (try/catch) +``` + +## AC-5: Logowanie automatyzacji +```gherkin +Given regula automatyzacji zostala wykonana +When akcja send_email sie powiodla +Then wpis w order_activity_log: activity_type='automation_email_sent', actor_type='system', actor_name='Automatyzacja: [nazwa reguly]' +When akcja send_email sie nie powiodla +Then wpis w order_activity_log: activity_type='automation_email_failed' z informacja o bledzie +``` + + + + + + + Task 1: AutomationService — ewaluacja warunkow i wykonanie akcji + + src/Modules/Automation/AutomationService.php, + src/Modules/Email/EmailSendingService.php + + + **AutomationService:** + - Konstruktor: AutomationRepository, EmailSendingService, OrdersRepository, CompanySettingsRepository + - `trigger(string $eventType, int $orderId): void` + - Pobiera aktywne reguly: `$this->repository->findActiveByEvent($eventType)` + - Dla kazdej reguly: sprawdza warunki -> jesli spelnione -> wykonuje akcje + - Calosc w try/catch — blad jednej reguly nie blokuje kolejnych + - `evaluateConditions(array $conditions, array $orderDetails): bool` + - Iteruje po warunkach (AND logic — wszystkie musza byc spelnione) + - Typ 'integration': sprawdza czy `$order['integration_id']` jest w `condition_value['integration_ids']` + - Zwraca true jesli wszystkie warunki spelnione + - `executeActions(array $actions, int $orderId, string $ruleName): void` + - Iteruje po akcjach + - Typ 'send_email': wywoluje handleSendEmail() + - `handleSendEmail(array $config, int $orderId, string $ruleName): void` + - templateId z config['template_id'] + - recipient z config['recipient'] + - Jesli 'client': `$this->emailService->send($orderId, $templateId, null, 'Automatyzacja: ' . $ruleName)` + - Jesli 'company': pobranie company email z CompanySettingsRepository, wywolanie send z recipientEmailOverride + - Jesli 'client_and_company': oba wywolania + - Logowanie wyniku (activity_type: automation_email_sent / automation_email_failed) + + **EmailSendingService — rozszerzenie:** + - Dodac opcjonalny parametr `?string $recipientEmailOverride = null` do metody `send()` + - Jesli podany: uzyc go zamiast findRecipientEmail($addresses) + - Zachowac pelna kompatybilnosc wsteczna (istniejace wywolania bez zmian) + - Dodac opcjonalny parametr `?string $recipientNameOverride = null` (dla "company" — nazwa firmy) + + Unikac: Modyfikacji sygnatury w sposob lamiaacy istniejace wywolania. + Unikac: Nadmiernego logowania — jeden wpis activity per akcja, nie per proba. + + PHP lint: php -l src/Modules/Automation/AutomationService.php && php -l src/Modules/Email/EmailSendingService.php + AC-1, AC-2, AC-3, AC-5 satisfied: AutomationService ewaluuje warunki i wykonuje akcje z poprawnym odbiorca + + + + Task 2: Integracja triggera w ReceiptController + DI wiring + + src/Modules/Accounting/ReceiptController.php, + routes/web.php, + DOCS/ARCHITECTURE.md, + DOCS/TECH_CHANGELOG.md + + + **ReceiptController:** + - Dodac AutomationService jako dependency w konstruktorze (8. parametr) + - W store(), po `$this->orders->recordActivity(...)` (linia ~189), dodac: + ```php + try { + $this->automation->trigger('receipt.created', $orderId); + } catch (Throwable) { + // Blad automatyzacji nie blokuje sukcesu paragonu + } + ``` + - Trigger MUSI byc w bloku try/catch — paragon jest juz zapisany, blad automatyzacji to problem poboczny + + **routes/web.php:** + - Dodac AutomationService do importow (use App\Modules\Automation\AutomationService) + - Utworzyc instancje AutomationService z wymaganymi zaleznosciami + - Przekazac do ReceiptController jako 8. argument + - Uwaga: CompanySettingsRepository ($companySettingsRepository) juz istnieje w web.php + + **DOCS/ARCHITECTURE.md:** + - Zaktualizowac opis modulu Automation o AutomationService + - Dodac opis flow: receipt.created -> AutomationService -> EmailSendingService + + **DOCS/TECH_CHANGELOG.md:** + - Dodac wpis o Phase 16 Plan 02 + + PHP lint: php -l src/Modules/Accounting/ReceiptController.php && php -l routes/web.php + AC-4 satisfied: Trigger w ReceiptController dziala, blad automatyzacji nie blokuje paragonu + + + + Watcher/executor regul automatyzacji — pelny flow od utworzenia paragonu do wyslania e-maila + + 1. Upewnij sie ze istnieje co najmniej 1 aktywna regula automatyzacji (z planu 16-01) + - Zdarzenie: Utworzono paragon + - Warunek: Integracja z wybranym kanalem + - Akcja: Wyslij e-mail z wybranym szablonem, odbiorca: Klient + 2. Wejdz na zamowienie z pasujacego kanalu sprzedazy + 3. Wystaw paragon (Orders > zamowienie > Wystaw paragon) + 4. Sprawdz activity log zamowienia — powinny byc wpisy: + - "Wystawiono paragon: PAR/..." (istniejacy) + - "Automatyzacja: [nazwa reguly] — wyslano e-mail..." (nowy, actor: system) + 5. Opcjonalnie: sprawdz email_logs — nowy wpis z template_id z reguly + 6. Test negatywny: wystaw paragon dla zamowienia z INNEGO kanalu (nie pasujacego do warunku) — brak wpisu automatyzacji + + Type "approved" to continue to UNIFY, or describe issues to fix + + + + + + +## DO NOT CHANGE +- src/Modules/Automation/AutomationController.php (CRUD z planu 16-01) +- src/Modules/Automation/AutomationRepository.php (DB layer z planu 16-01) +- database/migrations/* (brak nowych migracji w tym planie) +- resources/views/automation/* (widoki z planu 16-01) + +## SCOPE LIMITS +- Tylko zdarzenie receipt.created — brak nowych typow zdarzen +- Tylko warunek integration — brak nowych typow warunkow +- Tylko akcja send_email — brak nowych typow akcji +- Bez kolejkowania/crona — synchroniczne wykonanie przy triggerze +- Bez retry — jesli akcja sie nie powiedzie, logujemy blad i idziemy dalej + + + + +Before declaring plan complete: +- [ ] PHP lint przechodzi dla wszystkich zmienionych plikow +- [ ] AutomationService::trigger() nie rzuca wyjatkow na zewnatrz +- [ ] EmailSendingService::send() zachowuje kompatybilnosc wsteczna +- [ ] ReceiptController::store() tworzy paragon niezaleznie od wyniku automatyzacji +- [ ] Activity log zawiera wpisy automation_email_sent/failed z actor_type='system' +- [ ] DOCS/ARCHITECTURE.md i TECH_CHANGELOG.md zaktualizowane + + + +- Wszystkie taski ukonczone +- Wszystkie verification checks przechodza +- Pelny flow: paragon -> trigger -> ewaluacja -> wyslanie e-maila +- Brak regresji w istniejacym CRUD i wysylce e-mail + + + +After completion, create `.paul/phases/16-automated-tasks/16-02-SUMMARY.md` + diff --git a/.paul/phases/16-automated-tasks/16-02-SUMMARY.md b/.paul/phases/16-automated-tasks/16-02-SUMMARY.md new file mode 100644 index 0000000..b1cbb0c --- /dev/null +++ b/.paul/phases/16-automated-tasks/16-02-SUMMARY.md @@ -0,0 +1,107 @@ +--- +phase: 16-automated-tasks +plan: 02 +subsystem: automation +tags: [automation, watcher, executor, trigger, email-sending] + +requires: + - phase: 16-automated-tasks + provides: automation_rules/conditions/actions DB + AutomationRepository +provides: + - AutomationService (trigger + condition evaluation + action execution) + - ReceiptController trigger integration + - EmailSendingService recipient override support +affects: [] + +tech-stack: + added: [] + patterns: [event-trigger-pattern, condition-evaluator, action-executor] + +key-files: + created: + - src/Modules/Automation/AutomationService.php + modified: + - src/Modules/Accounting/ReceiptController.php + - src/Modules/Email/EmailSendingService.php + - routes/web.php + - DOCS/ARCHITECTURE.md + - DOCS/TECH_CHANGELOG.md + +key-decisions: + - "Synchronous trigger (not queued) — simplicity over performance" + - "recipientEmailOverride as optional params — backward compatible" + - "try/catch around trigger — automation failure never blocks receipt" + +patterns-established: + - "Event trigger pattern: Controller -> AutomationService::trigger(eventType, entityId)" + - "Condition evaluator: AND logic with type-specific evaluation methods" + +duration: ~15min +completed: 2026-03-18 +--- + +# Phase 16 Plan 02: Automation Watcher/Executor Summary + +**AutomationService: trigger receipt.created -> ewaluacja warunkow (integration) -> wykonanie akcji (send_email z 3 trybami odbiorcy).** + +## Performance + +| Metric | Value | +|--------|-------| +| Duration | ~15min | +| Completed | 2026-03-18 | +| Tasks | 3 completed (2 auto + 1 checkpoint) | +| Files created | 1 | +| Files modified | 5 | + +## Acceptance Criteria Results + +| Criterion | Status | Notes | +|-----------|--------|-------| +| AC-1: Ewaluacja warunkow | Pass | AND logic, integration_id check | +| AC-2: Akcja send_email | Pass | EmailSendingService::send() z actorName | +| AC-3: Odbiorca respektuje config | Pass | client/company/client_and_company | +| AC-4: Trigger w ReceiptController | Pass | try/catch, nie blokuje paragonu | +| AC-5: Logowanie automatyzacji | Pass | activity_type automation_email_* | + +## Accomplishments + +- AutomationService z pelnym flow: trigger -> evaluate -> execute +- Bezpieczna integracja w ReceiptController (try/catch) +- EmailSendingService rozszerzony o recipient override (backward compatible) +- 3 tryby odbiorcy e-mail: client, company, client_and_company + +## Files Created/Modified + +| File | Change | Purpose | +|------|--------|---------| +| `src/Modules/Automation/AutomationService.php` | Created | Watcher/executor | +| `src/Modules/Accounting/ReceiptController.php` | Modified | Trigger po zapisie paragonu | +| `src/Modules/Email/EmailSendingService.php` | Modified | recipientEmailOverride params | +| `routes/web.php` | Modified | DI wiring AutomationService | +| `DOCS/ARCHITECTURE.md` | Modified | Opis AutomationService + flow | +| `DOCS/TECH_CHANGELOG.md` | Modified | Wpis Phase 16 Plan 02 | + +## Deviations from Plan + +None — plan executed exactly as written. + +## Issues Encountered + +None. + +## Next Phase Readiness + +**Ready:** +- Phase 16 complete — pelny modul automatyzacji (CRUD + watcher/executor) +- Rozszerzalny: nowe typy zdarzen/warunkow/akcji = dodanie do whitelists + evaluator/handler + +**Concerns:** +- Brak + +**Blockers:** +- None + +--- +*Phase: 16-automated-tasks, Plan: 02* +*Completed: 2026-03-18* diff --git a/DOCS/ARCHITECTURE.md b/DOCS/ARCHITECTURE.md index e6d0be2..cc3ac61 100644 --- a/DOCS/ARCHITECTURE.md +++ b/DOCS/ARCHITECTURE.md @@ -13,6 +13,7 @@ - `App\Modules\Settings\EmailMailbox*` (skrzynki pocztowe SMTP — CRUD + test polaczenia) - `App\Modules\Settings\EmailTemplate*` (szablony e-mail — CRUD + Quill.js + zmienne + zalaczniki) - `App\Modules\Email` (wysylka e-mail z zamowien — EmailSendingService, VariableResolver, AttachmentGenerator) +- `App\Modules\Automation` (zadania automatyczne — reguly zdarzenie/warunki/akcje, CRUD) ## Routing - `GET /login`, `POST /login`, `POST /logout` @@ -71,6 +72,13 @@ - `POST /settings/email-mailboxes/delete` - `POST /settings/email-mailboxes/toggle` - `POST /settings/email-mailboxes/test` +- `GET /settings/automation` +- `GET /settings/automation/create` +- `POST /settings/automation/store` +- `GET /settings/automation/edit` +- `POST /settings/automation/update` +- `POST /settings/automation/delete` +- `POST /settings/automation/toggle` - `GET /health` - `GET /` (redirect) @@ -135,6 +143,9 @@ - `App\Modules\Accounting\ReceiptRepository` (findById, findByOrderId, create, getNextNumber, paginate, exportData) - `App\Modules\Accounting\ReceiptController` (create, store, show, printView, pdf) - `App\Modules\Accounting\AccountingController` (index — lista paragonow, export — XLSX) +- `App\Modules\Automation\AutomationController` (index, create, store, edit, update, destroy, toggleStatus) +- `App\Modules\Automation\AutomationRepository` (findAll, findById, create, update, delete, toggleActive, findActiveByEvent) +- `App\Modules\Automation\AutomationService` (trigger, evaluateConditions, executeActions — watcher/executor regul automatyzacji; flow: ReceiptController::store() -> trigger('receipt.created') -> ewaluacja warunkow -> EmailSendingService::send()) - `App\Modules\Shipments\ShipmentProviderInterface` - `App\Modules\Shipments\ShipmentProviderRegistry` - `App\Modules\Shipments\ApaczkaShipmentService` diff --git a/DOCS/DB_SCHEMA.md b/DOCS/DB_SCHEMA.md index c974815..c20ae80 100644 --- a/DOCS/DB_SCHEMA.md +++ b/DOCS/DB_SCHEMA.md @@ -436,6 +436,43 @@ Migracje z prefiksem `ensure_` to migracje kompensujące — zostały dodane - `created_at` DATETIME - Indeksy: `idx_email_logs_template`, `idx_email_logs_mailbox`, `idx_email_logs_order`, `idx_email_logs_status`, `idx_email_logs_sent_at` +### `automation_rules` +- Reguly automatyzacji (zdarzenie -> warunki -> akcje). +- Kolumny: + - `id` INT UNSIGNED PK AUTO_INCREMENT + - `name` VARCHAR(128) NOT NULL — nazwa reguly + - `event_type` VARCHAR(64) NOT NULL — typ zdarzenia (np. 'receipt.created') + - `is_active` TINYINT(1) NOT NULL DEFAULT 1 + - `created_at`, `updated_at` DATETIME +- Indeksy: + - `auto_rules_event_active_idx` (`event_type`, `is_active`) + +### `automation_conditions` +- Warunki reguly automatyzacji (laczenie logiczne AND). +- Kolumny: + - `id` INT UNSIGNED PK AUTO_INCREMENT + - `rule_id` INT UNSIGNED NOT NULL, FK -> `automation_rules.id` ON DELETE CASCADE + - `condition_type` VARCHAR(64) NOT NULL — typ warunku (np. 'integration') + - `condition_value` JSON NOT NULL — konfiguracja warunku (np. {"integration_ids": [1, 3]}) + - `sort_order` SMALLINT UNSIGNED NOT NULL DEFAULT 0 +- Indeksy: + - `auto_cond_rule_idx` (`rule_id`) +- Klucze obce: + - `auto_cond_rule_fk`: `rule_id` -> `automation_rules.id` (ON DELETE CASCADE) + +### `automation_actions` +- Akcje do wykonania po spelnieniu warunkow reguly. +- Kolumny: + - `id` INT UNSIGNED PK AUTO_INCREMENT + - `rule_id` INT UNSIGNED NOT NULL, FK -> `automation_rules.id` ON DELETE CASCADE + - `action_type` VARCHAR(64) NOT NULL — typ akcji (np. 'send_email') + - `action_config` JSON NOT NULL — konfiguracja akcji (np. {"template_id": 5, "recipient": "client"}) + - `sort_order` SMALLINT UNSIGNED NOT NULL DEFAULT 0 +- Indeksy: + - `auto_act_rule_idx` (`rule_id`) +- Klucze obce: + - `auto_act_rule_fk`: `rule_id` -> `automation_rules.id` (ON DELETE CASCADE) + ## Zasady aktualizacji - Po kazdej migracji dopisz: - nowe/zmienione tabele i kolumny, diff --git a/DOCS/TECH_CHANGELOG.md b/DOCS/TECH_CHANGELOG.md index eb2bf81..764cd2f 100644 --- a/DOCS/TECH_CHANGELOG.md +++ b/DOCS/TECH_CHANGELOG.md @@ -1,5 +1,24 @@ # Tech Changelog +## 2026-03-18 (Phase 16 — Zadania automatyczne, Plan 02: Watcher/Executor) +- Nowa klasa `App\Modules\Automation\AutomationService` — trigger + ewaluacja warunkow (AND) + wykonanie akcji. +- Flow: `ReceiptController::store()` -> `AutomationService::trigger('receipt.created', orderId)` -> sprawdzenie warunkow (integration_id) -> `EmailSendingService::send()`. +- Rozszerzenie `EmailSendingService::send()` o opcjonalne parametry `$recipientEmailOverride` i `$recipientNameOverride` (kompatybilnosc wsteczna). +- 3 tryby odbiorcy: 'client' (kupujacy), 'company' (e-mail firmy z company_settings), 'client_and_company' (oba). +- Trigger w try/catch — blad automatyzacji nie blokuje sukcesu tworzenia paragonu. +- Activity log: automation_email_sent / automation_email_failed z actor_type='system'. + +## 2026-03-18 (Phase 16 — Zadania automatyczne, Plan 01: DB + CRUD) +- Nowe tabele: `automation_rules`, `automation_conditions`, `automation_actions` (migracja 000057). +- Nowy modul `App\Modules\Automation` z 2 klasami: + - `AutomationController` — CRUD regul automatyzacji (index, create, store, edit, update, destroy, toggleStatus). + - `AutomationRepository` — operacje DB z transakcjami (create/update atomowe z conditions+actions), findActiveByEvent dla watchera. +- 7 nowych route'ow: `/settings/automation/*`. +- Widoki: `resources/views/automation/index.php` (lista regul), `resources/views/automation/form.php` (formularz z dynamicznymi warunkami/akcjami). +- Nowy JS: `public/assets/js/modules/automation-form.js` (dodawanie/usuwanie wierszy warunkow i akcji). +- Nowy SCSS: `resources/scss/modules/_automation.scss` (style formularza dynamicznego). +- Menu nawigacji: dodany link "Zadania automatyczne" w sekcji Ustawienia. + ## 2026-03-17 (Phase 15 — Wysylka e-mail z zamowien) - Nowa zaleznosc: `phpmailer/phpmailer` v7.0.2 (SMTP transport). - Nowy modul `App\Modules\Email` z 3 klasami: diff --git a/database/migrations/20260318_000057_create_automation_tables.sql b/database/migrations/20260318_000057_create_automation_tables.sql new file mode 100644 index 0000000..ea80e0d --- /dev/null +++ b/database/migrations/20260318_000057_create_automation_tables.sql @@ -0,0 +1,32 @@ +CREATE TABLE IF NOT EXISTS `automation_rules` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `name` VARCHAR(128) NOT NULL, + `event_type` VARCHAR(64) NOT NULL, + `is_active` TINYINT(1) NOT NULL DEFAULT 1, + `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + INDEX `auto_rules_event_active_idx` (`event_type`, `is_active`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE IF NOT EXISTS `automation_conditions` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `rule_id` INT UNSIGNED NOT NULL, + `condition_type` VARCHAR(64) NOT NULL, + `condition_value` JSON NOT NULL, + `sort_order` SMALLINT UNSIGNED NOT NULL DEFAULT 0, + PRIMARY KEY (`id`), + INDEX `auto_cond_rule_idx` (`rule_id`), + CONSTRAINT `auto_cond_rule_fk` FOREIGN KEY (`rule_id`) REFERENCES `automation_rules` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE IF NOT EXISTS `automation_actions` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `rule_id` INT UNSIGNED NOT NULL, + `action_type` VARCHAR(64) NOT NULL, + `action_config` JSON NOT NULL, + `sort_order` SMALLINT UNSIGNED NOT NULL DEFAULT 0, + PRIMARY KEY (`id`), + INDEX `auto_act_rule_idx` (`rule_id`), + CONSTRAINT `auto_act_rule_fk` FOREIGN KEY (`rule_id`) REFERENCES `automation_rules` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/public/assets/css/app.css b/public/assets/css/app.css index c3fd3f3..5de3862 100644 --- a/public/assets/css/app.css +++ b/public/assets/css/app.css @@ -1 +1,2812 @@ -:root{--c-primary: #6690f4;--c-primary-dark: #3164db;--c-bg: #f4f6f9;--c-surface: #ffffff;--c-text: #4e5e6a;--c-text-strong: #2d3748;--c-muted: #718096;--c-border: #b0bec5;--c-danger: #cc0000;--focus-ring: 0 0 0 3px rgba(102, 144, 244, 0.15);--shadow-card: 0 1px 4px rgba(0, 0, 0, 0.06)}.btn{display:inline-flex;align-items:center;justify-content:center;min-height:34px;padding:6px 12px;border:1px solid rgba(0,0,0,0);border-radius:8px;font:inherit;font-weight:600;text-decoration:none;cursor:pointer;transition:background-color .2s ease,border-color .2s ease,color .2s ease,transform .1s ease}.btn--primary{color:#fff;background:var(--c-primary)}.btn--primary:hover{background:var(--c-primary-dark)}.btn--secondary{color:var(--c-text-strong);border-color:var(--c-border);background:var(--c-surface)}.btn--secondary:hover{border-color:#cbd5e0;background:#f8fafc}.btn--danger{color:#fff;border-color:#b91c1c;background:#dc2626}.btn--danger:hover{border-color:#991b1b;background:#b91c1c}.btn--sm{min-height:28px;padding:3px 10px;font-size:12px}.btn--block{width:100%}.btn--disabled{opacity:.3;cursor:not-allowed;pointer-events:none}.btn:active{transform:translateY(1px)}.btn:focus-visible{outline:none;box-shadow:var(--focus-ring);border-color:var(--c-primary)}.form-control{width:100%;min-height:30px;border:1px solid var(--c-border);border-radius:6px;padding:4px 8px;font:inherit;color:var(--c-text-strong);background:#fff;transition:border-color .2s ease,box-shadow .2s ease}.form-control:focus{outline:none;border-color:var(--c-primary);box-shadow:var(--focus-ring)}.input{min-height:34px;border:1px solid var(--c-border);border-radius:8px;padding:5px 10px;font:inherit;color:var(--c-text-strong);background:#fff}.input--sm{min-height:28px;padding:3px 8px;font-size:12px}.flash{padding:8px 12px;border-radius:6px;font-size:13px}.flash--success{border:1px solid #b7ebcf;background:#f0fff6;color:#0f6b39}.flash--error{border:1px solid #fed7d7;background:#fff5f5;color:var(--c-danger)}.alert{padding:12px 14px;border-radius:8px;border:1px solid rgba(0,0,0,0);font-size:13px;min-height:44px}.alert--danger{border-color:#fed7d7;background:#fff5f5;color:var(--c-danger)}.alert--success{border-color:#b7ebcf;background:#f0fff6;color:#0f6b39}.alert--warning{border-color:#f7dd8b;background:#fff8e8;color:#815500}.form-field{display:grid;gap:5px}.field-label{color:var(--c-text-strong);font-size:13px;font-weight:600}.table-wrap{width:100%;overflow-x:auto}.table-wrap--visible{overflow:visible !important;overflow-x:visible !important}.table{width:100%;border-collapse:collapse;background:var(--c-surface)}.table th,.table td{padding:10px 12px;border-bottom:1px solid var(--c-border);text-align:left}.table th{color:var(--c-text-strong);font-weight:700;background:#f8fafc}.table--details th{white-space:nowrap}.table--details th:first-child,.table--details td:first-child{width:36px;text-align:center}.pagination{display:flex;align-items:center;flex-wrap:wrap;gap:8px}.pagination__item{display:inline-flex;align-items:center;justify-content:center;min-width:36px;height:36px;padding:0 10px;border-radius:8px;border:1px solid var(--c-border);color:var(--c-text-strong);background:var(--c-surface);text-decoration:none;font-weight:600}.pagination__item:hover{border-color:#cbd5e0;background:#f8fafc}.pagination__item.is-active{border-color:var(--c-primary);color:var(--c-primary);background:#edf2ff}.receipt-header{display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:16px;padding-bottom:12px;border-bottom:2px solid var(--c-text-strong)}.receipt-header__seller{flex:1}.receipt-header__seller strong{font-size:14px;display:block;margin-bottom:4px}.receipt-header__title{text-align:right}.receipt-header__title h1{font-size:18px;font-weight:700;margin-bottom:4px}.receipt-print{max-width:700px;margin:0 auto}@media print{.receipt-print{max-width:100%}}.email-send-overlay{position:fixed;inset:0;z-index:1000;background:rgba(0,0,0,.5);display:flex;align-items:center;justify-content:center}.email-send-modal{background:var(--c-card-bg, #fff);border-radius:8px;width:580px;max-width:95vw;max-height:90vh;display:flex;flex-direction:column;box-shadow:0 8px 32px rgba(0,0,0,.2)}.email-send-modal__header{display:flex;align-items:center;justify-content:space-between;padding:12px 16px;border-bottom:1px solid var(--c-border, #e0e0e0)}.email-send-modal__header h3{margin:0;font-size:15px}.email-send-modal__close{background:none;border:none;font-size:20px;cursor:pointer;color:var(--c-text-muted, #888);padding:0 4px}.email-send-modal__close:hover{color:var(--c-text, #333)}.email-send-modal__body{padding:16px;overflow-y:auto;flex:1}.email-send-modal__field{margin-bottom:10px}.email-send-modal__field label{display:block;font-size:12px;font-weight:600;margin-bottom:4px;color:var(--c-text-muted, #666)}.email-send-modal__field .input{width:100%}.email-send-modal__actions-top{margin-bottom:10px}.email-send-modal__footer{display:flex;justify-content:flex-end;gap:8px;padding:12px 16px;border-top:1px solid var(--c-border, #e0e0e0)}.email-send-preview{border:1px solid var(--c-border, #e0e0e0);border-radius:4px;padding:12px;max-height:280px;overflow-y:auto;background:var(--c-bg, #fafafa)}.email-send-preview__subject{font-weight:600;font-size:13px;margin-bottom:8px;padding-bottom:8px;border-bottom:1px solid var(--c-border, #e0e0e0)}.email-send-preview__body{font-size:13px;line-height:1.5}.email-send-preview__body p{margin:0 0 8px}.email-send-preview__attachments{margin-top:8px;padding-top:8px;border-top:1px solid var(--c-border, #e0e0e0);font-size:12px;color:var(--c-text-muted, #666)}*{box-sizing:border-box}html,body{min-height:100%}body{margin:0;font-family:"Roboto","Segoe UI",sans-serif;font-size:13px;color:var(--c-text);background:var(--c-bg)}a{color:var(--c-primary)}.app-shell{min-height:100vh;display:flex}.sidebar{width:260px;min-width:260px;flex-shrink:0;overflow:hidden;transition:width .22s ease,min-width .22s ease;border-right:1px solid #243041;background:#111a28;padding:18px 10px;display:flex;flex-direction:column}.sidebar.is-collapsed{width:52px;min-width:52px}.sidebar__brand{display:flex;align-items:center;justify-content:space-between;margin:4px 4px 16px;gap:6px;min-width:0}.sidebar__brand-text{color:#e9f0ff;font-size:24px;font-weight:300;letter-spacing:-0.02em;white-space:nowrap;overflow:hidden;flex:1;min-width:0}.sidebar__brand-text strong{font-weight:700}.sidebar__collapse-btn{flex-shrink:0;width:28px;height:28px;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,0);border:1px solid #2a3a54;border-radius:6px;color:#64748b;cursor:pointer;padding:0;transition:background .15s,color .15s}.sidebar__collapse-btn:hover{background:#1b2a3f;color:#cbd5e1}.sidebar__collapse-icon{display:block;transition:transform .22s ease;flex-shrink:0}.sidebar.is-collapsed .sidebar__collapse-icon{transform:rotate(180deg)}.sidebar__nav{display:grid;gap:4px}.sidebar__link{display:flex;align-items:center;gap:9px;white-space:nowrap;border-radius:8px;padding:9px 10px;text-decoration:none;color:#cbd5e1;font-weight:600}.sidebar__link:hover{color:#f8fafc;background:#1b2a3f}.sidebar__link.is-active{color:#fff;background:#2e4f93}.sidebar__group{display:grid;gap:2px}.sidebar__group-toggle{list-style:none;border-radius:8px;padding:9px 10px;color:#cbd5e1;font-weight:600;cursor:pointer;display:flex;align-items:center;gap:9px;white-space:nowrap;user-select:none}.sidebar__group-toggle::-webkit-details-marker{display:none}.sidebar__group:hover .sidebar__group-toggle,.sidebar__group-toggle:hover{color:#f8fafc;background:#1b2a3f}.sidebar__group.is-active .sidebar__group-toggle{color:#fff;background:#2e4f93}.sidebar__icon{flex-shrink:0;width:18px;height:18px;display:flex;align-items:center;justify-content:center;opacity:.85}.sidebar__label{flex:1;min-width:0;overflow:hidden}.sidebar__toggle-arrow{flex-shrink:0;margin-left:auto;opacity:.5;transition:transform .18s ease}details[open]>.sidebar__group-toggle .sidebar__toggle-arrow{transform:rotate(180deg)}.sidebar__group-links{display:grid;gap:2px;padding-left:12px;overflow:hidden}.sidebar__sublink{border-radius:6px;padding:7px 10px 7px 8px;text-decoration:none;color:#94a3b8;font-size:12.5px;font-weight:500;display:flex;align-items:center;gap:8px;white-space:nowrap}.sidebar__sublink::before{content:"";flex-shrink:0;width:5px;height:5px;border-radius:50%;background:rgba(148,163,184,.3);transition:background .15s}.sidebar__sublink:hover{color:#e2e8f0;background:#1b2a3f}.sidebar__sublink:hover::before{background:rgba(148,163,184,.65)}.sidebar__sublink.is-active{color:#fff;background:rgba(46,79,147,.55)}.sidebar__sublink.is-active::before{background:#93c5fd}.app-main{flex:1;min-width:0}.topbar{height:50px;border-bottom:1px solid var(--c-border);background:var(--c-surface);display:flex;align-items:center;justify-content:space-between;padding:0 20px;position:sticky;top:0;z-index:100}.brand{font-size:22px;font-weight:300;letter-spacing:-0.02em;color:var(--c-text-strong)}.brand strong{font-weight:700}.container{max-width:none;width:calc(100% - 20px);margin:12px 10px;padding:0 4px 14px}.card{background:var(--c-surface);border-radius:10px;box-shadow:var(--shadow-card);padding:14px}.card h1{margin:0 0 10px;color:var(--c-text-strong);font-size:24px;font-weight:700}.muted{color:var(--c-muted)}.accent{color:var(--c-primary);font-weight:600}.users-form{display:grid;gap:14px;max-width:460px}.form-field{margin-bottom:12px}.section-title{margin:0;color:var(--c-text-strong);font-size:18px;font-weight:700}h2.section-title,h3.section-title,h4.section-title{display:flex;align-items:center;gap:6px;font-weight:600;padding:6px 0;border-bottom:1px solid #e2e8f0;color:var(--c-primary, #2563eb)}h2.section-title::before,h3.section-title::before,h4.section-title::before{content:"■";font-size:.55em;opacity:.5}h3.section-title,h4.section-title{font-size:15px}h3.section-title::before,h4.section-title::before{content:"◆";font-size:.5em}.mt-0{margin-top:0}.mt-4{margin-top:4px}.mt-12{margin-top:8px}.mt-16{margin-top:12px}.settings-grid{display:grid;grid-template-columns:repeat(3, minmax(0, 1fr));gap:12px}.settings-nav{display:flex;gap:8px;flex-wrap:wrap}.settings-nav__link{text-decoration:none;border:1px solid var(--c-border);border-radius:8px;padding:8px 12px;color:var(--c-text-strong);font-weight:600}.settings-nav__link:hover{background:#f8fafc}.settings-nav__link.is-active{border-color:var(--c-primary);color:var(--c-primary);background:#edf2ff}.settings-stat{border:1px solid var(--c-border);border-radius:8px;padding:12px;background:#f8fafc}.settings-stat__label{display:block;color:var(--c-muted);font-size:12px;margin-bottom:4px}.settings-stat__value{color:var(--c-text-strong);font-size:20px}.settings-logs{margin:0;padding:12px;border-radius:8px;border:1px solid var(--c-border);background:#0b1220;color:#d1d5db;font-size:12px;line-height:1.5;overflow:auto}.settings-allegro-callback{display:block;width:100%;padding:8px 10px;border:1px solid var(--c-border);border-radius:8px;background:#f8fafc;color:var(--c-text-strong);font-size:12px;line-height:1.45;word-break:break-all}.page-head{display:flex;align-items:center;justify-content:space-between;gap:12px}.filters-grid{display:grid;grid-template-columns:repeat(3, minmax(0, 1fr));gap:12px}.filters-actions{display:flex;align-items:center;gap:8px}.product-form .form-control{width:100%}.form-grid{display:grid;grid-template-columns:repeat(2, minmax(0, 1fr));gap:12px}.form-grid-2{display:grid;grid-template-columns:repeat(2, minmax(0, 1fr));gap:12px;align-items:start}.form-grid-3{display:grid;grid-template-columns:repeat(3, minmax(0, 1fr));gap:12px;align-items:start}.form-grid-4{display:grid;grid-template-columns:repeat(4, minmax(0, 1fr));gap:12px;align-items:start}.form-actions{display:flex;gap:8px;flex-wrap:wrap;align-items:flex-start}.form-actions .btn{align-self:flex-start}.statuses-form{display:grid;gap:8px;grid-template-columns:repeat(2, minmax(0, 1fr))}.statuses-form .form-actions{grid-column:1/-1}.statuses-color-input{min-height:32px;padding:2px}.statuses-hint{grid-column:1/-1;margin:0}.statuses-group-block{border:1px solid var(--c-border);border-radius:10px;padding:8px;background:#fbfdff}.statuses-group-block__head{display:flex;align-items:center;justify-content:space-between;gap:6px;flex-wrap:wrap}.statuses-group-block__title{margin:0;display:inline-flex;align-items:center;gap:6px;color:var(--c-text-strong);font-size:14px}.statuses-color-dot{width:12px;height:12px;border-radius:999px;border:1px solid rgba(15,23,42,.15)}.statuses-dnd-list{margin:6px 0 0;padding:0;list-style:none;display:grid;gap:6px}.statuses-dnd-item{display:grid;grid-template-columns:24px 1fr;gap:6px;border:1px solid #dce4f0;border-radius:8px;background:#fff;padding:6px}.statuses-dnd-item__content{display:flex;align-items:center;gap:6px;min-width:0}.statuses-dnd-item.is-dragging{opacity:.6}.statuses-dnd-item__drag{display:inline-flex;align-items:center;justify-content:center;border:1px dashed #cbd5e1;border-radius:6px;color:#64748b;cursor:grab;user-select:none;font-weight:700;font-size:12px}.statuses-dnd-item__drag:active{cursor:grabbing}.statuses-inline-form{display:grid;gap:6px}.statuses-inline-form--row{grid-template-columns:minmax(180px, 1.4fr) minmax(150px, 1fr) auto auto auto;align-items:center;flex:1 1 auto;min-width:0}.statuses-inline-form--row-group{grid-template-columns:minmax(180px, 1.5fr) 56px auto auto auto;align-items:center;flex:1 1 auto;min-width:0}.statuses-inline-form--row .form-control,.statuses-inline-form--row-group .form-control{min-height:30px;padding:4px 8px}.statuses-inline-form--row .btn,.statuses-inline-form--row-group .btn,.statuses-inline-delete .btn{min-height:30px;padding:4px 10px;font-size:12px}.statuses-inline-check{margin-top:0;white-space:nowrap;font-size:12px}.statuses-inline-delete{margin:0;flex:0 0 auto}.statuses-code-label{font-size:12px;color:var(--c-muted)}.statuses-code-readonly{display:inline-flex;align-items:center;gap:6px;white-space:nowrap;font-size:12px}.statuses-code-readonly code{background:#eef2f7;border-radius:6px;padding:1px 6px;color:#1f2937;font-size:12px}.field-inline{display:flex;align-items:center;gap:8px;margin-top:2px}.modal-backdrop{position:fixed;inset:0;background:rgba(15,23,42,.5);display:flex;align-items:center;justify-content:center;padding:16px;z-index:200}.modal-backdrop[hidden]{display:none}.modal{width:min(560px,100%);background:#fff;border-radius:10px;box-shadow:0 20px 40px rgba(15,23,42,.35);overflow:hidden}.modal__header{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:16px 18px;border-bottom:1px solid var(--c-border)}.modal__header h3{margin:0;font-size:18px;color:var(--c-text-strong)}.modal__body{padding:16px 18px 18px}.status-pill{display:inline-flex;align-items:center;justify-content:center;border:1px solid #fed7d7;background:#fff5f5;color:#9b2c2c;padding:2px 8px;border-radius:999px;font-size:12px;font-weight:600}.status-pill.is-active{border-color:#b7ebcf;background:#f0fff6;color:#0f6b39}.table-row-actions{display:inline-flex;align-items:center;gap:6px;flex-wrap:wrap}.table-row-actions form{margin:0}.table-list{display:grid;gap:14px}.table-list__header{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap}.table-list__left{display:inline-flex;align-items:center;gap:8px;flex-wrap:wrap}.table-list-header-actions{display:inline-flex;align-items:center;gap:10px;flex-wrap:wrap}.js-filter-toggle-btn.is-active{border-color:#cbd5e0;background:#edf2ff;color:var(--c-primary-dark)}.table-filter-badge{display:inline-flex;align-items:center;justify-content:center;min-width:18px;height:18px;padding:0 5px;font-size:11px;font-weight:700;color:#fff;background:var(--c-primary);border-radius:999px}.table-filters-wrapper{display:none}.table-filters-wrapper.is-open{display:block}.table-list-filters{display:grid;gap:12px;grid-template-columns:repeat(auto-fit, minmax(170px, 1fr));align-items:end}.table-col-toggle-wrapper{position:relative}.table-col-toggle-dropdown{display:none;position:absolute;right:0;top:calc(100% + 6px);z-index:30;width:260px;max-height:360px;overflow:auto;border:1px solid var(--c-border);border-radius:10px;background:#fff;box-shadow:0 10px 25px rgba(15,23,42,.12)}.table-col-toggle-dropdown.is-open{display:block}.table-col-toggle-header{padding:10px 12px;border-bottom:1px solid var(--c-border);font-size:12px;font-weight:700;color:var(--c-muted)}.table-col-toggle-item{display:flex;align-items:center;gap:10px;padding:8px 12px;font-size:13px;color:var(--c-text-strong)}.table-col-toggle-item:hover{background:#f8fafc}.table-col-toggle-footer{border-top:1px solid var(--c-border);padding:8px 12px}.table-col-hidden{display:none}.table-col-switch{position:relative;display:inline-block;width:34px;min-width:34px;height:18px}.table-col-switch input{opacity:0;width:0;height:0;position:absolute}.table-col-switch-slider{position:absolute;top:0;left:0;right:0;bottom:0;background:#cbd5e1;border-radius:999px;transition:background-color .2s ease}.table-col-switch-slider::before{content:"";position:absolute;height:14px;width:14px;left:2px;bottom:2px;background:#fff;border-radius:50%;transition:transform .2s ease}.table-col-switch input:checked+.table-col-switch-slider{background:#16a34a}.table-col-switch input:checked+.table-col-switch-slider::before{transform:translateX(16px)}.table-sort-link{display:inline-flex;align-items:center;gap:6px;color:var(--c-text-strong);text-decoration:none}.table-sort-link:hover{color:var(--c-primary-dark)}.table-sort-icon.is-muted{color:#a0aec0}.table-list__footer{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap}.table-list-per-page-form{display:inline-flex;align-items:center;gap:8px}.table-list-per-page-form .form-control{min-width:90px}.table-select-col{width:44px;text-align:center}.table-select-toggle{display:inline-flex;align-items:center;justify-content:center}.table-select-toggle input[type=checkbox]{width:16px;height:16px}.orders-page .orders-head{background:linear-gradient(120deg, #f8fbff 0%, #eef5ff 100%);border:1px solid #dbe7fb}.orders-page .table-list{border:1px solid #dde5f2;border-radius:12px;box-shadow:0 6px 16px rgba(20,44,86,.08)}.orders-page .table-list__header{padding:10px 6px 2px}.orders-page .table-list-filters{padding:6px 6px 2px;border-top:1px solid #ebf0f7;border-bottom:1px solid #ebf0f7;background:#f9fbff}.orders-page .table-wrap{border-radius:10px;overflow:hidden;border:1px solid #e7edf6}.orders-page .table thead th{background:#f3f7fd;color:#30435f;font-size:12px;text-transform:uppercase;letter-spacing:.03em}.orders-page .table tbody td{vertical-align:middle;padding-top:10px;padding-bottom:10px;border-bottom-color:#edf2f8}.orders-page .table tbody tr:hover td{background:#f9fcff}.orders-list-page{padding:10px;margin-bottom:10px}.orders-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;flex-wrap:wrap}.orders-stats{display:inline-grid;grid-template-columns:repeat(3, minmax(86px, auto));gap:8px}.orders-stat{border:1px solid #d8e2f0;background:#f8fbff;border-radius:8px;padding:6px 8px;line-height:1.15}.orders-stat__label{display:block;color:#5f6f83;font-size:11px;margin-bottom:2px}.orders-stat__value{color:#12233a;font-size:16px;font-weight:700}.orders-ref{display:grid;gap:2px;min-width:170px}.orders-ref__main{font-weight:700;color:#0f1f35;font-size:14px}.orders-ref__meta{display:inline-flex;flex-wrap:wrap;gap:4px 10px;color:#64748b;font-size:12px}.orders-buyer{display:grid;gap:2px}.orders-buyer__name{color:#0f172a;font-weight:600;font-size:14px}.orders-buyer__meta{display:inline-flex;flex-wrap:wrap;gap:4px 10px;color:#64748b;font-size:12px}.orders-status-wrap{display:inline-flex;align-items:center;gap:5px;flex-wrap:wrap}.order-tag{display:inline-flex;align-items:center;justify-content:center;border:1px solid #d8e1ef;background:#f8fafc;color:#334155;border-radius:999px;padding:2px 8px;font-size:12px;font-weight:700;line-height:1.1}.order-tag.is-info{border-color:#bfdbfe;background:#eff6ff;color:#1d4ed8}.order-tag.is-success{border-color:#bbf7d0;background:#f0fdf4;color:#166534}.order-tag.is-danger{border-color:#fecaca;background:#fef2f2;color:#b91c1c}.order-tag.is-warn{border-color:#fde68a;background:#fffbeb;color:#92400e}.order-tag.is-cod{border-color:#f9a8d4;background:#fdf2f8;color:#9d174d}.order-tag.is-unpaid{border-color:#fca5a5;background:#fef2f2;color:#b91c1c}.orders-mini{font-size:14px;color:#223247;line-height:1.25}.orders-mini__delivery{font-size:12px;color:#64748b;margin-bottom:2px;max-width:160px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.orders-products{display:grid;gap:4px;min-width:240px}.orders-products__meta,.orders-products__more{font-size:12px;color:#64748b}.orders-product{display:grid;grid-template-columns:48px 1fr;gap:6px;align-items:center}.orders-product__thumb{width:48px;height:48px;border-radius:4px;border:1px solid #dbe3ef;object-fit:cover;background:#fff}.orders-product__thumb--empty{display:inline-block;background:#eef2f7;border-style:dashed}.orders-product__txt{min-width:0;display:grid;gap:1px}.orders-product__name{font-size:14px;color:#0f172a;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.orders-product__qty{font-size:12px;color:#64748b}.orders-image-hover-wrap{position:relative;display:inline-flex;align-items:center;justify-content:center;cursor:zoom-in}.orders-image-hover-popup{display:none;position:fixed;left:auto;top:auto;width:350px;max-height:350px;object-fit:contain;border-radius:8px;background:#fff;box-shadow:0 8px 24px rgba(0,0,0,.18);border:1px solid #dfe3ea;z-index:100;pointer-events:none}.orders-image-hover-wrap:hover .orders-image-hover-popup{display:block}.activity-type-badge{display:inline-block;padding:2px 8px;border-radius:4px;font-size:12px;font-weight:500;white-space:nowrap;background:#e2e8f0;color:#334155}.activity-type-badge--status_change{background:#dbeafe;color:#1e40af}.activity-type-badge--payment{background:#dcfce7;color:#166534}.activity-type-badge--invoice{background:#fef3c7;color:#92400e}.activity-type-badge--shipment{background:#e0e7ff;color:#3730a3}.activity-type-badge--message{background:#f3e8ff;color:#6b21a8}.activity-type-badge--document{background:#fce7f3;color:#9d174d}.activity-type-badge--import{background:#f1f5f9;color:#475569}.activity-type-badge--note{background:#ecfdf5;color:#065f46}.text-nowrap{white-space:nowrap}.orders-money{display:grid;gap:2px}.orders-money__main{color:#0f172a;font-weight:700;font-size:14px}.orders-money__meta{color:#64748b;font-size:12px}.table-list[data-table-list-id=orders]{gap:8px}.table-list[data-table-list-id=orders] .table-list__header{padding:2px 0 0}.table-list[data-table-list-id=orders] .table-list-filters{gap:8px;grid-template-columns:repeat(auto-fit, minmax(150px, 1fr))}.table-list[data-table-list-id=orders] .table th,.table-list[data-table-list-id=orders] .table td{padding:6px 8px}.table-list[data-table-list-id=orders] .table thead th{font-size:12px;text-transform:uppercase;letter-spacing:.02em;white-space:nowrap}.table-list[data-table-list-id=orders] .table tbody td{vertical-align:top;font-size:14px;line-height:1.25}.order-show-layout{display:grid;grid-template-columns:220px minmax(0, 1fr);gap:12px;align-items:start}.order-statuses-side{position:sticky;top:60px;padding:10px}.order-statuses-side__title{font-size:13px;font-weight:700;color:#0f172a;margin-bottom:8px}.order-status-group{margin-bottom:10px}.order-status-group__name{font-size:12px;color:#475569;font-weight:700;margin-bottom:5px}.order-status-row{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:4px 6px;border-radius:6px;color:#334155;font-size:12px;text-decoration:none}.order-status-row__count{min-width:24px;text-align:center;border-radius:999px;background:var(--status-color, #64748b);padding:1px 6px;font-weight:700;font-size:11px;color:#fff}.order-status-row:hover{background:#f1f5f9}.order-status-row.is-active{background:rgba(15,23,42,.06);color:#0f172a;font-weight:700}.order-show-main{min-width:0}.order-details-actions{display:inline-flex;flex-wrap:wrap;justify-content:flex-end;gap:6px}.order-details-page{padding:12px}.order-details-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;flex-wrap:wrap}.order-back-link{color:#475569;text-decoration:none;font-weight:600}.order-back-link:hover{color:#1d4ed8}.order-details-sub{display:inline-flex;gap:10px;flex-wrap:wrap;color:#64748b;font-size:12px}.order-details-pill{border-radius:999px;padding:5px 10px;background:#eef6ff;border:1px solid #cfe2ff;color:#1d4ed8;font-size:12px;font-weight:700}.order-status-change{display:flex;align-items:center;gap:10px;flex-wrap:wrap}.order-status-change__form{display:flex;align-items:center;gap:6px}.order-status-change__select{min-width:180px}.order-details-tabs{display:flex;gap:6px;flex-wrap:wrap}.order-details-tab{border:1px solid #d6deea;border-radius:8px;padding:5px 10px;color:#475569;font-size:12px;background:#f8fafc;cursor:pointer}.order-details-tab.is-active{border-color:#bfdbfe;color:#1d4ed8;background:#eff6ff;font-weight:700}.order-item-cell{display:grid;grid-template-columns:44px 1fr;gap:8px;align-items:center;min-width:260px}.order-item-thumb{width:44px;height:44px;border-radius:6px;border:1px solid #dbe3ef;object-fit:cover}.order-item-thumb--empty{display:inline-block;background:#eef2f7;border-style:dashed}.order-item-name{font-weight:600;color:#0f172a}.order-grid-2{display:grid;grid-template-columns:repeat(2, minmax(0, 1fr));gap:12px}.order-grid-3{display:grid;grid-template-columns:repeat(3, minmax(0, 1fr));gap:12px}.order-kv{margin:0;display:grid;grid-template-columns:150px 1fr;gap:6px 10px;font-size:12px}.payment-summary{display:grid;gap:6px;max-width:420px}.payment-summary__row{display:flex;align-items:center;gap:10px;font-size:12px}.payment-summary__label{width:150px;flex-shrink:0;color:#64748b}.payment-summary__value{font-weight:600;color:#0f172a}.order-kv dt{color:#64748b}.order-kv dd{margin:0;color:#0f172a;font-weight:600}.order-address{display:grid;gap:3px;font-size:12px;color:#0f172a}.order-events{display:grid;gap:8px}.order-event{border:1px solid #e2e8f0;border-radius:8px;padding:8px;background:#fbfdff}.order-event__head{color:#64748b;font-size:11px}.order-event__body{margin-top:4px;color:#0f172a;font-size:12px}.order-tab-panel{display:none}.order-tab-panel.is-active{display:block}.order-empty-placeholder{border:1px dashed #cbd5e1;border-radius:8px;min-height:180px;background:#f8fafc}.order-status-badge{display:inline-flex;align-items:center;justify-content:center;padding:4px 10px;border-radius:999px;font-size:12px;font-weight:700;border:1px solid #cbd5e1;color:#334155;background:#f8fafc}.order-status-badge.is-info{border-color:#bfdbfe;background:#eff6ff;color:#1d4ed8}.order-status-badge.is-success{border-color:#bbf7d0;background:#f0fdf4;color:#166534}.order-status-badge.is-danger{border-color:#fecaca;background:#fef2f2;color:#b91c1c}.order-status-badge.is-warn{border-color:#fde68a;background:#fffbeb;color:#92400e}.order-status-badge.is-empty{color:#94a3b8}.order-buyer{display:grid;gap:2px}.order-buyer__name{color:#0f172a;font-weight:600}.order-buyer__email{color:#64748b;font-size:12px}.table-inline-action{display:inline-block;margin-right:6px}.product-name-cell{display:inline-flex;align-items:center;gap:10px}.product-name-thumb{width:60px;height:60px;border-radius:6px;object-fit:cover;border:1px solid var(--c-border);background:#f8fafc}.product-name-thumb--empty{display:inline-block;width:60px;height:60px;border-radius:6px;border:1px dashed #cbd5e0;background:#f8fafc}.product-name-thumb-btn{border:0;padding:0;background:rgba(0,0,0,0);cursor:pointer;display:inline-flex;align-items:center;justify-content:center}.product-name-thumb-btn:focus-visible{outline:none;box-shadow:var(--focus-ring);border-radius:8px}.modal--image-preview{width:min(760px,100%)}.product-image-preview__img{display:block;width:100%;max-height:70vh;object-fit:contain;border-radius:8px;background:#f8fafc}.product-images-grid{display:grid;grid-template-columns:repeat(auto-fill, minmax(220px, 1fr));gap:12px}.product-image-card{border:1px solid #dfe3ea;border-radius:10px;padding:10px;background:#fff}.product-image-card__thumb-wrap{position:relative;border-radius:8px;overflow:hidden;background:#f2f5f8}.product-image-card__thumb{width:100%;height:160px;object-fit:cover;display:block}.product-image-card__thumb.is-empty{height:160px;display:grid;place-items:center;color:#6b7785;font-size:12px}.product-image-card__badge{display:none;position:absolute;top:8px;left:8px;background:#1f7a43;color:#fff;padding:3px 8px;border-radius:999px;font-size:11px}.product-image-card.is-main .product-image-card__badge{display:inline-block}.product-image-card__meta{margin-top:8px;font-size:11px;line-height:1.25;color:#5f6b79;overflow-wrap:anywhere}.product-image-card__actions{margin-top:10px;display:grid;grid-template-columns:1fr;gap:8px}.product-image-card__actions .btn{min-height:34px;font-size:12px;line-height:1.2;padding:6px 10px}.product-links-search-form{display:grid;gap:12px;grid-template-columns:minmax(220px, 320px) minmax(220px, 1fr) auto;align-items:end}.product-links-head{display:grid;gap:8px;grid-template-columns:repeat(3, minmax(0, 1fr))}.product-tabs-nav{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.product-links-inline-form{display:grid;gap:8px;grid-template-columns:minmax(140px, 1fr) minmax(140px, 1fr) auto;align-items:center}.product-links-actions-row{display:flex;align-items:center;gap:8px;flex-wrap:nowrap}.product-links-actions-row .product-links-relink-form{flex:1 1 auto}.product-links-unlink-form{margin:0;flex:0 0 auto}.product-link-status-cell{display:inline-flex;align-items:center;gap:6px}.product-link-alert-indicator{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;border-radius:999px;border:1px solid #f59e0b;background:#fffbeb;color:#b45309;font-size:12px;font-weight:700;cursor:help}.product-link-events-list{margin:0;padding:0;list-style:none;display:grid;gap:4px}.product-link-events-list li{display:grid;gap:2px}.product-link-events-type{font-weight:600;color:var(--c-text-strong)}.product-link-events-date{color:var(--c-muted);font-size:12px}.product-show-images-grid{display:grid;grid-template-columns:repeat(auto-fill, minmax(220px, 1fr));gap:12px}.product-show-image-card{border:1px solid var(--c-border);border-radius:10px;background:#fff;padding:10px;overflow:hidden}.product-show-image-card__meta{display:flex;align-items:flex-start;justify-content:space-between;gap:8px;min-width:0}.product-show-image-path{font-size:12px;min-width:0;overflow:hidden}.product-show-image-path summary{cursor:pointer;color:var(--c-muted, #888);list-style:none;user-select:none;white-space:nowrap}.product-show-image-path summary::-webkit-details-marker{display:none}.product-show-image-path summary::after{content:" ▾"}.product-show-image-path[open] summary::after{content:" ▴"}.product-show-image-path__url{margin-top:4px;word-break:break-all;overflow-wrap:break-word;font-size:11px}.product-show-image{width:100%;max-height:260px;object-fit:cover;border-radius:8px;border:1px solid #d9e0ea}.shipment-grid{display:grid;grid-template-columns:repeat(2, minmax(0, 1fr));gap:12px}.searchable-select{position:relative}.searchable-select__trigger{display:flex;align-items:center;justify-content:space-between;cursor:pointer;user-select:none;min-height:34px}.searchable-select__trigger::after{content:"";width:0;height:0;border-left:4px solid rgba(0,0,0,0);border-right:4px solid rgba(0,0,0,0);border-top:5px solid var(--c-text-muted, #6b7280);margin-left:8px;flex-shrink:0}.searchable-select__trigger--placeholder{color:var(--c-text-muted, #6b7280)}.searchable-select__dropdown{display:none;position:absolute;left:0;right:0;top:100%;z-index:50;max-height:280px;overflow:auto;background:#fff;border:1px solid var(--c-border);border-top:0;border-radius:0 0 8px 8px;box-shadow:0 8px 20px rgba(15,23,42,.12)}.searchable-select__dropdown.is-open{display:block}.searchable-select__search{position:sticky;top:0;border:none !important;border-bottom:1px solid var(--c-border) !important;border-radius:0 !important;box-shadow:none !important;font-size:13px;background:#fff;z-index:1}.searchable-select__option{padding:7px 10px;font-size:13px;cursor:pointer;color:var(--c-text-strong)}.searchable-select__option:hover{background:#f1f5f9}.searchable-select__option.is-selected{background:#edf2ff;font-weight:600}.flash{padding:10px 14px;border-radius:8px;font-size:13px;font-weight:500}.flash--success{background:#f0fdf4;border:1px solid #bbf7d0;color:#166534}.flash--error{background:#fef2f2;border:1px solid #fecaca;color:#b91c1c}.content-tabs-card{margin-top:0}.content-tabs-nav{display:flex;gap:4px;border-bottom:2px solid var(--c-border);margin-bottom:16px;flex-wrap:wrap}.content-tab-btn{padding:8px 16px;border:none;background:none;cursor:pointer;font-size:14px;font-weight:500;color:var(--c-text-muted, #6b7280);border-bottom:2px solid rgba(0,0,0,0);margin-bottom:-2px;border-radius:4px 4px 0 0;transition:color .15s,border-color .15s}.content-tab-btn:hover{color:var(--c-text-strong, #111827)}.content-tab-btn.is-active{color:var(--c-primary, #2563eb);border-bottom-color:var(--c-primary, #2563eb)}.content-tab-panel{display:none}.content-tab-panel.is-active{display:block}.shoppro-tabs-toolbar{display:flex;align-items:flex-end;justify-content:space-between;gap:10px;margin-bottom:10px;flex-wrap:wrap}.shoppro-tabs-toolbar__field{margin:0;min-width:260px;max-width:420px;flex:1 1 320px}.shoppro-tabs-toolbar__field .form-control{width:100%}.shoppro-tabs-toolbar__actions{display:inline-flex;align-items:center;gap:8px}.dm-carrier-select{min-width:140px}.dm-service-wrap{min-width:200px}.dm-service-wrap .dm-inpost-panel .form-control,.dm-service-wrap .dm-apaczka-panel .form-control{width:100%}.integration-settings-group{grid-column:1/-1;border:1px solid var(--c-border);border-radius:10px;background:#f8fbff;padding:10px}.integration-settings-group__head{margin-bottom:8px;padding:4px 0;border-bottom:1px solid #e2e8f0}.integration-settings-group__title{margin:0;font-size:14px;font-weight:600;letter-spacing:.01em;color:var(--c-text-strong, #1e293b)}.integration-settings-group__desc{margin:4px 0 0;color:#4b5563}.integration-settings-group__grid{display:grid;grid-template-columns:repeat(2, minmax(0, 1fr));gap:10px 12px;align-items:start}.integration-settings-group__full{grid-column:1/-1}.integration-settings-group__grid .form-field{margin:0;align-self:start}.integration-settings-group__grid .form-control{min-height:34px;height:34px}.integration-settings-group__grid input[type=date].form-control{line-height:1.2}.integration-settings-checkboxes{border:0;padding:0;margin:0}.integration-settings-checkboxes .field-label{display:block;margin-bottom:2px}.integration-settings-checkboxes__list{display:grid;grid-template-columns:repeat(2, minmax(0, 1fr));gap:6px 12px}.integration-settings-checkboxes__item{display:inline-flex;align-items:center;gap:6px;font-size:13px;color:#334155}@media(max-width: 768px){.app-shell{flex-direction:column}.sidebar{width:100% !important;min-width:0 !important;border-right:0;border-bottom:1px solid #243041;padding:14px;overflow-x:auto}.sidebar__brand{margin:0 0 10px;font-size:22px}.sidebar__collapse-btn{display:none}.sidebar__nav{display:flex;gap:8px;overflow-x:auto}.sidebar__link{white-space:nowrap}.topbar{padding:0 14px}.container{margin-top:16px;width:calc(100% - 16px);margin-left:8px;margin-right:8px;padding:0 3px 12px}.settings-grid{grid-template-columns:1fr}.page-head{flex-direction:column;align-items:flex-start}.orders-stats{grid-template-columns:1fr;width:100%}.order-show-layout{grid-template-columns:1fr}.order-statuses-side{position:static;top:auto}.order-details-actions{justify-content:flex-start}.order-grid-2,.order-grid-3{grid-template-columns:1fr}.order-kv{grid-template-columns:1fr;gap:2px}.filters-grid,.form-grid,.form-grid-2,.form-grid-3,.form-grid-4,.shipment-grid,.statuses-form,.statuses-inline-form,.table-list-filters,.product-links-search-form,.product-links-inline-form{grid-template-columns:1fr}.statuses-dnd-item__content{display:block}.statuses-inline-delete{margin-top:6px}.filters-actions{align-items:center}.table-list__header,.table-list__footer{align-items:flex-start}.product-links-head{grid-template-columns:1fr}.integration-settings-group__grid{grid-template-columns:1fr}.integration-settings-checkboxes__list{grid-template-columns:1fr}.card{padding:12px}.modal--image-preview{width:min(92vw,100%)}.email-tpl-editor-wrap{flex-direction:column}.email-tpl-var-panel{min-width:200px}.modal-box{width:95vw;max-height:90vh}}.email-tpl-editor-wrap{display:flex;flex-direction:column;border:1px solid var(--c-border);border-radius:6px;overflow:hidden}.email-tpl-toolbar{display:flex;align-items:center;gap:6px;padding:6px 8px;background:var(--c-bg-subtle, #f8f9fa);border-bottom:1px solid var(--c-border)}.email-tpl-var-dropdown{position:relative}.email-tpl-var-panel{position:absolute;top:100%;left:0;z-index:50;min-width:260px;max-height:320px;overflow-y:auto;background:var(--c-bg);border:1px solid var(--c-border);border-radius:6px;box-shadow:0 4px 12px rgba(0,0,0,.12);padding:6px;margin-top:4px}.email-var-group:not(:first-child){margin-top:6px;padding-top:6px;border-top:1px solid var(--c-border)}.email-var-group__label{font-size:11px;font-weight:600;text-transform:uppercase;color:var(--c-text-muted);padding:2px 4px;letter-spacing:.03em}.email-var-item{display:block;width:100%;text-align:left;padding:3px 6px;margin:1px 0;border:none;background:none;font-size:12px;font-family:"Roboto Mono",monospace;color:var(--c-text);border-radius:3px;cursor:pointer}.email-var-item:hover{background:var(--c-primary);color:#fff}#js-quill-editor{min-height:200px}#js-quill-editor .ql-editor{min-height:200px;font-size:13px}.modal-overlay{position:fixed;inset:0;z-index:1000;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.45)}.modal-box{width:min(680px,90vw);max-height:80vh;background:var(--c-bg);border-radius:8px;box-shadow:0 8px 30px rgba(0,0,0,.2);display:flex;flex-direction:column;overflow:hidden}.modal-box__header{display:flex;align-items:center;justify-content:space-between;padding:10px 16px;border-bottom:1px solid var(--c-border)}.modal-box__title{margin:0;font-size:15px;font-weight:600}.modal-box__close{background:none;border:none;font-size:22px;line-height:1;cursor:pointer;color:var(--c-text-muted);padding:0 4px}.modal-box__close:hover{color:var(--c-text)}.modal-box__body{padding:12px 16px;overflow-y:auto;flex:1} +@charset "UTF-8"; +:root { + --c-primary: #6690f4; + --c-primary-dark: #3164db; + --c-bg: #f4f6f9; + --c-surface: #ffffff; + --c-text: #4e5e6a; + --c-text-strong: #2d3748; + --c-muted: #718096; + --c-border: #b0bec5; + --c-danger: #cc0000; + --focus-ring: 0 0 0 3px rgba(102, 144, 244, 0.15); + --shadow-card: 0 1px 4px rgba(0, 0, 0, 0.06); +} + +.btn { + display: inline-flex; + align-items: center; + justify-content: center; + min-height: 34px; + padding: 6px 12px; + border: 1px solid transparent; + border-radius: 8px; + font: inherit; + font-weight: 600; + text-decoration: none; + cursor: pointer; + transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.1s ease; +} + +.btn--primary { + color: #ffffff; + background: var(--c-primary); +} + +.btn--primary:hover { + background: var(--c-primary-dark); +} + +.btn--secondary { + color: var(--c-text-strong); + border-color: var(--c-border); + background: var(--c-surface); +} + +.btn--secondary:hover { + border-color: #cbd5e0; + background: #f8fafc; +} + +.btn--danger { + color: #ffffff; + border-color: #b91c1c; + background: #dc2626; +} + +.btn--danger:hover { + border-color: #991b1b; + background: #b91c1c; +} + +.btn--sm { + min-height: 28px; + padding: 3px 10px; + font-size: 12px; +} + +.btn--block { + width: 100%; +} + +.btn--disabled { + opacity: 0.3; + cursor: not-allowed; + pointer-events: none; +} + +.btn:active { + transform: translateY(1px); +} + +.btn:focus-visible { + outline: none; + box-shadow: var(--focus-ring); + border-color: var(--c-primary); +} + +.form-control { + width: 100%; + min-height: 30px; + border: 1px solid var(--c-border); + border-radius: 6px; + padding: 4px 8px; + font: inherit; + color: var(--c-text-strong); + background: #ffffff; + transition: border-color 0.2s ease, box-shadow 0.2s ease; +} + +.form-control:focus { + outline: none; + border-color: var(--c-primary); + box-shadow: var(--focus-ring); +} + +.input { + min-height: 34px; + border: 1px solid var(--c-border); + border-radius: 8px; + padding: 5px 10px; + font: inherit; + color: var(--c-text-strong); + background: #ffffff; +} + +.input--sm { + min-height: 28px; + padding: 3px 8px; + font-size: 12px; +} + +.flash { + padding: 8px 12px; + border-radius: 6px; + font-size: 13px; +} + +.flash--success { + border: 1px solid #b7ebcf; + background: #f0fff6; + color: #0f6b39; +} + +.flash--error { + border: 1px solid #fed7d7; + background: #fff5f5; + color: var(--c-danger); +} + +.alert { + padding: 12px 14px; + border-radius: 8px; + border: 1px solid transparent; + font-size: 13px; + min-height: 44px; +} + +.alert--danger { + border-color: #fed7d7; + background: #fff5f5; + color: var(--c-danger); +} + +.alert--success { + border-color: #b7ebcf; + background: #f0fff6; + color: #0f6b39; +} + +.alert--warning { + border-color: #f7dd8b; + background: #fff8e8; + color: #815500; +} + +.form-field { + display: grid; + gap: 5px; +} + +.field-label { + color: var(--c-text-strong); + font-size: 13px; + font-weight: 600; +} + +.table-wrap { + width: 100%; + overflow-x: auto; +} +.table-wrap--visible { + overflow: visible !important; + overflow-x: visible !important; +} + +.table { + width: 100%; + border-collapse: collapse; + background: var(--c-surface); +} + +.table th, +.table td { + padding: 10px 12px; + border-bottom: 1px solid var(--c-border); + text-align: left; +} + +.table th { + color: var(--c-text-strong); + font-weight: 700; + background: #f8fafc; +} + +.table--details th { + white-space: nowrap; +} + +.table--details th:first-child, +.table--details td:first-child { + width: 36px; + text-align: center; +} + +.pagination { + display: flex; + align-items: center; + flex-wrap: wrap; + gap: 8px; +} + +.pagination__item { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 36px; + height: 36px; + padding: 0 10px; + border-radius: 8px; + border: 1px solid var(--c-border); + color: var(--c-text-strong); + background: var(--c-surface); + text-decoration: none; + font-weight: 600; +} + +.pagination__item:hover { + border-color: #cbd5e0; + background: #f8fafc; +} + +.pagination__item.is-active { + border-color: var(--c-primary); + color: var(--c-primary); + background: #edf2ff; +} + +.receipt-header { + display: flex; + justify-content: space-between; + align-items: flex-start; + margin-bottom: 16px; + padding-bottom: 12px; + border-bottom: 2px solid var(--c-text-strong); +} +.receipt-header__seller { + flex: 1; +} +.receipt-header__seller strong { + font-size: 14px; + display: block; + margin-bottom: 4px; +} +.receipt-header__title { + text-align: right; +} +.receipt-header__title h1 { + font-size: 18px; + font-weight: 700; + margin-bottom: 4px; +} + +.receipt-print { + max-width: 700px; + margin: 0 auto; +} +@media print { + .receipt-print { + max-width: 100%; + } +} + +.email-send-overlay { + position: fixed; + inset: 0; + z-index: 1000; + background: rgba(0, 0, 0, 0.5); + display: flex; + align-items: center; + justify-content: center; +} + +.email-send-modal { + background: var(--c-card-bg, #fff); + border-radius: 8px; + width: 580px; + max-width: 95vw; + max-height: 90vh; + display: flex; + flex-direction: column; + box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2); +} +.email-send-modal__header { + display: flex; + align-items: center; + justify-content: space-between; + padding: 12px 16px; + border-bottom: 1px solid var(--c-border, #e0e0e0); +} +.email-send-modal__header h3 { + margin: 0; + font-size: 15px; +} +.email-send-modal__close { + background: none; + border: none; + font-size: 20px; + cursor: pointer; + color: var(--c-text-muted, #888); + padding: 0 4px; +} +.email-send-modal__close:hover { + color: var(--c-text, #333); +} +.email-send-modal__body { + padding: 16px; + overflow-y: auto; + flex: 1; +} +.email-send-modal__field { + margin-bottom: 10px; +} +.email-send-modal__field label { + display: block; + font-size: 12px; + font-weight: 600; + margin-bottom: 4px; + color: var(--c-text-muted, #666); +} +.email-send-modal__field .input { + width: 100%; +} +.email-send-modal__actions-top { + margin-bottom: 10px; +} +.email-send-modal__footer { + display: flex; + justify-content: flex-end; + gap: 8px; + padding: 12px 16px; + border-top: 1px solid var(--c-border, #e0e0e0); +} + +.email-send-preview { + border: 1px solid var(--c-border, #e0e0e0); + border-radius: 4px; + padding: 12px; + max-height: 280px; + overflow-y: auto; + background: var(--c-bg, #fafafa); +} +.email-send-preview__subject { + font-weight: 600; + font-size: 13px; + margin-bottom: 8px; + padding-bottom: 8px; + border-bottom: 1px solid var(--c-border, #e0e0e0); +} +.email-send-preview__body { + font-size: 13px; + line-height: 1.5; +} +.email-send-preview__body p { + margin: 0 0 8px; +} +.email-send-preview__attachments { + margin-top: 8px; + padding-top: 8px; + border-top: 1px solid var(--c-border, #e0e0e0); + font-size: 12px; + color: var(--c-text-muted, #666); +} + +.section-header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; +} + +.automation-row { + display: flex; + align-items: flex-start; + gap: 8px; + padding: 10px 12px; + background: var(--c-surface, #f8f9fa); + border: 1px solid var(--c-border, #dee2e6); + border-radius: 6px; +} +.automation-row__fields { + flex: 1; + display: flex; + flex-direction: column; + gap: 6px; +} +.automation-row__type { + max-width: 280px; +} +.automation-row__config { + display: flex; + flex-wrap: wrap; + gap: 8px; +} +.automation-row__config .form-control { + min-width: 200px; + max-width: 300px; +} +.automation-row__remove { + flex-shrink: 0; + margin-top: 2px; + line-height: 1; + font-size: 16px; + padding: 2px 8px; +} + +.checkbox-group { + display: flex; + flex-wrap: wrap; + gap: 4px 16px; +} + +.checkbox-label { + display: flex; + align-items: center; + gap: 4px; + font-size: 13px; + cursor: pointer; + white-space: nowrap; +} +.checkbox-label input[type=checkbox] { + margin: 0; +} + +* { + box-sizing: border-box; +} + +html, +body { + min-height: 100%; +} + +body { + margin: 0; + font-family: "Roboto", "Segoe UI", sans-serif; + font-size: 13px; + color: var(--c-text); + background: var(--c-bg); +} + +a { + color: var(--c-primary); +} + +.app-shell { + min-height: 100vh; + display: flex; +} + +.sidebar { + width: 260px; + min-width: 260px; + flex-shrink: 0; + overflow: hidden; + transition: width 0.22s ease, min-width 0.22s ease; + border-right: 1px solid #243041; + background: #111a28; + padding: 18px 10px; + display: flex; + flex-direction: column; +} + +.sidebar.is-collapsed { + width: 52px; + min-width: 52px; +} + +.sidebar__brand { + display: flex; + align-items: center; + justify-content: space-between; + margin: 4px 4px 16px; + gap: 6px; + min-width: 0; +} + +.sidebar__brand-text { + color: #e9f0ff; + font-size: 24px; + font-weight: 300; + letter-spacing: -0.02em; + white-space: nowrap; + overflow: hidden; + flex: 1; + min-width: 0; +} +.sidebar__brand-text strong { + font-weight: 700; +} + +.sidebar__collapse-btn { + flex-shrink: 0; + width: 28px; + height: 28px; + display: flex; + align-items: center; + justify-content: center; + background: transparent; + border: 1px solid #2a3a54; + border-radius: 6px; + color: #64748b; + cursor: pointer; + padding: 0; + transition: background 0.15s, color 0.15s; +} +.sidebar__collapse-btn:hover { + background: #1b2a3f; + color: #cbd5e1; +} + +.sidebar__collapse-icon { + display: block; + transition: transform 0.22s ease; + flex-shrink: 0; +} + +.sidebar.is-collapsed .sidebar__collapse-icon { + transform: rotate(180deg); +} + +.sidebar__nav { + display: grid; + gap: 4px; +} + +.sidebar__link { + display: flex; + align-items: center; + gap: 9px; + white-space: nowrap; + border-radius: 8px; + padding: 9px 10px; + text-decoration: none; + color: #cbd5e1; + font-weight: 600; +} + +.sidebar__link:hover { + color: #f8fafc; + background: #1b2a3f; +} + +.sidebar__link.is-active { + color: #ffffff; + background: #2e4f93; +} + +.sidebar__group { + display: grid; + gap: 2px; +} + +.sidebar__group-toggle { + list-style: none; + border-radius: 8px; + padding: 9px 10px; + color: #cbd5e1; + font-weight: 600; + cursor: pointer; + display: flex; + align-items: center; + gap: 9px; + white-space: nowrap; + user-select: none; +} + +.sidebar__group-toggle::-webkit-details-marker { + display: none; +} + +.sidebar__group:hover .sidebar__group-toggle, +.sidebar__group-toggle:hover { + color: #f8fafc; + background: #1b2a3f; +} + +.sidebar__group.is-active .sidebar__group-toggle { + color: #ffffff; + background: #2e4f93; +} + +.sidebar__icon { + flex-shrink: 0; + width: 18px; + height: 18px; + display: flex; + align-items: center; + justify-content: center; + opacity: 0.85; +} + +.sidebar__label { + flex: 1; + min-width: 0; + overflow: hidden; +} + +.sidebar__toggle-arrow { + flex-shrink: 0; + margin-left: auto; + opacity: 0.5; + transition: transform 0.18s ease; +} + +details[open] > .sidebar__group-toggle .sidebar__toggle-arrow { + transform: rotate(180deg); +} + +.sidebar__group-links { + display: grid; + gap: 2px; + padding-left: 12px; + overflow: hidden; +} + +.sidebar__sublink { + border-radius: 6px; + padding: 7px 10px 7px 8px; + text-decoration: none; + color: #94a3b8; + font-size: 12.5px; + font-weight: 500; + display: flex; + align-items: center; + gap: 8px; + white-space: nowrap; +} +.sidebar__sublink::before { + content: ""; + flex-shrink: 0; + width: 5px; + height: 5px; + border-radius: 50%; + background: rgba(148, 163, 184, 0.3); + transition: background 0.15s; +} +.sidebar__sublink:hover { + color: #e2e8f0; + background: #1b2a3f; +} +.sidebar__sublink:hover::before { + background: rgba(148, 163, 184, 0.65); +} +.sidebar__sublink.is-active { + color: #ffffff; + background: rgba(46, 79, 147, 0.55); +} +.sidebar__sublink.is-active::before { + background: #93c5fd; +} + +.app-main { + flex: 1; + min-width: 0; +} + +.topbar { + height: 50px; + border-bottom: 1px solid var(--c-border); + background: var(--c-surface); + display: flex; + align-items: center; + justify-content: space-between; + padding: 0 20px; + position: sticky; + top: 0; + z-index: 100; +} + +.brand { + font-size: 22px; + font-weight: 300; + letter-spacing: -0.02em; + color: var(--c-text-strong); +} + +.brand strong { + font-weight: 700; +} + +.container { + max-width: none; + width: calc(100% - 20px); + margin: 12px 10px; + padding: 0 4px 14px; +} + +.card { + background: var(--c-surface); + border-radius: 10px; + box-shadow: var(--shadow-card); + padding: 14px; +} + +.card h1 { + margin: 0 0 10px; + color: var(--c-text-strong); + font-size: 24px; + font-weight: 700; +} + +.muted { + color: var(--c-muted); +} + +.accent { + color: var(--c-primary); + font-weight: 600; +} + +.users-form { + display: grid; + gap: 14px; + max-width: 460px; +} + +.form-field { + margin-bottom: 12px; +} + +.section-title { + margin: 0; + color: var(--c-text-strong); + font-size: 18px; + font-weight: 700; +} + +h2.section-title, +h3.section-title, +h4.section-title { + display: flex; + align-items: center; + gap: 6px; + font-weight: 600; + padding: 6px 0; + border-bottom: 1px solid #e2e8f0; + color: var(--c-primary, #2563eb); +} +h2.section-title::before, +h3.section-title::before, +h4.section-title::before { + content: "■"; + font-size: 0.55em; + opacity: 0.5; +} + +h3.section-title, +h4.section-title { + font-size: 15px; +} +h3.section-title::before, +h4.section-title::before { + content: "◆"; + font-size: 0.5em; +} + +.mt-0 { + margin-top: 0; +} + +.mt-4 { + margin-top: 4px; +} + +.mt-12 { + margin-top: 8px; +} + +.mt-16 { + margin-top: 12px; +} + +.settings-grid { + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 12px; +} + +.settings-nav { + display: flex; + gap: 8px; + flex-wrap: wrap; +} + +.settings-nav__link { + text-decoration: none; + border: 1px solid var(--c-border); + border-radius: 8px; + padding: 8px 12px; + color: var(--c-text-strong); + font-weight: 600; +} + +.settings-nav__link:hover { + background: #f8fafc; +} + +.settings-nav__link.is-active { + border-color: var(--c-primary); + color: var(--c-primary); + background: #edf2ff; +} + +.settings-stat { + border: 1px solid var(--c-border); + border-radius: 8px; + padding: 12px; + background: #f8fafc; +} + +.settings-stat__label { + display: block; + color: var(--c-muted); + font-size: 12px; + margin-bottom: 4px; +} + +.settings-stat__value { + color: var(--c-text-strong); + font-size: 20px; +} + +.settings-logs { + margin: 0; + padding: 12px; + border-radius: 8px; + border: 1px solid var(--c-border); + background: #0b1220; + color: #d1d5db; + font-size: 12px; + line-height: 1.5; + overflow: auto; +} + +.settings-allegro-callback { + display: block; + width: 100%; + padding: 8px 10px; + border: 1px solid var(--c-border); + border-radius: 8px; + background: #f8fafc; + color: var(--c-text-strong); + font-size: 12px; + line-height: 1.45; + word-break: break-all; +} + +.page-head { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; +} + +.filters-grid { + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 12px; +} + +.filters-actions { + display: flex; + align-items: center; + gap: 8px; +} + +.product-form .form-control { + width: 100%; +} + +.form-grid { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 12px; +} + +.form-grid-2 { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 12px; + align-items: start; +} + +.form-grid-3 { + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 12px; + align-items: start; +} + +.form-grid-4 { + display: grid; + grid-template-columns: repeat(4, minmax(0, 1fr)); + gap: 12px; + align-items: start; +} + +.form-actions { + display: flex; + gap: 8px; + flex-wrap: wrap; + align-items: flex-start; +} + +.form-actions .btn { + align-self: flex-start; +} + +.statuses-form { + display: grid; + gap: 8px; + grid-template-columns: repeat(2, minmax(0, 1fr)); +} + +.statuses-form .form-actions { + grid-column: 1/-1; +} + +.statuses-color-input { + min-height: 32px; + padding: 2px; +} + +.statuses-hint { + grid-column: 1/-1; + margin: 0; +} + +.statuses-group-block { + border: 1px solid var(--c-border); + border-radius: 10px; + padding: 8px; + background: #fbfdff; +} + +.statuses-group-block__head { + display: flex; + align-items: center; + justify-content: space-between; + gap: 6px; + flex-wrap: wrap; +} + +.statuses-group-block__title { + margin: 0; + display: inline-flex; + align-items: center; + gap: 6px; + color: var(--c-text-strong); + font-size: 14px; +} + +.statuses-color-dot { + width: 12px; + height: 12px; + border-radius: 999px; + border: 1px solid rgba(15, 23, 42, 0.15); +} + +.statuses-dnd-list { + margin: 6px 0 0; + padding: 0; + list-style: none; + display: grid; + gap: 6px; +} + +.statuses-dnd-item { + display: grid; + grid-template-columns: 24px 1fr; + gap: 6px; + border: 1px solid #dce4f0; + border-radius: 8px; + background: #fff; + padding: 6px; +} + +.statuses-dnd-item__content { + display: flex; + align-items: center; + gap: 6px; + min-width: 0; +} + +.statuses-dnd-item.is-dragging { + opacity: 0.6; +} + +.statuses-dnd-item__drag { + display: inline-flex; + align-items: center; + justify-content: center; + border: 1px dashed #cbd5e1; + border-radius: 6px; + color: #64748b; + cursor: grab; + user-select: none; + font-weight: 700; + font-size: 12px; +} + +.statuses-dnd-item__drag:active { + cursor: grabbing; +} + +.statuses-inline-form { + display: grid; + gap: 6px; +} + +.statuses-inline-form--row { + grid-template-columns: minmax(180px, 1.4fr) minmax(150px, 1fr) auto auto auto; + align-items: center; + flex: 1 1 auto; + min-width: 0; +} + +.statuses-inline-form--row-group { + grid-template-columns: minmax(180px, 1.5fr) 56px auto auto auto; + align-items: center; + flex: 1 1 auto; + min-width: 0; +} + +.statuses-inline-form--row .form-control, +.statuses-inline-form--row-group .form-control { + min-height: 30px; + padding: 4px 8px; +} + +.statuses-inline-form--row .btn, +.statuses-inline-form--row-group .btn, +.statuses-inline-delete .btn { + min-height: 30px; + padding: 4px 10px; + font-size: 12px; +} + +.statuses-inline-check { + margin-top: 0; + white-space: nowrap; + font-size: 12px; +} + +.statuses-inline-delete { + margin: 0; + flex: 0 0 auto; +} + +.statuses-code-label { + font-size: 12px; + color: var(--c-muted); +} + +.statuses-code-readonly { + display: inline-flex; + align-items: center; + gap: 6px; + white-space: nowrap; + font-size: 12px; +} + +.statuses-code-readonly code { + background: #eef2f7; + border-radius: 6px; + padding: 1px 6px; + color: #1f2937; + font-size: 12px; +} + +.field-inline { + display: flex; + align-items: center; + gap: 8px; + margin-top: 2px; +} + +.modal-backdrop { + position: fixed; + inset: 0; + background: rgba(15, 23, 42, 0.5); + display: flex; + align-items: center; + justify-content: center; + padding: 16px; + z-index: 200; +} + +.modal-backdrop[hidden] { + display: none; +} + +.modal { + width: min(560px, 100%); + background: #fff; + border-radius: 10px; + box-shadow: 0 20px 40px rgba(15, 23, 42, 0.35); + overflow: hidden; +} + +.modal__header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 10px; + padding: 16px 18px; + border-bottom: 1px solid var(--c-border); +} + +.modal__header h3 { + margin: 0; + font-size: 18px; + color: var(--c-text-strong); +} + +.modal__body { + padding: 16px 18px 18px; +} + +.status-pill { + display: inline-flex; + align-items: center; + justify-content: center; + border: 1px solid #fed7d7; + background: #fff5f5; + color: #9b2c2c; + padding: 2px 8px; + border-radius: 999px; + font-size: 12px; + font-weight: 600; +} + +.status-pill.is-active { + border-color: #b7ebcf; + background: #f0fff6; + color: #0f6b39; +} + +.table-row-actions { + display: inline-flex; + align-items: center; + gap: 6px; + flex-wrap: wrap; +} + +.table-row-actions form { + margin: 0; +} + +.table-list { + display: grid; + gap: 14px; +} + +.table-list__header { + display: flex; + justify-content: space-between; + align-items: center; + gap: 12px; + flex-wrap: wrap; +} + +.table-list__left { + display: inline-flex; + align-items: center; + gap: 8px; + flex-wrap: wrap; +} + +.table-list-header-actions { + display: inline-flex; + align-items: center; + gap: 10px; + flex-wrap: wrap; +} + +.js-filter-toggle-btn.is-active { + border-color: #cbd5e0; + background: #edf2ff; + color: var(--c-primary-dark); +} + +.table-filter-badge { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 18px; + height: 18px; + padding: 0 5px; + font-size: 11px; + font-weight: 700; + color: #fff; + background: var(--c-primary); + border-radius: 999px; +} + +.table-filters-wrapper { + display: none; +} + +.table-filters-wrapper.is-open { + display: block; +} + +.table-list-filters { + display: grid; + gap: 12px; + grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); + align-items: end; +} + +.table-col-toggle-wrapper { + position: relative; +} + +.table-col-toggle-dropdown { + display: none; + position: absolute; + right: 0; + top: calc(100% + 6px); + z-index: 30; + width: 260px; + max-height: 360px; + overflow: auto; + border: 1px solid var(--c-border); + border-radius: 10px; + background: #fff; + box-shadow: 0 10px 25px rgba(15, 23, 42, 0.12); +} + +.table-col-toggle-dropdown.is-open { + display: block; +} + +.table-col-toggle-header { + padding: 10px 12px; + border-bottom: 1px solid var(--c-border); + font-size: 12px; + font-weight: 700; + color: var(--c-muted); +} + +.table-col-toggle-item { + display: flex; + align-items: center; + gap: 10px; + padding: 8px 12px; + font-size: 13px; + color: var(--c-text-strong); +} + +.table-col-toggle-item:hover { + background: #f8fafc; +} + +.table-col-toggle-footer { + border-top: 1px solid var(--c-border); + padding: 8px 12px; +} + +.table-col-hidden { + display: none; +} + +.table-col-switch { + position: relative; + display: inline-block; + width: 34px; + min-width: 34px; + height: 18px; +} + +.table-col-switch input { + opacity: 0; + width: 0; + height: 0; + position: absolute; +} + +.table-col-switch-slider { + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + background: #cbd5e1; + border-radius: 999px; + transition: background-color 0.2s ease; +} + +.table-col-switch-slider::before { + content: ""; + position: absolute; + height: 14px; + width: 14px; + left: 2px; + bottom: 2px; + background: #fff; + border-radius: 50%; + transition: transform 0.2s ease; +} + +.table-col-switch input:checked + .table-col-switch-slider { + background: #16a34a; +} + +.table-col-switch input:checked + .table-col-switch-slider::before { + transform: translateX(16px); +} + +.table-sort-link { + display: inline-flex; + align-items: center; + gap: 6px; + color: var(--c-text-strong); + text-decoration: none; +} + +.table-sort-link:hover { + color: var(--c-primary-dark); +} + +.table-sort-icon.is-muted { + color: #a0aec0; +} + +.table-list__footer { + display: flex; + align-items: center; + justify-content: space-between; + gap: 10px; + flex-wrap: wrap; +} + +.table-list-per-page-form { + display: inline-flex; + align-items: center; + gap: 8px; +} + +.table-list-per-page-form .form-control { + min-width: 90px; +} + +.table-select-col { + width: 44px; + text-align: center; +} + +.table-select-toggle { + display: inline-flex; + align-items: center; + justify-content: center; +} + +.table-select-toggle input[type=checkbox] { + width: 16px; + height: 16px; +} + +.orders-page .orders-head { + background: linear-gradient(120deg, #f8fbff 0%, #eef5ff 100%); + border: 1px solid #dbe7fb; +} +.orders-page .table-list { + border: 1px solid #dde5f2; + border-radius: 12px; + box-shadow: 0 6px 16px rgba(20, 44, 86, 0.08); +} +.orders-page .table-list__header { + padding: 10px 6px 2px; +} +.orders-page .table-list-filters { + padding: 6px 6px 2px; + border-top: 1px solid #ebf0f7; + border-bottom: 1px solid #ebf0f7; + background: #f9fbff; +} +.orders-page .table-wrap { + border-radius: 10px; + overflow: hidden; + border: 1px solid #e7edf6; +} +.orders-page .table thead th { + background: #f3f7fd; + color: #30435f; + font-size: 12px; + text-transform: uppercase; + letter-spacing: 0.03em; +} +.orders-page .table tbody td { + vertical-align: middle; + padding-top: 10px; + padding-bottom: 10px; + border-bottom-color: #edf2f8; +} +.orders-page .table tbody tr:hover td { + background: #f9fcff; +} + +.orders-list-page { + padding: 10px; + margin-bottom: 10px; +} + +.orders-head { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 12px; + flex-wrap: wrap; +} + +.orders-stats { + display: inline-grid; + grid-template-columns: repeat(3, minmax(86px, auto)); + gap: 8px; +} + +.orders-stat { + border: 1px solid #d8e2f0; + background: #f8fbff; + border-radius: 8px; + padding: 6px 8px; + line-height: 1.15; +} +.orders-stat__label { + display: block; + color: #5f6f83; + font-size: 11px; + margin-bottom: 2px; +} +.orders-stat__value { + color: #12233a; + font-size: 16px; + font-weight: 700; +} + +.orders-ref { + display: grid; + gap: 2px; + min-width: 170px; +} +.orders-ref__main { + font-weight: 700; + color: #0f1f35; + font-size: 14px; +} +.orders-ref__meta { + display: inline-flex; + flex-wrap: wrap; + gap: 4px 10px; + color: #64748b; + font-size: 12px; +} + +.orders-buyer { + display: grid; + gap: 2px; +} +.orders-buyer__name { + color: #0f172a; + font-weight: 600; + font-size: 14px; +} +.orders-buyer__meta { + display: inline-flex; + flex-wrap: wrap; + gap: 4px 10px; + color: #64748b; + font-size: 12px; +} + +.orders-status-wrap { + display: inline-flex; + align-items: center; + gap: 5px; + flex-wrap: wrap; +} + +.order-tag { + display: inline-flex; + align-items: center; + justify-content: center; + border: 1px solid #d8e1ef; + background: #f8fafc; + color: #334155; + border-radius: 999px; + padding: 2px 8px; + font-size: 12px; + font-weight: 700; + line-height: 1.1; +} +.order-tag.is-info { + border-color: #bfdbfe; + background: #eff6ff; + color: #1d4ed8; +} +.order-tag.is-success { + border-color: #bbf7d0; + background: #f0fdf4; + color: #166534; +} +.order-tag.is-danger { + border-color: #fecaca; + background: #fef2f2; + color: #b91c1c; +} +.order-tag.is-warn { + border-color: #fde68a; + background: #fffbeb; + color: #92400e; +} +.order-tag.is-cod { + border-color: #f9a8d4; + background: #fdf2f8; + color: #9d174d; +} +.order-tag.is-unpaid { + border-color: #fca5a5; + background: #fef2f2; + color: #b91c1c; +} + +.orders-mini { + font-size: 14px; + color: #223247; + line-height: 1.25; +} +.orders-mini__delivery { + font-size: 12px; + color: #64748b; + margin-bottom: 2px; + max-width: 160px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.orders-products { + display: grid; + gap: 4px; + min-width: 240px; +} +.orders-products__meta, .orders-products__more { + font-size: 12px; + color: #64748b; +} + +.orders-product { + display: grid; + grid-template-columns: 48px 1fr; + gap: 6px; + align-items: center; +} +.orders-product__thumb { + width: 48px; + height: 48px; + border-radius: 4px; + border: 1px solid #dbe3ef; + object-fit: cover; + background: #fff; +} +.orders-product__thumb--empty { + display: inline-block; + background: #eef2f7; + border-style: dashed; +} +.orders-product__txt { + min-width: 0; + display: grid; + gap: 1px; +} +.orders-product__name { + font-size: 14px; + color: #0f172a; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} +.orders-product__qty { + font-size: 12px; + color: #64748b; +} + +.orders-image-hover-wrap { + position: relative; + display: inline-flex; + align-items: center; + justify-content: center; + cursor: zoom-in; +} + +.orders-image-hover-popup { + display: none; + position: fixed; + left: auto; + top: auto; + width: 350px; + max-height: 350px; + object-fit: contain; + border-radius: 8px; + background: #fff; + box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); + border: 1px solid #dfe3ea; + z-index: 100; + pointer-events: none; +} + +.orders-image-hover-wrap:hover .orders-image-hover-popup { + display: block; +} + +.activity-type-badge { + display: inline-block; + padding: 2px 8px; + border-radius: 4px; + font-size: 12px; + font-weight: 500; + white-space: nowrap; + background: #e2e8f0; + color: #334155; +} +.activity-type-badge--status_change { + background: #dbeafe; + color: #1e40af; +} +.activity-type-badge--payment { + background: #dcfce7; + color: #166534; +} +.activity-type-badge--invoice { + background: #fef3c7; + color: #92400e; +} +.activity-type-badge--shipment { + background: #e0e7ff; + color: #3730a3; +} +.activity-type-badge--message { + background: #f3e8ff; + color: #6b21a8; +} +.activity-type-badge--document { + background: #fce7f3; + color: #9d174d; +} +.activity-type-badge--import { + background: #f1f5f9; + color: #475569; +} +.activity-type-badge--note { + background: #ecfdf5; + color: #065f46; +} + +.text-nowrap { + white-space: nowrap; +} + +.orders-money { + display: grid; + gap: 2px; +} +.orders-money__main { + color: #0f172a; + font-weight: 700; + font-size: 14px; +} +.orders-money__meta { + color: #64748b; + font-size: 12px; +} + +.table-list[data-table-list-id=orders] { + gap: 8px; +} +.table-list[data-table-list-id=orders] .table-list__header { + padding: 2px 0 0; +} +.table-list[data-table-list-id=orders] .table-list-filters { + gap: 8px; + grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); +} +.table-list[data-table-list-id=orders] .table th, +.table-list[data-table-list-id=orders] .table td { + padding: 6px 8px; +} +.table-list[data-table-list-id=orders] .table thead th { + font-size: 12px; + text-transform: uppercase; + letter-spacing: 0.02em; + white-space: nowrap; +} +.table-list[data-table-list-id=orders] .table tbody td { + vertical-align: top; + font-size: 14px; + line-height: 1.25; +} + +.order-show-layout { + display: grid; + grid-template-columns: 220px minmax(0, 1fr); + gap: 12px; + align-items: start; +} + +.order-statuses-side { + position: sticky; + top: 60px; + padding: 10px; +} +.order-statuses-side__title { + font-size: 13px; + font-weight: 700; + color: #0f172a; + margin-bottom: 8px; +} + +.order-status-group { + margin-bottom: 10px; +} +.order-status-group__name { + font-size: 12px; + color: #475569; + font-weight: 700; + margin-bottom: 5px; +} + +.order-status-row { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; + padding: 4px 6px; + border-radius: 6px; + color: #334155; + font-size: 12px; + text-decoration: none; +} +.order-status-row__count { + min-width: 24px; + text-align: center; + border-radius: 999px; + background: var(--status-color, #64748b); + padding: 1px 6px; + font-weight: 700; + font-size: 11px; + color: #ffffff; +} + +.order-status-row:hover { + background: #f1f5f9; +} + +.order-status-row.is-active { + background: rgba(15, 23, 42, 0.06); + color: #0f172a; + font-weight: 700; +} + +.order-show-main { + min-width: 0; +} + +.order-details-actions { + display: inline-flex; + flex-wrap: wrap; + justify-content: flex-end; + gap: 6px; +} + +.order-details-page { + padding: 12px; +} + +.order-details-head { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 12px; + flex-wrap: wrap; +} + +.order-back-link { + color: #475569; + text-decoration: none; + font-weight: 600; +} + +.order-back-link:hover { + color: #1d4ed8; +} + +.order-details-sub { + display: inline-flex; + gap: 10px; + flex-wrap: wrap; + color: #64748b; + font-size: 12px; +} + +.order-details-pill { + border-radius: 999px; + padding: 5px 10px; + background: #eef6ff; + border: 1px solid #cfe2ff; + color: #1d4ed8; + font-size: 12px; + font-weight: 700; +} + +.order-status-change { + display: flex; + align-items: center; + gap: 10px; + flex-wrap: wrap; +} + +.order-status-change__form { + display: flex; + align-items: center; + gap: 6px; +} + +.order-status-change__select { + min-width: 180px; +} + +.order-details-tabs { + display: flex; + gap: 6px; + flex-wrap: wrap; +} + +.order-details-tab { + border: 1px solid #d6deea; + border-radius: 8px; + padding: 5px 10px; + color: #475569; + font-size: 12px; + background: #f8fafc; + cursor: pointer; +} + +.order-details-tab.is-active { + border-color: #bfdbfe; + color: #1d4ed8; + background: #eff6ff; + font-weight: 700; +} + +.order-item-cell { + display: grid; + grid-template-columns: 44px 1fr; + gap: 8px; + align-items: center; + min-width: 260px; +} + +.order-item-thumb { + width: 44px; + height: 44px; + border-radius: 6px; + border: 1px solid #dbe3ef; + object-fit: cover; +} + +.order-item-thumb--empty { + display: inline-block; + background: #eef2f7; + border-style: dashed; +} + +.order-item-name { + font-weight: 600; + color: #0f172a; +} + +.order-grid-2 { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 12px; +} + +.order-grid-3 { + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 12px; +} + +.order-kv { + margin: 0; + display: grid; + grid-template-columns: 150px 1fr; + gap: 6px 10px; + font-size: 12px; +} + +.payment-summary { + display: grid; + gap: 6px; + max-width: 420px; +} + +.payment-summary__row { + display: flex; + align-items: center; + gap: 10px; + font-size: 12px; +} + +.payment-summary__label { + width: 150px; + flex-shrink: 0; + color: #64748b; +} + +.payment-summary__value { + font-weight: 600; + color: #0f172a; +} + +.order-kv dt { + color: #64748b; +} + +.order-kv dd { + margin: 0; + color: #0f172a; + font-weight: 600; +} + +.order-address { + display: grid; + gap: 3px; + font-size: 12px; + color: #0f172a; +} + +.order-events { + display: grid; + gap: 8px; +} + +.order-event { + border: 1px solid #e2e8f0; + border-radius: 8px; + padding: 8px; + background: #fbfdff; +} + +.order-event__head { + color: #64748b; + font-size: 11px; +} + +.order-event__body { + margin-top: 4px; + color: #0f172a; + font-size: 12px; +} + +.order-tab-panel { + display: none; +} + +.order-tab-panel.is-active { + display: block; +} + +.order-empty-placeholder { + border: 1px dashed #cbd5e1; + border-radius: 8px; + min-height: 180px; + background: #f8fafc; +} + +.order-status-badge { + display: inline-flex; + align-items: center; + justify-content: center; + padding: 4px 10px; + border-radius: 999px; + font-size: 12px; + font-weight: 700; + border: 1px solid #cbd5e1; + color: #334155; + background: #f8fafc; +} +.order-status-badge.is-info { + border-color: #bfdbfe; + background: #eff6ff; + color: #1d4ed8; +} +.order-status-badge.is-success { + border-color: #bbf7d0; + background: #f0fdf4; + color: #166534; +} +.order-status-badge.is-danger { + border-color: #fecaca; + background: #fef2f2; + color: #b91c1c; +} +.order-status-badge.is-warn { + border-color: #fde68a; + background: #fffbeb; + color: #92400e; +} +.order-status-badge.is-empty { + color: #94a3b8; +} + +.order-buyer { + display: grid; + gap: 2px; +} +.order-buyer__name { + color: #0f172a; + font-weight: 600; +} +.order-buyer__email { + color: #64748b; + font-size: 12px; +} + +.table-inline-action { + display: inline-block; + margin-right: 6px; +} + +.product-name-cell { + display: inline-flex; + align-items: center; + gap: 10px; +} + +.product-name-thumb { + width: 60px; + height: 60px; + border-radius: 6px; + object-fit: cover; + border: 1px solid var(--c-border); + background: #f8fafc; +} + +.product-name-thumb--empty { + display: inline-block; + width: 60px; + height: 60px; + border-radius: 6px; + border: 1px dashed #cbd5e0; + background: #f8fafc; +} + +.product-name-thumb-btn { + border: 0; + padding: 0; + background: transparent; + cursor: pointer; + display: inline-flex; + align-items: center; + justify-content: center; +} + +.product-name-thumb-btn:focus-visible { + outline: none; + box-shadow: var(--focus-ring); + border-radius: 8px; +} + +.modal--image-preview { + width: min(760px, 100%); +} + +.product-image-preview__img { + display: block; + width: 100%; + max-height: 70vh; + object-fit: contain; + border-radius: 8px; + background: #f8fafc; +} + +.product-images-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); + gap: 12px; +} + +.product-image-card { + border: 1px solid #dfe3ea; + border-radius: 10px; + padding: 10px; + background: #fff; +} + +.product-image-card__thumb-wrap { + position: relative; + border-radius: 8px; + overflow: hidden; + background: #f2f5f8; +} + +.product-image-card__thumb { + width: 100%; + height: 160px; + object-fit: cover; + display: block; +} + +.product-image-card__thumb.is-empty { + height: 160px; + display: grid; + place-items: center; + color: #6b7785; + font-size: 12px; +} + +.product-image-card__badge { + display: none; + position: absolute; + top: 8px; + left: 8px; + background: #1f7a43; + color: #fff; + padding: 3px 8px; + border-radius: 999px; + font-size: 11px; +} + +.product-image-card.is-main .product-image-card__badge { + display: inline-block; +} + +.product-image-card__meta { + margin-top: 8px; + font-size: 11px; + line-height: 1.25; + color: #5f6b79; + overflow-wrap: anywhere; +} + +.product-image-card__actions { + margin-top: 10px; + display: grid; + grid-template-columns: 1fr; + gap: 8px; +} + +.product-image-card__actions .btn { + min-height: 34px; + font-size: 12px; + line-height: 1.2; + padding: 6px 10px; +} + +.product-links-search-form { + display: grid; + gap: 12px; + grid-template-columns: minmax(220px, 320px) minmax(220px, 1fr) auto; + align-items: end; +} + +.product-links-head { + display: grid; + gap: 8px; + grid-template-columns: repeat(3, minmax(0, 1fr)); +} + +.product-tabs-nav { + display: flex; + align-items: center; + gap: 8px; + flex-wrap: wrap; +} + +.product-links-inline-form { + display: grid; + gap: 8px; + grid-template-columns: minmax(140px, 1fr) minmax(140px, 1fr) auto; + align-items: center; +} + +.product-links-actions-row { + display: flex; + align-items: center; + gap: 8px; + flex-wrap: nowrap; +} + +.product-links-actions-row .product-links-relink-form { + flex: 1 1 auto; +} + +.product-links-unlink-form { + margin: 0; + flex: 0 0 auto; +} + +.product-link-status-cell { + display: inline-flex; + align-items: center; + gap: 6px; +} + +.product-link-alert-indicator { + display: inline-flex; + align-items: center; + justify-content: center; + width: 18px; + height: 18px; + border-radius: 999px; + border: 1px solid #f59e0b; + background: #fffbeb; + color: #b45309; + font-size: 12px; + font-weight: 700; + cursor: help; +} + +.product-link-events-list { + margin: 0; + padding: 0; + list-style: none; + display: grid; + gap: 4px; +} + +.product-link-events-list li { + display: grid; + gap: 2px; +} + +.product-link-events-type { + font-weight: 600; + color: var(--c-text-strong); +} + +.product-link-events-date { + color: var(--c-muted); + font-size: 12px; +} + +.product-show-images-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); + gap: 12px; +} + +.product-show-image-card { + border: 1px solid var(--c-border); + border-radius: 10px; + background: #fff; + padding: 10px; + overflow: hidden; +} +.product-show-image-card__meta { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 8px; + min-width: 0; +} + +.product-show-image-path { + font-size: 12px; + min-width: 0; + overflow: hidden; +} +.product-show-image-path summary { + cursor: pointer; + color: var(--c-muted, #888); + list-style: none; + user-select: none; + white-space: nowrap; +} +.product-show-image-path summary::-webkit-details-marker { + display: none; +} +.product-show-image-path summary::after { + content: " ▾"; +} +.product-show-image-path[open] summary::after { + content: " ▴"; +} +.product-show-image-path__url { + margin-top: 4px; + word-break: break-all; + overflow-wrap: break-word; + font-size: 11px; +} + +.product-show-image { + width: 100%; + max-height: 260px; + object-fit: cover; + border-radius: 8px; + border: 1px solid #d9e0ea; +} + +.shipment-grid { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 12px; +} + +.searchable-select { + position: relative; +} +.searchable-select__trigger { + display: flex; + align-items: center; + justify-content: space-between; + cursor: pointer; + user-select: none; + min-height: 34px; +} +.searchable-select__trigger::after { + content: ""; + width: 0; + height: 0; + border-left: 4px solid transparent; + border-right: 4px solid transparent; + border-top: 5px solid var(--c-text-muted, #6b7280); + margin-left: 8px; + flex-shrink: 0; +} +.searchable-select__trigger--placeholder { + color: var(--c-text-muted, #6b7280); +} +.searchable-select__dropdown { + display: none; + position: absolute; + left: 0; + right: 0; + top: 100%; + z-index: 50; + max-height: 280px; + overflow: auto; + background: #fff; + border: 1px solid var(--c-border); + border-top: 0; + border-radius: 0 0 8px 8px; + box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12); +} +.searchable-select__dropdown.is-open { + display: block; +} +.searchable-select__search { + position: sticky; + top: 0; + border: none !important; + border-bottom: 1px solid var(--c-border) !important; + border-radius: 0 !important; + box-shadow: none !important; + font-size: 13px; + background: #fff; + z-index: 1; +} +.searchable-select__option { + padding: 7px 10px; + font-size: 13px; + cursor: pointer; + color: var(--c-text-strong); +} +.searchable-select__option:hover { + background: #f1f5f9; +} +.searchable-select__option.is-selected { + background: #edf2ff; + font-weight: 600; +} + +.flash { + padding: 10px 14px; + border-radius: 8px; + font-size: 13px; + font-weight: 500; +} +.flash--success { + background: #f0fdf4; + border: 1px solid #bbf7d0; + color: #166534; +} +.flash--error { + background: #fef2f2; + border: 1px solid #fecaca; + color: #b91c1c; +} + +.content-tabs-card { + margin-top: 0; +} + +.content-tabs-nav { + display: flex; + gap: 4px; + border-bottom: 2px solid var(--c-border); + margin-bottom: 16px; + flex-wrap: wrap; +} + +.content-tab-btn { + padding: 8px 16px; + border: none; + background: none; + cursor: pointer; + font-size: 14px; + font-weight: 500; + color: var(--c-text-muted, #6b7280); + border-bottom: 2px solid transparent; + margin-bottom: -2px; + border-radius: 4px 4px 0 0; + transition: color 0.15s, border-color 0.15s; +} +.content-tab-btn:hover { + color: var(--c-text-strong, #111827); +} +.content-tab-btn.is-active { + color: var(--c-primary, #2563eb); + border-bottom-color: var(--c-primary, #2563eb); +} + +.content-tab-panel { + display: none; +} +.content-tab-panel.is-active { + display: block; +} + +.shoppro-tabs-toolbar { + display: flex; + align-items: flex-end; + justify-content: space-between; + gap: 10px; + margin-bottom: 10px; + flex-wrap: wrap; +} + +.shoppro-tabs-toolbar__field { + margin: 0; + min-width: 260px; + max-width: 420px; + flex: 1 1 320px; +} + +.shoppro-tabs-toolbar__field .form-control { + width: 100%; +} + +.shoppro-tabs-toolbar__actions { + display: inline-flex; + align-items: center; + gap: 8px; +} + +.dm-carrier-select { + min-width: 140px; +} + +.dm-service-wrap { + min-width: 200px; +} +.dm-service-wrap .dm-inpost-panel .form-control, +.dm-service-wrap .dm-apaczka-panel .form-control { + width: 100%; +} + +.integration-settings-group { + grid-column: 1/-1; + border: 1px solid var(--c-border); + border-radius: 10px; + background: #f8fbff; + padding: 10px; +} + +.integration-settings-group__head { + margin-bottom: 8px; + padding: 4px 0; + border-bottom: 1px solid #e2e8f0; +} + +.integration-settings-group__title { + margin: 0; + font-size: 14px; + font-weight: 600; + letter-spacing: 0.01em; + color: var(--c-text-strong, #1e293b); +} + +.integration-settings-group__desc { + margin: 4px 0 0; + color: #4b5563; +} + +.integration-settings-group__grid { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 10px 12px; + align-items: start; +} + +.integration-settings-group__full { + grid-column: 1/-1; +} + +.integration-settings-group__grid .form-field { + margin: 0; + align-self: start; +} + +.integration-settings-group__grid .form-control { + min-height: 34px; + height: 34px; +} + +.integration-settings-group__grid input[type=date].form-control { + line-height: 1.2; +} + +.integration-settings-checkboxes { + border: 0; + padding: 0; + margin: 0; +} + +.integration-settings-checkboxes .field-label { + display: block; + margin-bottom: 2px; +} + +.integration-settings-checkboxes__list { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 6px 12px; +} + +.integration-settings-checkboxes__item { + display: inline-flex; + align-items: center; + gap: 6px; + font-size: 13px; + color: #334155; +} + +@media (max-width: 768px) { + .app-shell { + flex-direction: column; + } + .sidebar { + width: 100% !important; + min-width: 0 !important; + border-right: 0; + border-bottom: 1px solid #243041; + padding: 14px; + overflow-x: auto; + } + .sidebar__brand { + margin: 0 0 10px; + font-size: 22px; + } + .sidebar__collapse-btn { + display: none; + } + .sidebar__nav { + display: flex; + gap: 8px; + overflow-x: auto; + } + .sidebar__link { + white-space: nowrap; + } + .topbar { + padding: 0 14px; + } + .container { + margin-top: 16px; + width: calc(100% - 16px); + margin-left: 8px; + margin-right: 8px; + padding: 0 3px 12px; + } + .settings-grid { + grid-template-columns: 1fr; + } + .page-head { + flex-direction: column; + align-items: flex-start; + } + .orders-stats { + grid-template-columns: 1fr; + width: 100%; + } + .order-show-layout { + grid-template-columns: 1fr; + } + .order-statuses-side { + position: static; + top: auto; + } + .order-details-actions { + justify-content: flex-start; + } + .order-grid-2, + .order-grid-3 { + grid-template-columns: 1fr; + } + .order-kv { + grid-template-columns: 1fr; + gap: 2px; + } + .filters-grid, + .form-grid, + .form-grid-2, + .form-grid-3, + .form-grid-4, + .shipment-grid, + .statuses-form, + .statuses-inline-form, + .table-list-filters, + .product-links-search-form, + .product-links-inline-form { + grid-template-columns: 1fr; + } + .statuses-dnd-item__content { + display: block; + } + .statuses-inline-delete { + margin-top: 6px; + } + .filters-actions { + align-items: center; + } + .table-list__header, + .table-list__footer { + align-items: flex-start; + } + .product-links-head { + grid-template-columns: 1fr; + } + .integration-settings-group__grid { + grid-template-columns: 1fr; + } + .integration-settings-checkboxes__list { + grid-template-columns: 1fr; + } + .card { + padding: 12px; + } + .modal--image-preview { + width: min(92vw, 100%); + } + .email-tpl-editor-wrap { + flex-direction: column; + } + .email-tpl-var-panel { + min-width: 200px; + } + .modal-box { + width: 95vw; + max-height: 90vh; + } +} +.email-tpl-editor-wrap { + display: flex; + flex-direction: column; + border: 1px solid var(--c-border); + border-radius: 6px; + overflow: hidden; +} + +.email-tpl-toolbar { + display: flex; + align-items: center; + gap: 6px; + padding: 6px 8px; + background: var(--c-bg-subtle, #f8f9fa); + border-bottom: 1px solid var(--c-border); +} + +.email-tpl-var-dropdown { + position: relative; +} + +.email-tpl-var-panel { + position: absolute; + top: 100%; + left: 0; + z-index: 50; + min-width: 260px; + max-height: 320px; + overflow-y: auto; + background: var(--c-bg); + border: 1px solid var(--c-border); + border-radius: 6px; + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12); + padding: 6px; + margin-top: 4px; +} + +.email-var-group:not(:first-child) { + margin-top: 6px; + padding-top: 6px; + border-top: 1px solid var(--c-border); +} +.email-var-group__label { + font-size: 11px; + font-weight: 600; + text-transform: uppercase; + color: var(--c-text-muted); + padding: 2px 4px; + letter-spacing: 0.03em; +} + +.email-var-item { + display: block; + width: 100%; + text-align: left; + padding: 3px 6px; + margin: 1px 0; + border: none; + background: none; + font-size: 12px; + font-family: "Roboto Mono", monospace; + color: var(--c-text); + border-radius: 3px; + cursor: pointer; +} +.email-var-item:hover { + background: var(--c-primary); + color: #fff; +} + +#js-quill-editor { + min-height: 200px; +} +#js-quill-editor .ql-editor { + min-height: 200px; + font-size: 13px; +} + +.modal-overlay { + position: fixed; + inset: 0; + z-index: 1000; + display: flex; + align-items: center; + justify-content: center; + background: rgba(0, 0, 0, 0.45); +} + +.modal-box { + width: min(680px, 90vw); + max-height: 80vh; + background: var(--c-bg); + border-radius: 8px; + box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2); + display: flex; + flex-direction: column; + overflow: hidden; +} +.modal-box__header { + display: flex; + align-items: center; + justify-content: space-between; + padding: 10px 16px; + border-bottom: 1px solid var(--c-border); +} +.modal-box__title { + margin: 0; + font-size: 15px; + font-weight: 600; +} +.modal-box__close { + background: none; + border: none; + font-size: 22px; + line-height: 1; + cursor: pointer; + color: var(--c-text-muted); + padding: 0 4px; +} +.modal-box__close:hover { + color: var(--c-text); +} +.modal-box__body { + padding: 12px 16px; + overflow-y: auto; + flex: 1; +} diff --git a/public/assets/js/modules/automation-form.js b/public/assets/js/modules/automation-form.js new file mode 100644 index 0000000..94f75a8 --- /dev/null +++ b/public/assets/js/modules/automation-form.js @@ -0,0 +1,132 @@ +(function() { + 'use strict'; + + var conditionsContainer = document.getElementById('js-conditions-container'); + var actionsContainer = document.getElementById('js-actions-container'); + var addConditionBtn = document.getElementById('js-add-condition'); + var addActionBtn = document.getElementById('js-add-action'); + var data = window.AutomationFormData || { integrations: [], emailTemplates: [], recipientLabels: {} }; + + function getNextIndex(container) { + var rows = container.querySelectorAll('.automation-row'); + var maxIdx = -1; + rows.forEach(function(row) { + var idx = parseInt(row.getAttribute('data-index') || '0', 10); + if (idx > maxIdx) maxIdx = idx; + }); + return maxIdx + 1; + } + + function escapeHtml(str) { + var div = document.createElement('div'); + div.textContent = str; + return div.innerHTML; + } + + function buildIntegrationCheckboxes(namePrefix) { + var html = '
'; + data.integrations.forEach(function(integ) { + html += ''; + }); + html += '
'; + return html; + } + + function buildEmailActionConfig(namePrefix) { + var html = ''; + + html += ''; + + return html; + } + + function addCondition() { + var idx = getNextIndex(conditionsContainer); + var namePrefix = 'conditions[' + idx + ']'; + + var row = document.createElement('div'); + row.className = 'automation-row mt-8'; + row.setAttribute('data-index', idx); + + row.innerHTML = '
' + + '' + + '
' + + buildIntegrationCheckboxes(namePrefix) + + '
' + + '
' + + ''; + + conditionsContainer.appendChild(row); + } + + function addAction() { + var idx = getNextIndex(actionsContainer); + var namePrefix = 'actions[' + idx + ']'; + + var row = document.createElement('div'); + row.className = 'automation-row mt-8'; + row.setAttribute('data-index', idx); + + row.innerHTML = '
' + + '' + + '
' + + buildEmailActionConfig(namePrefix) + + '
' + + '
' + + ''; + + actionsContainer.appendChild(row); + } + + function removeRow(btn) { + var row = btn.closest('.automation-row'); + if (row) row.remove(); + } + + function onConditionTypeChange(select) { + var row = select.closest('.automation-row'); + var configDiv = row.querySelector('.automation-row__config'); + var idx = row.getAttribute('data-index'); + var namePrefix = 'conditions[' + idx + ']'; + + if (select.value === 'integration') { + configDiv.innerHTML = buildIntegrationCheckboxes(namePrefix); + } + } + + function onActionTypeChange(select) { + var row = select.closest('.automation-row'); + var configDiv = row.querySelector('.automation-row__config'); + var idx = row.getAttribute('data-index'); + var namePrefix = 'actions[' + idx + ']'; + + if (select.value === 'send_email') { + configDiv.innerHTML = buildEmailActionConfig(namePrefix); + } + } + + if (addConditionBtn) addConditionBtn.addEventListener('click', addCondition); + if (addActionBtn) addActionBtn.addEventListener('click', addAction); + + window.AutomationForm = { + removeRow: removeRow, + onConditionTypeChange: onConditionTypeChange, + onActionTypeChange: onActionTypeChange + }; +})(); diff --git a/resources/scss/app.scss b/resources/scss/app.scss index b6d9b74..531d532 100644 --- a/resources/scss/app.scss +++ b/resources/scss/app.scss @@ -1,5 +1,6 @@ @use "shared/ui-components"; @use "modules/email-send"; +@use "modules/automation"; * { box-sizing: border-box; diff --git a/resources/scss/modules/_automation.scss b/resources/scss/modules/_automation.scss new file mode 100644 index 0000000..c88fe4b --- /dev/null +++ b/resources/scss/modules/_automation.scss @@ -0,0 +1,65 @@ +.section-header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; +} + +.automation-row { + display: flex; + align-items: flex-start; + gap: 8px; + padding: 10px 12px; + background: var(--c-surface, #f8f9fa); + border: 1px solid var(--c-border, #dee2e6); + border-radius: 6px; + + &__fields { + flex: 1; + display: flex; + flex-direction: column; + gap: 6px; + } + + &__type { + max-width: 280px; + } + + &__config { + display: flex; + flex-wrap: wrap; + gap: 8px; + + .form-control { + min-width: 200px; + max-width: 300px; + } + } + + &__remove { + flex-shrink: 0; + margin-top: 2px; + line-height: 1; + font-size: 16px; + padding: 2px 8px; + } +} + +.checkbox-group { + display: flex; + flex-wrap: wrap; + gap: 4px 16px; +} + +.checkbox-label { + display: flex; + align-items: center; + gap: 4px; + font-size: 13px; + cursor: pointer; + white-space: nowrap; + + input[type="checkbox"] { + margin: 0; + } +} diff --git a/resources/views/automation/form.php b/resources/views/automation/form.php new file mode 100644 index 0000000..e45bed6 --- /dev/null +++ b/resources/views/automation/form.php @@ -0,0 +1,139 @@ + 'Utworzono paragon', +]; + +$recipientLabels = [ + 'client' => 'Klient', + 'client_and_company' => 'Klient + e-mail z danych firmy', + 'company' => 'E-mail z danych firmy', +]; +?> + +
+

+ + + + + +
+ + + + + +
+ + +
+ +
+ +
+ +

Warunki

+

Wszystkie warunki musza byc spelnione (AND).

+ +
+ 0): ?> + $cond): ?> +
+
+ +
+ +
+ + + +
+
+
+ +
+ + +
+ + +

Akcje

+

Wszystkie akcje zostana wykonane po kolei.

+ +
+ 0): ?> + $act): ?> +
+
+ +
+ + + +
+
+ +
+ + +
+ + +
+ + Anuluj +
+
+
+ + + diff --git a/resources/views/automation/index.php b/resources/views/automation/index.php new file mode 100644 index 0000000..03cde15 --- /dev/null +++ b/resources/views/automation/index.php @@ -0,0 +1,96 @@ + 'Utworzono paragon', +]; +?> + +
+
+

Zadania automatyczne

+ Dodaj zadanie +
+

Reguły automatyzacji wykonywane po wystąpieniu zdarzenia.

+ + + + + +
+ +
+ +
+ +

Brak zadan automatycznych. Kliknij “Dodaj zadanie” aby utworzyc pierwsza regule.

+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
NazwaZdarzenieWarunkowAkcjiStatusAkcje
+ + Aktywne + + Nieaktywne + + + Edytuj +
+ + + +
+
+ + + +
+
+
+ +
+ + diff --git a/resources/views/layouts/app.php b/resources/views/layouts/app.php index ef0cfa7..840423f 100644 --- a/resources/views/layouts/app.php +++ b/resources/views/layouts/app.php @@ -101,6 +101,9 @@ Szablony e-mail + + Zadania automatyczne +
diff --git a/routes/web.php b/routes/web.php index 229f619..fbc7e79 100644 --- a/routes/web.php +++ b/routes/web.php @@ -47,6 +47,9 @@ use App\Modules\Email\VariableResolver; use App\Modules\Accounting\AccountingController; use App\Modules\Accounting\ReceiptController; use App\Modules\Accounting\ReceiptRepository; +use App\Modules\Automation\AutomationController; +use App\Modules\Automation\AutomationRepository; +use App\Modules\Automation\AutomationService; use App\Modules\Settings\CronSettingsController; use App\Modules\Settings\SettingsController; use App\Modules\Shipments\ApaczkaShipmentService; @@ -209,6 +212,13 @@ return static function (Application $app): void { $emailTemplateRepository, $emailMailboxRepository ); + $automationRepository = new AutomationRepository($app->db()); + $automationController = new AutomationController( + $template, + $translator, + $auth, + $automationRepository + ); $variableResolver = new VariableResolver(); $attachmentGenerator = new AttachmentGenerator($receiptRepository, $receiptConfigRepository, $template); $emailSendingService = new EmailSendingService( @@ -219,6 +229,12 @@ return static function (Application $app): void { $variableResolver, $attachmentGenerator ); + $automationService = new AutomationService( + $automationRepository, + $emailSendingService, + new OrdersRepository($app->db()), + $companySettingsRepository + ); $ordersController = new OrdersController($template, $translator, $auth, $app->orders(), $shipmentPackageRepositoryForOrders, $receiptRepository, $receiptConfigRepository, $emailSendingService, $emailTemplateRepository, $emailMailboxRepository); $receiptController = new ReceiptController( $template, @@ -227,7 +243,8 @@ return static function (Application $app): void { $receiptRepository, $receiptConfigRepository, $companySettingsRepository, - new OrdersRepository($app->db()) + new OrdersRepository($app->db()), + $automationService ); $accountingController = new AccountingController( $template, @@ -356,6 +373,13 @@ return static function (Application $app): void { $router->post('/settings/email-templates/toggle', [$emailTemplateController, 'toggleStatus'], [$authMiddleware]); $router->post('/settings/email-templates/preview', [$emailTemplateController, 'preview'], [$authMiddleware]); $router->get('/settings/email-templates/variables', [$emailTemplateController, 'getVariables'], [$authMiddleware]); + $router->get('/settings/automation', [$automationController, 'index'], [$authMiddleware]); + $router->get('/settings/automation/create', [$automationController, 'create'], [$authMiddleware]); + $router->post('/settings/automation/store', [$automationController, 'store'], [$authMiddleware]); + $router->get('/settings/automation/edit', [$automationController, 'edit'], [$authMiddleware]); + $router->post('/settings/automation/update', [$automationController, 'update'], [$authMiddleware]); + $router->post('/settings/automation/delete', [$automationController, 'destroy'], [$authMiddleware]); + $router->post('/settings/automation/toggle', [$automationController, 'toggleStatus'], [$authMiddleware]); $router->get('/accounting', [$accountingController, 'index'], [$authMiddleware]); $router->post('/accounting/export', [$accountingController, 'export'], [$authMiddleware]); $router->get('/orders/{id}/receipt/create', [$receiptController, 'create'], [$authMiddleware]); diff --git a/src/Modules/Accounting/ReceiptController.php b/src/Modules/Accounting/ReceiptController.php index b8d2126..cd1edfc 100644 --- a/src/Modules/Accounting/ReceiptController.php +++ b/src/Modules/Accounting/ReceiptController.php @@ -10,6 +10,7 @@ use App\Core\Security\Csrf; use App\Core\Support\Flash; use App\Core\View\Template; use App\Modules\Auth\AuthService; +use App\Modules\Automation\AutomationService; use App\Modules\Orders\OrdersRepository; use App\Modules\Settings\CompanySettingsRepository; use App\Modules\Settings\ReceiptConfigRepository; @@ -24,7 +25,8 @@ final class ReceiptController private readonly ReceiptRepository $receipts, private readonly ReceiptConfigRepository $receiptConfigs, private readonly CompanySettingsRepository $companySettings, - private readonly OrdersRepository $orders + private readonly OrdersRepository $orders, + private readonly AutomationService $automation ) { } @@ -189,6 +191,12 @@ final class ReceiptController ); Flash::set('order.success', 'Paragon wystawiony: ' . $receiptNumber); + + try { + $this->automation->trigger('receipt.created', $orderId); + } catch (Throwable) { + // Blad automatyzacji nie blokuje sukcesu paragonu + } } catch (Throwable) { Flash::set('order.error', 'Blad wystawiania paragonu'); } diff --git a/src/Modules/Automation/AutomationController.php b/src/Modules/Automation/AutomationController.php new file mode 100644 index 0000000..f3da42a --- /dev/null +++ b/src/Modules/Automation/AutomationController.php @@ -0,0 +1,346 @@ +repository->findAll(); + + $html = $this->template->render('automation/index', [ + 'title' => 'Zadania automatyczne', + 'activeMenu' => 'settings', + 'activeSettings' => 'automation', + 'user' => $this->auth->user(), + 'csrfToken' => Csrf::token(), + 'rules' => $rules, + 'successMessage' => Flash::get('settings.automation.success', ''), + 'errorMessage' => Flash::get('settings.automation.error', ''), + ], 'layouts/app'); + + return Response::html($html); + } + + public function create(Request $request): Response + { + return $this->renderForm(null); + } + + public function edit(Request $request): Response + { + $id = (int) $request->input('id', '0'); + $rule = $id > 0 ? $this->repository->findById($id) : null; + + if ($rule === null) { + Flash::set('settings.automation.error', 'Nie znaleziono reguly'); + return Response::redirect('/settings/automation'); + } + + return $this->renderForm($rule); + } + + public function store(Request $request): Response + { + $error = $this->validateCsrf($request); + if ($error !== null) { + return $error; + } + + $validationError = $this->validateInput($request); + if ($validationError !== null) { + Flash::set('settings.automation.error', $validationError); + return Response::redirect('/settings/automation/create'); + } + + try { + $this->repository->create( + $this->extractRuleData($request), + $this->extractConditions($request), + $this->extractActions($request) + ); + Flash::set('settings.automation.success', 'Zadanie automatyczne zostalo utworzone'); + } catch (Throwable) { + Flash::set('settings.automation.error', 'Blad zapisu zadania automatycznego'); + } + + return Response::redirect('/settings/automation'); + } + + public function update(Request $request): Response + { + $error = $this->validateCsrf($request); + if ($error !== null) { + return $error; + } + + $id = (int) $request->input('id', '0'); + if ($id <= 0) { + Flash::set('settings.automation.error', 'Nieprawidlowy identyfikator'); + return Response::redirect('/settings/automation'); + } + + $validationError = $this->validateInput($request); + if ($validationError !== null) { + Flash::set('settings.automation.error', $validationError); + return Response::redirect('/settings/automation/edit?id=' . $id); + } + + try { + $this->repository->update( + $id, + $this->extractRuleData($request), + $this->extractConditions($request), + $this->extractActions($request) + ); + Flash::set('settings.automation.success', 'Zadanie automatyczne zostalo zaktualizowane'); + } catch (Throwable) { + Flash::set('settings.automation.error', 'Blad aktualizacji zadania automatycznego'); + } + + return Response::redirect('/settings/automation'); + } + + public function destroy(Request $request): Response + { + $error = $this->validateCsrf($request); + if ($error !== null) { + return $error; + } + + $id = (int) $request->input('id', '0'); + if ($id <= 0) { + Flash::set('settings.automation.error', 'Nieprawidlowy identyfikator'); + return Response::redirect('/settings/automation'); + } + + try { + $this->repository->delete($id); + Flash::set('settings.automation.success', 'Zadanie automatyczne zostalo usuniete'); + } catch (Throwable) { + Flash::set('settings.automation.error', 'Blad usuwania zadania automatycznego'); + } + + return Response::redirect('/settings/automation'); + } + + public function toggleStatus(Request $request): Response + { + $error = $this->validateCsrf($request); + if ($error !== null) { + return $error; + } + + $id = (int) $request->input('id', '0'); + if ($id <= 0) { + Flash::set('settings.automation.error', 'Nieprawidlowy identyfikator'); + return Response::redirect('/settings/automation'); + } + + try { + $this->repository->toggleActive($id); + Flash::set('settings.automation.success', 'Status zadania zostal zmieniony'); + } catch (Throwable) { + Flash::set('settings.automation.error', 'Blad zmiany statusu'); + } + + return Response::redirect('/settings/automation'); + } + + private function renderForm(?array $rule): Response + { + $html = $this->template->render('automation/form', [ + 'title' => $rule !== null ? 'Edytuj zadanie automatyczne' : 'Nowe zadanie automatyczne', + 'activeMenu' => 'settings', + 'activeSettings' => 'automation', + 'user' => $this->auth->user(), + 'csrfToken' => Csrf::token(), + 'rule' => $rule, + 'integrations' => $this->repository->listOrderIntegrations(), + 'emailTemplates' => $this->repository->listEmailTemplates(), + 'eventTypes' => self::ALLOWED_EVENTS, + 'conditionTypes' => self::ALLOWED_CONDITION_TYPES, + 'actionTypes' => self::ALLOWED_ACTION_TYPES, + 'recipientOptions' => self::ALLOWED_RECIPIENTS, + 'errorMessage' => Flash::get('settings.automation.error', ''), + ], 'layouts/app'); + + return Response::html($html); + } + + private function validateCsrf(Request $request): ?Response + { + if (!Csrf::validate((string) $request->input('_token', ''))) { + Flash::set('settings.automation.error', 'Nieprawidlowy token CSRF'); + return Response::redirect('/settings/automation'); + } + + return null; + } + + private function validateInput(Request $request): ?string + { + $name = trim((string) $request->input('name', '')); + if ($name === '' || mb_strlen($name) > 128) { + return 'Nazwa jest wymagana (maks. 128 znakow)'; + } + + $eventType = (string) $request->input('event_type', ''); + if (!in_array($eventType, self::ALLOWED_EVENTS, true)) { + return 'Nieprawidlowy typ zdarzenia'; + } + + $conditions = $this->extractConditions($request); + if (count($conditions) === 0) { + return 'Wymagany jest co najmniej jeden warunek'; + } + + $actions = $this->extractActions($request); + if (count($actions) === 0) { + return 'Wymagana jest co najmniej jedna akcja'; + } + + return null; + } + + /** + * @return array + */ + private function extractRuleData(Request $request): array + { + return [ + 'name' => trim((string) $request->input('name', '')), + 'event_type' => (string) $request->input('event_type', ''), + 'is_active' => $request->input('is_active', null) !== null ? 1 : 0, + ]; + } + + /** + * @return list}> + */ + private function extractConditions(Request $request): array + { + $raw = $request->input('conditions', []); + if (!is_array($raw)) { + return []; + } + + $result = []; + foreach ($raw as $condition) { + if (!is_array($condition)) { + continue; + } + + $type = (string) ($condition['type'] ?? ''); + if (!in_array($type, self::ALLOWED_CONDITION_TYPES, true)) { + continue; + } + + $value = $this->parseConditionValue($type, $condition); + if ($value === null) { + continue; + } + + $result[] = ['type' => $type, 'value' => $value]; + } + + return $result; + } + + /** + * @param array $condition + * @return array|null + */ + private function parseConditionValue(string $type, array $condition): ?array + { + if ($type === 'integration') { + $ids = $condition['integration_ids'] ?? []; + if (!is_array($ids)) { + $ids = []; + } + $integrationIds = array_values(array_filter( + array_map('intval', $ids), + static fn (int $id): bool => $id > 0 + )); + + return count($integrationIds) > 0 ? ['integration_ids' => $integrationIds] : null; + } + + return null; + } + + /** + * @return list}> + */ + private function extractActions(Request $request): array + { + $raw = $request->input('actions', []); + if (!is_array($raw)) { + return []; + } + + $result = []; + foreach ($raw as $action) { + if (!is_array($action)) { + continue; + } + + $type = (string) ($action['type'] ?? ''); + if (!in_array($type, self::ALLOWED_ACTION_TYPES, true)) { + continue; + } + + $config = $this->parseActionConfig($type, $action); + if ($config === null) { + continue; + } + + $result[] = ['type' => $type, 'config' => $config]; + } + + return $result; + } + + /** + * @param array $action + * @return array|null + */ + private function parseActionConfig(string $type, array $action): ?array + { + if ($type === 'send_email') { + $templateId = (int) ($action['template_id'] ?? 0); + $recipient = (string) ($action['recipient'] ?? ''); + + if ($templateId <= 0 || !in_array($recipient, self::ALLOWED_RECIPIENTS, true)) { + return null; + } + + return ['template_id' => $templateId, 'recipient' => $recipient]; + } + + return null; + } +} diff --git a/src/Modules/Automation/AutomationRepository.php b/src/Modules/Automation/AutomationRepository.php new file mode 100644 index 0000000..bde7fa6 --- /dev/null +++ b/src/Modules/Automation/AutomationRepository.php @@ -0,0 +1,277 @@ +> + */ + public function findAll(): array + { + $sql = ' + SELECT r.id, r.name, r.event_type, r.is_active, r.created_at, r.updated_at, + (SELECT COUNT(*) FROM automation_conditions WHERE rule_id = r.id) AS conditions_count, + (SELECT COUNT(*) FROM automation_actions WHERE rule_id = r.id) AS actions_count + FROM automation_rules r + ORDER BY r.created_at DESC + '; + $statement = $this->pdo->prepare($sql); + $statement->execute(); + $rows = $statement->fetchAll(PDO::FETCH_ASSOC); + + return is_array($rows) ? $rows : []; + } + + /** + * @return array|null + */ + public function findById(int $id): ?array + { + $statement = $this->pdo->prepare('SELECT * FROM automation_rules WHERE id = :id LIMIT 1'); + $statement->execute(['id' => $id]); + $rule = $statement->fetch(PDO::FETCH_ASSOC); + + if (!is_array($rule)) { + return null; + } + + $rule['conditions'] = $this->loadConditions($id); + $rule['actions'] = $this->loadActions($id); + + return $rule; + } + + /** + * @param array $data + * @param list> $conditions + * @param list> $actions + */ + public function create(array $data, array $conditions, array $actions): int + { + $this->pdo->beginTransaction(); + + try { + $statement = $this->pdo->prepare( + 'INSERT INTO automation_rules (name, event_type, is_active) + VALUES (:name, :event_type, :is_active)' + ); + $statement->execute([ + 'name' => $data['name'], + 'event_type' => $data['event_type'], + 'is_active' => (int) ($data['is_active'] ?? 1), + ]); + + $ruleId = (int) $this->pdo->lastInsertId(); + + $this->insertConditions($ruleId, $conditions); + $this->insertActions($ruleId, $actions); + + $this->pdo->commit(); + + return $ruleId; + } catch (Throwable $e) { + $this->pdo->rollBack(); + throw $e; + } + } + + /** + * @param array $data + * @param list> $conditions + * @param list> $actions + */ + public function update(int $id, array $data, array $conditions, array $actions): bool + { + $this->pdo->beginTransaction(); + + try { + $statement = $this->pdo->prepare( + 'UPDATE automation_rules SET name = :name, event_type = :event_type, is_active = :is_active WHERE id = :id' + ); + $statement->execute([ + 'id' => $id, + 'name' => $data['name'], + 'event_type' => $data['event_type'], + 'is_active' => (int) ($data['is_active'] ?? 1), + ]); + + $this->pdo->prepare('DELETE FROM automation_conditions WHERE rule_id = :id')->execute(['id' => $id]); + $this->pdo->prepare('DELETE FROM automation_actions WHERE rule_id = :id')->execute(['id' => $id]); + + $this->insertConditions($id, $conditions); + $this->insertActions($id, $actions); + + $this->pdo->commit(); + + return true; + } catch (Throwable $e) { + $this->pdo->rollBack(); + throw $e; + } + } + + public function delete(int $id): void + { + $statement = $this->pdo->prepare('DELETE FROM automation_rules WHERE id = :id'); + $statement->execute(['id' => $id]); + } + + public function toggleActive(int $id): void + { + $statement = $this->pdo->prepare( + 'UPDATE automation_rules SET is_active = NOT is_active WHERE id = :id' + ); + $statement->execute(['id' => $id]); + } + + /** + * @return list> + */ + public function findActiveByEvent(string $eventType): array + { + $statement = $this->pdo->prepare( + 'SELECT id, name, event_type FROM automation_rules WHERE event_type = :event_type AND is_active = 1' + ); + $statement->execute(['event_type' => $eventType]); + $rules = $statement->fetchAll(PDO::FETCH_ASSOC); + + if (!is_array($rules)) { + return []; + } + + foreach ($rules as &$rule) { + $ruleId = (int) $rule['id']; + $rule['conditions'] = $this->loadConditions($ruleId); + $rule['actions'] = $this->loadActions($ruleId); + } + unset($rule); + + return $rules; + } + + /** + * @return list + */ + public function listOrderIntegrations(): array + { + $statement = $this->pdo->prepare( + "SELECT id, type, name FROM integrations WHERE type IN ('allegro', 'shoppro') AND is_active = 1 ORDER BY type, name" + ); + $statement->execute(); + $rows = $statement->fetchAll(PDO::FETCH_ASSOC); + + return is_array($rows) ? $rows : []; + } + + /** + * @return list + */ + public function listEmailTemplates(): array + { + $statement = $this->pdo->prepare( + 'SELECT id, name FROM email_templates WHERE is_active = 1 ORDER BY name' + ); + $statement->execute(); + $rows = $statement->fetchAll(PDO::FETCH_ASSOC); + + return is_array($rows) ? $rows : []; + } + + /** + * @return list> + */ + private function loadConditions(int $ruleId): array + { + $statement = $this->pdo->prepare( + 'SELECT id, condition_type, condition_value, sort_order FROM automation_conditions WHERE rule_id = :rule_id ORDER BY sort_order' + ); + $statement->execute(['rule_id' => $ruleId]); + $rows = $statement->fetchAll(PDO::FETCH_ASSOC); + + if (!is_array($rows)) { + return []; + } + + foreach ($rows as &$row) { + $decoded = json_decode((string) ($row['condition_value'] ?? '{}'), true); + $row['condition_value'] = is_array($decoded) ? $decoded : []; + } + unset($row); + + return $rows; + } + + /** + * @return list> + */ + private function loadActions(int $ruleId): array + { + $statement = $this->pdo->prepare( + 'SELECT id, action_type, action_config, sort_order FROM automation_actions WHERE rule_id = :rule_id ORDER BY sort_order' + ); + $statement->execute(['rule_id' => $ruleId]); + $rows = $statement->fetchAll(PDO::FETCH_ASSOC); + + if (!is_array($rows)) { + return []; + } + + foreach ($rows as &$row) { + $decoded = json_decode((string) ($row['action_config'] ?? '{}'), true); + $row['action_config'] = is_array($decoded) ? $decoded : []; + } + unset($row); + + return $rows; + } + + /** + * @param list> $conditions + */ + private function insertConditions(int $ruleId, array $conditions): void + { + $statement = $this->pdo->prepare( + 'INSERT INTO automation_conditions (rule_id, condition_type, condition_value, sort_order) + VALUES (:rule_id, :condition_type, :condition_value, :sort_order)' + ); + + foreach ($conditions as $index => $condition) { + $statement->execute([ + 'rule_id' => $ruleId, + 'condition_type' => $condition['type'], + 'condition_value' => json_encode($condition['value'], JSON_UNESCAPED_UNICODE), + 'sort_order' => $index, + ]); + } + } + + /** + * @param list> $actions + */ + private function insertActions(int $ruleId, array $actions): void + { + $statement = $this->pdo->prepare( + 'INSERT INTO automation_actions (rule_id, action_type, action_config, sort_order) + VALUES (:rule_id, :action_type, :action_config, :sort_order)' + ); + + foreach ($actions as $index => $action) { + $statement->execute([ + 'rule_id' => $ruleId, + 'action_type' => $action['type'], + 'action_config' => json_encode($action['config'], JSON_UNESCAPED_UNICODE), + 'sort_order' => $index, + ]); + } + } +} diff --git a/src/Modules/Automation/AutomationService.php b/src/Modules/Automation/AutomationService.php new file mode 100644 index 0000000..e9c49ba --- /dev/null +++ b/src/Modules/Automation/AutomationService.php @@ -0,0 +1,165 @@ +repository->findActiveByEvent($eventType); + if ($rules === []) { + return; + } + + $details = $this->orders->findDetails($orderId); + if ($details === null) { + return; + } + + $order = is_array($details['order'] ?? null) ? $details['order'] : []; + + foreach ($rules as $rule) { + try { + $conditions = is_array($rule['conditions'] ?? null) ? $rule['conditions'] : []; + $actions = is_array($rule['actions'] ?? null) ? $rule['actions'] : []; + $ruleName = (string) ($rule['name'] ?? ''); + + if ($this->evaluateConditions($conditions, $order)) { + $this->executeActions($actions, $orderId, $ruleName); + } + } catch (Throwable) { + // Blad jednej reguly nie blokuje kolejnych + } + } + } + + /** + * @param list> $conditions + * @param array $order + */ + private function evaluateConditions(array $conditions, array $order): bool + { + foreach ($conditions as $condition) { + $type = (string) ($condition['condition_type'] ?? ''); + $value = is_array($condition['condition_value'] ?? null) ? $condition['condition_value'] : []; + + if (!$this->evaluateSingleCondition($type, $value, $order)) { + return false; + } + } + + return true; + } + + /** + * @param array $value + * @param array $order + */ + private function evaluateSingleCondition(string $type, array $value, array $order): bool + { + if ($type === 'integration') { + return $this->evaluateIntegrationCondition($value, $order); + } + + return false; + } + + /** + * @param array $value + * @param array $order + */ + private function evaluateIntegrationCondition(array $value, array $order): bool + { + $allowedIds = is_array($value['integration_ids'] ?? null) ? $value['integration_ids'] : []; + if ($allowedIds === []) { + return false; + } + + $orderIntegrationId = (int) ($order['integration_id'] ?? 0); + if ($orderIntegrationId === 0) { + return false; + } + + return in_array($orderIntegrationId, array_map('intval', $allowedIds), true); + } + + /** + * @param list> $actions + */ + private function executeActions(array $actions, int $orderId, string $ruleName): void + { + foreach ($actions as $action) { + $type = (string) ($action['action_type'] ?? ''); + $config = is_array($action['action_config'] ?? null) ? $action['action_config'] : []; + + if ($type === 'send_email') { + $this->handleSendEmail($config, $orderId, $ruleName); + } + } + } + + /** + * @param array $config + */ + private function handleSendEmail(array $config, int $orderId, string $ruleName): void + { + $templateId = (int) ($config['template_id'] ?? 0); + if ($templateId <= 0) { + return; + } + + $recipient = (string) ($config['recipient'] ?? 'client'); + $actorName = 'Automatyzacja: ' . $ruleName; + + if ($recipient === 'client' || $recipient === 'client_and_company') { + $this->emailService->send($orderId, $templateId, null, $actorName); + } + + if ($recipient === 'company' || $recipient === 'client_and_company') { + $this->sendToCompany($orderId, $templateId, $actorName); + } + } + + private function sendToCompany(int $orderId, int $templateId, string $actorName): void + { + $settings = $this->companySettings->getSettings(); + $companyEmail = trim((string) ($settings['email'] ?? '')); + + if ($companyEmail === '' || filter_var($companyEmail, FILTER_VALIDATE_EMAIL) === false) { + $this->orders->recordActivity( + $orderId, + 'automation_email_failed', + $actorName . ' — brak adresu e-mail firmy w ustawieniach', + ['reason' => 'missing_company_email'], + 'system', + $actorName + ); + return; + } + + $companyName = trim((string) ($settings['company_name'] ?? '')); + + $this->emailService->send( + $orderId, + $templateId, + null, + $actorName, + $companyEmail, + $companyName + ); + } +} diff --git a/src/Modules/Email/EmailSendingService.php b/src/Modules/Email/EmailSendingService.php index e70adad..745c94e 100644 --- a/src/Modules/Email/EmailSendingService.php +++ b/src/Modules/Email/EmailSendingService.php @@ -28,7 +28,7 @@ final class EmailSendingService /** * @return array{success: bool, error: ?string, log_id: int} */ - public function send(int $orderId, int $templateId, ?int $mailboxId = null, ?string $actorName = null): array + public function send(int $orderId, int $templateId, ?int $mailboxId = null, ?string $actorName = null, ?string $recipientEmailOverride = null, ?string $recipientNameOverride = null): array { $details = $this->orders->findDetails($orderId); if ($details === null) { @@ -48,12 +48,16 @@ final class EmailSendingService return ['success' => false, 'error' => 'Brak skonfigurowanej skrzynki SMTP', 'log_id' => 0]; } - $recipientEmail = $this->findRecipientEmail($addresses); + $recipientEmail = $recipientEmailOverride !== null && $recipientEmailOverride !== '' + ? $recipientEmailOverride + : $this->findRecipientEmail($addresses); if ($recipientEmail === '') { - return ['success' => false, 'error' => 'Brak adresu e-mail kupujacego', 'log_id' => 0]; + return ['success' => false, 'error' => 'Brak adresu e-mail odbiorcy', 'log_id' => 0]; } - $recipientName = $this->findRecipientName($addresses); + $recipientName = $recipientNameOverride !== null && $recipientNameOverride !== '' + ? $recipientNameOverride + : $this->findRecipientName($addresses); $companySettings = $this->loadCompanySettings(); $variableMap = $this->variableResolver->buildVariableMap($order, $addresses, $companySettings);