From 9df7a63244cbb8b3c0a35b12a87a17d0ca6a8180 Mon Sep 17 00:00:00 2001 From: Jacek Pyziak Date: Wed, 4 Mar 2026 23:56:45 +0100 Subject: [PATCH] feat: Enhance order date handling with effective date fallback and update documentation --- .vscode/ftp-kr.sync.cache.json | 246 ++++++++++++++++++++---- DOCS/ARCHITECTURE.md | 2 + DOCS/DB_SCHEMA.md | 1 + DOCS/TECH_CHANGELOG.md | 3 + DOCS/todo.md | 4 +- src/Modules/Orders/OrdersRepository.php | 22 ++- 6 files changed, 237 insertions(+), 41 deletions(-) diff --git a/.vscode/ftp-kr.sync.cache.json b/.vscode/ftp-kr.sync.cache.json index bdcffa9..f4a1e69 100644 --- a/.vscode/ftp-kr.sync.cache.json +++ b/.vscode/ftp-kr.sync.cache.json @@ -3,8 +3,8 @@ "public_html": { "AGENTS.md": { "type": "-", - "size": 2593, - "lmtime": 1772522685966, + "size": 3402, + "lmtime": 1772652932723, "modified": false }, "ARCHITECTURE.md": { @@ -374,8 +374,20 @@ }, "cron.php": { "type": "-", - "size": 114, - "lmtime": 1772490484677, + "size": 2398, + "lmtime": 1772661752605, + "modified": false + }, + "debug_allegro_offer_image.php": { + "type": "-", + "size": 5749, + "lmtime": 1772659638204, + "modified": false + }, + "debug_allegro_order_media.php": { + "type": "-", + "size": 3578, + "lmtime": 1772659291974, "modified": false }, "deploy_and_seed_orders.php": { @@ -408,16 +420,22 @@ "lmtime": 1771692294431, "modified": false }, + "randomize_order_statuses.php": { + "type": "-", + "size": 3646, + "lmtime": 1772497235553, + "modified": false + }, "test_gs1_api.php": { "type": "-", "size": 7348, "lmtime": 1771964550467, "modified": false }, - "randomize_order_statuses.php": { + "debug_order_delivery.php": { "type": "-", - "size": 3646, - "lmtime": 1772497235553, + "size": 2031, + "lmtime": 1772662252283, "modified": false } }, @@ -601,6 +619,42 @@ "size": 1378, "lmtime": 1772491798937, "modified": false + }, + "20260304_000023_create_allegro_integration_settings_table.sql": { + "type": "-", + "size": 1416, + "lmtime": 1772654150195, + "modified": false + }, + "20260304_000024_add_allegro_token_refresh_schedule.sql": { + "type": "-", + "size": 2964, + "lmtime": 1772655425959, + "modified": false + }, + "20260304_000025_create_allegro_order_status_mappings_table.sql": { + "type": "-", + "size": 618, + "lmtime": 1772656570162, + "modified": false + }, + "20260304_000026_make_allegro_status_mapping_nullable.sql": { + "type": "-", + "size": 99, + "lmtime": 1772657798905, + "modified": false + }, + "20260304_000027_add_allegro_orders_import_schedule.sql": { + "type": "-", + "size": 1588, + "lmtime": 1772660772041, + "modified": false + }, + "20260304_000028_add_allegro_status_sync_schedule.sql": { + "type": "-", + "size": 852, + "lmtime": 1772661760885, + "modified": false } }, "seeders": {}, @@ -628,14 +682,14 @@ "DOCS": { "ARCHITECTURE.md": { "type": "-", - "size": 7199, - "lmtime": 1772497590235, + "size": 14854, + "lmtime": 1772662333693, "modified": false }, "DB_SCHEMA.md": { "type": "-", - "size": 3138, - "lmtime": 1772496281398, + "size": 6999, + "lmtime": 1772661998528, "modified": false }, "ORDERS_SCHEMA_APILO_DRAFT.md": { @@ -652,16 +706,22 @@ }, "TECH_CHANGELOG.md": { "type": "-", - "size": 8638, - "lmtime": 1772497584302, + "size": 17750, + "lmtime": 1772662343016, + "modified": false + }, + "todo.md": { + "type": "-", + "size": 688, + "lmtime": 1772662690145, "modified": false } }, ".env": { "type": "-", - "size": 408, - "lmtime": 1771869136710, - "modified": true + "size": 393, + "lmtime": 1772654691844, + "modified": false }, ".env.codex.bak": { "type": "-", @@ -1876,8 +1936,8 @@ "css": { "app.css": { "type": "-", - "size": 25538, - "lmtime": 1772497577480, + "size": 25757, + "lmtime": 1772654371834, "modified": false }, "app.css.map": { @@ -1889,7 +1949,7 @@ "login.css": { "type": "-", "size": 4665, - "lmtime": 1772497577979, + "lmtime": 1772654372304, "modified": false }, "login.css.map": { @@ -1937,8 +1997,8 @@ "lang": { "pl.php": { "type": "-", - "size": 33450, - "lmtime": 1772496207146, + "size": 41962, + "lmtime": 1772661591586, "modified": false } }, @@ -1961,8 +2021,8 @@ "scss": { "app.scss": { "type": "-", - "size": 28671, - "lmtime": 1772497569553, + "size": 28929, + "lmtime": 1772654341335, "modified": false }, "login.scss": { @@ -2014,8 +2074,8 @@ "layouts": { "app.php": { "type": "-", - "size": 3524, - "lmtime": 1772495209961, + "size": 3970, + "lmtime": 1772655168615, "modified": false }, "auth.php": { @@ -2092,11 +2152,17 @@ } }, "settings": { + "allegro.php": { + "type": "-", + "size": 16587, + "lmtime": 1772661581724, + "modified": false + }, "cron.php": { "type": "-", - "size": 7180, - "lmtime": 1772395792152, - "modified": true + "size": 6247, + "lmtime": 1772655160233, + "modified": false }, "database.php": { "type": "-", @@ -2148,8 +2214,8 @@ "routes": { "web.php": { "type": "-", - "size": 3538, - "lmtime": 1772496154180, + "size": 6986, + "lmtime": 1772661209733, "modified": false } }, @@ -2197,8 +2263,8 @@ "Core": { "Application.php": { "type": "-", - "size": 7008, - "lmtime": 1772495113026, + "size": 10729, + "lmtime": 1772661737740, "modified": false }, "Database": { @@ -2310,6 +2376,18 @@ } }, "Cron": { + "AllegroOrdersImportHandler.php": { + "type": "-", + "size": 665, + "lmtime": 1772660734274, + "modified": false + }, + "AllegroTokenRefreshHandler.php": { + "type": "-", + "size": 1965, + "lmtime": 1772655083686, + "modified": false + }, "CronJobProcessor.php": { "type": "-", "size": 6385, @@ -2328,6 +2406,18 @@ "lmtime": 1772489146286, "modified": false }, + "CronRepository.php": { + "type": "-", + "size": 14940, + "lmtime": 1772661551022, + "modified": false + }, + "CronRunner.php": { + "type": "-", + "size": 2815, + "lmtime": 1772655073134, + "modified": false + }, "ProductLinksHealthCheckHandler.php": { "type": "-", "size": 5247, @@ -2351,6 +2441,12 @@ "size": 528, "lmtime": 1772489139382, "modified": false + }, + "AllegroStatusSyncHandler.php": { + "type": "-", + "size": 456, + "lmtime": 1772661713965, + "modified": false } }, "GS1": { @@ -2382,6 +2478,12 @@ } }, "Orders": { + "OrderImportRepository.php": { + "type": "-", + "size": 18405, + "lmtime": 1772655751334, + "modified": false + }, "OrderImportService.php": { "type": "-", "size": 21009, @@ -2390,14 +2492,14 @@ }, "OrdersController.php": { "type": "-", - "size": 21408, - "lmtime": 1772496952329, + "size": 22423, + "lmtime": 1772658312572, "modified": false }, "OrdersRepository.php": { "type": "-", - "size": 18855, - "lmtime": 1772496882865, + "size": 24750, + "lmtime": 1772658967435, "modified": false }, "OrderStatusSyncService.php": { @@ -2484,12 +2586,78 @@ } }, "Settings": { + "AllegroApiClient.php": { + "type": "-", + "size": 3449, + "lmtime": 1772659378931, + "modified": false + }, + "AllegroIntegrationController.php": { + "type": "-", + "size": 29116, + "lmtime": 1772661726470, + "modified": false + }, + "AllegroIntegrationRepository.php": { + "type": "-", + "size": 10965, + "lmtime": 1772655846785, + "modified": false + }, + "AllegroOAuthClient.php": { + "type": "-", + "size": 5988, + "lmtime": 1772660267587, + "modified": false + }, + "AllegroOrderImportService.php": { + "type": "-", + "size": 31721, + "lmtime": 1772662304371, + "modified": false + }, + "AllegroOrdersSyncService.php": { + "type": "-", + "size": 11544, + "lmtime": 1772660728121, + "modified": false + }, + "AllegroOrderSyncStateRepository.php": { + "type": "-", + "size": 8757, + "lmtime": 1772660685699, + "modified": false + }, + "AllegroStatusDiscoveryService.php": { + "type": "-", + "size": 5786, + "lmtime": 1772657848652, + "modified": false + }, + "AllegroStatusMappingRepository.php": { + "type": "-", + "size": 4690, + "lmtime": 1772657817169, + "modified": false + }, + "AllegroStatusSyncService.php": { + "type": "-", + "size": 1537, + "lmtime": 1772661706942, + "modified": false + }, "AppSettingsRepository.php": { "type": "-", "size": 1905, "lmtime": 1771954924419, "modified": false }, + "CronSettingsController.php": { + "type": "-", + "size": 3345, + "lmtime": 1772655129538, + "modified": false + }, "IntegrationRepository.php": { "type": "-", "size": 25754, @@ -3632,6 +3800,12 @@ "size": 3392, "lmtime": 1771959054615, "modified": false + }, + "tmp_schema_check.php": { + "type": "-", + "size": 429, + "lmtime": 1772655634873, + "modified": false } } }, diff --git a/DOCS/ARCHITECTURE.md b/DOCS/ARCHITECTURE.md index 6c789b3..d04340e 100644 --- a/DOCS/ARCHITECTURE.md +++ b/DOCS/ARCHITECTURE.md @@ -80,6 +80,8 @@ - `GET /orders/list`: - `OrdersController::index(Request): Response` - pobiera dane listy przez `OrdersRepository::paginate(...)`, + - data zamowienia na liscie korzysta z fallbacku: `orders.ordered_at` -> `orders.source_created_at` -> `orders.source_updated_at` -> `orders.fetched_at`, + - domyslne sortowanie i filtry zakresu dat (`date_from`, `date_to`) korzystaja z tej samej daty efektywnej, - pobiera slowniki filtrow (`sourceOptions()`, `statusOptions()`), statystyki (`quickStats()`), agregaty statusow (`statusCounts()`) i konfiguracje grup/statusow (`statusPanelConfig()`), - buduje panel statusow z grupami i licznikami (`buildStatusPanel(...)`) z linkami filtrujacymi po statusie, - panel statusow i etykiety statusow sa zgodne z konfiguracja z `Ustawienia > Statusy` (z fallbackiem `Pozostale`), diff --git a/DOCS/DB_SCHEMA.md b/DOCS/DB_SCHEMA.md index d2ce5d5..ed1c741 100644 --- a/DOCS/DB_SCHEMA.md +++ b/DOCS/DB_SCHEMA.md @@ -21,6 +21,7 @@ - 2026-03-04: Rozszerzono zakladke `Ustawienia` integracji Allegro o kierunek synchronizacji statusow i interwal synchronizacji statusow; zapis do `app_settings` (`allegro_status_sync_direction`, `allegro_status_sync_interval_minutes`) - bez zmian schematu. - 2026-03-04: Dodano harmonogram `allegro_status_sync` (cron synchronizacji statusow) + defaulty `app_settings` dla kierunku i interwalu status sync - migracja `20260304_000028_add_allegro_status_sync_schedule.sql`. - 2026-03-04: Import Allegro mapuje forme wysylki do `orders.external_carrier_id` i `orders.external_carrier_account_id` - bez zmian schematu. +- 2026-03-04: Poprawiono prezentacje daty zamowienia na liscie (`fallback ordered_at -> source_created_at -> source_updated_at -> fetched_at`) - bez zmian schematu. ## Tabele diff --git a/DOCS/TECH_CHANGELOG.md b/DOCS/TECH_CHANGELOG.md index 21afaab..126b6cc 100644 --- a/DOCS/TECH_CHANGELOG.md +++ b/DOCS/TECH_CHANGELOG.md @@ -1,6 +1,9 @@ # Tech Changelog ## 2026-03-04 +- Poprawiono kolumne `Data zamowienia` na liscie zamowien: + - wartosc jest liczona fallbackiem `orders.ordered_at -> orders.source_created_at -> orders.source_updated_at -> orders.fetched_at`, + - domyslne sortowanie listy i filtry zakresu dat korzystaja z tej samej daty efektywnej, co eliminuje puste wartosci przy rekordach bez `ordered_at`. - Import zamowienia Allegro zapisuje teraz forme wysylki: - `delivery.method.name` (fallback `delivery.method.id`) trafia do `orders.external_carrier_id`, - techniczne `delivery.method.id` trafia do `orders.external_carrier_account_id`. diff --git a/DOCS/todo.md b/DOCS/todo.md index b793b19..8d91a44 100644 --- a/DOCS/todo.md +++ b/DOCS/todo.md @@ -5,4 +5,6 @@ 5. [] W szczegĂłlach zamĂłwienia dorobić opcjÄ™ zmiany statusu. 6. [] W szczególach zamówienia 2 razy wyświetla się ID zamówienai z allegro, np: 008d3d60-1743-11f1-b15c-fdb4f87ccfc6 7. [] Przy imporcie z allegro liczba przesyłek jest 0. -8. [] Kolumna LP w szczególach zamówienia jest zbyt szeroka. \ No newline at end of file +8. [] Kolumna LP w szczególach zamówienia jest zbyt szeroka. +9. [x] Na lisćie zamówień pole po którym jest domyślnie sortowana czyli data zamówienia jest puste. +10. [] Na liście zamówień ukryć kolumnę ostatnia zmiana. \ No newline at end of file diff --git a/src/Modules/Orders/OrdersRepository.php b/src/Modules/Orders/OrdersRepository.php index 14dc0b5..2c2cf56 100644 --- a/src/Modules/Orders/OrdersRepository.php +++ b/src/Modules/Orders/OrdersRepository.php @@ -27,6 +27,7 @@ final class OrdersRepository $where = []; $params = []; $effectiveStatusSql = $this->effectiveStatusSql('o', 'asm'); + $effectiveOrderedAtSql = $this->effectiveOrderedAtSql('o'); $search = trim((string) ($filters['search'] ?? '')); if ($search !== '') { @@ -60,13 +61,13 @@ final class OrdersRepository $dateFrom = trim((string) ($filters['date_from'] ?? '')); if ($dateFrom !== '' && preg_match('/^\d{4}-\d{2}-\d{2}$/', $dateFrom) === 1) { - $where[] = 'o.ordered_at >= :date_from'; + $where[] = $effectiveOrderedAtSql . ' >= :date_from'; $params['date_from'] = $dateFrom . ' 00:00:00'; } $dateTo = trim((string) ($filters['date_to'] ?? '')); if ($dateTo !== '' && preg_match('/^\d{4}-\d{2}-\d{2}$/', $dateTo) === 1) { - $where[] = 'o.ordered_at <= :date_to'; + $where[] = $effectiveOrderedAtSql . ' <= :date_to'; $params['date_to'] = $dateTo . ' 23:59:59'; } @@ -84,7 +85,7 @@ final class OrdersRepository 'source_updated_at' => 'o.source_updated_at', 'fetched_at' => 'o.fetched_at', 'id' => 'o.id', - default => 'o.ordered_at', + default => $effectiveOrderedAtSql, }; try { @@ -108,8 +109,10 @@ final class OrdersRepository o.total_with_tax, o.total_paid, o.ordered_at, + o.source_created_at, o.source_updated_at, o.fetched_at, + ' . $effectiveOrderedAtSql . ' AS effective_ordered_at, o.is_invoice, o.is_canceled_by_buyer, a.name AS buyer_name, @@ -161,7 +164,8 @@ final class OrdersRepository 'currency' => (string) ($row['currency'] ?? ''), 'total_with_tax' => $row['total_with_tax'] !== null ? (float) $row['total_with_tax'] : null, 'total_paid' => $row['total_paid'] !== null ? (float) $row['total_paid'] : null, - 'ordered_at' => (string) ($row['ordered_at'] ?? ''), + 'ordered_at' => (string) ($row['effective_ordered_at'] ?? ''), + 'source_created_at' => (string) ($row['source_created_at'] ?? ''), 'source_updated_at' => (string) ($row['source_updated_at'] ?? ''), 'fetched_at' => (string) ($row['fetched_at'] ?? ''), 'is_invoice' => (int) ($row['is_invoice'] ?? 0) === 1, @@ -551,6 +555,16 @@ final class OrdersRepository END'; } + private function effectiveOrderedAtSql(string $orderAlias): string + { + return 'COALESCE(' + . $orderAlias . '.ordered_at, ' + . $orderAlias . '.source_created_at, ' + . $orderAlias . '.source_updated_at, ' + . $orderAlias . '.fetched_at' + . ')'; + } + private function resolvedMediaUrlSql(string $itemAlias): string { if (!$this->canResolveMappedMedia()) {