# Import Center

Import Center (`/import-center`) is the single operational upload entry point for Main Price List, Clearance Price List, Price Update, Shipment, and Salesman Van Stock. Catalog Center and historical import pages link here; they do not run competing upload logic.

## Safe staged workflow

1. Upload without mutating operational data.
2. Inspect the detected type and confidence.
3. Confirm or change the final import purpose.
4. Analyze rows and review issues.
5. Resolve duplicate groups with Keep First, Keep Second, Skip Both, or row editing; bulk Keep First, Keep Last, and Skip All are available.
6. Edit or skip problem rows and review the change summary.
7. Confirm once; the locked session prevents replay from creating another active version.

Rows use Ready, Needs Review, Invalid, and Skipped. Ready rows may be imported while unresolved/problem rows remain audited as skipped, producing `completed_with_skipped_rows`. Only unreadable files, absent required mappings, or no usable rows block the whole file.

## Price semantics

- **Main Price List:** full active Main catalog membership replacement.
- **Clearance Price List:** full active Clearance membership replacement.
- **Price Update:** updates only products present in the file and leaves other membership unchanged; unknown products require review and are not silently created.

Full replacements build a staging catalog inside a database transaction. The new catalog is activated and the previous active catalog archived only after all rows are written. A failure rolls everything back and leaves the old catalog active. Products omitted from a new list remain in the master products table and historical records. Exactly one catalog and one price import remain active for each full-list type.

## Other import purposes

Shipment passes into the existing Shipment parser and does not replace prices. Salesman Van Stock requires an explicit salesman/van and preserves its existing snapshot semantics; it is not Stock Replenishment and is not additive receiving.

Original row data and user decisions are retained in the session/import-item JSON for audit. Existing uploaded sessions can be returned to Confirm and safely re-analyzed from their unchanged stored original file.

## Background analysis and large files

The upload request only validates and stores the original file, creates an idempotent `ImportSession`, and returns immediately. Confirming the purpose queues `AnalyzeImportSession` on the database-backed `imports` queue. The persisted status moves through `awaiting_confirmation → analysis_queued → analyzing → ready / needs_review / failed`; History and Preview auto-refresh and may be closed/reopened safely.

The upload form carries a unique request token, and status claiming prevents browser retry, refresh, or double-click from creating a second session or analysis job. A background exception is persisted in `notes` and displayed with a retry action. Production runs the queue through a cPanel cron entry guarded by `flock`, so it is independent of SSH sessions and overlapping workers cannot start. Full price activation remains synchronous and transactional because the measured production activation completed in about one second; replay protection remains in `ImportCenterWorkflowService`.
