@@ -, +, @@
---------
is not a text file.
-- a horrible lack of validation and spamminess ensues.
a) One containing valid barcodes on each line
-- this file should trigger no errors.
b) A copy of the first with an extra line of >20 characters
(e.g. The Quick Red Fox Jumped Over The Brown Fence)
-- this file should trigger the singular error message case.
c) A copy of the second with the last line duplicated
-- this file should trigger the plural error message case.
---
.../prog/en/modules/tools/inventory.tt | 4 ++++
tools/inventory.pl | 22 ++++++++++++++++++++
2 files changed, 26 insertions(+)
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt
@@ -96,6 +96,10 @@ $(document).ready(function(){
Inventory/Stocktaking
[% IF (moddatecount) %][% moddatecount %] items modified : datelastseen set to [% date | $KohaDates %]
[% END %]
[% IF (errorfile) %][% errorfile %] can't be opened
[% END %]
+ [% IF (err_length && err_length==1) %]There was 1 barcode that was too long.
[% END %]
+ [% IF (err_length && err_length>1) %]There were [% err_length %] barcodes that were too long.
[% END %]
+ [% IF (err_data && err_data==1) %]There was 1 barcode that contained at least one non-alphanumeric character.
[% END %]
+ [% IF (err_data && err_data>1) %]There were [% err_data %] barcodes that contained at least one non-alphanumeric character.
[% END %]
[% FOREACH error IN errorloop %]
[% error.barcode %]
--- a/tools/inventory.pl
+++ a/tools/inventory.pl
@@ -160,9 +160,31 @@ if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) {
my $count = 0;
+ my @barcodes;
+ my $err_length=0;
+ my $err_data=0;
while (my $barcode=<$uploadbarcodes>){
$barcode =~ s/\r?\n$//;
next unless $barcode;
+ if (length($barcode)>20) {
+ $err_length += 1;
+ }
+ if ($barcode =~ /[^0-9a-zA-Z]/) {
+ $err_data += 1;
+ }
+ next if length($barcode)>20; # 20 is the current length of barcode.
+ next if ( $barcode =~ /[^0-9a-zA-Z]/ ); # Only 0-9a-zA-Z are valid.
+ push @barcodes,$barcode;
+ }
+ if (! @barcodes) {
+ push @errorloop, {'barcode'=>'No valid barcodes!'};
+ $op=''; # force the initial inventory screen again.
+ }
+ else {
+ $template->param( err_length => $err_length,
+ err_data => $err_data );
+ }
+ foreach my $barcode (@barcodes) {
if ( $qwithdrawn->execute($barcode) && $qwithdrawn->rows ) {
push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 };
} else {
--