@@ -, +, @@ --- C4/Circulation.pm | 32 +++++++++++-------- circ/returns.pl | 3 +- .../prog/en/modules/circ/returns.tt | 17 ++++++++-- 3 files changed, 36 insertions(+), 16 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -2175,6 +2175,7 @@ sub AddReturn { else { $messages->{'WrongTransfer'} = $transfer->tobranch; $messages->{'WrongTransferItem'} = $item->itemnumber; + $messages->{'TransferTrigger'} = $transfer->reason; } } else { @@ -3589,19 +3590,24 @@ This function validate the line of brachtransfer but with the wrong destination sub updateWrongTransfer { my ( $itemNumber,$waitingAtLibrary,$FromLibrary ) = @_; - my $dbh = C4::Context->dbh; -# first step validate the actual line of transfert . - my $sth = - $dbh->prepare( - "update branchtransfers set datearrived = now(),tobranch=?,comments='wrongtransfer' where itemnumber= ? AND datearrived IS NULL" - ); - $sth->execute($FromLibrary,$itemNumber); - -# second step create a new line of branchtransfer to the right location . - ModItemTransfer($itemNumber, $FromLibrary, $waitingAtLibrary); - -#third step changing holdingbranch of item - my $item = Koha::Items->find($itemNumber)->holdingbranch($FromLibrary)->store; + + # first step: cancel the original transfer + my $item = Koha::Items->find($itemNumber); + my $transfer = $item->get_transfer; + $transfer->set({ datecancelled => dt_from_string, cancellation_reason => 'WrongTransfer' }); + + # second step: create a new transfer to the right location + my $new_transfer = Koha::Item::Transfer->new( + { + itemnumber => $itemNumber, + daterequested => dt_from_string, + datesent => dt_from_string, + frombranch => $FromLibrary, + tobranch => $transfer->tobranch, + reason => $transfer->reason, + comments => $transfer->comments + } + )->store(); } =head2 CalcDateDue --- a/circ/returns.pl +++ a/circ/returns.pl @@ -134,7 +134,7 @@ foreach ( $query->param ) { # Deal with the requests.... if ($query->param('WT-itemNumber')){ - updateWrongTransfer ($query->param('WT-itemNumber'),$query->param('WT-waitingAt'),$query->param('WT-From')); + updateWrongTransfer (scalar $query->param('WT-itemNumber'),scalar $query->param('WT-waitingAt'), scalar $query->param('WT-From')); } my $itemnumber = $query->param('itemnumber'); @@ -393,6 +393,7 @@ if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) { WrongTransfer => 1, TransferWaitingAt => $messages->{'WrongTransfer'}, WrongTransferItem => $messages->{'WrongTransferItem'}, + trigger => $messages->{'TransferTrigger'}, ); my $reserve = $messages->{'ResFound'}; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -432,7 +432,7 @@