From 82d1fe4086f639c9f5e7a9b1ebcfa7955c65f860 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 17 Sep 2012 09:06:38 -0400 Subject: [PATCH] Bug 8559 - conflicting item statuses - Force cancel or revert If a librarian checks out a waiting hold to a different patron it gives the item conflicting statuses. The item will show as both checked out to the different patron, and waiting for the original patron. This patch fixes this by not allowing this situation to occurr. If a librarian attempts to issue an item that is waiting for a different patron, the system will force the librarian to choose to a) not issue the item b) issue the item, and cancel the waiting hold c) issue the item, and revert the waiting hold In this scenario, reverting the waiting hold means to push it back on the reserves queue as a hold with a priority of 1, which will push the priorities of any existing holds back by 1 as well. It will become an item level hold for the given item, as we cannot know if the hold was item-level or bib-level given the data we have about the hold. Signed-off-by: Owen Leonard All three cases tested, correct outcome each time Signed-off-by: Jonathan Druart Signed-off-by: Jared Camins-Esakov --- C4/Reserves.pm | 65 ++++++++++++++++++- .../prog/en/modules/circ/circulation.tt | 10 +-- 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 1dc6f72ab8..40e59a3cb8 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -2007,7 +2007,10 @@ sub MoveReserve { ModReserveFill($borr_res); } - if ($cancelreserve) { # cancel reserves on this item + if ( $cancelreserve eq 'revert' ) { ## Revert waiting reserve to priority 1 + RevertWaitingStatus( itemnumber => $itemnumber ); + } + elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) { # cancel reserves on this item CancelReserve(0, $res->{'itemnumber'}, $res->{'borrowernumber'}); CancelReserve($res->{'biblionumber'}, 0, $res->{'borrowernumber'}); } @@ -2058,6 +2061,66 @@ sub MergeHolds { } } +=head2 RevertWaitingStatus + + $success = RevertWaitingStatus( itemnumber => $itemnumber ); + + Reverts a 'waiting' hold back to a regular hold with a priority of 1. + + Caveat: Any waiting hold fixed with RevertWaitingStatus will be an + item level hold, even if it was only a bibliolevel hold to + begin with. This is because we can no longer know if a hold + was item-level or bib-level after a hold has been set to + waiting status. + +=cut + +sub RevertWaitingStatus { + my ( %params ) = @_; + my $itemnumber = $params{'itemnumber'}; + + return unless ( $itemnumber ); + + my $dbh = C4::Context->dbh; + + ## Get the waiting reserve we want to revert + my $query = " + SELECT * FROM reserves + WHERE itemnumber = ? + AND found IS NOT NULL + "; + my $sth = $dbh->prepare( $query ); + $sth->execute( $itemnumber ); + my $reserve = $sth->fetchrow_hashref(); + + ## Increment the priority of all other non-waiting + ## reserves for this bib record + $query = " + UPDATE reserves + SET + priority = priority + 1 + WHERE + biblionumber = ? + AND + priority > 0 + "; + $sth = $dbh->prepare( $query ); + $sth->execute( $reserve->{'biblionumber'} ); + + ## Fix up the currently waiting reserve + $query = " + UPDATE reserves + SET + priority = 1, + found = NULL, + waitingdate = NULL + WHERE + reserve_id = ? + "; + $sth = $dbh->prepare( $query ); + return $sth->execute( $reserve->{'reserve_id'} ); +} + =head2 ReserveSlip ReserveSlip($branchcode, $borrowernumber, $biblionumber) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index ee3a66662c..c860ed6832 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -385,16 +385,18 @@ function validate1(date) { [% IF ( RESERVED ) %]

- +

[% END %] [% IF ( RESERVE_WAITING ) %] -

- +

-

+
+ + +

[% END %] -- 2.39.5