+ push @errorloop, { barcode => $barcode, ERR_BARCODE => 1 };
+ }
+ }
+ }
+ $template->param( date => output_pref ( { str => $date, dateformat => 'iso' } ) );
+ $template->param( errorloop => \@errorloop ) if (@errorloop);
+}
+
+# Build inventorylist: used as result list when you do not pass barcodes
+# This list is also used when you want to compare with barcodes
+my ( $inventorylist, $rightplacelist );
+if ( $op && ( !$uploadbarcodes || $compareinv2barcd )) {
+ ( $inventorylist ) = GetItemsForInventory({
+ minlocation => $minlocation,
+ maxlocation => $maxlocation,
+ class_source => $class_source,
+ location => $location,
+ ignoreissued => $ignoreissued,
+ datelastseen => $datelastseen,
+ branchcode => $branchcode,
+ branch => $branch,
+ offset => 0,
+ statushash => $staton,
+ ignore_waiting_holds => $ignore_waiting_holds,
+ itemtypes => \@selected_itemtypes,
+ });
+}
+# Build rightplacelist used to check if a scanned item is in the right place.
+if( @scanned_items ) {
+ ( $rightplacelist ) = GetItemsForInventory({
+ minlocation => $minlocation,
+ maxlocation => $maxlocation,
+ class_source => $class_source,
+ location => $location,
+ ignoreissued => undef,
+ datelastseen => undef,
+ branchcode => $branchcode,
+ branch => $branch,
+ offset => 0,
+ statushash => undef,
+ ignore_waiting_holds => $ignore_waiting_holds,
+ itemtypes => \@selected_itemtypes,
+ });
+ # Convert the structure to a hash on barcode
+ $rightplacelist = {
+ map { $_->{barcode} ? ( $_->{barcode}, $_ ) : (); } @$rightplacelist
+ };
+}
+
+# Report scanned items that are on the wrong place, or have a wrong notforloan
+# status, or are still checked out.
+for ( my $i = 0; $i < @scanned_items; $i++ ) {
+
+ my $item = $scanned_items[$i];
+
+ $item->{notforloancode} = $item->{notforloan}; # save for later use
+ my $fc = $item->{'frameworkcode'} || '';
+
+ # Populating with authorised values description
+ foreach my $field (qw/ location notforloan itemlost damaged withdrawn /) {
+ my $av = Koha::AuthorisedValues->get_description_by_koha_field(
+ { frameworkcode => $fc, kohafield => "items.$field", authorised_value => $item->{$field} } );
+ if ( $av and defined $item->{$field} and defined $av->{lib} ) {
+ $item->{$field} = $av->{lib};
+ }
+ }
+
+ # If we have scanned items with a non-matching notforloan value
+ if( none { $item->{'notforloancode'} eq $_ } @notforloans ) {
+ $item->{problems}->{changestatus} = 1;
+ additemtoresults( $item, $results );
+ }
+
+ # Check for items shelved out of order
+ if ($out_of_order) {
+ unless ( $i == 0 ) {
+ my $previous_item = $scanned_items[ $i - 1 ];
+ if ( $previous_item && $item->{cn_sort} lt $previous_item->{cn_sort} ) {
+ $item->{problems}->{out_of_order} = 1;
+ additemtoresults( $item, $results );