1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
define_tag('checksumUPC', -namespace = 'jina_',
-req = 'check', -copy,
-opt = 'add'
);
// tag used for checksum calculation for the UPC barcode system
// usage jina_checksumUPC('NNNNNNNN')
// will return true or false depending on if the checksum checks
// usage with optional param -add jina_checksumUPC('NNNNNNNN', -add)
// returns the correct checksum for the checked value
local('temp',
'total' = integer,
'odd' = integer,
'checksum'
);
#check = string_replaceregexp(#check, -find = '[^0-9]', -replace = '');
if(!local_defined('add'));
#checksum = #check -> substring(#check -> size, 1);
#check -> remove(#check -> size, 1);
/if;
iterate(#check, #temp);
if((loop_count % 2) == 1);
#odd += integer(#temp);
else;
#total += integer(#temp);
/if;
/iterate;
#total += (#odd * 3);
if(local_defined('add'));
return(#total % 10);
else(#total % 10 == #checksum);
return(true);
else;
return(false);
/if;
/define_tag;
|