From bf1a858645217786e8b2d559537baa421a6a6103 Mon Sep 17 00:00:00 2001 From: tipaul Date: Mon, 7 Jul 2003 14:43:42 +0000 Subject: [PATCH] improving checkdigit sub. --- C4/Input.pm | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/C4/Input.pm b/C4/Input.pm index 4815091c0a..e1824a3450 100644 --- a/C4/Input.pm +++ b/C4/Input.pm @@ -90,7 +90,10 @@ sub checkdigit { #different from the one where the checkdigit on the number is #not correct - unless ( $nounique ) + if (C4::Context->preference("checkdigit") eq "none") { + return 1; + } + unless ( $nounique ) { my $dbh=C4::Context->dbh; my $query=qq{SELECT * FROM borrowers WHERE cardnumber="$infl"}; @@ -103,28 +106,24 @@ sub checkdigit { } } - if (C4::Context->preference("checkdigit") eq "none") { - return 1; - } else { - my @weightings = (8,4,6,3,5,2,1); - my $sum; - my $i = 1; - my $valid = 0; - - foreach $i (1..7) { - my $temp1 = $weightings[$i-1]; - my $temp2 = substr($infl,$i,1); - $sum += $temp1 * $temp2; - } - my $rem = ($sum%11); - if ($rem == 10) { - $rem = "X"; - } - if ($rem eq substr($infl,8,1)) { - $valid = 1; - } - return $valid; + my @weightings = (8,4,6,3,5,2,1); + my $sum; + my $i = 1; + my $valid = 0; + + foreach $i (1..7) { + my $temp1 = $weightings[$i-1]; + my $temp2 = substr($infl,$i,1); + $sum += $temp1 * $temp2; + } + my $rem = ($sum%11); + if ($rem == 10) { + $rem = "X"; + } + if ($rem eq substr($infl,8,1)) { + $valid = 1; } + return $valid; } # sub checkdigit =item checkvalidisbn -- 2.39.5