From ee39dcd78310184b419ad373ba278e2cf275fe19 Mon Sep 17 00:00:00 2001 From: tipaul Date: Fri, 23 Sep 2005 09:42:33 +0000 Subject: [PATCH] when calculating the member barcode number if the checkdigit is set to "katipo" use katipo calc method. Otherwise, just find the max existing number and add 1 (without check digit or V at the beginning) --- C4/Members.pm | 79 ++++++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index a510e4b1c5..af80a15fe9 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -221,42 +221,51 @@ sub fixup_cardnumber ($) { # Defaults to "0", which is interpreted as "no". if ($cardnumber !~ /\S/ && $autonumber_members) { - my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select max(substring(borrowers.cardnumber,2,7)) from borrowers"); - $sth->execute; - - my $data=$sth->fetchrow_hashref; - $cardnumber=$data->{'max(substring(borrowers.cardnumber,2,7))'}; - $sth->finish; - - # purpose: generate checksum'd member numbers. - # We'll assume we just got the max value of digits 2-8 of member #'s - # from the database and our job is to increment that by one, - # determine the 1st and 9th digits and return the full string. - - if (! $cardnumber) { # If DB has no values, - $cardnumber = 1000000; # start at 1000000 - } else { - $cardnumber += 1; - } - - my $sum = 0; - for (my $i = 0; $i < 8; $i += 1) { - # read weightings, left to right, 1 char at a time - my $temp1 = $weightings[$i]; - - # sequence left to right, 1 char at a time - my $temp2 = substr($cardnumber,$i,1); - - # mult each char 1-7 by its corresponding weighting - $sum += $temp1 * $temp2; + my $dbh = C4::Context->dbh; + if (C4::Context->preference('checkdigit') eq 'katipo') { + # if checkdigit is selected, calculate katipo-style cardnumber. + # otherwise, just use the max() + # purpose: generate checksum'd member numbers. + # We'll assume we just got the max value of digits 2-8 of member #'s + # from the database and our job is to increment that by one, + # determine the 1st and 9th digits and return the full string. + my $sth=$dbh->prepare("select max(substring(borrowers.cardnumber,2,7)) from borrowers"); + $sth->execute; + + my $data=$sth->fetchrow_hashref; + $cardnumber=$data->{'max(substring(borrowers.cardnumber,2,7))'}; + $sth->finish; + if (! $cardnumber) { # If DB has no values, + $cardnumber = 1000000; # start at 1000000 + } else { + $cardnumber += 1; + } + + my $sum = 0; + for (my $i = 0; $i < 8; $i += 1) { + # read weightings, left to right, 1 char at a time + my $temp1 = $weightings[$i]; + + # sequence left to right, 1 char at a time + my $temp2 = substr($cardnumber,$i,1); + + # mult each char 1-7 by its corresponding weighting + $sum += $temp1 * $temp2; + } + + my $rem = ($sum%11); + $rem = 'X' if $rem == 10; + + $cardnumber="V$cardnumber$rem"; + } else { + my $sth=$dbh->prepare("select max(borrowers.cardnumber) from borrowers"); + $sth->execute; + + my ($result)=$sth->fetchrow; + $sth->finish; + $cardnumber=$result+1; + } } - - my $rem = ($sum%11); - $rem = 'X' if $rem == 10; - - $cardnumber="V$cardnumber$rem"; - } return $cardnumber; } -- 2.39.5