Bug 13949 - Item search should have holding library
[koha_ffzg] / tools / inventory.pl
index 015d0be..74069e5 100755 (executable)
@@ -32,7 +32,6 @@ use C4::Output;
 use C4::Biblio;
 use C4::Items;
 use C4::Koha;
-use C4::Branch; # GetBranches
 use C4::Circulation;
 use C4::Reports::Guided;    #_get_column_defs
 use C4::Charset;
@@ -52,6 +51,7 @@ my $branchcode = $input->param('branchcode') || '';
 my $branch     = $input->param('branch');
 my $op         = $input->param('op');
 my $compareinv2barcd = $input->param('compareinv2barcd');
+my $dont_checkin = $input->param('dont_checkin');
 
 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
     {   template_name   => "tools/inventory.tt",
@@ -63,16 +63,6 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
     }
 );
 
-
-my $branches = GetBranches();
-my @branch_loop;
-for my $branch_hash (keys %$branches) {
-    push @branch_loop, {value => "$branch_hash",
-                       branchname => $branches->{$branch_hash}->{'branchname'},
-                       selected => ($branch_hash eq $branchcode?1:0)};
-}
-
-@branch_loop = sort {$a->{branchname} cmp $b->{branchname}} @branch_loop;
 my @authorised_value_list;
 my $authorisedvalue_categories = '';
 
@@ -127,7 +117,6 @@ for my $authvfield (@$statuses) {
 }
 $statussth =~ s, and $,,g;
 $template->param(
-    branchloop               => \@branch_loop,
     authorised_values        => \@authorised_value_list,
     today                    => dt_from_string,
     minlocation              => $minlocation,
@@ -150,7 +139,7 @@ my @scanned_items;
 my @errorloop;
 if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) {
     my $dbh = C4::Context->dbh;
-    my $date = dt_from_string( $input->param('setdate') );
+    my $date = dt_from_string( scalar $input->param('setdate') );
     $date = output_pref ( { dt => $date, dateformat => 'iso' } );
 
     my $strsth  = "select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =?";
@@ -161,6 +150,7 @@ if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) {
     my $count = 0;
 
     my @barcodes;
+    my @uploadedbarcodes;
 
     my $sth = $dbh->column_info(undef,undef,"items","barcode");
     my $barcode_def = $sth->fetchall_hashref('COLUMN_NAME');
@@ -169,8 +159,13 @@ if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) {
     my $err_data=0;
     my $lines_read=0;
     binmode($uploadbarcodes, ":encoding(UTF-8)");
-    while (my $barcode=<$uploadbarcodes>){
-        $barcode =~ s/\r?\n$//;
+    while (my $barcode=<$uploadbarcodes>) {
+        $barcode =~ s/\r/\n/g;
+        $barcode =~ s/\n\n/\n/g;
+        my @data = split(/\n/,$barcode);
+        push @uploadedbarcodes, @data;
+    }
+    for my $barcode (@uploadedbarcodes) {
         next unless $barcode;
         ++$lines_read;
         if (length($barcode)>$barcode_size) {
@@ -203,14 +198,16 @@ if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) {
                 ModItem( { datelastseen => $date }, undef, $item->{'itemnumber'} );
                 push @scanned_items, $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}
+                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){
+                            push @errorloop, {'barcode'=>$barcode,'ERR_ONLOAN_RET'=>1}
+                        } else {
+                            push @errorloop, {'barcode'=>$barcode,'ERR_ONLOAN_NOT_RET'=>1}
+                        }
                     }
                 }
             } else {
@@ -269,11 +266,11 @@ if ( $markseen or $op ) {
 
 # 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)
+    # set "missing" flags for all items with a datelastseen (dls) before the chosen datelastseen (cdls)
     my $dls = output_pref( { dt => dt_from_string( $datelastseen ),
                              dateformat => 'iso' } );
     foreach my $item ( @$inventorylist ) {
-        my $cdls = output_pref( { dt => dt_from_string( $_->{datelastseen} ),
+        my $cdls = output_pref( { dt => dt_from_string( $item->{datelastseen} ),
                                   dateformat => 'iso' } );
         if ( $cdls lt $dls ) {
             $item->{problem} = 'missingitem';
@@ -286,7 +283,7 @@ if ( $compareinv2barcd ) {
 
 
 # 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
+# note this list is always displayed, whatever the librarian has chosen for comparison
 my $moddatecount = 0;
 foreach my $item ( @scanned_items ) {
 
@@ -320,7 +317,7 @@ foreach my $item ( @scanned_items ) {
     }
 
     # Modify date last seen for scanned items
-    ModDateLastSeen($_->{'itemnumber'});
+    ModDateLastSeen($item->{'itemnumber'});
     $moddatecount++;
 }