| 1 | package Business::NAB::BPAY::Remittance::File::TrailerRecord; | ||||||||||||||||||||||||||||
| 2 | 2 | $Business::NAB::BPAY::Remittance::File::TrailerRecord::VERSION = '0.11'; | |||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | Business::NAB::BPAY::Remittance::File::TrailerRecord | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | use Business::NAB::BPAY::Remittance::File::TrailerRecord; | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # parse | ||||||||||||||||||||||||||||
| 12 | my $Trailer = Business::NAB::BPAY::Remittance::File::TrailerRecord | ||||||||||||||||||||||||||||
| 13 | ->new_from_record( $line ); | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # create | ||||||||||||||||||||||||||||
| 16 | my $Trailer = Business::NAB::BPAY::Remittance::File::TrailerRecord->new( | ||||||||||||||||||||||||||||
| 17 | biller_code => ... | ||||||||||||||||||||||||||||
| 18 | number_of_payments => ... | ||||||||||||||||||||||||||||
| 19 | amount_of_payments => ... | ||||||||||||||||||||||||||||
| 20 | number_of_error_corrections => ... | ||||||||||||||||||||||||||||
| 21 | amount_of_error_corrections => ... | ||||||||||||||||||||||||||||
| 22 | number_of_reversals => ... | ||||||||||||||||||||||||||||
| 23 | amount_of_reversals => ... | ||||||||||||||||||||||||||||
| 24 | settlement_amount => ... | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | my $line = $Trailer->to_record; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | Class for trailer record in the "BPAY Remittance File" | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =cut; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 2 | ▶ | use feature qw/ signatures /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | use Carp qw/ croak /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 2 | ▶ | use Business::NAB::Types qw/ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | add_max_string_attribute | ||||||||||||||||||||||||||||
| 43 | 2 | /; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 2 | ▶ | no warnings qw/ experimental::signatures /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =over | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =item biller_code (Str, max length 10) | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =item number_of_payments (NAB::Type::BRFInt) | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =item amount_of_payments (NAB::Type::BRFInt) | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =item number_of_error_corrections (NAB::Type::BRFInt) | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =item amount_of_error_corrections (NAB::Type::BRFInt) | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =item number_of_reversals (NAB::Type::BRFInt) | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =item amount_of_reversals (NAB::Type::BRFInt) | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =item settlement_amount (NAB::Type::BRFInt) | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =back | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =cut | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 2 | foreach my $str_attr ( | |||||||||||||||||||||||||||
| 72 | 'biller_code[10]', | ||||||||||||||||||||||||||||
| 73 | ) { | ||||||||||||||||||||||||||||
| 74 | 2 | __PACKAGE__->add_max_string_attribute( | |||||||||||||||||||||||||||
| 75 | $str_attr, | ||||||||||||||||||||||||||||
| 76 | is => 'ro', | ||||||||||||||||||||||||||||
| 77 | required => 1, | ||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 2 | foreach my $attr ( | |||||||||||||||||||||||||||
| 82 | qw/ | ||||||||||||||||||||||||||||
| 83 | number_of_payments | ||||||||||||||||||||||||||||
| 84 | amount_of_payments | ||||||||||||||||||||||||||||
| 85 | number_of_error_corrections | ||||||||||||||||||||||||||||
| 86 | amount_of_error_corrections | ||||||||||||||||||||||||||||
| 87 | number_of_reversals | ||||||||||||||||||||||||||||
| 88 | amount_of_reversals | ||||||||||||||||||||||||||||
| 89 | settlement_amount | ||||||||||||||||||||||||||||
| 90 | / | ||||||||||||||||||||||||||||
| 91 | ) { | ||||||||||||||||||||||||||||
| 92 | has $attr => ( | ||||||||||||||||||||||||||||
| 93 | is => 'ro', | ||||||||||||||||||||||||||||
| 94 | isa => 'NAB::Type::BRFInt', | ||||||||||||||||||||||||||||
| 95 | required => 1, | ||||||||||||||||||||||||||||
| 96 | coerce => 1, | ||||||||||||||||||||||||||||
| 97 | 35 | ▶ | trigger => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 98 | 35 | my ( $self, $value, $old_value ) = @_; | |||||||||||||||||||||||||||
| 99 | 35 | $self->{ $attr } = int( $value ); | |||||||||||||||||||||||||||
| 100 | }, | ||||||||||||||||||||||||||||
| 101 | 14 | ); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 7 | ▶ | sub _pack_template { | ||||||||||||||||||||||||||
|
Subroutine
_pack_template: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 105 | 7 | return "A2 A10 A9 A15 A9 A15 A9 A15 A15"; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =head1 METHODS | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =head2 new_from_record | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | Returns a new instance of the class with attributes populated from | ||||||||||||||||||||||||||||
| 113 | the result of parsing the passed line: | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | my $Trailer = Business::NAB::BPAY::Remittance::File::TrailerRecord | ||||||||||||||||||||||||||||
| 116 | ->new_from_record( $line ); | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 3 | ▶ | sub new_from_record ( $class, $line ) { | ||||||||||||||||||||||||||
|
Subroutine
new_from_record: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # undef being "this space intentionally left blank" | ||||||||||||||||||||||||||||
| 123 | my ( | ||||||||||||||||||||||||||||
| 124 | 3 | $record_type, | |||||||||||||||||||||||||||
| 125 | $biller_code, | ||||||||||||||||||||||||||||
| 126 | $total_payments, | ||||||||||||||||||||||||||||
| 127 | $amount_payments, | ||||||||||||||||||||||||||||
| 128 | $total_error, | ||||||||||||||||||||||||||||
| 129 | $amount_error, | ||||||||||||||||||||||||||||
| 130 | $total_reversals, | ||||||||||||||||||||||||||||
| 131 | $amount_reversals, | ||||||||||||||||||||||||||||
| 132 | $settlement_amount, | ||||||||||||||||||||||||||||
| 133 | ) = unpack( $class->_pack_template(), $line ); | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 3 | ▶ | if ( $record_type ne '99' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 1 | croak( "unsupported record type ($record_type)" ); | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 2 | return $class->new( | |||||||||||||||||||||||||||
| 140 | biller_code => $biller_code, | ||||||||||||||||||||||||||||
| 141 | number_of_payments => $total_payments, | ||||||||||||||||||||||||||||
| 142 | amount_of_payments => $amount_payments, | ||||||||||||||||||||||||||||
| 143 | number_of_error_corrections => $total_error, | ||||||||||||||||||||||||||||
| 144 | amount_of_error_corrections => $amount_error, | ||||||||||||||||||||||||||||
| 145 | number_of_reversals => $total_reversals, | ||||||||||||||||||||||||||||
| 146 | amount_of_reversals => $amount_reversals, | ||||||||||||||||||||||||||||
| 147 | settlement_amount => $settlement_amount, | ||||||||||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =head2 to_record | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | Returns a string constructed from the object's attributes, representing | ||||||||||||||||||||||||||||
| 154 | the record for use in a batch file: | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | my $line = $Trailer->to_record; | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =cut | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 4 | ▶ | sub to_record ( $self ) { | ||||||||||||||||||||||||||
|
Subroutine
to_record: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 4 | my $record = pack( | |||||||||||||||||||||||||||
| 163 | $self->_pack_template(), | ||||||||||||||||||||||||||||
| 164 | "99", | ||||||||||||||||||||||||||||
| 165 | $self->biller_code, | ||||||||||||||||||||||||||||
| 166 | sprintf( "%09s", $self->_brf_int( $self->number_of_payments ) ), | ||||||||||||||||||||||||||||
| 167 | sprintf( "%015s", $self->_brf_int( $self->amount_of_payments ) ), | ||||||||||||||||||||||||||||
| 168 | sprintf( "%09s", $self->_brf_int( $self->number_of_error_corrections ) ), | ||||||||||||||||||||||||||||
| 169 | sprintf( "%015s", $self->_brf_int( $self->amount_of_error_corrections ) ), | ||||||||||||||||||||||||||||
| 170 | sprintf( "%09s", $self->_brf_int( $self->number_of_reversals ) ), | ||||||||||||||||||||||||||||
| 171 | sprintf( "%015s", $self->_brf_int( $self->amount_of_reversals ) ), | ||||||||||||||||||||||||||||
| 172 | sprintf( "%015s", $self->_brf_int( $self->settlement_amount ) ), | ||||||||||||||||||||||||||||
| 173 | ); | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 4 | return $record; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 28 | ▶ | sub _brf_int { | ||||||||||||||||||||||||||
|
Subroutine
_brf_int: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 179 | 28 | my ( $self, $str ) = @_; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | # trailer record amounts in BPAY Remittance Files use the last | ||||||||||||||||||||||||||||
| 182 | # character to represent: | ||||||||||||||||||||||||||||
| 183 | # - the last digit | ||||||||||||||||||||||||||||
| 184 | # - the sign | ||||||||||||||||||||||||||||
| 185 | # | ||||||||||||||||||||||||||||
| 186 | # it's a little odd, but i guess they've historically had to squeeze | ||||||||||||||||||||||||||||
| 187 | # amounts into the 15 available spaces (which are minor units, so 13, | ||||||||||||||||||||||||||||
| 188 | # which still feels like a lot, but whatever). this is the *only* | ||||||||||||||||||||||||||||
| 189 | # NAB file type that does this, so it might actually be a BPAY thing | ||||||||||||||||||||||||||||
| 190 | # | ||||||||||||||||||||||||||||
| 191 | # see also: NAB::Type::BRFInt in Business::NAB::Types which will coerce | ||||||||||||||||||||||||||||
| 192 | # NAB's value to an actual signed integer | ||||||||||||||||||||||||||||
| 193 | 28 | my $last_char = chop( $str ); | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 28 | ▶ | if ( $str && $str < 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$str and $str < 0
MC/DC100%2/2
$str and $str < 0
$str
$str < 0
Truth table100%3/3
A and B
A= $strB= $str < 0
| |||||||||||||||||||||||||||||
| 196 | 1 | $str *= -1; | |||||||||||||||||||||||||||
| 197 | 1 | $last_char =~ tr/0-9$/}J-R/; | |||||||||||||||||||||||||||
| 198 | } else { | ||||||||||||||||||||||||||||
| 199 | 27 | $last_char =~ tr/0-9$/{A-I/; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 28 | return $str . $last_char; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | L<Business::NAB::Types> | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | =cut | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||