MaTirelire/AccountsV2.pm

filter: Statementstmt 15.6% 44 / 282 Branchbran 0.0% 0 / 124 Conditioncond 0.0% 0 / 30 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 47.6% 10 / 21 Podpod 54.5% 6 / 11 totaltotal 12.3% 60 / 485 CC 82 SCAR 64.3
CC
82
Cov
10%
validRecords
1482.0
PackRecord
240.0
ParseRecord
210.0
CRAP 622.1
« BlockPack.pm ↑ Summary MaTirelire/AccountsV1.pm »
1 =encoding iso-8859-1
2  
3 =cut
4  
5 #
6 # Copyright (C) 2005, Maxime Soulé
7 # You may distribute this file under the terms of the Artistic
8 # License, as specified in the README file.
9 #
10  
11 package Palm::MaTirelire::AccountsV2;
12  
13 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use Palm::BlockPack;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use Palm::MaTirelire;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Palm::StdAppInfo();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use base qw(Palm::MaTirelire Palm::StdAppInfo);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 our $VERSION = '1.0';
23  
24 1 ▶use constant UNKNOWN_MODE => ((1 << 5) - 1);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use constant UNKNOWN_TYPE => ((1 << 8) - 1);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 ▶use constant MATI_DB_PREFS_VERSION => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29  
30 # AppInfoBlock
31 1 my $APPINFO_BLOCK = Palm::BlockPack->new
32 ('N' => [ 'access_code' => 0 ],
33 UInt32 => [
34 [ 'version:4' => 1 ],
35 [ 'cur_category:4' => 0 ],
36 [ 'show_all_cat:1' => 0 ],
37 [ 'remove_type:1' => 0 ],#DmRemoveRecord really deletes
38 [ 'deny_find:1' => 0 ],
39 [ 'sort_type:3' => 0 ],
40 [ 'list_date:1' => 0 ],
41 [ 'check_locked:1' => 0 ],
42 [ 'repeat_startup:1' => 0 ],
43 [ 'repeat_days:7' => 15 ],
44 [ 'reserved1:*' => 0 ],
45 ],
46 UInt32 => [
47 [ 'sum_type:4' => 0 ],
48 [ 'sum_date:5' => 1 ],
49 [ 'sum_todayplus:5' => 10 ],
50 [ 'sum_at_date:1' => 0 ],
51 [ 'accounts_sel_type:2' => 0 ],
52 [ 'accounts_currency:8' => 0 ],
53 [ 'reserved2:*' => 0 ],
54 ],
55 'n' => [ 'selected_accounts' => 0x0 ],
56 'DateType' => 'sum_',
57 );
58  
59 1 ▶use constant DB_PREFS_STATS_NUM => 14;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 1 my $APPINFO_BLOCK_STATS = Palm::BlockPack->new
61 ('DateType' => [ 'beg_date_' => 0 ],
62 'DateType' => [ 'end_date_' => 0 ],
63 UInt32 => [
64 [ 'menu_choice:3' => 0 ],
65 [ 'week_bounds:1' => 0 ],
66 [ 'by:4' => 0 ],
67 [ 'type_any:1' => 0 ],
68 [ 'type:8' => 0 ],
69 [ 'mode_any:1' => 0 ],
70 [ 'mode:5' => 0 ],
71 [ 'on:2' => 0 ],
72 [ 'val_date:1' => 0 ],
73 [ 'ignore_nulls:1' => 0 ],
74 [ 'type_children:1' => 0 ],
75 [ 'reserved:*' => 0 ],
76 ],
77 'n' => [ 'checked_accounts' => 0 ],
78 );
79  
80 1 my $APPINFO_BLOCK_END = Palm::BlockPack->new('Z*' => [ 'note' => '' ]);
81  
82 1 my $ACCOUNT_BLOCK = Palm::BlockPack->new
83 ('DateType' => [ 'date_' => 0 ],
84 'TimeType' => [ 'time_' => 0 ],
85  
86 '-N' => [ 'amount' => 0 ],
87  
88 UInt32 => [
89 [ 'checked:1' => 1 ],
90 [ 'marked:1' => 0 ],
91 [ 'warning:1' => 0 ],
92 [ 'stmt_num:1' => 0 ],
93 [ 'currency:8' => 0 ],
94 [ 'cheques_by_cbook:6' => 25 ],
95 [ 'num_chequebook:2'=> 0 ],
96 [ 'take_last_date:1'=> 0 ],
97 [ 'reserved:*' => 0 ],
98 ],
99 '-N' => [ 'overdraft_thresold' => 0 ],
100 '-N' => [ 'non_overdraft_thresold' => 0 ],
101  
102 '[N4]' => [ 'check_books' ],
103  
104 'Z24' => [ 'number' => '' ],
105  
106 'Z*' => [ 'note' => '' ],
107 );
108  
109 1 my $TRANS_BLOCK = Palm::BlockPack->new
110 ('DateType' => [ 'date_' => 'now' ],
111 'TimeType' => [ 'time_' => 'now' ],
112  
113 '-N' => [ 'amount' => 0 ],
114  
115 UInt32 => [
116 [ 'checked:1' => 0 ],
117 [ 'marked:1' => 0 ],
118 [ 'alarm:1' => 0 ],
119 [ 'mode:5' => UNKNOWN_MODE ],
120 [ 'type:8' => UNKNOWN_TYPE ],
121 'value_date:1',
122 'check_num:1',
123 'repeat:1',
124 'xfer:1',
125 'xfer_cat:1',
126 'stmt_num:1',
127 'currency:1',
128 'splits:1',
129 [ 'reserved:*' => 0 ],
130 ],
131 );
132  
133 1 my $TRANS_VALUEDATE_BLOCK = Palm::BlockPack->new(DateType => '');
134  
135 1 my $TRANS_CHECKNUM_BLOCK = Palm::BlockPack->new(N => 'check_num');
136  
137 1 my $TRANS_REPEAT_BLOCK = Palm::BlockPack->new
138 (UInt16 => [
139 'repeat_type:2',
140 'repeat_freq:6',
141 'reserved:*',
142 ],
143 DateType => 'end_date_',
144 );
145  
146 1 my $TRANS_XFER_BLOCK = Palm::BlockPack->new(N => 'xfer');
147  
148 1 my $TRANS_STMTNUM_BLOCK = Palm::BlockPack->new(N => 'stmt_num');
149  
150 1 my $TRANS_CURRENCY_BLOCK = Palm::BlockPack->new
151 ('-N' => 'currency_amount',
152 UInt32 => [
153 'currency:8',
154 'reserved:*',
155 ]);
156  
157 1 my $TRANS_SUBTR_BLOCK = Palm::BlockPack->new
158 (UInt16 => [
159 'num:8',
160 'reserved:*',
161 ],
162 n => 'size');
163  
164 1 my $TRANS_SUBTR_SUB_BLOCK = Palm::BlockPack->new
165 (
166 UInt32 => [
167 'type:8',
168 'reserved:*',
169 ],
170 '-N' => 'amount',
171 'Z*' => 'desc',
172 );
173  
174 1 my $TRANS_NOTE_BLOCK = Palm::BlockPack->new('Z*' => [ note => '' ]);
175  
176  
177 sub import
178 1 ▶{
Subroutine import: called CC=1 SCAR=0.0
179 1 &Palm::PDB::RegisterPDBHandlers(__PACKAGE__, [ "MaT2", 'Acnt' ]);
180 }
181  
182  
183 sub new
184 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
185 0 my $classname = shift;
186 0 my $self = $classname->SUPER::new(@_);
187  
188 # Create a generic PDB. No need to rebless it,
189 # though.
190  
191 0 $self->{name} = "MaTi=Default"; # Default name
192 0 $self->{type} = "Acnt";
193  
194 # Add the standard AppInfo block stuff
195 0 &Palm::StdAppInfo::seed_StdAppInfo($self->{appinfo});
196  
197 # delete the auto-created "Unfiled" category
198 0 $self->{appinfo}{categories}[0]{name} = undef;
199  
200 # The AppInfo block stuff
201 0 $APPINFO_BLOCK->init_block($self->{appinfo});
202 0 $self->{appinfo}{stats} = [ ({}) x DB_PREFS_STATS_NUM ];
203 0 foreach my $idx (0 .. DB_PREFS_STATS_NUM - 1)
204 {
205 0 $APPINFO_BLOCK_STATS->init_block($self->{appinfo}{stats}[$idx]);
206 }
207 0 $APPINFO_BLOCK_END->init_block($self->{appinfo});
208  
209 0 return $self;
210 }
211  
212  
213 sub ParseAppInfoBlock
214 0 ▶{
Subroutine ParseAppInfoBlock: not called CC=5 SCAR=34.0
Pod documented
215 0 my $self = shift;
216 0 my $data = shift;
217 0 my $appinfo = {};
218 0 my $std_len;
219  
220 # Get the standard parts of the AppInfo block
221 0 &Palm::StdAppInfo::parse_StdAppInfo($appinfo, $data);
222  
223 # Palm::StdAppInfo::parse_StdAppInfo nous laisse le reste dans
224 # $appinfo->{other}
225 0 $data = delete $appinfo->{other};
226 0 $APPINFO_BLOCK->unpack_block(\$data, $appinfo, 1);
227  
228 0 ▶ if ($appinfo->{version} >= MATI_DB_PREFS_VERSION)
Branch: 1 branch
BranchTrueFalseTotal
if ($appinfo->{'version'} >= 1) { } 0 0 0
229 {
230 0 foreach my $idx (0 .. DB_PREFS_STATS_NUM - 1)
231 {
232 0 ▶ unless (defined $appinfo->{appinfo}{stats}[$idx])
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $appinfo->{"appinfo"}{"stats"}[$idx]) 0 0 0
233 {
234 0 $appinfo->{appinfo}{stats}[$idx] = {};
235 }
236  
237 $APPINFO_BLOCK_STATS->unpack_block(\$data,
238 0 $appinfo->{appinfo}{stats}[$idx],
239 1);
240 }
241 }
242 # La version 0 n'avait pas encore les stats
243 else
244 {
245 0 $appinfo->{version} = MATI_DB_PREFS_VERSION;
246  
247 0 $self->{appinfo}{stats} = [ ({}) x DB_PREFS_STATS_NUM ];
248 0 foreach my $idx (0 .. DB_PREFS_STATS_NUM - 1)
249 {
250 0 $APPINFO_BLOCK_STATS->init_block($self->{appinfo}{stats}[$idx]);
251 }
252 }
253 0 $APPINFO_BLOCK_END->unpack_block(\$data, $appinfo);
254  
255 0 return $appinfo;
256 }
257  
258  
259 sub PackAppInfoBlock
260 0 ▶{
Subroutine PackAppInfoBlock: not called CC=2 SCAR=17.9
Pod documented
261 0 my $self = shift;
262 0 my $appinfo = $self->{appinfo};
263 0 my $pack;
264  
265 0 $appinfo->{other} = $APPINFO_BLOCK->pack_block($appinfo);
266 0 foreach my $idx (0 .. DB_PREFS_STATS_NUM - 1)
267 {
268 $appinfo->{other} .=
269 0 $APPINFO_BLOCK_STATS->pack_block($appinfo->{stats}[$idx]);
270 }
271 $appinfo->{other} .=
272 0 $APPINFO_BLOCK_END->pack_block($appinfo);
273  
274 # Pack the AppInfo block (and then append $appinfo->{other})
275 0 $pack = &Palm::StdAppInfo::pack_StdAppInfo($appinfo);
276  
277 0 return $pack;
278 }
279  
280  
281 sub new_Record
282 0 ▶{
Subroutine new_Record: not called CC=1 SCAR=6.9
Pod documented
283 0 my $classname = shift;
284 0 my $retval = $classname->SUPER::new_Record(@_);
285  
286 0 $TRANS_BLOCK->init_block($retval);
287 0 $TRANS_NOTE_BLOCK->init_block($retval);
288  
289 0 return $retval;
290 }
291  
292  
293 sub new_AccountProperties
294 0 ▶{
Subroutine new_AccountProperties: not called CC=1 SCAR=6.9
Pod undocumented
295 0 my $classname = shift;
296 0 my $retval = $classname->SUPER::new_Record(@_);
297  
298 0 $ACCOUNT_BLOCK->init_block($retval);
299  
300 0 return $retval;
301 }
302  
303  
304 sub findAccountPropertiesByName ($$)
305 0 ▶{
Subroutine findAccountPropertiesByName: not called CC=4 SCAR=30.0
Pod undocumented
306 0 my($self, $account_name) = @_;
307  
308 0 my $ref_accounts = $self->{appinfo}{categories};
309  
310 0 ▶ for (my $index = 0; $index < @$ref_accounts; $index++)
Branch: 1 branch
BranchTrueFalseTotal
if ($index < @$ref_accounts) 0 0 0
311 {
312 0 my $cur_account = $ref_accounts->[$index]{name};
313  
314 0 ▶ if (defined $cur_account and $cur_account eq $account_name)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cur_account and $cur_account eq $account_name) 0 0 0
Condition0%0/3
defined $cur_account and $cur_account eq $account_name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cur_account and $cur_account eq $account_name
defined $cur_account $cur_account eq $account_name
Truth table0%0/3
A and B
A= defined $cur_accountB= $cur_account eq $account_name
ABresult
0X0
100
111
315 {
316 0 return $self->findAccountPropertiesByIndex($index);
317 }
318 }
319  
320 0 return undef;
321 }
322  
323  
324 sub findAccountPropertiesByIndex ($$)
325 0 ▶{
Subroutine findAccountPropertiesByIndex: not called CC=6 SCAR=37.4
Pod undocumented
326 0 my($self, $account_idx) = @_;
327  
328 0 foreach my $rec (@{$self->{records}})
329 {
330 # Account properties
331 0 ▶ if ($rec->{date_day} == 0 and $rec->{date_month} == 0
Branch: 1 branch
BranchTrueFalseTotal
if ($rec->{"date_day"} == 0 and $rec->{"date_month"} == 0 and $rec->{"date_year"} == 0 and $rec->{"category"} == $account_idx) 0 0 0
Condition0%0/9
$rec->{"date_day"} == 0 and $rec->{"date_month"} == 0 and $rec->{"date_year"} == 0 and $rec->{"category"} == $account_idx
!ll&&!rl&&r
000
$rec->{"date_day"} == 0 and $rec->{"date_month"} == 0 and $rec->{"date_year"} == 0
!ll&&!rl&&r
000
$rec->{"date_day"} == 0 and $rec->{"date_month"} == 0
!ll&&!rl&&r
000
MC/DC0%0/4
$rec->{"date_day"} == 0 and $rec->{"date_month"} == 0 and $rec->{"date_year"} == 0 and $rec->{"category"} == $account_idx
$rec->{"date_day"} == 0 $rec->{"date_month"} == 0 $rec->{"date_year"} == 0 $rec->{"category"} == $account_idx
Truth table0%0/5
A and B and C and D
A= $rec->{"date_day"} == 0B= $rec->{"date_month"} == 0C= $rec->{"date_year"} == 0D= $rec->{"category"} == $account_idx
ABCDresult
0XXX0
10XX0
110X0
11100
11111
332 and $rec->{date_year} == 0 and $rec->{category} == $account_idx)
333 {
334 0 return $rec;
335 }
336 }
337  
338 0 return undef;
339 }
340  
341  
342 sub ParseRecord
343 0 ▶{
Subroutine ParseRecord: not called CC=14 SCAR=53.5
Pod documented
344 0 my $self = shift;
345 0 my %record = @_;
346  
347 0 delete $record{offset}; # This is useless
348 0 my $data = delete $record{data};
349  
350 0 $record{size} = length $data; # used in validRecords sub
351  
352 # !!! PROBLÈME !!!
353 0 ▶ return \%record if $record{size} < 4;
Branch: 1 branch
BranchTrueFalseTotal
if $record{"size"} < 4 0 0 0
354  
355 # Propriétés du compte
356 0 ▶ if (unpack('N', $data) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (unpack('N', $data) == 0) { } 0 0 0
357 {
358 0 $ACCOUNT_BLOCK->unpack_block(\$data, \%record);
359 }
360 # Opération...
361 else
362 {
363 0 $TRANS_BLOCK->unpack_block(\$data, \%record, 1);
364  
365 # Value date
366 0 ▶ if (delete $record{value_date})
Branch: 1 branch
BranchTrueFalseTotal
if (delete $record{"value_date"}) 0 0 0
367 {
368 0 $record{value_date} = {};
369 0 $TRANS_VALUEDATE_BLOCK->unpack_block(\$data,$record{value_date}, 1);
370 }
371  
372 # Cheque number
373 0 ▶ if (delete $record{check_num})
Branch: 1 branch
BranchTrueFalseTotal
if (delete $record{"check_num"}) 0 0 0
374 {
375 0 $TRANS_CHECKNUM_BLOCK->unpack_block(\$data, \%record, 1);
376 }
377  
378 # Repetition
379 0 ▶ if (delete $record{repeat})
Branch: 1 branch
BranchTrueFalseTotal
if (delete $record{"repeat"}) 0 0 0
380 {
381 0 $record{repeat} = {};
382 0 $TRANS_REPEAT_BLOCK->unpack_block(\$data, $record{repeat}, 1);
383 }
384  
385 # Transfer
386 0 ▶ if (delete $record{xfer})
Branch: 1 branch
BranchTrueFalseTotal
if (delete $record{'xfer'}) { } 0 0 0
387 {
388 0 $TRANS_XFER_BLOCK->unpack_block(\$data, \%record, 1);
389 }
390 else
391 {
392 0 delete $record{xfer_cat};
393 }
394  
395 # Statement number
396 0 ▶ if (delete $record{stmt_num})
Branch: 1 branch
BranchTrueFalseTotal
if (delete $record{"stmt_num"}) 0 0 0
397 {
398 0 $TRANS_STMTNUM_BLOCK->unpack_block(\$data, \%record, 1);
399 }
400  
401 # Currency
402 0 ▶ if (delete $record{currency})
Branch: 1 branch
BranchTrueFalseTotal
if (delete $record{"currency"}) 0 0 0
403 {
404 0 $record{currency} = {};
405 0 $TRANS_CURRENCY_BLOCK->unpack_block(\$data, $record{currency}, 1);
406 }
407  
408 # Sub-transactions
409 0 ▶ if (delete $record{splits})
Branch: 1 branch
BranchTrueFalseTotal
if (delete $record{"splits"}) 0 0 0
410 {
411 0 $record{splits} = {};
412 0 $TRANS_SUBTR_BLOCK->unpack_block(\$data, $record{splits}, 1);
413  
414 0 ▶ if ($record{splits}{size} > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($record{"splits"}{"size"} > 0) 0 0 0
415 {
416 0 my $subtrs = substr($data, 0, $record{splits}{size}, '');
417  
418 0 $record{splits}{list} = [];
419  
420 0 ▶ while (length $subtrs > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (length $subtrs > 0) 0 0 0
421 {
422 0 my %subtr;
423  
424 0 $TRANS_SUBTR_SUB_BLOCK->unpack_block(\$subtrs, \%subtr, 1);
425  
426 # La somme des sous-op est égale à la valeur
427 # absolue du montant de l'opération. Donc on
428 # corrige au chargement si le montant de
429 # l'opération est < 0
430 0 ▶ if ($record{amount} < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($record{"amount"} < 0) 0 0 0
431 {
432 0 $subtr{amount} = - $subtr{amount};
433 }
434  
435 # La description a toujours une longueur multiple de 2
436 # y compris le \0 de fin
437 0 ▶ substr($subtrs, 0, 1) = '' if length($subtr{desc}) % 2 == 0;
Branch: 1 branch
BranchTrueFalseTotal
if length($subtr{"desc"}) % 2 == 0 0 0 0
438  
439 0 push(@{$record{splits}{list}}, \%subtr);
440 }
441 }
442  
443 # Here we can delete the number and the size, they will be
444 # recomputed at PackRecord
445 0 delete @{$record{splits}}{qw(num size)};
446 }
447  
448 0 $TRANS_NOTE_BLOCK->unpack_block(\$data, \%record);
449 }
450  
451 0 return \%record;
452 }
453  
454  
455 sub PackRecord
456 0 ▶{
Subroutine PackRecord: not called CC=15 SCAR=54.8
Pod documented
457 0 my $self = shift;
458 0 my $record = shift;
459 0 my $pack;
460  
461 # Propriétés du compte
462 0 ▶ if ($record->{date_day} == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($record->{'date_day'} == 0) { } 0 0 0
463 {
464 0 $pack = $ACCOUNT_BLOCK->pack_block($record);
465 }
466 # Opération...
467 else
468 {
469 # Small check...
470 0 ▶ if ($record->{xfer_cat})
Branch: 1 branch
BranchTrueFalseTotal
if ($record->{"xfer_cat"}) 0 0 0
471 {
472 0 ▶ if (not defined $record->{xfer} or $record->{xfer} >= 16)
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $record->{"xfer"} or $record->{"xfer"} >= 16) 0 0 0
Condition0%0/3
not defined $record->{"xfer"} or $record->{"xfer"} >= 16
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $record->{"xfer"} or $record->{"xfer"} >= 16
not defined $record->{"xfer"} $record->{"xfer"} >= 16
Truth table0%0/3
not(A) or B
A= not defined $record->{"xfer"}B= $record->{"xfer"} >= 16
ABresult
1X1
011
000
473 0 { delete $record->{xfer_cat} }
474 }
475  
476 0 $pack = $TRANS_BLOCK->pack_block($record);
477  
478 # Value date
479 0 ▶ if ($record->{value_date})
Branch: 1 branch
BranchTrueFalseTotal
if ($record->{"value_date"}) 0 0 0
480 {
481 0 $pack .= $TRANS_VALUEDATE_BLOCK->pack_block($record->{value_date});
482 }
483  
484 # Cheque number
485 0 ▶ if ($record->{check_num})
Branch: 1 branch
BranchTrueFalseTotal
if ($record->{"check_num"}) 0 0 0
486 {
487 0 $pack .= $TRANS_CHECKNUM_BLOCK->pack_block($record);
488 }
489  
490 # Repetition
491 0 ▶ if ($record->{repeat})
Branch: 1 branch
BranchTrueFalseTotal
if ($record->{"repeat"}) 0 0 0
492 {
493 0 $pack .= $TRANS_REPEAT_BLOCK->pack_block($record->{repeat});
494 }
495  
496 # Transfer
497 0 ▶ if ($record->{xfer})
Branch: 1 branch
BranchTrueFalseTotal
if ($record->{"xfer"}) 0 0 0
498 {
499 0 $pack .= $TRANS_XFER_BLOCK->pack_block($record);
500 }
501  
502 # Statement number
503 0 ▶ if ($record->{stmt_num})
Branch: 1 branch
BranchTrueFalseTotal
if ($record->{"stmt_num"}) 0 0 0
504 {
505 0 $pack .= $TRANS_STMTNUM_BLOCK->pack_block($record);
506 }
507  
508 # Currency
509 0 ▶ if ($record->{currency})
Branch: 1 branch
BranchTrueFalseTotal
if ($record->{"currency"}) 0 0 0
510 {
511 0 $pack .= $TRANS_CURRENCY_BLOCK->pack_block($record->{currency});
512 }
513  
514 # Sub-transactions
515 0 ▶ if ($record->{splits})
Branch: 1 branch
BranchTrueFalseTotal
if ($record->{"splits"}) 0 0 0
516 {
517 0 my $subtrs = '';
518 0 foreach my $ref_subtr (@{$record->{splits}{list}})
519 {
520 # La somme des sous-op doit être égale à la valeur
521 # absolue du montant de l'opération. Donc on corrige à
522 # la sauvegarde si le montant de l'opération est < 0
523 0 ▶ if ($record->{amount} < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($record->{"amount"} < 0) 0 0 0
524 {
525 0 $ref_subtr->{amount} = - $ref_subtr->{amount};
526 }
527  
528 0 $subtrs .= $TRANS_SUBTR_SUB_BLOCK->pack_block($ref_subtr);
529  
530 # La description a toujours une longueur multiple de 2
531 # y compris le \0 de fin
532 0 ▶ $subtrs .= "\0" if length($subtrs) % 2;
Branch: 1 branch
BranchTrueFalseTotal
if length($subtrs) % 2 0 0 0
533 }
534  
535 0 $record->{splits}{num} = @{$record->{splits}{list}};
536 0 $record->{splits}{size} = length $subtrs;
537  
538 0 $pack .= $TRANS_SUBTR_BLOCK->pack_block($record->{splits});
539  
540 0 $pack .= $subtrs;
541  
542 # Here we can delete the number and the size, they will be
543 # recomputed the next time
544 0 delete @{$record->{splits}}{qw(num size)};
545 }
546  
547 0 $pack .= $TRANS_NOTE_BLOCK->pack_block($record);
548 }
549  
550 0 return $pack;
551 }
552  
553  
554 #
555 # À faire les différentes sortes de tri...
556 sub sortRecords
557 0 ▶{
Subroutine sortRecords: not called CC=4 SCAR=30.0
Pod undocumented
558 0 my $self = shift;
559  
560 # Sort by value date
561 0 ▶ if ($self->{appinfo}{sort_type} == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'appinfo'}{'sort_type'} == 1) { } 0 0 0
562 {
563 0 @{$self->{records}} = sort
564 {
565 0 my($refa, $refb) = ($a, $b);
566  
567 # Account properties don't have value_date
568 0 ▶ if ($a->{value_date})
Branch: 1 branch
BranchTrueFalseTotal
if ($Palm::MaTirelire::AccountsV2::a->{"value_date"}) 0 0 0
569 {
570 $refa = { date_day => $a->{value_date}{day},
571 date_month => $a->{value_date}{month},
572 date_year => $a->{value_date}{year},
573 time_hour => $a->{time_hour},
574 time_min => $a->{time_min},
575 0 };
576 }
577  
578 # Account properties don't have value_date
579 0 ▶ if ($b->{value_date})
Branch: 1 branch
BranchTrueFalseTotal
if ($Palm::MaTirelire::AccountsV2::b->{"value_date"}) 0 0 0
580 {
581 $refb = { date_day => $b->{value_date}{day},
582 date_month => $b->{value_date}{month},
583 date_year => $b->{value_date}{year},
584 time_hour => $b->{time_hour},
585 time_min => $b->{time_min},
586 0 };
587 }
588  
589 # Pack date and time on an 31 bits width integer...
590  
591 # 11 bits: 30 .. 20
592 (($refa->{date_year} << 20)
593 # 4 bits: 19 .. 16
594 | ($refa->{date_month} << 16)
595 # 5 bits: 15 .. 11
596 | ($refa->{date_day} << 11)
597 # 5 bits: 10 .. 6
598 | ($refa->{time_hour} << 6)
599 # 6 bits: 5 .. 0 11 bits: 30 .. 20
600 | $refa->{time_min}) <=> (($refb->{date_year} << 20)
601 # 4 bits: 19 .. 16
602 | ($refb->{date_month} << 16)
603 # 5 bits: 15 .. 11
604 | ($refb->{date_day} << 11)
605 # 5 bits: 10 .. 6
606 | ($refb->{time_hour} << 6)
607 # 6 bits: 5 .. 0
608 | $refb->{time_min})
609 0 }
610 0 @{$self->{records}};
611 }
612 # Sort by date
613 else
614 {
615 # Force "sort by date" as there is no other sort type at this time
616 0 $self->{appinfo}{sort_type} = 0;
617  
618 0 @{$self->{records}} = sort
619 {
620 # Pack date and time on an 31 bits width integer...
621  
622 # 11 bits: 30 .. 20
623 (($a->{date_year} << 20)
624 # 4 bits: 19 .. 16
625 | ($a->{date_month} << 16)
626 # 5 bits: 15 .. 11
627 | ($a->{date_day} << 11)
628 # 5 bits: 10 .. 6
629 | ($a->{time_hour} << 6)
630 # 6 bits: 5 .. 0 11 bits: 30 .. 20
631 | $a->{time_min}) <=> (($b->{date_year} << 20)
632 # 4 bits: 19 .. 16
633 | ($b->{date_month} << 16)
634 # 5 bits: 15 .. 11
635 | ($b->{date_day} << 11)
636 # 5 bits: 10 .. 6
637 | ($b->{time_hour} << 6)
638 # 6 bits: 5 .. 0
639 | $b->{time_min})
640 0 }
641 0 @{$self->{records}};
642 }
643 }
644  
645  
646 #
647 # Returns a list (number of deleted records, number of errors corrected)
648 sub validRecords ($;$)
649 0 ▶{
Subroutine validRecords: not called CC=38 SCAR=73.0
Pod undocumented
650 0 my($self, $verbose) = @_;
651  
652 # $verbose can be a reference on a filehandle
653 0 ▶ $verbose = \*STDOUT if $verbose && not ref $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose and not ref $verbose 0 0 0
Condition0%0/3
$verbose and not ref $verbose
!ll&&!rl&&r
000
MC/DC0%0/2
$verbose and not ref $verbose
$verbose not ref $verbose
Truth table0%0/3
A and not(B)
A= $verboseB= not ref $verbose
ABresult
0X0
100
111
654  
655 0 my $deleted_records = 0;
656 0 my $errors_found = 0;
657  
658 0 my @to_del;
659 my %ids;
660 0 my $index = 0;
661  
662 0 foreach my $rec (@{$self->{records}})
663 {
664 0 ▶ if ($rec->{attributes}{expunged})
Branch: 2 branches
BranchTrueFalseTotal
if ($rec->{'attributes'}{'expunged'}) { } 0 0 0
elsif ($rec->{'size'} == 0) { } 0 0 0
665 {
666 0 ▶ print $verbose "Record #$index expunged => delete it really\n"
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
667 if $verbose;
668  
669 # No need to count these already deleted records
670 0 push(@to_del, $index);
671 }
672 elsif ($rec->{size} == 0)
673 {
674 0 ▶ print $verbose ("Record #$index (cat=$rec->{category}) "
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
675 . "UniqueID $rec->{id}\n"
676 . "**** empty => deleted\n")
677 if $verbose;
678  
679 0 push(@to_del, $index);
680 0 $deleted_records++;
681 }
682 else
683 {
684 0 $ids{$rec->{id}} = 1;
685 }
686 0 $index++;
687 }
688  
689 0 ▶ if (@to_del)
Branch: 1 branch
BranchTrueFalseTotal
if (@to_del) 0 0 0
690 {
691 0 foreach my $idx (reverse @to_del)
692 {
693 0 splice @{$self->{records}}, $idx, 1;
694 }
695 }
696  
697 0 my %links;
698 0 $index = 0;
699  
700 0 foreach my $rec (@{$self->{records}})
701 {
702 0 my @err_msg;
703  
704 0 ▶ if ($rec->{reserved})
Branch: 1 branch
BranchTrueFalseTotal
if ($rec->{"reserved"}) 0 0 0
705 {
706 0 $rec->{reserved} = 0;
707 0 push(@err_msg, "null reserved field corrected");
708 }
709  
710 # Account properties
711 0 ▶ if ($rec->{date_day} == 0 and $rec->{date_month} == 0
Branch: 1 branch
BranchTrueFalseTotal
if ($rec->{'date_day'} == 0 and $rec->{'date_month'} == 0 and $rec->{'date_year'} == 0) { } 0 0 0
Condition0%0/6
$rec->{"date_day"} == 0 and $rec->{"date_month"} == 0 and $rec->{"date_year"} == 0
!ll&&!rl&&r
000
$rec->{"date_day"} == 0 and $rec->{"date_month"} == 0
!ll&&!rl&&r
000
MC/DC0%0/3
$rec->{"date_day"} == 0 and $rec->{"date_month"} == 0 and $rec->{"date_year"} == 0
$rec->{"date_day"} == 0 $rec->{"date_month"} == 0 $rec->{"date_year"} == 0
Truth table0%0/4
A and B and C
A= $rec->{"date_day"} == 0B= $rec->{"date_month"} == 0C= $rec->{"date_year"} == 0
ABCresult
0XX0
10X0
1100
1111
712 and $rec->{date_year} == 0)
713 {
714 # Nothing to do here...
715 }
716 else
717 {
718 # Repeat
719 0 ▶ if ($rec->{repeat})
Branch: 1 branch
BranchTrueFalseTotal
if ($rec->{"repeat"}) 0 0 0
720 {
721 0 ▶ if ($rec->{repeat}{repeat_freq} == 0
Branch: 1 branch
BranchTrueFalseTotal
if ($rec->{"repeat"}{"repeat_freq"} == 0 or $rec->{"repeat"}{"repeat_type"} > 2) 0 0 0
Condition0%0/3
$rec->{"repeat"}{"repeat_freq"} == 0 or $rec->{"repeat"}{"repeat_type"} > 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$rec->{"repeat"}{"repeat_freq"} == 0 or $rec->{"repeat"}{"repeat_type"} > 2
$rec->{"repeat"}{"repeat_freq"} == 0 $rec->{"repeat"}{"repeat_type"} > 2
Truth table0%0/3
A or B
A= $rec->{"repeat"}{"repeat_freq"} == 0B= $rec->{"repeat"}{"repeat_type"} > 2
ABresult
1X1
011
000
722 or $rec->{repeat}{repeat_type} > 2)
723 {
724 0 push(@err_msg, "deleted repeat option");
725 0 delete $rec->{repeat};
726 }
727  
728 0 ▶ if ($rec->{repeat}{reserved} != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($rec->{"repeat"}{"reserved"} != 0) 0 0 0
729 {
730 0 $rec->{repeat}{reserved} = 0;
731 0 push(@err_msg, "repeat option, reserved corrected");
732 }
733 }
734  
735 # Xfer
736 0 ▶ if (exists $rec->{xfer})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rec->{"xfer"}) 0 0 0
737 {
738 0 my $error = 0;
739  
740 0 ▶ if ($rec->{xfer_cat})
Branch: 1 branch
BranchTrueFalseTotal
if ($rec->{'xfer_cat'}) { } 0 0 0
741 {
742 0 ▶ if ($rec->{xfer} >= 16)
Branch: 1 branch
BranchTrueFalseTotal
if ($rec->{"xfer"} >= 16) 0 0 0
743 {
744 0 push(@err_msg, "invalid account (xfer) link");
745  
746 0 $error = 1;
747 }
748 }
749 else
750 {
751 0 ▶ if (exists $ids{$rec->{xfer}})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ids{$rec->{'xfer'}}) { } 0 0 0
752 {
753 0 $links{$rec->{id}} = $rec->{xfer};
754 }
755 else
756 {
757 0 push(@err_msg, "invalid transaction (xfer) link");
758  
759 0 $error = 1;
760 }
761 }
762  
763 0 ▶ if ($error)
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
764 {
765 0 delete @$rec{qw(xfer xfer_cat)};
766 0 push(@err_msg, "deleted transfer option");
767 }
768 }
769  
770 # Splits
771 0 ▶ if (exists $rec->{splits})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rec->{"splits"}) 0 0 0
772 {
773 0 ▶ if (not defined $rec->{splits}{list}
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rec->{"splits"}{"list"} or @{$rec->{"splits"}{"list"};} == 0) 0 0 0
Condition0%0/3
not defined $rec->{"splits"}{"list"} or @{$rec->{"splits"}{"list"};} == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $rec->{"splits"}{"list"} or @{$rec->{"splits"}{"list"};} == 0
not defined $rec->{"splits"}{"list"} @{$rec->{"splits"}{"list"};} == 0
Truth table0%0/3
not(A) or B
A= not defined $rec->{"splits"}{"list"}B= @{$rec->{"splits"}{"list"};} == 0
ABresult
1X1
011
000
774 0 or @{$rec->{splits}{list}} == 0)
775 {
776 0 push(@err_msg, "deleted splits option");
777 0 delete $rec->{splits};
778 }
779  
780 0 ▶ for (my $split_idx = @{$rec->{splits}{list}}; $split_idx-- > 0;)
Branch: 1 branch
BranchTrueFalseTotal
if ($split_idx-- > 0) 0 0 0
781 {
782 0 ▶ if ($rec->{splits}{list}[$split_idx]{reserved})
Branch: 1 branch
BranchTrueFalseTotal
if ($rec->{"splits"}{"list"}[$split_idx]{"reserved"}) 0 0 0
783 {
784 0 $rec->{splits}{list}[$split_idx]{reserved} = 0;
785 0 push(@err_msg, "split #$split_idx, reserved corrected");
786 }
787 }
788  
789 0 ▶ if ($rec->{splits}{reserved})
Branch: 1 branch
BranchTrueFalseTotal
if ($rec->{"splits"}{"reserved"}) 0 0 0
790 {
791 0 $rec->{splits}{reserved} = 0;
792 0 push(@err_msg, "splits option, reserved corrected");
793 }
794 }
795  
796 # No account (not possible ?)
797 0 ▶ if ($rec->{category} eq '')
Branch: 1 branch
BranchTrueFalseTotal
if ($rec->{"category"} eq "") 0 0 0
798 {
799 0 $rec->{attributes} = { dirty => 1 };
800 0 push(@err_msg, "not associated to an account");
801 }
802  
803 0 ▶ if (@err_msg)
Branch: 1 branch
BranchTrueFalseTotal
if (@err_msg) 0 0 0
804 {
805 0 ▶ if ($verbose)
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 0 0
806 {
807 print $verbose
808 ("Record #$index (account=$rec->{category}) ",
809 "UniqueID $rec->{id}\n",
810 "$rec->{date_year}/$rec->{date_month}/$rec->{date_day} ",
811 "$rec->{time_hour}:$rec->{time_min} ",
812 0 "amount = ", $rec->{amount} / 100, "\n",
813 " ");
814  
815 0 print $verbose join("\n ", @err_msg), "\n";
816 }
817  
818 0 $rec->{attributes}{Dirty} = 1;
819  
820 0 $errors_found++;
821 }
822 }
823 }
824  
825 0 ▶ while (my($id, $link) = each %links)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %links) 0 0 0
826 {
827 0 ▶ if (not exists $links{$link})
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $links{$link}) { } 0 0 0
elsif ($links{$link} != $id) { } 0 0 0
828 {
829 0 ▶ print $verbose ("**** Xfer: $id => $link but $link is not linked,",
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
830 " corrected.\n")
831 if $verbose;
832  
833 0 my $rec = $self->findRecordByID($link);
834 0 $rec->{xfer} = $id;
835 0 delete $rec->{xfer_cat};
836  
837 0 $rec->{attributes}{Dirty} = 1;
838 }
839 elsif ($links{$link} != $id)
840 {
841 0 ▶ print $verbose
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
842 "**** Xfer: $id => $link but $link => $links{$link}\n"
843 if $verbose;
844 }
845 }
846  
847 0 return ($deleted_records, $errors_found);
848 }
849  
850 1 1;
851 __END__
« BlockPack.pm ↑ Summary MaTirelire/AccountsV1.pm »