NIP Control Number Verifier
#!/usr/bin/perl
#
# Skrypcik sprawdza plik wejsciowy w formacie .csv pola oddzielane znakiem ; na poprawnosc
# numeru NIP, na podstawie ostatniej cyfry kontrolnej
#
# $inputfile - plik wejsciowy
# $outputfile - plik z blednymi NIPami
# @wagi - stale wagowe kolejnych cyfr
#
########### Maciej Stopa
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
#
# This is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
############
use strict;
my $inputfile = "do_wsadu_access.csv";
my $outputfile = "bledne_nipy.csv";
my @wagi = ('6','5','7','2','3','4','5','6','7');
open (INPUT, "< $inputfile") or die "Nie mozna otworzyc pliku $inputfile: $!\n";
open (OUTPUT, "> $outputfile") or die "Nie mozna otworzyc pliku $outputfile.xml : $!\n";
while (<INPUT>) {
my @linia=split(/;|\n|\r/);
my $nip = @linia[10];
#my $nip = "7680002466";
my @chars = split(//, $nip);
my $suma = 0;
for (my $i = 0; $i < 9; $i++) {
my $cyfra=@chars[$i];
$suma=$suma+(@wagi[$i]*@chars[$i]);
# print $cyfra." suma ".$suma."\n";
}
my $mod = $suma % 11;
if ($mod == 10) { $mod = 0; };
if (@chars[9]!=$mod)
{
print "BLAD !!!";
print OUTPUT $_;
}
print "NIP: ".$nip.", Suma kontrolna ".$suma." mod 11 = ".$mod."\n";
}
close (OUTPUT);
close (INPUT);
exit;