51 lines
2.1 KiB
PowerShell
51 lines
2.1 KiB
PowerShell
# Simulare a regulii GetCodFiscalValid pe TOATE codurile din XML-urile Fidelio.
|
|
# Raporteaza cate coduri se pastreaza, cate se sterg si cate sunt straine (nevalidate).
|
|
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]))
|
|
}
|
|
function Test-CUI([string]$c) {
|
|
if ($c -notmatch '^\d{2,10}$') { return $false }
|
|
$c = $c.PadLeft(10, '0'); $k = '7532175321'; $s = 0
|
|
for ($i = 0; $i -lt 9; $i++) { $s += [int]::Parse($c[$i]) * [int]::Parse($k[$i]) }
|
|
$r = ($s * 10) % 11; if ($r -eq 10) { $r = 0 }
|
|
return ($r -eq [int]::Parse($c[9]))
|
|
}
|
|
|
|
$map = @{}
|
|
Get-ChildItem -Path $Dir -Filter 'bts_detalii_facturi_rep_*.xml' | ForEach-Object {
|
|
$t = Get-Content $_.FullName -Raw
|
|
foreach ($m in [regex]::Matches($t, '(?i)<CODFISCAL_CNP>([^<]*)</CODFISCAL_CNP>')) {
|
|
$v = $m.Groups[1].Value.Trim().ToUpper()
|
|
if ($v -ne '') { $map[$v] = 1 }
|
|
}
|
|
}
|
|
|
|
$pastratCNP = 0; $pastratCUI = 0; $strain = 0; $sters = 0
|
|
$listaStersi = @()
|
|
foreach ($cod in $map.Keys) {
|
|
$prefix = ($cod -replace '[^A-Z]', '')
|
|
$roPrefix = @('RO', 'CUI', 'CF', 'CIF') -contains $prefix
|
|
$romanesc = ($prefix -eq '' -or $roPrefix)
|
|
if (-not $romanesc) { $strain++; continue }
|
|
$cifre = ($cod -replace '[^\d]', '')
|
|
if ($cifre.Length -eq 13 -and -not $roPrefix) {
|
|
if (Test-CNP $cifre) { $pastratCNP++ } else { $sters++; $listaStersi += $cod }
|
|
} elseif ($cifre.Length -ge 2 -and $cifre.Length -le 10) {
|
|
if (Test-CUI $cifre) { $pastratCUI++ } else { $sters++; $listaStersi += $cod }
|
|
} else { $sters++; $listaStersi += $cod }
|
|
}
|
|
|
|
"total coduri distincte : $($map.Count)"
|
|
"CNP valide pastrate : $pastratCNP"
|
|
"CUI valide pastrate : $pastratCUI"
|
|
"straine (nevalidate) : $strain"
|
|
"STERSE (invalide) : $sters"
|
|
'--- primele 30 sterse ---'
|
|
$listaStersi | Select-Object -First 30
|