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