Bug 19116: Hold not set to waiting after transfer
[koha.git] / C4 / Reserves.pm
blobfbf03fbd86962d55bc5df5199146396eaef66c8b
1 package C4::Reserves;
3 # Copyright 2000-2002 Katipo Communications
4 # 2006 SAN Ouest Provence
5 # 2007-2010 BibLibre Paul POULAIN
6 # 2011 Catalyst IT
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 use strict;
25 #use warnings; FIXME - Bug 2505
26 use C4::Context;
27 use C4::Biblio;
28 use C4::Members;
29 use C4::Items;
30 use C4::Circulation;
31 use C4::Accounts;
33 # for _koha_notify_reserve
34 use C4::Members::Messaging;
35 use C4::Members qw();
36 use C4::Letters;
37 use C4::Log;
39 use Koha::Biblios;
40 use Koha::DateUtils;
41 use Koha::Calendar;
42 use Koha::Database;
43 use Koha::Hold;
44 use Koha::Old::Hold;
45 use Koha::Holds;
46 use Koha::Libraries;
47 use Koha::IssuingRules;
48 use Koha::Items;
49 use Koha::ItemTypes;
50 use Koha::Patrons;
52 use List::MoreUtils qw( firstidx any );
53 use Carp;
54 use Data::Dumper;
56 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
58 =head1 NAME
60 C4::Reserves - Koha functions for dealing with reservation.
62 =head1 SYNOPSIS
64 use C4::Reserves;
66 =head1 DESCRIPTION
68 This modules provides somes functions to deal with reservations.
70 Reserves are stored in reserves table.
71 The following columns contains important values :
72 - priority >0 : then the reserve is at 1st stage, and not yet affected to any item.
73 =0 : then the reserve is being dealed
74 - found : NULL : means the patron requested the 1st available, and we haven't chosen the item
75 T(ransit) : the reserve is linked to an item but is in transit to the pickup branch
76 W(aiting) : the reserve is linked to an item, is at the pickup branch, and is waiting on the hold shelf
77 F(inished) : the reserve has been completed, and is done
78 - itemnumber : empty : the reserve is still unaffected to an item
79 filled: the reserve is attached to an item
80 The complete workflow is :
81 ==== 1st use case ====
82 patron request a document, 1st available : P >0, F=NULL, I=NULL
83 a library having it run "transfertodo", and clic on the list
84 if there is no transfer to do, the reserve waiting
85 patron can pick it up P =0, F=W, I=filled
86 if there is a transfer to do, write in branchtransfer P =0, F=T, I=filled
87 The pickup library receive the book, it check in P =0, F=W, I=filled
88 The patron borrow the book P =0, F=F, I=filled
90 ==== 2nd use case ====
91 patron requests a document, a given item,
92 If pickup is holding branch P =0, F=W, I=filled
93 If transfer needed, write in branchtransfer P =0, F=T, I=filled
94 The pickup library receive the book, it checks it in P =0, F=W, I=filled
95 The patron borrow the book P =0, F=F, I=filled
97 =head1 FUNCTIONS
99 =cut
101 BEGIN {
102 require Exporter;
103 @ISA = qw(Exporter);
104 @EXPORT = qw(
105 &AddReserve
107 &GetReservesForBranch
108 &GetReserveStatus
110 &GetOtherReserves
112 &ModReserveFill
113 &ModReserveAffect
114 &ModReserve
115 &ModReserveStatus
116 &ModReserveCancelAll
117 &ModReserveMinusPriority
118 &MoveReserve
120 &CheckReserves
121 &CanBookBeReserved
122 &CanItemBeReserved
123 &CanReserveBeCanceledFromOpac
124 &CancelExpiredReserves
126 &AutoUnsuspendReserves
128 &IsAvailableForItemLevelRequest
130 &OPACItemHoldsAllowed
132 &AlterPriority
133 &ToggleLowestPriority
135 &ReserveSlip
136 &ToggleSuspend
137 &SuspendAll
139 &GetReservesControlBranch
141 IsItemOnHoldAndFound
143 GetMaxPatronHoldsForRecord
145 @EXPORT_OK = qw( MergeHolds );
148 =head2 AddReserve
150 AddReserve($branch,$borrowernumber,$biblionumber,$bibitems,$priority,$resdate,$expdate,$notes,$title,$checkitem,$found)
152 Adds reserve and generates HOLDPLACED message.
154 The following tables are available witin the HOLDPLACED message:
156 branches
157 borrowers
158 biblio
159 biblioitems
160 items
161 reserves
163 =cut
165 sub AddReserve {
166 my (
167 $branch, $borrowernumber, $biblionumber, $bibitems,
168 $priority, $resdate, $expdate, $notes,
169 $title, $checkitem, $found, $itemtype
170 ) = @_;
172 $resdate = output_pref( { str => dt_from_string( $resdate ), dateonly => 1, dateformat => 'iso' })
173 or output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' });
175 $expdate = output_pref({ str => $expdate, dateonly => 1, dateformat => 'iso' });
177 if ( C4::Context->preference('AllowHoldDateInFuture') ) {
179 # Make room in reserves for this before those of a later reserve date
180 $priority = _ShiftPriorityByDateAndPriority( $biblionumber, $resdate, $priority );
183 my $waitingdate;
185 # If the reserv had the waiting status, we had the value of the resdate
186 if ( $found eq 'W' ) {
187 $waitingdate = $resdate;
190 # Don't add itemtype limit if specific item is selected
191 $itemtype = undef if $checkitem;
193 # updates take place here
194 my $hold = Koha::Hold->new(
196 borrowernumber => $borrowernumber,
197 biblionumber => $biblionumber,
198 reservedate => $resdate,
199 branchcode => $branch,
200 priority => $priority,
201 reservenotes => $notes,
202 itemnumber => $checkitem,
203 found => $found,
204 waitingdate => $waitingdate,
205 expirationdate => $expdate,
206 itemtype => $itemtype,
208 )->store();
210 logaction( 'HOLDS', 'CREATE', $hold->id, Dumper($hold->unblessed) )
211 if C4::Context->preference('HoldsLog');
213 my $reserve_id = $hold->id();
215 # add a reserve fee if needed
216 if ( C4::Context->preference('HoldFeeMode') ne 'any_time_is_collected' ) {
217 my $reserve_fee = GetReserveFee( $borrowernumber, $biblionumber );
218 ChargeReserveFee( $borrowernumber, $reserve_fee, $title );
221 _FixPriority({ biblionumber => $biblionumber});
223 # Send e-mail to librarian if syspref is active
224 if(C4::Context->preference("emailLibrarianWhenHoldIsPlaced")){
225 my $patron = Koha::Patrons->find( $borrowernumber );
226 my $library = $patron->library;
227 if ( my $letter = C4::Letters::GetPreparedLetter (
228 module => 'reserves',
229 letter_code => 'HOLDPLACED',
230 branchcode => $branch,
231 lang => $patron->lang,
232 tables => {
233 'branches' => $library->unblessed,
234 'borrowers' => $patron->unblessed,
235 'biblio' => $biblionumber,
236 'biblioitems' => $biblionumber,
237 'items' => $checkitem,
238 'reserves' => $hold->unblessed,
240 ) ) {
242 my $admin_email_address = $library->branchemail || C4::Context->preference('KohaAdminEmailAddress');
244 C4::Letters::EnqueueLetter(
245 { letter => $letter,
246 borrowernumber => $borrowernumber,
247 message_transport_type => 'email',
248 from_address => $admin_email_address,
249 to_address => $admin_email_address,
255 return $reserve_id;
258 =head2 CanBookBeReserved
260 $canReserve = &CanBookBeReserved($borrowernumber, $biblionumber)
261 if ($canReserve eq 'OK') { #We can reserve this Item! }
263 See CanItemBeReserved() for possible return values.
265 =cut
267 sub CanBookBeReserved{
268 my ($borrowernumber, $biblionumber) = @_;
270 my $items = GetItemnumbersForBiblio($biblionumber);
271 #get items linked via host records
272 my @hostitems = get_hostitemnumbers_of($biblionumber);
273 if (@hostitems){
274 push (@$items,@hostitems);
277 my $canReserve;
278 foreach my $item (@$items) {
279 $canReserve = CanItemBeReserved( $borrowernumber, $item );
280 return 'OK' if $canReserve eq 'OK';
282 return $canReserve;
285 =head2 CanItemBeReserved
287 $canReserve = &CanItemBeReserved($borrowernumber, $itemnumber)
288 if ($canReserve eq 'OK') { #We can reserve this Item! }
290 @RETURNS OK, if the Item can be reserved.
291 ageRestricted, if the Item is age restricted for this borrower.
292 damaged, if the Item is damaged.
293 cannotReserveFromOtherBranches, if syspref 'canreservefromotherbranches' is OK.
294 tooManyReserves, if the borrower has exceeded his maximum reserve amount.
295 notReservable, if holds on this item are not allowed
297 =cut
299 sub CanItemBeReserved {
300 my ( $borrowernumber, $itemnumber ) = @_;
302 my $dbh = C4::Context->dbh;
303 my $ruleitemtype; # itemtype of the matching issuing rule
304 my $allowedreserves = 0; # Total number of holds allowed across all records
305 my $holds_per_record = 1; # Total number of holds allowed for this one given record
307 # we retrieve borrowers and items informations #
308 # item->{itype} will come for biblioitems if necessery
309 my $item = GetItem($itemnumber);
310 my $biblio = Koha::Biblios->find( $item->{biblionumber} );
311 my $patron = Koha::Patrons->find( $borrowernumber );
312 my $borrower = $patron->unblessed;
314 # If an item is damaged and we don't allow holds on damaged items, we can stop right here
315 return 'damaged'
316 if ( $item->{damaged}
317 && !C4::Context->preference('AllowHoldsOnDamagedItems') );
319 # Check for the age restriction
320 my ( $ageRestriction, $daysToAgeRestriction ) =
321 C4::Circulation::GetAgeRestriction( $biblio->biblioitem->agerestriction, $borrower );
322 return 'ageRestricted' if $daysToAgeRestriction && $daysToAgeRestriction > 0;
324 # Check that the patron doesn't have an item level hold on this item already
325 return 'itemAlreadyOnHold'
326 if Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->count();
328 my $controlbranch = C4::Context->preference('ReservesControlBranch');
330 my $querycount = q{
331 SELECT count(*) AS count
332 FROM reserves
333 LEFT JOIN items USING (itemnumber)
334 LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber)
335 LEFT JOIN borrowers USING (borrowernumber)
336 WHERE borrowernumber = ?
339 my $branchcode = "";
340 my $branchfield = "reserves.branchcode";
342 if ( $controlbranch eq "ItemHomeLibrary" ) {
343 $branchfield = "items.homebranch";
344 $branchcode = $item->{homebranch};
346 elsif ( $controlbranch eq "PatronLibrary" ) {
347 $branchfield = "borrowers.branchcode";
348 $branchcode = $borrower->{branchcode};
351 # we retrieve rights
352 if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->{'itype'}, $branchcode ) ) {
353 $ruleitemtype = $rights->{itemtype};
354 $allowedreserves = $rights->{reservesallowed};
355 $holds_per_record = $rights->{holds_per_record};
357 else {
358 $ruleitemtype = '*';
361 $item = Koha::Items->find( $itemnumber );
362 my $holds = Koha::Holds->search(
364 borrowernumber => $borrowernumber,
365 biblionumber => $item->biblionumber,
366 found => undef, # Found holds don't count against a patron's holds limit
369 if ( $holds->count() >= $holds_per_record ) {
370 return "tooManyHoldsForThisRecord";
373 # we retrieve count
375 $querycount .= "AND $branchfield = ?";
377 # If using item-level itypes, fall back to the record
378 # level itemtype if the hold has no associated item
379 $querycount .=
380 C4::Context->preference('item-level_itypes')
381 ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?"
382 : " AND biblioitems.itemtype = ?"
383 if ( $ruleitemtype ne "*" );
385 my $sthcount = $dbh->prepare($querycount);
387 if ( $ruleitemtype eq "*" ) {
388 $sthcount->execute( $borrowernumber, $branchcode );
390 else {
391 $sthcount->execute( $borrowernumber, $branchcode, $ruleitemtype );
394 my $reservecount = "0";
395 if ( my $rowcount = $sthcount->fetchrow_hashref() ) {
396 $reservecount = $rowcount->{count};
399 # we check if it's ok or not
400 if ( $reservecount >= $allowedreserves ) {
401 return 'tooManyReserves';
404 my $circ_control_branch =
405 C4::Circulation::_GetCircControlBranch( $item->unblessed(), $borrower );
406 my $branchitemrule =
407 C4::Circulation::GetBranchItemRule( $circ_control_branch, $item->itype );
409 if ( $branchitemrule->{holdallowed} == 0 ) {
410 return 'notReservable';
413 if ( $branchitemrule->{holdallowed} == 1
414 && $borrower->{branchcode} ne $item->homebranch )
416 return 'cannotReserveFromOtherBranches';
419 # If reservecount is ok, we check item branch if IndependentBranches is ON
420 # and canreservefromotherbranches is OFF
421 if ( C4::Context->preference('IndependentBranches')
422 and !C4::Context->preference('canreservefromotherbranches') )
424 my $itembranch = $item->homebranch;
425 if ( $itembranch ne $borrower->{branchcode} ) {
426 return 'cannotReserveFromOtherBranches';
430 return 'OK';
433 =head2 CanReserveBeCanceledFromOpac
435 $number = CanReserveBeCanceledFromOpac($reserve_id, $borrowernumber);
437 returns 1 if reserve can be cancelled by user from OPAC.
438 First check if reserve belongs to user, next checks if reserve is not in
439 transfer or waiting status
441 =cut
443 sub CanReserveBeCanceledFromOpac {
444 my ($reserve_id, $borrowernumber) = @_;
446 return unless $reserve_id and $borrowernumber;
447 my $reserve = Koha::Holds->find($reserve_id);
449 return 0 unless $reserve->borrowernumber == $borrowernumber;
450 return 0 if ( $reserve->found eq 'W' ) or ( $reserve->found eq 'T' );
452 return 1;
456 =head2 GetOtherReserves
458 ($messages,$nextreservinfo)=$GetOtherReserves(itemnumber);
460 Check queued list of this document and check if this document must be transferred
462 =cut
464 sub GetOtherReserves {
465 my ($itemnumber) = @_;
466 my $messages;
467 my $nextreservinfo;
468 my ( undef, $checkreserves, undef ) = CheckReserves($itemnumber);
469 if ($checkreserves) {
470 my $iteminfo = GetItem($itemnumber);
471 if ( $iteminfo->{'holdingbranch'} ne $checkreserves->{'branchcode'} ) {
472 $messages->{'transfert'} = $checkreserves->{'branchcode'};
473 #minus priorities of others reservs
474 ModReserveMinusPriority(
475 $itemnumber,
476 $checkreserves->{'reserve_id'},
479 #launch the subroutine dotransfer
480 C4::Items::ModItemTransfer(
481 $itemnumber,
482 $iteminfo->{'holdingbranch'},
483 $checkreserves->{'branchcode'}
488 #step 2b : case of a reservation on the same branch, set the waiting status
489 else {
490 $messages->{'waiting'} = 1;
491 ModReserveMinusPriority(
492 $itemnumber,
493 $checkreserves->{'reserve_id'},
495 ModReserveStatus($itemnumber,'W');
498 $nextreservinfo = $checkreserves->{'borrowernumber'};
501 return ( $messages, $nextreservinfo );
504 =head2 ChargeReserveFee
506 $fee = ChargeReserveFee( $borrowernumber, $fee, $title );
508 Charge the fee for a reserve (if $fee > 0)
510 =cut
512 sub ChargeReserveFee {
513 my ( $borrowernumber, $fee, $title ) = @_;
514 return if !$fee || $fee==0; # the last test is needed to include 0.00
515 my $accquery = qq{
516 INSERT INTO accountlines ( borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding ) VALUES (?, ?, NOW(), ?, ?, 'Res', ?)
518 my $dbh = C4::Context->dbh;
519 my $nextacctno = &getnextacctno( $borrowernumber );
520 $dbh->do( $accquery, undef, ( $borrowernumber, $nextacctno, $fee, "Reserve Charge - $title", $fee ) );
523 =head2 GetReserveFee
525 $fee = GetReserveFee( $borrowernumber, $biblionumber );
527 Calculate the fee for a reserve (if applicable).
529 =cut
531 sub GetReserveFee {
532 my ( $borrowernumber, $biblionumber ) = @_;
533 my $borquery = qq{
534 SELECT reservefee FROM borrowers LEFT JOIN categories ON borrowers.categorycode = categories.categorycode WHERE borrowernumber = ?
536 my $issue_qry = qq{
537 SELECT COUNT(*) FROM items
538 LEFT JOIN issues USING (itemnumber)
539 WHERE items.biblionumber=? AND issues.issue_id IS NULL
541 my $holds_qry = qq{
542 SELECT COUNT(*) FROM reserves WHERE biblionumber=? AND borrowernumber<>?
545 my $dbh = C4::Context->dbh;
546 my ( $fee ) = $dbh->selectrow_array( $borquery, undef, ($borrowernumber) );
547 my $hold_fee_mode = C4::Context->preference('HoldFeeMode') || 'not_always';
548 if( $fee and $fee > 0 and $hold_fee_mode eq 'not_always' ) {
549 # This is a reconstruction of the old code:
550 # Compare number of items with items issued, and optionally check holds
551 # If not all items are issued and there are no holds: charge no fee
552 # NOTE: Lost, damaged, not-for-loan, etc. are just ignored here
553 my ( $notissued, $reserved );
554 ( $notissued ) = $dbh->selectrow_array( $issue_qry, undef,
555 ( $biblionumber ) );
556 if( $notissued ) {
557 ( $reserved ) = $dbh->selectrow_array( $holds_qry, undef,
558 ( $biblionumber, $borrowernumber ) );
559 $fee = 0 if $reserved == 0;
562 return $fee;
565 =head2 GetReservesForBranch
567 @transreserv = GetReservesForBranch($frombranch);
569 =cut
571 sub GetReservesForBranch {
572 my ($frombranch) = @_;
573 my $dbh = C4::Context->dbh;
575 my $query = "
576 SELECT reserve_id,borrowernumber,reservedate,itemnumber,waitingdate, expirationdate
577 FROM reserves
578 WHERE priority='0'
579 AND found='W'
581 $query .= " AND branchcode=? " if ( $frombranch );
582 $query .= "ORDER BY waitingdate" ;
584 my $sth = $dbh->prepare($query);
585 if ($frombranch){
586 $sth->execute($frombranch);
587 } else {
588 $sth->execute();
591 my @transreserv;
592 my $i = 0;
593 while ( my $data = $sth->fetchrow_hashref ) {
594 $transreserv[$i] = $data;
595 $i++;
597 return (@transreserv);
600 =head2 GetReserveStatus
602 $reservestatus = GetReserveStatus($itemnumber);
604 Takes an itemnumber and returns the status of the reserve placed on it.
605 If several reserves exist, the reserve with the lower priority is given.
607 =cut
609 ## FIXME: I don't think this does what it thinks it does.
610 ## It only ever checks the first reserve result, even though
611 ## multiple reserves for that bib can have the itemnumber set
612 ## the sub is only used once in the codebase.
613 sub GetReserveStatus {
614 my ($itemnumber) = @_;
616 my $dbh = C4::Context->dbh;
618 my ($sth, $found, $priority);
619 if ( $itemnumber ) {
620 $sth = $dbh->prepare("SELECT found, priority FROM reserves WHERE itemnumber = ? order by priority LIMIT 1");
621 $sth->execute($itemnumber);
622 ($found, $priority) = $sth->fetchrow_array;
625 if(defined $found) {
626 return 'Waiting' if $found eq 'W' and $priority == 0;
627 return 'Finished' if $found eq 'F';
630 return 'Reserved' if $priority > 0;
632 return ''; # empty string here will remove need for checking undef, or less log lines
635 =head2 CheckReserves
637 ($status, $reserve, $all_reserves) = &CheckReserves($itemnumber);
638 ($status, $reserve, $all_reserves) = &CheckReserves(undef, $barcode);
639 ($status, $reserve, $all_reserves) = &CheckReserves($itemnumber,undef,$lookahead);
641 Find a book in the reserves.
643 C<$itemnumber> is the book's item number.
644 C<$lookahead> is the number of days to look in advance for future reserves.
646 As I understand it, C<&CheckReserves> looks for the given item in the
647 reserves. If it is found, that's a match, and C<$status> is set to
648 C<Waiting>.
650 Otherwise, it finds the most important item in the reserves with the
651 same biblio number as this book (I'm not clear on this) and returns it
652 with C<$status> set to C<Reserved>.
654 C<&CheckReserves> returns a two-element list:
656 C<$status> is either C<Waiting>, C<Reserved> (see above), or 0.
658 C<$reserve> is the reserve item that matched. It is a
659 reference-to-hash whose keys are mostly the fields of the reserves
660 table in the Koha database.
662 =cut
664 sub CheckReserves {
665 my ( $item, $barcode, $lookahead_days, $ignore_borrowers) = @_;
666 my $dbh = C4::Context->dbh;
667 my $sth;
668 my $select;
669 if (C4::Context->preference('item-level_itypes')){
670 $select = "
671 SELECT items.biblionumber,
672 items.biblioitemnumber,
673 itemtypes.notforloan,
674 items.notforloan AS itemnotforloan,
675 items.itemnumber,
676 items.damaged,
677 items.homebranch,
678 items.holdingbranch
679 FROM items
680 LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber
681 LEFT JOIN itemtypes ON items.itype = itemtypes.itemtype
684 else {
685 $select = "
686 SELECT items.biblionumber,
687 items.biblioitemnumber,
688 itemtypes.notforloan,
689 items.notforloan AS itemnotforloan,
690 items.itemnumber,
691 items.damaged,
692 items.homebranch,
693 items.holdingbranch
694 FROM items
695 LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber
696 LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype
700 if ($item) {
701 $sth = $dbh->prepare("$select WHERE itemnumber = ?");
702 $sth->execute($item);
704 else {
705 $sth = $dbh->prepare("$select WHERE barcode = ?");
706 $sth->execute($barcode);
708 # note: we get the itemnumber because we might have started w/ just the barcode. Now we know for sure we have it.
709 my ( $biblio, $bibitem, $notforloan_per_itemtype, $notforloan_per_item, $itemnumber, $damaged, $item_homebranch, $item_holdingbranch ) = $sth->fetchrow_array;
711 return if ( $damaged && !C4::Context->preference('AllowHoldsOnDamagedItems') );
713 return unless $itemnumber; # bail if we got nothing.
715 # if item is not for loan it cannot be reserved either.....
716 # except where items.notforloan < 0 : This indicates the item is holdable.
717 return if ( $notforloan_per_item > 0 ) or $notforloan_per_itemtype;
719 # Find this item in the reserves
720 my @reserves = _Findgroupreserve( $bibitem, $biblio, $itemnumber, $lookahead_days, $ignore_borrowers);
722 # $priority and $highest are used to find the most important item
723 # in the list returned by &_Findgroupreserve. (The lower $priority,
724 # the more important the item.)
725 # $highest is the most important item we've seen so far.
726 my $highest;
727 if (scalar @reserves) {
728 my $LocalHoldsPriority = C4::Context->preference('LocalHoldsPriority');
729 my $LocalHoldsPriorityPatronControl = C4::Context->preference('LocalHoldsPriorityPatronControl');
730 my $LocalHoldsPriorityItemControl = C4::Context->preference('LocalHoldsPriorityItemControl');
732 my $priority = 10000000;
733 foreach my $res (@reserves) {
734 if ( $res->{'itemnumber'} == $itemnumber && $res->{'priority'} == 0) {
735 if ($res->{'found'} eq 'W') {
736 return ( "Waiting", $res, \@reserves ); # Found it, it is waiting
737 } else {
738 return ( "Reserved", $res, \@reserves ); # Found determinated hold, e. g. the tranferred one
740 } else {
741 my $patron;
742 my $iteminfo;
743 my $local_hold_match;
745 if ($LocalHoldsPriority) {
746 $patron = Koha::Patrons->find( $res->{borrowernumber} );
747 $iteminfo = C4::Items::GetItem($itemnumber);
749 my $local_holds_priority_item_branchcode =
750 $iteminfo->{$LocalHoldsPriorityItemControl};
751 my $local_holds_priority_patron_branchcode =
752 ( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' )
753 ? $res->{branchcode}
754 : ( $LocalHoldsPriorityPatronControl eq 'HomeLibrary' )
755 ? $patron->branchcode
756 : undef;
757 $local_hold_match =
758 $local_holds_priority_item_branchcode eq
759 $local_holds_priority_patron_branchcode;
762 # See if this item is more important than what we've got so far
763 if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) {
764 $iteminfo ||= C4::Items::GetItem($itemnumber);
765 next if $res->{itemtype} && $res->{itemtype} ne _get_itype( $iteminfo );
766 $patron ||= Koha::Patrons->find( $res->{borrowernumber} );
767 my $branch = GetReservesControlBranch( $iteminfo, $patron->unblessed );
768 my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'});
769 next if ($branchitemrule->{'holdallowed'} == 0);
770 next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
771 next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $iteminfo->{ $branchitemrule->{hold_fulfillment_policy} }) );
772 $priority = $res->{'priority'};
773 $highest = $res;
774 last if $local_hold_match;
780 # If we get this far, then no exact match was found.
781 # We return the most important (i.e. next) reservation.
782 if ($highest) {
783 $highest->{'itemnumber'} = $item;
784 return ( "Reserved", $highest, \@reserves );
787 return ( '' );
790 =head2 CancelExpiredReserves
792 CancelExpiredReserves();
794 Cancels all reserves with an expiration date from before today.
796 =cut
798 sub CancelExpiredReserves {
800 my $today = dt_from_string();
801 my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays');
803 my $dbh = C4::Context->dbh;
805 my $dtf = Koha::Database->new->schema->storage->datetime_parser;
806 # FIXME To move to Koha::Holds->search_expired (?)
807 my $holds = Koha::Holds->search(
809 expirationdate => { '<', $dtf->format_date($today) }
813 while ( my $hold = $holds->next ) {
814 my $calendar = Koha::Calendar->new( branchcode => $hold->branchcode );
816 next if !$cancel_on_holidays && $calendar->is_holiday( $today );
818 my $cancel_params = {};
819 if ( $hold->found eq 'W' ) {
820 $cancel_params->{charge_cancel_fee} = 1;
822 $hold->cancel( $cancel_params );
827 =head2 AutoUnsuspendReserves
829 AutoUnsuspendReserves();
831 Unsuspends all suspended reserves with a suspend_until date from before today.
833 =cut
835 sub AutoUnsuspendReserves {
836 my $today = dt_from_string();
838 my @holds = Koha::Holds->search( { suspend_until => { '<' => $today->ymd() } } );
840 map { $_->suspend(0)->suspend_until(undef)->store() } @holds;
843 =head2 ModReserve
845 ModReserve({ rank => $rank,
846 reserve_id => $reserve_id,
847 branchcode => $branchcode
848 [, itemnumber => $itemnumber ]
849 [, biblionumber => $biblionumber, $borrowernumber => $borrowernumber ]
852 Change a hold request's priority or cancel it.
854 C<$rank> specifies the effect of the change. If C<$rank>
855 is 'W' or 'n', nothing happens. This corresponds to leaving a
856 request alone when changing its priority in the holds queue
857 for a bib.
859 If C<$rank> is 'del', the hold request is cancelled.
861 If C<$rank> is an integer greater than zero, the priority of
862 the request is set to that value. Since priority != 0 means
863 that the item is not waiting on the hold shelf, setting the
864 priority to a non-zero value also sets the request's found
865 status and waiting date to NULL.
867 The optional C<$itemnumber> parameter is used only when
868 C<$rank> is a non-zero integer; if supplied, the itemnumber
869 of the hold request is set accordingly; if omitted, the itemnumber
870 is cleared.
872 B<FIXME:> Note that the forgoing can have the effect of causing
873 item-level hold requests to turn into title-level requests. This
874 will be fixed once reserves has separate columns for requested
875 itemnumber and supplying itemnumber.
877 =cut
879 sub ModReserve {
880 my ( $params ) = @_;
882 my $rank = $params->{'rank'};
883 my $reserve_id = $params->{'reserve_id'};
884 my $branchcode = $params->{'branchcode'};
885 my $itemnumber = $params->{'itemnumber'};
886 my $suspend_until = $params->{'suspend_until'};
887 my $borrowernumber = $params->{'borrowernumber'};
888 my $biblionumber = $params->{'biblionumber'};
890 return if $rank eq "W";
891 return if $rank eq "n";
893 return unless ( $reserve_id || ( $borrowernumber && ( $biblionumber || $itemnumber ) ) );
895 my $hold;
896 unless ( $reserve_id ) {
897 $hold = Koha::Holds->search({ biblionumber => $biblionumber, borrowernumber => $borrowernumber, itemnumber => $itemnumber });
898 return unless $hold; # FIXME Should raise an exception
899 $reserve_id = $hold->reserve_id;
902 $hold ||= Koha::Holds->find($reserve_id);
904 if ( $rank eq "del" ) {
905 $hold->cancel;
907 elsif ($rank =~ /^\d+/ and $rank > 0) {
908 logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) )
909 if C4::Context->preference('HoldsLog');
911 $hold->set(
913 priority => $rank,
914 branchcode => $branchcode,
915 itemnumber => $itemnumber,
916 found => undef,
917 waitingdate => undef
919 )->store();
921 if ( defined( $suspend_until ) ) {
922 if ( $suspend_until ) {
923 $suspend_until = eval { dt_from_string( $suspend_until ) };
924 $hold->suspend_hold( $suspend_until );
925 } else {
926 # If the hold is suspended leave the hold suspended, but convert it to an indefinite hold.
927 # If the hold is not suspended, this does nothing.
928 $hold->set( { suspend_until => undef } )->store();
932 _FixPriority({ reserve_id => $reserve_id, rank =>$rank });
936 =head2 ModReserveFill
938 &ModReserveFill($reserve);
940 Fill a reserve. If I understand this correctly, this means that the
941 reserved book has been found and given to the patron who reserved it.
943 C<$reserve> specifies the reserve to fill. It is a reference-to-hash
944 whose keys are fields from the reserves table in the Koha database.
946 =cut
948 sub ModReserveFill {
949 my ($res) = @_;
950 my $reserve_id = $res->{'reserve_id'};
952 my $hold = Koha::Holds->find($reserve_id);
954 # get the priority on this record....
955 my $priority = $hold->priority;
957 # update the hold statuses, no need to store it though, we will be deleting it anyway
958 $hold->set(
960 found => 'F',
961 priority => 0,
965 # FIXME Must call Koha::Hold->cancel ? => No, should call ->filled and add the correct log
966 Koha::Old::Hold->new( $hold->unblessed() )->store();
968 $hold->delete();
970 if ( C4::Context->preference('HoldFeeMode') eq 'any_time_is_collected' ) {
971 my $reserve_fee = GetReserveFee( $hold->borrowernumber, $hold->biblionumber );
972 ChargeReserveFee( $hold->borrowernumber, $reserve_fee, $hold->biblio->title );
975 # now fix the priority on the others (if the priority wasn't
976 # already sorted!)....
977 unless ( $priority == 0 ) {
978 _FixPriority( { reserve_id => $reserve_id, biblionumber => $hold->biblionumber } );
982 =head2 ModReserveStatus
984 &ModReserveStatus($itemnumber, $newstatus);
986 Update the reserve status for the active (priority=0) reserve.
988 $itemnumber is the itemnumber the reserve is on
990 $newstatus is the new status.
992 =cut
994 sub ModReserveStatus {
996 #first : check if we have a reservation for this item .
997 my ($itemnumber, $newstatus) = @_;
998 my $dbh = C4::Context->dbh;
1000 my $query = "UPDATE reserves SET found = ?, waitingdate = NOW() WHERE itemnumber = ? AND found IS NULL AND priority = 0";
1001 my $sth_set = $dbh->prepare($query);
1002 $sth_set->execute( $newstatus, $itemnumber );
1004 if ( C4::Context->preference("ReturnToShelvingCart") && $newstatus ) {
1005 CartToShelf( $itemnumber );
1009 =head2 ModReserveAffect
1011 &ModReserveAffect($itemnumber,$borrowernumber,$diffBranchSend,$reserve_id);
1013 This function affect an item and a status for a given reserve, either fetched directly
1014 by record_id, or by borrowernumber and itemnumber or biblionumber. If only biblionumber
1015 is given, only first reserve returned is affected, which is ok for anything but
1016 multi-item holds.
1018 if $transferToDo is not set, then the status is set to "Waiting" as well.
1019 otherwise, a transfer is on the way, and the end of the transfer will
1020 take care of the waiting status
1022 =cut
1024 sub ModReserveAffect {
1025 my ( $itemnumber, $borrowernumber, $transferToDo, $reserve_id ) = @_;
1026 my $dbh = C4::Context->dbh;
1028 # we want to attach $itemnumber to $borrowernumber, find the biblionumber
1029 # attached to $itemnumber
1030 my $sth = $dbh->prepare("SELECT biblionumber FROM items WHERE itemnumber=?");
1031 $sth->execute($itemnumber);
1032 my ($biblionumber) = $sth->fetchrow;
1034 # get request - need to find out if item is already
1035 # waiting in order to not send duplicate hold filled notifications
1037 my $hold;
1038 # Find hold by id if we have it
1039 $hold = Koha::Holds->find( $reserve_id ) if $reserve_id;
1040 # Find item level hold for this item if there is one
1041 $hold ||= Koha::Holds->search( { borrowernumber => $borrowernumber, itemnumber => $itemnumber } )->next();
1042 # Find record level hold if there is no item level hold
1043 $hold ||= Koha::Holds->search( { borrowernumber => $borrowernumber, biblionumber => $biblionumber } )->next();
1045 return unless $hold;
1047 my $already_on_shelf = $hold->found && $hold->found eq 'W';
1049 $hold->itemnumber($itemnumber);
1050 $hold->set_waiting($transferToDo);
1052 _koha_notify_reserve( $hold->reserve_id )
1053 if ( !$transferToDo && !$already_on_shelf );
1055 _FixPriority( { biblionumber => $biblionumber } );
1057 if ( C4::Context->preference("ReturnToShelvingCart") ) {
1058 CartToShelf($itemnumber);
1061 return;
1064 =head2 ModReserveCancelAll
1066 ($messages,$nextreservinfo) = &ModReserveCancelAll($itemnumber,$borrowernumber);
1068 function to cancel reserv,check other reserves, and transfer document if it's necessary
1070 =cut
1072 sub ModReserveCancelAll {
1073 my $messages;
1074 my $nextreservinfo;
1075 my ( $itemnumber, $borrowernumber ) = @_;
1077 #step 1 : cancel the reservation
1078 my $holds = Koha::Holds->search({ itemnumber => $itemnumber, borrowernumber => $borrowernumber });
1079 return unless $holds->count;
1080 $holds->next->cancel;
1082 #step 2 launch the subroutine of the others reserves
1083 ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber);
1085 return ( $messages, $nextreservinfo );
1088 =head2 ModReserveMinusPriority
1090 &ModReserveMinusPriority($itemnumber,$borrowernumber,$biblionumber)
1092 Reduce the values of queued list
1094 =cut
1096 sub ModReserveMinusPriority {
1097 my ( $itemnumber, $reserve_id ) = @_;
1099 #first step update the value of the first person on reserv
1100 my $dbh = C4::Context->dbh;
1101 my $query = "
1102 UPDATE reserves
1103 SET priority = 0 , itemnumber = ?
1104 WHERE reserve_id = ?
1106 my $sth_upd = $dbh->prepare($query);
1107 $sth_upd->execute( $itemnumber, $reserve_id );
1108 # second step update all others reserves
1109 _FixPriority({ reserve_id => $reserve_id, rank => '0' });
1112 =head2 IsAvailableForItemLevelRequest
1114 my $is_available = IsAvailableForItemLevelRequest($item_record,$borrower_record);
1116 Checks whether a given item record is available for an
1117 item-level hold request. An item is available if
1119 * it is not lost AND
1120 * it is not damaged AND
1121 * it is not withdrawn AND
1122 * does not have a not for loan value > 0
1124 Need to check the issuingrules onshelfholds column,
1125 if this is set items on the shelf can be placed on hold
1127 Note that IsAvailableForItemLevelRequest() does not
1128 check if the staff operator is authorized to place
1129 a request on the item - in particular,
1130 this routine does not check IndependentBranches
1131 and canreservefromotherbranches.
1133 =cut
1135 sub IsAvailableForItemLevelRequest {
1136 my $item = shift;
1137 my $borrower = shift;
1139 my $dbh = C4::Context->dbh;
1140 # must check the notforloan setting of the itemtype
1141 # FIXME - a lot of places in the code do this
1142 # or something similar - need to be
1143 # consolidated
1144 my $itype = _get_itype($item);
1145 my $notforloan_per_itemtype
1146 = $dbh->selectrow_array("SELECT notforloan FROM itemtypes WHERE itemtype = ?",
1147 undef, $itype);
1149 return 0 if
1150 $notforloan_per_itemtype ||
1151 $item->{itemlost} ||
1152 $item->{notforloan} > 0 ||
1153 $item->{withdrawn} ||
1154 ($item->{damaged} && !C4::Context->preference('AllowHoldsOnDamagedItems'));
1156 my $on_shelf_holds = _OnShelfHoldsAllowed($itype,$borrower->{categorycode},$item->{holdingbranch});
1158 if ( $on_shelf_holds == 1 ) {
1159 return 1;
1160 } elsif ( $on_shelf_holds == 2 ) {
1161 my @items =
1162 Koha::Items->search( { biblionumber => $item->{biblionumber} } );
1164 my $any_available = 0;
1166 foreach my $i (@items) {
1167 $any_available = 1
1168 unless $i->itemlost
1169 || $i->notforloan > 0
1170 || $i->withdrawn
1171 || $i->onloan
1172 || IsItemOnHoldAndFound( $i->id )
1173 || ( $i->damaged
1174 && !C4::Context->preference('AllowHoldsOnDamagedItems') )
1175 || Koha::ItemTypes->find( $i->effective_itemtype() )->notforloan;
1178 return $any_available ? 0 : 1;
1181 return $item->{onloan} || GetReserveStatus($item->{itemnumber}) eq "Waiting";
1184 =head2 OnShelfHoldsAllowed
1186 OnShelfHoldsAllowed($itemtype,$borrowercategory,$branchcode);
1188 Checks issuingrules, using the borrowers categorycode, the itemtype, and branchcode to see if onshelf
1189 holds are allowed, returns true if so.
1191 =cut
1193 sub OnShelfHoldsAllowed {
1194 my ($item, $borrower) = @_;
1196 my $itype = _get_itype($item);
1197 return _OnShelfHoldsAllowed($itype,$borrower->{categorycode},$item->{holdingbranch});
1200 sub _get_itype {
1201 my $item = shift;
1203 my $itype;
1204 if (C4::Context->preference('item-level_itypes')) {
1205 # We can't trust GetItem to honour the syspref, so safest to do it ourselves
1206 # When GetItem is fixed, we can remove this
1207 $itype = $item->{itype};
1209 else {
1210 # XXX This is a bit dodgy. It relies on biblio itemtype column having different name.
1211 # So if we already have a biblioitems join when calling this function,
1212 # we don't need to access the database again
1213 $itype = $item->{itemtype};
1215 unless ($itype) {
1216 my $dbh = C4::Context->dbh;
1217 my $query = "SELECT itemtype FROM biblioitems WHERE biblioitemnumber = ? ";
1218 my $sth = $dbh->prepare($query);
1219 $sth->execute($item->{biblioitemnumber});
1220 if (my $data = $sth->fetchrow_hashref()){
1221 $itype = $data->{itemtype};
1224 return $itype;
1227 sub _OnShelfHoldsAllowed {
1228 my ($itype,$borrowercategory,$branchcode) = @_;
1230 my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrowercategory, itemtype => $itype, branchcode => $branchcode });
1231 return $issuing_rule ? $issuing_rule->onshelfholds : undef;
1234 =head2 AlterPriority
1236 AlterPriority( $where, $reserve_id );
1238 This function changes a reserve's priority up, down, to the top, or to the bottom.
1239 Input: $where is 'up', 'down', 'top' or 'bottom'. Biblionumber, Date reserve was placed
1241 =cut
1243 sub AlterPriority {
1244 my ( $where, $reserve_id ) = @_;
1246 my $hold = Koha::Holds->find( $reserve_id );
1247 return unless $hold;
1249 if ( $hold->cancellationdate ) {
1250 warn "I cannot alter the priority for reserve_id $reserve_id, the reserve has been cancelled (" . $hold->cancellationdate . ')';
1251 return;
1254 if ( $where eq 'up' || $where eq 'down' ) {
1256 my $priority = $hold->priority;
1257 $priority = $where eq 'up' ? $priority - 1 : $priority + 1;
1258 _FixPriority({ reserve_id => $reserve_id, rank => $priority })
1260 } elsif ( $where eq 'top' ) {
1262 _FixPriority({ reserve_id => $reserve_id, rank => '1' })
1264 } elsif ( $where eq 'bottom' ) {
1266 _FixPriority({ reserve_id => $reserve_id, rank => '999999' });
1269 # FIXME Should return the new priority
1272 =head2 ToggleLowestPriority
1274 ToggleLowestPriority( $borrowernumber, $biblionumber );
1276 This function sets the lowestPriority field to true if is false, and false if it is true.
1278 =cut
1280 sub ToggleLowestPriority {
1281 my ( $reserve_id ) = @_;
1283 my $dbh = C4::Context->dbh;
1285 my $sth = $dbh->prepare( "UPDATE reserves SET lowestPriority = NOT lowestPriority WHERE reserve_id = ?");
1286 $sth->execute( $reserve_id );
1288 _FixPriority({ reserve_id => $reserve_id, rank => '999999' });
1291 =head2 ToggleSuspend
1293 ToggleSuspend( $reserve_id );
1295 This function sets the suspend field to true if is false, and false if it is true.
1296 If the reserve is currently suspended with a suspend_until date, that date will
1297 be cleared when it is unsuspended.
1299 =cut
1301 sub ToggleSuspend {
1302 my ( $reserve_id, $suspend_until ) = @_;
1304 $suspend_until = dt_from_string($suspend_until) if ($suspend_until);
1306 my $hold = Koha::Holds->find( $reserve_id );
1308 if ( $hold->is_suspended ) {
1309 $hold->resume()
1310 } else {
1311 $hold->suspend_hold( $suspend_until );
1315 =head2 SuspendAll
1317 SuspendAll(
1318 borrowernumber => $borrowernumber,
1319 [ biblionumber => $biblionumber, ]
1320 [ suspend_until => $suspend_until, ]
1321 [ suspend => $suspend ]
1324 This function accepts a set of hash keys as its parameters.
1325 It requires either borrowernumber or biblionumber, or both.
1327 suspend_until is wholly optional.
1329 =cut
1331 sub SuspendAll {
1332 my %params = @_;
1334 my $borrowernumber = $params{'borrowernumber'} || undef;
1335 my $biblionumber = $params{'biblionumber'} || undef;
1336 my $suspend_until = $params{'suspend_until'} || undef;
1337 my $suspend = defined( $params{'suspend'} ) ? $params{'suspend'} : 1;
1339 $suspend_until = eval { dt_from_string($suspend_until) }
1340 if ( defined($suspend_until) );
1342 return unless ( $borrowernumber || $biblionumber );
1344 my $params;
1345 $params->{found} = undef;
1346 $params->{borrowernumber} = $borrowernumber if $borrowernumber;
1347 $params->{biblionumber} = $biblionumber if $biblionumber;
1349 my @holds = Koha::Holds->search($params);
1351 if ($suspend) {
1352 map { $_->suspend_hold($suspend_until) } @holds;
1354 else {
1355 map { $_->resume() } @holds;
1360 =head2 _FixPriority
1362 _FixPriority({
1363 reserve_id => $reserve_id,
1364 [rank => $rank,]
1365 [ignoreSetLowestRank => $ignoreSetLowestRank]
1370 _FixPriority({ biblionumber => $biblionumber});
1372 This routine adjusts the priority of a hold request and holds
1373 on the same bib.
1375 In the first form, where a reserve_id is passed, the priority of the
1376 hold is set to supplied rank, and other holds for that bib are adjusted
1377 accordingly. If the rank is "del", the hold is cancelled. If no rank
1378 is supplied, all of the holds on that bib have their priority adjusted
1379 as if the second form had been used.
1381 In the second form, where a biblionumber is passed, the holds on that
1382 bib (that are not captured) are sorted in order of increasing priority,
1383 then have reserves.priority set so that the first non-captured hold
1384 has its priority set to 1, the second non-captured hold has its priority
1385 set to 2, and so forth.
1387 In both cases, holds that have the lowestPriority flag on are have their
1388 priority adjusted to ensure that they remain at the end of the line.
1390 Note that the ignoreSetLowestRank parameter is meant to be used only
1391 when _FixPriority calls itself.
1393 =cut
1395 sub _FixPriority {
1396 my ( $params ) = @_;
1397 my $reserve_id = $params->{reserve_id};
1398 my $rank = $params->{rank} // '';
1399 my $ignoreSetLowestRank = $params->{ignoreSetLowestRank};
1400 my $biblionumber = $params->{biblionumber};
1402 my $dbh = C4::Context->dbh;
1404 my $hold;
1405 if ( $reserve_id ) {
1406 $hold = Koha::Holds->find( $reserve_id );
1407 return unless $hold;
1410 unless ( $biblionumber ) { # FIXME This is a very weird API
1411 $biblionumber = $hold->biblionumber;
1414 if ( $rank eq "del" ) { # FIXME will crash if called without $hold
1415 $hold->cancel;
1417 elsif ( $rank eq "W" || $rank eq "0" ) {
1419 # make sure priority for waiting or in-transit items is 0
1420 my $query = "
1421 UPDATE reserves
1422 SET priority = 0
1423 WHERE reserve_id = ?
1424 AND found IN ('W', 'T')
1426 my $sth = $dbh->prepare($query);
1427 $sth->execute( $reserve_id );
1429 my @priority;
1431 # get whats left
1432 my $query = "
1433 SELECT reserve_id, borrowernumber, reservedate
1434 FROM reserves
1435 WHERE biblionumber = ?
1436 AND ((found <> 'W' AND found <> 'T') OR found IS NULL)
1437 ORDER BY priority ASC
1439 my $sth = $dbh->prepare($query);
1440 $sth->execute( $biblionumber );
1441 while ( my $line = $sth->fetchrow_hashref ) {
1442 push( @priority, $line );
1445 # To find the matching index
1446 my $i;
1447 my $key = -1; # to allow for 0 to be a valid result
1448 for ( $i = 0 ; $i < @priority ; $i++ ) {
1449 if ( $reserve_id == $priority[$i]->{'reserve_id'} ) {
1450 $key = $i; # save the index
1451 last;
1455 # if index exists in array then move it to new position
1456 if ( $key > -1 && $rank ne 'del' && $rank > 0 ) {
1457 my $new_rank = $rank -
1458 1; # $new_rank is what you want the new index to be in the array
1459 my $moving_item = splice( @priority, $key, 1 );
1460 splice( @priority, $new_rank, 0, $moving_item );
1463 # now fix the priority on those that are left....
1464 $query = "
1465 UPDATE reserves
1466 SET priority = ?
1467 WHERE reserve_id = ?
1469 $sth = $dbh->prepare($query);
1470 for ( my $j = 0 ; $j < @priority ; $j++ ) {
1471 $sth->execute(
1472 $j + 1,
1473 $priority[$j]->{'reserve_id'}
1477 $sth = $dbh->prepare( "SELECT reserve_id FROM reserves WHERE lowestPriority = 1 ORDER BY priority" );
1478 $sth->execute();
1480 unless ( $ignoreSetLowestRank ) {
1481 while ( my $res = $sth->fetchrow_hashref() ) {
1482 _FixPriority({
1483 reserve_id => $res->{'reserve_id'},
1484 rank => '999999',
1485 ignoreSetLowestRank => 1
1491 =head2 _Findgroupreserve
1493 @results = &_Findgroupreserve($biblioitemnumber, $biblionumber, $itemnumber, $lookahead, $ignore_borrowers);
1495 Looks for a holds-queue based item-specific match first, then for a holds-queue title-level match, returning the
1496 first match found. If neither, then we look for non-holds-queue based holds.
1497 Lookahead is the number of days to look in advance.
1499 C<&_Findgroupreserve> returns :
1500 C<@results> is an array of references-to-hash whose keys are mostly
1501 fields from the reserves table of the Koha database, plus
1502 C<biblioitemnumber>.
1504 =cut
1506 sub _Findgroupreserve {
1507 my ( $bibitem, $biblio, $itemnumber, $lookahead, $ignore_borrowers) = @_;
1508 my $dbh = C4::Context->dbh;
1510 # TODO: consolidate at least the SELECT portion of the first 2 queries to a common $select var.
1511 # check for exact targeted match
1512 my $item_level_target_query = qq{
1513 SELECT reserves.biblionumber AS biblionumber,
1514 reserves.borrowernumber AS borrowernumber,
1515 reserves.reservedate AS reservedate,
1516 reserves.branchcode AS branchcode,
1517 reserves.cancellationdate AS cancellationdate,
1518 reserves.found AS found,
1519 reserves.reservenotes AS reservenotes,
1520 reserves.priority AS priority,
1521 reserves.timestamp AS timestamp,
1522 biblioitems.biblioitemnumber AS biblioitemnumber,
1523 reserves.itemnumber AS itemnumber,
1524 reserves.reserve_id AS reserve_id,
1525 reserves.itemtype AS itemtype
1526 FROM reserves
1527 JOIN biblioitems USING (biblionumber)
1528 JOIN hold_fill_targets USING (biblionumber, borrowernumber, itemnumber)
1529 WHERE found IS NULL
1530 AND priority > 0
1531 AND item_level_request = 1
1532 AND itemnumber = ?
1533 AND reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY)
1534 AND suspend = 0
1535 ORDER BY priority
1537 my $sth = $dbh->prepare($item_level_target_query);
1538 $sth->execute($itemnumber, $lookahead||0);
1539 my @results;
1540 if ( my $data = $sth->fetchrow_hashref ) {
1541 push( @results, $data )
1542 unless any{ $data->{borrowernumber} eq $_ } @$ignore_borrowers ;
1544 return @results if @results;
1546 # check for title-level targeted match
1547 my $title_level_target_query = qq{
1548 SELECT reserves.biblionumber AS biblionumber,
1549 reserves.borrowernumber AS borrowernumber,
1550 reserves.reservedate AS reservedate,
1551 reserves.branchcode AS branchcode,
1552 reserves.cancellationdate AS cancellationdate,
1553 reserves.found AS found,
1554 reserves.reservenotes AS reservenotes,
1555 reserves.priority AS priority,
1556 reserves.timestamp AS timestamp,
1557 biblioitems.biblioitemnumber AS biblioitemnumber,
1558 reserves.itemnumber AS itemnumber,
1559 reserves.reserve_id AS reserve_id,
1560 reserves.itemtype AS itemtype
1561 FROM reserves
1562 JOIN biblioitems USING (biblionumber)
1563 JOIN hold_fill_targets USING (biblionumber, borrowernumber)
1564 WHERE found IS NULL
1565 AND priority > 0
1566 AND item_level_request = 0
1567 AND hold_fill_targets.itemnumber = ?
1568 AND reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY)
1569 AND suspend = 0
1570 ORDER BY priority
1572 $sth = $dbh->prepare($title_level_target_query);
1573 $sth->execute($itemnumber, $lookahead||0);
1574 @results = ();
1575 if ( my $data = $sth->fetchrow_hashref ) {
1576 push( @results, $data )
1577 unless any{ $data->{borrowernumber} eq $_ } @$ignore_borrowers ;
1579 return @results if @results;
1581 my $query = qq{
1582 SELECT reserves.biblionumber AS biblionumber,
1583 reserves.borrowernumber AS borrowernumber,
1584 reserves.reservedate AS reservedate,
1585 reserves.waitingdate AS waitingdate,
1586 reserves.branchcode AS branchcode,
1587 reserves.cancellationdate AS cancellationdate,
1588 reserves.found AS found,
1589 reserves.reservenotes AS reservenotes,
1590 reserves.priority AS priority,
1591 reserves.timestamp AS timestamp,
1592 reserves.itemnumber AS itemnumber,
1593 reserves.reserve_id AS reserve_id,
1594 reserves.itemtype AS itemtype
1595 FROM reserves
1596 WHERE reserves.biblionumber = ?
1597 AND (reserves.itemnumber IS NULL OR reserves.itemnumber = ?)
1598 AND reserves.reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY)
1599 AND suspend = 0
1600 ORDER BY priority
1602 $sth = $dbh->prepare($query);
1603 $sth->execute( $biblio, $itemnumber, $lookahead||0);
1604 @results = ();
1605 while ( my $data = $sth->fetchrow_hashref ) {
1606 push( @results, $data )
1607 unless any{ $data->{borrowernumber} eq $_ } @$ignore_borrowers ;
1609 return @results;
1612 =head2 _koha_notify_reserve
1614 _koha_notify_reserve( $hold->reserve_id );
1616 Sends a notification to the patron that their hold has been filled (through
1617 ModReserveAffect, _not_ ModReserveFill)
1619 The letter code for this notice may be found using the following query:
1621 select distinct letter_code
1622 from message_transports
1623 inner join message_attributes using (message_attribute_id)
1624 where message_name = 'Hold_Filled'
1626 This will probably sipmly be 'HOLD', but because it is defined in the database,
1627 it is subject to addition or change.
1629 The following tables are availalbe witin the notice:
1631 branches
1632 borrowers
1633 biblio
1634 biblioitems
1635 reserves
1636 items
1638 =cut
1640 sub _koha_notify_reserve {
1641 my $reserve_id = shift;
1642 my $hold = Koha::Holds->find($reserve_id);
1643 my $borrowernumber = $hold->borrowernumber;
1645 my $patron = Koha::Patrons->find( $borrowernumber );
1647 # Try to get the borrower's email address
1648 my $to_address = C4::Members::GetNoticeEmailAddress($borrowernumber);
1650 my $messagingprefs = C4::Members::Messaging::GetMessagingPreferences( {
1651 borrowernumber => $borrowernumber,
1652 message_name => 'Hold_Filled'
1653 } );
1655 my $library = Koha::Libraries->find( $hold->branchcode )->unblessed;
1657 my $admin_email_address = $library->{branchemail} || C4::Context->preference('KohaAdminEmailAddress');
1659 my %letter_params = (
1660 module => 'reserves',
1661 branchcode => $hold->branchcode,
1662 lang => $patron->lang,
1663 tables => {
1664 'branches' => $library,
1665 'borrowers' => $patron->unblessed,
1666 'biblio' => $hold->biblionumber,
1667 'biblioitems' => $hold->biblionumber,
1668 'reserves' => $hold->unblessed,
1669 'items' => $hold->itemnumber,
1673 my $notification_sent = 0; #Keeping track if a Hold_filled message is sent. If no message can be sent, then default to a print message.
1674 my $send_notification = sub {
1675 my ( $mtt, $letter_code ) = (@_);
1676 return unless defined $letter_code;
1677 $letter_params{letter_code} = $letter_code;
1678 $letter_params{message_transport_type} = $mtt;
1679 my $letter = C4::Letters::GetPreparedLetter ( %letter_params );
1680 unless ($letter) {
1681 warn "Could not find a letter called '$letter_params{'letter_code'}' for $mtt in the 'reserves' module";
1682 return;
1685 C4::Letters::EnqueueLetter( {
1686 letter => $letter,
1687 borrowernumber => $borrowernumber,
1688 from_address => $admin_email_address,
1689 message_transport_type => $mtt,
1690 } );
1693 while ( my ( $mtt, $letter_code ) = each %{ $messagingprefs->{transports} } ) {
1694 next if (
1695 ( $mtt eq 'email' and not $to_address ) # No email address
1696 or ( $mtt eq 'sms' and not $patron->smsalertnumber ) # No SMS number
1697 or ( $mtt eq 'phone' and C4::Context->preference('TalkingTechItivaPhoneNotification') ) # Notice is handled by TalkingTech_itiva_outbound.pl
1700 &$send_notification($mtt, $letter_code);
1701 $notification_sent++;
1703 #Making sure that a print notification is sent if no other transport types can be utilized.
1704 if (! $notification_sent) {
1705 &$send_notification('print', 'HOLD');
1710 =head2 _ShiftPriorityByDateAndPriority
1712 $new_priority = _ShiftPriorityByDateAndPriority( $biblionumber, $reservedate, $priority );
1714 This increments the priority of all reserves after the one
1715 with either the lowest date after C<$reservedate>
1716 or the lowest priority after C<$priority>.
1718 It effectively makes room for a new reserve to be inserted with a certain
1719 priority, which is returned.
1721 This is most useful when the reservedate can be set by the user. It allows
1722 the new reserve to be placed before other reserves that have a later
1723 reservedate. Since priority also is set by the form in reserves/request.pl
1724 the sub accounts for that too.
1726 =cut
1728 sub _ShiftPriorityByDateAndPriority {
1729 my ( $biblio, $resdate, $new_priority ) = @_;
1731 my $dbh = C4::Context->dbh;
1732 my $query = "SELECT priority FROM reserves WHERE biblionumber = ? AND ( reservedate > ? OR priority > ? ) ORDER BY priority ASC LIMIT 1";
1733 my $sth = $dbh->prepare( $query );
1734 $sth->execute( $biblio, $resdate, $new_priority );
1735 my $min_priority = $sth->fetchrow;
1736 # if no such matches are found, $new_priority remains as original value
1737 $new_priority = $min_priority if ( $min_priority );
1739 # Shift the priority up by one; works in conjunction with the next SQL statement
1740 $query = "UPDATE reserves
1741 SET priority = priority+1
1742 WHERE biblionumber = ?
1743 AND borrowernumber = ?
1744 AND reservedate = ?
1745 AND found IS NULL";
1746 my $sth_update = $dbh->prepare( $query );
1748 # Select all reserves for the biblio with priority greater than $new_priority, and order greatest to least
1749 $query = "SELECT borrowernumber, reservedate FROM reserves WHERE priority >= ? AND biblionumber = ? ORDER BY priority DESC";
1750 $sth = $dbh->prepare( $query );
1751 $sth->execute( $new_priority, $biblio );
1752 while ( my $row = $sth->fetchrow_hashref ) {
1753 $sth_update->execute( $biblio, $row->{borrowernumber}, $row->{reservedate} );
1756 return $new_priority; # so the caller knows what priority they wind up receiving
1759 =head2 OPACItemHoldsAllowed
1761 OPACItemHoldsAllowed($item_record,$borrower_record);
1763 Checks issuingrules, using the borrowers categorycode, the itemtype, and branchcode to see
1764 if specific item holds are allowed, returns true if so.
1766 =cut
1768 sub OPACItemHoldsAllowed {
1769 my ($item,$borrower) = @_;
1771 my $branchcode = $item->{homebranch} or die "No homebranch";
1772 my $itype;
1773 my $dbh = C4::Context->dbh;
1774 if (C4::Context->preference('item-level_itypes')) {
1775 # We can't trust GetItem to honour the syspref, so safest to do it ourselves
1776 # When GetItem is fixed, we can remove this
1777 $itype = $item->{itype};
1779 else {
1780 my $query = "SELECT itemtype FROM biblioitems WHERE biblioitemnumber = ? ";
1781 my $sth = $dbh->prepare($query);
1782 $sth->execute($item->{biblioitemnumber});
1783 if (my $data = $sth->fetchrow_hashref()){
1784 $itype = $data->{itemtype};
1788 my $query = "SELECT opacitemholds,categorycode,itemtype,branchcode FROM issuingrules WHERE
1789 (issuingrules.categorycode = ? OR issuingrules.categorycode = '*')
1791 (issuingrules.itemtype = ? OR issuingrules.itemtype = '*')
1793 (issuingrules.branchcode = ? OR issuingrules.branchcode = '*')
1794 ORDER BY
1795 issuingrules.categorycode desc,
1796 issuingrules.itemtype desc,
1797 issuingrules.branchcode desc
1798 LIMIT 1";
1799 my $sth = $dbh->prepare($query);
1800 $sth->execute($borrower->{categorycode},$itype,$branchcode);
1801 my $data = $sth->fetchrow_hashref;
1802 my $opacitemholds = uc substr ($data->{opacitemholds}, 0, 1);
1803 return '' if $opacitemholds eq 'N';
1804 return $opacitemholds;
1807 =head2 MoveReserve
1809 MoveReserve( $itemnumber, $borrowernumber, $cancelreserve )
1811 Use when checking out an item to handle reserves
1812 If $cancelreserve boolean is set to true, it will remove existing reserve
1814 =cut
1816 sub MoveReserve {
1817 my ( $itemnumber, $borrowernumber, $cancelreserve ) = @_;
1819 my $lookahead = C4::Context->preference('ConfirmFutureHolds'); #number of days to look for future holds
1820 my ( $restype, $res, $all_reserves ) = CheckReserves( $itemnumber, undef, $lookahead );
1821 return unless $res;
1823 my $biblionumber = $res->{biblionumber};
1825 if ($res->{borrowernumber} == $borrowernumber) {
1826 ModReserveFill($res);
1828 else {
1829 # warn "Reserved";
1830 # The item is reserved by someone else.
1831 # Find this item in the reserves
1833 my $borr_res;
1834 foreach (@$all_reserves) {
1835 $_->{'borrowernumber'} == $borrowernumber or next;
1836 $_->{'biblionumber'} == $biblionumber or next;
1838 $borr_res = $_;
1839 last;
1842 if ( $borr_res ) {
1843 # The item is reserved by the current patron
1844 ModReserveFill($borr_res);
1847 if ( $cancelreserve eq 'revert' ) { ## Revert waiting reserve to priority 1
1848 RevertWaitingStatus({ itemnumber => $itemnumber });
1850 elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) { # cancel reserves on this item
1851 my $hold = Koha::Holds->find( $res->{reserve_id} );
1852 $hold->cancel;
1857 =head2 MergeHolds
1859 MergeHolds($dbh,$to_biblio, $from_biblio);
1861 This shifts the holds from C<$from_biblio> to C<$to_biblio> and reorders them by the date they were placed
1863 =cut
1865 sub MergeHolds {
1866 my ( $dbh, $to_biblio, $from_biblio ) = @_;
1867 my $sth = $dbh->prepare(
1868 "SELECT count(*) as reserve_count FROM reserves WHERE biblionumber = ?"
1870 $sth->execute($from_biblio);
1871 if ( my $data = $sth->fetchrow_hashref() ) {
1873 # holds exist on old record, if not we don't need to do anything
1874 $sth = $dbh->prepare(
1875 "UPDATE reserves SET biblionumber = ? WHERE biblionumber = ?");
1876 $sth->execute( $to_biblio, $from_biblio );
1878 # Reorder by date
1879 # don't reorder those already waiting
1881 $sth = $dbh->prepare(
1882 "SELECT * FROM reserves WHERE biblionumber = ? AND (found <> ? AND found <> ? OR found is NULL) ORDER BY reservedate ASC"
1884 my $upd_sth = $dbh->prepare(
1885 "UPDATE reserves SET priority = ? WHERE biblionumber = ? AND borrowernumber = ?
1886 AND reservedate = ? AND (itemnumber = ? or itemnumber is NULL) "
1888 $sth->execute( $to_biblio, 'W', 'T' );
1889 my $priority = 1;
1890 while ( my $reserve = $sth->fetchrow_hashref() ) {
1891 $upd_sth->execute(
1892 $priority, $to_biblio,
1893 $reserve->{'borrowernumber'}, $reserve->{'reservedate'},
1894 $reserve->{'itemnumber'}
1896 $priority++;
1901 =head2 RevertWaitingStatus
1903 RevertWaitingStatus({ itemnumber => $itemnumber });
1905 Reverts a 'waiting' hold back to a regular hold with a priority of 1.
1907 Caveat: Any waiting hold fixed with RevertWaitingStatus will be an
1908 item level hold, even if it was only a bibliolevel hold to
1909 begin with. This is because we can no longer know if a hold
1910 was item-level or bib-level after a hold has been set to
1911 waiting status.
1913 =cut
1915 sub RevertWaitingStatus {
1916 my ( $params ) = @_;
1917 my $itemnumber = $params->{'itemnumber'};
1919 return unless ( $itemnumber );
1921 my $dbh = C4::Context->dbh;
1923 ## Get the waiting reserve we want to revert
1924 my $query = "
1925 SELECT * FROM reserves
1926 WHERE itemnumber = ?
1927 AND found IS NOT NULL
1929 my $sth = $dbh->prepare( $query );
1930 $sth->execute( $itemnumber );
1931 my $reserve = $sth->fetchrow_hashref();
1933 ## Increment the priority of all other non-waiting
1934 ## reserves for this bib record
1935 $query = "
1936 UPDATE reserves
1938 priority = priority + 1
1939 WHERE
1940 biblionumber = ?
1942 priority > 0
1944 $sth = $dbh->prepare( $query );
1945 $sth->execute( $reserve->{'biblionumber'} );
1947 ## Fix up the currently waiting reserve
1948 $query = "
1949 UPDATE reserves
1951 priority = 1,
1952 found = NULL,
1953 waitingdate = NULL
1954 WHERE
1955 reserve_id = ?
1957 $sth = $dbh->prepare( $query );
1958 $sth->execute( $reserve->{'reserve_id'} );
1959 _FixPriority( { biblionumber => $reserve->{biblionumber} } );
1962 =head2 ReserveSlip
1964 ReserveSlip($branchcode, $borrowernumber, $biblionumber)
1966 Returns letter hash ( see C4::Letters::GetPreparedLetter ) or undef
1968 The letter code will be HOLD_SLIP, and the following tables are
1969 available within the slip:
1971 reserves
1972 branches
1973 borrowers
1974 biblio
1975 biblioitems
1976 items
1978 =cut
1980 sub ReserveSlip {
1981 my ($branch, $borrowernumber, $biblionumber) = @_;
1983 # return unless ( C4::Context->boolean_preference('printreserveslips') );
1984 my $patron = Koha::Patrons->find( $borrowernumber );
1986 my $hold = Koha::Holds->search({biblionumber => $biblionumber, borrowernumber => $borrowernumber })->next;
1987 return unless $hold;
1988 my $reserve = $hold->unblessed;
1990 return C4::Letters::GetPreparedLetter (
1991 module => 'circulation',
1992 letter_code => 'HOLD_SLIP',
1993 branchcode => $branch,
1994 lang => $patron->lang,
1995 tables => {
1996 'reserves' => $reserve,
1997 'branches' => $reserve->{branchcode},
1998 'borrowers' => $reserve->{borrowernumber},
1999 'biblio' => $reserve->{biblionumber},
2000 'biblioitems' => $reserve->{biblionumber},
2001 'items' => $reserve->{itemnumber},
2006 =head2 GetReservesControlBranch
2008 my $reserves_control_branch = GetReservesControlBranch($item, $borrower);
2010 Return the branchcode to be used to determine which reserves
2011 policy applies to a transaction.
2013 C<$item> is a hashref for an item. Only 'homebranch' is used.
2015 C<$borrower> is a hashref to borrower. Only 'branchcode' is used.
2017 =cut
2019 sub GetReservesControlBranch {
2020 my ( $item, $borrower ) = @_;
2022 my $reserves_control = C4::Context->preference('ReservesControlBranch');
2024 my $branchcode =
2025 ( $reserves_control eq 'ItemHomeLibrary' ) ? $item->{'homebranch'}
2026 : ( $reserves_control eq 'PatronLibrary' ) ? $borrower->{'branchcode'}
2027 : undef;
2029 return $branchcode;
2032 =head2 CalculatePriority
2034 my $p = CalculatePriority($biblionumber, $resdate);
2036 Calculate priority for a new reserve on biblionumber, placing it at
2037 the end of the line of all holds whose start date falls before
2038 the current system time and that are neither on the hold shelf
2039 or in transit.
2041 The reserve date parameter is optional; if it is supplied, the
2042 priority is based on the set of holds whose start date falls before
2043 the parameter value.
2045 After calculation of this priority, it is recommended to call
2046 _ShiftPriorityByDateAndPriority. Note that this is currently done in
2047 AddReserves.
2049 =cut
2051 sub CalculatePriority {
2052 my ( $biblionumber, $resdate ) = @_;
2054 my $sql = q{
2055 SELECT COUNT(*) FROM reserves
2056 WHERE biblionumber = ?
2057 AND priority > 0
2058 AND (found IS NULL OR found = '')
2060 #skip found==W or found==T (waiting or transit holds)
2061 if( $resdate ) {
2062 $sql.= ' AND ( reservedate <= ? )';
2064 else {
2065 $sql.= ' AND ( reservedate < NOW() )';
2067 my $dbh = C4::Context->dbh();
2068 my @row = $dbh->selectrow_array(
2069 $sql,
2070 undef,
2071 $resdate ? ($biblionumber, $resdate) : ($biblionumber)
2074 return @row ? $row[0]+1 : 1;
2077 =head2 IsItemOnHoldAndFound
2079 my $bool = IsItemFoundHold( $itemnumber );
2081 Returns true if the item is currently on hold
2082 and that hold has a non-null found status ( W, T, etc. )
2084 =cut
2086 sub IsItemOnHoldAndFound {
2087 my ($itemnumber) = @_;
2089 my $rs = Koha::Database->new()->schema()->resultset('Reserve');
2091 my $found = $rs->count(
2093 itemnumber => $itemnumber,
2094 found => { '!=' => undef }
2098 return $found;
2101 =head2 GetMaxPatronHoldsForRecord
2103 my $holds_per_record = ReservesControlBranch( $borrowernumber, $biblionumber );
2105 For multiple holds on a given record for a given patron, the max
2106 number of record level holds that a patron can be placed is the highest
2107 value of the holds_per_record rule for each item if the record for that
2108 patron. This subroutine finds and returns the highest holds_per_record
2109 rule value for a given patron id and record id.
2111 =cut
2113 sub GetMaxPatronHoldsForRecord {
2114 my ( $borrowernumber, $biblionumber ) = @_;
2116 my $patron = Koha::Patrons->find($borrowernumber);
2117 my @items = Koha::Items->search( { biblionumber => $biblionumber } );
2119 my $controlbranch = C4::Context->preference('ReservesControlBranch');
2121 my $categorycode = $patron->categorycode;
2122 my $branchcode;
2123 $branchcode = $patron->branchcode if ( $controlbranch eq "PatronLibrary" );
2125 my $max = 0;
2126 foreach my $item (@items) {
2127 my $itemtype = $item->effective_itemtype();
2129 $branchcode = $item->homebranch if ( $controlbranch eq "ItemHomeLibrary" );
2131 my $rule = GetHoldRule( $categorycode, $itemtype, $branchcode );
2132 my $holds_per_record = $rule ? $rule->{holds_per_record} : 0;
2133 $max = $holds_per_record if $holds_per_record > $max;
2136 return $max;
2139 =head2 GetHoldRule
2141 my $rule = GetHoldRule( $categorycode, $itemtype, $branchcode );
2143 Returns the matching hold related issuingrule fields for a given
2144 patron category, itemtype, and library.
2146 =cut
2148 sub GetHoldRule {
2149 my ( $categorycode, $itemtype, $branchcode ) = @_;
2151 my $dbh = C4::Context->dbh;
2153 my $sth = $dbh->prepare(
2155 SELECT categorycode, itemtype, branchcode, reservesallowed, holds_per_record
2156 FROM issuingrules
2157 WHERE (categorycode in (?,'*') )
2158 AND (itemtype IN (?,'*'))
2159 AND (branchcode IN (?,'*'))
2160 ORDER BY categorycode DESC,
2161 itemtype DESC,
2162 branchcode DESC
2166 $sth->execute( $categorycode, $itemtype, $branchcode );
2168 return $sth->fetchrow_hashref();
2171 =head1 AUTHOR
2173 Koha Development Team <http://koha-community.org/>
2175 =cut