From 7414263d8e27449b19ff104d6d0267b764d97920 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 16 Jan 2020 13:56:41 +0000 Subject: [PATCH] Bug 24298: Record transfer triggers for returns This patch adds handling to catch transfers that may have been triggered on item return. --- C4/Circulation.pm | 6 ++++-- C4/Items.pm | 13 ++++++------- C4/SIP/ILS/Transaction/Checkin.pm | 3 ++- circ/returns.pl | 4 +++- .../intranet-tmpl/prog/en/modules/circ/returns.tt | 1 + 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index e4ded839af..fc7026f39c 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1882,6 +1882,7 @@ sub AddReturn { # get the proper branch to which to return the item my $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $branch; # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch) + my $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef; my $borrowernumber = $patron ? $patron->borrowernumber : undef; # we don't know if we had a borrower or not my $patron_unblessed = $patron ? $patron->unblessed : {}; @@ -2115,12 +2116,13 @@ sub AddReturn { (C4::Context->preference("UseBranchTransferLimits") and ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType ) )) { - $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->itemnumber,$branch, $returnbranch; + $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s, %s)", $item->itemnumber,$branch, $returnbranch, $transfer_trigger; $debug and warn "item: " . Dumper($item_unblessed); - ModItemTransfer($item->itemnumber, $branch, $returnbranch); + ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger); $messages->{'WasTransfered'} = 1; } else { $messages->{'NeedsTransfer'} = $returnbranch; + $messages->{'TransferTrigger'} = $transfer_trigger; } } diff --git a/C4/Items.pm b/C4/Items.pm index bd335d5563..2b71f40d89 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -538,15 +538,14 @@ sub ModItem { =head2 ModItemTransfer - ModItemTransfer($itenumber, $frombranch, $tobranch); + ModItemTransfer($itemnumber, $frombranch, $tobranch, $trigger); -Marks an item as being transferred from one branch -to another. +Marks an item as being transferred from one branch to another and records the trigger. =cut sub ModItemTransfer { - my ( $itemnumber, $frombranch, $tobranch ) = @_; + my ( $itemnumber, $frombranch, $tobranch, $trigger ) = @_; my $dbh = C4::Context->dbh; my $item = Koha::Items->find( $itemnumber ); @@ -558,9 +557,9 @@ sub ModItemTransfer { #new entry in branchtransfers.... my $sth = $dbh->prepare( - "INSERT INTO branchtransfers (itemnumber, frombranch, datesent, tobranch) - VALUES (?, ?, NOW(), ?)"); - $sth->execute($itemnumber, $frombranch, $tobranch); + "INSERT INTO branchtransfers (itemnumber, frombranch, datesent, tobranch, trigger) + VALUES (?, ?, NOW(), ?, ?)"); + $sth->execute($itemnumber, $frombranch, $tobranch, $trigger); ModItem({ holdingbranch => $frombranch }, undef, $itemnumber, { log_action => 0 }); ModDateLastSeen($itemnumber); diff --git a/C4/SIP/ILS/Transaction/Checkin.pm b/C4/SIP/ILS/Transaction/Checkin.pm index f0e8bbdf49..08aaddb7ca 100644 --- a/C4/SIP/ILS/Transaction/Checkin.pm +++ b/C4/SIP/ILS/Transaction/Checkin.pm @@ -121,7 +121,8 @@ sub do_checkin { $messages->{ResFound}->{borrowernumber}, 1, $messages->{ResFound}->{reserve_id}); ModItemTransfer( $messages->{ResFound}->{itemnumber}, $branch, - $messages->{ResFound}->{branchcode} + $messages->{ResFound}->{branchcode}, + $messages->{TransferTrigger}, ); } diff --git a/circ/returns.pl b/circ/returns.pl index 4b338e4796..2ad804ebdb 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -232,7 +232,8 @@ if ($dotransfer){ # An item has been returned to a branch other than the homebranch, and the librarian has chosen to initiate a transfer my $transferitem = $query->param('transferitem'); my $tobranch = $query->param('tobranch'); - ModItemTransfer($transferitem, $userenv_branch, $tobranch); + my $trigger = $query->param('trigger'); + ModItemTransfer($transferitem, $userenv_branch, $tobranch, $trigger); } if ($canceltransfer){ @@ -371,6 +372,7 @@ if ( $messages->{'NeedsTransfer'} ){ $template->param( found => 1, needstransfer => $messages->{'NeedsTransfer'}, + trigger => $messages->{'TransferTrigger'}, itemnumber => $itemnumber, ); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt index 29818882c9..fe9b4d498b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -519,6 +519,7 @@ + [% INCLUDE all_checkin_messages %]