From 7e919d12d846c72fd5d376c4c8549f6b7135f9d9 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 17 Jan 2020 13:58:12 +0000 Subject: [PATCH] Bug 24446: Catch daterequested in circ returns MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Update C4::Circulation::AddReturn to use Koha::Item->get_transfer to find requested transfers and use Koha::Item::Transfer->receipt to complete transfer requests if they have arrived at their destination or return the relevant 'WrongTransfer', 'WasTransfered' and 'TransferTrigger' messages to the end user. Signed-off-by: Kathleen Milne Signed-off-by: Joonas Kylmälä Signed-off-by: Jonathan Druart --- C4/Circulation.pm | 51 ++++++++++++------- circ/returns.pl | 4 +- .../prog/en/modules/circ/returns.tt | 23 ++++++++- 3 files changed, 58 insertions(+), 20 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 8e4072467a..ca0f13dca3 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -387,7 +387,7 @@ sub transferbook { ModItemTransfer( $itemnumber, $fbr, $tbr, $trigger ); # don't need to update MARC anymore, we do it in batch now - $messages->{'WasTransfered'} = 1; + $messages->{'WasTransfered'} = $tbr; } ModDateLastSeen( $itemnumber ); @@ -2136,23 +2136,31 @@ sub AddReturn { } # check if we have a transfer for this document - my ($datesent,$frombranch,$tobranch) = GetTransfers( $item->itemnumber ); + my $transfer = $item->get_transfer; # if we have a transfer to complete, we update the line of transfers with the datearrived my $is_in_rotating_collection = C4::RotatingCollections::isItemInAnyCollection( $item->itemnumber ); - if ($datesent) { - # At this point we will either fill the transfer or it is a wrong transfer - # either way we should not now generate a new transfer + if ($transfer) { $validTransfer = 0; - if ( $tobranch eq $branch ) { - my $sth = C4::Context->dbh->prepare( - "UPDATE branchtransfers SET datearrived = now() WHERE itemnumber= ? AND datearrived IS NULL" - ); - $sth->execute( $item->itemnumber ); - $messages->{'TransferArrived'} = $frombranch; - } else { - $messages->{'WrongTransfer'} = $tobranch; - $messages->{'WrongTransferItem'} = $item->itemnumber; + if ( $transfer->in_transit ) { + if ( $transfer->tobranch eq $branch ) { + $transfer->receive; + $messages->{'TransferArrived'} = $transfer->frombranch; + } + else { + $messages->{'WrongTransfer'} = $transfer->tobranch; + $messages->{'WrongTransferItem'} = $item->itemnumber; + } + } + else { + if ( $transfer->tobranch eq $branch ) { + $transfer->receive; + $messages->{'TransferArrived'} = $transfer->frombranch; + } + else { + $messages->{'WasTransfered'} = $transfer->tobranch; + $messages->{'TransferTrigger'} = $transfer->reason; + } } } @@ -2243,7 +2251,13 @@ sub AddReturn { } # Transfer to returnbranch if Automatic transfer set or append message NeedsTransfer - if ($validTransfer && !$is_in_rotating_collection && ($doreturn or $messages->{'NotIssued'}) and !$resfound and ($branch ne $returnbranch) ){ + if ( $validTransfer && !$is_in_rotating_collection + && ( $doreturn or $messages->{'NotIssued'} ) + and !$resfound + and ( $branch ne $returnbranch ) + and not $messages->{'WrongTransfer'} + and not $messages->{'WasTransfered'} ) + { my $BranchTransferLimitsType = C4::Context->preference("BranchTransferLimitsType") eq 'itemtype' ? 'effective_itemtype' : 'ccode'; if (C4::Context->preference("AutomaticItemReturn" ) or (C4::Context->preference("UseBranchTransferLimits") and @@ -2252,7 +2266,8 @@ sub AddReturn { $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, $transfer_trigger, { skip_record_index => 1 }); - $messages->{'WasTransfered'} = 1; + $messages->{'WasTransfered'} = $returnbranch; + $messages->{'TransferTrigger'} = $transfer_trigger; } else { $messages->{'NeedsTransfer'} = $returnbranch; $messages->{'TransferTrigger'} = $transfer_trigger; @@ -3416,7 +3431,9 @@ sub GetTransfers { SELECT datesent, frombranch, tobranch, - branchtransfer_id + branchtransfer_id, + daterequested, + reason FROM branchtransfers WHERE itemnumber = ? AND datearrived IS NULL diff --git a/circ/returns.pl b/circ/returns.pl index d9359a0b66..b58e340f85 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -367,7 +367,9 @@ my $reserved = 0; if ( $messages->{'WasTransfered'} ) { $template->param( found => 1, - transfer => 1, + transfer => $messages->{'WasTransfered'}, + 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 c2bdd03bb9..b5754e8b7f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -106,6 +106,25 @@ [% END # /IF hold_auto_filled %] + [% IF ( trigger ) %] +
+

Reason for transfer

+

+ [%- SWITCH trigger -%] + [%- CASE 'Manual' -%]Manual + [%- CASE 'StockrotationAdvance' -%]Stock rotation advance + [%- CASE 'StockrotationRepatriation' -%]Stock rotation repatriation + [%- CASE 'ReturnToHome' -%]Return to home library + [%- CASE 'ReturnToHolding' -%]Return to holding library + [%- CASE 'RotatingCollection' -%]Rotating collection + [%- CASE 'Reserve' -%]Reserve + [%- CASE 'LostReserve' -%]Lost reserve + [%- CASE 'CancelReserve' -%]Cancelled reserve + [%- END -%] +

+
+ [% END %] + [% IF privacy == 2 AND NOT Koha.Preference('AnonymousPatron') %]
Error: @@ -538,7 +557,7 @@