Commit Graph

65 Commits

Author SHA1 Message Date
HotSwapp
cd3e5505c3 Add .gitignore and remove sensitive/generated files
- Add comprehensive .gitignore file to exclude:
  * data-import/ directory with all CSV files
  * Database files (*.db)
  * Legacy data directories (old-csv/, old-database/)
  * Generated HTML files (rolodex.html, sync_result.html)
  * Temporary files (cookies.txt, test_upload.csv, etc.)
  * Python cache files (__pycache__/)
  * IDE and OS files (.vscode/, .DS_Store, etc.)
- Remove all previously tracked sensitive and generated files from git
2025-10-14 08:05:48 -05:00
HotSwapp
65e4995a5b fixed sort time 2025-10-14 07:56:13 -05:00
HotSwapp
9b2ce0d28f Final enhancement: Increase encoding detection read size to 50KB
- Increased read size from 20KB to 50KB in both main.py and import_legacy.py
- This ensures problematic bytes at position 3738+ are caught during encoding detection
- Provides maximum robustness for legacy CSV files with deeply embedded encoding issues
- Maintains all previous improvements including fallback mechanisms
2025-10-13 21:44:17 -05:00
HotSwapp
05b9d38c61 Enhance UTF-8 encoding fix for CSV imports
- Increased encoding detection read size from 10KB to 20KB in both main.py and import_legacy.py
- This ensures problematic bytes deeper in files (like position 3738) are caught during encoding detection
- Maintains backwards compatibility with properly encoded UTF-8 files
- Provides more robust handling of legacy CSV files with mixed encodings
2025-10-13 20:00:43 -05:00
HotSwapp
b6c09dc836 Fix UTF-8 encoding issue in CSV imports
- Updated open_text_with_fallbacks() in both main.py and import_legacy.py
- Increased fallback read size from 1KB to 10KB to catch encoding issues deeper in files
- Added proper fallback mechanism to main.py version of the function
- This fixes the 'utf-8' codec can't decode byte 0xa9 error when uploading planinfo.csv files
2025-10-13 19:49:18 -05:00
HotSwapp
84c3dac83a Improve Rolodex imports, display, and add repair script 2025-10-13 15:00:13 -05:00
HotSwapp
2e2380552e Customer 360: extended Client fields, auto-migrate, updated Rolodex CRUD/templates, QDRO routes/views, importer mapping
QDRO links appear in rolodex_view.html case rows and case.html header when QDRO data exists, matching legacy flows.
2025-10-13 14:04:35 -05:00
HotSwapp
4cd35c66fd Rolodex UX: add /rolodex/{id}/edit route, prefill support for new form, fix edit links, and improve empty state guidance. Also fix header width lints in template. 2025-10-13 10:37:20 -05:00
HotSwapp
42ea13e413 Fix import status logic bug
The import_log.status was incorrectly set to 'failed' when there were NO errors.
The condition 'if result["errors"]' evaluates to False when errors list is empty,
causing the logic to be inverted.

Fixed: 'completed' if not result['errors'] else 'failed'

This caused successful imports with 0 errors to show as 'Failed' in the UI.
2025-10-13 10:23:46 -05:00
HotSwapp
02d439cf8b Update duplicate handling docs to include pension tables
- Document composite primary key handling for pension tables
- Add code examples for both single and composite key duplicate detection
- List all pension-related tables with duplicate protection
2025-10-13 09:36:09 -05:00
HotSwapp
c3bbf927a5 Add duplicate handling for pension import functions
- Added duplicate detection and handling for pensions, pension_death, pension_separate, and pension_results imports
- Tracks (file_no, version) composite keys in-memory during import
- Checks database for existing records before insert
- Handles IntegrityError gracefully with fallback to row-by-row insertion
- Returns 'skipped' count in import results
- Prevents transaction rollback cascades that previously caused all subsequent rows to fail
- Consistent with existing rolodex duplicate handling pattern
2025-10-13 09:35:35 -05:00
HotSwapp
69f1043be3 Fix upload detection for model class names and add States/Printers/Setup import
- Enhanced get_import_type_from_filename() to recognize model class names (LegacyFile, FilesR, etc.) in addition to legacy CSV names
- Added import functions for States, Printers, and Setup reference tables
- Updated VALID_IMPORT_TYPES and IMPORT_ORDER to include new tables
- Updated admin panel table counts to display new reference tables
- Created UPLOAD_FIX.md documentation explaining the changes and how to handle existing unknown files

