NAB/Australian/DirectEntry/Payments/DetailRecord.pm

filter: Statementstmt 100% 47 / 47 Branchbran 88.8% 16 / 18 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 14 / 14 Podpod 80.0% 4 / 5 totaltotal 94.2% 82 / 87 CC 10 SCAR 11.6
CC
10
Cov
96%
new_from_record
7.0
to_record
3.0
is_debit
2.0
CRAP 3.2
« NAB/AccountInformation/Group.pm ↑ Summary NAB/FileContainer.pm »
1 package Business::NAB::Australian::DirectEntry::Payments::DetailRecord;
2 4 $Business::NAB::Australian::DirectEntry::Payments::DetailRecord::VERSION = '0.11';
3 =head1 NAME
4  
5 Business::NAB::Australian::DirectEntry::Payments::DetailRecord
6  
7 =head1 SYNOPSIS
8  
9 use Business::NAB::Australian::DirectEntry::Payments::DetailRecord;
10  
11 # parse
12 my $Record = Business::NAB::Australian::DirectEntry
13 ::Payments::DetailRecord->new_from_record( $line );
14  
15 # create
16 my $Record = Business::NAB::Australian::DirectEntry
17 ::Payments::DetailRecord->new(
18 bsb_number => '083-047',
19 account_number => '111111111',
20 transaction_code => '13',
21 amount => 1,
22 title_of_account => ' Beneficiary 1',
23 lodgement_reference => 'FOR DEMONSTRATION',
24 bsb_number_trace => '083-047',
25 account_number_trace => '123456789',
26 remitter_name => 'NAB SAMPLE TEST',
27 withholding_tax => '00000000',
28 );
29  
30 my $line = $Record->to_record;
31  
32 =head1 DESCRIPTION
33  
34 Class for detail record in the "Australian Direct Entry Payments and
35 Dishonour report"
36  
37 =cut;
38  
39 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 4 ▶use feature qw/ signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 4 ▶use Carp qw/ croak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 4 ▶use Business::NAB::Types qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
46 add_max_string_attribute
47 4 /;
48  
49 4 ▶no warnings qw/ experimental::signatures /;
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 =head1 ATTRIBUTES
52  
53 =over
54  
55 =item bsb_number (NAB::Type::BSBNumber)
56  
57 =item bsb_number_trace (NAB::Type::BSBNumber)
58  
59 =item account_number (NAB::Type::AccountNumber)
60  
61 =item account_number_trace (NAB::Type::AccountNumber)
62  
63 =item indicator (NAB::Type::Indicator)
64  
65 =item amount (NAB::Type::PositiveInt)
66  
67 =item withholding_tax (NAB::Type::PositiveIntOrZero)
68  
69 =item transaction_code (Str, max length 2)
70  
71 =item title_of_account (Str, max length 32)
72  
73 =item lodgement_reference (Str, max length 18)
74  
75 =item remitter_name (Str, max length 16)
76  
77 =back
78  
79 =cut
80  
81 4 has [ qw/ bsb_number bsb_number_trace / ] => (
82 is => 'ro',
83 isa => 'NAB::Type::BSBNumber',
84 required => 1,
85 coerce => 1,
86 );
87  
88 4 has [ qw/ account_number account_number_trace / ] => (
89 is => 'ro',
90 isa => 'NAB::Type::AccountNumber',
91 required => 1,
92 );
93  
94 has [ qw/ indicator / ] => (
95 is => 'ro',
96 isa => 'NAB::Type::Indicator',
97 required => 0,
98 22 ▶ default => sub { ' ' },
Subroutine __ANON__: called CC=1 SCAR=0.0
99 4 );
100  
101 4 has [ qw/ amount / ] => (
102 is => 'ro',
103 isa => 'NAB::Type::PositiveInt',
104 required => 1,
105 );
106  
107 4 has [ qw/ withholding_tax / ] => (
108 is => 'ro',
109 isa => 'NAB::Type::PositiveIntOrZero',
110 required => 0,
111 );
112  
113 4 foreach my $str_attr (
114 'transaction_code[2]',
115 'title_of_account[32]',
116 'lodgement_reference[18]',
117 'remitter_name[16]',
118 ) {
119 16 ▶ __PACKAGE__->add_max_string_attribute(
Branch: 1 branch
BranchTrueFalseTotal
$str_attr =~ /original/ ? : 0 16 16
120 $str_attr,
121 is => 'ro',
122 required => $str_attr =~ /original/ ? 0 : 1,
123 );
124 }
125  
126 39 ▶sub _pack_template {
Subroutine _pack_template: called CC=1 SCAR=0.0
127 39 return "A1 A7 A9 A1 A2 A10 A32 A18 A7 A9 A16 A8";
128 }
129  
130 128 ▶sub record_type { 1 }
Subroutine record_type: called CC=1 SCAR=0.0
Pod undocumented
131  
132 =head1 METHODS
133  
134 =head2 new_from_record
135  
136 Returns a new instance of the class with attributes populated from
137 the result of parsing the passed line:
138  
139 my $Record = Business::NAB::Australian::DirectEntry
140 ::Payments::DescriptiveRecord->new_from_record( $line );
141  
142 =cut
143  
144 28 ▶sub new_from_record ( $class, $line ) {
Subroutine new_from_record: called CC=7 SCAR=19.5
Pod documented
145  
146 # undef being "this space intentionally left blank"
147 my (
148 28 $record_type,
149 $bsb_number,
150 $account_number,
151 $indicator,
152 $transaction_code,
153 $amount,
154 $title_of_account,
155 $lodgement_reference,
156 $bsb_number_trace,
157 $account_number_trace,
158 $remitter_name,
159 $withholding_tax,
160 $rest,
161 ) = unpack( $class->_pack_template(), $line );
162  
163 28 my ( $return_code, $orig_day, $orig_user_id );
164  
165 28 ▶ if ( $record_type ne $class->record_type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($record_type ne $class->record_type) 1 27 28
166 1 croak( "unsupported record type ($record_type)" );
167 }
168  
169 27 ▶ if ( $class->record_type eq '1' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($class->record_type eq '1') { } 13 14 27
elsif ($class->record_type eq '2') { } 14 0 14
170  
171 # payments descriptive record
172 } elsif ( $class->record_type eq '2' ) {
173  
174 # returns descriptive record
175 14 $return_code = $indicator;
176 14 $orig_day = $withholding_tax;
177 14 $orig_user_id = $rest;
178 }
179  
180 # Account numbers may be padded with leading spaces
181 # which we strip to preserve round-tripping
182 27 $account_number =~ s/^ +//;
183  
184 27 ▶ return $class->new(
Branch: 2 branches
BranchTrueFalseTotal
$class->record_type eq '1' ? : 13 14 27
$class->record_type eq '2' ? : 14 13 27
Condition50%1/2
$indicator or " "
l!l
013
MC/DC0%0/1
$indicator or " "
$indicator
Truth table50%1/2
A
A= $indicator
Aresult
11
00
185 bsb_number => $bsb_number,
186 account_number => $account_number,
187 transaction_code => $transaction_code,
188 amount => $amount,
189 title_of_account => $title_of_account,
190 lodgement_reference => $lodgement_reference,
191 bsb_number_trace => $bsb_number_trace,
192 account_number_trace => $account_number_trace,
193 remitter_name => $remitter_name,
194  
195 (
196 $class->record_type eq '1'
197 ? (
198 indicator => $indicator || ' ',
199 withholding_tax => $withholding_tax,
200 )
201 : ()
202 ),
203  
204 (
205 $class->record_type eq '2'
206 ? (
207 return_code => $return_code,
208 original_day_of_processing => $orig_day,
209 original_user_id_number => $orig_user_id,
210 )
211 : ()
212 ),
213 );
214 }
215  
216 =head2 to_record
217  
218 Returns a string constructed from the object's attributes, representing
219 the record for use in a batch file:
220  
221 my $line = $Record->to_record;
222  
223 =cut
224  
225 39 ▶sub to_record ( $self ) {
Subroutine to_record: called CC=3 SCAR=11.0
Pod documented
226  
227 39 ▶ my $record = pack(
Branch: 2 branches
BranchTrueFalseTotal
$self->record_type eq '1' ? : 25 14 39
$self->record_type eq '1' ? : 25 14 39
228 $self->_pack_template(),
229 $self->record_type,
230 $self->bsb_number,
231 sprintf( '% 9s', $self->account_number ),
232  
233 $self->record_type eq '1'
234 ? $self->indicator
235 : $self->return_code,
236  
237 $self->transaction_code,
238 sprintf( "%010.0f", $self->amount ),
239 $self->title_of_account,
240 $self->lodgement_reference,
241 $self->bsb_number_trace,
242 $self->account_number_trace,
243 $self->remitter_name,
244  
245 $self->record_type eq '1'
246 ? ( $self->withholding_tax )
247 : (
248 $self->original_day_of_processing,
249 $self->original_user_id_number,
250 ),
251 );
252  
253 39 return $record;
254 }
255  
256 =head2 is_debit
257  
258 =head2 is_credit
259  
260 Boolean check on the transaction type
261  
262 if ( $Record->is_credit ) {
263 ...
264 }
265  
266 =cut
267  
268 44 ▶sub is_credit ( $self ) {
Subroutine is_credit: called CC=1 SCAR=0.0
Pod documented
269 44 return !$self->is_debit;
270 }
271  
272 88 ▶sub is_debit ( $self ) {
Subroutine is_debit: called CC=2 SCAR=6.9
Pod documented
273  
274 # there's only one debit transaction type code so
275 # this is pretty straightforward
276 88 ▶ return $self->transaction_code eq '13' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->transaction_code eq '13' ? : 80 8 88
277 }
278  
279 =head1 SEE ALSO
280  
281 L<Business::NAB::Types>
282  
283 =cut
284  
285 4 __PACKAGE__->meta->make_immutable;
« NAB/AccountInformation/Group.pm ↑ Summary NAB/FileContainer.pm »