From 0c3fb7051e199e8dbe55da93f50fdf9fb80647cb Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Thu, 20 Dec 2007 12:22:39 -0600 Subject: [PATCH] Members.pm - checkuniquemember minor refactor and perldoc correction. Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Members.pm | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 2a075f41e8..40bee8394c 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -1124,53 +1124,38 @@ sub GetBorNotifyAcctRecord { =head2 checkuniquemember (OUEST-PROVENCE) - $result = &checkuniquemember($collectivity,$surname,$categorycode,$firstname,$dateofbirth); + ($result,$categorycode) = &checkuniquemember($collectivity,$surname,$firstname,$dateofbirth); Checks that a member exists or not in the database. -C<&result> is 1 (=exist) or 0 (=does not exist) +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<&categorycode> is from categorycode table C<&firstname> is the firstname (only if collectivity=0) -C<&dateofbirth> is the date of birth (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; - if ($collectivity) { - -# $request="select count(*) from borrowers where surname=? and categorycode=?"; - $request = - "select borrowernumber,categorycode from borrowers where surname=? "; - } - else { - -# $request="select count(*) from borrowers where surname=? and categorycode=? and firstname=? and dateofbirth=?"; - $request = -"select borrowernumber,categorycode from borrowers where surname=? and firstname=? and dateofbirth=?"; - } + my $request = ($collectivity) ? + "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? " : + "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=? and dateofbirth=? "; my $sth = $dbh->prepare($request); if ($collectivity) { $sth->execute( uc($surname) ); - } - else { + } else { $sth->execute( uc($surname), ucfirst($firstname), $dateofbirth ); } my @data = $sth->fetchrow; - if ( $data[0] ) { - $sth->finish; - return $data[0], $data[1]; - - # - } - else { - $sth->finish; - return 0; - } + $sth->finish; + ( $data[0] ) and return $data[0], $data[1]; + return 0; } sub checkcardnumber { -- 2.11.0