Business-BankAccount-NZ
view release on metacpan or search on metacpan
#-------------------------------------------------------------------------
# Subroutines for validating the various account numbers
#
# National Australia Bank
#
# Each digit is multiplied by a corresponding value in the @vals array
# and added to the total. The total is then divided by 11. If there
# is a remainer then the account number is invalid.
#
sub nab_account($) {
my ($self) = @_;
# Get account digits in an array
my @acc = get_acc_array($self->{account_no});
# Values by which to multiply the digits
my @vals = (7, 6, 5, 4, 3, 2, 1);
my $res = 0;
# The suffix
my $suff = $self->{suffix};
# We only deal with suffixes 3 digits long
}
}
# Reserve Bank
#
# Each digit is multiplied by a corresponding value in the @vals array.
# If the result is more than 1 digit long then the digits are added together
# and that result is added to the total. The total is then divided by 11. If there
# is a remainer then the account number is invalid.
#
sub rb_account($) {
my ($self) = @_;
# Get the account number digits
my @acc = get_acc_array($self->{account_no});
# The suffix
my $suff = $self->{suffix};
# The values by which the account number digits are multiplied
my @vals = (0, 0, 0, 5, 4, 3, 2);
my $res = 0;
# We only deal with suffixes of one digit
if (length($suff) == 1) {
# United Bank
# NOTE: uses multi_add2 not multi_add
#
# Each digit of the account number and the suffix is multiplied by a corresponding
# value in the @vals or @vals2 arrays. If the result is more than 1 digit long then
# the digits are added together until the result is only 1 digit long, and that result
# is added to the total. The total is then divided by 10. If there is a remainer
# then the account number is invalid.
#
sub ub_account($) {
my ($self) = @_;
# Get the digits of the account number
my @acc = get_acc_array($self->{account_no});
# The suffix
my $suff = $self->{suffix};
# Get the digits of the suffix
my @suffs = get_acc_array($suff);
# Values to multiply the account number digits by
my @vals = (1, 3, 7, 1, 3, 7, 1);
# Values to multiply the suffix digits by
}
}
# CountryWide and Rural banks
#
# Each digit is multiplied by a corresponding value in the @vals array
# and the result is added to the total. The total is then divided by 10. If there
# is a remainer then the account number is invalid.
#
sub cwrb_account($) {
my ($self) = @_;
# The account number digits
my @acc = get_acc_array($self->{account_no});
# The suffix
my $suff = $self->{suffix};
# The values to multiply with
my @vals = (1, 7, 3, 1, 7, 3, 1);
my $res = 0;
# Validate the suffix
# The normal case (21 banks)
#
# Each digit of the account number and the branch is multiplied by a corresponding
# value in the @vals or @vals2 arrays and the result is added to the total. The
# total is then divided by 11. If there is a remainer then the account number
# is invalid.
#
# Banks include:
# 01, 02, 03, 06, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 27, 30 and 31
sub other_account($) {
my ($self) = @_;
# Get the account number digits
my @acc = get_acc_array($self->{account_no});
# Get the branch number digits
my @branch = get_acc_array($self->{branch});
# Get the suffix
my $suff = $self->{suffix};
# Values to multiply the branch digits with
my @vals = (6, 3, 7, 9);
# Values to multiply the account digits with
return 1;
} else {
# Result was not zero so error
$self->{error} = 1;
$self->{error_string} = "Invalid account number: $self->{account_no}";
return 0;
}
}
# Return the account number as an array
sub get_acc_array($) {
my ($acc_no) = @_;
return split('', $acc_no);
}
# Multiply the two numbers together and add up any extra digits once.
sub multi_add($$) {
my ($a, $b) = @_;
my $prod = $a * $b;
my $res = 0;
my @nums = split('', $prod);
foreach my $c (@nums) {
$res += $c;
}
return $res;
}
# Multiply the two numbers together and add up any extra digits
# until you have only one digit.
sub multi_add2($$) {
my ($a, $b) = @_;
my $prod = $a * $b;
my $res = $prod;
my @nums = split('', $prod);
while($#nums >= 1) {
$res = 0;
foreach my $c (@nums) {
$res += $c;
}
@nums = split('', $res);
( run in 0.875 second using v1.01-cache-2.11-cpan-65fba6d93b7 )