return ( $total, \@acctlines, $numlines );
}
-=head2 checkuniquemember (OUEST-PROVENCE)
-
- ($result,$categorycode) = &checkuniquemember($collectivity,$surname,$firstname,$dateofbirth);
-
-Checks that a member exists or not in the database.
-
-C<&result> is nonzero (=exist) or 0 (=does not exist)
-C<&categorycode> is from categorycode table
-C<&collectivity> is 1 (= we add a collectivity) or 0 (= we add a physical member)
-C<&surname> is the surname
-C<&firstname> is the firstname (only if collectivity=0)
-C<&dateofbirth> is the date of birth in ISO format (only if collectivity=0)
-
-=cut
-
-# FIXME: This function is not legitimate. Multiple patrons might have the same first/last name and birthdate.
-# This is especially true since first name is not even a required field.
-
-sub checkuniquemember {
- my ( $collectivity, $surname, $firstname, $dateofbirth ) = @_;
- my $dbh = C4::Context->dbh;
- my $request = ($collectivity) ?
- "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? " :
- ($dateofbirth) ?
- "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=? and dateofbirth=?" :
- "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?";
- my $sth = $dbh->prepare($request);
- if ($collectivity) {
- $sth->execute( uc($surname) );
- } elsif($dateofbirth){
- $sth->execute( uc($surname), ucfirst($firstname), $dateofbirth );
- }else{
- $sth->execute( uc($surname), ucfirst($firstname));
- }
- my @data = $sth->fetchrow;
- ( $data[0] ) and return $data[0], $data[1];
- return 0;
-}
-
sub checkcardnumber {
my ( $cardnumber, $borrowernumber ) = @_;
}
}
-#############test for member being unique #############
+# Test uniqueness of surname, firstname and dateofbirth
if ( ( $op eq 'insert' ) and !$nodouble ) {
- my $category_type_send;
- if ( $category_type eq 'I' ) {
- $category_type_send = $category_type;
+ my $conditions;
+ $conditions->{surname} = $newdata{surname} if $newdata{surname};
+ if ( $category_type ne 'I' ) {
+ $conditions->{firstname} = $newdata{firstname} if $newdata{firstname};
+ $conditions->{dateofbirth} = $newdata{dateofbirth} if $newdata{dateofbirth};
}
- my $check_category; # recover the category code of the doublon suspect borrowers
- # ($result,$categorycode) = checkuniquemember($collectivity,$surname,$firstname,$dateofbirth)
- ( $check_member, $check_category ) = checkuniquemember(
- $category_type_send,
- ( $newdata{surname} ? $newdata{surname} : $data{surname} ),
- ( $newdata{firstname} ? $newdata{firstname} : $data{firstname} ),
- ( $newdata{dateofbirth} ? $newdata{dateofbirth} : $data{dateofbirth} )
- );
- if ( !$check_member ) {
+ my $patrons = Koha::Patrons->search($conditions);
+ if ( $patrons->count > 0) {
$nodouble = 1;
+ $check_member = $patrons->next->borrowernumber;
}
}