Commit Graph

121 Commits

Author SHA1 Message Date
BOHA
aec822adc2 fix: clearCookie must match setCookie options for browser to clear it
clearCookie was missing httpOnly, secure, sameSite — browser ignored
the Set-Cookie header because the options didn't match the original
cookie attributes. Cookie persisted after logout, allowing F5 to
re-authenticate via silent refresh.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 20:44:28 +01:00
BOHA
04828fefe2 fix: logout deletes all tokens from same browser/IP, not just current
On logout, finds all refresh tokens matching the same user + IP +
user-agent (same browser session) and deletes them all. This cleans
up zombie tokens from previous logins and token rotations that
were showing as stale sessions on the dashboard.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 20:38:09 +01:00
BOHA
f71ad6e2a8 fix: logout now properly cleans up session tokens
- Deletes current token AND tokens replaced by it
- Cleans up all expired tokens on logout
- Prevents stale sessions from showing on dashboard after re-login

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 20:35:28 +01:00
BOHA
456232cd82 fix: dashboard TOTP status always showing inactive
loadAuthData() didn't include totp_enabled or require_2fa in the
AuthData response. The frontend always saw undefined → false.

Now includes both fields from the database.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 20:31:06 +01:00
BOHA
33268b38ae fix: TOTP login flow loses remember_me — sessions expire after 1 hour
The TOTP verification endpoint always created refresh tokens with
remember_me=false and 1-hour expiry, regardless of what the user
selected at login.

Fix:
- Frontend now sends remember_me in the TOTP verify request body
- Backend reads remember_me and uses it for token expiry (30 days)
  and cookie maxAge

Users with 2FA who checked "remember me" will now stay logged in
for 30 days instead of being kicked out after 1 hour.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 20:28:54 +01:00
BOHA
c4c4433561 feat: editable billing text on invoices
- Added billing_text column to invoices table (VARCHAR 500)
- Prisma migration: 20260323_add_billing_text
- Form field on invoice create page with placeholder
- PDF uses billing_text, falls back to default translation
- Stored on create and editable on draft invoices

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 19:47:15 +01:00
BOHA
2540efbec2 refactor: merge InvoiceCreate into InvoiceDetail (single page for create + edit)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 19:34:16 +01:00
BOHA
5285c3c7c9 fix: VAT select in invoices — use admin-form-select instead of admin-form-input 2026-03-23 19:27:46 +01:00
BOHA
d33c2b3416 fix: invoice numbering — use MAX from invoices table instead of sequence counter 2026-03-23 19:25:16 +01:00
BOHA
93ea9911f8 fix: invoice items table — match offer detail card style
Changed from offers-editor-section + offers-items-table to
admin-card + admin-card-body + admin-table-responsive, matching
the offer detail page structure.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 19:22:01 +01:00
BOHA
892d83cd90 feat: add drag-and-drop item reordering to invoice create and edit
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 19:18:01 +01:00
BOHA
2b4a98b958 fix: save item position after drag-and-drop reordering 2026-03-23 19:06:21 +01:00
BOHA
bfb3a975ea fix: restrict item drag to parent table bounds 2026-03-23 19:04:55 +01:00
BOHA
3bef879ff9 fix: move useSensors hook to component top level (React hooks rules) 2026-03-23 19:03:38 +01:00
BOHA
185157fe86 feat: offer items drag-and-drop reordering + fix scope template insertion
1. Item reordering: replaced placeholder with @dnd-kit drag-and-drop.
   Each item row has a drag handle for reordering via vertical drag.
   Uses SortableContext with verticalListSortingStrategy.

2. Scope template insertion: fixed template loading to use already-fetched
   data instead of re-fetching from non-existent endpoint. Templates with
   sections are now stored fully and inserted directly on selection.
   Also copies template description to scope_description.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 19:02:15 +01:00
BOHA
95065f54eb fix: offer scope sections — add blue EN / red CZ language badges on title labels
Matches PHP styling with offers-lang-badge and offers-lang-badge-cz classes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 18:56:12 +01:00
BOHA
bcad377f92 fix: dashboard — gate all sections by user permissions
API now only returns data sections the user has permission to see:
- my_shift: attendance.record
- attendance: attendance.admin
- offers: offers.view
- projects: projects.view
- invoices: invoices.view
- orders: orders.view
- leave_pending: attendance.approve
- recent_activity: settings.audit

