From 6eade474ed3a84a5ba372a26ac27bf9fb4bd2299 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 15 Mar 2017 16:02:38 -0300 Subject: [PATCH] Bug 18276: Remove GetBiblioFromItemNumber - Easy ones The subroutine C4::Biblio::GetBiblioFromItemNumber was wrong for several reasons: - badly named, we can get biblio info from a barcode - SELECT * from items, biblio and biblioitems makes things hard to follow and debug, we never know where do come from the value we display - sometimes called only for trivial information such as biblionumber, author or title This patchset suggests to replace it with calls to: - Koha::Items->find for item's info - $item->biblio for biblio's info - $item->biblio->biblioitem for biblioitem's info Test plan: Item's info should correctly be displayed on the following pages: - circulation history - transfer book - checkin - waiting holds QA will check the other changes reading the code, it's trivial Signed-off-by: Josef Moravec Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- C4/Circulation.pm | 70 +++++++------- C4/Members.pm | 14 +-- C4/SIP/ILS/Item.pm | 36 ++++---- C4/SIP/ILS/Transaction/Hold.pm | 24 ++--- catalogue/issuehistory.pl | 2 +- cataloguing/moveitem.pl | 24 ++--- circ/branchtransfers.pl | 46 +++++----- circ/returns.pl | 91 +++++++++---------- circ/transferstoreceive.pl | 27 ++++-- circ/waitingreserves.pl | 34 +++---- .../prog/en/modules/cataloguing/moveitem.tt | 8 +- misc/cronjobs/advance_notices.pl | 9 +- offline_circ/enqueue_koc.pl | 9 +- offline_circ/list.pl | 9 +- offline_circ/process_koc.pl | 49 +++++----- opac/opac-shelves.pl | 4 +- virtualshelves/shelves.pl | 3 +- 17 files changed, 220 insertions(+), 239 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 6303c86824..69ac19a2d8 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -305,31 +305,32 @@ sub transferbook { my ( $tbr, $barcode, $ignoreRs ) = @_; my $messages; my $dotransfer = 1; - my $itemnumber = GetItemnumberFromBarcode( $barcode ); - my $issue = Koha::Checkouts->find({ itemnumber => $itemnumber }); - my $biblio = GetBiblioFromItemNumber($itemnumber); + my $item = Koha::Items->find( { barcode => $barcode } ); # bad barcode.. - if ( not $itemnumber ) { + unless ( $item ) { $messages->{'BadBarcode'} = $barcode; $dotransfer = 0; } + my $itemnumber = $item->itemnumber; + my $issue = GetOpenIssue($itemnumber); # get branches of book... - my $hbr = $biblio->{'homebranch'}; - my $fbr = $biblio->{'holdingbranch'}; + my $hbr = $item->homebranch; + my $fbr = $item->holdingbranch; # if using Branch Transfer Limits if ( C4::Context->preference("UseBranchTransferLimits") == 1 ) { + my $code = C4::Context->preference("BranchTransferLimitsType") eq 'ccode' ? $item->ccode : $item->biblio->biblioitem->itemtype; # BranchTransferLimitsType is 'ccode' or 'itemtype' if ( C4::Context->preference("item-level_itypes") && C4::Context->preference("BranchTransferLimitsType") eq 'itemtype' ) { - if ( ! IsBranchTransferAllowed( $tbr, $fbr, $biblio->{'itype'} ) ) { - $messages->{'NotAllowed'} = $tbr . "::" . $biblio->{'itype'}; + if ( ! IsBranchTransferAllowed( $tbr, $fbr, $item->itype ) ) { + $messages->{'NotAllowed'} = $tbr . "::" . $item->itype; $dotransfer = 0; } - } elsif ( ! IsBranchTransferAllowed( $tbr, $fbr, $biblio->{ C4::Context->preference("BranchTransferLimitsType") } ) ) { - $messages->{'NotAllowed'} = $tbr . "::" . $biblio->{ C4::Context->preference("BranchTransferLimitsType") }; + } elsif ( ! IsBranchTransferAllowed( $tbr, $fbr, $code ) ) { + $messages->{'NotAllowed'} = $tbr . "::" . $code; $dotransfer = 0; - } + } } # if is permanent... @@ -373,7 +374,7 @@ sub transferbook { } ModDateLastSeen( $itemnumber ); - return ( $dotransfer, $messages, $biblio ); + return ( $dotransfer, $messages ); } @@ -672,7 +673,7 @@ sub CanBookBeIssued { my $onsite_checkout = $params->{onsite_checkout} || 0; my $override_high_holds = $params->{override_high_holds} || 0; - my $item = GetItem(GetItemnumberFromBarcode( $barcode )); + my $item = GetItem(undef, $barcode ); my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } ); my $biblioitem = GetBiblioItemData($item->{biblioitemnumber}); $item->{'itemtype'}=$item->{'itype'}; @@ -1146,8 +1147,8 @@ sub CanBookBeReturned { sub checkHighHolds { my ( $item, $borrower ) = @_; - my $biblio = GetBiblioFromItemNumber( $item->{itemnumber} ); my $branch = _GetCircControlBranch( $item, $borrower ); + my $item_object = Koha::Items->find( $item->{itemnumber} ); my $return_data = { exceeded => 0, @@ -1206,11 +1207,7 @@ sub checkHighHolds { my $calendar = Koha::Calendar->new( branchcode => $branch ); - my $itype = - ( C4::Context->preference('item-level_itypes') ) - ? $biblio->{'itype'} - : $biblio->{'itemtype'}; - + my $itype = $item_object->effective_itemtype; my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branch, $borrower ); my $decreaseLoanHighHoldsDuration = C4::Context->preference('decreaseLoanHighHoldsDuration'); @@ -1299,15 +1296,13 @@ sub AddIssue { # find which item we issue my $item = GetItem( '', $barcode ) or return; # if we don't get an Item, abort. + my $item_object = Koha::Items->find( { barcode => $barcode } ); my $branch = _GetCircControlBranch( $item, $borrower ); # get actual issuing if there is one my $actualissue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } ); - # get biblioinformation for this item - my $biblio = GetBiblioFromItemNumber( $item->{itemnumber} ); - # check if we just renew the issue. if ( $actualissue and $actualissue->borrowernumber eq $borrower->{'borrowernumber'} and not $switch_onsite_checkout ) { @@ -1360,10 +1355,7 @@ sub AddIssue { # Record in the database the fact that the book was issued. unless ($datedue) { - my $itype = - ( C4::Context->preference('item-level_itypes') ) - ? $biblio->{'itype'} - : $biblio->{'itemtype'}; + my $itype = $item_object->effective_itemtype; $datedue = CalcDateDue( $issuedate, $itype, $branch, $borrower ); } @@ -1464,7 +1456,7 @@ sub AddIssue { logaction( "CIRCULATION", "ISSUE", $borrower->{'borrowernumber'}, - $biblio->{'itemnumber'} + $item->{'itemnumber'} ) if C4::Context->preference("IssueLog"); } return $issue; @@ -1862,7 +1854,6 @@ sub AddReturn { } # full item data, but no borrowernumber or checkout info (no issue) - # we know GetItem should work because GetItemnumberFromBarcode worked my $hbr = GetBranchItemRule($item->{'homebranch'}, $item->{'itype'})->{'returnbranch'} || "homebranch"; # get the proper branch to which to return the item my $returnbranch = $item->{$hbr} || $branch ; @@ -2823,7 +2814,8 @@ sub AddRenewal { my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd(); my $item = GetItem($itemnumber) or return; - my $biblio = GetBiblioFromItemNumber($itemnumber) or return; + my $item_object = Koha::Items->find( $itemnumber ); # Should replace $item + my $biblio = $item_object->biblio; my $dbh = C4::Context->dbh; @@ -2851,8 +2843,7 @@ sub AddRenewal { # based on the value of the RenewalPeriodBase syspref. unless ($datedue) { - my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'}; - + my $itemtype = $item_object->effective_itemtype; $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? dt_from_string( $issue->date_due, 'sql' ) : DateTime->now( time_zone => C4::Context->tz()); @@ -2870,14 +2861,13 @@ sub AddRenewal { $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber ); # Update the renewal count on the item, and tell zebra to reindex - $renews = $biblio->{'renewals'} + 1; - ModItem({ renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $biblio->{'biblionumber'}, $itemnumber); + $renews = $item->{renewals} + 1; + ModItem({ renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber); # Charge a new rental fee, if applicable? my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); if ( $charge > 0 ) { my $accountno = getnextacctno( $borrowernumber ); - my $item = GetBiblioFromItemNumber($itemnumber); my $manager_id = 0; $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; $sth = $dbh->prepare( @@ -2887,7 +2877,7 @@ sub AddRenewal { VALUES (now(),?,?,?,?,?,?,?,?)" ); $sth->execute( $borrowernumber, $accountno, $charge, $manager_id, - "Renewal of Rental Item $item->{'title'} $item->{'barcode'}", + "Renewal of Rental Item " . $item_object->title . " $item->{'barcode'}", 'Rent', $charge, $itemnumber ); } @@ -3708,9 +3698,10 @@ sub ProcessOfflineOperation { sub ProcessOfflineReturn { my $operation = shift; - my $itemnumber = C4::Items::GetItemnumberFromBarcode( $operation->{barcode} ); + my $item = Koha::Items->find({barcode => $operation->{barcode}}); - if ( $itemnumber ) { + if ( $item ) { + my $itemnumber = $item->itemnumber; my $issue = GetOpenIssue( $itemnumber ); if ( $issue ) { MarkIssueReturned( @@ -3739,10 +3730,11 @@ sub ProcessOfflineIssue { my $borrower = C4::Members::GetMember( cardnumber => $operation->{cardnumber} ); if ( $borrower->{borrowernumber} ) { - my $itemnumber = C4::Items::GetItemnumberFromBarcode( $operation->{barcode} ); - unless ($itemnumber) { + my $item = Koha::Items->find({ barcode => $operation->{barcode} }); + unless ($item) { return "Barcode not found."; } + my $itemnumber = $item->itemnumber; my $issue = GetOpenIssue( $itemnumber ); if ( $issue and ( $issue->{borrowernumber} ne $borrower->{borrowernumber} ) ) { # Item already issued to another borrower, mark it returned diff --git a/C4/Members.pm b/C4/Members.pm index df5ac26fe2..73f3383018 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -827,9 +827,10 @@ sub GetMemberAccountRecords { my $total = 0; while ( my $data = $sth->fetchrow_hashref ) { if ( $data->{itemnumber} ) { - my $biblio = GetBiblioFromItemNumber( $data->{itemnumber} ); - $data->{biblionumber} = $biblio->{biblionumber}; - $data->{title} = $biblio->{title}; + my $item = Koha::Items->find( $data->{itemnumber} ); + my $biblio = $item->biblio; + $data->{biblionumber} = $biblio->biblionumber; + $data->{title} = $biblio->title; } $acctlines[$numlines] = $data; $numlines++; @@ -908,9 +909,10 @@ sub GetBorNotifyAcctRecord { my $total = 0; while ( my $data = $sth->fetchrow_hashref ) { if ( $data->{itemnumber} ) { - my $biblio = GetBiblioFromItemNumber( $data->{itemnumber} ); - $data->{biblionumber} = $biblio->{biblionumber}; - $data->{title} = $biblio->{title}; + my $item = Koha::Items->find( $data->{itemnumber} ); + my $biblio = $item->biblio; + $data->{biblionumber} = $biblio->biblionumber; + $data->{title} = $biblio->title; } $acctlines[$numlines] = $data; $numlines++; diff --git a/C4/SIP/ILS/Item.pm b/C4/SIP/ILS/Item.pm index 922c24c302..49611d7071 100644 --- a/C4/SIP/ILS/Item.pm +++ b/C4/SIP/ILS/Item.pm @@ -26,6 +26,7 @@ use Koha::Database; use Koha::Biblios; use Koha::Checkouts; use Koha::Patrons; +use Koha::Items; =encoding UTF-8 @@ -71,37 +72,34 @@ use Koha::Patrons; sub new { my ($class, $item_id) = @_; my $type = ref($class) || $class; - my $self; - my $itemnumber = GetItemnumberFromBarcode($item_id); - my $item = GetBiblioFromItemNumber($itemnumber); # actually biblio.*, biblioitems.* AND items.* (overkill) - if (! $item) { + my $item = Koha::Items->find( { barcode => $item_id } ); + unless ( $item ) { syslog("LOG_DEBUG", "new ILS::Item('%s'): not found", $item_id); warn "new ILS::Item($item_id) : No item '$item_id'."; return; } - $item->{ 'itemnumber' } = $itemnumber; - $item->{ 'id' } = $item->{barcode}; # to SIP, the barcode IS the id. - $item->{permanent_location}= $item->{homebranch}; - $item->{'collection_code'} = $item->{ccode}; - $item->{ 'call_number' } = $item->{itemcallnumber}; + my $self = $item->unblessed; + $self->{ 'id' } = $item->barcode; # to SIP, the barcode IS the id. + $self->{permanent_location}= $item->homebranch; + $self->{'collection_code'} = $item->ccode; + $self->{ 'call_number' } = $item->itemcallnumber; - my $it = C4::Context->preference('item-level_itypes') ? $item->{itype} : $item->{itemtype}; + my $it = $item->effective_itemtype; my $itemtype = Koha::Database->new()->schema()->resultset('Itemtype')->find( $it ); - $item->{sip_media_type} = $itemtype->sip_media_type() if $itemtype; + $self->{sip_media_type} = $itemtype->sip_media_type() if $itemtype; # check if its on issue and if so get the borrower - my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } ); + my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } ); if ($issue) { - $item->{due_date} = dt_from_string( $issue->date_due, 'sql' )->truncate( to => 'minute' ); + $self->{due_date} = dt_from_string( $issue->date_due, 'sql' )->truncate( to => 'minute' ); } my $borrower = $issue ? GetMember( borrowernumber => $issue->borrowernumber ) : {}; - $item->{patron} = $borrower->{'cardnumber'}; - my $biblio = Koha::Biblios->find( $item->{biblionumber } ); + $self->{patron} = $borrower->{'cardnumber'}; + my $biblio = Koha::Biblios->find( $self->{biblionumber} ); my $holds = $biblio->current_holds->unblessed; - $item->{hold_queue} = $holds; - $item->{hold_shelf} = [( grep { defined $_->{found} and $_->{found} eq 'W' } @{$item->{hold_queue}} )]; - $item->{pending_queue} = [( grep {(! defined $_->{found}) or $_->{found} ne 'W' } @{$item->{hold_queue}} )]; - $self = $item; + $self->{hold_queue} = $holds; + $self->{hold_shelf} = [( grep { defined $_->{found} and $_->{found} eq 'W' } @{$self->{hold_queue}} )]; + $self->{pending_queue} = [( grep {(! defined $_->{found}) or $_->{found} ne 'W' } @{$self->{hold_queue}} )]; bless $self, $type; syslog("LOG_DEBUG", "new ILS::Item('%s'): found with title '%s'", diff --git a/C4/SIP/ILS/Transaction/Hold.pm b/C4/SIP/ILS/Transaction/Hold.pm index da3ad83da3..50bc914da1 100644 --- a/C4/SIP/ILS/Transaction/Hold.pm +++ b/C4/SIP/ILS/Transaction/Hold.pm @@ -3,17 +3,15 @@ package C4::SIP::ILS::Transaction::Hold; -use warnings; -use strict; +use Modern::Perl; use C4::SIP::ILS::Transaction; use C4::Reserves; # AddReserve use C4::Members; # GetMember -use C4::Biblio; # GetBiblioFromItemNumber GetBiblioItemByBiblioNumber use parent qw(C4::SIP::ILS::Transaction); - +use Koha::Items; my %fields = ( expiration_date => 0, @@ -49,8 +47,8 @@ sub do_hold { $self->ok(0); return $self; } - my $bib = GetBiblioFromItemNumber( undef, $self->{item}->id ); - unless ($bib) { + my $item = Koha::Items->find({ barcode => $self->{item}->id }); + unless ($item) { $self->screen_msg( 'No biblio record matches barcode "' . $self->{item}->id . '".' ); $self->ok(0); return $self; @@ -61,8 +59,7 @@ sub do_hold { $self->ok(0); return $self; } - my $bibno = $bib->{biblionumber}; - AddReserve( $branch, $borrower->{borrowernumber}, $bibno, GetBiblioItemByBiblioNumber($bibno) ); + AddReserve( $branch, $borrower->{borrowernumber}, $item->biblionumber ); # unfortunately no meaningful return value $self->ok(1); @@ -82,10 +79,10 @@ sub drop_hold { $self->ok(0); return $self; } - my $bib = GetBiblioFromItemNumber(undef, $self->{item}->id); + my $item = Koha::Items->find({ barcode => $self->{item}->id }); CancelReserve({ - biblionumber => $bib->{biblionumber}, + biblionumber => $item->biblionumber, itemnumber => $self->{item}->id, borrowernumber => $borrower->{borrowernumber} }); @@ -107,8 +104,8 @@ sub change_hold { $self->ok(0); return $self; } - my $bib = GetBiblioFromItemNumber(undef, $self->{item}->id); - unless ($bib) { + my $item = Koha::Items->find({ barcode => $self->{item}->id }); + unless ($item) { $self->screen_msg('No biblio record matches barcode "' . $self->{item}->id . '".'); $self->ok(0); return $self; @@ -119,8 +116,7 @@ sub change_hold { $self->ok(0); return $self; } - my $bibno = $bib->{biblionumber}; - ModReserve({ biblionumber => $bibno, borrowernumber => $borrower->{borrowernumber}, branchcode => $branch }); + ModReserve({ biblionumber => $item->biblionumber, borrowernumber => $borrower->{borrowernumber}, branchcode => $branch }); $self->ok(1); return $self; diff --git a/catalogue/issuehistory.pl b/catalogue/issuehistory.pl index a3e349d260..d4774c8367 100755 --- a/catalogue/issuehistory.pl +++ b/catalogue/issuehistory.pl @@ -24,7 +24,7 @@ use C4::Auth; use C4::Output; use C4::Circulation; # GetBiblioIssues -use C4::Biblio; # GetBiblio GetBiblioFromItemNumber +use C4::Biblio; # GetBiblio use C4::Search; # enabled_staff_search_views my $query = new CGI; diff --git a/cataloguing/moveitem.pl b/cataloguing/moveitem.pl index 79736a6034..37c9a5e41e 100755 --- a/cataloguing/moveitem.pl +++ b/cataloguing/moveitem.pl @@ -34,6 +34,9 @@ use C4::Acquisition qw/GetOrderFromItemnumber ModOrder GetOrder/; use Date::Calc qw(Today); use MARC::File::XML; + +use Koha::Items; + my $query = CGI->new; # The biblio to move the item to @@ -61,19 +64,15 @@ $template->param(biblionumber => $biblionumber); # If we already have the barcode of the item to move and the biblionumber to move the item to if ($barcode && $biblionumber) { - - # We get his itemnumber - my $itemnumber = GetItemnumberFromBarcode($barcode); - if ($itemnumber) { - # And then, we get the item - my $item = GetItem($itemnumber); + my $itemnumber; + my $item = Koha::Items->find({ barcode => $barcode }); + + if ($item) { - if ($item) { + $itemnumber = $item->itemnumber; + my $frombiblionumber = $item->biblionumber; - my $results = GetBiblioFromItemNumber($itemnumber, $barcode); - my $frombiblionumber = $results->{'biblionumber'}; - my $moveresult = MoveItemFromBiblio($itemnumber, $frombiblionumber, $biblionumber); if ($moveresult) { $template->param(success => 1); @@ -87,11 +86,6 @@ if ($barcode && $biblionumber) { $template->param(error => 1, errornoitem => 1); } - } else { - $template->param(error => 1, - errornoitemnumber => 1); - - } $template->param( barcode => $barcode, itemnumber => $itemnumber, diff --git a/circ/branchtransfers.pl b/circ/branchtransfers.pl index 0022e27e53..87104c22fd 100755 --- a/circ/branchtransfers.pl +++ b/circ/branchtransfers.pl @@ -33,6 +33,7 @@ use C4::Koha; use C4::Members; use Koha::BiblioFrameworks; use Koha::AuthorisedValues; +use Koha::Items; ############################################### # Getting state @@ -112,32 +113,28 @@ defined $barcode and $barcode =~ s/^\s*|\s*$//g; # FIXME: barcodeInputFilter # warn "barcode : $barcode"; if ($barcode) { - my $iteminformation; - ( $transfered, $messages, $iteminformation ) = + ( $transfered, $messages ) = transferbook( $tobranchcd, $barcode, $ignoreRs ); -# use Data::Dumper; -# warn "Transfered : $transfered / ".Dumper($messages); + my $item = Koha::Items->find({ barcode => $barcode }); $found = $messages->{'ResFound'}; if ($transfered) { my %item; + my $biblio = $item->biblio; my $frbranchcd = C4::Context->userenv->{'branch'}; -# if ( not($found) ) { - $item{'biblionumber'} = $iteminformation->{'biblionumber'}; - $item{'itemnumber'} = $iteminformation->{'itemnumber'}; - $item{'title'} = $iteminformation->{'title'}; - $item{'author'} = $iteminformation->{'author'}; - $item{'itemtype'} = $iteminformation->{'itemtype'}; - $item{'ccode'} = $iteminformation->{'ccode'}; - $item{'itemcallnumber'} = $iteminformation->{'itemcallnumber'}; - my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $iteminformation->{location} }); + $item{'biblionumber'} = $item->biblionumber; + $item{'itemnumber'} = $item->itemnumber; + $item{'title'} = $biblio->title; + $item{'author'} = $biblio->author; + $item{'itemtype'} = $biblio->biblioitem->itemtype; + $item{'ccode'} = $item->ccode; + $item{'itemcallnumber'} = $item->itemcallnumber; + my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $item->location }); $item{'location'} = $av->count ? $av->next->lib : ''; -# } $item{counter} = 0; $item{barcode} = $barcode; $item{frombrcd} = $frbranchcd; $item{tobrcd} = $tobranchcd; push( @trsfitemloop, \%item ); -# warn Dumper(@trsfitemloop); } } @@ -153,15 +150,16 @@ foreach ( $query->param ) { $item{barcode} = $bc; $item{frombrcd} = $frbcd; $item{tobrcd} = $tobcd; - my ($iteminformation) = GetBiblioFromItemNumber( GetItemnumberFromBarcode($bc) ); - $item{'biblionumber'} = $iteminformation->{'biblionumber'}; - $item{'itemnumber'} = $iteminformation->{'itemnumber'}; - $item{'title'} = $iteminformation->{'title'}; - $item{'author'} = $iteminformation->{'author'}; - $item{'itemtype'} = $iteminformation->{'itemtype'}; - $item{'ccode'} = $iteminformation->{'ccode'}; - $item{'itemcallnumber'} = $iteminformation->{'itemcallnumber'}; - my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $iteminformation->{location} }); + my $item = Koha::Items->find({ barcode => $bc }); + my $biblio = $item->biblio; + $item{'biblionumber'} = $item->biblionumber; + $item{'itemnumber'} = $item->itemnumber; + $item{'title'} = $biblio->title; + $item{'author'} = $biblio->author; + $item{'itemtype'} = $biblio->biblioitem->itemtype; + $item{'ccode'} = $item->ccode; + $item{'itemcallnumber'} = $item->itemcallnumber; + my $av = Koha::AuthorisedValues->search({ category => 'LOC', authorised_value => $item->location }); $item{'location'} = $av->count ? $av->next->lib : ''; push( @trsfitemloop, \%item ); } diff --git a/circ/returns.pl b/circ/returns.pl index 991bf68cf8..ddced56afb 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -52,6 +52,7 @@ use Koha::DateUtils; use Koha::Calendar; use Koha::BiblioFrameworks; use Koha::Checkouts; +use Koha::Items; use Koha::Patrons; my $query = new CGI; @@ -146,14 +147,14 @@ if ($query->param('WT-itemNumber')){ } if ( $query->param('reserve_id') ) { - my $item = $query->param('itemnumber'); + my $itemnumber = $query->param('itemnumber'); my $borrowernumber = $query->param('borrowernumber'); my $reserve_id = $query->param('reserve_id'); my $diffBranchReturned = $query->param('diffBranch'); - my $iteminfo = GetBiblioFromItemNumber($item); my $cancel_reserve = $query->param('cancel_reserve'); # fix up item type for display - $iteminfo->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $iteminfo->{'itype'} : $iteminfo->{'itemtype'}; + my $item = Koha::Items->find( $itemnumber ); + my $biblio = $item->biblio; if ( $cancel_reserve ) { CancelReserve({ reserve_id => $reserve_id, charge_cancel_fee => !$forgivemanualholdsexpire }); @@ -161,19 +162,19 @@ if ( $query->param('reserve_id') ) { my $diffBranchSend = ($userenv_branch ne $diffBranchReturned) ? $diffBranchReturned : undef; # diffBranchSend tells ModReserveAffect whether document is expected in this library or not, # i.e., whether to apply waiting status - ModReserveAffect( $item, $borrowernumber, $diffBranchSend, $reserve_id ); + ModReserveAffect( $itemnumber, $borrowernumber, $diffBranchSend, $reserve_id ); } # check if we have other reserves for this document, if we have a return send the message of transfer - my ( $messages, $nextreservinfo ) = GetOtherReserves($item); + my ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber); my $borr = GetMember( borrowernumber => $nextreservinfo ); my $name = $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'}; if ( $messages->{'transfert'} ) { $template->param( - itemtitle => $iteminfo->{'title'}, - itemnumber => $iteminfo->{'itemnumber'}, - itembiblionumber => $iteminfo->{'biblionumber'}, - iteminfo => $iteminfo->{'author'}, + itemtitle => $biblio->title, + itemnumber => $item->itemnumber, + itembiblionumber => $biblio->biblionumber, + iteminfo => $biblio->author, name => $name, borrowernumber => $borrowernumber, borcnum => $borr->{'cardnumber'}, @@ -256,20 +257,11 @@ my $returnbranch; if ($barcode) { $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace $barcode = barcodedecode($barcode) if C4::Context->preference('itemBarcodeInputFilter'); - $itemnumber = GetItemnumberFromBarcode($barcode); - -# -# save the return -# - - # get biblio description - my $biblio = GetBiblioFromItemNumber($itemnumber); - # fix up item type for display - $biblio->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $biblio->{'itype'} : $biblio->{'itemtype'}; + my $item = Koha::Items->find({ barcode => $barcode }); # Check if we should display a checkin message, based on the the item # type of the checked in item - my $itemtype = Koha::ItemTypes->find( $biblio->{'itemtype'} ); + my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype ); if ( $itemtype && $itemtype->checkinmsg ) { $template->param( checkinmsg => $itemtype->checkinmsg, @@ -278,26 +270,27 @@ if ($barcode) { } # make sure return branch respects home branch circulation rules, default to homebranch - my $hbr = GetBranchItemRule($biblio->{'homebranch'}, $itemtype ? $itemtype->itemtype : undef )->{'returnbranch'} || "homebranch"; - $returnbranch = $biblio->{$hbr}; + my $hbr = GetBranchItemRule($item->homebranch, $itemtype ? $itemtype->itemtype : undef )->{'returnbranch'} || "homebranch"; + $returnbranch = $item->$hbr; - my $materials = $biblio->{'materials'}; + my $materials = $item->materials; my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials }); $materials = $descriptions->{lib} // $materials; my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ); + my $biblio = $item->biblio; $template->param( - title => $biblio->{'title'}, - homebranch => $biblio->{'homebranch'}, - holdingbranch => $biblio->{'holdingbranch'}, + title => $biblio->title, + homebranch => $item->homebranch, + holdingbranch => $item->holdingbranch, returnbranch => $returnbranch, - author => $biblio->{'author'}, - itembarcode => $biblio->{'barcode'}, - itemtype => $biblio->{'itemtype'}, - ccode => $biblio->{'ccode'}, - itembiblionumber => $biblio->{'biblionumber'}, - biblionumber => $biblio->{'biblionumber'}, + author => $biblio->author, + itembarcode => $item->barcode, + itemtype => $item->effective_itemtype, + ccode => $item->ccode, + itembiblionumber => $biblio->biblionumber, + biblionumber => $biblio->biblionumber, borrower => $borrower, additional_materials => $materials, issue => $issue, @@ -595,25 +588,23 @@ foreach ( sort { $a <=> $b } keys %returneditems ) { $ri{borrowernumber} = $riborrowernumber{$_}; } - # my %ri; - my $biblio = GetBiblioFromItemNumber(GetItemnumberFromBarcode($bar_code)); - my $item = GetItem( GetItemnumberFromBarcode($bar_code) ); - # fix up item type for display - $biblio->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $biblio->{'itype'} : $biblio->{'itemtype'}; - $ri{itembiblionumber} = $biblio->{'biblionumber'}; - $ri{itemtitle} = $biblio->{'title'}; - $ri{itemauthor} = $biblio->{'author'}; - $ri{itemcallnumber} = $biblio->{'itemcallnumber'}; - $ri{dateaccessioned} = $item->{dateaccessioned}; - $ri{itemtype} = $biblio->{'itemtype'}; - $ri{itemnote} = $biblio->{'itemnotes'}; - $ri{itemnotes_nonpublic} = $item->{'itemnotes_nonpublic'}; - $ri{ccode} = $biblio->{'ccode'}; - $ri{enumchron} = $biblio->{'enumchron'}; - $ri{itemnumber} = $biblio->{'itemnumber'}; + my $item = Koha::Items->find({ barcode => $bar_code }); + my $biblio = $item->biblio; + # FIXME pass $item to the template and we are done here... + $ri{itembiblionumber} = $biblio->biblionumber; + $ri{itemtitle} = $biblio->title; + $ri{itemauthor} = $biblio->author; + $ri{itemcallnumber} = $item->itemcallnumber; + $ri{dateaccessioned} = $item->dateaccessioned; + $ri{itemtype} = $item->effective_itemtype; + $ri{itemnote} = $item->itemnotes; + $ri{itemnotes_nonpublic} = $item->itemnotes_nonpublic; + $ri{ccode} = $item->ccode; + $ri{enumchron} = $item->enumchron; + $ri{itemnumber} = $item->itemnumber; $ri{barcode} = $bar_code; - $ri{homebranch} = $item->{'homebranch'}; - $ri{holdingbranch} = $item->{'holdingbranch'}; + $ri{homebranch} = $item->homebranch; + $ri{holdingbranch} = $item->holdingbranch; $ri{location} = $biblio->{'location'}; my $shelfcode = $ri{'location'}; diff --git a/circ/transferstoreceive.pl b/circ/transferstoreceive.pl index 60bcd8bf77..1ef3f0c3a5 100755 --- a/circ/transferstoreceive.pl +++ b/circ/transferstoreceive.pl @@ -89,20 +89,29 @@ while ( my $library = $libraries->next ) { $getransf{'messcompa'} = 1; $getransf{'diff'} = $diff; } - my $gettitle = GetBiblioFromItemNumber( $num->{'itemnumber'} ); - my $itemtype = Koha::ItemTypes->find( (C4::Context->preference('item-level_itypes')) ? $gettitle->{'itype'} : $gettitle->{'itemtype'} ); + + my $item = Koha::Items->find( $num->{itemnumber} ); + my $biblio = $item->biblio; + my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype ); $getransf{'datetransfer'} = $num->{'datesent'}; $getransf{'itemtype'} = $itemtype->description; # FIXME Should not it be translated_description? - foreach (qw(title author biblionumber itemnumber barcode homebranch holdingbranch itemcallnumber)) { - $getransf{$_} = $gettitle->{$_}; - } - - my $record = GetMarcBiblio($gettitle->{'biblionumber'}); - $getransf{'subtitle'} = GetRecordValue('subtitle', $record, GetFrameworkCode($gettitle->{'biblionumber'})); + %getransf = ( + %getransf, + title => $biblio->title, + author => $biblio->author, + biblionumber => $biblio->biblionumber, + itemnumber => $item->itemnumber, + barcode => $item->barcode, + homebranch => $item->homebranch, + holdingbranch => $item->holdingbranch, + itemcallnumber => $item->itemcallnumber, + ); + + my $record = GetMarcBiblio($biblio->biblionumber); + $getransf{'subtitle'} = GetRecordValue('subtitle', $record, $biblio->frameworkcode); # we check if we have a reserv for this transfer - my $item = Koha::Items->find( $num->{itemnumber} ); my $holds = $item->current_holds; if ( my $first_hold = $holds->next ) { my $getborrower = C4::Members::GetMember( borrowernumber => $first_hold->borrowernumber ); diff --git a/circ/waitingreserves.pl b/circ/waitingreserves.pl index f781869e47..a3dfd29692 100755 --- a/circ/waitingreserves.pl +++ b/circ/waitingreserves.pl @@ -37,6 +37,7 @@ use C4::Reserves; use C4::Koha; use Koha::DateUtils; use Koha::BiblioFrameworks; +use Koha::Items; use Koha::ItemTypes; my $input = new CGI; @@ -92,34 +93,33 @@ foreach my $num (@getreserves) { next unless ($num->{'waitingdate'} && $num->{'waitingdate'} ne '0000-00-00'); my $itemnumber = $num->{'itemnumber'}; - my $gettitle = GetBiblioFromItemNumber( $itemnumber ); + my $item = Koha::Items->find( $itemnumber ); + my $biblio = $item->biblio; my $borrowernum = $num->{'borrowernumber'}; - my $holdingbranch = $gettitle->{'holdingbranch'}; - my $homebranch = $gettitle->{'homebranch'}; + my $holdingbranch = $item->holdingbranch; + my $homebranch = $item->homebranch; my %getreserv = ( itemnumber => $itemnumber, borrowernum => $borrowernum, ); - # fix up item type for display - $gettitle->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $gettitle->{'itype'} : $gettitle->{'itemtype'}; my $getborrower = GetMember(borrowernumber => $num->{'borrowernumber'}); - my $itemtype = Koha::ItemTypes->find( $gettitle->{'itemtype'} ); # using the fixed up itype/itemtype + my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype ); $getreserv{'waitingdate'} = $num->{'waitingdate'}; my ( $expire_year, $expire_month, $expire_day ) = split (/-/, $num->{'expirationdate'}); my $calcDate = Date_to_Days( $expire_year, $expire_month, $expire_day ); $getreserv{'itemtype'} = $itemtype->description; # FIXME Should not it be translated_description? - $getreserv{'title'} = $gettitle->{'title'}; - $getreserv{'subtitle'} = GetRecordValue('subtitle', GetMarcBiblio($gettitle->{'biblionumber'}), GetFrameworkCode($gettitle->{'biblionumber'})); - $getreserv{'biblionumber'} = $gettitle->{'biblionumber'}; - $getreserv{'barcode'} = $gettitle->{'barcode'}; - $getreserv{'homebranch'} = $gettitle->{'homebranch'}; - $getreserv{'holdingbranch'} = $gettitle->{'holdingbranch'}; - $getreserv{'itemcallnumber'} = $gettitle->{'itemcallnumber'}; - $getreserv{'enumchron'} = $gettitle->{'enumchron'}; - $getreserv{'copynumber'} = $gettitle->{'copynumber'}; + $getreserv{'title'} = $biblio->title; + $getreserv{'subtitle'} = GetRecordValue('subtitle', GetMarcBiblio($biblio->biblionumber), $biblio->frameworkcode); + $getreserv{'biblionumber'} = $biblio->biblionumber; + $getreserv{'barcode'} = $item->barcode; + $getreserv{'homebranch'} = $homebranch; + $getreserv{'holdingbranch'} = $item->holdingbranch; + $getreserv{'itemcallnumber'} = $item->itemcallnumber; + $getreserv{'enumchron'} = $item->enumchron; + $getreserv{'copynumber'} = $item->copynumber; if ( $homebranch ne $holdingbranch ) { $getreserv{'dotransfer'} = 1; } @@ -190,7 +190,7 @@ sub cancel { if ($nextreservinfo) { my %res; my $borrowerinfo = C4::Members::GetMember( borrowernumber => $nextreservinfo ); - my $iteminfo = GetBiblioFromItemNumber($item); + my $title = Koha::Items->find( $item )->biblio->title; if ( $messages->{'transfert'} ) { $res{messagetransfert} = $messages->{'transfert'}; $res{branchcode} = $messages->{'transfert'}; @@ -201,7 +201,7 @@ sub cancel { $res{nextreservsurname} = $borrowerinfo->{'surname'}; $res{nextreservfirstname} = $borrowerinfo->{'firstname'}; $res{nextreservitem} = $item; - $res{nextreservtitle} = $iteminfo->{'title'}; + $res{nextreservtitle} = $title; $res{waiting} = $messages->{'waiting'} ? 1 : 0; return \%res; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/moveitem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/moveitem.tt index f11dc7decc..3e2f10eec0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/moveitem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/moveitem.tt @@ -36,18 +36,14 @@ [% IF ( errornonewitem ) %]ERROR: Unable to create the new item.

