blib/lib/Finance/Bank/ID/BPRKS.pm

filter: Statementstmt 38.4% 78 / 203 Branchbran 24.4% 23 / 94 Conditioncond 11.7% 2 / 17 MC/DCmcdc 9.0% 1 / 11 Subroutinesub 47.8% 11 / 23 Podpod 83.3% 5 / 6 totaltotal 33.9% 120 / 354 CC 57 SCAR 44.2
CC
57
Cov
33%
get_statement
306.0
_parse_mon
71.0
check_balance
30.0
CRAP 83.3
↑ Summary
1 package Finance::Bank::ID::BPRKS;
2  
3 2 our $DATE = '2017-07-10'; # DATE
4 2 our $VERSION = '0.06'; # VERSION
5  
6 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Parse::Number::ID qw(parse_number_id);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 extends 'Finance::Bank::ID::Base';
14  
15 2 has _variant => (is => 'rw'); # 'individual' only, for now
16 ###bca
17 ###has skip_NEXT => (is => 'rw');
18  
19 1 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.7
Pod undocumented
20 1 my ($self, $args) = @_;
21  
22 1 ▶ $self->site("https://ib.bprks.co.id") unless $self->site;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->site 1 0 1
23 1 ▶ $self->https_host("ib.bprks.co.id") unless $self->https_host;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->https_host 1 0 1
24 }
25  
26 0 ▶sub _req {
Subroutine _req: not called CC=1 SCAR=6.9
27 0 my ($self, @args) = @_;
28  
29 # 2012-03-12 - KlikBCA server since a few week ago rejects TE request
30 # header, so we do not send them.
31 ###bca
32 ###local @LWP::Protocol::http::EXTRA_SOCK_OPTS =
33 ### @LWP::Protocol::http::EXTRA_SOCK_OPTS;
34 ###push(@LWP::Protocol::http::EXTRA_SOCK_OPTS, SendTE => 0);
35 #$log->tracef("EXTRA_SOCK_OPTS=%s", \@LWP::Protocol::http::EXTRA_SOCK_OPTS);
36  
37 0 $self->SUPER::_req(@args);
38 }
39  
40 # XXX tmp, should be in an indo date utility module
41 4 ▶sub _parse_mon {
Subroutine _parse_mon: called CC=13 SCAR=42.6
42 4 my $self = shift;
43 4 local $_ = lc(shift);
44 4 ▶ if (/^(?:jan|januar[iy])$/) {
Branch: 12 branches
BranchTrueFalseTotal
if (/^(?:jan|januar[iy])$/) { } 0 4 4
elsif (/^(?:[fp]eb|[fp]ebruar[iy])$/) { } 0 4 4
elsif (/^(?:mar|mrt|maret|march)$/) { } 0 4 4
elsif (/^(?:apr|april)$/) { } 0 4 4
elsif (/^(?:mei|may)$/) { } 2 2 4
elsif (/^(?:jun|jun[eiy])$/) { } 2 0 2
elsif (/^(?:jul|jul[iy])$/) { } 0 0 0
elsif (/^(?:agu|aug|ags?t|august|agustus)$/) { } 0 0 0
elsif (/^(?:sep|september)$/) { } 0 0 0
elsif (/^(?:o[kc]t|o[ct]ober)$/) { } 0 0 0
elsif (/^(?:no[pv]|no[pv]ember)$/) { } 0 0 0
elsif (/^(?:de[sc]|de[sc]ember)$/) { } 0 0 0
45 0 return 1;
46 } elsif (/^(?:[fp]eb|[fp]ebruar[iy])$/) {
47 0 return 2;
48 } elsif (/^(?:mar|mrt|maret|march)$/) {
49 0 return 3;
50 } elsif (/^(?:apr|april)$/) {
51 0 return 4;
52 } elsif (/^(?:mei|may)$/) {
53 2 return 5;
54 } elsif (/^(?:jun|jun[eiy])$/) {
55 2 return 6;
56 } elsif (/^(?:jul|jul[iy])$/) {
57 0 return 7;
58 } elsif (/^(?:agu|aug|ags?t|august|agustus)$/) {
59 0 return 8;
60 } elsif (/^(?:sep|september)$/) {
61 0 return 9;
62 } elsif (/^(?:o[kc]t|o[ct]ober)$/) {
63 0 return 10;
64 } elsif (/^(?:no[pv]|no[pv]ember)$/) {
65 0 return 11;
66 } elsif (/^(?:de[sc]|de[sc]ember)$/) {
67 0 return 12;
68 } else {
69 0 die "Can't parse month: $_";
70 #return 0;
71 }
72 }
73  
74 12 ▶sub _parse_num {
Subroutine _parse_num: called CC=2 SCAR=6.9
75 12 my ($self, $s) = @_;
76 12 my $neg = $s =~ s/^\((.+)\)$/$1/;
77 12 my $n = parse_number_id(text => $s);
78 12 ▶ $neg ? -$n : $n;
Branch: 1 branch
BranchTrueFalseTotal
$neg ? : 4 8 12
79 }
80  
81 0 ▶sub login {
Subroutine login: not called CC=4 SCAR=30.0
Pod documented
82 0 die "Not yet implemented";
83 0 my ($self) = @_;
84 0 my $s = $self->site;
85  
86 0 ▶ return 1 if $self->logged_in;
Branch: 1 branch
BranchTrueFalseTotal
if $self->logged_in 0 0 0
87 0 ▶ die "400 Username not supplied" unless $self->username;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->username 0 0 0
88 0 ▶ die "400 Password not supplied" unless $self->password;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->password 0 0 0
89  
90 0 $self->logger->debug('Logging in ...');
91 0 $self->_req(get => [$s]);
92 $self->_req(submit_form => [
93 form_number => 1,
94 fields => {'value(user_id)'=>$self->username,
95 'value(pswd)'=>$self->password,
96 },
97 button => 'value(Submit)',
98 ],
99 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
100 0 my ($mech) = @_;
101 0 ▶ $mech->content =~ /var err='(.+?)'/ and return $1;
Branch: 1 branch
BranchTrueFalseTotal
$mech->content =~ /var err='(.+?)'/ and return $1 0 0 0
102 0 ▶ $mech->content =~ /=logout"/ and return;
Branch: 1 branch
BranchTrueFalseTotal
$mech->content =~ /=logout"/ and return 0 0 0
103 0 "unknown login result page";
104 }
105 0 );
106 0 $self->logged_in(1);
107 0 $self->_req(get => ["$s/authentication.do?value(actions)=welcome"]);
108 #$self->_req(get => ["$s/nav_bar_indo/menu_nav.htm"]); # failed?
109 }
110  
111 0 ▶sub logout {
Subroutine logout: not called CC=2 SCAR=17.9
Pod documented
112 0 die "Not yet implemented";
113 0 my ($self) = @_;
114  
115 0 ▶ return 1 unless $self->logged_in;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->logged_in 0 0 0
116 0 $self->logger->debug('Logging out ...');
117 0 $self->_req(get => [$self->site . "/authentication.do?value(actions)=logout"]);
118 0 $self->logged_in(0);
119 }
120  
121 0 ▶sub _menu {
Subroutine _menu: not called CC=1 SCAR=6.9
122 0 my ($self) = @_;
123 0 my $s = $self->site;
124 0 $self->_req(get => ["$s/nav_bar_indo/account_information_menu.htm"]);
125 }
126  
127 0 ▶sub list_cards {
Subroutine list_cards: not called CC=1 SCAR=6.9
Pod documented
128 0 die "Not yet implemented";
129 0 my ($self) = @_;
130 0 $self->login;
131 0 $self->logger->info("Listing ATM cards");
132 0 map { $_->{account} } $self->_check_balances;
133 }
134  
135 0 ▶sub _check_balances {
Subroutine _check_balances: not called CC=2 SCAR=17.9
136 0 my ($self) = @_;
137 0 my $s = $self->site;
138  
139 0 my $re = qr!
140 <tr>\s*
141 <td[^>]+>\s*<div[^>]+>\s*<font[^>]+>\s*(\d+)\s*</font>\s*</div>\s*</td>\s*
142 <td[^>]+>\s*<div[^>]+>\s*<font[^>]+>\s*([^<]*?)\s*</font>\s*</div>\s*</td>\s*
143 <td[^>]+>\s*<div[^>]+>\s*<font[^>]+>\s*([A-Z]+)\s*</font>\s*</div>\s*</td>\s*
144 <td[^>]+>\s*<div[^>]+>\s*<font[^>]+>\s*([0-9,.]+)\.(\d\d)\s*</font>\s*</div>\s*</td>
145 !x;
146  
147 0 $self->login;
148 0 $self->_menu;
149 $self->_req(post => ["$s/balanceinquiry.do"],
150 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
151 0 my ($mech) = @_;
152 0 ▶ $mech->content =~ $re or
Branch: 1 branch
BranchTrueFalseTotal
$mech->content =~ /$re/ or return "can't find balances, maybe page layout changed?" 0 0 0
153 return "can't find balances, maybe page layout changed?";
154 0 '';
155 }
156 0 );
157  
158 0 my @res;
159 0 my $content = $self->mech->content;
160 0 ▶ while ($content =~ m/$re/og) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /$re/go) 0 0 0
161 0 push @res, { account => $1,
162 account_type => $2,
163 currency => $3,
164 balance => $self->_stripD($4) + 0.01*$5,
165 };
166 }
167 0 @res;
168 }
169  
170 0 ▶sub check_balance {
Subroutine check_balance: not called CC=5 SCAR=34.0
Pod documented
171 0 die "Not yet implemented";
172 0 my ($self, $account) = @_;
173 0 my @bals = $self->_check_balances;
174 0 ▶ return unless @bals;
Branch: 1 branch
BranchTrueFalseTotal
unless @bals 0 0 0
175 0 ▶ return $bals[0]{balance} if !$account;
Branch: 1 branch
BranchTrueFalseTotal
unless $account 0 0 0
176 0 for (@bals) {
177 0 ▶ return $_->{balance} if $_->{account} eq $account;
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"account"} eq $account 0 0 0
178 }
179 0 return;
180 }
181  
182 0 ▶sub get_statement {
Subroutine get_statement: not called CC=17 SCAR=57.2
Pod documented
183 0 die "Not yet implemented";
184 0 my ($self, %args) = @_;
185 0 my $s = $self->site;
186 0 my $max_days = 31;
187  
188 0 $self->login;
189 0 $self->_menu;
190 $self->logger->info("Getting statement for ".
191 0 ▶ ($args{account} ? "account `$args{account}'" : "default account")." ...");
Branch: 1 branch
BranchTrueFalseTotal
$args{'account'} ? : 0 0 0
192 $self->_req(post => ["$s/accountstmt.do?value(actions)=acct_stmt"],
193 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
194 0 my ($mech) = @_;
195 0 ▶ $mech->content =~ /<form/i or
Branch: 1 branch
BranchTrueFalseTotal
$mech->content =~ /<form/i or return "no form found, maybe we got logged out?" 0 0 0
196 return "no form found, maybe we got logged out?";
197 0 '';
198 0 });
199  
200 0 my $form = $self->mech->form_number(1);
201  
202 # in the site this is done by javascript onSubmit(), so we emulate it here
203 0 $form->action("$s/accountstmt.do?value(actions)=acctstmtview");
204  
205 # in the case of the current date being a saturday/sunday/holiday, end
206 # date will be forwarded 1 or more days from the current date by the site,
207 # so we need to know end date and optionally forward start date when needed,
208 # to avoid total number of days being > 31.
209  
210 0 my $today = DateTime->today;
211 0 my $max_dt = DateTime->new(day => $form->value("value(endDt)"),
212 month => $form->value("value(endMt)"),
213 year => $form->value("value(endYr)"));
214 0 my $cmp = DateTime->compare($today, $max_dt);
215 0 my $delta_days = $cmp * $today->subtract_datetime($max_dt, $today)->days;
216 0 ▶ if ($delta_days > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delta_days > 0) 0 0 0
217 0 $self->logger->warn("Something weird is going on, end date is being ".
218 "set less than today's date by the site (".
219 $self->_fmtdate($max_dt)."). ".
220 "Please check your computer's date setting. ".
221 "Continuing anyway.");
222 }
223 0 my $min_dt = $max_dt->clone->subtract(days => ($max_days-1));
224  
225 0 ▶ my $end_dt = $args{end_date} || $max_dt;
Condition0%0/3
$args{'end_date'} || $max_dt
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'end_date'} || $max_dt
$args{'end_date'} $max_dt
Truth table0%0/3
A || B
A= $args{'end_date'}B= $max_dt
ABresult
1X1
011
000
226 my $start_dt = $args{start_date} ||
227 0 ▶ $end_dt->clone->subtract(days => (($args{days} || $max_days)-1));
Condition0%0/6
$args{'start_date'} || $end_dt->clone->subtract('days', ($args{'days'} || $max_days) - 1)
l!l&&r!l&&!r
000
$args{'days'} || $max_days
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'start_date'} || $end_dt->clone->subtract('days', ($args{'days'} || $max_days) - 1)
$args{'start_date'} $end_dt->clone->subtract('days', ($args{'days'} || $max_days) - 1)
MC/DC0%0/2
$args{'days'} || $max_days
$args{'days'} $max_days
Truth table0%0/3
A || B
A= $args{'start_date'}B= $end_dt->clone->subtract('days', ($args{'days'} || $max_days) - 1)
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $args{'days'}B= $max_days
ABresult
1X1
011
000
228 0 ▶ if (DateTime->compare($start_dt, $min_dt) == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ("DateTime"->compare($start_dt, $min_dt) == -1) 0 0 0
229 0 $self->logger->warn("Start date ".$self->_fmtdate($start_dt)." is less than ".
230 "minimum date ".$self->_fmtdate($min_dt).". Setting to ".
231 "minimum date instead.");
232 0 $start_dt = $min_dt;
233 }
234 0 ▶ if (DateTime->compare($start_dt, $max_dt) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ("DateTime"->compare($start_dt, $max_dt) == 1) 0 0 0
235 0 $self->logger->warn("Start date ".$self->_fmtdate($start_dt)." is greater than ".
236 "maximum date ".$self->_fmtdate($max_dt).". Setting to ".
237 "maximum date instead.");
238 0 $start_dt = $max_dt;
239 }
240 0 ▶ if (DateTime->compare($end_dt, $min_dt) == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ("DateTime"->compare($end_dt, $min_dt) == -1) 0 0 0
241 0 $self->logger->warn("End date ".$self->_fmtdate($end_dt)." is less than ".
242 "minimum date ".$self->_fmtdate($min_dt).". Setting to ".
243 "minimum date instead.");
244 0 $end_dt = $min_dt;
245 }
246 0 ▶ if (DateTime->compare($end_dt, $max_dt) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ("DateTime"->compare($end_dt, $max_dt) == 1) 0 0 0
247 0 $self->logger->warn("End date ".$self->_fmtdate($end_dt)." is greater than ".
248 "maximum date ".$self->_fmtdate($max_dt).". Setting to ".
249 "maximum date instead.");
250 0 $end_dt = $max_dt;
251 }
252 0 ▶ if (DateTime->compare($start_dt, $end_dt) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ("DateTime"->compare($start_dt, $end_dt) == 1) 0 0 0
253 0 $self->logger->warn("Start date ".$self->_fmtdate($start_dt)." is greater than ".
254 "end date ".$self->_fmtdate($end_dt).". Setting to ".
255 "end date instead.");
256 0 $start_dt = $end_dt;
257 }
258  
259 0 my $select = $form->find_input("value(D1)");
260 0 my $d1 = $select->value;
261 0 ▶ if ($args{account}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"account"}) 0 0 0
262 0 my @d1 = $select->possible_values;
263 0 my @accts = $select->value_names;
264 0 for (0..$#accts) {
265 0 ▶ if ($args{account} eq $accts[$_]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"account"} eq $accts[$_]) 0 0 0
266 0 $d1 = $d1[$_];
267 0 last;
268 }
269 }
270 }
271  
272 $self->_req(submit_form => [
273 form_number => 1,
274 fields => {
275 "value(D1)" => $d1,
276 "value(startDt)" => $start_dt->day,
277 "value(startMt)" => $start_dt->month,
278 "value(startYr)" => $start_dt->year,
279 "value(endDt)" => $end_dt->day,
280 "value(endMt)" => $end_dt->month,
281 "value(endYr)" => $end_dt->year,
282 },
283 ],
284 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
285 0 my ($mech) = @_;
286 0 ''; # XXX check for error
287 0 });
288 0 ▶ my $parse_opts = $args{parse_opts} // {};
Condition0%0/2
$args{"parse_opts"} // {}
l!l
00
MC/DC0%0/1
$args{"parse_opts"} // {}
$args{"parse_opts"}
Truth table0%0/2
A
A= $args{"parse_opts"}
Aresult
11
00
289 0 my $resp = $self->parse_statement($self->mech->content, %$parse_opts);
290 0 ▶ return if !$resp || $resp->[0] != 200;
Branch: 1 branch
BranchTrueFalseTotal
if not $resp or $resp->[0] != 200 0 0 0
Condition0%0/3
not $resp or $resp->[0] != 200
l!l&&r!l&&!r
000
MC/DC0%0/2
not $resp or $resp->[0] != 200
not $resp $resp->[0] != 200
Truth table0%0/3
not(A) or B
A= not $respB= $resp->[0] != 200
ABresult
1X1
011
000
291 0 $resp->[2];
292 }
293  
294 2 ▶sub _ps_detect {
Subroutine _ps_detect: called CC=2 SCAR=7.4
295 2 my ($self, $page) = @_;
296 2 ▶ unless ($page =~ />Detail Informasi Mutasi Rekening</) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($page =~ />Detail Informasi Mutasi Rekening</) 0 2 2
297 0 return "No BPR KS statement page signature found";
298 }
299 2 $self->_variant('individual');
300 2 "";
301 }
302  
303 2 ▶sub _ps_get_metadata {
Subroutine _ps_get_metadata: called CC=8 SCAR=24.0
304 2 my ($self, $page, $stmt) = @_;
305  
306 2 ▶ unless ($page =~ m!<label[^>]*>No\. Rekening</label></td>\s*<td[^>]*>(\d+)</td>!s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($page =~ m[<label[^>]*>No\. Rekening</label></td>\s*<td[^>]*>(\d+)</td>]s) 0 2 2
307 0 return "can't get account number";
308 }
309 2 $stmt->{account} = $1;
310  
311 2 my $adv1 = "probably the statement format changed, or input incomplete";
312  
313 2 ▶ unless ($page =~ m!<label[^>]*>Periode Mutasi Rekening</label></td>\s*<td>\s*(?<d1>\d{1,2})-(?<m1>\w+)-(?<y1>\d{4})\s*s/d\s*(?<d2>\d{1,2})-(?<m2>\w+)-(?<y2>\d{4})\s*</td>!s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($page =~ m[<label[^>]*>Periode Mutasi Rekening</label></td>\s*<td>\s*(?<d1>\d{1,2})-(?<m1>\w+)-(?<y1>\d{4})\s*s/d\s*(?<d2>\d{1,2})-(?<m2>\w+)-(?<y2>\d{4})\s*</td>]s) 0 2 2
314 0 return "can't get statement period, $adv1";
315 }
316 2 $stmt->{start_date} = DateTime->new(day=>$+{d1}, month=>$self->_parse_mon($+{m1}), year=>$+{y1});
317 2 $stmt->{end_date} = DateTime->new(day=>$+{d2}, month=>$self->_parse_mon($+{m2}), year=>$+{y2});
318  
319 2 ▶ unless ($page =~ m!<label[^>]*>Mata Uang</label></td>\s*<td[^>]*>(\w+)</td>!s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($page =~ m[<label[^>]*>Mata Uang</label></td>\s*<td[^>]*>(\w+)</td>]s) 0 2 2
320 0 return "can't get currency, $adv1";
321 }
322 2 ▶ $stmt->{currency} = ($1 eq 'Rp' ? 'IDR' : $1);
Branch: 1 branch
BranchTrueFalseTotal
$1 eq 'Rp' ? : 0 2 2
323  
324 2 ▶ unless ($page =~ m!<label[^>]*>Nama</label></td>\s*<td[^>]*>([^<]+?)\s*</td>!s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($page =~ m[<label[^>]*>Nama</label></td>\s*<td[^>]*>([^<]+?)\s*</td>]s) 0 2 2
325 0 return "can't get account holder, $adv1";
326 }
327 2 $stmt->{account_holder} = $1;
328  
329 # additional: Tipe: Tabungan
330  
331 2 ▶ unless ($page =~ m!<label[^>]*>Mutasi Kredit</label></td>\s*<td[^>]*>([^<]+)</td>!s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($page =~ m[<label[^>]*>Mutasi Kredit</label></td>\s*<td[^>]*>([^<]+)</td>]s) 0 2 2
332 0 return "can't get total credit, $adv1";
333 }
334 2 $stmt->{_total_credit_in_stmt} = $self->_parse_num($1);
335 # no _num_credit_tx_in_stmt, pity cause it's required for proper checking
336  
337 2 ▶ unless ($page =~ m!<label[^>]*>Mutasi Debet</label></td>\s*<td[^>]*>([^<]+)</td>!s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($page =~ m[<label[^>]*>Mutasi Debet</label></td>\s*<td[^>]*>([^<]+)</td>]s) 0 2 2
338 0 return "can't get total credit, $adv1";
339 }
340 2 $stmt->{_total_debit_in_stmt} = -$self->_parse_num($1);
341 # no _num_debit_tx_in_stmt, pity cause it's required for proper checking
342 2 "";
343 }
344  
345 2 ▶sub _ps_get_transactions {
Subroutine _ps_get_transactions: called CC=5 SCAR=16.1
346 2 my ($self, $page, $stmt) = @_;
347  
348 2 my @e;
349 2 ▶ while ($page =~ m!
Branch: 1 branch
BranchTrueFalseTotal
if ($page =~ m[ <tr \s+ class="(?:odd|even)" \s+ id="informal_(?<seq>\d+)"[^>]*>\s* <td[^>]+>\s* (?<date>\d\d/\d\d/\d\d\d\d) \s*</td>\s* <td[^>]+>\s* (?<desc>[^<]+?) \s*</td>\s* <td[^>]+>\s* (?<ref>[^<]+?) \s*</td>\s* <td[^>]+>\s* (?<amt>[^<]+?) \s*</td>\s* <td[^>]+>\s* (?<bal>[^<]+?) \s*</td>\s* </tr>]gsx) 4 2 6
350 <tr \s+ class="(?:odd|even)" \s+ id="informal_(?<seq>\d+)"[^>]*>\s*
351 <td[^>]+>\s* (?<date>\d\d/\d\d/\d\d\d\d) \s*</td>\s*
352 <td[^>]+>\s* (?<desc>[^<]+?) \s*</td>\s*
353 <td[^>]+>\s* (?<ref>[^<]+?) \s*</td>\s*
354 <td[^>]+>\s* (?<amt>[^<]+?) \s*</td>\s*
355 <td[^>]+>\s* (?<bal>[^<]+?) \s*</td>\s*
356 </tr>!sxg) {
357 4 my %m = %+;
358 4 push @e, \%m;
359 }
360  
361 2 my @tx;
362 my @skipped_tx;
363 2 my $last_date;
364 2 my $seq;
365 2 my $i = 0;
366 2 for my $e (@e) {
367 4 $i++;
368 4 my $tx = {};
369 #$tx->{stmt_start_date} = $stmt->{start_date};
370  
371 ### bca
372 ###if ($e->{date} =~ /NEXT/) {
373 ### $tx->{date} = $stmt->{end_date};
374 ### $tx->{is_next} = 1;
375 ###} elsif ($e->{date} =~ /PEND/) {
376 ### $tx->{date} = $stmt->{end_date};
377 ### $tx->{is_pending} = 1;
378 ###} else {
379 4 my ($day, $mon, $year) = split m!/!, $e->{date};
380 4 my $last_nonpend_date = DateTime->new(
381 year => $year,
382 month => $mon,
383 day => $day);
384 4 $tx->{date} = $last_nonpend_date;
385 ###$tx->{is_pending} = 0;
386 ###}
387  
388 4 $tx->{description} = $e->{desc};
389  
390 4 $tx->{amount} = $self->_parse_num($e->{amt});
391 4 $tx->{balance} = $self->_parse_num($e->{bal});
392  
393 ### bca
394 ###if ($tx->{is_next} && $self->skip_NEXT) {
395 ###}
396  
397 4 ▶ if (!$last_date || DateTime->compare($last_date, $tx->{date})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $last_date or 'DateTime'->compare($last_date, $tx->{'date'})) { } 2 2 4
Condition66%2/3
not $last_date or "DateTime"->compare($last_date, $tx->{"date"})
l!l&&r!l&&!r
202
MC/DC50%1/2
not $last_date or "DateTime"->compare($last_date, $tx->{"date"})
not $last_date "DateTime"->compare($last_date, $tx->{"date"})
Truth table66%2/3
not(A) or B
A= not $last_dateB= "DateTime"->compare($last_date, $tx->{"date"})
ABresult
1X1
011
000
398 2 $seq = 1;
399 2 $last_date = $tx->{date};
400 } else {
401 2 $seq++;
402 }
403 4 $tx->{seq} = $seq;
404  
405 ### bca
406 ###if ($self->_variant eq 'individual' &&
407 ### $tx->{date}->dow =~ /6|7/ &&
408 ### $tx->{description} !~ /^(BIAYA ADM|BUNGA|CR KOREKSI BUNGA|PAJAK BUNGA)$/) {
409 ### return "check failed in tx#$i: In KlikBCA Perorangan, all ".
410 ### "transactions must not be in Sat/Sun except for Interest and ".
411 ### "Admin Fee";
412 ### # note: in Tahapan perorangan, BIAYA ADM is set on
413 ### # Fridays, but for Tapres (?) on last day of the month
414 ###}
415  
416 ###if ($self->_variant eq 'bisnis' &&
417 ### $tx->{date}->dow =~ /6|7/ &&
418 ### $tx->{description} !~ /^(BIAYA ADM|BUNGA|CR KOREKSI BUNGA|PAJAK BUNGA)$/) {
419 ### return "check failed in tx#$i: In KlikBCA Bisnis, all ".
420 ### "transactions must not be in Sat/Sun except for Interest and ".
421 ### "Admin Fee";
422 ### # note: in KlikBCA bisnis, BIAYA ADM is set on the last day of the
423 ### # month, regardless of whether it's Sat/Sun or not
424 ###}
425  
426 ###if ($tx->{is_next} && $self->skip_NEXT) {
427 ### push @skipped_tx, $tx;
428 ### $seq--;
429 ###} else {
430 4 push @tx, $tx;
431 ###}
432 }
433 2 $stmt->{transactions} = \@tx;
434 2 $stmt->{skipped_transactions} = \@skipped_tx;
435 2 "";
436 }
437  
438 2 1;
439 # ABSTRACT: Check your BPR KS accounts from Perl
440  
441 __END__
↑ Summary