NAME

Business::NAB::AccountInformation::File

SYNOPSIS

use Business::NAB::AccountInformation::File;

# parse
my $AccountInfo = Business::NAB::AccountInformation::File
    ->new_from_file( $file_path );

foreach my $Group ( $AccountInfo->groups->@* ) {

    foreach my $Account ( $Group->accounts->@* ) {

        foreach my $Transaction ( $Account->transactions->@* ) {

            ...
        }
    }
}

DESCRIPTION

Class for parsing a NAB "Account Information File (NAI/BAI2)" file

ATTRIBUTES

sender_identification (Str, max length 8)
receiver_identification (Str, max length 4096)
file_creation_date (DateTime)
file_creation_time (Str, max length 4)
file_sequence_number (NAB::Type::PositiveInt)
physical_record_length (NAB::Type::PositiveIntOrZero)
blocking_factor (NAB::Type::PositiveIntOrZero)
version_number (NAB::Type::PositiveInt)
control_total_a (Int)
number_of_groups (Int)
number_of_records (Int)
control_total_b (Int)
groups (ArrayRef[Business::NAB::AccountInformation::Group])

METHODS

new_from_file

Returns a new instance of the class with attributes populated from the result of parsing the passed file

my $Payments = Business::NAB::AccountInformation::File
    ->new_from_file( $file_path );

validate_totals

Checks if the control_total_a and control_total_b values match the expected totals of the contained group items:

$File->validate_totals;

Will throw an exception if any total doesn't match the expected value.

reconstruct_file_records

Returns the file contents as a hashref, having reconstructed the various records within it, for easier parsing:

my $records = Business::NAB::AccountInformation::File
    ->reconstruct_file_records( $file );

This is due to the file format being somewhat baroque and, essentially, a CSV of fixed width meaning some lines get truncated and continued on the next line or multiple lines.

The returned hashref is of the form:

{
    records => @records,
    raw_record_count => $raw_record_count,
}

is_bai2

Boolean check on the file type

if ( $File->is_bai2 ) {
    ...
} else {
    # it's an NAI file
    ...
}

SEE ALSO

Business::NAB::Types

Business::NAB::AccountInformation::Group

Business::NAB::AccountInformation::Account

Business::NAB::AccountInformation::Transaction