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
GetItemsInfo
GetItemsLocationInfo
GetHostItemsInfo
+ GetItemnumbersForBiblio
get_itemnumbers_of
get_hostitemnumbers_of
GetItemnumberFromBarcode
GetAnalyticsCount
GetItemHolds
+ SearchItems
PrepareItemrecordDisplay
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'.
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",'');
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);
$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
$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}');" />
};
}
+@{$budget_loop} =
+ sort { uc( $a->{b_txt}) cmp uc( $b->{b_txt}) } @{$budget_loop};
if ($close) {
$budget_id = $data->{'budget_id'};
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,