7.2 KiB
AI Report
Summary
Improved the employee import flow so repeated rows with the same employeeCode are treated as one employee while still creating a training history record for each course row. The import summary and template were updated to reflect employee creation/update, linked users, imported training records, and K/S/A target handling.
Files Changed
src/app/api/import-employees/route.tssrc/app/api/import-employees/template/route.tssrc/constants/thai-labels.tssrc/features/import-employees/api/types.tssrc/features/import-employees/components/employee-import-page.tsxdocs/ai/report.md
Root Cause / Reason For Change
- The original import flow only handled employee master data and K/S/A targets.
- Duplicate
employeeCoderows in a single file were rejected instead of being merged into one employee with many training rows. - The result summary contract was also inconsistent between backend and frontend.
Changes Made
- Split import headers into employee headers, training headers, and target headers.
- Expanded the downloadable template to include course name, category, training hours, training type, and training date.
- Changed import parsing to group rows by
employeeCode. - Kept employee creation/updating at one record per
employeeCode. - Added validation for per-row training history data:
- course name
- category
K/S/A - training hours
- optional training type with normalization
- optional training date with fallback to import year
- Created one approved
training_recordsrow for each valid training row. - Preserved K/S/A employee target import and fallback behavior.
- Fixed import summary fields so frontend and backend now use the same names.
- Updated the import result UI to show:
- created employees
- updated employees
- linked users
- imported training records
- imported targets
Testing Checklist
employeeCoderepeated in one file creates one employee- repeated employee rows still create multiple training records
- existing employee in database is updated instead of duplicated
- import summary returns consistent field names
- downloadable template includes training history columns
npx tsc --noEmitpassesnpm run lintpasses with existing repo warnings only- manually upload a file with one employee and many course rows
- manually upload a file for an existing employee and confirm no duplicate employee is created
- confirm overview/report/training history totals reflect imported approved records
Risks
- Imported training records are marked as approved immediately so they affect dashboards and reports right away.
- If the same file is imported again, training history rows may be duplicated because this change intentionally deduplicates employees, not course rows.
- The audit log summary text still falls back to the generic import message shape because only the import contract was changed in this task.
Rollback Plan
- Revert
src/app/api/import-employees/route.ts. - Revert
src/app/api/import-employees/template/route.ts. - Revert
src/constants/thai-labels.ts. - Revert
src/features/import-employees/api/types.ts. - Revert
src/features/import-employees/components/employee-import-page.tsx. - Restore or remove
docs/ai/report.mdas needed.
Thai UI Fix Report
Summary
Fixed corrupted Thai text on /dashboard/import-employees after the previous import work. The issue was caused by Thai literals being saved in a broken encoding state in the import page, shared Thai label constants, and related import API/template files.
Files Changed
src/constants/thai-labels.tssrc/features/import-employees/components/employee-import-page.tsxsrc/app/api/import-employees/template/route.tssrc/app/api/import-employees/route.tssrc/components/themes/font.config.tssrc/styles/themes/training-system.cssdocs/ai/report.md
Root Cause
- Some Thai strings were rewritten from garbled terminal output during the previous task.
- The
/dashboard/import-employeespage and related API messages therefore showed mojibake instead of readable Thai. - The main
training-systemtheme also did not explicitly prioritize a Thai-capable web font.
Changes Made
- Restored all corrupted Thai labels in
src/constants/thai-labels.ts. - Rewrote the import employee UI copy in
src/features/import-employees/components/employee-import-page.tsxwith readable Thai text. - Restored Thai sample data and error text in
src/app/api/import-employees/template/route.ts. - Restored Thai validation and response messages in
src/app/api/import-employees/route.tswithout changing the import logic. - Added
Noto Sans Thaiinsrc/components/themes/font.config.ts. - Updated
src/styles/themes/training-system.cssto prioritize the Thai font in the main dashboard theme.
Testing Checklist
rgno longer finds mojibake text in import-employees related files- open
/dashboard/import-employeesand verify all Thai text reads normally - try upload with invalid file and confirm Thai error messages display correctly
- download template and verify Thai headers/sample values are readable in Excel
Notes
- This task intentionally did not change employee import business logic.
- The fix is focused on Thai text rendering and Thai-readable feedback only.
Extract Total Hours Report
Summary
Removed ชั่วโมงรวม, ชั่วโมง K, ชั่วโมง S, and ชั่วโมง A from the employee import template and import flow. The import now accepts only employee data plus training history rows, while hour summaries remain derived from real Training Record data.
Files Changed
src/constants/thai-labels.tssrc/app/api/import-employees/template/route.tssrc/app/api/import-employees/route.tssrc/features/import-employees/components/employee-import-page.tsxsrc/features/import-employees/api/types.tsdocs/ai/report.md
Columns Removed From Import Template
ชั่วโมงรวมชั่วโมง Kชั่วโมง Sชั่วโมง A
Logic Changes
- Removed target-hour columns from
thaiImportTemplateHeaders. - Updated the downloadable Excel template so it no longer includes K/S/A summary columns.
- Removed Excel parsing and validation for total/K/S/A hours from the import route.
- Removed import-time writes for employee target-hour values from the import route.
- Kept employee creation/update and
Training Recordcreation as before. - Updated the import page copy so it explains that hour summaries are calculated automatically from
Training Record. - Removed import summary cards related to imported K/S/A targets and training-policy fallback.
Testing
npx tsc --noEmit- Verify template headers no longer contain total/K/S/A columns
- Verify import still accepts repeated employee rows with multiple course rows
- Verify successful import still creates employee + training records
Result
- Import template no longer exposes total/K/S/A hour columns.
- Import no longer treats Excel hour-summary fields as source of truth.
- Hour summaries remain based on real training records only.