| 1 | package Business::NAB::AccountInformation::Transaction; | ||||||||||
| 2 | 3 | $Business::NAB::AccountInformation::Transaction::VERSION = '0.11'; | |||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Business::NAB::AccountInformation::Transaction | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | use Business::NAB::AccountInformation::Transaction; | ||||||||||
| 10 | |||||||||||
| 11 | my $Transaction = Business::NAB::AccountInformation::Transaction->new( | ||||||||||
| 12 | transaction_code => $trans_code, | ||||||||||
| 13 | amount_minor_units => $amount, | ||||||||||
| 14 | funds_type => $funds_type, | ||||||||||
| 15 | reference_number => $ref_number, | ||||||||||
| 16 | text => $text, | ||||||||||
| 17 | ); | ||||||||||
| 18 | |||||||||||
| 19 | =head1 DESCRIPTION | ||||||||||
| 20 | |||||||||||
| 21 | Class for parsing a NAB "Account Information File (NAI/BAI2)" transaction | ||||||||||
| 22 | line (type C<16>). | ||||||||||
| 23 | |||||||||||
| 24 | =cut | ||||||||||
| 25 | |||||||||||
| 26 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 3 | ▶ | use feature qw/ signatures state /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 3 | ▶ | use Carp qw/ croak /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | 3 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | 3 | ▶ | use Moose::Util::TypeConstraints; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 3 | ▶ | no warnings qw/ experimental::signatures /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | |||||||||||
| 35 | 3 | ▶ | use Text::CSV_XS qw/ csv /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | 3 | ▶ | use Business::NAB::Types qw/ | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | add_max_string_attribute | ||||||||||
| 38 | 3 | /; | |||||||||
| 39 | |||||||||||
| 40 | =head1 ATTRIBUTES | ||||||||||
| 41 | |||||||||||
| 42 | =over | ||||||||||
| 43 | |||||||||||
| 44 | =item transaction_code (Str, max length 3) | ||||||||||
| 45 | |||||||||||
| 46 | =item funds_type (Str, max length 1) | ||||||||||
| 47 | |||||||||||
| 48 | =item bank_reference (Str, max length 4096) | ||||||||||
| 49 | |||||||||||
| 50 | =item customer_reference (Str, max length 4096) | ||||||||||
| 51 | |||||||||||
| 52 | =item text (Str, max length 4096) | ||||||||||
| 53 | |||||||||||
| 54 | =item amount_minor_units (NAB::Type::PositiveIntOrZero) | ||||||||||
| 55 | |||||||||||
| 56 | =back | ||||||||||
| 57 | |||||||||||
| 58 | =cut | ||||||||||
| 59 | |||||||||||
| 60 | 3 | foreach my $str_attr ( | |||||||||
| 61 | 'transaction_code[3]', | ||||||||||
| 62 | 'funds_type[1]', | ||||||||||
| 63 | 'bank_reference[4096]', | ||||||||||
| 64 | 'customer_reference[4096]', | ||||||||||
| 65 | 'text[4096]', | ||||||||||
| 66 | ) { | ||||||||||
| 67 | 15 | __PACKAGE__->add_max_string_attribute( | |||||||||
| 68 | $str_attr, | ||||||||||
| 69 | is => 'ro', | ||||||||||
| 70 | required => 1, | ||||||||||
| 71 | ); | ||||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 3 | has [ qw/ amount_minor_units / ] => ( | |||||||||
| 75 | is => 'ro', | ||||||||||
| 76 | isa => 'NAB::Type::PositiveIntOrZero', | ||||||||||
| 77 | required => 1, | ||||||||||
| 78 | ); | ||||||||||
| 79 | |||||||||||
| 80 | =head1 METHODS | ||||||||||
| 81 | |||||||||||
| 82 | =head2 new_from_raw_record | ||||||||||
| 83 | |||||||||||
| 84 | Returns a new instance of the class with attributes populated from | ||||||||||
| 85 | the result of parsing the passed line: | ||||||||||
| 86 | |||||||||||
| 87 | my $Transaction = Business::NAB::AccountInformation::Transaction | ||||||||||
| 88 | ::Payments::DescriptiveRecord->new_from_raw_record( $line ); | ||||||||||
| 89 | |||||||||||
| 90 | =cut | ||||||||||
| 91 | |||||||||||
| 92 | 3 | ▶ | sub new_from_raw_record ( $class, $line ) { | ||||||||
|
Subroutine
new_from_raw_record: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 93 | |||||||||||
| 94 | 3 | ▶ | my $aoa = csv( in => \$line ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | or croak( Text::CSV->error_diag ); | ||||||||||
| 96 | |||||||||||
| 97 | 3 | return $class->new_from_record( $aoa->[ 0 ]->@* ); | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | =head2 new_from_record | ||||||||||
| 101 | |||||||||||
| 102 | Returns a new instance of the class with attributes populated from | ||||||||||
| 103 | the result of parsing the already parsed line: | ||||||||||
| 104 | |||||||||||
| 105 | my $Transaction = Business::NAB::AccountInformation::Transaction | ||||||||||
| 106 | ::Payments::DescriptiveRecord->new_from_record( @record ); | ||||||||||
| 107 | |||||||||||
| 108 | =cut | ||||||||||
| 109 | |||||||||||
| 110 | 15 | ▶ | sub new_from_record ( $class, @record ) { | ||||||||
|
Subroutine
new_from_record: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 111 | |||||||||||
| 112 | 15 | my ( $record_type, $trans_code, $amount, $funds_type, $bank_ref, $cust_ref, @text ) | |||||||||
| 113 | = @record; | ||||||||||
| 114 | |||||||||||
| 115 | 15 | ▶ | if ( $record_type ne '16' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 116 | 1 | croak( "unsupported record type ($record_type)" ); | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | 14 | return $class->new( | |||||||||
| 120 | transaction_code => $trans_code, | ||||||||||
| 121 | amount_minor_units => $amount, | ||||||||||
| 122 | funds_type => $funds_type, | ||||||||||
| 123 | bank_reference => $bank_ref, | ||||||||||
| 124 | customer_reference => $cust_ref, | ||||||||||
| 125 | text => join( " ", @text ), | ||||||||||
| 126 | ); | ||||||||||
| 127 | } | ||||||||||
| 128 | |||||||||||
| 129 | =head2 is_debit | ||||||||||
| 130 | |||||||||||
| 131 | =head2 is_credit | ||||||||||
| 132 | |||||||||||
| 133 | Boolean check on the transaction type | ||||||||||
| 134 | |||||||||||
| 135 | if ( $Transaction->is_credit ) { | ||||||||||
| 136 | ... | ||||||||||
| 137 | } | ||||||||||
| 138 | |||||||||||
| 139 | =cut | ||||||||||
| 140 | |||||||||||
| 141 | 1 | ▶ | sub is_debit ( $self ) { | ||||||||
|
Subroutine
is_debit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 142 | 1 | return $self->_raw_description->[ 0 ] eq 'DR'; | |||||||||
| 143 | } | ||||||||||
| 144 | |||||||||||
| 145 | 1 | ▶ | sub is_credit ( $self ) { | ||||||||
|
Subroutine
is_credit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 146 | 1 | return $self->_raw_description->[ 0 ] eq 'CR'; | |||||||||
| 147 | } | ||||||||||
| 148 | |||||||||||
| 149 | =head2 description | ||||||||||
| 150 | |||||||||||
| 151 | Returns a descriptive string for the transaction type | ||||||||||
| 152 | |||||||||||
| 153 | my $description = $Transaction->description; | ||||||||||
| 154 | |||||||||||
| 155 | =cut | ||||||||||
| 156 | |||||||||||
| 157 | 1 | ▶ | sub description ( $self ) { | ||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 158 | 1 | return $self->_raw_description->[ 1 ]; | |||||||||
| 159 | } | ||||||||||
| 160 | |||||||||||
| 161 | 3 | ▶ | sub _raw_description ( $self ) { | ||||||||
|
Subroutine
_raw_description: called CC=1 SCAR=0.0
| |||||||||||
| 162 | |||||||||||
| 163 | 3 | state %transaction_details_codes = ( | |||||||||
| 164 | 175 => [ 'CR', 'Cheques' ], | ||||||||||
| 165 | 195 => [ 'CR', 'Transfer credits' ], | ||||||||||
| 166 | 238 => [ 'CR', 'Dividend' ], | ||||||||||
| 167 | 252 => [ 'CR', 'Reversal Entry' ], | ||||||||||
| 168 | 357 => [ 'CR', 'Credit adjustment' ], | ||||||||||
| 169 | 399 => [ 'CR', 'Miscellaneous credits' ], | ||||||||||
| 170 | 475 => [ 'DR', 'Cheques (paid)' ], | ||||||||||
| 171 | 495 => [ 'DR', 'Transfer debits' ], | ||||||||||
| 172 | 501 => [ 'DR', 'Automatic drawings' ], | ||||||||||
| 173 | 512 => [ 'DR', 'Documentary L/C Drawings/Fees' ], | ||||||||||
| 174 | 555 => [ 'DR', 'Dishonoured cheques' ], | ||||||||||
| 175 | 564 => [ 'DR', 'Loan fees' ], | ||||||||||
| 176 | 595 => [ 'DR', 'FlexiPay' ], | ||||||||||
| 177 | 631 => [ 'DR', 'Debit adjustment' ], | ||||||||||
| 178 | 654 => [ 'DR', 'Debit Interest' ], | ||||||||||
| 179 | 699 => [ 'DR', 'Miscellaneous debits' ], | ||||||||||
| 180 | 905 => [ 'CR', 'Credit Interest' ], | ||||||||||
| 181 | 906 => [ 'CR', 'National nominees credits' ], | ||||||||||
| 182 | 910 => [ 'CR', 'Cash' ], | ||||||||||
| 183 | 911 => [ 'CR', 'Cash/cheques' ], | ||||||||||
| 184 | 915 => [ 'CR', 'Agent Credits' ], | ||||||||||
| 185 | 920 => [ 'CR', 'Inter-bank credits' ], | ||||||||||
| 186 | 925 => [ 'CR', 'Bankcard credits' ], | ||||||||||
| 187 | 930 => [ 'CR', 'Credit balance transfer' ], | ||||||||||
| 188 | 935 => [ 'CR', 'Credits summarised' ], | ||||||||||
| 189 | 936 => [ 'CR', 'EFTPOS' ], | ||||||||||
| 190 | 938 => [ 'CR', 'NFCA credit transactions' ], | ||||||||||
| 191 | 950 => [ 'DR', 'Loan establishment fees' ], | ||||||||||
| 192 | 951 => [ 'DR', 'Account keeping fees' ], | ||||||||||
| 193 | 952 => [ 'DR', 'Unused limit fees' ], | ||||||||||
| 194 | 953 => [ 'DR', 'Security fees' ], | ||||||||||
| 195 | 955 => [ 'DR', 'Charges' ], | ||||||||||
| 196 | 956 => [ 'DR', 'National nominee debits' ], | ||||||||||
| 197 | 960 => [ 'DR', 'Stamp duty-cheque book' ], | ||||||||||
| 198 | 961 => [ 'DR', 'Stamp duty' ], | ||||||||||
| 199 | 962 => [ 'DR', 'Stamp duty-security' ], | ||||||||||
| 200 | 970 => [ 'DR', 'State government tax' ], | ||||||||||
| 201 | 971 => [ 'DR', 'Federal government tax' ], | ||||||||||
| 202 | 975 => [ 'DR', 'Bankcards' ], | ||||||||||
| 203 | 980 => [ 'DR', 'Debit balance transfers' ], | ||||||||||
| 204 | 985 => [ 'DR', 'Debits summarised' ], | ||||||||||
| 205 | 986 => [ 'DR', 'Cheques summarised' ], | ||||||||||
| 206 | 987 => [ 'DR', 'Non-cheques summarised' ], | ||||||||||
| 207 | 988 => [ 'DR', 'NFCA debit transaction' ], | ||||||||||
| 208 | ); | ||||||||||
| 209 | |||||||||||
| 210 | 3 | return $transaction_details_codes{ $self->transaction_code }; | |||||||||
| 211 | } | ||||||||||
| 212 | |||||||||||
| 213 | =head1 SEE ALSO | ||||||||||
| 214 | |||||||||||
| 215 | L<Business::NAB::Types> | ||||||||||
| 216 | |||||||||||
| 217 | =cut | ||||||||||
| 218 | |||||||||||
| 219 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||