Merge remote-tracking branch 'origin/new/bug_7178'
authorPaul Poulain <paul.poulain@biblibre.com>
Mon, 14 May 2012 14:18:46 +0000 (16:18 +0200)
committerPaul Poulain <paul.poulain@biblibre.com>
Mon, 14 May 2012 14:18:46 +0000 (16:18 +0200)
1  2 
C4/Items.pm
acqui/neworderempty.pl

diff --combined C4/Items.pm
@@@ -26,11 -26,11 +26,11 @@@ use C4::Context
  use C4::Koha;
  use C4::Biblio;
  use C4::Dates qw/format_date format_date_in_iso/;
 -use C4::Search qw/SimpleSearch/;
  use MARC::Record;
  use C4::ClassSource;
  use C4::Log;
  use List::MoreUtils qw/any/;
 +use C4::Search;
  use Data::Dumper; # used as part of logging item record changes, not just for
                    # debugging; so please don't remove this
  
@@@ -67,7 -67,6 +67,7 @@@ BEGIN 
          GetItemsInfo
        GetItemsLocationInfo
        GetHostItemsInfo
 +        GetItemnumbersForBiblio
          get_itemnumbers_of
        get_hostitemnumbers_of
          GetItemnumberFromBarcode
@@@ -81,6 -80,7 +81,7 @@@
        GetAnalyticsCount
          GetItemHolds
  
+         SearchItems
  
          PrepareItemrecordDisplay
  
@@@ -309,7 -309,7 +310,7 @@@ Sequence number of original item tag i
  Item barcode, provide to assist in the construction of
  useful error messages.
  
 -=item error_condition
 +=item error_code
  
  Code representing the error condition.  Can be 'duplicate_barcode',
  'invalid_homebranch', or 'invalid_holdingbranch'.
@@@ -329,9 -329,6 +330,9 @@@ sub AddItemBatchFromMarc 
      my @errors = ();
      my $dbh = C4::Context->dbh;
  
 +    # We modify the record, so lets work on a clone so we don't change the
 +    # original.
 +    $record = $record->clone();
      # loop through the item tags and start creating items
      my @bad_item_fields = ();
      my ($itemtag, $itemsubfield) = &GetMarcFromKohaField("items.itemnumber",'');
@@@ -1497,26 -1494,6 +1498,26 @@@ sub  GetLastAcquisitions 
        return @results;
  }
  
 +=head2 GetItemnumbersForBiblio
 +
 +  my $itemnumbers = GetItemnumbersForBiblio($biblionumber);
 +
 +Given a single biblionumber, return an arrayref of all the corresponding itemnumbers
 +
 +=cut
 +
 +sub GetItemnumbersForBiblio {
 +    my $biblionumber = shift;
 +    my @items;
 +    my $dbh = C4::Context->dbh;
 +    my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?");
 +    $sth->execute($biblionumber);
 +    while (my $result = $sth->fetchrow_hashref) {
 +        push @items, $result->{'itemnumber'};
 +    }
 +    return \@items;
 +}
 +
  =head2 get_itemnumbers_of
  
    my @itemnumbers_of = get_itemnumbers_of(@biblionumbers);
@@@ -2517,6 -2494,43 +2518,43 @@@ sub GetItemHolds 
      $holds = $sth->fetchrow;
      return $holds;
  }
+ # Return the list of the column names of items table
+ sub _get_items_columns {
+     my $dbh = C4::Context->dbh;
+     my $sth = $dbh->column_info(undef, undef, 'items', '%');
+     $sth->execute;
+     my $results = $sth->fetchall_hashref('COLUMN_NAME');
+     return keys %$results;
+ }
+ =head2 SearchItems
+     my $items = SearchItems($field, $value);
+ SearchItems will search for items on a specific given field.
+ For instance you can search all items with a specific stocknumber like this:
+     my $items = SearchItems('stocknumber', $stocknumber);
+ =cut
+ sub SearchItems {
+     my ($field, $value) = @_;
+     my $dbh = C4::Context->dbh;
+     my @columns = _get_items_columns;
+     my $results = [];
+     if(0 < grep /^$field$/, @columns) {
+         my $query = "SELECT $field FROM items WHERE $field = ?";
+         my $sth = $dbh->prepare( $query );
+         $sth->execute( $value );
+         $results = $sth->fetchall_arrayref({});
+     }
+     return $results;
+ }
  =head1  OTHER FUNCTIONS
  
  =head2 _find_value
@@@ -2600,7 -2614,6 +2638,7 @@@ sub PrepareItemrecordDisplay 
                  $subfield_data{subfield}      = $subfield;
                  $subfield_data{countsubfield} = $cntsubf++;
                  $subfield_data{kohafield}     = $tagslib->{$tag}->{$subfield}->{'kohafield'};
 +                $subfield_data{id}            = "tag_".$tag."_subfield_".$subfield."_".int(rand(1000000));
  
                  #        $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib};
                  $subfield_data{marc_lib}   = $tagslib->{$tag}->{$subfield}->{lib};
                              my $extended_param = plugin_parameters( $dbh, $temp, $tagslib, $subfield_data{id}, undef );
                              my ( $function_name, $javascript ) = plugin_javascript( $dbh, $temp, $tagslib, $subfield_data{id}, undef );
                              $subfield_data{random}     = int(rand(1000000));    # why do we need 2 different randoms?
 -                            my $index_subfield = int(rand(1000000));
 -                            $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield;
                              $subfield_data{marc_value} = qq[<input tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255"
                                  onfocus="Focus$function_name($subfield_data{random}, '$subfield_data{id}');"
                                   onblur=" Blur$function_name($subfield_data{random}, '$subfield_data{id}');" />
diff --combined acqui/neworderempty.pl
@@@ -264,8 -264,6 +264,8 @@@ foreach my $r (@{$budgets}) 
      };
  }
  
 +@{$budget_loop} =
 +  sort { uc( $a->{b_txt}) cmp uc( $b->{b_txt}) } @{$budget_loop};
  
  if ($close) {
      $budget_id      =  $data->{'budget_id'};
@@@ -380,7 -378,7 +380,7 @@@ $template->param
      listprice        => sprintf("%.2f", $data->{'listprice'}||$data->{'price'}||$listprice),
      total            => sprintf("%.2f", ($data->{'ecost'}||0)*($data->{'quantity'}||0) ),
      ecost            => $data->{'ecost'},
-     unitprice        => sprintf("%.2f", $data->{'unitprice'}),
+     unitprice        => sprintf("%.2f", $data->{'unitprice'}||0),
      notes            => $data->{'notes'},
      publishercode    => $data->{'publishercode'},
      barcode_subfield => $barcode_subfield,