This fixes the issue where files uploaded with model class names (e.g., LegacyFile.csv) were being categorized as 'unknown' instead of being properly detected.
2025-10-13 09:08:06 -05:00
HotSwapp
e6a78221e6 Add documentation for pension_schedule schema fix 2025-10-13 08:54:45 -05:00
HotSwapp
83a3959906 Fix pension_schedule table schema to support multiple vesting milestones per pension
- Changed primary key from composite (file_no, version) to auto-increment id
- A pension can have multiple vesting schedule entries (e.g., vests 20% at year 1, 100% at year 5)
- Added index on (file_no, version) for efficient lookups
- Successfully imported 502 vesting schedule entries for 416 unique pensions
- Some pensions have up to 6 vesting milestones
2025-10-13 08:54:19 -05:00
HotSwapp
ac98bded69 Add detailed skip tracking for phone imports
- Track skipped_no_phone and skipped_no_id separately
- Display skip information in admin UI with warning icon
- Clarify that empty phone numbers cannot be imported (PK constraint)
- Update documentation to explain expected skip behavior
- Example: 143 rows without phone numbers is correct, not an error

When importing PHONE.csv with empty phone numbers:
- Rows are properly skipped (cannot have NULL in primary key)
- User sees: '⚠️ Skipped: 143 rows without phone number'
- This is expected behavior, not a bug
2025-10-13 08:46:53 -05:00
HotSwapp
63809d46fb Fix PHONE.csv import duplicate constraint error
- Implement upsert logic in import_phone() function
- Check for existing (id, phone) combinations before insert
- Track duplicates within CSV to skip gracefully
- Update existing records instead of failing on duplicates
- Add detailed statistics: inserted, updated, skipped counts
- Align with upsert pattern used in other import functions
- Add documentation in docs/PHONE_IMPORT_FIX.md

Fixes: UNIQUE constraint failed: phone.id, phone.phone error
when re-importing or uploading CSV with duplicate entries
2025-10-12 21:45:30 -05:00
HotSwapp
22e99d27ed Fix UNIQUE constraint errors in reference table imports with upsert logic
- Implement upsert (INSERT or UPDATE) logic for all reference table imports
- Fixed functions: import_trnstype, import_trnslkup, import_footers,
  import_filestat, import_employee, import_gruplkup, import_filetype,
  import_fvarlkup, import_rvarlkup
