fix: stable scan display, accurate workflow preview, cladiri count

ROOT CAUSE: The cross-reference between immovable list and GIS layer
produces wildly different matchedCount on each scan (320, 430, 629, 433)
because the eTerra immovable/list API with inscrisCF=-1 returns
inconsistent results across calls. The GIS layer count (505) is stable.

SCAN DISPLAY — now uses only stable numbers:
- Header shows 'Layer GIS: 505 terenuri + X cladiri' (stable ArcGIS count)
- Shows 'Lista imobile: 2.717 (estimat ~2.212 fara geometrie)' using
  simple subtraction totalImmovables - remoteGisCount
- Cross-ref matchedCount kept internally for import logic, but NOT shown
  as the primary number — eliminates visual instability
- hasNoGeomParcels now uses estimated count (stable)

WORKFLOW PREVIEW — now accurate:
- Step 1: 'Sync GIS — descarca 505 terenuri + X cladiri' (separate counts)
  or 'skip (date proaspete in DB)' when fresh
- Step 2 (enrichment): Fixed 'deja imbogatite' bug when DB is empty.
  Now correctly computes what WILL be in DB after sync completes:
  geoAfterSync + noGeomAfterImport - localDbEnrichedComplete
- Steps 3-4 unchanged

CLADIRI COUNT:
- Scan now also fetches CLADIRI_ACTIVE layer count (lightweight, OBJECTID only)
- New field remoteCladiriCount in NoGeomScanResult
- Displayed in header and workflow step 1
- Non-fatal: if CLADIRI fetch fails, just shows 0
This commit is contained in:
AI Assistant
2026-03-07 21:40:38 +02:00
parent 531c3b0858
commit b287b4c34b
3 changed files with 88 additions and 50 deletions
@@ -113,10 +113,12 @@ export type NoGeomQuality = {
export type NoGeomScanResult = {
totalImmovables: number;
/** Immovables that matched a remote GIS feature (have geometry) */
/** Immovables that matched a remote GIS feature (cross-ref, may vary) */
withGeometry: number;
/** Total features in the remote ArcGIS TERENURI_ACTIVE layer */
/** Total features in the remote ArcGIS TERENURI_ACTIVE layer (stable) */
remoteGisCount: number;
/** Total features in the remote ArcGIS CLADIRI_ACTIVE layer (stable) */
remoteCladiriCount: number;
noGeomCount: number;
/** Match quality: how many matched by cadastral ref vs immovable ID */
matchedByRef: number;
@@ -185,6 +187,7 @@ export async function scanNoGeometryParcels(
totalImmovables: 0,
withGeometry: 0,
remoteGisCount: 0,
remoteCladiriCount: 0,
noGeomCount: 0,
matchedByRef: 0,
matchedById: 0,
@@ -233,6 +236,25 @@ export async function scanNoGeometryParcels(
pageSize: 2000,
});
// 2b. Also fetch CLADIRI_ACTIVE count (lightweight, just OBJECTID)
const cladiriLayer = {
id: "CLADIRI_ACTIVE",
name: "CLADIRI_ACTIVE",
endpoint: "aut" as const,
whereTemplate: "{{adminField}}={{siruta}} AND IS_ACTIVE=1",
};
let remoteCladiriCount = 0;
try {
const cladiriFeatures = await client.fetchAllLayer(cladiriLayer, siruta, {
returnGeometry: false,
outFields: "OBJECTID",
pageSize: 2000,
});
remoteCladiriCount = cladiriFeatures.length;
} catch {
// Non-fatal — just won't show clădiri count
}
const remoteCadRefs = new Set<string>();
const remoteImmIds = new Set<string>();
for (const f of remoteFeatures) {
@@ -392,6 +414,7 @@ export async function scanNoGeometryParcels(
totalImmovables: allImmovables.length,
withGeometry: matchedCount,
remoteGisCount: remoteFeatures.length,
remoteCladiriCount,
noGeomCount: noGeomItems.length,
matchedByRef,
matchedById,