koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha/C4 Reserves2.pm [dev_week]


From: Chris Cormack
Subject: [Koha-cvs] koha/C4 Reserves2.pm [dev_week]
Date: Mon, 11 Jun 2007 23:48:26 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         dev_week
Changes by:     Chris Cormack <rangi>   07/06/11 23:48:26

Modified files:
        C4             : Reserves2.pm 

Log message:
        Merging in code to do item level reserves

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Reserves2.pm?cvsroot=koha&only_with_tag=dev_week&r1=1.38.4.3&r2=1.38.4.4

Patches:
Index: Reserves2.pm
===================================================================
RCS file: /sources/koha/koha/C4/Attic/Reserves2.pm,v
retrieving revision 1.38.4.3
retrieving revision 1.38.4.4
diff -u -b -r1.38.4.3 -r1.38.4.4
--- Reserves2.pm        11 Jun 2007 22:36:40 -0000      1.38.4.3
+++ Reserves2.pm        11 Jun 2007 23:48:25 -0000      1.38.4.4
@@ -3,9 +3,10 @@
 
 package C4::Reserves2;
 
-# $Id: Reserves2.pm,v 1.38.4.3 2007/06/11 22:36:40 rangi Exp $
+# $Id: Reserves2.pm,v 1.38.4.4 2007/06/11 23:48:25 rangi Exp $
 
 # Copyright 2000-2002 Katipo Communications
+# Copyright 2007 Liblime
 #
 # This file is part of Koha.
 #
@@ -107,7 +108,7 @@
        my ($bib,$bor)address@hidden;
        my $dbh = C4::Context->dbh;
        # Find the desired items in the reserves
-       my $query="SELECT *,reserves.branchcode,biblio.title AS btitle, 
reserves.timestamp as rtimestamp FROM reserves,borrowers,biblio ";
+       my $query="SELECT *,reserves.branchcode,biblio.title AS btitle, 
reserves.timestamp as rtimestamp,itemnumber FROM reserves,borrowers,biblio ";
        # FIXME - These three bits of SQL seem to contain a fair amount of
        # redundancy. Wouldn't it be better to have a @clauses array, add
        # one or two clauses as necessary, then join(" AND ", @clauses) ?
@@ -249,18 +250,28 @@
            # FIXME - $item might be undefined or empty: the caller
            # might be searching by barcode.
            if ($res->{'itemnumber'} == $item) {
-               # Found it
-               return ("Waiting", $res);
-           } else {
+                       if ( C4::Context->preference('itemlevelreserves') && 
$res->{'Found'} ne 'W' ) {
+                                return ( "Reserved", $res );
+                       }
+                       else {
+                               return ( "Waiting", $res );
+                               
+                   }
+           } 
+               else {
                # See if this item is more important than what we've got
                # so far.
                if ($res->{'priority'} != 0 && $res->{'priority'} < $priority) {
+                               if ( 
C4::Context->preference('itemlevelreserves') ){                    
+                               }
+                               else {
                    $priority = $res->{'priority'};
                    $highest = $res;
                }
            }
        }
     }
+    }
 
     # If we get this far, then no exact match was found. Print the
     # most important item on the list. I think this tells us who's
@@ -514,7 +525,28 @@
                    OR reserves.constrainttype='a' )
                   AND reserves.cancellationdate is NULL
                   AND (reserves.found <> 'F' or reserves.found is NULL)");
