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:
parent
9635b2f3a3
commit
6db136f578
|
@ -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
|
vat (0.0-2) bookworm; urgency=medium
|
||||||
|
|
||||||
* Fix CIF computation.
|
* Fix CIF computation.
|
||||||
|
|
2
es.c
2
es.c
|
@ -56,7 +56,7 @@ valid_cif(const char *cif) {
|
||||||
odds += a + b;
|
odds += a + b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
checksum = 10 - (odds + evens) % 10;
|
checksum = (10 - (odds + evens) % 10) % 10;
|
||||||
return cif[8] == checksum + 48 || cif[8] == "JABCDEFGHI"[checksum];
|
return cif[8] == checksum + 48 || cif[8] == "JABCDEFGHI"[checksum];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,12 @@ SELECT 'ES40404040D'::VATIN,
|
||||||
' esx0523821l '::VATIN,
|
' esx0523821l '::VATIN,
|
||||||
'ESM0243487d'::VATIN,
|
'ESM0243487d'::VATIN,
|
||||||
' ESb17616756 '::VATIN,
|
' ESb17616756 '::VATIN,
|
||||||
'ESb17385717'::VATIN
|
'ESb17385717'::VATIN,
|
||||||
|
'ESA08023780'::VATIN
|
||||||
;
|
;
|
||||||
vatin | vatin | vatin | vatin | vatin | vatin
|
vatin | vatin | vatin | vatin | vatin | vatin | vatin
|
||||||
-------------+-------------+-------------+-------------+-------------+-------------
|
-------------+-------------+-------------+-------------+-------------+-------------+-------------
|
||||||
ES40404040D | ES40404040D | ESX0523821L | ESM0243487D | ESB17616756 | ESB17385717
|
ES40404040D | ES40404040D | ESX0523821L | ESM0243487D | ESB17616756 | ESB17385717 | ESA08023780
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- Test invalid checksums
|
-- Test invalid checksums
|
||||||
|
|
|
@ -10,7 +10,8 @@ SELECT 'ES40404040D'::VATIN,
|
||||||
' esx0523821l '::VATIN,
|
' esx0523821l '::VATIN,
|
||||||
'ESM0243487d'::VATIN,
|
'ESM0243487d'::VATIN,
|
||||||
' ESb17616756 '::VATIN,
|
' ESb17616756 '::VATIN,
|
||||||
'ESb17385717'::VATIN
|
'ESb17385717'::VATIN,
|
||||||
|
'ESA08023780'::VATIN
|
||||||
;
|
;
|
||||||
|
|
||||||
-- Test invalid checksums
|
-- Test invalid checksums
|
||||||
|
|
Loading…
Reference in New Issue