NAB/Australian/DirectEntry/Report.pm

filter: Statementstmt 100% 80 / 80 Branchbran 83.3% 5 / 6 Conditioncond 66.6% 6 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 13 / 13 Podpod 100% 4 / 4 totaltotal 91.5% 108 / 118 CC 11 SCAR 17.6
CC
11
Cov
96%
to_file
11.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.8
« NAB/AccountInformation/File.pm ↑ Summary NAB/Australian/DirectEntry/Payments.pm »
1 package Business::NAB::Australian::DirectEntry::Report;
2 1 $Business::NAB::Australian::DirectEntry::Report::VERSION = '0.11';
3 =head1 NAME
4  
5 Business::NAB::Australian::DirectEntry::Report
6  
7 =head1 SYNOPSIS
8  
9 use Business::NAB::Australian::DirectEntry::Report;
10  
11 # parse;
12 my $Report = Business::NAB::Australian::DirectEntry::Report
13 ->new_from_file( $file_path );
14  
15 foreach my $Credit (
16 grep { $_->is_credit } $Report->payment_record->@*
17 ) {
18 ...
19 }
20  
21 # build
22 my $Report = Business::NAB::Australian::DirectEntry::Report->new;
23  
24 $Report->add_header_record(
25 .. # Business::NAB:: ... HeaderRecord object
26 );
27  
28 $Report->add_payment_record(
29 .. # Business::NAB:: ... PaymentRecord object
30 ) for ( @payments );
31  
32 $Report->to_file(
33 $file_path,
34 $separator, # defaults to "\r\n"
35 );
36  
37 =head1 DESCRIPTION
38  
39 Class for building/parsing a Australian Direct Entry Reports file
40  
41 =cut
42  
43 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 ▶use feature qw/ signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 ▶use autodie qw/ :all /;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 1 ▶use Carp qw/ croak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 1 with 'Business::NAB::Role::AttributeContainer';
51 1 extends 'Business::NAB::FileContainer';
52  
53 1 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 1 ▶no warnings qw/ experimental::signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 1 ▶use List::Util qw/ sum0 /;
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58 # we have long namespaces and use them multiple times so have
59 # normalised them out into the $parent and @subclasses below
60 1 my $parent = 'Business::NAB::Australian::DirectEntry::Report';
61  
62 1 my @subclasses = (
63 qw/
64 HeaderRecord
65 PaymentRecord
66 ValueSummary
67 FailedRecord
68 FailedSummary
69 TrailerRecord
70 DisclaimerRecord
71 /
72 );
73  
74 =head1 ATTRIBUTES
75  
76 All attributes are ArrayRef[Obj] where Obj are of the Business::NAB::Australian::DirectEntry::Report::* namespace:
77  
78 HeaderRecord
79 PaymentRecord
80 ValueSummary
81 FailedRecord
82 FailedSummary
83 TrailerRecord
84 DisclaimerRecord
85  
86 Convenience methods are available for trivial addition of new elements
87 to the arrays:
88  
89 $Report->add_header_record( $HeaderRecord );
90 $Report->add_payment_record( $PaymentRecord );
91 $Report->add_value_summary( $ValueSummary );
92 $Report->add_failed_record( $FailedRecord );
93 $Report->add_failed_summary( $FailedSummary );
94 $Report->add_trailer_record( $TrailerRecord );
95 $Report->add_disclaimer_record( $DisclaimerRecord );
96  
97 =over
98  
99 =item header_record (ArrayRef[Obj])
100  
101 =item payment_record (ArrayRef[Obj])
102  
103 =item value_summary (ArrayRef[Obj])
104  
105 =item failed_record (ArrayRef[Obj])
106  
107 =item failed_summary (ArrayRef[Obj])
108  
109 =item trailer_record (ArrayRef[Obj])
110  
111 =item disclaimer_record (ArrayRef[Obj])
112  
113 =back
114  
115 =cut
116  
117 1 __PACKAGE__->load_attributes( $parent, @subclasses );
118  
119 =head1 METHODS
120  
121 =head2 new_from_file
122  
123 Returns a new instance of the class with attributes populated from
124 the result of parsing the passed file
125  
126 my $Payments = Business::NAB::Australian::DirectEntry::Report
127 ->new_from_file( $file_path );
128  
129 =cut
130  
131 1 ▶sub new_from_file ( $class, $file ) {
Subroutine new_from_file: called CC=1 SCAR=0.0
Pod documented
132  
133 1 my %sub_class_map = (
134 '00' => 'HeaderRecord',
135 '53' => 'PaymentRecord',
136 '54' => 'ValueSummary',
137 '57' => 'PaymentRecord',
138 '58' => 'ValueSummary',
139 '61' => 'FailedRecord',
140 '62' => 'FailedSummary',
141 '99' => 'TrailerRecord',
142 '100' => 'DisclaimerRecord',
143 );
144  
145 1 my $self = $class->new;
146  
147 1 return $self->SUPER::new_from_file(
148 $parent, $file, \%sub_class_map, ','
149 );
150 }
151  
152 =head2 to_file
153  
154 Writes the file content to the passed file path:
155  
156 $Report->to_file(
157 $file_path,
158 $separator, # defaults to "\r\n"
159 );
160  
161 =cut
162  
163 3 ▶sub to_file (
Subroutine to_file: called CC=11 SCAR=24.0
Pod documented
164 $self,
165 $file,
166 3 $sep = "\r\n",
167 ) {
168 3 open( my $fh, '>', $file );
169  
170 3 print $fh $self->header_record->[ 0 ]->to_record . $sep;
171  
172 3 my $class = "Business::NAB::Australian::DirectEntry::Report::ValueSummary";
173 3 my @records;
174  
175 3 foreach my $type ( qw/ credit debit / ) {
176  
177 6 my $check = "is_${type}";
178 6 my @payments = grep { $_->$check } $self->payment_record->@*;
179 6 print $fh $_->to_record . $sep foreach ( @payments );
180  
181 6 my ( $ValueSummary ) = grep { $_->$check } $self->value_summary->@*;
182  
183 $ValueSummary //= $class->new(
184 record_type => $type eq 'credit' ? '54' : '58',
185 sub_trancode => 'UVD',
186 number_of_items => scalar( @payments ),
187 6 ▶ total_of_items => sum0 map { $_->amount } @payments,
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'credit' ? : 1 1 2
Condition66%2/3
$ValueSummary //= $class->new("record_type", $type eq "credit" ? 54 : 58, "sub_trancode", "UVD", "number_of_items", scalar @payments, "total_of_items", &sum0(map({$_->amount;} @payments)))
l!l&&r!l&&!r
420
MC/DC0%0/2
$ValueSummary //= $class->new("record_type", $type eq "credit" ? 54 : 58, "sub_trancode", "UVD", "number_of_items", scalar @payments, "total_of_items", &sum0(map({$_->amount;} @payments)))
$ValueSummary $class->new("record_type", $type eq "credit" ? 54 : 58, "sub_trancode", "UVD", "number_of_items", scalar @payments, "total_of_items", &sum0(map({$_->amount;} @payments)))
Truth table66%2/3
A //= B
A= $ValueSummaryB= $class->new("record_type", $type eq "credit" ? 54 : 58, "sub_trancode", "UVD", "number_of_items", scalar @payments, "total_of_items", &sum0(map({$_->amount;} @payments)))
ABresult
1X1
011
000
188 );
189  
190 6 print $fh $ValueSummary->to_record . $sep;
191  
192 6 push( @records, @payments );
193 }
194  
195 3 $class = "Business::NAB::Australian::DirectEntry::Report::FailedSummary";
196  
197 3 ▶ if ( my @failed = $self->failed_record->@* ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@failed) = @{$self->failed_record}) 3 0 3
198  
199 3 print $fh $_->to_record . $sep foreach ( @failed );
200  
201 3 my ( $FailedSummary ) = $self->failed_summary->@*;
202  
203 $FailedSummary //= $class->new(
204 sub_trancode => 'UXS',
205 number_of_items => scalar( @failed ),
206 failed_item_treatment_option => 1,
207 text => 'Failed items will be returned as individual '
208 . 'items to your trace account.',
209 3 ▶ total_of_items => sum0 map { $_->amount } @failed,
Condition66%2/3
$FailedSummary //= $class->new("sub_trancode", "UXS", "number_of_items", scalar @failed, "failed_item_treatment_option", 1, "text", "Failed items will be returned as individual items to your trace account.", "total_of_items", &sum0(map({$_->amount;} @failed)))
l!l&&r!l&&!r
210
MC/DC0%0/2
$FailedSummary //= $class->new("sub_trancode", "UXS", "number_of_items", scalar @failed, "failed_item_treatment_option", 1, "text", "Failed items will be returned as individual items to your trace account.", "total_of_items", &sum0(map({$_->amount;} @failed)))
$FailedSummary $class->new("sub_trancode", "UXS", "number_of_items", scalar @failed, "failed_item_treatment_option", 1, "text", "Failed items will be returned as individual items to your trace account.", "total_of_items", &sum0(map({$_->amount;} @failed)))
Truth table66%2/3
A //= B
A= $FailedSummaryB= $class->new("sub_trancode", "UXS", "number_of_items", scalar @failed, "failed_item_treatment_option", 1, "text", "Failed items will be returned as individual items to your trace account.", "total_of_items", &sum0(map({$_->amount;} @failed)))
ABresult
1X1
011
000
210 );
211  
212 3 print $fh $FailedSummary->to_record . $sep;
213  
214 3 push( @records, @failed );
215 }
216  
217 3 ▶ if ( my ( $TrailerRecord ) = $self->trailer_record->@* ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($TrailerRecord) = @{$self->trailer_record}) { } 2 1 3
218 2 print $fh $TrailerRecord->to_record . $sep;
219 } else {
220  
221 1 my $credit_total = sum0 map { $_->amount } grep { $_->is_credit }
222 @records;
223  
224 1 my $debit_total = sum0 map { $_->amount } grep { $_->is_debit }
225 @records;
226  
227 1 $class = "Business::NAB::Australian::DirectEntry::Report::TrailerRecord";
228 1 $TrailerRecord = $class->new(
229 net_file_total => $credit_total - $debit_total,
230 credit_file_total => $credit_total,
231 debit_file_total => $debit_total,
232 total_number_of_records => scalar( @records ),
233 );
234  
235 1 print $fh $TrailerRecord->to_record . $sep;
236 }
237  
238 3 $class = "Business::NAB::Australian::DirectEntry::Report::DisclaimerRecord";
239 3 my ( $DisclaimerRecord ) = $self->disclaimer_record->@*;
240 3 ▶ $DisclaimerRecord //= $class->new(
Condition66%2/3
$DisclaimerRecord //= $class->new("text", "(c) 2012 National Australia Bank Limit ABN 12 004 044 937")
l!l&&r!l&&!r
120
MC/DC0%0/2
$DisclaimerRecord //= $class->new("text", "(c) 2012 National Australia Bank Limit ABN 12 004 044 937")
$DisclaimerRecord $class->new("text", "(c) 2012 National Australia Bank Limit ABN 12 004 044 937")
Truth table66%2/3
A //= B
A= $DisclaimerRecordB= $class->new("text", "(c) 2012 National Australia Bank Limit ABN 12 004 044 937")
ABresult
1X1
011
000
241 text => "(c) 2012 National Australia Bank Limit ABN 12 004 044 937",
242 );
243  
244 3 print $fh $DisclaimerRecord->to_record . $sep;
245  
246 3 close( $fh );
247  
248 3 return;
249 }
250  
251 =head2 original_filename
252  
253 An alias for the header_record C<import_file_name>
254  
255 =cut
256  
257 1 ▶sub original_filename ( $self ) {
Subroutine original_filename: called CC=1 SCAR=0.0
Pod documented
258 1 $self->header_record->[ 0 ]->import_file_name;
259 }
260  
261 =head2 status
262  
263 Hardcoded to "PROCESSED" - as per NAB's documentation that states
264 "This report assists with confirming the processing of your payment
265 file..."
266  
267 =cut
268  
269 1 ▶sub status ( $self ) { 'PROCESSED' }
Subroutine status: called CC=1 SCAR=0.0
Pod documented
270  
271 =head1 SEE ALSO
272  
273 L<Business::NAB::Australian::DirectEntry::Report::PaymentRecord>
274  
275 L<Business::NAB::Australian::DirectEntry::Report::ValueSummary>
276  
277 L<Business::NAB::Australian::DirectEntry::Report::FailedRecord>
278  
279 L<Business::NAB::Australian::DirectEntry::Report::FailedSummary>
280  
281 =cut
282  
283 1 __PACKAGE__->meta->make_immutable;
« NAB/AccountInformation/File.pm ↑ Summary NAB/Australian/DirectEntry/Payments.pm »