+
+ }
+
+ $template->param( date => $date, Number => $count );
+ $template->param( errorloop => \@errorloop ) if (@errorloop);
+}
+
+# now build the result list: inventoried items if requested, and mis-placed items -always-
+my $inventorylist;
+my @items_with_problems;
+if ( $markseen or $op ) {
+ # retrieve all items in this range.
+ my $totalrecords;
+ ($inventorylist, $totalrecords) = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, '', $branchcode, $branch, 0, undef , $staton);
+}
+
+# If "compare barcodes list to results" has been checked, we want to alert for missing items
+if ( $compareinv2barcd ) {
+ # set "missing" flags for all items with a datelastseen (dls) before the choosen datelastseen (cdls)
+ my $dls = output_pref( dt_from_string( $datelastseen ), 'iso' );
+ foreach my $item ( @$inventorylist ) {
+ my $cdls = output_pref( dt_from_string( $_->{datelastseen} ), 'iso' );
+ if ( $cdls lt $dls ) {
+ $item->{problem} = 'missingitem';
+ # We have to push a copy of the item, not the reference
+ push @items_with_problems, { %$item };
+ }
+ }
+}
+
+
+
+# insert "wrongplace" to all scanned items that are not supposed to be in this range
+# note this list is always displayed, whatever the librarian has choosen for comparison
+my $moddatecount = 0;
+foreach my $item ( @scanned_items ) {
+
+ # Saving notforloan code before it's replaced by it's authorised value for later comparison
+ $item->{notforloancode} = $item->{notforloan};
+
+ # Populating with authorised values
+ foreach my $field ( keys %$item ) {
+ # If the koha field is mapped to a marc field
+ my $fc = $item->{'frameworkcode'} || '';
+ my ($f, $sf) = GetMarcFromKohaField("items.$field", $fc);
+ if ($f and $sf) {
+ # We replace the code with it's description
+ my $authvals = C4::Koha::GetKohaAuthorisedValuesFromField($f, $sf, $fc);
+ if ($authvals and defined $item->{$field} and defined $authvals->{$item->{$field}}) {
+ $item->{$field} = $authvals->{$item->{$field}};
+ }
+ }