[Koha-cvs] koha C4/Reserves2.pm request.pl modrequest.pl p... [rel_2_2]

Chris Cormack crc at liblime.com
Fri Apr 20 00:54:58 CEST 2007


CVSROOT:	/sources/koha
Module name:	koha
Branch:		rel_2_2
Changes by:	Chris Cormack <rangi>	07/04/19 22:54:58

Modified files:
	C4             : Reserves2.pm 
	.              : request.pl modrequest.pl placerequest.pl 
	koha-tmpl/intranet-tmpl/npl/en: request.tmpl 

Log message:
	Allowing item level reserves
	You must have itemlevelreserves set to 1 in system preferences for this to work, otherwise the default behaviour occurs
	Currently its working in circulation and you can place and remove reserves in the librarian interface
	Next I have to get the opac going, plus serials

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Reserves2.pm?cvsroot=koha&only_with_tag=rel_2_2&r1=1.38.2.1&r2=1.38.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/request.pl?cvsroot=koha&only_with_tag=rel_2_2&r1=1.28.2.5&r2=1.28.2.6
http://cvs.savannah.gnu.org/viewcvs/koha/modrequest.pl?cvsroot=koha&only_with_tag=rel_2_2&r1=1.6&r2=1.6.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/placerequest.pl?cvsroot=koha&only_with_tag=rel_2_2&r1=1.4&r2=1.4.4.1
http://cvs.savannah.gnu.org/viewcvs/koha/koha-tmpl/intranet-tmpl/npl/en/request.tmpl?cvsroot=koha&only_with_tag=rel_2_2&r1=1.3.2.2&r2=1.3.2.3

Patches:
Index: C4/Reserves2.pm
===================================================================
RCS file: /sources/koha/koha/C4/Reserves2.pm,v
retrieving revision 1.38.2.1
retrieving revision 1.38.2.2
diff -u -b -r1.38.2.1 -r1.38.2.2
--- C4/Reserves2.pm	3 Aug 2006 03:53:16 -0000	1.38.2.1
+++ C4/Reserves2.pm	19 Apr 2007 22:54:58 -0000	1.38.2.2
@@ -3,7 +3,7 @@
 
 package C4::Reserves2;
 
-# $Id: Reserves2.pm,v 1.38.2.1 2006/08/03 03:53:16 kados Exp $
+# $Id: Reserves2.pm,v 1.38.2.2 2007/04/19 22:54:58 rangi Exp $
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -232,7 +232,7 @@
     return (0, 0) if ($notforloan);
 # get the reserves...
     # Find this item in the reserves
-    my ($count, @reserves) = Findgroupreserve($bibitem, $biblio);
+    my ($count, @reserves) = Findgroupreserve($bibitem, $biblio,$item);
     # $priority and $highest are used to find the most important item
     # in the list returned by &Findgroupreserve. (The lower $priority,
     # the more important the item.)
