# Cazuri in care CODFISCAL_CNP e invalid dar REGCOMERT_CI_PASS contine un CNP valid (campuri inversate). param([string]$Dir = "D:\PROIECTE\FLORA\FLORA2ROA\EXEMPLE\hotel") function Test-CNP([string]$c) { if ($c -notmatch '^\d{13}$') { return $false } $w = @(2,7,9,1,4,6,3,5,8,2,7,9); $s = 0 for ($i = 0; $i -lt 12; $i++) { $s += [int]::Parse($c[$i]) * $w[$i] } $r = $s % 11; if ($r -eq 10) { $r = 1 } return ($r -eq [int]::Parse($c[12])) } $rows = @{} Get-ChildItem -Path $Dir -Filter 'bts_detalii_facturi_rep_*.xml' | ForEach-Object { $t = Get-Content $_.FullName -Raw foreach ($m in [regex]::Matches($t, '(?is)([^<]*).*?([^<]*)\s*([^<]*)')) { $nume = $m.Groups[1].Value.Trim().ToUpper() $cod = $m.Groups[2].Value.Trim().ToUpper() $reg = $m.Groups[3].Value.Trim().ToUpper() if ($cod -ne '') { $rows["$nume|$cod|$reg"] = [pscustomobject]@{ Nume=$nume; Cod=$cod; Reg=$reg } } } } $swap = $rows.Values | Where-Object { $d = $_.Cod -replace '[^\d]', '' $r = $_.Reg -replace '[^\d]', '' -not (Test-CNP $d) -and (Test-CNP $r) } "cazuri cu campuri inversate (CNP valid in REGCOMERT) = $($swap.Count)" $swap | Format-Table -AutoSize Nume, Cod, Reg | Out-String -Width 200 # exista informatie de tara la cumparator? $f = Get-ChildItem -Path $Dir -Filter 'bts_detalii_facturi_rep_*.xml' | Select-Object -First 1 $t = Get-Content $f.FullName -Raw $m = [regex]::Match($t, '(?is).*?') '' '=== campurile de tara existente in XML (primul rand) ===' [regex]::Matches($m.Value, '(?i)<(\w*TARA\w*)>([^<]*)') | ForEach-Object { " $($_.Groups[1].Value) = [$($_.Groups[2].Value)]" } '' '=== cate randuri au COMPANIE_TARA completat ===' $cuTara = 0; $total = 0 Get-ChildItem -Path $Dir -Filter 'bts_detalii_facturi_rep_*.xml' | ForEach-Object { $txt = Get-Content $_.FullName -Raw foreach ($mm in [regex]::Matches($txt, '(?i)([^<]*)')) { $total++ if ($mm.Groups[1].Value.Trim() -ne '') { $cuTara++ } } } "COMPANIE_TARA completat pe $cuTara din $total randuri"