line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::ID::NPWP; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-11-21'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.090'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
67389
|
use 5.010001; |
|
1
|
|
|
|
|
11
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
36
|
|
8
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use Exporter 'import'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
536
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(parse_npwp); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %SPEC; |
14
|
|
|
|
|
|
|
|
15
|
99
|
100
|
|
99
|
|
249
|
sub _z { $_[0] > 9 ? $_[0]-9 : $_[0] } |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$SPEC{parse_npwp} = { |
18
|
|
|
|
|
|
|
v => 1.1, |
19
|
|
|
|
|
|
|
summary => 'Parse Indonesian taxpayer registration number (NPWP)', |
20
|
|
|
|
|
|
|
args => { |
21
|
|
|
|
|
|
|
npwp => { |
22
|
|
|
|
|
|
|
summary => 'Input NPWP to be parsed', |
23
|
|
|
|
|
|
|
schema => 'str', |
24
|
|
|
|
|
|
|
pos => 0, |
25
|
|
|
|
|
|
|
req => 1, |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
}, |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
sub parse_npwp { |
30
|
11
|
|
|
11
|
1
|
25928
|
my %args = @_; |
31
|
|
|
|
|
|
|
|
32
|
11
|
50
|
|
|
|
36
|
my $npwp = $args{npwp} or return [400, "Please specify npwp"]; |
33
|
11
|
|
|
|
|
19
|
my $res = {}; |
34
|
|
|
|
|
|
|
|
35
|
11
|
|
|
|
|
39
|
$npwp =~ s/^\s+//; |
36
|
|
|
|
|
|
|
# assume A = 0 if not specified |
37
|
11
|
50
|
|
|
|
32
|
if ($npwp =~ /^\d\./) { $npwp = "0$npwp" } |
|
0
|
|
|
|
|
0
|
|
38
|
|
|
|
|
|
|
|
39
|
11
|
|
|
|
|
65
|
$npwp =~ s/\D+//g; |
40
|
|
|
|
|
|
|
# assume BBB = 000 if not specified |
41
|
11
|
50
|
|
|
|
31
|
if (length($npwp) == 12) { $npwp .= "000" } |
|
0
|
|
|
|
|
0
|
|
42
|
11
|
50
|
|
|
|
26
|
return [400, "Not 15 digit"] unless length($npwp) == 15; |
43
|
|
|
|
|
|
|
|
44
|
11
|
|
|
|
|
45
|
$npwp =~ /^(.)(.)(.)(.)(.)(.)(.)(.)(.)/; |
45
|
11
|
50
|
|
|
|
37
|
if ((_z(1*$1) + _z(2*$2) + _z(1*$3) + |
46
|
|
|
|
|
|
|
_z(2*$4) + _z(1*$5) + _z(2*$6) + |
47
|
|
|
|
|
|
|
_z(1*$7) + _z(2*$8) + _z(1*$9)) % 10) { |
48
|
0
|
|
|
|
|
0
|
return [400, "Wrong check digit"]; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
( |
52
|
|
|
|
|
|
|
$res->{taxpayer_code}, $res->{serial}, $res->{check_digit}, |
53
|
|
|
|
|
|
|
$res->{tax_office_code}, $res->{branch_code}, |
54
|
11
|
|
|
|
|
67
|
) = $npwp =~ /(..)(.{6})(.)(...)(...)/; |
55
|
|
|
|
|
|
|
|
56
|
11
|
50
|
|
|
|
40
|
return [400, "Serial starts from 1, not 0"] if $res->{serial} < 1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$res->{normalized} = join( |
59
|
|
|
|
|
|
|
"", |
60
|
|
|
|
|
|
|
$res->{taxpayer_code}, ".", |
61
|
|
|
|
|
|
|
substr($res->{serial}, 0, 3), ".", substr($res->{serial}, 3), ".", |
62
|
|
|
|
|
|
|
$res->{check_digit}, "-", |
63
|
|
|
|
|
|
|
$res->{tax_office_code}, ".", $res->{branch_code}, |
64
|
11
|
|
|
|
|
46
|
); |
65
|
|
|
|
|
|
|
|
66
|
11
|
|
|
|
|
38
|
[200, "OK", $res]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
# ABSTRACT: Parse Indonesian taxpayer registration number (NPWP) |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |