2 # NOTE: This file uses standard 8-character tabs
6 # Copyright 2000-2002 Katipo Communications
7 # 2006 SAN Ouest Provence
8 # 2007 BibLibre Paul POULAIN
10 # This file is part of Koha.
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA 02111-1307 USA
35 our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,%EXPORT_TAGS);
37 my $library_name = C4::Context->preference("LibraryName");
39 # set the version for version checking
40 $VERSION = do { my @v = '$Revision$' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); };
44 C4::Reserves - Koha functions for dealing with reservation.
52 this modules provides somes functions to deal with reservations.
54 Reserves are stored in reserves table.
55 The following columns contains important values :
56 - priority >0 : then the reserve is at 1st stage, and not yet affected to any item.
57 =0 : then the reserve is being dealed
58 - found : NULL : means the patron requested the 1st available, and we haven't choosen the item
59 W(aiting) : the reserve has an itemnumber affected, and is on the way
60 F(inished) : the reserve has been completed, and is done
61 - itemnumber : empty : the reserve is still unaffected to an item
62 filled: the reserve is attached to an item
63 The complete workflow is :
64 ==== 1st use case ====
65 patron request a document, 1st available : P >0, F=NULL, I=NULL
66 a library having it run "transfertodo", and clic on the list
67 if there is no transfer to do, the reserve waiting
68 patron can pick it up P =0, F=W, I=filled
69 if there is a transfer to do, write in branchtransfer P =0, F=NULL, I=filled
70 The pickup library recieve the book, it check in P =0, F=W, I=filled
71 The patron borrow the book P =0, F=F, I=filled
73 ==== 2nd use case ====
74 patron requests a document, a given item,
75 If pickup is holding branch P =0, F=W, I=filled
76 If transfer needed, write in branchtransfer P =0, F=NULL, I=filled
77 The pickup library recieve the book, it checks it in P =0, F=W, I=filled
78 The patron borrow the book P =0, F=F, I=filled
91 &GetReservesFromItemnumber
92 &GetReservesFromBiblionumber
93 &GetReservesFromBorrowernumber
107 &ModReserveMinusPriority
116 AddReserve($branch,$borrowernumber,$biblionumber,$constraint,$bibitems,$priority,$notes,$title,$checkitem,$found)
122 $branch, $borrowernumber, $biblionumber,
123 $constraint, $bibitems, $priority, $notes,
124 $title, $checkitem, $found
127 GetReserveFee($borrowernumber, $biblionumber, $constraint,
129 my $dbh = C4::Context->dbh;
130 my $const = lc substr( $constraint, 0, 1 );
131 my @datearr = localtime(time);
133 ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
136 # If the reserv had the waiting status, we had the value of the resdate
137 if ( $found eq 'W' ) {
138 $waitingdate = $resdate;
142 # updates take place here
144 my $nextacctno = &getnextacctno( $borrowernumber );
146 INSERT INTO accountlines
147 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
149 (?,?,now(),?,?,'Res',?)
151 my $usth = $dbh->prepare($query);
152 $usth->execute( $borrowernumber, $nextacctno, $fee,
153 "Reserve Charge - $title", $fee );
160 (borrowernumber,biblionumber,reservedate,branchcode,constrainttype,
161 priority,reservenotes,itemnumber,found,waitingdate)
166 my $sth = $dbh->prepare($query);
168 $borrowernumber, $biblionumber, $resdate, $branch,
169 $const, $priority, $notes, $checkitem,
175 if ( ( $const eq "o" ) || ( $const eq "e" ) ) {
176 my $numitems = @$bibitems;
178 while ( $i < $numitems ) {
179 my $biblioitem = @$bibitems[$i];
181 INSERT INTO reserveconstraints
182 (borrowernumber,biblionumber,reservedate,biblioitemnumber)
186 my $sth = $dbh->prepare("");
187 $sth->execute( $borrowernumber, $biblionumber, $resdate,
196 =item GetReservesFromBiblionumber
198 @borrowerreserv=&GetReserves($biblionumber,$itemnumber,$borrowernumber);
200 this function get the list of reservation for an C<$biblionumber>, C<$itemnumber> or C<$borrowernumber>
202 Only 1 argument has to be passed.
206 sub GetReservesFromBiblionumber {
207 my ( $biblionumber, $itemnumber, $borrowernumber ) = @_;
208 my $dbh = C4::Context->dbh;
210 # Find the desired items in the reserves
213 timestamp AS rtimestamp,
222 WHERE cancellationdate IS NULL
223 AND (found <> \'F\' OR found IS NULL)
226 my $sth = $dbh->prepare($query);
227 $sth->execute($biblionumber);
230 while ( my $data = $sth->fetchrow_hashref ) {
232 # FIXME - What is this if-statement doing? How do constraints work?
233 if ( $data->{constrainttype} eq 'o' ) {
235 SELECT biblioitemnumber
236 FROM reserveconstraints
237 WHERE biblionumber = ?
238 AND borrowernumber = ?
241 my $csth = $dbh->prepare($query);
242 $csth->execute( $data->{biblionumber}, $data->{borrowernumber},
243 $data->{reservedate}, );
246 while ( my $bibitemnos = $csth->fetchrow_array ) {
247 push( @bibitemno, $bibitemnos );
249 my $count = @bibitemno;
251 # if we have two or more different specific itemtypes
252 # reserved by same person on same day
255 $bdata = GetBiblioItemData( $bibitemno[$i] );
260 # Look up the book we just found.
261 $bdata = GetBiblioItemData( $bibitemno[0] );
265 # Add the results of this latest search to the current
267 # FIXME - An 'each' would probably be more efficient.
268 foreach my $key ( keys %$bdata ) {
269 $data->{$key} = $bdata->{$key};
272 push @results, $data;
275 return ( $#results + 1, \@results );
278 =item GetReservesFromItemnumber
280 ( $reservedate, $borrowernumber, $branchcode ) = GetReservesFromItemnumber($itemnumber);
282 TODO :: Description here
286 sub GetReservesFromItemnumber {
287 my ( $itemnumber ) = @_;
288 my $dbh = C4::Context->dbh;
290 SELECT reservedate,borrowernumber,branchcode
293 AND cancellationdate IS NULL
294 AND (found <> 'F' OR found IS NULL)
296 my $sth_res = $dbh->prepare($query);
297 $sth_res->execute($itemnumber);
298 my ( $reservedate, $borrowernumber,$branchcode ) = $sth_res->fetchrow_array;
299 return ( $reservedate, $borrowernumber, $branchcode );
302 =item GetReservesFromBorrowernumber
304 $borrowerreserv = GetReservesFromBorrowernumber($borrowernumber,$tatus);
310 sub GetReservesFromBorrowernumber {
311 my ( $borrowernumber, $status ) = @_;
312 my $dbh = C4::Context->dbh;
315 $sth = $dbh->prepare("
318 WHERE borrowernumber=?
319 AND cancellationdate IS NULL
323 $sth->execute($borrowernumber,$status);
325 $sth = $dbh->prepare("
328 WHERE borrowernumber=?
329 AND cancellationdate IS NULL
330 AND (found != 'F' or found is null)
333 $sth->execute($borrowernumber);
335 my $data = $sth->fetchall_arrayref({});
338 #-------------------------------------------------------------------------------------
340 =item GetReserveCount
342 $number = &GetReserveCount($borrowernumber);
344 this function returns the number of reservation for a borrower given on input arg.
348 sub GetReserveCount {
349 my ($borrowernumber) = @_;
351 my $dbh = C4::Context->dbh;
354 SELECT COUNT(*) AS counter
356 WHERE borrowernumber = ?
357 AND cancellationdate IS NULL
358 AND (found != \'F\' OR found IS NULL)
360 my $sth = $dbh->prepare($query);
361 $sth->execute($borrowernumber);
362 my $row = $sth->fetchrow_hashref;
365 return $row->{counter};
368 =item GetOtherReserves
370 ($messages,$nextreservinfo)=$GetOtherReserves(itemnumber);
372 Check queued list of this document and check if this document must be transfered
376 sub GetOtherReserves {
377 my ($itemnumber) = @_;
380 my ( $restype, $checkreserves ) = CheckReserves($itemnumber);
381 if ($checkreserves) {
382 my $iteminfo = GetItem($itemnumber);
383 if ( $iteminfo->{'holdingbranch'} ne $checkreserves->{'branchcode'} ) {
384 $messages->{'transfert'} = $checkreserves->{'branchcode'};
385 #minus priorities of others reservs
386 ModReserveMinusPriority(
388 $checkreserves->{'borrowernumber'},
389 $iteminfo->{'biblionumber'}
392 #launch the subroutine dotransfer
393 C4::Circulation::ModItemTransfer(
395 $iteminfo->{'holdingbranch'},
396 $checkreserves->{'branchcode'}
401 #step 2b : case of a reservation on the same branch, set the waiting status
403 $messages->{'waiting'} = 1;
404 ModReserveMinusPriority(
406 $checkreserves->{'borrowernumber'},
407 $iteminfo->{'biblionumber'}
409 ModReserveStatus($itemnumber,'W');
412 $nextreservinfo = $checkreserves->{'borrowernumber'};
415 return ( $messages, $nextreservinfo );
420 $fee = GetReserveFee($borrowernumber,$biblionumber,$constraint,$biblionumber);
422 Calculate the fee for a reserve
427 my ($borrowernumber, $biblionumber, $constraint, $bibitems ) = @_;
430 my $dbh = C4::Context->dbh;
431 my $const = lc substr( $constraint, 0, 1 );
433 SELECT * FROM borrowers
434 LEFT JOIN categories ON borrowers.categorycode = categories.categorycode
435 WHERE borrowernumber = ?
437 my $sth = $dbh->prepare($query);
438 $sth->execute($borrowernumber);
439 my $data = $sth->fetchrow_hashref;
441 my $fee = $data->{'reservefee'};
442 my $cntitems = @- > $bibitems;
446 # check for items on issue
447 # first find biblioitem records
449 my $sth1 = $dbh->prepare(
450 "SELECT * FROM biblio LEFT JOIN biblioitems on biblio.biblionumber = biblioitems.biblionumber
451 WHERE (biblio.biblionumber = ?)"
453 $sth1->execute($biblionumber);
454 while ( my $data1 = $sth1->fetchrow_hashref ) {
455 if ( $const eq "a" ) {
456 push @biblioitems, $data1;
461 while ( $x < $cntitems ) {
462 if ( @$bibitems->{'biblioitemnumber'} ==
463 $data->{'biblioitemnumber'} )
469 if ( $const eq 'o' ) {
471 push @biblioitems, $data1;
476 push @biblioitems, $data1;
482 my $cntitemsfound = @biblioitems;
486 while ( $x < $cntitemsfound ) {
487 my $bitdata = $biblioitems[$x];
488 my $sth2 = $dbh->prepare(
490 WHERE biblioitemnumber = ?"
492 $sth2->execute( $bitdata->{'biblioitemnumber'} );
493 while ( my $itdata = $sth2->fetchrow_hashref ) {
494 my $sth3 = $dbh->prepare(
495 "SELECT * FROM issues
497 AND returndate IS NULL"
499 $sth3->execute( $itdata->{'itemnumber'} );
500 if ( my $isdata = $sth3->fetchrow_hashref ) {
508 if ( $allissued == 0 ) {
510 $dbh->prepare("SELECT * FROM reserves WHERE biblionumber = ?");
511 $rsth->execute($biblionumber);
512 if ( my $rdata = $rsth->fetchrow_hashref ) {
522 =item GetReservesToBranch
524 @transreserv = GetReservesToBranch( $frombranch );
526 Get reserve list for a given branch
530 sub GetReservesToBranch {
531 my ( $frombranch ) = @_;
532 my $dbh = C4::Context->dbh;
533 my $sth = $dbh->prepare(
534 "SELECT borrowernumber,reservedate,itemnumber,timestamp
536 WHERE priority='0' AND cancellationdate is null
540 $sth->execute( $frombranch );
543 while ( my $data = $sth->fetchrow_hashref ) {
544 $transreserv[$i] = $data;
548 return (@transreserv);
551 =item GetReservesForBranch
553 @transreserv = GetReservesForBranch($frombranch);
557 sub GetReservesForBranch {
558 my ($frombranch) = @_;
559 my $dbh = C4::Context->dbh;
560 my $sth = $dbh->prepare( "
561 SELECT borrowernumber,reservedate,itemnumber,waitingdate
564 AND cancellationdate IS NULL
567 ORDER BY waitingdate" );
568 $sth->execute($frombranch);
571 while ( my $data = $sth->fetchrow_hashref ) {
572 $transreserv[$i] = $data;
576 return (@transreserv);
581 ($status, $reserve) = &CheckReserves($itemnumber);
583 Find a book in the reserves.
585 C<$itemnumber> is the book's item number.
587 As I understand it, C<&CheckReserves> looks for the given item in the
588 reserves. If it is found, that's a match, and C<$status> is set to
591 Otherwise, it finds the most important item in the reserves with the
592 same biblio number as this book (I'm not clear on this) and returns it
593 with C<$status> set to C<Reserved>.
595 C<&CheckReserves> returns a two-element list:
597 C<$status> is either C<Waiting>, C<Reserved> (see above), or 0.
599 C<$reserve> is the reserve item that matched. It is a
600 reference-to-hash whose keys are mostly the fields of the reserves
601 table in the Koha database.
606 my ( $item, $barcode ) = @_;
607 my $dbh = C4::Context->dbh;
610 my $qitem = $dbh->quote($item);
611 # Look up the item by itemnumber
613 SELECT items.biblionumber, items.biblioitemnumber, itemtypes.notforloan
615 LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber
616 LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype
617 WHERE itemnumber=$qitem
619 $sth = $dbh->prepare($query);
622 my $qbc = $dbh->quote($barcode);
623 # Look up the item by barcode
625 SELECT items.biblionumber, items.biblioitemnumber, itemtypes.notforloan
627 LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber
628 LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype
629 WHERE items.biblioitemnumber = biblioitems.biblioitemnumber
630 AND biblioitems.itemtype = itemtypes.itemtype
633 $sth = $dbh->prepare($query);
635 # FIXME - This function uses $item later on. Ought to set it here.
638 my ( $biblio, $bibitem, $notforloan ) = $sth->fetchrow_array;
641 # if item is not for loan it cannot be reserved either.....
642 return ( 0, 0 ) if $notforloan;
644 # get the reserves...
645 # Find this item in the reserves
646 my @reserves = _Findgroupreserve( $bibitem, $biblio );
647 my $count = scalar @reserves;
649 # $priority and $highest are used to find the most important item
650 # in the list returned by &_Findgroupreserve. (The lower $priority,
651 # the more important the item.)
652 # $highest is the most important item we've seen so far.
653 my $priority = 10000000;
656 foreach my $res (@reserves) {
657 # FIXME - $item might be undefined or empty: the caller
658 # might be searching by barcode.
659 if ( $res->{'itemnumber'} == $item ) {
661 return ( "Waiting", $res );
664 # See if this item is more important than what we've got
666 if ( $res->{'priority'} != 0 && $res->{'priority'} < $priority )
668 $priority = $res->{'priority'};
675 # If we get this far, then no exact match was found. Print the
676 # most important item on the list. I think this tells us who's
677 # next in line to get this book.
678 if ($highest) { # FIXME - $highest might be undefined
679 $highest->{'itemnumber'} = $item;
680 return ( "Reserved", $highest );
689 &CancelReserve($biblionumber, $itemnumber, $borrowernumber);
693 Use either C<$biblionumber> or C<$itemnumber> to specify the item to
694 cancel, but not both: if both are given, C<&CancelReserve> does
697 C<$borrowernumber> is the borrower number of the patron on whose
698 behalf the book was reserved.
700 If C<$biblionumber> was given, C<&CancelReserve> also adjusts the
701 priorities of the other people who are waiting on the book.
706 my ( $biblio, $item, $borr ) = @_;
707 my $dbh = C4::Context->dbh;
708 if ( $item and $borr ) {
709 # removing a waiting reserve record....
710 # update the database...
713 SET cancellationdate = now(),
717 AND borrowernumber = ?
719 my $sth = $dbh->prepare($query);
720 $sth->execute( $item, $borr );
724 # removing a reserve record....
725 # get the prioritiy on this record....
728 SELECT priority FROM reserves
729 WHERE biblionumber = ?
730 AND borrowernumber = ?
731 AND cancellationdate IS NULL
732 AND itemnumber IS NULL
733 AND (found <> 'F' OR found IS NULL)
735 my $sth = $dbh->prepare($query);
736 $sth->execute( $biblio, $borr );
737 ($priority) = $sth->fetchrow_array;
741 SET cancellationdate = now(),
744 WHERE biblionumber = ?
745 AND borrowernumber = ?
746 AND cancellationdate IS NULL
747 AND (found <> 'F' or found IS NULL)
750 # update the database, removing the record...
751 $sth = $dbh->prepare($query);
752 $sth->execute( $biblio, $borr );
755 # now fix the priority on the others....
756 _FixPriority( $priority, $biblio );
762 &ModReserve($rank,$biblio,$borrower,$branch)
767 #subroutine to update a reserve
768 my ( $rank, $biblio, $borrower, $branch , $itemnumber) = @_;
769 return if $rank eq "W";
770 return if $rank eq "n";
771 my $dbh = C4::Context->dbh;
772 if ( $rank eq "del" ) {
775 SET cancellationdate=now()
776 WHERE biblionumber = ?
777 AND borrowernumber = ?
778 AND cancellationdate is NULL
779 AND (found <> 'F' or found is NULL)
781 my $sth = $dbh->prepare($query);
782 $sth->execute( $biblio, $borrower );
788 UPDATE reserves SET priority = ? ,branchcode = ?, itemnumber = ?, found = NULL
789 WHERE biblionumber = ?
790 AND borrowernumber = ?
791 AND cancellationdate is NULL
792 AND (found <> 'F' or found is NULL)
794 my $sth = $dbh->prepare($query);
795 $sth->execute( $rank, $branch,$itemnumber, $biblio, $borrower);
797 _FixPriority( $biblio, $borrower, $rank);
803 &ModReserveFill($reserve);
805 Fill a reserve. If I understand this correctly, this means that the
806 reserved book has been found and given to the patron who reserved it.
808 C<$reserve> specifies the reserve to fill. It is a reference-to-hash
809 whose keys are fields from the reserves table in the Koha database.
815 my $dbh = C4::Context->dbh;
816 # fill in a reserve record....
817 my $biblionumber = $res->{'biblionumber'};
818 my $borrowernumber = $res->{'borrowernumber'};
819 my $resdate = $res->{'reservedate'};
821 # get the priority on this record....
823 my $query = "SELECT priority
825 WHERE biblionumber = ?
826 AND borrowernumber = ?
827 AND reservedate = ?";
828 my $sth = $dbh->prepare($query);
829 $sth->execute( $biblionumber, $borrowernumber, $resdate );
830 ($priority) = $sth->fetchrow_array;
833 # update the database...
834 $query = "UPDATE reserves
837 WHERE biblionumber = ?
839 AND borrowernumber = ?
841 $sth = $dbh->prepare($query);
842 $sth->execute( $biblionumber, $resdate, $borrowernumber );
845 # now fix the priority on the others (if the priority wasn't
846 # already sorted!)....
847 unless ( $priority == 0 ) {
848 _FixPriority( $priority, $biblionumber );
852 =item ModReserveStatus
854 &ModReserveStatus($itemnumber, $newstatus);
856 Update the reserve status for the active (priority=0) reserve.
858 $itemnumber is the itemnumber the reserve is on
860 $newstatus is the new status.
864 sub ModReserveStatus {
866 #first : check if we have a reservation for this item .
867 my ($itemnumber, $newstatus) = @_;
868 my $dbh = C4::Context->dbh;
869 my $query = " UPDATE reserves
870 SET found=?,waitingdate = now()
875 my $sth_set = $dbh->prepare($query);
876 $sth_set->execute( $newstatus, $itemnumber );
880 =item ModReserveAffect
882 &ModReserveAffect($itemnumber,$borrowernumber,$diffBranchSend);
884 This function affect an item and a status for a given reserve
885 The itemnumber parameter is used to find the biblionumber.
886 with the biblionumber & the borrowernumber, we can affect the itemnumber
887 to the correct reserve.
889 if $transferToDo is not set, then the status is set to "Waiting" as well.
890 otherwise, a transfer is on the way, and the end of the transfer will
891 take care of the waiting status
894 sub ModReserveAffect {
895 my ( $itemnumber, $borrowernumber,$transferToDo ) = @_;
896 my $dbh = C4::Context->dbh;
898 # we want to attach $itemnumber to $borrowernumber, find the biblionumber
899 # attached to $itemnumber
900 my $sth = $dbh->prepare("SELECT biblionumber FROM items WHERE itemnumber=?");
901 $sth->execute($itemnumber);
902 my ($biblionumber) = $sth->fetchrow;
903 # If we affect a reserve that has to be transfered, don't set to Waiting
910 WHERE borrowernumber = ?
912 AND reserves.cancellationdate IS NULL
913 AND (reserves.found <> 'F' OR reserves.found IS NULL)
917 # affect the reserve to Waiting as well.
924 WHERE borrowernumber = ?
926 AND reserves.cancellationdate IS NULL
927 AND (reserves.found <> 'F' OR reserves.found IS NULL)
930 $sth = $dbh->prepare($query);
931 $sth->execute( $itemnumber, $borrowernumber,$biblionumber);
936 =item ModReserveCancelAll
938 ($messages,$nextreservinfo) = &ModReserveCancelAll($itemnumber,$borrowernumber);
940 function to cancel reserv,check other reserves, and transfer document if it's necessary
944 sub ModReserveCancelAll {
947 my ( $itemnumber, $borrowernumber ) = @_;
949 #step 1 : cancel the reservation
950 my $CancelReserve = CancelReserve( undef, $itemnumber, $borrowernumber );
952 #step 2 launch the subroutine of the others reserves
953 ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber);
955 return ( $messages, $nextreservinfo );
958 =item ModReserveMinusPriority
960 &ModReserveMinusPriority($itemnumber,$borrowernumber,$biblionumber)
962 Reduce the values of queuded list
966 sub ModReserveMinusPriority {
967 my ( $itemnumber, $borrowernumber, $biblionumber ) = @_;
969 #first step update the value of the first person on reserv
970 my $dbh = C4::Context->dbh;
973 SET priority = 0 , itemnumber = ?
974 WHERE cancellationdate IS NULL
978 my $sth_upd = $dbh->prepare($query);
979 $sth_upd->execute( $itemnumber, $borrowernumber, $biblionumber );
981 # second step update all others reservs
984 SET priority = priority-1
985 WHERE biblionumber = ?
987 AND cancellationdate IS NULL
989 $sth_upd = $dbh->prepare($query);
990 $sth_upd->execute( $biblionumber );
997 &_FixPriority($biblio,$borrowernumber,$rank);
999 Only used internally (so don't export it)
1000 Changed how this functions works #
1001 Now just gets an array of reserves in the rank order and updates them with
1002 the array index (+1 as array starts from 0)
1003 and if $rank is supplied will splice item from the array and splice it back in again
1004 in new priority rank
1009 my ( $biblio, $borrowernumber, $rank ) = @_;
1010 my $dbh = C4::Context->dbh;
1011 if ( $rank eq "del" ) {
1012 CancelReserve( $biblio, undef, $borrowernumber );
1014 if ( $rank eq "W" || $rank eq "0" ) {
1016 # make sure priority for waiting items is 0
1020 WHERE biblionumber = ?
1021 AND borrowernumber = ?
1022 AND cancellationdate IS NULL
1025 my $sth = $dbh->prepare($query);
1026 $sth->execute( $biblio, $borrowernumber );
1032 # FIXME adding a new security in returned elements for changing priority,
1033 # now, we don't care anymore any reservations with itemnumber linked (suppose a waiting reserve)
1035 SELECT borrowernumber, reservedate, constrainttype
1037 WHERE biblionumber = ?
1038 AND cancellationdate IS NULL
1039 AND itemnumber IS NULL
1040 AND ((found <> 'F' and found <> 'W') or found is NULL)
1041 ORDER BY priority ASC
1043 my $sth = $dbh->prepare($query);
1044 $sth->execute($biblio);
1045 while ( my $line = $sth->fetchrow_hashref ) {
1046 push( @reservedates, $line );
1047 push( @priority, $line );
1050 # To find the matching index
1052 my $key = -1; # to allow for 0 to be a valid result
1053 for ( $i = 0 ; $i < @priority ; $i++ ) {
1054 if ( $borrowernumber == $priority[$i]->{'borrowernumber'} ) {
1055 $key = $i; # save the index
1060 # if index exists in array then move it to new position
1061 if ( $key > -1 && $rank ne 'del' && $rank > 0 ) {
1062 my $new_rank = $rank -
1063 1; # $new_rank is what you want the new index to be in the array
1064 my $moving_item = splice( @priority, $key, 1 );
1065 splice( @priority, $new_rank, 0, $moving_item );
1068 # now fix the priority on those that are left....
1072 WHERE biblionumber = ?
1073 AND borrowernumber = ?
1077 $sth = $dbh->prepare($query);
1078 for ( my $j = 0 ; $j < @priority ; $j++ ) {
1081 $priority[$j]->{'borrowernumber'},
1082 $priority[$j]->{'reservedate'}
1088 =item _Findgroupreserve
1090 @results = &_Findgroupreserve($biblioitemnumber, $biblionumber);
1093 I don't know what this does, because I don't understand how reserve
1094 constraints work. I think the idea is that you reserve a particular
1095 biblio, and the constraint allows you to restrict it to a given
1096 biblioitem (e.g., if you want to borrow the audio book edition of "The
1097 Prophet", rather than the first available publication).
1099 C<&_Findgroupreserve> returns :
1100 C<@results> is an array of references-to-hash whose keys are mostly
1101 fields from the reserves table of the Koha database, plus
1102 C<biblioitemnumber>.
1106 sub _Findgroupreserve {
1107 my ( $bibitem, $biblio ) = @_;
1108 my $dbh = C4::Context->dbh;
1110 SELECT reserves.biblionumber AS biblionumber,
1111 reserves.borrowernumber AS borrowernumber,
1112 reserves.reservedate AS reservedate,
1113 reserves.branchcode AS branchcode,
1114 reserves.cancellationdate AS cancellationdate,
1115 reserves.found AS found,
1116 reserves.reservenotes AS reservenotes,
1117 reserves.priority AS priority,
1118 reserves.timestamp AS timestamp,
1119 reserveconstraints.biblioitemnumber AS biblioitemnumber,
1120 reserves.itemnumber AS itemnumber
1122 LEFT JOIN reserveconstraints ON reserves.biblionumber = reserveconstraints.biblionumber
1123 WHERE reserves.biblionumber = ?
1124 AND ( ( reserveconstraints.biblioitemnumber = ?
1125 AND reserves.borrowernumber = reserveconstraints.borrowernumber
1126 AND reserves.reservedate =reserveconstraints.reservedate )
1127 OR reserves.constrainttype='a' )
1128 AND reserves.cancellationdate is NULL
1129 AND (reserves.found <> 'F' or reserves.found is NULL)
1131 my $sth = $dbh->prepare($query);
1132 $sth->execute( $biblio, $bibitem );
1134 while ( my $data = $sth->fetchrow_hashref ) {
1135 push( @results, $data );
1145 Koha Developement team <info@koha.org>