@@ -, +, @@ Koha::Items->find({ barcode => $barcode }); --- C4/ImportBatch.pm | 5 +++-- C4/Items.pm | 6 +++--- circ/returns.pl | 5 +++-- labels/label-edit-batch.pl | 9 +++++---- members/mancredit.pl | 4 +++- members/maninvoice.pl | 4 +++- rotating_collections/addItems.pl | 5 ++++- serials/serials-edit.pl | 9 ++++----- tools/batchMod.pl | 27 ++++++++------------------- 9 files changed, 36 insertions(+), 38 deletions(-) --- a/C4/ImportBatch.pm +++ a/C4/ImportBatch.pm @@ -27,6 +27,7 @@ use C4::Items; use C4::Charset; use C4::AuthoritiesMarc; use C4::MarcModificationTemplates; +use Koha::Items; use Koha::Plugins::Handler; use Koha::Logger; @@ -747,7 +748,7 @@ sub BatchCommitItems { my $item = TransformMarcToKoha( $item_marc ); - my $duplicate_barcode = exists( $item->{'barcode'} ) && GetItemnumberFromBarcode( $item->{'barcode'} ); + my $duplicate_barcode = exists( $item->{'barcode'} ) && Koha::Items->find({ barcode => $item->{'barcode'} }); my $duplicate_itemnumber = exists( $item->{'itemnumber'} ); my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?"); @@ -761,7 +762,7 @@ sub BatchCommitItems { $updsth->finish(); $num_items_replaced++; } elsif ( $action eq "replace" && $duplicate_barcode ) { - my $itemnumber = GetItemnumberFromBarcode( $item->{'barcode'} ); + my $itemnumber = $duplicate_barcode->itemnumber; ModItemFromMarc( $item_marc, $biblionumber, $itemnumber ); $updsth->bind_param( 1, 'imported' ); $updsth->bind_param( 2, $item->{itemnumber} ); --- a/C4/Items.pm +++ a/C4/Items.pm @@ -740,10 +740,10 @@ sub CheckItemPreSave { # check for duplicate barcode if (exists $item_ref->{'barcode'} and defined $item_ref->{'barcode'}) { - my $existing_itemnumber = GetItemnumberFromBarcode($item_ref->{'barcode'}); - if ($existing_itemnumber) { + my $existing_item= Koha::Items->find({barcode => $item_ref->{'barcode'}}); + if ($existing_item) { if (!exists $item_ref->{'itemnumber'} # new item - or $item_ref->{'itemnumber'} != $existing_itemnumber) { # existing item + or $item_ref->{'itemnumber'} != $existing_item->itemnumber) { # existing item $errors{'duplicate_barcode'} = $item_ref->{'barcode'}; } } --- a/circ/returns.pl +++ a/circ/returns.pl @@ -591,8 +591,9 @@ $template->param( AudioAlerts => C4::Context->preference("AudioAlerts"), ); -$itemnumber = GetItemnumberFromBarcode( $barcode ); -if ( $itemnumber ) { +my $item_from_barcode = Koha::Items->find({barcode => $barcode }); # How many times do we fetch this item?!? +if ( $item_from_barcode ) { + $itemnumber = $item_from_barcode->itemnumber; my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber ); if ( $holdingBranch and $collectionBranch ) { $holdingBranch //= ''; --- a/labels/label-edit-batch.pl +++ a/labels/label-edit-batch.pl @@ -25,10 +25,12 @@ use CGI qw ( -utf8 ); use C4::Auth qw(get_template_and_user); use C4::Output qw(output_html_with_http_headers); -use C4::Items qw(GetItem GetItemnumberFromBarcode); +use C4::Items qw(GetItem); use C4::Creators; use C4::Labels; +use Koha::Items; + my $cgi = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { @@ -90,9 +92,8 @@ elsif ($op eq 'add') { push @item_numbers, $number; } elsif ($number_type eq "barcode" ) { # we must test in case an invalid barcode is passed in; we effectively disgard them atm - if( my $item_number = GetItemnumberFromBarcode($number) ){ - push @item_numbers, $item_number; - } + my $item = Koha::Items->find({barcode => $number}); + push @item_numbers, $item->itemnumber if $item; } } } --- a/members/mancredit.pl +++ a/members/mancredit.pl @@ -34,6 +34,7 @@ use C4::Items; use C4::Members::Attributes qw(GetBorrowerAttributes); use Koha::Account; +use Koha::Items; use Koha::Patrons; use Koha::Patron::Categories; use Koha::Token; @@ -67,7 +68,8 @@ if ($add){ my $barcode = $input->param('barcode'); my $item_id; if ($barcode) { - $item_id = GetItemnumberFromBarcode($barcode); + my $item = Koha::Items->find({barcode => $barcode}); + $item_id = $item->itemnumber if $item; } my $description = $input->param('desc'); my $note = $input->param('note'); --- a/members/maninvoice.pl +++ a/members/maninvoice.pl @@ -33,6 +33,7 @@ use C4::Items; use C4::Members::Attributes qw(GetBorrowerAttributes); use Koha::Token; +use Koha::Items; use Koha::Patrons; use Koha::Patron::Categories; @@ -61,7 +62,8 @@ if ($add){ my $barcode=$input->param('barcode'); my $itemnum; if ($barcode) { - $itemnum = GetItemnumberFromBarcode($barcode); + my $item = Koha::Items->find({barcode => $barcode}); + $itemnum = $item->itemnumber if $item; } my $desc=$input->param('desc'); my $amount=$input->param('amount'); --- a/rotating_collections/addItems.pl +++ a/rotating_collections/addItems.pl @@ -24,6 +24,8 @@ use C4::Context; use C4::RotatingCollections; use C4::Items; +use Koha::Items; + use CGI qw ( -utf8 ); my $query = new CGI; @@ -44,7 +46,8 @@ if ( $query->param('action') eq 'addItem' ) { my $colId = $query->param('colId'); my $barcode = $query->param('barcode'); my $removeItem = $query->param('removeItem'); - my $itemnumber = GetItemnumberFromBarcode($barcode); + my $item = Koha::Items->find({barcode => $barcode}); + my $itemnumber = $item ? $item->itemnumber : undef; my ( $success, $errorCode, $errorMessage ); --- a/serials/serials-edit.pl +++ a/serials/serials-edit.pl @@ -72,7 +72,9 @@ use C4::Output; use C4::Context; use C4::Serials; use C4::Search qw/enabled_staff_search_views/; + use Koha::DateUtils; +use Koha::Items; use Koha::Serial::Items; use List::MoreUtils qw/uniq/; @@ -372,11 +374,8 @@ if ( $op and $op eq 'serialchangestatus' ) { ) ) { - $exists = GetItemnumberFromBarcode( - $bib_record->subfield( - $barcodetagfield, $barcodetagsubfield - ) - ); + my $barcode = $bib_record->subfield( $barcodetagfield, $barcodetagsubfield ); + $exists = Koha::Items->find({barcode => $barcode}); } # push @errors,"barcode_not_unique" if($exists); --- a/tools/batchMod.pl +++ a/tools/batchMod.pl @@ -244,15 +244,10 @@ if ($op eq "show"){ @contentlist = uniq @contentlist; if ($filecontent eq 'barcode_file') { - foreach my $barcode (@contentlist) { - - my $itemnumber = GetItemnumberFromBarcode($barcode); - if ($itemnumber) { - push @itemnumbers,$itemnumber; - } else { - push @notfoundbarcodes, $barcode; - } - } + my $existing_items = Koha::Items->search({ itemnumber => \@contentlist })->get_column('itemnumber'); + @itemnumbers = $existing_items->get_column('itemnumber'); + my %exists = map {$_=>1} @{$existing_items->get_column('barcode')}; + @notfoundbarcodes = grep { !$exists{$_} } @contentlist; } elsif ( $filecontent eq 'itemid_file') { @itemnumbers = Koha::Items->search({ itemnumber => \@contentlist })->get_column('itemnumber'); @@ -269,16 +264,10 @@ if ($op eq "show"){ if ( my $list=$input->param('barcodelist')){ push my @barcodelist, uniq( split(/\s\n/, $list) ); - foreach my $barcode (@barcodelist) { - - my $itemnumber = GetItemnumberFromBarcode($barcode); - if ($itemnumber) { - push @itemnumbers,$itemnumber; - } else { - push @notfoundbarcodes, $barcode; - } - } - + my $existing_items = Koha::Items->search({ itemnumber => \@barcodelist })->get_column('itemnumber'); + @itemnumbers = $existing_items->get_column('itemnumber'); + my %exists = map {$_=>1} @{$existing_items->get_column('barcode')}; + @notfoundbarcodes = grep { !$exists{$_} } @barcodelist; } } --