@@ -, +, @@ (with AutomaticItemReturn system preferences enabled) items check-in library to it's home library 'Wrong transfer' was detected. to reflect where the item was most recently checked in. checked in branch as the 'from' branch of the transfer. accepting the transfer and confirm that also works. that this results in the item staying at it's current location and the final transfer having been cancelled. --- C4/Circulation.pm | 32 +++++---- Koha/Item/Transfer.pm | 14 ++++ circ/returns.pl | 30 +++++--- .../prog/en/modules/circ/returns.tt | 72 ++++++++++--------- 4 files changed, 94 insertions(+), 54 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' })->store(); + + # second step: create a new transfer to the right location + my $new_transfer = $item->request_transfer( + { + to => $transfer->to_library, + reason => $transfer->reason, + comment => $transfer->comments, + ignore_limits => 1, + enqueue => 1 + } + ); + + return $new_transfer; } =head2 CalcDateDue --- a/Koha/Item/Transfer.pm +++ a/Koha/Item/Transfer.pm @@ -66,6 +66,20 @@ sub from_library { return Koha::Library->_new_from_dbic($from_library_rs); } +=head3 to_library + + my $to_library = $transfer->to_library; + +Returns the associated to_library for this transfer. + +=cut + +sub to_library { + my ($self) = @_; + my $to_library_rs = $self->_result->tobranch; + return Koha::Library->_new_from_dbic($to_library_rs); +} + =head3 transit Set the transfer as in transit by updating the datesent time. --- a/circ/returns.pl +++ a/circ/returns.pl @@ -55,6 +55,7 @@ use Koha::Checkouts; use Koha::DateUtils; use Koha::Holds; use Koha::Items; +use Koha::Item::Transfers; use Koha::Patrons; my $query = CGI->new; @@ -132,11 +133,6 @@ 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')); -} - my $itemnumber = $query->param('itemnumber'); if ( $query->param('reserve_id') ) { my $borrowernumber = $query->param('borrowernumber'); @@ -190,6 +186,7 @@ if ( my $dropboxmode = $query->param('dropboxmode'); my $dotransfer = $query->param('dotransfer'); my $canceltransfer = $query->param('canceltransfer'); +my $transit = $query->param('transit'); my $dest = $query->param('dest'); #dropbox: get last open day (today - 1) my $dropboxdate = Koha::Checkouts::calculate_dropbox_date(); @@ -227,7 +224,15 @@ if ($dotransfer){ ModItemTransfer($transferitem, $userenv_branch, $tobranch, $trigger); } -if ($canceltransfer){ +if ($transit) { + my $transfer = Koha::Item::Transfers->find($transit); + if ( $canceltransfer ) { + $transfer->cancel({ reason => 'Manual', force => 1}); + $template->param( transfercancelled => 1); + } else { + $transfer->transit; + } +} elsif ($canceltransfer){ my $item = Koha::Items->find($itemnumber); my $transfer = $item->get_transfer; $transfer->cancel({ reason => 'Manual', force => 1}); @@ -239,6 +244,7 @@ if ($canceltransfer){ } } + # actually return book and prepare item table..... my $returnbranch; if ($barcode) { @@ -389,10 +395,19 @@ if ( $messages->{'Wrongbranch'} ){ # case of wrong transfert, if the document wasn't transferred to the right library (according to branchtransfer (tobranch) BDD) if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) { + + # Trigger modal to prompt librarian $template->param( WrongTransfer => 1, TransferWaitingAt => $messages->{'WrongTransfer'}, WrongTransferItem => $messages->{'WrongTransferItem'}, + trigger => $messages->{'TransferTrigger'}, + ); + + # Update the transfer to reflect the new item holdingbranch + my $new_transfer = updateWrongTransfer($messages->{'WrongTransferItem'},$messages->{'WrongTransfer'}, $userenv_branch); + $template->param( + NewTransfer => $new_transfer->id ); my $reserve = $messages->{'ResFound'}; @@ -402,9 +417,6 @@ if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) { patron => $patron, ); } - $template->param( - wtransfertFrom => $userenv_branch, - ); } # --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -430,38 +430,40 @@ [% END %] @@ -1126,6 +1128,12 @@ Dopop( $(this).data("url") ); }); + $('.cancel').on("click",function(e){ + var docancel = $("").attr("type", "hidden").attr("name", "canceltransfer").val(1); + $('#wrongtransferform').append(docancel); + this.form.submit(); + }); + $('.print').on("click",function(e){ this.form.print_slip.value = 1; let barcode = document.getElementById('confirm-hold-barcode'); --