Import parteneri: se curata doar CNP-urile invalide, codul persoanelor juridice ramane neatins
This commit is contained in:
49
ALTE/check_swap_tara.ps1
Normal file
49
ALTE/check_swap_tara.ps1
Normal file
@@ -0,0 +1,49 @@
|
||||
# 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)<CUMPARATOR>([^<]*)</CUMPARATOR>.*?<CODFISCAL_CNP>([^<]*)</CODFISCAL_CNP>\s*<REGCOMERT_CI_PASS>([^<]*)</REGCOMERT_CI_PASS>')) {
|
||||
$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)<ROW>.*?</ROW>')
|
||||
''
|
||||
'=== campurile de tara existente in XML (primul rand) ==='
|
||||
[regex]::Matches($m.Value, '(?i)<(\w*TARA\w*)>([^<]*)</\1>') | 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)<COMPANIE_TARA>([^<]*)</COMPANIE_TARA>')) {
|
||||
$total++
|
||||
if ($mm.Groups[1].Value.Trim() -ne '') { $cuTara++ }
|
||||
}
|
||||
}
|
||||
"COMPANIE_TARA completat pe $cuTara din $total randuri"
|
||||
Reference in New Issue
Block a user