Fix CIF computation in cases where CIF ends with 0

This si because the computed value was 10, instead of 0.
This commit is contained in:
jordi fita mas 2023-07-03 01:38:00 +02:00
parent 9635b2f3a3
commit 6db136f578
4 changed files with 14 additions and 6 deletions

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
vat (0.2-3) bookworm; urgency=medium
* Fix CIF computation for CIF ending with 0.
-- jordi fita mas <jordi@tandem.blog> Mon, 03 Jul 2023 01:37:34 +0002
vat (0.0-2) bookworm; urgency=medium
* Fix CIF computation.

2
es.c
View File

@ -56,7 +56,7 @@ valid_cif(const char *cif) {
odds += a + b;
}
}
checksum = 10 - (odds + evens) % 10;
checksum = (10 - (odds + evens) % 10) % 10;
return cif[8] == checksum + 48 || cif[8] == "JABCDEFGHI"[checksum];
}

View File

@ -8,11 +8,12 @@ SELECT 'ES40404040D'::VATIN,
' esx0523821l '::VATIN,
'ESM0243487d'::VATIN,
' ESb17616756 '::VATIN,
'ESb17385717'::VATIN
'ESb17385717'::VATIN,
'ESA08023780'::VATIN
;
vatin | vatin | vatin | vatin | vatin | vatin
-------------+-------------+-------------+-------------+-------------+-------------
ES40404040D | ES40404040D | ESX0523821L | ESM0243487D | ESB17616756 | ESB17385717
vatin | vatin | vatin | vatin | vatin | vatin | vatin
-------------+-------------+-------------+-------------+-------------+-------------+-------------
ES40404040D | ES40404040D | ESX0523821L | ESM0243487D | ESB17616756 | ESB17385717 | ESA08023780
(1 row)
-- Test invalid checksums

View File

@ -10,7 +10,8 @@ SELECT 'ES40404040D'::VATIN,
' esx0523821l '::VATIN,
'ESM0243487d'::VATIN,
' ESb17616756 '::VATIN,
'ESb17385717'::VATIN
'ESb17385717'::VATIN,
'ESA08023780'::VATIN
;
-- Test invalid checksums