From 4dd13e655fe61b118b8fd5e2f72f946ac5348188 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 4 Mar 2013 14:47:57 +0100 Subject: [PATCH] Bug 9761: Make it possible to confirm future hold requests at checkin time Description: A new pref ConfirmFutureHolds is added. When confirming a hold at checkin time, the number of days in this pref is taken into account when looking for reserves. Note that this pref does not interfere with renewing, issuing or transferring a book. For report Holds to pull, the default end date is calculated with this new preference. The use of ConfirmFutureHolds is useful only when future holds are allowed. Test plan: 1) Enable future holds. Add a number of days into ConfirmFutureHolds. 2) Place a future hold within this number of days. 3) Run holds to pull report. Check default startdate and enddate. 4) Check this book in. Can you confirm the hold? Do not confirm. 5) Issue the book to another patron. You should not see a warning. 6) Renew the book for this patron via opac or staff. No warning either. 7) Check in again. Warning pops up again. 8) Transfer book. Switch branch. Check in. Hold found pops up. Do not confirm. 9) Back to first branch. Check in (with popup). Remove the hold. Add new future hold past the number of days. Check in (no warn). Signed-off-by: Kyle M Hall --- C4/Circulation.pm | 3 ++- C4/Reserves.pm | 23 +++++++++++--------- circ/pendingreserves.pl | 25 ++++++++++++---------- .../en/modules/admin/preferences/circulation.pref | 7 +++++- .../prog/en/modules/circ/pendingreserves.tt | 2 +- 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 30cbe2f..3674cd7 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1876,7 +1876,8 @@ sub AddReturn { # find reserves..... # if we don't have a reserve with the status W, we launch the Checkreserves routine my ($resfound, $resrec); - ($resfound, $resrec, undef) = C4::Reserves::CheckReserves( $item->{'itemnumber'} ) unless ( $item->{'wthdrawn'} ); + my $lookahead= C4::Context->preference('ConfirmFutureHolds'); #number of days to look for future holds + ($resfound, $resrec, undef) = C4::Reserves::CheckReserves( $item->{'itemnumber'}, undef, $lookahead ) unless ( $item->{'wthdrawn'} ); if ($resfound) { $resrec->{'ResFound'} = $resfound; $messages->{'ResFound'} = $resrec; diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 5ff12e4..30c677d 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -775,10 +775,12 @@ sub GetReserveStatus { ($status, $reserve, $all_reserves) = &CheckReserves($itemnumber); ($status, $reserve, $all_reserves) = &CheckReserves(undef, $barcode); + ($status, $reserve, $all_reserves) = &CheckReserves($itemnumber,undef,$lookahead); Find a book in the reserves. C<$itemnumber> is the book's item number. +C<$lookahead> is the number of days to look in advance for future reserves. As I understand it, C<&CheckReserves> looks for the given item in the reserves. If it is found, that's a match, and C<$status> is set to @@ -799,7 +801,7 @@ table in the Koha database. =cut sub CheckReserves { - my ( $item, $barcode ) = @_; + my ( $item, $barcode, $lookahead_days) = @_; my $dbh = C4::Context->dbh; my $sth; my $select; @@ -846,7 +848,7 @@ sub CheckReserves { return ( '' ) if ( $notforloan_per_item > 0 ) or $notforloan_per_itemtype; # Find this item in the reserves - my @reserves = _Findgroupreserve( $bibitem, $biblio, $itemnumber ); + my @reserves = _Findgroupreserve( $bibitem, $biblio, $itemnumber, $lookahead_days); # $priority and $highest are used to find the most important item # in the list returned by &_Findgroupreserve. (The lower $priority, @@ -1728,11 +1730,12 @@ sub _FixPriority { =head2 _Findgroupreserve - @results = &_Findgroupreserve($biblioitemnumber, $biblionumber, $itemnumber); + @results = &_Findgroupreserve($biblioitemnumber, $biblionumber, $itemnumber, $lookahead); Looks for an item-specific match first, then for a title-level match, returning the first match found. If neither, then we look for a 3rd kind of match based on reserve constraints. +Lookahead is the number of days to look in advance. TODO: add more explanation about reserve constraints @@ -1744,7 +1747,7 @@ C. =cut sub _Findgroupreserve { - my ( $bibitem, $biblio, $itemnumber ) = @_; + my ( $bibitem, $biblio, $itemnumber, $lookahead) = @_; my $dbh = C4::Context->dbh; # TODO: consolidate at least the SELECT portion of the first 2 queries to a common $select var. @@ -1768,11 +1771,11 @@ sub _Findgroupreserve { AND priority > 0 AND item_level_request = 1 AND itemnumber = ? - AND reservedate <= CURRENT_DATE() + AND reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY) AND suspend = 0 /; my $sth = $dbh->prepare($item_level_target_query); - $sth->execute($itemnumber); + $sth->execute($itemnumber, $lookahead||0); my @results; if ( my $data = $sth->fetchrow_hashref ) { push( @results, $data ); @@ -1799,11 +1802,11 @@ sub _Findgroupreserve { AND priority > 0 AND item_level_request = 0 AND hold_fill_targets.itemnumber = ? - AND reservedate <= CURRENT_DATE() + AND reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY) AND suspend = 0 /; $sth = $dbh->prepare($title_level_target_query); - $sth->execute($itemnumber); + $sth->execute($itemnumber, $lookahead||0); @results = (); if ( my $data = $sth->fetchrow_hashref ) { push( @results, $data ); @@ -1831,11 +1834,11 @@ sub _Findgroupreserve { AND reserves.reservedate = reserveconstraints.reservedate ) OR reserves.constrainttype='a' ) AND (reserves.itemnumber IS NULL OR reserves.itemnumber = ?) - AND reserves.reservedate <= CURRENT_DATE() + AND reserves.reservedate <= DATE_ADD(NOW(),INTERVAL ? DAY) AND suspend = 0 /; $sth = $dbh->prepare($query); - $sth->execute( $biblio, $bibitem, $itemnumber ); + $sth->execute( $biblio, $bibitem, $itemnumber, $lookahead||0); @results = (); while ( my $data = $sth->fetchrow_hashref ) { push( @results, $data ); diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index 9a60ec1..efcd778 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -25,6 +25,10 @@ use strict; #use warnings; FIXME - Bug 2505 + +use constant TWO_DAYS => 2; +use constant TWO_DAYS_AGO => -2; + use C4::Context; use C4::Output; use CGI; @@ -66,26 +70,24 @@ my $author; my ( $year, $month, $day ) = Today(); my $todaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", $year, $month, $day); -my $yesterdaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD($year, $month, $day, 0, 0, -1)); -# changed from delivered range of 10 years-yesterday to 2 days ago-today -# Find two days ago for the default shelf pull start and end dates, unless HoldsToPullStartDate sys pref is set. -my $defaultstartdate = ( C4::Context->preference('HoldsToPullStartDate') ) ? "-".C4::Context->preference('HoldsToPullStartDate') : -2; -my $pastdate = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD($year, $month, $day, 0, 0, $defaultstartdate)); - -# Predefine the start and end dates if they are not already defined $startdate =~ s/^\s+//; $startdate =~ s/\s+$//; $enddate =~ s/^\s+//; $enddate =~ s/\s+$//; -# Check if null, should string match, if so set start and end date to yesterday + if (!defined($startdate) or $startdate eq "") { + # changed from delivered range of 10 years-yesterday to 2 days ago-today + # Find two days ago for the default shelf pull start date, unless HoldsToPullStartDate sys pref is set. + my $pastdate= sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD($year, $month, $day, 0, 0, -C4::Context->preference('HoldsToPullStartDate')||TWO_DAYS_AGO )); $startdate = format_date($pastdate); } + if (!defined($enddate) or $enddate eq "") { - $enddate = format_date($todaysdate); + #similarly: calculate end date with ConfirmFutureHolds (days) + my $d=sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD($year, $month, $day, 0, 0, C4::Context->preference('ConfirmFutureHolds')||0 )); + $enddate = format_date($d); } - my @reservedata; if ( $run_report ) { my $dbh = C4::Context->dbh; @@ -202,7 +204,8 @@ $template->param( run_report => $run_report, reserveloop => \@reservedata, "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1, - HoldsToPullStartDate => (C4::Context->preference('HoldsToPullStartDate')?C4::Context->preference('HoldsToPullStartDate'):2), + HoldsToPullStartDate=> C4::Context->preference('HoldsToPullStartDate')||TWO_DAYS, + HoldsToPullEndDate => C4::Context->preference('ConfirmFutureHolds')||0, ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 64cf338..025ab88 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -55,7 +55,7 @@ Circulation: - Set the default start date for the Holds to pull list to - pref: HoldsToPullStartDate class: integer - - day(s) ago. + - day(s) ago. Note that the default end date is controlled by preference ConfirmFutureHolds. - - pref: AllowAllMessageDeletion choices: @@ -358,6 +358,11 @@ Circulation: no: "Don't allow" - "patrons to place holds that don't enter the waiting list until a certain future date. (AllowHoldDateInFuture must also be enabled)." - + - Confirm future hold requests at checkin within + - pref: ConfirmFutureHolds + class: integer + - day(s). Note that this number of days will be used too in calculating the default end date for the Holds to pull-report. (As may be obvious, use of this preference becomes useful only when allowing future holds. + - - Check the - pref: ReservesControlBranch choices: diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt index 026e9dd..18b3db3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt @@ -174,7 +174,7 @@ $(document).ready(function() { -

(Inclusive, default is [% HoldsToPullStartDate %] days ago to today, set other date ranges as needed. )

+

(Inclusive, default is [% HoldsToPullStartDate %] days ago to [% IF ( HoldsToPullEndDate ) %][% HoldsToPullEndDate %] days ahead[% ELSE %]today[% END %], set other date ranges as needed. )

-- 1.8.1.2