Frontend hides KPI cards, activity feed, and attendance sections
for users without the matching permissions.

Regular employees now only see their shift status, quick actions,
profile, and sessions — not company KPIs or admin data.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 18:51:29 +01:00
BOHA
a1c70ba25f fix: force all spinners inside buttons to 16px (admin-spinner-sm size) 2026-03-23 18:48:06 +01:00
BOHA
98454edcf1 fix: prevent buttons from resizing during loading state
- Added white-space: nowrap to .admin-btn (prevents text wrapping)
- Modal footer buttons get min-width: 100px for consistent sizing
- Spinner in buttons doesn't add extra vertical space

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 18:46:18 +01:00
BOHA
aeac76687b fix: all item/sub-object schemas accept string numbers from form inputs
Fixed offers, orders, attendance, scope-templates schemas — quantity,
unit_price, position, hours, minutes now use z.union([z.number(), z.string()])
with transform instead of bare z.number().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 18:42:41 +01:00
BOHA
a8a28d8472 fix: confirm modal — always use admin-btn-primary (admin-btn-danger has no CSS) 2026-03-23 14:17:31 +01:00
BOHA
040b41ed90 fix: pagination component — use correct CSS class names
Component used admin-pagination-btn/pages/dots but CSS has
admin-pagination-page/controls/ellipsis. Fixed to match existing CSS.
Added record count display.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 13:59:49 +01:00
BOHA
0b4b6b24e1 fix: attendance times showing +1 hour due to UTC timezone conversion
Times in the database are stored as local time (CET). JavaScript's
Date constructor treated them as UTC, then toLocaleTimeString added
+1 hour for CET timezone.

Fix: extract hours/minutes directly from the datetime string via regex
instead of going through Date object. No timezone conversion applied.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 13:50:30 +01:00
BOHA
bb0bf25ce0 fix: CSP and Permissions-Policy blocking GPS, geocoding, and map
- Permissions-Policy: geolocation=(self) instead of geolocation=()
  (was blocking all geolocation access)
- connect-src: added nominatim.openstreetmap.org for reverse geocoding
- script-src: added unpkg.com for Leaflet JS
- style-src: added unpkg.com for Leaflet CSS
- img-src: added *.tile.openstreetmap.org for map tiles

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 13:44:50 +01:00
BOHA
2718a7b716 fix: attendance admin — add user_name to records, fix Czech diacritics in table headers
- listAttendance() now maps users.first_name + last_name to user_name
- Fixed escaped Unicode in table headers (Zaměstnanec, Příchod, Poznámka)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 13:41:55 +01:00
BOHA
c817e004b7 feat: supplier name autocomplete on received invoices
- Added GET /api/admin/received-invoices/suppliers endpoint (distinct names)
- Upload and edit forms use HTML datalist for browser-native autocomplete
- Suggestions loaded once on page mount

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 13:32:38 +01:00
BOHA
a4c4a377c9 fix: frontend VAT preview — extract VAT from inclusive amount, not add on top 2026-03-23 13:27:50 +01:00
BOHA
8b5f216960 fix: received invoices — amount field is VAT-inclusive, extract VAT from it
Previously: amount was treated as base, VAT added on top (amount * rate / 100)
Now: amount includes VAT, VAT is extracted (amount - amount / (1 + rate/100))