- Now checks if record exists before inserting; updates if exists
- Makes imports idempotent - can safely re-run without errors
- Added tracking of inserted vs updated counts in result dict
- Maintains batch commit performance for large imports
- Fixes sqlite3.IntegrityError when re-importing CSV files
2025-10-12 21:36:28 -05:00
HotSwapp
ad1c75d759 docs: Add comprehensive guide on duplicate record handling 2025-10-12 21:08:38 -05:00
HotSwapp
2833110de0 chore: Remove test database file 2025-10-12 21:07:59 -05:00
HotSwapp
c3e741b7ad fix: Handle duplicate IDs in rolodex import gracefully
- Added duplicate tracking within import session (seen_in_import set)
- Skip records that already exist in database
- Added fallback to row-by-row insert when bulk insert fails
- Track skipped records in result
- Prevents cascade errors after UNIQUE constraint violation
- Gracefully handles legacy data with duplicate IDs
2025-10-12 21:07:52 -05:00
HotSwapp
789eb2c134 docs: Add comprehensive troubleshooting guide for import issues 2025-10-12 20:13:55 -05:00
HotSwapp
89ff90a384 docs: Add comprehensive documentation of CSV encoding fix 2025-10-12 19:19:56 -05:00
HotSwapp
7958556613 Fix: Improved CSV encoding detection for legacy data with non-standard characters
- Changed encoding fallback order to prioritize iso-8859-1/latin-1 over cp1252
- Increased encoding test from 1KB to 10KB to catch issues deeper in files
- Added proper file handle cleanup on encoding failures
- Resolves 'charmap codec can't decode byte 0x9d' error in rolodex import
- Tested with rolodex file containing 52,100 rows successfully
2025-10-12 19:19:25 -05:00
HotSwapp
f4c5b9019b Fix Unicode encoding error in rolodex import
- Enhanced open_text_with_fallbacks() function to handle problematic bytes
- Added CP1250 encoding to fallback list for better character set support
- Added graceful error handling with replacement characters for edge cases
- Ensures rolodex CSV import works with legacy encoding issues

Fixes: 'charmap' codec can't decode byte 0x9d error during rolodex import
2025-10-12 18:24:24 -05:00
HotSwapp
97af250657 import: make FILETYPE import idempotent by skipping existing and in-batch duplicates; tested via Docker admin import twice without UNIQUE constraint errors 2025-10-08 13:48:00 -05:00
HotSwapp
c23e8d0b8a feat(admin): add mapping workflow for unknown CSVs
- New POST /admin/map-files to reclassify unknown files to a chosen import type
- Centralize VALID_IMPORT_TYPES and pass to admin template
- UI: dropdown + 'Map Selected' button in Unknown card
- JS: mapSelectedFiles() posts selection and reloads on success
- Keeps UUID suffix, prevents traversal, logs actions
2025-10-08 13:22:34 -05:00
HotSwapp
dc1c10f44b feat: Add delete button for uploaded CSV files in admin panel
- Added delete button (trash icon) next to each uploaded file in the import section
- Implemented DELETE endpoint at /admin/delete-file/{filename} with authentication and validation
- Added JavaScript function to handle file deletion with confirmation dialog
- Includes security checks for directory traversal and file existence
- Logs file deletion actions with username for audit trail
- UI automatically refreshes after successful deletion
2025-10-08 13:07:04 -05:00
HotSwapp
fa4e0b9f62 Add Database Status section to admin panel
- Added table_counts query in /admin route to get record counts for all tables
  * Reference tables (TrnsType, TrnsLkup, Footers, FileStat, Employee, etc.)
  * Core data tables (Rolodex, LegacyPhone, LegacyFile, Ledger, etc.)
  * Specialized tables (PlanInfo, Qdros, Pensions, etc.)
  * Modern models (Client, Phone, Case, Transaction, Payment, Document)

- Created Database Status UI section in admin.html
  * Four-column layout showing all table categories
  * Color-coded badges (green=has data, gray=empty)
  * Check mark icons for populated tables
  * Table row highlighting based on data presence
  * Legend explaining the visual indicators

- Helps users track import progress at a glance
- Shows which tables have been successfully imported
- Distinguishes between legacy and modern model data
2025-10-08 12:59:35 -05:00
HotSwapp
2e7e9693c5 Add next section prompt and task summary 2025-10-08 09:55:12 -05:00
HotSwapp
e11e9aaf16 Add comprehensive CSV import system documentation
- Created IMPORT_GUIDE.md: Complete user guide with step-by-step instructions
  * Detailed import order for all 27+ tables
  * Troubleshooting guide
  * Data validation procedures
  * Best practices and performance notes

- Created IMPORT_SYSTEM_SUMMARY.md: Technical implementation summary
  * Complete list of all implemented functions (28 import + 7 sync)
  * Architecture and data flow diagrams
  * Module organization
  * Testing status and next steps
  * ~3,000 lines of code documented
