2 # NOTE: This file uses standard 8-character tabs
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 USA
32 our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,%EXPORT_TAGS);
34 my $library_name = C4::Context->preference("LibraryName");
36 # set the version for version checking
37 $VERSION = do { my @v = '$Revision$' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); };
41 C4::Reserves - Koha functions for dealing with reservation.
49 this modules provides somes functions to deal with reservations.
62 &GetReservesFromItemnumber
63 &GetReservesFromBiblionumber
64 &GetReservesFromBorrowernumber
78 &ModReserveMinusPriority
87 AddReserve($branch,$borrowernumber,$biblionumber,$constraint,$bibitems,$priority,$notes,$title,$checkitem,$found)
93 $branch, $borrowernumber, $biblionumber,
94 $constraint, $bibitems, $priority, $notes,
95 $title, $checkitem, $found
98 GetReserveFee($borrowernumber, $biblionumber, $constraint,
100 my $dbh = C4::Context->dbh;
101 my $const = lc substr( $constraint, 0, 1 );
102 my @datearr = localtime(time);
104 ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
107 # If the reserv had the waiting status, we had the value of the resdate
108 if ( $found eq 'W' ) {
109 $waitingdate = $resdate;
113 # updates take place here
115 my $nextacctno = &getnextacctno( $borrowernumber );
117 INSERT INTO accountlines
118 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
120 (?,?,now(),?,?,'Res',?)
122 my $usth = $dbh->prepare($query);
123 $usth->execute( $borrowernumber, $nextacctno, $fee,
124 "Reserve Charge - $title", $fee );
131 (borrowernumber,biblionumber,reservedate,branchcode,constrainttype,
132 priority,reservenotes,itemnumber,found,waitingdate)
137 my $sth = $dbh->prepare($query);
139 $borrowernumber, $biblionumber, $resdate, $branch,
140 $const, $priority, $notes, $checkitem,
146 if ( ( $const eq "o" ) || ( $const eq "e" ) ) {
147 my $numitems = @$bibitems;
149 while ( $i < $numitems ) {
150 my $biblioitem = @$bibitems[$i];
152 INSERT INTO reserveconstraints
153 (borrowernumber,biblionumber,reservedate,biblioitemnumber)
157 my $sth = $dbh->prepare("");
158 $sth->execute( $borrowernumber, $biblionumber, $resdate,
167 =item GetReservesFromBiblionumber
169 @borrowerreserv=&GetReserves($biblionumber,$itemnumber,$borrowernumber);
171 this function get the list of reservation for an C<$biblionumber>, C<$itemnumber> or C<$borrowernumber>
173 Only 1 argument has to be passed.
177 sub GetReservesFromBiblionumber {
178 my ( $biblionumber, $itemnumber, $borrowernumber ) = @_;
179 my $dbh = C4::Context->dbh;
181 # Find the desired items in the reserves
184 timestamp AS rtimestamp,
193 WHERE cancellationdate IS NULL
194 AND (found <> \'F\' OR found IS NULL)
197 my $sth = $dbh->prepare($query);
198 $sth->execute($biblionumber);
201 while ( my $data = $sth->fetchrow_hashref ) {
203 # FIXME - What is this if-statement doing? How do constraints work?
204 if ( $data->{constrainttype} eq 'o' ) {
206 SELECT biblioitemnumber
207 FROM reserveconstraints
208 WHERE biblionumber = ?
209 AND borrowernumber = ?
212 my $csth = $dbh->prepare($query);
213 $csth->execute( $data->{biblionumber}, $data->{borrowernumber},
214 $data->{reservedate}, );
217 while ( my $bibitemnos = $csth->fetchrow_array ) {
218 push( @bibitemno, $bibitemnos );
220 my $count = @bibitemno;
222 # if we have two or more different specific itemtypes
223 # reserved by same person on same day
226 $bdata = GetBiblioItemData( $bibitemno[$i] );
231 # Look up the book we just found.
232 $bdata = GetBiblioItemData( $bibitemno[0] );
236 # Add the results of this latest search to the current
238 # FIXME - An 'each' would probably be more efficient.
239 foreach my $key ( keys %$bdata ) {
240 $data->{$key} = $bdata->{$key};
243 push @results, $data;
246 return ( $#results + 1, \@results );
249 =item GetReservesFromItemnumber
251 ( $reservedate, $borrowernumber, $branchcode ) = GetReservesFromItemnumber($itemnumber);
253 TODO :: Description here
257 sub GetReservesFromItemnumber {
258 my ( $itemnumber ) = @_;
259 my $dbh = C4::Context->dbh;
261 SELECT reservedate,borrowernumber,branchcode
264 AND cancellationdate IS NULL
265 AND (found <> 'F' OR found IS NULL)
267 my $sth_res = $dbh->prepare($query);
268 $sth_res->execute($itemnumber);
269 my ( $reservedate, $borrowernumber,$branchcode ) = $sth_res->fetchrow_array;
270 return ( $reservedate, $borrowernumber, $branchcode );
273 =item GetReservesFromBorrowernumber
275 $borrowerreserv = GetReservesFromBorrowernumber($borrowernumber,$tatus);
280 sub GetReservesFromBorrowernumber {
281 my ( $borrowernumber, $status ) = @_;
282 my $dbh = C4::Context->dbh;
285 $sth = $dbh->prepare("
288 WHERE borrowernumber=?
289 AND cancellationdate IS NULL
293 $sth->execute($borrowernumber,$status);
295 $sth = $dbh->prepare("
298 WHERE borrowernumber=?
299 AND cancellationdate IS NULL
300 AND (found != 'F' or found is null)
303 $sth->execute($borrowernumber);
305 my $data = $sth->fetchall_arrayref({});
308 #-------------------------------------------------------------------------------------
310 =item GetReserveCount
312 $number = &GetReserveCount($borrowernumber);
314 this function returns the number of reservation for a borrower given on input arg.
318 sub GetReserveCount {
319 my ($borrowernumber) = @_;
321 my $dbh = C4::Context->dbh;
324 SELECT COUNT(*) AS counter
326 WHERE borrowernumber = ?
327 AND cancellationdate IS NULL
328 AND (found != \'F\' OR found IS NULL)
330 my $sth = $dbh->prepare($query);
331 $sth->execute($borrowernumber);
332 my $row = $sth->fetchrow_hashref;
335 return $row->{counter};
338 =item GetOtherReserves
340 ($messages,$nextreservinfo)=$GetOtherReserves(itemnumber);
342 Check queued list of this document and check if this document must be transfered
346 sub GetOtherReserves {
347 my ($itemnumber) = @_;
350 my ( $restype, $checkreserves ) = CheckReserves($itemnumber);
351 if ($checkreserves) {
352 my $iteminfo = GetItem($itemnumber);
353 if ( $iteminfo->{'holdingbranch'} ne $checkreserves->{'branchcode'} ) {
354 $messages->{'transfert'} = $checkreserves->{'branchcode'};
355 #minus priorities of others reservs
356 ModReserveMinusPriority(
358 $checkreserves->{'borrowernumber'},
359 $iteminfo->{'biblionumber'}
362 #launch the subroutine dotransfer
363 C4::Circulation::ModItemTransfer(
365 $iteminfo->{'holdingbranch'},
366 $checkreserves->{'branchcode'}
371 #step 2b : case of a reservation on the same branch, set the waiting status
373 $messages->{'waiting'} = 1;
374 ModReserveMinusPriority(
376 $checkreserves->{'borrowernumber'},
377 $iteminfo->{'biblionumber'}
379 ModReserveStatus($itemnumber,'W');
382 $nextreservinfo = $checkreserves->{'borrowernumber'};
385 return ( $messages, $nextreservinfo );
390 $fee = GetReserveFee($borrowernumber,$biblionumber,$constraint,$biblionumber);
392 Calculate the fee for a reserve
397 my ($borrowernumber, $biblionumber, $constraint, $bibitems ) = @_;
400 my $dbh = C4::Context->dbh;
401 my $const = lc substr( $constraint, 0, 1 );
403 SELECT * FROM borrowers,categories
404 WHERE borrowernumber = ?
405 AND borrowers.categorycode = categories.categorycode
407 my $sth = $dbh->prepare($query);
408 $sth->execute($borrowernumber);
409 my $data = $sth->fetchrow_hashref;
411 my $fee = $data->{'reservefee'};
412 my $cntitems = @- > $bibitems;
416 # check for items on issue
417 # first find biblioitem records
419 my $sth1 = $dbh->prepare(
420 "SELECT * FROM biblio,biblioitems
421 WHERE (biblio.biblionumber = ?)
422 AND (biblio.biblionumber = biblioitems.biblionumber)"
424 $sth1->execute($biblionumber);
425 while ( my $data1 = $sth1->fetchrow_hashref ) {
426 if ( $const eq "a" ) {
427 push @biblioitems, $data1;
432 while ( $x < $cntitems ) {
433 if ( @$bibitems->{'biblioitemnumber'} ==
434 $data->{'biblioitemnumber'} )
440 if ( $const eq 'o' ) {
442 push @biblioitems, $data1;
447 push @biblioitems, $data1;
453 my $cntitemsfound = @biblioitems;
457 while ( $x < $cntitemsfound ) {
458 my $bitdata = $biblioitems[$x];
459 my $sth2 = $dbh->prepare(
461 WHERE biblioitemnumber = ?"
463 $sth2->execute( $bitdata->{'biblioitemnumber'} );
464 while ( my $itdata = $sth2->fetchrow_hashref ) {
465 my $sth3 = $dbh->prepare(
466 "SELECT * FROM issues
468 AND returndate IS NULL"
470 $sth3->execute( $itdata->{'itemnumber'} );
471 if ( my $isdata = $sth3->fetchrow_hashref ) {
479 if ( $allissued == 0 ) {
481 $dbh->prepare("SELECT * FROM reserves WHERE biblionumber = ?");
482 $rsth->execute($biblionumber);
483 if ( my $rdata = $rsth->fetchrow_hashref ) {
493 =item GetReservesToBranch
495 @transreserv = GetReservesToBranch( $frombranch );
497 Get reserve list for a given branch
501 sub GetReservesToBranch {
502 my ( $frombranch ) = @_;
503 my $dbh = C4::Context->dbh;
504 my $sth = $dbh->prepare(
505 "SELECT borrowernumber,reservedate,itemnumber,timestamp
507 WHERE priority='0' AND cancellationdate is null
511 $sth->execute( $frombranch );
514 while ( my $data = $sth->fetchrow_hashref ) {
515 $transreserv[$i] = $data;
519 return (@transreserv);
522 =item GetReservesForBranch
524 @transreserv = GetReservesForBranch($frombranch);
528 sub GetReservesForBranch {
529 my ($frombranch) = @_;
530 my $dbh = C4::Context->dbh;
531 my $sth = $dbh->prepare( "
532 SELECT borrowernumber,reservedate,itemnumber,waitingdate
535 AND cancellationdate IS NULL
538 ORDER BY waitingdate" );
539 $sth->execute($frombranch);
542 while ( my $data = $sth->fetchrow_hashref ) {
543 $transreserv[$i] = $data;
547 return (@transreserv);
552 ($status, $reserve) = &CheckReserves($itemnumber);
554 Find a book in the reserves.
556 C<$itemnumber> is the book's item number.
558 As I understand it, C<&CheckReserves> looks for the given item in the
559 reserves. If it is found, that's a match, and C<$status> is set to
562 Otherwise, it finds the most important item in the reserves with the
563 same biblio number as this book (I'm not clear on this) and returns it
564 with C<$status> set to C<Reserved>.
566 C<&CheckReserves> returns a two-element list:
568 C<$status> is either C<Waiting>, C<Reserved> (see above), or 0.
570 C<$reserve> is the reserve item that matched. It is a
571 reference-to-hash whose keys are mostly the fields of the reserves
572 table in the Koha database.
577 my ( $item, $barcode ) = @_;
578 my $dbh = C4::Context->dbh;
581 my $qitem = $dbh->quote($item);
582 # Look up the item by itemnumber
584 SELECT items.biblionumber, items.biblioitemnumber, itemtypes.notforloan
585 FROM items, biblioitems, itemtypes
586 WHERE items.biblioitemnumber = biblioitems.biblioitemnumber
587 AND biblioitems.itemtype = itemtypes.itemtype
588 AND itemnumber=$qitem
590 $sth = $dbh->prepare($query);
593 my $qbc = $dbh->quote($barcode);
594 # Look up the item by barcode
596 SELECT items.biblionumber, items.biblioitemnumber, itemtypes.notforloan
597 FROM items, biblioitems, itemtypes
598 WHERE items.biblioitemnumber = biblioitems.biblioitemnumber
599 AND biblioitems.itemtype = itemtypes.itemtype
602 $sth = $dbh->prepare($query);
604 # FIXME - This function uses $item later on. Ought to set it here.
607 my ( $biblio, $bibitem, $notforloan ) = $sth->fetchrow_array;
610 # if item is not for loan it cannot be reserved either.....
611 return ( 0, 0 ) if $notforloan;
613 # get the reserves...
614 # Find this item in the reserves
615 my @reserves = _Findgroupreserve( $bibitem, $biblio );
616 my $count = scalar @reserves;
618 # $priority and $highest are used to find the most important item
619 # in the list returned by &_Findgroupreserve. (The lower $priority,
620 # the more important the item.)
621 # $highest is the most important item we've seen so far.
622 my $priority = 10000000;
625 foreach my $res (@reserves) {
626 # FIXME - $item might be undefined or empty: the caller
627 # might be searching by barcode.
628 if ( $res->{'itemnumber'} == $item ) {
630 return ( "Waiting", $res );
633 # See if this item is more important than what we've got
635 if ( $res->{'priority'} != 0 && $res->{'priority'} < $priority )
637 $priority = $res->{'priority'};
644 # If we get this far, then no exact match was found. Print the
645 # most important item on the list. I think this tells us who's
646 # next in line to get this book.
647 if ($highest) { # FIXME - $highest might be undefined
648 $highest->{'itemnumber'} = $item;
649 return ( "Reserved", $highest );
658 &CancelReserve($biblionumber, $itemnumber, $borrowernumber);
662 Use either C<$biblionumber> or C<$itemnumber> to specify the item to
663 cancel, but not both: if both are given, C<&CancelReserve> does
666 C<$borrowernumber> is the borrower number of the patron on whose
667 behalf the book was reserved.
669 If C<$biblionumber> was given, C<&CancelReserve> also adjusts the
670 priorities of the other people who are waiting on the book.
675 my ( $biblio, $item, $borr ) = @_;
676 my $dbh = C4::Context->dbh;
677 if ( ( $item and $borr ) and ( not $biblio ) ) {
678 # removing a waiting reserve record....
679 # update the database...
682 SET cancellationdate = now(),
686 AND borrowernumber = ?
688 my $sth = $dbh->prepare($query);
689 $sth->execute( $item, $borr );
692 if ( ( $biblio and $borr ) and ( not $item ) ) {
693 # removing a reserve record....
694 # get the prioritiy on this record....
697 SELECT priority FROM reserves
698 WHERE biblionumber = ?
699 AND borrowernumber = ?
700 AND cancellationdate IS NULL
701 AND itemnumber IS NULL
702 AND (found <> 'F' OR found IS NULL)
704 my $sth = $dbh->prepare($query);
705 $sth->execute( $biblio, $borr );
706 ($priority) = $sth->fetchrow_array;
710 SET cancellationdate = now(),
713 WHERE biblionumber = ?
714 AND borrowernumber = ?
715 AND cancellationdate IS NULL
716 AND (found <> 'F' or found IS NULL)
719 # update the database, removing the record...
720 $sth = $dbh->prepare($query);
721 $sth->execute( $biblio, $borr );
724 # now fix the priority on the others....
725 _FixPriority( $priority, $biblio );
731 &ModReserve($rank,$biblio,$borrower,$branch)
736 #subroutine to update a reserve
737 my ( $rank, $biblio, $borrower, $branch , $itemnumber) = @_;
738 return if $rank eq "W";
739 return if $rank eq "n";
740 my $dbh = C4::Context->dbh;
741 if ( $rank eq "del" ) {
744 SET cancellationdate=now()
745 WHERE biblionumber = ?
746 AND borrowernumber = ?
747 AND cancellationdate is NULL
748 AND (found <> 'F' or found is NULL)
750 my $sth = $dbh->prepare($query);
751 $sth->execute( $biblio, $borrower );
757 UPDATE reserves SET priority = ? ,branchcode = ?, itemnumber = ?, found = NULL
758 WHERE biblionumber = ?
759 AND borrowernumber = ?
760 AND cancellationdate is NULL
761 AND (found <> 'F' or found is NULL)
763 my $sth = $dbh->prepare($query);
764 $sth->execute( $rank, $branch,$itemnumber, $biblio, $borrower);
766 _FixPriority( $biblio, $borrower, $rank);
772 &ModReserveFill($reserve);
774 Fill a reserve. If I understand this correctly, this means that the
775 reserved book has been found and given to the patron who reserved it.
777 C<$reserve> specifies the reserve to fill. It is a reference-to-hash
778 whose keys are fields from the reserves table in the Koha database.
784 my $dbh = C4::Context->dbh;
785 # fill in a reserve record....
786 my $biblionumber = $res->{'biblionumber'};
787 my $borrowernumber = $res->{'borrowernumber'};
788 my $resdate = $res->{'reservedate'};
790 # get the priority on this record....
792 my $query = "SELECT priority
794 WHERE biblionumber = ?
795 AND borrowernumber = ?
796 AND reservedate = ?";
797 my $sth = $dbh->prepare($query);
798 $sth->execute( $biblionumber, $borrowernumber, $resdate );
799 ($priority) = $sth->fetchrow_array;
802 # update the database...
803 $query = "UPDATE reserves
806 WHERE biblionumber = ?
808 AND borrowernumber = ?
810 $sth = $dbh->prepare($query);
811 $sth->execute( $biblionumber, $resdate, $borrowernumber );
814 # now fix the priority on the others (if the priority wasn't
815 # already sorted!)....
816 unless ( $priority == 0 ) {
817 _FixPriority( $priority, $biblionumber );
821 =item ModReserveStatus
823 &ModReserveStatus($itemnumber, $newstatus);
825 Update the reserve status for the active (priority=0) reserve.
827 $itemnumber is the itemnumber the reserve is on
829 $newstatus is the new status.
833 sub ModReserveStatus {
835 #first : check if we have a reservation for this item .
836 my ($itemnumber, $newstatus) = @_;
837 my $dbh = C4::Context->dbh;
838 my $query = " UPDATE reserves
839 SET found=?,waitingdate = now()
844 my $sth_set = $dbh->prepare($query);
845 $sth_set->execute( $newstatus, $itemnumber );
849 =item ModReserveAffect
851 &ModReserveAffect($itemnumber,$borrowernumber,$diffBranchSend);
853 This function affect an item and a status for a given reserve
854 The itemnumber parameter is used to find the biblionumber.
855 with the biblionumber & the borrowernumber, we can affect the itemnumber
856 to the correct reserve.
858 if $transferToDo is set, then the status is set to "Waiting" as well.
859 otherwise, a transfer is on the way, and the end of the transfer will
860 take care of the waiting status
863 sub ModReserveAffect {
864 my ( $itemnumber, $borrowernumber,$transferToDo ) = @_;
865 my $dbh = C4::Context->dbh;
867 # we want to attach $itemnumber to $borrowernumber, find the biblionumber
868 # attached to $itemnumber
869 my $sth = $dbh->prepare("SELECT biblionumber FROM items WHERE itemnumber=?");
870 $sth->execute($itemnumber);
871 my ($biblionumber) = $sth->fetchrow;
872 # If we affect a reserve that has to be transfered, don't set to Waiting
879 WHERE borrowernumber = ?
881 AND reserves.cancellationdate IS NULL
882 AND (reserves.found <> 'F' OR reserves.found IS NULL)
886 # affect the reserve to Waiting as well.
893 WHERE borrowernumber = ?
895 AND reserves.cancellationdate IS NULL
896 AND (reserves.found <> 'F' OR reserves.found IS NULL)
899 $sth = $dbh->prepare($query);
900 $sth->execute( $itemnumber, $borrowernumber,$biblionumber);
903 # now fix up the remaining priorities....
904 # _FixPriority( $data->{'priority'}, $biblio ); # can't work, 1st parameter should be $biblionumbern NOT priority. FIXME : remove this line if no problem seen once it is commented.
908 =item ModReserveCancelAll
910 ($messages,$nextreservinfo) = &ModReserveCancelAll($itemnumber,$borrowernumber);
912 function to cancel reserv,check other reserves, and transfer document if it's necessary
916 sub ModReserveCancelAll {
919 my ( $itemnumber, $borrowernumber ) = @_;
921 #step 1 : cancel the reservation
922 my $CancelReserve = CancelReserve( undef, $itemnumber, $borrowernumber );
924 #step 2 launch the subroutine of the others reserves
925 ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber);
927 return ( $messages, $nextreservinfo );
930 =item ModReserveMinusPriority
932 &ModReserveMinusPriority($itemnumber,$borrowernumber,$biblionumber)
934 Reduce the values of queuded list
938 sub ModReserveMinusPriority {
939 my ( $itemnumber, $borrowernumber, $biblionumber ) = @_;
941 #first step update the value of the first person on reserv
942 my $dbh = C4::Context->dbh;
945 SET priority = 0 , itemnumber = ?
946 WHERE cancellationdate IS NULL
950 my $sth_upd = $dbh->prepare($query);
951 $sth_upd->execute( $itemnumber, $borrowernumber, $biblionumber );
953 # second step update all others reservs
956 SET priority = priority-1
957 WHERE biblionumber = ?
959 AND cancellationdate IS NULL
961 $sth_upd = $dbh->prepare($query);
962 $sth_upd->execute( $biblionumber );
969 &_FixPriority($biblio,$borrowernumber,$rank);
971 Only used internally (so don't export it)
972 Changed how this functions works #
973 Now just gets an array of reserves in the rank order and updates them with
974 the array index (+1 as array starts from 0)
975 and if $rank is supplied will splice item from the array and splice it back in again
981 my ( $biblio, $borrowernumber, $rank ) = @_;
982 my $dbh = C4::Context->dbh;
983 if ( $rank eq "del" ) {
984 CancelReserve( $biblio, undef, $borrowernumber );
986 if ( $rank eq "W" || $rank eq "0" ) {
988 # make sure priority for waiting items is 0
992 WHERE biblionumber = ?
993 AND borrowernumber = ?
994 AND cancellationdate IS NULL
997 my $sth = $dbh->prepare($query);
998 $sth->execute( $biblio, $borrowernumber );
1004 # FIXME adding a new security in returned elements for changing priority,
1005 # now, we don't care anymore any reservations with itemnumber linked (suppose a waiting reserve)
1007 SELECT borrowernumber, reservedate, constrainttype
1009 WHERE biblionumber = ?
1010 AND cancellationdate IS NULL
1011 AND itemnumber IS NULL
1012 AND ((found <> 'F' and found <> 'W') or found is NULL)
1013 ORDER BY priority ASC
1015 my $sth = $dbh->prepare($query);
1016 $sth->execute($biblio);
1017 while ( my $line = $sth->fetchrow_hashref ) {
1018 push( @reservedates, $line );
1019 push( @priority, $line );
1022 # To find the matching index
1024 my $key = -1; # to allow for 0 to be a valid result
1025 for ( $i = 0 ; $i < @priority ; $i++ ) {
1026 if ( $borrowernumber == $priority[$i]->{'borrowernumber'} ) {
1027 $key = $i; # save the index
1032 # if index exists in array then move it to new position
1033 if ( $key > -1 && $rank ne 'del' && $rank > 0 ) {
1034 my $new_rank = $rank -
1035 1; # $new_rank is what you want the new index to be in the array
1036 my $moving_item = splice( @priority, $key, 1 );
1037 splice( @priority, $new_rank, 0, $moving_item );
1040 # now fix the priority on those that are left....
1044 WHERE biblionumber = ?
1045 AND borrowernumber = ?
1049 $sth = $dbh->prepare($query);
1050 for ( my $j = 0 ; $j < @priority ; $j++ ) {
1053 $priority[$j]->{'borrowernumber'},
1054 $priority[$j]->{'reservedate'}
1060 =item _Findgroupreserve
1062 @results = &_Findgroupreserve($biblioitemnumber, $biblionumber);
1065 I don't know what this does, because I don't understand how reserve
1066 constraints work. I think the idea is that you reserve a particular
1067 biblio, and the constraint allows you to restrict it to a given
1068 biblioitem (e.g., if you want to borrow the audio book edition of "The
1069 Prophet", rather than the first available publication).
1071 C<&_Findgroupreserve> returns :
1072 C<@results> is an array of references-to-hash whose keys are mostly
1073 fields from the reserves table of the Koha database, plus
1074 C<biblioitemnumber>.
1078 sub _Findgroupreserve {
1079 my ( $bibitem, $biblio ) = @_;
1080 my $dbh = C4::Context->dbh;
1082 SELECT reserves.biblionumber AS biblionumber,
1083 reserves.borrowernumber AS borrowernumber,
1084 reserves.reservedate AS reservedate,
1085 reserves.branchcode AS branchcode,
1086 reserves.cancellationdate AS cancellationdate,
1087 reserves.found AS found,
1088 reserves.reservenotes AS reservenotes,
1089 reserves.priority AS priority,
1090 reserves.timestamp AS timestamp,
1091 reserveconstraints.biblioitemnumber AS biblioitemnumber,
1092 reserves.itemnumber AS itemnumber
1094 LEFT JOIN reserveconstraints ON reserves.biblionumber = reserveconstraints.biblionumber
1095 WHERE reserves.biblionumber = ?
1096 AND ( ( reserveconstraints.biblioitemnumber = ?
1097 AND reserves.borrowernumber = reserveconstraints.borrowernumber
1098 AND reserves.reservedate =reserveconstraints.reservedate )
1099 OR reserves.constrainttype='a' )
1100 AND reserves.cancellationdate is NULL
1101 AND (reserves.found <> 'F' or reserves.found is NULL)
1103 my $sth = $dbh->prepare($query);
1104 $sth->execute( $biblio, $bibitem );
1106 while ( my $data = $sth->fetchrow_hashref ) {
1107 push( @results, $data );
1117 Koha Developement team <info@koha.org>