Example: 9798.58 at 21% → VAT = 9798.58 - 8098.00 = 1700.58

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 13:24:54 +01:00
BOHA
fe12fde9db fix: convert dates to yyyy-MM-dd when opening received invoice edit form
ISO datetime strings from API caused "Invalid time value" in date picker.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 13:19:43 +01:00
BOHA
9a0acb8983 fix: allow any authenticated user to list vehicles
Vehicle list (GET) now requires only authentication, not trips.vehicles
permission. Users with trips.view can see available cars in the trip
modal. Create/update/delete still require trips.vehicles.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 13:12:22 +01:00
BOHA
20c1aab14c fix: use nodemailer address object for proper UTF-8 encoding in from name 2026-03-23 12:55:32 +01:00
BOHA
9f36ad0985 feat: configurable SMTP_FROM_NAME via .env (defaults to BOHA Automation) 2026-03-23 12:52:21 +01:00
BOHA
8a453deaac feat: add email notification for new leave requests
- mailer.ts: nodemailer transport via local sendmail
- leave-notification.ts: HTML email matching PHP template
- Sends notification to LEAVE_NOTIFY_EMAIL on new leave request
- Non-blocking: errors logged but don't fail the request
- Added LEAVE_NOTIFY_EMAIL and APP_URL env vars

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 11:54:29 +01:00
BOHA
0baa604ade fix: remove duplicate canSecurity declaration in Settings 2026-03-23 11:43:27 +01:00
BOHA
1a62b31cd2 fix: support PHP encryption format for TOTP secrets
PHP uses base64(nonce+ciphertext+tag), TS was using hex:hex:hex.
decrypt() now auto-detects the format. encrypt() now outputs
PHP-compatible base64 format for cross-compatibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 11:42:32 +01:00
BOHA
f40f9d2a4b feat: wire up mandatory 2FA toggle in global settings
Connects the existing UI button to GET/POST /api/admin/totp/required
endpoints. Fetches current state on load, toggles on click.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 11:40:50 +01:00
BOHA
e0fbae1530 fix: received invoices — show skeleton only on initial load, not on sort/filter
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 11:03:22 +01:00
BOHA
0ad88aa5ce fix: invoice item schema accepts string numbers from form inputs
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 11:01:34 +01:00
BOHA
d3a72c51a2 fix: table sort toggle — use single state object to prevent lost updates
Two separate useState calls (sort + order) caused React to skip
re-renders when clicking the same column — setSort returned the same
value so React bailed out, and the nested setOrder was lost.

Single state object guarantees a new reference on every click,
so React always re-renders and useListData always refetches.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 10:58:56 +01:00
BOHA
635c6fd0ff fix: table sorting blocked by pointerEvents:none during loading
Root cause: useListData set loading=true on every refetch, and all 4
admin list pages (offers, orders, invoices, projects) applied
pointerEvents:'none' while loading — blocking all clicks including
sort column headers.

Fix: removed setLoading(true) from refetch (matching PHP behavior)
and removed pointerEvents from all list page cards. Opacity fade
kept as visual feedback.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 10:57:17 +01:00
BOHA
56065c381b fix: align useTableSort with PHP version — userClicked ref, nullable activeSort
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 10:53:26 +01:00
BOHA
1a175e805b fix: use vehicle initial_km as start_km for first trip record
When no trips exist for a vehicle, the last-km endpoint now returns
the vehicle's initial_km instead of 0, matching the PHP behavior:
COALESCE(MAX(end_km), vehicle.initial_km, 0)

Also fixed ordering from id DESC to end_km DESC for correctness.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 10:49:42 +01:00
BOHA
7ef25a077b feat: add SPAYD QR payment code to invoice PDF
Generates QR code in SVG format using the SPAYD payment standard,
matching the PHP implementation. Contains: IBAN, amount, currency,
variable symbol, constant symbol, and invoice reference.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 10:37:43 +01:00
BOHA
47fb4dc8ac feat: integrate ProjectFileManager into project detail page
Replace the file management placeholder with the actual ProjectFileManager
component, providing projectId, projectNumber, hasPermission, and hasNasFolder
props from the existing page state.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 10:22:10 +01:00
BOHA
3c1a35ae9c feat: add ProjectFileManager component with file browser UI
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 10:20:49 +01:00
BOHA
b87081dd2c feat: integrate NAS file operations with project CRUD
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 10:19:15 +01:00
BOHA
49e668ee2a feat: add project files REST endpoints with auth and audit logging
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 10:19:11 +01:00
BOHA
ff26dc497d feat: add NasFileManager service with security-hardened file operations
TypeScript port of PHP NasFileManager with symlink rejection,
path traversal protection, MIME validation via file-type, and
blocked extension checking.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 10:16:36 +01:00
BOHA
373ea82279 fix: rewrite attendance print to match PHP design 1:1
- Dark table headers (#333), proper column widths, uppercase labels
- User header bar with gray background and total hours
- Records from userData.records (not filtered from global records)
- Fund row with covered/total and status badge
- Leave summary with vacation remaining
- Print wrapper table for repeating header
- Matching CSS: borders, fonts, spacing, badges

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 09:39:31 +01:00
BOHA
23ae832eeb fix: attendance print - return proper data structure with records, leave balances, and fund stats
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 09:36:52 +01:00