2025-10-08 09:54:30 -05:00
HotSwapp
4030dbd88e Implement comprehensive CSV import system for legacy database migration
- Added 5 new legacy models to app/models.py (FileType, FileNots, RolexV, FVarLkup, RVarLkup)
- Created app/import_legacy.py with import functions for all legacy tables:
  * Reference tables: TRNSTYPE, TRNSLKUP, FOOTERS, FILESTAT, EMPLOYEE, GRUPLKUP, FILETYPE, FVARLKUP, RVARLKUP
  * Core tables: ROLODEX, PHONE, ROLEX_V, FILES, FILES_R, FILES_V, FILENOTS, LEDGER, DEPOSITS, PAYMENTS
  * Specialized: PLANINFO, QDROS, PENSIONS and all pension-related tables
- Created app/sync_legacy_to_modern.py with sync functions to populate modern models from legacy data
- Updated admin routes in app/main.py:
  * Extended process_csv_import to support all new import types
  * Added /admin/sync endpoint for syncing legacy to modern models
  * Updated get_import_type_from_filename to recognize all CSV file patterns
- Enhanced app/templates/admin.html with:
  * Import Order Guide showing recommended import sequence
  * Sync to Modern Models section with confirmation dialog
  * Sync results display with detailed per-table statistics
  * Updated supported file formats list
- All import functions use batch processing (500 rows), proper error handling, and structured logging
- Sync functions maintain foreign key integrity and skip orphaned records with warnings
2025-10-08 09:41:38 -05:00
HotSwapp
2efbf14940 fixed rolodex page 2025-10-07 23:09:15 -05:00
HotSwapp
fdcff9fbb2 Expand encoding fallback to handle more legacy CSV encodings
- Added windows-1252, cp1250, iso-8859-1 to encoding fallback list
- Enhanced error logging in open_text_with_fallbacks function
- Improved error messages to show all attempted encodings
- Added warning logs for each encoding attempt that fails

This should resolve 'charmap' codec errors and other encoding issues with legacy CSV files that use different Windows codepages or ISO encodings.
2025-10-07 22:25:34 -05:00
HotSwapp
09ef56fc1d Apply encoding fallback to all CSV importers (phone, files, ledger, payments, qdros)
- Updated import_phone_data to use open_text_with_fallbacks for encoding support
- Updated import_files_data to use open_text_with_fallbacks for encoding support
- Updated import_ledger_data to use open_text_with_fallbacks for encoding support
- Updated import_qdros_data to use open_text_with_fallbacks for encoding support
- Updated import_payments_data to use open_text_with_fallbacks for encoding support

All CSV import functions now use the same encoding fallback pattern that tries utf-8, utf-8-sig, cp1252, and latin-1 encodings to handle legacy CSV files with different encodings.
2025-10-07 22:21:07 -05:00
HotSwapp
58b2bb9a6c Add stored filename visibility and auto-select functionality to admin upload results
- Added 'Stored Filename' column to Upload Results table showing the actual filename used for storage
- Added 'Select All' button for each import type section to quickly select/deselect all files
- Improved JavaScript to handle select all/deselect all functionality with proper button state management
- Enhanced UI to clearly distinguish between original and stored filenames
2025-10-07 22:15:08 -05:00
HotSwapp
9497d69c76 Navbar: remove brand logo image; keep text brand only 2025-10-07 22:03:20 -05:00
HotSwapp
2a7d91da54 Auth UI: reliably hide navbar on login via body_class; add .auth-logo sized ~button width; restart 2025-10-07 21:59:40 -05:00
HotSwapp
bb68c489ee Auth UI: hide navbar on login via base navbar block; keep footer; remove circular logo styling; widen auth wrapper; restart container 2025-10-07 21:50:18 -05:00
HotSwapp
180314d43d UI: Simplify login page styling, remove purple gradient background, stop global .container overrides; add scoped .auth-wrapper; neutralize buttons/cards; rebuild verified via smoke test 2025-10-07 21:37:10 -05:00
HotSwapp
7fe57ccb6d Improve login screen design and functionality
- Increased logo size from 60x60 to 120x120px with proper styling
- Enhanced card layout with better padding and rounded corners
- Added modern gradient background and improved visual hierarchy
- Improved form styling with larger inputs and better spacing
- Enhanced password visibility toggle with better UX
- Improved error message styling with icons and rounded corners
- Added responsive design improvements for better mobile experience
- Updated color scheme with modern gradients and improved contrast
2025-10-07 21:33:12 -05:00
HotSwapp
aeb0be6982 feat(reports): add Envelope, Phone Book (address+phone) and Rolodex Info reports
- PDF builders in app/reporting.py (envelope, phone+address, rolodex info)
- Endpoints in app/main.py with auth, filtering, logging, Content-Disposition
- New HTML template report_phone_book_address.html
- Rolodex bulk actions updated with buttons/links
- JS helper to submit selections to alternate endpoints

