Bug 8717 - Wrong subscription notes are showing in catalogue detail view of serials...
[koha.git] / C4 / Members.pm
index b11d976..b2f45b9 100644 (file)
@@ -38,11 +38,12 @@ use C4::NewsChannels; #get slip news
 use DateTime;
 use DateTime::Format::DateParse;
 use Koha::DateUtils;
+use Text::Unaccent qw( unac_string );
 
 our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug);
 
 BEGIN {
-    $VERSION = 3.02;
+    $VERSION = 3.07.00.049;
     $debug = $ENV{DEBUG} || 0;
     require Exporter;
     @ISA = qw(Exporter);
@@ -800,6 +801,7 @@ sub Generate_Userid {
     $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
     $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
     $newuid = lc(($firstname)? "$firstname.$surname" : $surname);
+    $newuid = unac_string('utf-8',$newuid);
     $newuid .= $offset unless $offset == 0;
     $offset++;
 
@@ -897,11 +899,8 @@ sub fixup_cardnumber {
         return "V$cardnumber$rem";
      } else {
 
-     # MODIFIED BY JF: mysql4.1 allows casting as an integer, which is probably
-     # better. I'll leave the original in in case it needs to be changed for you
-     # my $sth=$dbh->prepare("select max(borrowers.cardnumber) from borrowers");
         my $sth = $dbh->prepare(
-            "select max(cast(cardnumber as signed)) from borrowers"
+            'SELECT MAX( CAST( cardnumber AS SIGNED ) ) FROM borrowers WHERE cardnumber REGEXP "^-?[0-9]+$"'
         );
         $sth->execute;
         my ($result) = $sth->fetchrow;
@@ -998,7 +997,6 @@ sub GetPendingIssues {
     # must avoid biblioitems.* to prevent large marc and marcxml fields from killing performance
     # FIXME: namespace collision: each table has "timestamp" fields.  Which one is "timestamp" ?
     # FIXME: circ/ciculation.pl tries to sort by timestamp!
-    # FIXME: C4::Print::printslip tries to sort by timestamp!
     # FIXME: namespace collision: other collisions possible.
     # FIXME: most of this data isn't really being used by callers.
     my $query =
@@ -1074,10 +1072,9 @@ C<items> tables of the Koha database.
 sub GetAllIssues {
     my ( $borrowernumber, $order, $limit ) = @_;
 
-    #FIXME: sanity-check order and limit
-    my $dbh   = C4::Context->dbh;
+    my $dbh = C4::Context->dbh;
     my $query =
-  "SELECT *, issues.timestamp as issuestimestamp, issues.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp 
+'SELECT *, issues.timestamp as issuestimestamp, issues.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp
   FROM issues 
   LEFT JOIN items on items.itemnumber=issues.itemnumber
   LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
@@ -1090,20 +1087,14 @@ sub GetAllIssues {
   LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
   LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
   WHERE borrowernumber=? AND old_issues.itemnumber IS NOT NULL
-  order by $order";
-    if ( $limit != 0 ) {
+  order by ' . $order;
+    if ($limit) {
         $query .= " limit $limit";
     }
 
     my $sth = $dbh->prepare($query);
-    $sth->execute($borrowernumber, $borrowernumber);
-    my @result;
-    my $i = 0;
-    while ( my $data = $sth->fetchrow_hashref ) {
-        push @result, $data;
-    }
-
-    return \@result;
+    $sth->execute( $borrowernumber, $borrowernumber );
+    return $sth->fetchall_arrayref( {} );
 }
 
 
@@ -2280,14 +2271,14 @@ sub IssueSlip {
 
 #   return unless ( C4::Context->boolean_preference('printcirculationslips') );
 
-    my $today       = POSIX::strftime("%Y-%m-%d", localtime);
+    my $now       = POSIX::strftime("%Y-%m-%d", localtime);
 
     my $issueslist = GetPendingIssues($borrowernumber);
     foreach my $it (@$issueslist){
-        if ($it->{'issuedate'} eq $today) {
-            $it->{'today'} = 1;
+        if ((substr $it->{'issuedate'}, 0, 10) eq $now) {
+            $it->{'now'} = 1;
         }
-        elsif ($it->{'date_due'} le $today) {
+        elsif ((substr $it->{'date_due'}, 0, 10) le $now) {
             $it->{'overdue'} = 1;
         }
 
@@ -2303,7 +2294,7 @@ sub IssueSlip {
                 'biblio' => $_,
                 'items'  => $_,
                 'issues' => $_,
-            }, grep { $_->{'today'} } @issues ],
+            }, grep { $_->{'now'} } @issues ],
         );
     }
     else {