From 8663c499e66ec2aaf971c82f2c522f1c73bddca0 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 19 Feb 2018 11:29:04 +0100 Subject: [PATCH] Bug 20206: Find barcodes with more or less leading zeroes Content-Type: text/plain; charset=utf-8 --- koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt | 1 + tools/inventory.pl | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt index 2db78af6bd..5057ed0753 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt @@ -31,6 +31,7 @@
[% error.barcode | html %] [% IF (error.ERR_BARCODE) %]: barcode not found[% END %] + [% IF (error.ERR_DUPLICATE_BARCODES) %]: duplicate barcodes with/without leading zeroes[% END %] [% IF (error.ERR_WTHDRAWN) %]: item withdrawn[% END %] [% IF (error.ERR_ONLOAN_RET) %]: item was on loan. It was returned before marked as seen[% END %] [% IF (error.ERR_ONLOAN_NOT_RET) %]: item was on loan. couldn't be returned.[% END %] diff --git a/tools/inventory.pl b/tools/inventory.pl index 13b7a538a5..a4ecb87589 100755 --- a/tools/inventory.pl +++ b/tools/inventory.pl @@ -197,8 +197,11 @@ if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) { if ( $qwithdrawn->execute($barcode) && $qwithdrawn->rows ) { push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 }; } else { - my $item = Koha::Items->find({barcode => $barcode}); - if ( $item ) { + my $barcode_nz = $barcode; + $barcode_nz =~ s/^0*//; + my $item_rs = Koha::Items->search({barcode => { 'regexp', "^0*${barcode_nz}\$" }}); + if ( $item_rs->count == 1 ) { + my $item = $item_rs->next; # Modify date last seen for scanned items, remove lost status $item->set({ itemlost => 0, datelastseen => $date })->store; my $item_unblessed = $item->unblessed; @@ -217,6 +220,8 @@ if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) { } } push @scanned_items, $item_unblessed; + } elsif( $item_rs->count > 1 ) { # duplicates like 1 and 01 + push @errorloop, { barcode => $barcode_nz, ERR_DUPLICATE_BARCODES => 1 }; } else { push @errorloop, { barcode => $barcode, ERR_BARCODE => 1 }; } -- 2.11.0