[% INCLUDE actions %] [% INCLUDE fail %] +

[% END %] [% IF ( errornoitem ) %]ERROR: Unable to get the item.

[% INCLUDE actions %] [% INCLUDE fail %] - [% END %] - - [% IF ( errornoitemnumber ) %]ERROR: Unable to get the item number from this barcode.

- [% INCLUDE actions %] - [% INCLUDE fail %] - [% END %]

+ [% END %] [% ELSE %] diff --git a/misc/cronjobs/advance_notices.pl b/misc/cronjobs/advance_notices.pl index 2274737aaf..3fc57c5bcb 100755 --- a/misc/cronjobs/advance_notices.pl +++ b/misc/cronjobs/advance_notices.pl @@ -57,6 +57,7 @@ use C4::Members::Messaging; use C4::Overdues; use Koha::DateUtils; use C4::Log; +use Koha::Items; use Koha::Libraries; use Koha::Patrons; @@ -251,7 +252,7 @@ UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { $due_digest->{ $upcoming->{borrowernumber} }->{email} = $from_address; $due_digest->{ $upcoming->{borrowernumber} }->{count}++; } else { - my $biblio = C4::Biblio::GetBiblioFromItemNumber( $upcoming->{'itemnumber'} ); + my $item = Koha::Items->find( $upcoming->{itemnumber} ); my $letter_type = 'DUE'; $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},'0'); my $titles = ""; @@ -265,7 +266,7 @@ UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { my $letter = parse_letter( { letter_code => $letter_type, borrowernumber => $upcoming->{'borrowernumber'}, branchcode => $upcoming->{'branchcode'}, - biblionumber => $biblio->{'biblionumber'}, + biblionumber => $item->biblionumber, itemnumber => $upcoming->{'itemnumber'}, substitute => { 'items.content' => $titles }, message_transport_type => $transport, @@ -285,7 +286,7 @@ UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { $upcoming_digest->{ $upcoming->{borrowernumber} }->{email} = $from_address; $upcoming_digest->{ $upcoming->{borrowernumber} }->{count}++; } else { - my $biblio = C4::Biblio::GetBiblioFromItemNumber( $upcoming->{'itemnumber'} ); + my $item = Koha::Items->find( $upcoming->{itemnumber} ); my $letter_type = 'PREDUE'; $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},$borrower_preferences->{'days_in_advance'}); my $titles = ""; @@ -299,7 +300,7 @@ UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { my $letter = parse_letter( { letter_code => $letter_type, borrowernumber => $upcoming->{'borrowernumber'}, branchcode => $upcoming->{'branchcode'}, - biblionumber => $biblio->{'biblionumber'}, + biblionumber => $item->biblionumber, itemnumber => $upcoming->{'itemnumber'}, substitute => { 'items.content' => $titles }, message_transport_type => $transport, diff --git a/offline_circ/enqueue_koc.pl b/offline_circ/enqueue_koc.pl index 3640c1d1d8..57ae38c86e 100755 --- a/offline_circ/enqueue_koc.pl +++ b/offline_circ/enqueue_koc.pl @@ -32,8 +32,9 @@ use C4::Circulation; use C4::Items; use C4::Members; use C4::Stats; -use Koha::UploadedFiles; use Koha::Checkouts; +use Koha::UploadedFiles; +use Koha::Items; use Date::Calc qw( Add_Delta_Days Date_to_Days ); @@ -190,10 +191,10 @@ sub _get_borrowernumber_from_barcode { return unless $barcode; - my $item = GetBiblioFromItemNumber( undef, $barcode ); - return unless $item->{'itemnumber'}; + my $item = Koha::Items->find({ barcode => $barcode }); + return unless $item; - my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } ); + my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } ); return unless $issue; return $issue->borrowernumber; } diff --git a/offline_circ/list.pl b/offline_circ/list.pl index 4a130ed302..fb550494b4 100755 --- a/offline_circ/list.pl +++ b/offline_circ/list.pl @@ -30,6 +30,8 @@ use C4::Circulation; use C4::Members; use C4::Biblio; +use Koha::Items; + my $query = CGI->new; my ($template, $loggedinuser, $cookie) = get_template_and_user({ @@ -43,9 +45,10 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user({ my $operations = GetOfflineOperations; for (@$operations) { - my $biblio = GetBiblioFromItemNumber(undef, $_->{'barcode'}); - $_->{'bibliotitle'} = $biblio->{'title'}; - $_->{'biblionumber'} = $biblio->{'biblionumber'}; + my $item = Koha::Items->find({ barcode => $_->{barcode} }); + my $biblio = $item->biblio; + $_->{'bibliotitle'} = $biblio->title; + $_->{'biblionumber'} = $biblio->biblionumber; my $borrower = C4::Members::GetMember( cardnumber => $_->{'cardnumber'} ); if ($borrower) { $_->{'borrowernumber'} = $borrower->{'borrowernumber'}; diff --git a/offline_circ/process_koc.pl b/offline_circ/process_koc.pl index 7567dd3148..fa092ffcfa 100755 --- a/offline_circ/process_koc.pl +++ b/offline_circ/process_koc.pl @@ -250,19 +250,20 @@ sub kocIssueItem { $circ->{ 'barcode' } = barcodedecode($circ->{'barcode'}) if( $circ->{'barcode'} && C4::Context->preference('itemBarcodeInputFilter')); my $branchcode = C4::Context->userenv->{branch}; my $borrower = GetMember( 'cardnumber'=>$circ->{ 'cardnumber' } ); - my $item = GetBiblioFromItemNumber( undef, $circ->{ 'barcode' } ); - my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } ); + my $item = Koha::Items->find({ barcode => $circ->{barcode} }); + my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } ); + my $biblio = $item->biblio; if ( $issue ) { ## Item is currently checked out to another person. #warn "Item Currently Issued."; - my $issue = GetOpenIssue( $item->{'itemnumber'} ); # FIXME Hum? That does not make sense, if it's in the issue table, the issue is open (i.e. returndate is null) + my $issue = GetOpenIssue( $item->itemnumber ); # FIXME Hum? That does not make sense, if it's in the issue table, the issue is open (i.e. returndate is null) if ( $issue->{'borrowernumber'} eq $borrower->{'borrowernumber'} ) { ## Issued to this person already, renew it. #warn "Item issued to this member already, renewing."; C4::Circulation::AddRenewal( $issue->{'borrowernumber'}, # borrowernumber - $item->{'itemnumber'}, # itemnumber + $item->itemnumber, # itemnumber undef, # branch undef, # datedue - let AddRenewal calculate it automatically $circ->{'date'}, # issuedate @@ -270,9 +271,9 @@ sub kocIssueItem { push @output, { renew => 1, - title => $item->{ 'title' }, - biblionumber => $item->{'biblionumber'}, - barcode => $item->{ 'barcode' }, + title => $biblio->title, + biblionumber => $biblio->biblionumber, + barcode => $item->barcode, firstname => $borrower->{ 'firstname' }, surname => $borrower->{ 'surname' }, borrowernumber => $borrower->{'borrowernumber'}, @@ -291,9 +292,9 @@ sub kocIssueItem { C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG ); push @output, { issue => 1, - title => $item->{ 'title' }, - biblionumber => $item->{'biblionumber'}, - barcode => $item->{ 'barcode' }, + title => $biblio->title, + biblionumber => $biblio->biblionumber, + barcode => $item->barcode, firstname => $borrower->{ 'firstname' }, surname => $borrower->{ 'surname' }, borrowernumber => $borrower->{'borrowernumber'}, @@ -311,9 +312,9 @@ sub kocIssueItem { C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG ); push @output, { issue => 1, - title => $item->{ 'title' }, - biblionumber => $item->{'biblionumber'}, - barcode => $item->{ 'barcode' }, + title => $biblio->title, + biblionumber => $biblio->biblionumber, + barcode => $item->barcode, firstname => $borrower->{ 'firstname' }, surname => $borrower->{ 'surname' }, borrowernumber => $borrower->{'borrowernumber'}, @@ -326,27 +327,27 @@ sub kocIssueItem { sub kocReturnItem { my ( $circ ) = @_; $circ->{'barcode'} = barcodedecode($circ->{'barcode'}) if( $circ->{'barcode'} && C4::Context->preference('itemBarcodeInputFilter')); - my $item = GetBiblioFromItemNumber( undef, $circ->{ 'barcode' } ); - #warn( Data::Dumper->Dump( [ $circ, $item ], [ qw( circ item ) ] ) ); + my $item = Koha::Items->find({ barcode => $circ->{barcode} }); + my $biblio = $item->biblio; my $borrowernumber = _get_borrowernumber_from_barcode( $circ->{'barcode'} ); if ( $borrowernumber ) { my $borrower = GetMember( 'borrowernumber' => $borrowernumber ); C4::Circulation::MarkIssueReturned( $borrowernumber, - $item->{'itemnumber'}, + $item->itemnumber, undef, $circ->{'date'}, $borrower->{'privacy'} ); - ModItem({ onloan => undef }, $item->{'biblionumber'}, $item->{'itemnumber'}); - ModDateLastSeen( $item->{'itemnumber'} ); + ModItem({ onloan => undef }, $biblio->biblionumber, $item->itemnumber); + ModDateLastSeen( $item->itemnumber ); push @output, { return => 1, - title => $item->{ 'title' }, - biblionumber => $item->{'biblionumber'}, - barcode => $item->{ 'barcode' }, + title => $biblio->title, + biblionumber => $biblio->biblionumber, + barcode => $item->barcode, borrowernumber => $borrower->{'borrowernumber'}, firstname => $borrower->{'firstname'}, surname => $borrower->{'surname'}, @@ -396,10 +397,10 @@ sub _get_borrowernumber_from_barcode { return unless $barcode; - my $item = GetBiblioFromItemNumber( undef, $barcode ); - return unless $item->{'itemnumber'}; + my $item = Koha::Items->find({ barcode => $barcode }); + return unless $item; - my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } ); + my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } ); return unless $issue; return $issue->borrowernumber; } diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index 85bc8e60eb..39aa93cad6 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -30,6 +30,7 @@ use C4::Tags qw( get_tags ); use C4::XSLT; use Koha::Biblioitems; +use Koha::Items; use Koha::ItemTypes; use Koha::Virtualshelves; use Koha::RecordProcessor; @@ -174,9 +175,8 @@ if ( $op eq 'add_form' ) { if( my $barcode = $query->param('barcode') ) { my $item = GetItem( 0, $barcode); if (defined $item && $item->{itemnumber}) { - my $biblio = GetBiblioFromItemNumber( $item->{itemnumber} ); if ( $shelf->can_biblios_be_added( $loggedinuser ) ) { - my $added = eval { $shelf->add_biblio( $biblio->{biblionumber}, $loggedinuser ); }; + my $added = eval { $shelf->add_biblio( $item->{biblionumber}, $loggedinuser ); }; if ($@) { push @messages, { type => 'error', code => ref($@), msg => $@ }; } elsif ( $added ) { diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl index 86b7852b2b..df700839f2 100755 --- a/virtualshelves/shelves.pl +++ b/virtualshelves/shelves.pl @@ -152,8 +152,7 @@ if ( $op eq 'add_form' ) { next if $barcode eq ''; my $item = GetItem( 0, $barcode); if (defined $item && $item->{itemnumber}) { - my $biblio = GetBiblioFromItemNumber( $item->{itemnumber} ); - my $added = eval { $shelf->add_biblio( $biblio->{biblionumber}, $loggedinuser ); }; + my $added = eval { $shelf->add_biblio( $item->{biblionumber}, $loggedinuser ); }; if ($@) { push @messages, { item_barcode => $barcode, type => 'alert', code => ref($@), msg => $@ }; } elsif ( $added ) { -- 2.39.5