BUGFIXING mail alert on issue arrival
[koha_gimpoz] / C4 / Reserves.pm
index d6bb83a..df06370 100644 (file)
@@ -22,23 +22,19 @@ package C4::Reserves;
 # 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;
 use C4::Context;
 use C4::Biblio;
+use C4::Items;
 use C4::Search;
 use C4::Circulation;
 use C4::Accounts;
 
-our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,%EXPORT_TAGS);
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 my $library_name = C4::Context->preference("LibraryName");
 
-# set the version for version checking
-$VERSION = do { my @v = '$Revision$' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); };
-
 =head1 NAME
 
 C4::Reserves - Koha functions for dealing with reservation.
@@ -83,33 +79,35 @@ C4::Reserves - Koha functions for dealing with reservation.
 
 =cut
 
-@ISA = qw(Exporter);
-
-@EXPORT = qw(
-  &AddReserve
-  
-  &GetReservesFromItemnumber
-  &GetReservesFromBiblionumber
-  &GetReservesFromBorrowernumber
-  &GetReservesForBranch
-  &GetReservesToBranch
-  &GetReserveCount
-  &GetReserveFee
-  &GetReservesForBranch
-  &GetReservesToBranch
-  &GetOtherReserves
+BEGIN {
+    # set the version for version checking
+    $VERSION = 3.01;
+       require Exporter;
+    @ISA = qw(Exporter);
+    @EXPORT = qw(
+        &AddReserve
   
-  &ModReserveFill
-  &ModReserveAffect
-  &ModReserve
-  &ModReserveStatus
-  &ModReserveCancelAll
-  &ModReserveMinusPriority
-
-  &CheckReserves
-  &CancelReserve
-);
-
+        &GetReservesFromItemnumber
+        &GetReservesFromBiblionumber
+        &GetReservesFromBorrowernumber
+        &GetReservesForBranch
+        &GetReservesToBranch
+        &GetReserveCount
+        &GetReserveFee
+    
+        &GetOtherReserves
+        
+        &ModReserveFill
+        &ModReserveAffect
+        &ModReserve
+        &ModReserveStatus
+        &ModReserveCancelAll
+        &ModReserveMinusPriority
+        
+        &CheckReserves
+        &CancelReserve
+    );
+}    
 
 =item AddReserve
 
@@ -217,7 +215,8 @@ sub GetReservesFromBiblionumber {
                 reservedate,
                 constrainttype,
                 found,
-                itemnumber
+                itemnumber,
+                reservenotes
         FROM     reserves
         WHERE     cancellationdate IS NULL
         AND    (found <> \'F\' OR found IS NULL)
@@ -557,15 +556,22 @@ sub GetReservesToBranch {
 sub GetReservesForBranch {
     my ($frombranch) = @_;
     my $dbh          = C4::Context->dbh;
-    my $sth          = $dbh->prepare( "
-        SELECT borrowernumber,reservedate,itemnumber,waitingdate
+       my $query        = "SELECT borrowernumber,reservedate,itemnumber,waitingdate
         FROM   reserves 
         WHERE   priority='0'
             AND cancellationdate IS NULL 
-            AND found='W' 
-            AND branchcode=?
-        ORDER BY waitingdate" );
-    $sth->execute($frombranch);
+            AND found='W' ";
+    if ($frombranch){
+        $query .= " AND branchcode=? ";
+       }
+    $query .= "ORDER BY waitingdate" ;
+    my $sth = $dbh->prepare($query);
+    if ($frombranch){
+               $sth->execute($frombranch);
+       }
+    else {
+               $sth->execute();
+       }
     my @transreserv;
     my $i = 0;
     while ( my $data = $sth->fetchrow_hashref ) {
@@ -1031,12 +1037,13 @@ sub _FixPriority {
     # get whats left
 # FIXME adding a new security in returned elements for changing priority,
 # now, we don't care anymore any reservations with itemnumber linked (suppose a waiting reserve)
+       # This is wrong a waiting reserve has W set
+       # The assumption that having an itemnumber set means waiting is wrong and should be corrected any place it occurs
     my $query = qq/
         SELECT borrowernumber, reservedate, constrainttype
         FROM   reserves
         WHERE  biblionumber   = ?
           AND  cancellationdate IS NULL
-          AND  itemnumber IS NULL
           AND  ((found <> 'F' and found <> 'W') or found is NULL)
         ORDER BY priority ASC
     /;
@@ -1146,3 +1153,4 @@ Koha Developement team <info@koha.org>
 
 =cut
 
+1;