@@ -, +, @@ --- C4/Reserves.pm | 137 +++++++++++++++++++- circ/circulation.pl | 5 + installer/data/mysql/kohastructure.sql | 4 + installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 14 ++ .../en/modules/admin/preferences/circulation.pref | 6 + .../prog/en/modules/circ/circulation.tt | 59 ++++++++- .../prog/en/modules/members/moremember.tt | 54 ++++++++ .../prog/en/modules/reserve/request.tt | 41 ++++++- koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt | 61 ++++++++- members/moremember.pl | 4 + misc/cronjobs/holds/auto_unsuspend_holds.pl | 34 +++++ opac/opac-modrequest-suspend.pl | 46 +++++++ opac/opac-user.pl | 4 + reserve/modrequest.pl | 3 +- reserve/modrequest_suspendall.pl | 58 ++++++++ reserve/request.pl | 9 +- 17 files changed, 526 insertions(+), 14 deletions(-) create mode 100755 misc/cronjobs/holds/auto_unsuspend_holds.pl create mode 100755 opac/opac-modrequest-suspend.pl create mode 100755 reserve/modrequest_suspendall.pl --- a/C4/Reserves.pm +++ a/C4/Reserves.pm @@ -117,10 +117,14 @@ BEGIN { &CancelReserve &CancelExpiredReserves + &AutoUnsuspendReserves + &IsAvailableForItemLevelRequest &AlterPriority &ToggleLowestPriority + &ToggleSuspend + &SuspendAll ); @EXPORT_OK = qw( MergeHolds ); } @@ -263,7 +267,9 @@ sub GetReservesFromBiblionumber { itemnumber, reservenotes, expirationdate, - lowestPriority + lowestPriority, + suspend, + suspend_until FROM reserves WHERE biblionumber = ? "; unless ( $all_dates ) { @@ -873,6 +879,24 @@ sub CancelExpiredReserves { } +=head2 AutoUnsuspendReserves + + AutoUnsuspendReserves(); + +Unsuspends all suspended reserves with a suspend_until date from before today. + +=cut + +sub AutoUnsuspendReserves { + + my $dbh = C4::Context->dbh; + + my $query = "UPDATE reserves SET suspend = 0, suspend_until = NULL WHERE DATE( suspend_until ) < DATE( CURDATE() )"; + my $sth = $dbh->prepare( $query ); + $sth->execute(); + +} + =head2 CancelReserve &CancelReserve($biblionumber, $itemnumber, $borrowernumber); @@ -1008,7 +1032,7 @@ itemnumber and supplying itemnumber. sub ModReserve { #subroutine to update a reserve - my ( $rank, $biblio, $borrower, $branch , $itemnumber) = @_; + my ( $rank, $biblio, $borrower, $branch , $itemnumber, $suspend_until) = @_; return if $rank eq "W"; return if $rank eq "n"; my $dbh = C4::Context->dbh; @@ -1041,14 +1065,25 @@ sub ModReserve { } elsif ($rank =~ /^\d+/ and $rank > 0) { - my $query = qq/ - UPDATE reserves SET priority = ? ,branchcode = ?, itemnumber = ?, found = NULL, waitingdate = NULL + my $query = " + UPDATE reserves SET priority = ? ,branchcode = ?, itemnumber = ?, found = NULL, waitingdate = NULL WHERE biblionumber = ? - AND borrowernumber = ? - /; + AND borrowernumber = ? + "; my $sth = $dbh->prepare($query); $sth->execute( $rank, $branch,$itemnumber, $biblio, $borrower); $sth->finish; + + if ( defined( $suspend_until ) ) { + if ( $suspend_until ) { + $suspend_until = C4::Dates->new( $suspend_until )->output("iso"); + warn "SUSPEND UNTIL: $suspend_until"; + $dbh->do("UPDATE reserves SET suspend = 1, suspend_until = ? WHERE biblionumber = ? AND borrowernumber = ?", undef, ( $suspend_until, $biblio, $borrower ) ); + } else { + $dbh->do("UPDATE reserves SET suspend_until = NULL WHERE biblionumber = ? AND borrowernumber = ?", undef, ( $biblio, $borrower ) ); + } + } + _FixPriority( $biblio, $borrower, $rank); } } @@ -1455,6 +1490,93 @@ sub ToggleLowestPriority { _FixPriority( $biblionumber, $borrowernumber, '999999' ); } +=head2 ToggleSuspend + + ToggleSuspend( $borrowernumber, $biblionumber ); + +This function sets the suspend field to true if is false, and false if it is true. +If the reserve is currently suspended with a suspend_until date, that date will +be cleared when it is unsuspended. + +=cut + +sub ToggleSuspend { + my ( $borrowernumber, $biblionumber ) = @_; + + my $dbh = C4::Context->dbh; + + my $sth = $dbh->prepare( + "UPDATE reserves SET suspend = NOT suspend, + suspend_until = CASE WHEN suspend = 0 THEN NULL ELSE suspend_until END + WHERE biblionumber = ? + AND borrowernumber = ? + "); + $sth->execute( + $biblionumber, + $borrowernumber, + ); + $sth->finish; +} + +=head2 SuspendAll + + SuspendAll( + borrowernumber => $borrowernumber, + [ biblionumber => $biblionumber, ] + [ suspend_until => $suspend_until, ] + [ suspend => $suspend ] + ); + + This function accepts a set of hash keys as its parameters. + It requires either borrowernumber or biblionumber, or both. + + suspend_until is wholly optional. + +=cut + +sub SuspendAll { + my %params = @_; + + my $borrowernumber = $params{'borrowernumber'} || undef; + my $biblionumber = $params{'biblionumber'} || undef; + my $suspend_until = $params{'suspend_until'} || undef; + my $suspend = defined( $params{'suspend'} ) ? $params{'suspend'} : 1; + + warn "C4::Reserves::SuspendAll( borrowernumber => $borrowernumber, biblionumber => $biblionumber, suspend_until => $suspend_until, suspend => $suspend )"; + + $suspend_until = C4::Dates->new( $suspend_until )->output("iso") if ( defined( $suspend_until ) ); + + return unless ( $borrowernumber || $biblionumber ); + + my ( $query, $sth, $dbh, @query_params ); + + $query = "UPDATE reserves SET suspend = ? "; + push( @query_params, $suspend ); + if ( !$suspend ) { + $query .= ", suspend_until = NULL "; + } elsif ( $suspend_until ) { + $query .= ", suspend_until = ? "; + push( @query_params, $suspend_until ); + } + $query .= " WHERE "; + if ( $borrowernumber ) { + $query .= " borrowernumber = ? "; + push( @query_params, $borrowernumber ); + } + $query .= " AND " if ( $borrowernumber && $biblionumber ); + if ( $biblionumber ) { + $query .= " biblionumber = ? "; + push( @query_params, $biblionumber ); + } + $query .= " AND found IS NULL "; + + $dbh = C4::Context->dbh; + $sth = $dbh->prepare( $query ); + $sth->execute( @query_params ); + $sth->finish; +} + + =head2 _FixPriority &_FixPriority($biblio,$borrowernumber,$rank,$ignoreSetLowestRank); @@ -1599,6 +1721,7 @@ sub _Findgroupreserve { AND item_level_request = 1 AND itemnumber = ? AND reservedate <= CURRENT_DATE() + AND suspend = 0 /; my $sth = $dbh->prepare($item_level_target_query); $sth->execute($itemnumber); @@ -1629,6 +1752,7 @@ sub _Findgroupreserve { AND item_level_request = 0 AND hold_fill_targets.itemnumber = ? AND reservedate <= CURRENT_DATE() + AND suspend = 0 /; $sth = $dbh->prepare($title_level_target_query); $sth->execute($itemnumber); @@ -1660,6 +1784,7 @@ sub _Findgroupreserve { OR reserves.constrainttype='a' ) AND (reserves.itemnumber IS NULL OR reserves.itemnumber = ?) AND reserves.reservedate <= CURRENT_DATE() + AND suspend = 0 /; $sth = $dbh->prepare($query); $sth->execute( $biblio, $bibitem, $itemnumber ); --- a/circ/circulation.pl +++ a/circ/circulation.pl @@ -358,6 +358,8 @@ if ($borrowernumber) { $getreserv{itemcallnumber} = $getiteminfo->{'itemcallnumber'}; $getreserv{biblionumber} = $getiteminfo->{'biblionumber'}; $getreserv{waitingat} = GetBranchName( $num_res->{'branchcode'} ); + $getreserv{suspend} = $num_res->{'suspend'}; + $getreserv{suspend_until} = C4::Dates->new( $num_res->{'suspend_until'}, "iso")->output("syspref"); # check if we have a waiting status for reservations if ( $num_res->{'found'} eq 'W' ) { $getreserv{color} = 'reserved'; @@ -729,4 +731,7 @@ $template->param( DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), canned_bor_notes_loop => $canned_notes, ); + +$template->param( AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds') ); + output_html_with_http_headers $query, $cookie, $template->output; --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -1400,6 +1400,8 @@ CREATE TABLE `old_reserves` ( -- this table holds all holds/reserves that have b `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library `expirationdate` DATE DEFAULT NULL, -- the date the hold expires (usually the date entered by the patron to say they don't need the hold after a certain date) `lowestPriority` tinyint(1) NOT NULL, + `suspend` BOOLEAN NOT NULL DEFAULT 0, + `suspend_until` DATETIME NULL DEFAULT NULL, KEY `old_reserves_borrowernumber` (`borrowernumber`), KEY `old_reserves_biblionumber` (`biblionumber`), KEY `old_reserves_itemnumber` (`itemnumber`), @@ -1593,6 +1595,8 @@ CREATE TABLE `reserves` ( -- information related to holds/reserves in Koha `waitingdate` date default NULL, -- the date the item was marked as waiting for the patron at the library `expirationdate` DATE DEFAULT NULL, -- the date the hold expires (usually the date entered by the patron to say they don't need the hold after a certain date) `lowestPriority` tinyint(1) NOT NULL, + `suspend` BOOLEAN NOT NULL DEFAULT 0, + `suspend_until` DATETIME NULL DEFAULT NULL, KEY priorityfoundidx (priority,found), KEY `borrowernumber` (`borrowernumber`), KEY `biblionumber` (`biblionumber`), --- a/installer/data/mysql/sysprefs.sql +++ a/installer/data/mysql/sysprefs.sql @@ -337,3 +337,4 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('BorrowerRenewalPeriodBase', 'now', 'Set whether the borrower renewal date should be counted from the dateexpiry or from the current date ','dateexpiry|now','Choice'); INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('AllowItemsOnHoldCheckout',0,'Do not generate RESERVE_WAITING and RESERVED warning when checking out items reserved to someone else. This allows self checkouts for those items.','','YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacExportOptions','bibtex|dc|marcxml|marc8|utf8|marcstd|mods|ris','Define export options available on OPAC detail page.','','free'); +INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('AutoResumeSuspendedHolds', '1', NULL , 'Allow suspended holds to be automatically resumed by a set date.', 'YesNo'); --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -4734,6 +4734,20 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.07.00.XXX"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE reserves ADD suspend BOOLEAN NOT NULL DEFAULT 0"); + $dbh->do("ALTER TABLE old_reserves ADD suspend BOOLEAN NOT NULL DEFAULT 0"); + + $dbh->do("ALTER TABLE reserves ADD suspend_until DATETIME NULL DEFAULT NULL"); + $dbh->do("ALTER TABLE old_reserves ADD suspend_until DATETIME NULL DEFAULT NULL"); + + $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('AutoResumeSuspendedHolds', '1', NULL , 'Allow suspended holds to be automatically resumed by a set date.', 'YesNo')"); + + print "Upgrade to $DBversion done (Add suspend fields to reserves table, add syspref AutoResumeSuspendedHolds)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 DropAllForeignKeys($table) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -329,6 +329,12 @@ Circulation: yes: Transfer no: "Don't transfer" - items when cancelling all waiting holds. + - + - pref: AutoResumeSuspendedHolds + choices: + yes: Allow + no: "Don't allow" + - suspended holds to be automatically resumed by a set date. Fines Policy: - - Calculate fines based on days overdue --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -947,9 +947,10 @@ No patron matched [% message %]
Patron has nothing on hold.
[% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -593,6 +593,7 @@ function validate1(date) {Patron has nothing on hold.
[% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -597,6 +597,7 @@ function checkMultiHold() {