Commit Graph

35 Commits

Author SHA1 Message Date
Hermes c0ebe7f59f fix(manage-users): detach FK references before deleting user (RESTRICT FKs in order_history/action_logs/suggestions/order_groups blocked auth.deleteUser with 'Database error deleting user') 2026-08-14 15:20:40 +02:00
Hermes 7654413d8b fix(push): test notification targets the device's own subscription (by endpoint), not localStorage phone 2026-08-13 15:02:26 +02:00
Hermes 15132f56e8 feat(client): PWA install — client route, manifest start_url=/client, SW app-shell, invitation links → /client/:token 2026-08-11 13:37:29 +02:00
root 1922778e0f feat(push): prepare client subscription test contour 2026-08-06 08:56:12 +00:00
root d397d0cb24 feat: configurable business schedule (delivery/pickup/SMS days)
- New table business_schedule_settings (delivery_days, pickup_days, sms_days)
- RPC get_business_schedule() (public) + update_business_schedule() (admin)
- Admin UI: BusinessSchedulePanel with day pills for each category
- ClientDeliveryPage: fetches schedule, replaces hardcoded Sunday/weekend checks
- PickupSlotsPicker: uses pickupDays prop instead of hardcoded isWeekend
- Edge function confirm-delivery-choice: reads delivery_days from DB
- delivery-invitations.ts: buildDefaultDatedAvailableSlots reads delivery_days
- RPC confirm_delivery_choice_by_token: checks delivery_days instead of extract(dow)=0
- SMS scripts: get_sms_days() reads sms_days from business_schedule_settings
  and overrides per-campaign work_days setting
- Nav item Расписание for mega_admin and admin roles
- Default: Mon-Fri (1,2,3,4,5) for all three categories
2026-07-03 12:45:02 +00:00
root 93d3ce4ca8 fix: manage-users — remove manual public.users insert, trigger handle_new_user does it via user_metadata 2026-06-30 07:04:24 +00:00
root cadcceef7e feat: manage-users edge function — admin user CRUD (create/delete) 2026-06-30 06:55:55 +00:00
root b74add32ef fix: skip Sunday in delivery date selection (client flow + backend validation)
- buildDefaultDatedAvailableSlots(): skip Sunday via getNextWorkday()
- ClientDeliveryPage.jsx: getAllowedDeliveryDateKeys() + fallback slots skip Sunday
- confirm-delivery-choice edge function: reject Sunday for delivery
- confirm_delivery_choice_by_token SQL RPC: extract(dow) = 0 → RAISE EXCEPTION
- Tests: Friday→Sat+Mon, Saturday→Mon+Tue (skip Sunday)
- Skill updated with pitfall
2026-06-23 04:56:49 +00:00
root d04901d296 security: fix 9 vulnerabilities + OrdersTable 14px font + colored status badges
Security fixes:
- Remove VITE_SUPABASE_SERVICE_ROLE_KEY from Docker build args
- Add missing security.ts functions (verifyInternalRequest, requireSameOrigin, etc)
- Store only OTP hash, remove plaintext otp_code
- Fix CORS origin check: startsWith → exact match
- Use atomic SQL check_rate_limit RPC instead of JS rate limiter
- Mask PII in get_delivery_invitation_by_token single-order path
- Add RequireAuth wrapper for protected routes
- Revoke anon execute on confirm_delivery_choice_by_token
- Add HSTS header to Caddyfile

