Bug 15479 Make ILS cardnumber comparison case insensitive
authorColin Campbell <colin.campbell@ptfs-europe.com>
Wed, 6 Jan 2016 12:56:24 +0000 (12:56 +0000)
committerBrendan Gallagher <brendan@bywatersolutions.com>
Tue, 23 Feb 2016 23:19:57 +0000 (23:19 +0000)
The borrowers table is defined COLLATE=utf8_unicode_ci which means
that cardnumbers may be saved in either lowercase or uppercase and
these are considered equivalent.
The server was performing a case sensitive comparison between
the incoming patron identifier and that retrieved from the db
As a result some renewals were rejected as being on loan to
another borrower if the stored cardnumber differed in case.

Make code comparison comply with db.

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com
C4/SIP/ILS.pm

index 7d702b7..d6117c0 100644 (file)
@@ -146,8 +146,7 @@ sub checkout {
     # holds checked inside do_checkout
     # } elsif ($item->hold_queue && @{$item->hold_queue} && ! $item->barcode_is_borrowernumber($patron_id, $item->hold_queue->[0]->{borrowernumber})) {
        #       $circ->screen_msg("Item on Hold for Another User");
-    } elsif ($item->{patron} && ($item->{patron} ne $patron_id)) {
-       # I can't deal with this right now
+    } elsif ($item->{patron} && !_ci_cardnumber_cmp($item->{patron},$patron_id)) {
                $circ->screen_msg("Item checked out to another patron");
     } else {
                $circ->do_checkout();
@@ -155,7 +154,7 @@ sub checkout {
                        $debug and warn "circ is ok";
                        # If the item is already associated with this patron, then
                        # we're renewing it.
-                       $circ->renew_ok($item->{patron} && ($item->{patron} eq $patron_id));
+                       $circ->renew_ok($item->{patron} && _ci_cardnumber_cmp($item->{patron}, $patron_id));
                
                        $item->{patron} = $patron_id;
                        $item->{due_date} = $circ->{due};
@@ -174,6 +173,13 @@ sub checkout {
     return $circ;
 }
 
+sub _ci_cardnumber_cmp {
+    my ( $s1, $s2) = @_;
+    # As the database is case insensitive we need to normalize two strings
+    # before comparing them
+    return ( uc($s1) eq uc($s2) );
+}
+
 sub checkin {
     my ( $self, $item_id, $trans_date, $return_date, $current_loc, $item_props, $cancel, $checked_in_ok ) = @_;
     my ( $patron, $item, $circ );