Tested via docker compose build/up and health check.
2025-10-07 17:50:03 -05:00
HotSwapp
684b947651 docs: add next-section prompt for Reports (Envelope, Phone Book variants, Rolodex Info); confirm TODO next step pending run/test 2025-10-07 17:40:02 -05:00
HotSwapp
f649b3c4f1 reports: add PDF generation infra (fpdf2); Phone Book CSV/PDF export; Payments - Detailed report with preview and PDF grouped by deposit date; update Dockerfile for deps; smoke-tested in Docker 2025-10-07 17:30:50 -05:00
HotSwapp
a4f47fce4f docs(todo): check off structured logging/audit trail; audit logs on ledger CUD with pre/post totals; payments search and dashboard present 2025-10-07 17:19:44 -05:00
HotSwapp
d3d89c7a5f feat(logging): structured audit logs for ledger CRUD with user, keys, pre/post balances\n\n- Add compute_case_totals_for_case_id and helpers to extract ledger keys\n- Instrument ledger_create/update/delete to emit ledger_audit with deltas\n- Preserve existing event logs (ledger_create/update/delete)\n- Verified in Docker; smoke tests pass 2025-10-07 17:10:36 -05:00
HotSwapp
e07a4fda1c Answer-table pattern: add reusable macros, integrate with Rolodex; bulk actions retained. Field prompts/help: generic focus-based help in forms (case, rolodex); add JS support. Rebuild Docker. 2025-10-07 17:00:54 -05:00
HotSwapp
748fe92565 chore(todo): check off completed legacy MVP items (models, imports, rolodex CRUD & search, dashboard/case/ledger basics, payments search, amount auto-compute, item_no uniqueness) 2025-10-07 16:32:28 -05:00
HotSwapp
1eb8ba8edd API: Standardized JSON list responses with Pydantic schemas and Pagination; add sort_by/sort_dir validation with whitelists; consistent JSON 401 for /api/*; structured logging for sorting/pagination; add pydantic dep; add Docker smoke script and README docs. 2025-10-07 16:05:09 -05:00
HotSwapp
c68ba45ceb Add legacy SQLAlchemy models mapped from docs/legacy-schema.md: ROLODEX, PHONE, FILES (+R/V), LEDGER, FILESTAT, FOOTERS, EMPLOYEE, STATES, GRUPLKUP, PRINTERS, SETUP, DEPOSITS, PAYMENTS (legacy), TRNSTYPE, TRNSLKUP, PLANINFO, QDROS, PENSIONS (+RESULTS/MARRIAGE/DEATH/SCHEDULE/SEPARATE). Add appropriate FKs and indexes; keep modern models intact. 2025-10-07 10:12:00 -05:00
HotSwapp
432f303a33 docs: add inferred legacy schema from CSV headers and .SC usage to guide migration 2025-10-07 09:51:30 -05:00