UI:
- OrdersTable desktop: all cells text-sm (14px)
- Status column: use colored Badge with tone from getOrderGroupStatusTone
- Header row: text-sm (14px)
2026-06-19 12:14:19 +00:00
root 37ea7d3a19 fix: убрать генерацию pickup_code — приходит из 1С, показывать только при самовывозе 2026-06-16 07:36:47 +00:00
root 9408b98f06 fix: pickup_code — 6-значное число вместо букв 2026-06-16 06:57:57 +00:00
root 5867272873 feat: pickup_code для самовывоза + упрощение статуса отгрузки
- pickup_code: автогенерация 6-значного кода при выборе самовывоза
- Колонка pickup_code в order_groups + SELECT
- Отображение кода выдачи в карточках (логист, клиент)
- Упрощение: любая отгрузка → delivered (проблемы в has_delivery_problem)
- RPC: добавлены deliveryType, pickupCode, pickupDate, pickupTimeSlot
2026-06-16 06:53:12 +00:00
root 41272bdbbf fix: аудит доставки — критические и средние баги
Edge function confirm-delivery-choice:
- currentGroup использовался до объявления — перемещён вверх
- pickup не очищал assigned_driver_id — добавлена очистка
- выборка currentGroup теперь включает delivery_address, customer_address

Edge function update-order-group-delivery-choice:
- добавлена поддержка deliveryType=pickup (ранее всегда ставил 'agreed')
- pickup очищает assigned_driver_id, устанавливает pickup_date/time_slot
- дата доставки не обязательна для pickup

Фронтенд:
- assignDriverToOrderGroup: null → 'agreed' (NOT NULL constraint)
- isDeliveryAgreed включает статус 'pickup'
- orderGroupViews: warning-тон для групп с проблемами отгрузки
- OrdersTable: колонка Отгрузка с визуализацией проблем
2026-06-15 15:38:42 +00:00
root ae1e0a2e0e fix: 3 бага доставки — самовывоз/водитель/отгрузка
Bug 1: deliveryType='delivery' перезаписывался на 'pickup' маппером из-за адреса/источника. Теперь если БД явно содержит delivery_type='delivery', маппер это уважает.

Bug 2: водитель не мог сохранить частичную отгрузку — добавлена кнопка 'Сохранить отгрузку' в DriverShipmentPanel + saveShipmentData() в репозитории.

Bug 3: при смене типа на самовывоз assigned_driver_id не очищался — добавлено assigned_driver_id: null в updatePayload.
2026-06-15 15:10:30 +00:00
root 7e43f9e990 feat: requires_address status + address input for pickup-to-delivery switch
- New status: requires_address (Требуется адрес) in deliveryWorkflow
- ClientDeliveryPage: address input shown when delivery chosen without address on file
- OrderDetailPanel: requires_address status badge + address input for manager
- confirm_delivery_choice_by_token RPC: p_delivery_address param, sets requires_address status
- Edge function: delivery_address passed to RPC
- deliveryInvitationApi: deliveryAddress param
- CHECK constraint: requires_address, address_required added
- PickupSlotsPicker: styled storage conditions info block
2026-06-10 14:52:17 +00:00
root e05613ac1d feat: add pickup (самовывоз) delivery type
- New status pickup in delivery workflow
- DB: delivery_type, pickup_date, pickup_time_slot columns
- Client page: tabs Доставка/Самовывоз with PickupSlotsPicker
- PickupSlotsPicker: today/tomorrow/day-after with half-day slots
- Storage notice: free 2 workdays, then 300₽/day
- OrderDetailPanel: delivery type tabs, pickup date/time, status button
- Edge function: delivery_type/pickup fields in confirm-delivery-choice
- RPC: confirm_delivery_choice_by_token updated for pickup
- orderGroupRepository: full pickup field mapping
2026-06-10 12:02:46 +00:00
root dac8450586 feat: action_logs — журнал действий сотрудников с фильтрами 2026-05-27 15:12:46 +00:00
Codex e6dc1972fb feat: show full order composition on delivery page
- Extract OrderCompositionPanel as standalone component
- Support nested order items with sub-positions from source_orders
- Enrich order items from Edge Function when RPC only has invoice refs
- Update RPC SQL to extract product items from source_orders
- Update Edge Function to include source_orders items in invitation
- Add detail rows (account, customer) when no order items available
2026-05-21 11:52:46 +03:00
Codex 6244749545 feat: unify manual_required status and driver label
- orderGroupViews: unify notification manual_required + pending delivery_status into single "Требуется ручное управление" status
- LogisticsReadinessBoard: use status:manual_required in funnel instead of delivery:manual_confirmation_required
- DriverDeliveryPlanner: show "Назначено вам" for driver_assigned instead of "Назначен водитель"
- Add sync-manual-status.sql trigger patch for backend
2026-05-20 16:25:06 +03:00
Codex 838c4cb7ae feat(paid-storage): bypass stale RPC for paid_storage transitions
- OrderDetailPanel: paid_storage bypasses update_delivery_status RPC
- Repository: direct table update for paid_storage entry/exit
- LogisticsBoard: collapsible sections ordered by funnel
- SQL: updated paid_storage schema patch
- LoginPage: hide dev quick-login in production
2026-05-20 16:25:06 +03:00
Codex c8fbe95bd1 feat(paid-storage): inline confirmation + cancel action + status display
- Replaced window.confirm with inline confirmation panel in app style
- Shows confirmation block with 'Yes, transfer' / 'Cancel' buttons
- After transfer: shows 'Transferred to paid storage' with date and yellow indicator
- Added cancel button to revert from paid_storage back to pending_confirmation
2026-05-20 16:25:06 +03:00
Codex b9c6bb2810 fix: RLS recursion, driver UI, auth errors, status counts
- Fix infinite RLS recursion in users policies via current_role_name()
- Add is_admin() helper and simplify users select policies
- Fix order_groups insert for service_role (n8n integration)
- Fix status option counts in dropdown (LogisticsReadinessBoard)
- Add driver delivery status buttons (loaded, on_route, delivered, problem, cancelled)
- Replace driver date range filters with single date picker + date pills
- Hide SMS/internal data from driver view in OrderDetailPanel
- Fix Edge Function error messages in OTP flow (read error.context body)
- Add update_delivery_status RPC for driver workflow
- Remove customer column from order_groups fetch (DB schema mismatch)
- UI: swap filter/search positions, limit modal width, status label cleanup
2026-05-20 16:25:05 +03:00
Codex fc74241378 fix(delivery): show invoice refs in client flow 2026-05-14 12:51:25 +03:00
Codex eeb2620547 fix(delivery): switch public flow to rpc 2026-05-13 18:59:30 +03:00
Codex 633973142d fix(delivery): load links and schedule SMS 2026-05-13 18:59:30 +03:00
Codex b79de7afba feat(delivery): auto-create invitation links
Add a Supabase trigger that creates delivery invitations and writes delivery_link on order_groups changes. n8n can now consume link_ready rows without calling the edge function first.
2026-05-13 18:59:30 +03:00
Codex f2230f3277 Add logistics UI actions and demo login buttons
- Fix bug in transfer-to-logistics: body.note was incorrectly used for delivery_agreement_status
- Add quick actions section in OrderDetailPanel for status changes (visible to role)
- Add driver assignment buttons for logistician/admin
- Add demo login buttons for all roles (works with real Supabase config)
- Add loginAsDemoUser function to AuthContext for quick demo login
2026-05-13 18:59:30 +03:00
Codex 219670583b Add security hardening SQL patch 2026-05-13 18:59:30 +03:00
Codex e29a51e7ea Harden auth and delivery endpoints 2026-05-13 18:59:30 +03:00
Codex a5113a2ed5 feat: simplify delivery roles and docs 2026-04-16 13:31:17 +03:00
Codex c28c826601 feat: show client order items in delivery flow 2026-04-16 12:42:41 +03:00
Codex ca72a4e662 feat: document product and wire real client flow 2026-04-14 23:20:50 +03:00
Codex 49e60d48c1 feat: complete delivery workflow updates 2026-04-13 16:32:18 +03:00
Codex 1798e3acfd refactor: align delivery flow with 1c imports 2026-04-13 16:24:04 +03:00
Codex b40a4a553e Initial import 2026-03-14 18:40:54 +03:00