[Koha-cvs] koha C4/Reserves2.pm circ/circulation.pl circ/c... [rel_3_0]
Antoine Farnault
antoine at koha-fr.org
Wed Sep 20 17:47:49 CEST 2006
CVSROOT: /sources/koha
Module name: koha
Branch: rel_3_0
Changes by: Antoine Farnault <toins> 06/09/20 15:47:49
Modified files:
C4 : Reserves2.pm
circ : circulation.pl currenttransfers.pl
reserve : modrequest.pl placerequest.pl request.pl
Log message:
some code clean on reserve. Not completely done yet.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Reserves2.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.46.2.1&r2=1.46.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/circ/circulation.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.97.2.2&r2=1.97.2.3
http://cvs.savannah.gnu.org/viewcvs/koha/circ/currenttransfers.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.3&r2=1.3.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/reserve/modrequest.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.2&r2=1.2.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/reserve/placerequest.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.3.2.1&r2=1.3.2.2
http://cvs.savannah.gnu.org/viewcvs/koha/reserve/request.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.6.2.2&r2=1.6.2.3
Patches:
Index: C4/Reserves2.pm
===================================================================
RCS file: /sources/koha/koha/C4/Reserves2.pm,v
retrieving revision 1.46.2.1
retrieving revision 1.46.2.2
diff -u -b -r1.46.2.1 -r1.46.2.2
--- C4/Reserves2.pm 30 Aug 2006 16:38:51 -0000 1.46.2.1
+++ C4/Reserves2.pm 20 Sep 2006 15:47:49 -0000 1.46.2.2
@@ -3,8 +3,6 @@
package C4::Reserves2;
-# $Id: Reserves2.pm,v 1.46.2.1 2006/08/30 16:38:51 toins Exp $
-
# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
@@ -22,20 +20,21 @@
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
+# $Id: Reserves2.pm,v 1.46.2.2 2006/09/20 15:47:49 toins Exp $
+
use strict;
require Exporter;
-use DBI;
use C4::Context;
use C4::Biblio;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
my $library_name = C4::Context->preference("LibraryName");
# set the version for version checking
-$VERSION = 0.01;
+$VERSION = do { my @v = '$Revision: 1.46.2.2 $' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); };
=head1 NAME
-C4::Reserves2 - FIXME
+C4::Reserves2 - Koha functions for dealing with reservation.
=head1 SYNOPSIS
@@ -43,7 +42,7 @@
=head1 DESCRIPTION
-FIXME
+this modules provides somes functions to deal with reservations.
=head1 FUNCTIONS
@@ -56,48 +55,56 @@
@EXPORT = qw(
&FindReserves
&CheckReserves
- &CheckWaiting
+ &GetWaitingReserves
&CancelReserve
&CalcReserveFee
&FillReserve
&ReserveWaiting
&CreateReserve
- &updatereserves
&UpdateReserve
- &getreservetitle
- &Findgroupreserve
- &FastFindReserves
+ &GetReserveTitle
+ &GetReservations
&SetWaitingStatus
&GlobalCancel
&MinusPriority
&OtherReserves
- GetFirstReserveDateFromItem
- GetNumberReservesFromBorrower
- &fixpriority
+ &GetFirstReserveDateFromItem
+ &CountReservesFromBorrower
);
# make all your functions, whether exported or not;
+
=item GlobalCancel
+
+($messages,$nextreservinfo) = &GlobalCancel($itemnumber,$borrowernumber);
+
New op dev for the circulation based on item, global is a function to cancel reserv,check other reserves, and transfer document if it's necessary
+
=cut
+
#'
sub GlobalCancel {
my $messages;
my $nextreservinfo;
my ($itemnumber,$borrowernumber)=@_;
-# step 1 : cancel the reservation
+ #step 1 : cancel the reservation
my $CancelReserve = CancelReserve(0,$itemnumber,$borrowernumber);
-# step 2 launch the subroutine of the others reserves
+ #step 2 launch the subroutine of the others reserves
my ($messages,$nextreservinfo) = OtherReserves($itemnumber);
-return ($messages,$nextreservinfo);
+ return ($messages,$nextreservinfo);
}
=item OtherReserves
- New op dev: check queued list of this document and check if this document must be transfered
+
+($messages,$nextreservinfo)=$OtherReserves(itemnumber);
+
+Check queued list of this document and check if this document must be transfered
+
=cut
+
#'
sub OtherReserves {
my ($itemnumber)=@_;
@@ -105,18 +112,16 @@
my $nextreservinfo;
my ($restype,$checkreserves) = CheckReserves($itemnumber);
if ($checkreserves){
- my %env;
my $iteminfo = C4::Circulation::Circ2::getiteminformation($itemnumber);
if ($iteminfo->{'holdingbranch'} ne $checkreserves->{'branchcode'}){
$messages->{'transfert'} = $checkreserves->{'branchcode'};
-
-# minus priorities of others reservs
+ #minus priorities of others reservs
MinusPriority($itemnumber,$checkreserves->{'borrowernumber'},$iteminfo->{'biblionumber'});
-# launch the subroutine dotransfer
+ #launch the subroutine dotransfer
C4::Circulation::Circ2::dotransfer($itemnumber,$iteminfo->{'holdingbranch'},$checkreserves->{'branchcode'}),
}
-# step 2b : case of a reservation on the same branch, set the waiting status
+ #step 2b : case of a reservation on the same branch, set the waiting status
else{
$messages->{'waiting'} = 1;
MinusPriority($itemnumber,$checkreserves->{'borrowernumber'},$iteminfo->{'biblionumber'});
@@ -130,94 +135,141 @@
}
=item MinusPriority
- Reduce the values of queuded list
+
+&MinusPriority($itemnumber,$borrowernumber,$biblionumber)
+
+Reduce the values of queuded list
+
=cut
+
#'
sub MinusPriority{
my ($itemnumber,$borrowernumber,$biblionumber)=@_;
-# first step update the value of the first person on reserv
+ #first step update the value of the first person on reserv
my $dbh = C4::Context->dbh;
- my $sth_upd=$dbh->prepare("UPDATE reserves SET priority = 0 , itemnumber = ?
- WHERE cancellationdate is NULL
+ my $query = qq/
+ UPDATE reserves
+ SET priority = 0 , itemnumber = ?
+ WHERE cancellationdate IS NULL
AND borrowernumber=?
- AND biblionumber=?");
+ AND biblionumber=?
+ /;
+ my $sth_upd=$dbh->prepare($query);
$sth_upd->execute($itemnumber,$borrowernumber,$biblionumber);
$sth_upd->finish;
-# second step update all others reservs
- my $sth_oth=$dbh->prepare("SELECT priority,borrowernumber,biblionumber,reservedate FROM reserves WHERE priority !='0' AND cancellationdate is NULL");
- $sth_oth->execute();
+ # second step update all others reservs
+ $query = qq/
+ SELECT priority,borrowernumber,biblionumber,reservedate
+ FROM reserves
+ WHERE priority !='0'
+ AND cancellationdate IS NULL
+ /;
+ my $sth_oth=$dbh->prepare($query);
+ $sth_oth->execute;
while (my ($priority,$borrowernumber,$biblionumber,$reservedate)=$sth_oth->fetchrow_array){
$priority--;
- my $sth_upd_oth = $dbh->prepare("UPDATE reserves SET priority = ?
+ $query = qq/
+ UPDATE reserves
+ SET priority = ?
WHERE biblionumber = ?
AND borrowernumber = ?
- AND reservedate = ?");
+ AND reservedate = ?
+ /;
+ my $sth_upd_oth = $dbh->prepare($query);
$sth_upd_oth->execute($priority,$biblionumber,$borrowernumber,$reservedate);
$sth_upd_oth->finish;
}
$sth_oth->finish;
-
}
+=item SetWaitingStatus
+
+&SetWaitingStatus($itemnumber);
+
+we check if we have a reserves with itemnumber (New op system of reserves), if we found one, we update the status of the reservation when we have : 'priority' = 0, and we have an itemnumber
-=item GlobalCancel
- New op dev for the circulation based on item, global is a function to cancel reserv,check other reserves, and transfer document if it's necessary
=cut
-#'
-# New op dev :
-# we check if we have a reserves with itemnumber (New op system of reserves), if we found one, we update the status of the reservation when we have : 'priority' = 0, and we have an itemnumber
-sub SetWaitingStatus{
-# first : check if we have a reservation for this item .
+
+sub SetWaitingStatus {
+ #first : check if we have a reservation for this item .
my ($itemnumber)=@_;
my $dbh = C4::Context->dbh;
- my $sth_find=$dbh->prepare("SELECT priority,borrowernumber from reserves WHERE itemnumber=? and cancellationdate is NULL and found is NULL and priority='0'");
+ my $query = qq/
+ SELECT priority,borrowernumber
+ FROM reserves
+ WHERE itemnumber=?
+ AND cancellationdate IS NULL
+ AND found IS NULL AND priority='0'
+ /;
+ my $sth_find=$dbh->prepare($query);
$sth_find->execute($itemnumber);
my ($priority,$borrowernumber) = $sth_find->fetchrow_array;
$sth_find->finish;
- if (not $borrowernumber){
- return();
- }
- else{
-# step 2 : if we have a borrowernumber, we update the value found to 'W' for notify the borrower
- my $sth_set=$dbh->prepare("UPDATE reserves SET found='W',waitingdate = now() where borrowernumber=? AND itemnumber=? AND found is null");
+ return unless $borrowernumber;
+
+ # step 2 : if we have a borrowernumber, we update the value found to 'W' to notify the borrower
+ $query = qq/
+ UPDATE reserves
+ SET found='W',waitingdate = now()
+ WHERE borrowernumber=?
+ AND itemnumber=?
+ AND found IS NULL
+ /;
+ my $sth_set=$dbh->prepare($query);
$sth_set->execute($borrowernumber,$itemnumber);
$sth_set->finish;
- }
-
}
-sub FastFindReserves {
+=item GetReservations
+
+ at borrowerreserv=&GetReservations($itemnumber,$borrowernumber);
+
+this function get the list of reservation for an C<$itemnumber> or C<$borrowernumber>
+given on input arg. You should give $itemnumber OR $borrowernumber but not both.
+
+=cut
+
+sub GetReservations {
my ($itemnumber,$borrowernumber)=@_;
if ($itemnumber){
my $dbh = C4::Context->dbh;
- my $sth_res=$dbh->prepare("SELECT reservedate,borrowernumber from reserves WHERE itemnumber=? and cancellationdate is NULL AND (found != 'F' or found is null)");
+ my $query = qq/
+ SELECT reservedate,borrowernumber
+ FROM reserves
+ WHERE itemnumber=?
+ AND cancellationdate IS NULL
+ AND (found <> 'F' OR found IS NULL)
+ /;
+ my $sth_res=$dbh->prepare($query);
$sth_res->execute($itemnumber);
my ($reservedate,$borrowernumber)=$sth_res->fetchrow_array;
- $sth_res->finish;
return($reservedate,$borrowernumber);
}
if ($borrowernumber){
my $dbh = C4::Context->dbh;
- my $sth_find=$dbh->prepare("SELECT * from reserves WHERE borrowernumber=? and cancellationdate is NULL and (found != 'F' or found is null) order by reservedate");
+ my $query = qq/
+ SELECT *
+ FROM reserves
+ WHERE borrowernumber=?
+ AND cancellationdate IS NULL
+ AND (found != 'F' or found is null)
+ ORDER BY reservedate
+ /;
+
+ my $sth_find=$dbh->prepare($query);
$sth_find->execute($borrowernumber);
my @borrowerreserv;
- my $i=0;
while (my $data=$sth_find->fetchrow_hashref){
- $borrowerreserv[$i]=$data;
- $i++;
+ push @borrowerreserv,$data;
}
- $sth_find->finish;
- return (@borrowerreserv);
+ return @borrowerreserv;
}
-
}
-
-
=item FindReserves
- ($count, $results) = &FindReserves($biblionumber, $borrowernumber);
+ $results = &FindReserves($biblionumber, $borrowernumber);
Looks books up in the reserves. C<$biblionumber> is the biblionumber
of the book to look up. C<$borrowernumber> is the borrower number of a
@@ -236,12 +288,11 @@
C<&FindReserves> returns a two-element array:
-C<$count> is the number of elements in C<$results>.
-
C<$results> is a reference to an array of references of hashes. Each hash
has for keys a list of column from reserves table (see details in function).
=cut
+
#'
sub FindReserves {
my ($bib, $bor) = @_;
@@ -249,8 +300,8 @@
my @bind;
# Find the desired items in the reserves
- my $query = '
-SELECT branchcode,
+ my $query = qq/
+ SELECT branchcode,
timestamp AS rtimestamp,
priority,
biblionumber,
@@ -261,25 +312,25 @@
FROM reserves
WHERE cancellationdate IS NULL
AND (found <> \'F\' OR found IS NULL)
-';
+ /;
if ($bib ne '') {
$query.= '
AND biblionumber = ?
-';
+ ';
push @bind, $bib;
}
if ($bor ne '') {
$query.= '
AND borrowernumber = ?
-';
+ ';
push @bind, $bor;
}
$query.= '
ORDER BY priority
-';
+ ';
my $sth=$dbh->prepare($query);
$sth->execute(@bind);
my @results;
@@ -288,12 +339,12 @@
# FIXME - What is this if-statement doing? How do constraints work?
if ($data->{constrainttype} eq 'o') {
$query = '
-SELECT biblioitemnumber
+ SELECT biblioitemnumber
FROM reserveconstraints
WHERE biblionumber = ?
AND borrowernumber = ?
AND reservedate = ?
-';
+ ';
my $csth=$dbh->prepare($query);
$csth->execute(
$data->{biblionumber},
@@ -333,18 +384,28 @@
return($#results+1,\@results);
}
-sub GetNumberReservesFromBorrower {
+#-------------------------------------------------------------------------------------
+
+=item CountReservesFromBorrower
+
+$number = &CountReservesFromBorrower($borrowernumber);
+
+this function returns the number of reservation for a borrower given on input arg.
+
+=cut
+
+sub CountReservesFromBorrower {
my ($borrowernumber) = @_;
my $dbh = C4::Context->dbh;
my $query = '
-SELECT COUNT(*) AS counter
+ SELECT COUNT(*) AS counter
FROM reserves
WHERE borrowernumber = ?
AND cancellationdate IS NULL
AND (found != \'F\' OR found IS NULL)
-';
+ ';
my $sth = $dbh->prepare($query);
$sth->execute($borrowernumber);
my $row = $sth->fetchrow_hashref;
@@ -353,26 +414,37 @@
return $row->{counter};
}
+#-------------------------------------------------------------------------------------
+
+=item GetFirstReserveDateFromItem
+
+$date = GetFirstReserveDateFromItem($itemnumber)
+
+this function returns the first date a item has been reserved.
+
+=cut
+
sub GetFirstReserveDateFromItem {
my ($itemnumber) = @_;
my $dbh = C4::Context->dbh;
my $query = '
-SELECT reservedate
+ SELECT reservedate
FROM reserves
WHERE itemnumber = ?
AND cancellationdate IS NULL
AND (found != \'F\' OR found IS NULL)
-';
+ ';
my $sth = $dbh->prepare($query);
$sth->execute($itemnumber);
my $row = $sth->fetchrow_hashref;
- $sth->finish;
return $row->{reservedate};
}
+#-------------------------------------------------------------------------------------
+
=item CheckReserves
($status, $reserve) = &CheckReserves($itemnumber, $barcode);
@@ -403,38 +475,46 @@
table in the Koha database.
=cut
+
#'
sub CheckReserves {
my ($item, $barcode) = @_;
-# warn "In CheckReserves: itemnumber = $item";
+ # warn "In CheckReserves: itemnumber = $item";
my $dbh = C4::Context->dbh;
my $sth;
if ($item) {
my $qitem=$dbh->quote($item);
# Look up the item by itemnumber
- $sth=$dbh->prepare("SELECT items.biblionumber, items.biblioitemnumber, itemtypes.notforloan
+ my $query =qq/
+ SELECT items.biblionumber, items.biblioitemnumber, itemtypes.notforloan
FROM items, biblioitems, itemtypes
WHERE items.biblioitemnumber = biblioitems.biblioitemnumber
AND biblioitems.itemtype = itemtypes.itemtype
- AND itemnumber=$qitem");
+ AND itemnumber=$qitem
+ /;
+ $sth=$dbh->prepare($query);
} else {
my $qbc=$dbh->quote($barcode);
# Look up the item by barcode
- $sth=$dbh->prepare("SELECT items.biblionumber, items.biblioitemnumber, itemtypes.notforloan
+ my $query = qq(
+ SELECT items.biblionumber, items.biblioitemnumber, itemtypes.notforloan
FROM items, biblioitems, itemtypes
WHERE items.biblioitemnumber = biblioitems.biblioitemnumber
AND biblioitems.itemtype = itemtypes.itemtype
- AND barcode=$qbc");
+ AND barcode=$qbc
+ );
+ $sth=$dbh->prepare($query);
# FIXME - This function uses $item later on. Ought to set it here.
}
$sth->execute;
my ($biblio, $bibitem, $notforloan) = $sth->fetchrow_array;
$sth->finish;
-# if item is not for loan it cannot be reserved either.....
- return (0, 0) if ($notforloan);
-# get the reserves...
+ # if item is not for loan it cannot be reserved either.....
+ return (0,0) if $notforloan;
+ # get the reserves...
# Find this item in the reserves
- my ($count, @reserves) = Findgroupreserve($bibitem, $biblio);
+ my @reserves = Findgroupreserve($bibitem, $biblio);
+ my $count = scalar @reserves;
# $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.)
@@ -470,6 +550,8 @@
}
}
+#-------------------------------------------------------------------------------------
+
=item CancelReserve
&CancelReserve($biblionumber, $itemnumber, $borrowernumber);
@@ -487,19 +569,24 @@
priorities of the other people who are waiting on the book.
=cut
+
#'
sub CancelReserve {
my ($biblio, $item, $borr) = @_;
my $dbh = C4::Context->dbh;
- #warn "In CancelReserve";
+
if (($item and $borr) and (not $biblio)) {
# removing a waiting reserve record....
# update the database...
- my $sth = $dbh->prepare("update reserves set cancellationdate = now(),
+ my $query = qq/
+ UPDATE reserves
+ SET cancellationdate = now(),
found = Null,
priority = 0
- where itemnumber = ?
- and borrowernumber = ?");
+ WHERE itemnumber = ?
+ AND borrowernumber = ?
+ /;
+ my $sth = $dbh->prepare($query);
$sth->execute($item,$borr);
$sth->finish;
}
@@ -507,23 +594,29 @@
# removing a reserve record....
# get the prioritiy on this record....
my $priority;
- my $sth=$dbh->prepare("SELECT priority FROM reserves
+ my $query = qq/
+ SELECT priority FROM reserves
WHERE biblionumber = ?
AND borrowernumber = ?
- AND cancellationdate is NULL
- AND (found <> 'F' or found is NULL)");
+ AND cancellationdate IS NULL
+ AND (found <> 'F' OR found IS NULL)
+ /;
+ my $sth=$dbh->prepare($query);
$sth->execute($biblio,$borr);
($priority) = $sth->fetchrow_array;
$sth->finish;
-
- # update the database, removing the record...
- $sth = $dbh->prepare("update reserves set cancellationdate = now(),
+ $query = qq/
+ UPDATE reserves
+ SET cancellationdate = now(),
found = Null,
priority = 0
- where biblionumber = ?
- and borrowernumber = ?
- and cancellationdate is NULL
- and (found <> 'F' or found is NULL)");
+ WHERE biblionumber = ?
+ AND borrowernumber = ?
+ AND cancellationdate IS NULL
+ AND (found <> 'F' or found IS NULL)
+ /;
+ # update the database, removing the record...
+ $sth = $dbh->prepare($query);
$sth->execute($biblio,$borr);
$sth->finish;
# now fix the priority on the others....
@@ -531,6 +624,8 @@
}
}
+#-------------------------------------------------------------------------------------
+
=item FillReserve
&FillReserve($reserve);
@@ -542,21 +637,21 @@
whose keys are fields from the reserves table in the Koha database.
=cut
+
#'
sub FillReserve {
my ($res) = @_;
my $dbh = C4::Context->dbh;
# fill in a reserve record....
- # FIXME - Remove some of the redundancy here
- my $biblio = $res->{'biblionumber'}; my $qbiblio =$biblio;
+ my $qbiblio = $res->{'biblionumber'};
my $borr = $res->{'borrowernumber'};
my $resdate = $res->{'reservedate'};
# get the priority on this record....
my $priority;
- {
- my $query = "SELECT priority FROM reserves
+ my $query = "SELECT priority
+ FROM reserves
WHERE biblionumber = ?
AND borrowernumber = ?
AND reservedate = ?";
@@ -564,58 +659,73 @@
$sth->execute($qbiblio,$borr,$resdate);
($priority) = $sth->fetchrow_array;
$sth->finish;
- }
# update the database...
- {
- my $query = "UPDATE reserves SET found = 'F',
+ my $query = "UPDATE reserves
+ SET found = 'F',
priority = 0
WHERE biblionumber = ?
AND reservedate = ?
- AND borrowernumber = ?";
+ AND borrowernumber = ?
+ ";
my $sth = $dbh->prepare($query);
$sth->execute($qbiblio,$resdate,$borr);
$sth->finish;
- }
# now fix the priority on the others (if the priority wasn't
# already sorted!)....
unless ($priority == 0) {
- fixpriority($priority, $biblio);
+ FixPriority($priority, $qbiblio);
}
}
-# Only used internally + reorder_reserve.pl
-# Changed how this functions works #
-# Now just gets an array of reserves in the rank order and updates them with
-# the array index (+1 as array starts from 0)
-# and if $rank is supplied will splice item from the array and splice it back in again
-# in new priority rank
-sub fixpriority {
+#-------------------------------------------------------------------------------------
+
+=item FixPriority
+
+&FixPriority($biblio,$borrowernumber,$rank);
+
+ Only used internally (so don't export it)
+ Changed how this functions works #
+ Now just gets an array of reserves in the rank order and updates them with
+ the array index (+1 as array starts from 0)
+ and if $rank is supplied will splice item from the array and splice it back in again
+ in new priority rank
+
+=cut
+
+sub FixPriority {
my ($biblio,$borrowernumber,$rank) = @_;
my $dbh = C4::Context->dbh;
- warn "BIB: $biblio, BORR: $borrowernumber, RANK: $rank";
if($rank eq "del"){
- warn "Cancel";
CancelReserve($biblio,undef,$borrowernumber);
}
if($rank eq "W" || $rank eq "0"){
# make sure priority for waiting items is 0
- my $sth=$dbh->prepare("UPDATE reserves SET priority = 0
+ my $query = qq/
+ UPDATE reserves
+ SET priority = 0
WHERE biblionumber = ?
AND borrowernumber = ?
- AND cancellationdate is NULL
- AND found ='W'");
+ AND cancellationdate IS NULL
+ AND found ='W'
+ /;
+ my $sth=$dbh->prepare($query);
$sth->execute($biblio,$borrowernumber);
}
my @priority;
my @reservedates;
# get whats left
- my $sth=$dbh->prepare("SELECT borrowernumber, reservedate, constrainttype FROM reserves
+ my $query = qq/
+ SELECT borrowernumber, reservedate, constrainttype
+ FROM reserves
WHERE biblionumber = ?
- AND cancellationdate is NULL
- AND ((found <> 'F' and found <> 'W') or found is NULL) ORDER BY priority ASC");
+ AND cancellationdate IS NULL
+ AND ((found <> 'F' and found <> 'W') or found is NULL)
+ ORDER BY priority ASC
+ /;
+ my $sth=$dbh->prepare($query);
$sth->execute($biblio);
while(my $line = $sth->fetchrow_hashref){
push(@reservedates,$line);
@@ -630,7 +740,6 @@
last;
}
}
- warn "key: $key";
# if index exists in array then move it to new position
if($key>-1 && $rank ne 'del' && $rank > 0){
my $new_rank = $rank-1; # $new_rank is what you want the new index to be in the array
@@ -638,24 +747,36 @@
splice(@priority, $new_rank, 0, $moving_item);
}
# now fix the priority on those that are left....
- for(my $j=0;$j<@priority;$j++){
- # warn "update reserves set priority = ".($j+1)." where biblionumber = $biblio and borrowernumber = $priority[$j]->{'borrowernumber'} ";
- # warn "and reservedate =$priority[$j]->{'reservedate'}";
- my $sth = $dbh->prepare("UPDATE reserves SET priority = " . ($j+1 ) . "
+ my $query = qq/
+ UPDATE reserves
+ SET priority = ?
WHERE biblionumber = ?
AND borrowernumber = ?
- AND reservedate = ? and found is null");
- $sth->execute($biblio,$priority[$j]->{'borrowernumber'},$priority[$j]->{'reservedate'});
+ AND reservedate = ?
+ AND found IS NULL
+ /;
+ my $sth = $dbh->prepare($query);
+ for(my $j=0;$j<@priority;$j++){
+ $sth->execute($j+1,$biblio,$priority[$j]->{'borrowernumber'},$priority[$j]->{'reservedate'});
$sth->finish;
}
}
-# XXX - POD
+#-------------------------------------------------------------------------------------
+
+=item ReserveWaiting
+
+branchcode = &ReserveWaiting($item,$borr);
+this function set FOUND to 'W' for Waiting into the database.
+
+=cut
+
sub ReserveWaiting {
my ($item, $borr) = @_;
my $dbh = C4::Context->dbh;
-# get priority and biblionumber....
- my $sth = $dbh->prepare("SELECT reserves.priority as priority,
+ # get priority and biblionumber....
+ my $query = qq/
+ SELECT reserves.priority as priority,
reserves.biblionumber as biblionumber,
reserves.branchcode as branchcode,
reserves.timestamp as timestamp
@@ -663,67 +784,90 @@
WHERE reserves.biblionumber = items.biblionumber
AND items.itemnumber = ?
AND reserves.borrowernumber = ?
- AND reserves.cancellationdate is NULL
- AND (reserves.found <> 'F' or reserves.found is NULL)");
+ AND reserves.cancellationdate IS NULL
+ AND (reserves.found <> 'F' OR reserves.found IS NULL)
+ /;
+ my $sth = $dbh->prepare($query);
$sth->execute($item,$borr);
my $data = $sth->fetchrow_hashref;
$sth->finish;
my $biblio = $data->{'biblionumber'};
my $timestamp = $data->{'timestamp'};
-# update reserves record....
- $sth = $dbh->prepare("UPDATE reserves SET priority = 0, found = 'W', itemnumber = ?
+ # update reserves record....
+ $query = qq/
+ UPDATE reserves
+ SET priority = 0,
+ found = 'W',
+ itemnumber = ?
WHERE borrowernumber = ?
AND biblionumber = ?
- AND timestamp = ?");
+ AND timestamp = ?
+ /;
+ $sth = $dbh->prepare($query);
$sth->execute($item,$borr,$biblio,$timestamp);
$sth->finish;
-# now fix up the remaining priorities....
- fixpriority($data->{'priority'}, $biblio);
+ # now fix up the remaining priorities....
+ FixPriority($data->{'priority'}, $biblio);
my $branchcode = $data->{'branchcode'};
return $branchcode;
}
-# XXX - POD
-sub CheckWaiting {
+#-------------------------------------------------------------------------------------
+
+=item GetWaitingReserves
+
+\@itemswaiting=GetWaitingReserves($borr);
+
+this funtion fetch the list of waiting reserves from database.
+
+=cut
+
+sub GetWaitingReserves {
my ($borr)=@_;
my $dbh = C4::Context->dbh;
my @itemswaiting;
- my $sth = $dbh->prepare("SELECT * FROM reserves
+ my $query = qq/
+ SELECT *
+ FROM reserves
WHERE borrowernumber = ?
AND reserves.found = 'W'
- AND cancellationdate is NULL");
+ AND cancellationdate IS NULL
+ /;
+ my $sth = $dbh->prepare($query);
$sth->execute($borr);
while (my $data=$sth->fetchrow_hashref) {
push(@itemswaiting,$data);
}
$sth->finish;
- return (scalar(@itemswaiting),\@itemswaiting);
+ return \@itemswaiting;
}
+#-------------------------------------------------------------------------------------
+
=item Findgroupreserve
- ($count, @results) = &Findgroupreserve($biblioitemnumber, $biblionumber);
+ @results = &Findgroupreserve($biblioitemnumber, $biblionumber);
+****** FIXME ******
I don't know what this does, because I don't understand how reserve
constraints work. I think the idea is that you reserve a particular
biblio, and the constraint allows you to restrict it to a given
biblioitem (e.g., if you want to borrow the audio book edition of "The
Prophet", rather than the first available publication).
-C<&Findgroupreserve> returns a two-element array:
-
-C<$count> is the number of elements in C<@results>.
-
+C<&Findgroupreserve> returns :
C<@results> is an array of references-to-hash whose keys are mostly
fields from the reserves table of the Koha database, plus
C<biblioitemnumber>.
=cut
+
#'
sub Findgroupreserve {
my ($bibitem,$biblio)=@_;
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("SELECT reserves.biblionumber AS biblionumber,
+ my $query = qq/
+ SELECT reserves.biblionumber AS biblionumber,
reserves.borrowernumber AS borrowernumber,
reserves.reservedate AS reservedate,
reserves.branchcode AS branchcode,
@@ -734,27 +878,36 @@
reserves.timestamp AS timestamp,
reserveconstraints.biblioitemnumber AS biblioitemnumber,
reserves.itemnumber AS itemnumber
- FROM reserves LEFT JOIN reserveconstraints
- ON reserves.biblionumber = reserveconstraints.biblionumber
+ FROM reserves
+ LEFT JOIN reserveconstraints ON reserves.biblionumber = reserveconstraints.biblionumber
WHERE reserves.biblionumber = ?
AND ( ( reserveconstraints.biblioitemnumber = ?
AND reserves.borrowernumber = reserveconstraints.borrowernumber
AND reserves.reservedate =reserveconstraints.reservedate )
OR reserves.constrainttype='a' )
AND reserves.cancellationdate is NULL
- AND (reserves.found <> 'F' or reserves.found is NULL)");
+ AND (reserves.found <> 'F' or reserves.found is NULL)
+ /;
+ my $sth=$dbh->prepare($query);
$sth->execute($biblio, $bibitem);
my @results;
while (my $data=$sth->fetchrow_hashref){
push(@results,$data);
}
$sth->finish;
- return(scalar(@results), at results);
+ return @results;
}
-# FIXME - A somewhat different version of this function appears in
-# C4::Reserves. Pick one and stick with it.
-# XXX - POD
+
+=item CreateReserve
+
+CreateReserve($env,$branch,$borrnum,$biblionumber,$constraint,$bibitems,$priority,$notes,$title,$checkitem,$found)
+
+FIXME - A somewhat different version of this function appears in
+C4::Reserves. Pick one and stick with it.
+
+=cut
+
sub CreateReserve {
my ($env,$branch,$borrnum,$biblionumber,$constraint,$bibitems,$priority,$notes,$title,$checkitem,$found)= @_;
my $fee;
@@ -775,19 +928,27 @@
#eval {
# updates take place here
if ($fee > 0) {
-# print $fee;
my $nextacctno = &getnextacctno($env,$borrnum,$dbh);
- my $usth = $dbh->prepare("insert into accountlines
+ my $query =qq/
+ INSERT INTO accountlines
(borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
- values
- (?,?,now(),?,?,'Res',?)");
+ VALUES
+ (?,?,now(),?,?,'Res',?)
+ /;
+ my $usth = $dbh->prepare($query);
$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,itemnumber,found,waitingdate)
- values (?,?,?,?,?,?,?,?,?,?)");
+ my $query = qq/
+ INSERT INTO reserves
+ (borrowernumber,biblionumber,reservedate,branchcode,constrainttype,
+ priority,reservenotes,itemnumber,found,waitingdate)
+ VALUES
+ (?,?,?,?,?,
+ ?,?,?,?,?)
+ /;
+ my $sth = $dbh->prepare($query);
$sth->execute($borrnum,$biblionumber,$resdate,$branch,$const,$priority,$notes,$checkitem,$found,$waitingdate);
$sth->finish;
#}
@@ -796,31 +957,37 @@
my $i = 0;
while ($i < $numitems) {
my $biblioitem = @$bibitems[$i];
- my $sth = $dbh->prepare("insert into
- reserveconstraints
+ my $query = qq/
+ INSERT INTO reserveconstraints
(borrowernumber,biblionumber,reservedate,biblioitemnumber)
- values (?,?,?,?)");
+ VALUES
+ (?,?,?,?)
+ /;
+ my $sth = $dbh->prepare("");
$sth->execute($borrnum,$biblionumber,$resdate,$biblioitem);
$sth->finish;
$i++;
}
}
-# print $query;
- return();
+ return;
}
# FIXME - A functionally identical version of this function appears in
# C4::Reserves. Pick one and stick with it.
# XXX - Internal use only
# FIXME - opac-reserves.pl need to use it, temporarily put into @EXPORT
+
sub CalcReserveFee {
my ($env,$borrnum,$biblionumber,$constraint,$bibitems) = @_;
#check for issues;
my $dbh = C4::Context->dbh;
my $const = lc substr($constraint,0,1);
- my $sth = $dbh->prepare("SELECT * FROM borrowers,categories
- WHERE (borrowernumber = ?)
- AND (borrowers.categorycode = categories.categorycode)");
+ my $query = qq/
+ SELECT * FROM borrowers,categories
+ WHERE borrowernumber = ?
+ AND borrowers.categorycode = categories.categorycode
+ /;
+ my $sth = $dbh->prepare($query);
$sth->execute($borrnum);
my $data = $sth->fetchrow_hashref;
$sth->finish();
@@ -934,10 +1101,12 @@
return $fee;
}
+=item GetNextAccountNumber
+GetNextAccountNumber()
-# XXX - Internal use
-sub getnextacctno {
+=cut
+sub GetNextAccountNumber {
my ($env,$bornumber,$dbh)=@_;
my $nextaccntno = 1;
my $sth = $dbh->prepare("select * from accountlines
@@ -951,42 +1120,14 @@
return($nextaccntno);
}
-# XXX - POD
-sub updatereserves{
- #subroutine to update a reserve
- my ($rank,$biblio,$borrower,$del,$branch)=@_;
- my $dbh = C4::Context->dbh;
- if ($del == 0){
- my $sth = $dbh->prepare("Update reserves set priority=?,branchcode=? where
- biblionumber=? and borrowernumber=?");
- $sth->execute($rank,$branch,$biblio,$borrower);
- $sth->finish();
- } else {
- my $sth=$dbh->prepare("Select * from reserves where biblionumber=? and
- borrowernumber=?");
- $sth->execute($biblio,$borrower);
- my $data=$sth->fetchrow_hashref;
- $sth->finish();
- $sth=$dbh->prepare("Select * from reserves where biblionumber=? and
- priority > ? and cancellationdate is NULL
- order by priority") || die $dbh->errstr;
- $sth->execute($biblio,$data->{'priority'}) || die $sth->errstr;
- while (my $data=$sth->fetchrow_hashref){
- $data->{'priority'}--;
- my $sth3=$dbh->prepare("Update reserves set priority=?
- where biblionumber=? and borrowernumber=?");
- $sth3->execute($data->{'priority'},$data->{'biblionumber'},$data->{'borrowernumber'}) || die $sth3->errstr;
- $sth3->finish();
- }
- $sth->finish();
- $sth=$dbh->prepare("update reserves set cancellationdate=now() where biblionumber=?
- and borrowernumber=?");
- $sth->execute($biblio,$borrower);
- $sth->finish;
- }
-}
+#-------------------------------------------------------------------------------------
+
+=item UpdateReserve
+
+&UpdateReserve($rank,$biblio,$borrower,$branch)
+
+=cut
-# XXX - POD
sub UpdateReserve {
#subroutine to update a reserve
my ($rank,$biblio,$borrower,$branch)=@_;
@@ -994,35 +1135,61 @@
return if $rank eq "n";
my $dbh = C4::Context->dbh;
if ($rank eq "del") {
- my $sth=$dbh->prepare("UPDATE reserves SET cancellationdate=now()
+ my $query = qq/
+ UPDATE reserves
+ SET cancellationdate=now()
WHERE biblionumber = ?
AND borrowernumber = ?
AND cancellationdate is NULL
- AND (found <> 'F' or found is NULL)");
+ AND (found <> 'F' or found is NULL)
+ /;
+ my $sth=$dbh->prepare($query);
$sth->execute($biblio, $borrower);
$sth->finish;
} else {
- my $sth=$dbh->prepare("UPDATE reserves SET priority = ? ,branchcode = ?, itemnumber = NULL, found = NULL
+ my $query = qq/
+ UPDATE reserves SET priority = ? ,branchcode = ?, itemnumber = NULL, found = NULL
WHERE biblionumber = ?
AND borrowernumber = ?
AND cancellationdate is NULL
- AND (found <> 'F' or found is NULL)");
+ AND (found <> 'F' or found is NULL)
+ /;
+ my $sth=$dbh->prepare($query);
$sth->execute($rank, $branch, $biblio, $borrower);
$sth->finish;
}
}
-# XXX - POD
-sub getreservetitle {
+=item GetReserveTitle
+
+$data = GetReserveTitle($biblio,$bor,$date,$timestamp);
+
+=cut
+
+sub GetReserveTitle {
my ($biblio,$bor,$date,$timestamp)=@_;
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("Select * from reserveconstraints,biblioitems where
- reserveconstraints.biblioitemnumber=biblioitems.biblioitemnumber
- and reserveconstraints.biblionumber=? and reserveconstraints.borrowernumber
- = ? and reserveconstraints.reservedate=? and
- reserveconstraints.timestamp=?");
+ my $query = qq/
+ SELECT *
+ FROM reserveconstraints,biblioitems
+ WHERE reserveconstraints.biblioitemnumber=biblioitems.biblioitemnumber
+ AND reserveconstraints.biblionumber=?
+ AND reserveconstraints.borrowernumber = ?
+ AND reserveconstraints.reservedate=?
+ AND reserveconstraints.timestamp=?
+ /;
+ my $sth=$dbh->prepare($query);
$sth->execute($biblio,$bor,$date,$timestamp);
my $data=$sth->fetchrow_hashref;
$sth->finish;
- return($data);
+ return $data;
}
+
+=back
+
+=head1 AUTHOR
+
+Koha Developement team <info at koha.org>
+
+=cut
+
Index: circ/circulation.pl
===================================================================
RCS file: /sources/koha/koha/circ/circulation.pl,v
retrieving revision 1.97.2.2
retrieving revision 1.97.2.3
diff -u -b -r1.97.2.2 -r1.97.2.3
--- circ/circulation.pl 13 Sep 2006 08:21:23 -0000 1.97.2.2
+++ circ/circulation.pl 20 Sep 2006 15:47:49 -0000 1.97.2.3
@@ -161,7 +161,8 @@
#borrowercard expired
$template->param( warndeparture => $warning );
}
- my ($reserved_num,$reserved_waiting) = CheckWaiting($borrowernumber);
+ my $reserved_waiting = GetWaitingReserves($borrowernumber);
+ my $reserved_num = scalar @$reserved_waiting;
if ($reserved_num > 0) {
for (my $i = 0; $i < $reserved_num; $i++) {
my ($count,$line) = getbiblio($reserved_waiting->[$i]->{'biblionumber'});
@@ -237,7 +238,7 @@
if ($borrowernumber) {
# new op dev
# now we show the status of the borrower's reservations
- my @borrowerreserv = FastFindReserves(0,$borrowernumber);
+ my @borrowerreserv = GetReservations(0,$borrowernumber);
my @reservloop;
foreach my $num_res (@borrowerreserv) {
my %getreserv;
Index: circ/currenttransfers.pl
===================================================================
RCS file: /sources/koha/koha/circ/currenttransfers.pl,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -u -b -r1.3 -r1.3.2.1
--- circ/currenttransfers.pl 21 Jul 2006 10:10:29 -0000 1.3
+++ circ/currenttransfers.pl 20 Sep 2006 15:47:49 -0000 1.3.2.1
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-# $Id: currenttransfers.pl,v 1.3 2006/07/21 10:10:29 toins Exp $
+# $Id: currenttransfers.pl,v 1.3.2.1 2006/09/20 15:47:49 toins Exp $
# Copyright 2000-2002 Katipo Communications
#
@@ -91,7 +91,7 @@
$getransf{'itemcallnumber'} = $gettitle->{'itemcallnumber'};
# we check if we have a reserv for this transfer
- my @checkreserv = FastFindReserves($num->{'itemnumber'});
+ my @checkreserv = GetReservations($num->{'itemnumber'});
if (@checkreserv[0]){
my $getborrower = getpatroninformation (\%env,$checkreserv[1]);
$getransf{'borrowernum'} = $getborrower->{'borrowernumber'};
Index: reserve/modrequest.pl
===================================================================
RCS file: /sources/koha/koha/reserve/modrequest.pl,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -b -r1.2 -r1.2.2.1
--- reserve/modrequest.pl 19 May 2006 17:05:11 -0000 1.2
+++ reserve/modrequest.pl 20 Sep 2006 15:47:49 -0000 1.2.2.1
@@ -23,7 +23,6 @@
# Suite 330, Boston, MA 02111-1307 USA
use strict;
-#use DBI;
use C4::Search;
use CGI;
use C4::Output;
Index: reserve/placerequest.pl
===================================================================
RCS file: /sources/koha/koha/reserve/placerequest.pl,v
retrieving revision 1.3.2.1
retrieving revision 1.3.2.2
diff -u -b -r1.3.2.1 -r1.3.2.2
--- reserve/placerequest.pl 30 Aug 2006 16:38:51 -0000 1.3.2.1
+++ reserve/placerequest.pl 20 Sep 2006 15:47:49 -0000 1.3.2.2
@@ -22,7 +22,6 @@
# Suite 330, Boston, MA 02111-1307 USA
use strict;
-#use DBI;
use C4::Search;
use C4::Biblio;
use CGI;
Index: reserve/request.pl
===================================================================
RCS file: /sources/koha/koha/reserve/request.pl,v
retrieving revision 1.6.2.2
retrieving revision 1.6.2.3
diff -u -b -r1.6.2.2 -r1.6.2.3
--- reserve/request.pl 31 Aug 2006 13:28:52 -0000 1.6.2.2
+++ reserve/request.pl 20 Sep 2006 15:47:49 -0000 1.6.2.3
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-# $Id: request.pl,v 1.6.2.2 2006/08/31 13:28:52 alaurin Exp $
+# $Id: request.pl,v 1.6.2.3 2006/09/20 15:47:49 toins Exp $
#script to place reserves/requests
#writen 2/1/00 by chris at katipo.oc.nz
@@ -101,7 +101,7 @@
# FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
my $number_reserves =
- GetNumberReservesFromBorrower($borrowerinfo->{'borrowernumber'});
+ CountReservesFromBorrower($borrowerinfo->{'borrowernumber'});
if ($number_reserves > C4::Context->preference('maxreserves')) {
$maxreserves = 1;
More information about the Koha-cvs
mailing list