+    if (C4::Context->preference('itemlevelreserves')){
+               $sth = $dbh->prepare(
+                       "SELECT reserves.biblionumber               AS 
biblionumber,
+             reserves.borrowernumber             AS borrowernumber,
+             reserves.reservedate                AS reservedate,
+             reserves.branchcode                 AS branchcode,
+             reserves.cancellationdate           AS cancellationdate,
+             reserves.found                      AS found,
+             reserves.reservenotes               AS reservenotes,
+             reserves.priority                   AS priority,
+             reserves.timestamp                  AS timestamp,
+             reserves.itemnumber                 AS itemnumber,
+             FROM reserves
+             WHERE reserves.biblionumber = ?
+             AND reserves.cancellationdate is NULL
+             AND (reserves.found <> 'F' or reserves.found is NULL)"
+         );
+         $sth->execute($biblio);
+     }
+     else {
   $sth->execute($biblio, $bibitem);
+        }
   my @results;
   while (my $data=$sth->fetchrow_hashref){
     push(@results,$data);
@@ -528,7 +560,7 @@
 # XXX - POD
 sub CreateReserve {
   my
-($env,$branch,$borrnum,$biblionumber,$constraint,$bibitems,$priority,$notes,$title)=
 @_;
+($env,$branch,$borrnum,$biblionumber,$constraint,$bibitems,$priority,$notes,$title,$itemnumbers)=
 @_;
   my $fee=CalcReserveFee($env,$borrnum,$biblionumber,$constraint,$bibitems);
   my $dbh = C4::Context->dbh;
   my $const = lc substr($constraint,0,1);
@@ -546,28 +578,49 @@
     $usth->execute($borrnum,$nextacctno,$fee,'Reserve Charge -'.$title,$fee);
     $usth->finish;
   }
-  #if ($const eq 'a'){
-    my $sth = $dbh->prepare("insert into reserves
-   
(borrowernumber,biblionumber,reservedate,branchcode,constrainttype,priority,reservenotes)
-    values (?,?,?,?,?,?,?)");
-    
$sth->execute($borrnum,$biblionumber,$resdate,$branch,$const,$priority,$notes);
+    
+    if ( C4::Context->preference('itemlevelreserves') ) { 
+               my $sth = $dbh->prepare( 
+                       "INSERT INTO reserves 
(borrowernumber,biblionumber,reservedate,branchcode,constrainttype,priority,reservenotes,itemnumber)
 VALUES (?,?,?,?,?,?,?,?)"                                                      
                                                                                
 
+          );
+        if ( $constraint ne 'a' ) { 
+                       foreach my $item (@$bibitems) {
+                               $sth->execute( $borrnum, $biblionumber, 
$resdate, $branch,
+                                       $const, $priority, $notes, $item );
+                               $priority++;
+                       }
+                       $sth->finish();
+               }                                                               
                                                                                
   
+        else {
+                       $sth->execute( $borrnum, $biblionumber, $resdate, 
$branch, $const,
+                               $priority, $notes, '' );
+                       $priority++;
+
+               }
+    }        
+    else {
+               my $sth = $dbh->prepare(
+                       "INSERT INTO reserves 
(borrowernumber,biblionumber,reservedate,branchcode,constrainttype,priority,reservenotes)
 VALUES (?,?,?,?,?,?,?)" 
+               );
+               
+                $sth->execute( $borrnum, $biblionumber, $resdate, $branch, 
$const,
+                        $priority, $notes ); 
     $sth->finish;
-  #}
-  if (($const eq "o") || ($const eq "e")) {
+               
+        if ( ( $const eq "o" ) || ( $const eq "e" ) ) {
     my $numitems = @$bibitems;
     my $i = 0;
-    while ($i < $numitems) {
+                       while ( $i < $numitems ) {
       my $biblioitem = @$bibitems[$i];
-      my $sth = $dbh->prepare("insert into
-      reserveconstraints
-      (borrowernumber,biblionumber,reservedate,biblioitemnumber)
-      values (?,?,?,?)");
-      $sth->execute($borrnum,$biblionumber,$resdate,$biblioitem);
+                               my $sth        = $dbh->prepare(
+                                       "INSERT INTO  reserveconstraints 
(borrowernumber,biblionumber,reservedate,biblioitemnumber) VALUES (?,?,?,?)"
+                               );
+                $sth->execute( $borrnum, $biblionumber, $resdate, $biblioitem 
); 
       $sth->finish;
       $i++;
     }
   }
-#  print $query;
+       }
   return();
 }
 
@@ -707,27 +760,42 @@
 # XXX - POD
 sub UpdateReserve {
     #subroutine to update a reserve
-    my ($rank,$biblio,$borrower,$branch)address@hidden;
+    my ($rank,$biblio,$borrower,$branch,$itemnumber)address@hidden;
     return if $rank eq "W";
     return if $rank eq "n";
     my $dbh = C4::Context->dbh;
-    if ($rank eq "del") {
-       my $sth=$dbh->prepare("UPDATE reserves SET cancellationdate=now()
-                                   WHERE biblionumber   = ?
-                                     AND borrowernumber = ?
-                                    AND cancellationdate is NULL
-                                     AND (found <> 'F' or found is NULL)");
-       $sth->execute($biblio, $borrower);
+       if ( $rank eq "del" ) {
+               if ( C4::Context->preference('itemlevelreserves') ) {
+                       my $sth = $dbh->prepare(
+                               "UPDATE reserves SET cancellationdate=now() 
WHERE itemnumber=? AND borrowernumber=? AND cancellationdate is NULL AND (found 
<> 'F' or found is NULL)"
+                       );
+            $sth->execute( $itemnumber, $borrower );
+            $sth->finish();
+        }
+        else {
+                       my $sth = $dbh->prepare(
+                               "UPDATE reserves SET cancellationdate=now() 
WHERE biblionumber   = ? AND borrowernumber = ? AND cancellationdate is NULL 
AND (found <> 'F' or found is NULL)" 
+                       );
+            $sth->execute( $biblio, $borrower );
        $sth->finish;
-    } else {
-       my $sth=$dbh->prepare("UPDATE reserves SET priority = ? ,branchcode = 
?, itemnumber = NULL, found = NULL
-                                   WHERE biblionumber   = ?
-                                     AND borrowernumber = ?
-                                    AND cancellationdate is NULL
-                                     AND (found <> 'F' or found is NULL)");
-       $sth->execute($rank, $branch, $biblio, $borrower);
+        }
+    }
+       else {
+               if ( C4::Context->preference('itemlevelreserves') ) { 
+                       my $sth = $dbh->prepare(
+                               "UPDATE reserves SET priority = ? ,branchcode = 
? WHERE biblionumber   = ? AND borrowernumber = ? AND itemnumber= ? AND 
cancellationdate is NULL AND (found <> 'F' or found is NULL)"
+                       );
+            $sth->execute( $rank, $branch, $biblio, $borrower, $itemnumber ); 
+            $sth->finish;
+               }
+        else {
+                       my $sth = $dbh->prepare(
+                               "UPDATE reserves SET priority = ? ,branchcode = 
?, itemnumber = NULL, found = NULL WHERE biblionumber   = ? AND borrowernumber 
= ? AND cancellationdate is NULL AND (found <> 'F' or found is NULL)"
+                       );
+            $sth->execute( $rank, $branch, $biblio, $borrower );
        $sth->finish;
     }
+       }
 }
 
 # XXX - POD




reply via email to

[Prev in Thread] Current Thread [Next in Thread]