warn on attempts to add duplicate item barcodes during batch import
[koha.git] / C4 / Members.pm
index f426da4..00d4341 100644 (file)
@@ -17,7 +17,6 @@ package C4::Members;
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id$
 
 use strict;
 require Exporter;
@@ -31,7 +30,7 @@ use C4::Reserves;
 
 our ($VERSION,@ISA,@EXPORT,@EXPORT_OK);
 
-$VERSION = do { my @v = '$Revision$' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); };
+$VERSION = 3.00;
 
 =head1 NAME
 
@@ -150,7 +149,7 @@ C<$count> is the number of elements in C<$borrowers>.
 
 #'
 #used by member enquiries from the intranet
-#called by member.pl
+#called by member.pl and circ/circulation.pl
 sub SearchMember {
     my ($searchstring, $orderby, $type,$category_type,$filter,$showallbranches ) = @_;
     my $dbh   = C4::Context->dbh;
@@ -158,14 +157,27 @@ sub SearchMember {
     my $count;
     my @data;
     my @bind = ();
-
+       
+       # this is used by circulation everytime a new borrowers cardnumber is scanned
+       # so we can check an exact match first, if that works return, otherwise do the rest
+    $query = "SELECT * FROM borrowers
+                    LEFT JOIN categories ON borrowers.categorycode=categories.categorycode
+                             WHERE cardnumber = ?";
+    my $sth = $dbh->prepare($query);
+    $sth->execute($searchstring);
+    my $data = $sth->fetchall_arrayref({});
+    if (@$data){
+               return ( scalar(@$data), $data );
+       }
+    $sth->finish;
+               
     if ( $type eq "simple" )    # simple search for one letter only
     {
-        $query =
-          "SELECT * 
-           FROM borrowers
-           LEFT JOIN categories ON borrowers.categorycode=categories.categorycode ".
-                  ($category_type?" AND category_type = ".$dbh->quote($category_type):"");
+        $query =  "SELECT *
+             FROM borrowers
+             LEFT JOIN categories ON borrowers.categorycode=categories.categorycode ".
+                    ($category_type?" AND category_type = ".$dbh->quote($category_type):""); 
+
         $query .=
          " WHERE (surname LIKE ? OR cardnumber like ?) ";
         if (C4::Context->preference("IndependantBranches") && !$showallbranches){
@@ -656,9 +668,9 @@ sub AddMember {
     my $dbh = C4::Context->dbh;
     $data{'userid'} = '' unless $data{'password'};
     $data{'password'} = md5_base64( $data{'password'} ) if $data{'password'};
-    $data{'dateofbirth'} = format_date_in_iso( $data{'dateofbirth'} );
-    $data{'dateenrolled'} = format_date_in_iso( $data{'dateenrolled'} );
-    $data{'dateexpiry'}   = format_date_in_iso( $data{'dateexpiry'} );
+    $data{'dateofbirth'}  = format_date_in_iso( $data{'dateofbirth'} );
+    $data{'dateenrolled'} = format_date_in_iso( $data{'dateenrolled'});
+    $data{'dateexpiry'}   = format_date_in_iso( $data{'dateexpiry'}  );
     my $query =
         "insert into borrowers set cardnumber="
       . $dbh->quote( $data{'cardnumber'} )
@@ -721,7 +733,7 @@ sub AddMember {
       . ",B_phone="
       . $dbh->quote( $data{'B_phone'} )
       . ",B_email="
-      . $dbh->quote( $data{'B_email'}, )
+      . $dbh->quote( $data{'B_email'} )
       . ",password="
       . $dbh->quote( $data{'password'} )
       . ",userid="
@@ -1104,17 +1116,15 @@ sub GetMemberAccountRecords {
     my @acctlines;
     my $numlines = 0;
     my $strsth      = qq(
-SELECT * 
-FROM accountlines 
-WHERE borrowernumber=?);
+                        SELECT * 
+                        FROM accountlines 
+                        WHERE borrowernumber=?);
     my @bind = ($borrowernumber);
     if ($date && $date ne ''){
-    $strsth.="
-AND date < ? ";
-    push(@bind,$date);
+            $strsth.=" AND date < ? ";
+            push(@bind,$date);
     }
-    $strsth.="
-ORDER BY date desc,timestamp DESC";
+    $strsth.=" ORDER BY date desc,timestamp DESC";
     my $sth= $dbh->prepare( $strsth );
     $sth->execute( @bind );
     my $total = 0;
@@ -1148,16 +1158,15 @@ sub GetBorNotifyAcctRecord {
     my $dbh = C4::Context->dbh;
     my @acctlines;
     my $numlines = 0;
-    my $query    = qq| SELECT * 
-                       FROM accountlines 
-                       WHERE borrowernumber=? 
-                       AND notify_id=? 
-                       AND (accounttype='FU' OR accounttype='N' OR accounttype='M'OR accounttype='A'OR accounttype='F'OR accounttype='L' OR accounttype='IP' OR accounttype='CH' OR accounttype='RE' OR accounttype='RL')
-                       AND amountoutstanding != '0' 
-                       ORDER BY notify_id,accounttype
-               |;
-    my $sth = $dbh->prepare($query);
-
+    my $sth = $dbh->prepare(
+            "SELECT * 
+                FROM accountlines 
+                WHERE borrowernumber=? 
+                    AND notify_id=? 
+                    AND (accounttype='FU' OR accounttype='N' OR accounttype='M'OR accounttype='A'OR accounttype='F'OR accounttype='L' OR accounttype='IP' OR accounttype='CH' OR accounttype='RE' OR accounttype='RL')
+                    AND amountoutstanding != '0' 
+                ORDER BY notify_id,accounttype
+                ");
     $sth->execute( $borrowernumber, $notifyid );
     my $total = 0;
     while ( my $data = $sth->fetchrow_hashref ) {