@@ -245,7 +245,12 @@
 	    # might be searching by barcode.
 	    if ($res->{'itemnumber'} == $item) {
 		# Found it
+		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.
@@ -473,9 +478,34 @@
 =cut
 #'
 sub Findgroupreserve {
-  my ($bibitem,$biblio)=@_;
+  my ($bibitem,$biblio,$itemnumber)=@_;
   my $dbh = C4::Context->dbh;
-  my $sth=$dbh->prepare("SELECT reserves.biblionumber               AS biblionumber,
+    my $sth;
+    if (C4::Context->preference('itemlevelreserves')){
+	warn "finding group reserves for $itemnumber";
+	$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.itemnumber = ? AND reserves.constrainttype = ?)
+		   OR (reserves.biblionumber = ? AND reserves.constrainttype = ?))
+                  AND (reserves.found <> 'F' or reserves.found is NULL)
+                  AND cancellationdate is NULL
+                  ");
+        $sth->execute($biblio,$itemnumber,'o',$biblio,'a');
+
+
+    }
+    else {
+   $sth=$dbh->prepare("SELECT reserves.biblionumber               AS biblionumber,
                       reserves.borrowernumber             AS borrowernumber,
                       reserves.reservedate                AS reservedate,
                       reserves.branchcode                 AS branchcode,
@@ -496,6 +526,7 @@
                   AND reserves.cancellationdate is NULL
                   AND (reserves.found <> 'F' or reserves.found is NULL)");
   $sth->execute($biblio, $bibitem);
+    }
   my @results;
   while (my $data=$sth->fetchrow_hashref){
     push(@results,$data);
@@ -509,16 +540,14 @@
 # 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);
   my @datearr = localtime(time);
   my $resdate =(1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
-  #eval {
   # updates take place here
   if ($fee > 0) {
-#    print $fee;
     my $nextacctno = &getnextacctno($env,$borrnum,$dbh);
     my $usth = $dbh->prepare("insert into accountlines
     (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
@@ -527,13 +556,30 @@
     $usth->execute($borrnum,$nextacctno,$fee,'Reserve Charge -'.$title,$fee);
     $usth->finish;
   }
-  #if ($const eq 'a'){
+  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,$branch,$resdate,$const,$priority,$notes,$item);
+	  $priority++;
+	  }
+      $sth->finish();
+   }
+   else {
+       	  $sth->execute($borrnum,$biblionumber,$branch,$resdate,$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")) {
     my $numitems = @$bibitems;
     my $i = 0;
@@ -548,6 +594,7 @@
       $i++;
     }
   }
+  }
 #  print $query;
   return();
 }
@@ -653,7 +700,7 @@
 # XXX - POD
 sub updatereserves{
   #subroutine to update a reserve
-  my ($rank,$biblio,$borrower,$del,$branch)=@_;
+  my ($rank,$biblio,$borrower,$del,$branch,$itemnumber)=@_;
   my $dbh = C4::Context->dbh;
   if ($del == 0){
     my $sth = $dbh->prepare("Update reserves set priority=?,branchcode=? where
@@ -678,21 +725,36 @@
       $sth3->finish();
     }
     $sth->finish();
+    if (C4::Context->preference('itemlevelreserves')){
+	$sth=$dbh->prepare("UPDATE reserves SET cancellationdate=now() WHERE itemnumber=? AND borrowernumber=?");
+	$sth->execute($itemnumber,$borrower);
+	$sth->finish();
+	} 
+    else {
     $sth=$dbh->prepare("update reserves set cancellationdate=now() where biblionumber=?
     and borrowernumber=?");
     $sth->execute($biblio,$borrower);
     $sth->finish;
   }
+  }
 }
 
 # XXX - POD
 sub UpdateReserve {
     #subroutine to update a reserve
-    my ($rank,$biblio,$borrower,$branch)=@_;
+    my ($rank,$biblio,$borrower,$branch,$itemnumber)=@_;
     return if $rank eq "W";
     return if $rank eq "n";
     my $dbh = C4::Context->dbh;
     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 = ?
@@ -700,7 +762,21 @@
                                      AND (found <> 'F' or found is NULL)");
 	$sth->execute($biblio, $borrower);
 	$sth->finish;
+        }
     } 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 = ?
@@ -709,6 +785,7 @@
 	$sth->execute($rank, $branch, $biblio, $borrower);
 	$sth->finish;
     }
+    }
 }
 
 # XXX - POD

Index: request.pl
===================================================================
RCS file: /sources/koha/koha/Attic/request.pl,v
retrieving revision 1.28.2.5
retrieving revision 1.28.2.6
diff -u -b -r1.28.2.5 -r1.28.2.6
--- request.pl	20 Jun 2006 16:21:43 -0000	1.28.2.5
+++ request.pl	19 Apr 2007 22:54:58 -0000	1.28.2.6
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 
-# $Id: request.pl,v 1.28.2.5 2006/06/20 16:21:43 oleonard Exp $
+# $Id: request.pl,v 1.28.2.6 2007/04/19 22:54:58 rangi Exp $
 
 #script to place reserves/requests
 #writen 2/1/00 by chris at katipo.oc.nz
@@ -36,6 +36,7 @@
 use C4::Acquisition;
 use CGI;
 use C4::Date;
+use C4::Context;
 
 my $input = new CGI;
 my ($template, $borrowernumber, $cookie)
@@ -81,6 +82,8 @@
 # get biblioitem information and build rows for form
 my ($count2, at data) = bibitems($bib);
 
+
+
 my @bibitemloop;
 foreach my $dat (sort {$b->{'dateaccessioned'} cmp $a->{'dateaccessioned'}} @data) {
     $dat->{'dewey'}="" if ($dat->{'dewey'} == 0);
@@ -88,25 +91,49 @@
     $dat->{'dewey'}=~ s/\.0000$//;
     $dat->{'dewey'}=~ s/00$//;
 
-	my %abibitem;
-	my @barcodeloop;
+
     my @barcodes = barcodes($dat->{'biblioitemnumber'});
+    if (C4::Context->preference('itemlevelreserves')){
     foreach my $num (@barcodes) {
+	    my %abibitem;
+	    $abibitem{'class'}="$dat->{'classification'}$dat->{'dewey'}$dat->{'subclass'}";
+	    $abibitem{'itemlost'}=(($dat->{'notforloan'})|| ($dat->{'itemlost'} == 1)) ;
+	    $abibitem{'biblioitemnumber'}=$dat->{'biblioitemnumber'};
+	    $abibitem{'description'}=$dat->{'description'};
+	    $abibitem{'volumeddesc'}=$dat->{'volumeddesc'};
+	    $abibitem{'publicationyear'}=$dat->{'publicationyear'};
 		my %barcode;
+	    my @barcodeloop;
 		$barcode{'barcode'}=$num->{'barcode'};
 		$barcode{'message'}=$num->{'itemlost'} == 1 ? "(lost)" :
 	    $num->{'itemlost'} == 2 ? "(long overdue)" : "";
 		push(@barcodeloop, \%barcode);
-    }
 	$abibitem{'barcodeloop'}=\@barcodeloop;
+	    $abibitem{'biblioitemnumber'}=$num->{'itemnumber'};
+	    push(@bibitemloop,\%abibitem);
+    
+	}
+    }
+    else {	
+	my @barcodeloop;
+	my %abibitem;
     $abibitem{'class'}="$dat->{'classification'}$dat->{'dewey'}$dat->{'subclass'}";
-    my $select;
     $abibitem{'itemlost'}=(($dat->{'notforloan'})|| ($dat->{'itemlost'} == 1)) ;
 	$abibitem{'biblioitemnumber'}=$dat->{'biblioitemnumber'};
 	$abibitem{'description'}=$dat->{'description'};
 	$abibitem{'volumeddesc'}=$dat->{'volumeddesc'};
 	$abibitem{'publicationyear'}=$dat->{'publicationyear'};
+
+	foreach my $num (@barcodes) {
+	    my %barcode;
+	    $barcode{'barcode'}=$num->{'barcode'};
+	    $barcode{'message'}=$num->{'itemlost'} == 1 ? "(lost)" :
+	    $num->{'itemlost'} == 2 ? "(long overdue)" : "";
+	    push(@barcodeloop, \%barcode);
+	}
+	$abibitem{'barcodeloop'}=\@barcodeloop;
 	push(@bibitemloop,\%abibitem);
+    }
 }
 
 
@@ -163,6 +190,7 @@
 	$reserve{'constrainttypeo'}=($res->{'constrainttype'} eq 'o');
 	$reserve{'voldesc'}=$res->{'volumeddesc'};
 	$reserve{'itemtype'}=$res->{'itemtype'};
+    	$reserve{'itemnumber'}=$res->{'itemnumber'};
 	$reserve{'branchloop'}=\@branchloop;
 	$reserve{'optionloop'}=\@optionloop;
 	push(@reserveloop,\%reserve);

Index: modrequest.pl
===================================================================
RCS file: /sources/koha/koha/Attic/modrequest.pl,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -u -b -r1.6 -r1.6.2.1
--- modrequest.pl	21 Jun 2004 21:40:33 -0000	1.6
+++ modrequest.pl	19 Apr 2007 22:54:58 -0000	1.6.2.1
@@ -38,12 +38,13 @@
 my @biblio=$input->param('biblio');
 my @borrower=$input->param('borrowernumber');
 my @branch=$input->param('pickup');
+my @itemnumber=$input->param('itemnumber');
 my $count=@rank;
 
 # goes through and manually changes the reserves record....
 # no attempt is made to check consistency.
 for (my $i=0;$i<$count;$i++){
-    UpdateReserve($rank[$i],$biblio[$i],$borrower[$i],$branch[$i]); #from C4::Reserves2
+    UpdateReserve($rank[$i],$biblio[$i],$borrower[$i],$branch[$i],$itemnumber[$i]); #from C4::Reserves2
 }
 
 my $from=$input->param('from');

Index: placerequest.pl
===================================================================
RCS file: /sources/koha/koha/Attic/placerequest.pl,v
retrieving revision 1.4
retrieving revision 1.4.4.1
diff -u -b -r1.4 -r1.4.4.1

Index: koha-tmpl/intranet-tmpl/npl/en/request.tmpl
===================================================================
RCS file: /sources/koha/koha/koha-tmpl/intranet-tmpl/npl/en/Attic/request.tmpl,v
retrieving revision 1.3.2.2
retrieving revision 1.3.2.3
diff -u -b -r1.3.2.2 -r1.3.2.3
--- koha-tmpl/intranet-tmpl/npl/en/request.tmpl	17 Feb 2005 20:56:59 -0000	1.3.2.2
+++ koha-tmpl/intranet-tmpl/npl/en/request.tmpl	19 Apr 2007 22:54:58 -0000	1.3.2.3
@@ -33,7 +33,7 @@
 
 	<div class="table"><table>
 <tr>
-	<!-- Hide from NPL --><th>Reserve</th><!-- /Hide from NPL -->
+	<th>Reserve</th>
 	<th>Item Type</th>
 	<th>Call Number</th>
 	<!-- Hide from NPL --><th>Volume</th><!-- /Hide from NPL -->
@@ -49,6 +49,7 @@
 			<!-- TMPL_ELSE -->
 				<input type="checkbox" name="reqbib" value=<!-- TMPL_VAR Name="biblioitemnumber" -->>
 				<input type="hidden" name="biblioitem" value=<!-- TMPL_VAR Name="biblioitemnumber" -->>
+				<input type="hidden" name="itemnumber" value="<!-- TMPL_VAR Name="itemnumber" -->">
 			<!-- /TMPL_IF -->
 		</td><!-- /Hide from NPL -->
 		<td>
@@ -93,6 +94,7 @@
 			<td>
 			<input type="hidden" name="borrowernumber" value="<!-- TMPL_VAR Name="borrowernumber" -->" />
 			<input type="hidden" name="biblio" value="<!-- TMPL_VAR Name="biblionumber" -->" />
+			<input type="hidden" name="itemnumber" value="<!-- TMPL_VAR Name="itemnumber" -->" />
 			<select name="rank-request">
 				<!-- TMPL_IF Name="wait" -->
 					<option value="W" selected="selected">Consigned</option>
@@ -137,10 +139,14 @@
 						Next Available
 					<!-- TMPL_ELSE -->
 						<!-- TMPL_IF Name="constrainttypeo" -->
+						        <!-- TMPL_IF NAME="itemnumber" -->
+							     This Item only : <!-- TMPL_VAR NAME="itemnumber" -->
+							<!-- TMPL_ELSE -->
 							This type only : <!-- TMPL_VAR Name="volumeddesc" --> <!-- TMPL_VAR Name="itemtype" -->
 						<!-- /TMPL_IF -->
 					<!-- /TMPL_IF -->
 				<!-- /TMPL_IF -->
+				<!-- /TMPL_IF -->
 
 			</td><!-- /Hide from NPL -->
 		</tr>





More information about the Koha-cvs mailing list