Bug 6521 - allow blank cardnumbers to not trigger "already in use"

Now a blank cardnumber will get stored as a null in the database, which
is a value that allows duplicates. As such, if cardnumbers aren't
mandatory, then you can actually save a user with it being blank.

Signed-off-by: Nicole C. Engard <nengard@bywatersolutions.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
(cherry picked from commit 785af7310d)

Signed-off-by: Chris Nighswonger <chris.nighswonger@gmail.com>
This commit is contained in:
Robin Sheat 2011-06-21 07:54:55 -04:00 committed by Chris Nighswonger
parent d1af75ae4a
commit 89538c1943
2 changed files with 18 additions and 13 deletions

View File

@ -900,6 +900,7 @@ sub fixup_cardnumber ($) {
# if ($cardnumber !~ /\S/ && $autonumber_members) {
($autonumber_members) or return $cardnumber;
defined($cardnumber) or return $cardnumber;
my $checkdigit = C4::Context->preference('checkdigit');
my $dbh = C4::Context->dbh;
if ( $checkdigit and $checkdigit eq 'katipo' ) {
@ -1261,6 +1262,8 @@ sub checkuniquemember {
sub checkcardnumber {
my ($cardnumber,$borrowernumber) = @_;
# If cardnumber is null, we assume they're allowed.
return 0 if !defined($cardnumber);
my $dbh = C4::Context->dbh;
my $query = "SELECT * FROM borrowers WHERE cardnumber=?";
$query .= " AND borrowernumber <> ?" if ($borrowernumber);

View File

@ -236,19 +236,22 @@ if ( (defined $newdata{'userid'}) && ($newdata{'userid'} eq '')){
$debug and warn join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry);
my $extended_patron_attributes = ();
if ($op eq 'save' || $op eq 'insert'){
if (checkcardnumber($newdata{cardnumber},$newdata{borrowernumber})){
push @errors, 'ERROR_cardnumber';
}
my $dateofbirthmandatory = (scalar grep {$_ eq "dateofbirth"} @field_check) ? 1 : 0;
if ($newdata{dateofbirth} && $dateofbirthmandatory) {
my $age = GetAge($newdata{dateofbirth});
my $borrowercategory=GetBorrowercategory($newdata{'categorycode'});
my ($low,$high) = ($borrowercategory->{'dateofbirthrequired'}, $borrowercategory->{'upperagelimit'});
if (($high && ($age > $high)) or ($age < $low)) {
push @errors, 'ERROR_age_limitations';
$template->param('ERROR_age_limitations' => "$low to $high");
# If the cardnumber is blank, treat it as null.
$newdata{'cardnumber'} = undef if $newdata{'cardnumber'} =~ /^\s*$/;
if (checkcardnumber($newdata{cardnumber},$newdata{borrowernumber})){
push @errors, 'ERROR_cardnumber';
}
my $dateofbirthmandatory = (scalar grep {$_ eq "dateofbirth"} @field_check) ? 1 : 0;
if ($newdata{dateofbirth} && $dateofbirthmandatory) {
my $age = GetAge($newdata{dateofbirth});
my $borrowercategory=GetBorrowercategory($newdata{'categorycode'});
my ($low,$high) = ($borrowercategory->{'dateofbirthrequired'}, $borrowercategory->{'upperagelimit'});
if (($high && ($age > $high)) or ($age < $low)) {
push @errors, 'ERROR_age_limitations';
$template->param('ERROR_age_limitations' => "$low to $high");
}
}
}
if($newdata{surname} && C4::Context->preference('uppercasesurnames')) {
$newdata{'surname'} = uc($newdata{'surname'});
@ -396,7 +399,6 @@ if ( $op eq "duplicate" ) {
$template->param( step_1 => 1, step_2 => 1, step_3 => 1, step_4 => 1, step_5 => 1, step_6 => 1 ) unless $step;
}
# my $cardnumber=$data{'cardnumber'};
$data{'cardnumber'}=fixup_cardnumber($data{'cardnumber'}) if $op eq 'add';
if(!defined($data{'sex'})){
$template->param( none => 1);