- $strsth="select * from items where items.barcode =? and items.wthdrawn = 1";
- my $qwthdrawn = $dbh->prepare($strsth);
- my @errorloop;
- my $count=0;
- while (my $barcode=<$uploadbarcodes>){
- $barcode =~ s/\r?\n$//;
- if ($qwthdrawn->execute($barcode) &&$qwthdrawn->rows){
- push @errorloop, {'barcode'=>$barcode,'ERR_WTHDRAWN'=>1};
- }else{
- my $item = GetItem('', $barcode);
- if (defined $item && $item->{'itemnumber'}){
- ModItem({ datelastseen => $date }, undef, $item->{'itemnumber'});
- push @brcditems, $item;
- $count++;
- $qonloan->execute($barcode);
- if ($qonloan->rows){
- my $data = $qonloan->fetchrow_hashref;
- my ($doreturn, $messages, $iteminformation, $borrower) =AddReturn($barcode, $data->{homebranch});
- if ($doreturn){
- push @errorloop, {'barcode'=>$barcode,'ERR_ONLOAN_RET'=>1}
- } else {
- push @errorloop, {'barcode'=>$barcode,'ERR_ONLOAN_NOT_RET'=>1}
+ $strsth="select * from items where items.barcode =? and items.withdrawn = 1";
+ my $qwithdrawn = $dbh->prepare($strsth);
+
+ my @barcodes;
+ my @uploadedbarcodes;
+
+ my $sth = $dbh->column_info(undef,undef,"items","barcode");
+ my $barcode_def = $sth->fetchall_hashref('COLUMN_NAME');
+ my $barcode_size = $barcode_def->{barcode}->{COLUMN_SIZE};
+ my $err_length=0;
+ my $err_data=0;
+ my $lines_read=0;
+ if ($uploadbarcodes && length($uploadbarcodes) > 0) {
+ binmode($uploadbarcodes, ":encoding(UTF-8)");
+ while (my $barcode=<$uploadbarcodes>) {
+ my $split_chars = C4::Context->preference('BarcodeSeparators');
+ push @uploadedbarcodes, grep { /\S/ } split( /[$split_chars]/, $barcode );
+ }
+ } else {
+ push @uploadedbarcodes, split(/\s\n/, $input->param('barcodelist') );
+ $uploadbarcodes = $barcodelist;
+ }
+ for my $barcode (@uploadedbarcodes) {
+ next unless $barcode;
+ ++$lines_read;
+ if (length($barcode)>$barcode_size) {
+ $err_length += 1;
+ }
+ my $check_barcode = $barcode;
+ $check_barcode =~ s/\p{Print}//g;
+ if (length($check_barcode)>0) { # Only printable unicode characters allowed.
+ $err_data += 1;
+ }
+ next if length($barcode)>$barcode_size;
+ next if ( length($check_barcode)>0 );
+ push @barcodes,$barcode;
+ }
+ $template->param( LinesRead => $lines_read );
+ 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 {
+ my $item = Koha::Items->find({barcode => $barcode});
+ if ( $item ) {
+ # Modify date last seen for scanned items, remove lost status
+ $item->set({ itemlost => 0, datelastseen => $date_dt })->store;
+ my $item_unblessed = $item->unblessed;
+ $moddatecount++;
+ unless ( $dont_checkin ) {
+ $qonloan->execute($barcode);
+ if ($qonloan->rows){
+ my $data = $qonloan->fetchrow_hashref;
+ my ($doreturn, $messages, $iteminformation, $borrower) =AddReturn($barcode, $data->{homebranch});
+ if( $doreturn ) {
+ $item_unblessed->{onloan} = undef;
+ $item_unblessed->{datelastseen} = dt_from_string;
+ } else {
+ push @errorloop, { barcode => $barcode, ERR_ONLOAN_NOT_RET => 1 };
+ }