View | Details | Raw Unified | Return to bug 18295
Collapse All | Expand All

(-)a/C4/Items.pm (-48 / +3 lines)
Lines 77-83 BEGIN { Link Here
77
	GetItemsLocationInfo
77
	GetItemsLocationInfo
78
	GetHostItemsInfo
78
	GetHostItemsInfo
79
        GetItemnumbersForBiblio
79
        GetItemnumbersForBiblio
80
        get_itemnumbers_of
81
	get_hostitemnumbers_of
80
	get_hostitemnumbers_of
82
        GetItemnumberFromBarcode
81
        GetItemnumberFromBarcode
83
        GetBarcodeFromItemnumber
82
        GetBarcodeFromItemnumber
Lines 1478-1518 sub GetItemnumbersForBiblio { Link Here
1478
    return \@items;
1477
    return \@items;
1479
}
1478
}
1480
1479
1481
=head2 get_itemnumbers_of
1482
1483
  my @itemnumbers_of = get_itemnumbers_of(@biblionumbers);
1484
1485
Given a list of biblionumbers, return the list of corresponding itemnumbers
1486
for each biblionumber.
1487
1488
Return a reference on a hash where keys are biblionumbers and values are
1489
references on array of itemnumbers.
1490
1491
=cut
1492
1493
sub get_itemnumbers_of {
1494
    my @biblionumbers = @_;
1495
1496
    my $dbh = C4::Context->dbh;
1497
1498
    my $query = '
1499
        SELECT itemnumber,
1500
            biblionumber
1501
        FROM items
1502
        WHERE biblionumber IN (?' . ( ',?' x scalar @biblionumbers - 1 ) . ')
1503
    ';
1504
    my $sth = $dbh->prepare($query);
1505
    $sth->execute(@biblionumbers);
1506
1507
    my %itemnumbers_of;
1508
1509
    while ( my ( $itemnumber, $biblionumber ) = $sth->fetchrow_array ) {
1510
        push @{ $itemnumbers_of{$biblionumber} }, $itemnumber;
1511
    }
1512
1513
    return \%itemnumbers_of;
1514
}
1515
1516
=head2 get_hostitemnumbers_of
1480
=head2 get_hostitemnumbers_of
1517
1481
1518
  my @itemnumbers_of = get_hostitemnumbers_of($biblionumber);
1482
  my @itemnumbers_of = get_hostitemnumbers_of($biblionumber);
Lines 1548-1565 sub get_hostitemnumbers_of { Link Here
1548
    foreach my $hostfield ( $marcrecord->field($tag) ) {
1512
    foreach my $hostfield ( $marcrecord->field($tag) ) {
1549
        my $hostbiblionumber = $hostfield->subfield($biblio_s);
1513
        my $hostbiblionumber = $hostfield->subfield($biblio_s);
1550
        my $linkeditemnumber = $hostfield->subfield($item_s);
1514
        my $linkeditemnumber = $hostfield->subfield($item_s);
1551
        my @itemnumbers;
1515
        my $is_from_biblio = Koha::Items->search({ itemnumber => $linkeditemnumber, biblionumber => $hostbiblionumber });
1552
        if ( my $itemnumbers =
1516
        push @returnhostitemnumbers, $linkeditemnumber
1553
            get_itemnumbers_of($hostbiblionumber)->{$hostbiblionumber} )
1517
          if $is_from_biblio;
1554
        {
1555
            @itemnumbers = @$itemnumbers;
1556
        }
1557
        foreach my $itemnumber (@itemnumbers) {
1558
            if ( $itemnumber eq $linkeditemnumber ) {
1559
                push( @returnhostitemnumbers, $itemnumber );
1560
                last;
1561
            }
1562
        }
1563
    }
1518
    }
1564
1519
1565
    return @returnhostitemnumbers;
1520
    return @returnhostitemnumbers;
(-)a/cataloguing/merge.pl (-6 / +7 lines)
Lines 31-36 use C4::Reserves qw/MergeHolds/; Link Here
31
use C4::Acquisition qw/ModOrder GetOrdersByBiblionumber/;
31
use C4::Acquisition qw/ModOrder GetOrdersByBiblionumber/;
32
32
33
use Koha::BiblioFrameworks;
33
use Koha::BiblioFrameworks;
34
use Koha::Items;
34
use Koha::MetadataRecord;
35
use Koha::MetadataRecord;
35
36
36
my $input = new CGI;
37
my $input = new CGI;
Lines 87-100 if ($merge) { Link Here
87
88
88
    # Moving items from the other record to the reference record
89
    # Moving items from the other record to the reference record
89
    foreach my $biblionumber (@biblionumbers) {
90
    foreach my $biblionumber (@biblionumbers) {
90
        my $itemnumbers = get_itemnumbers_of($biblionumber);
91
        my $items = Koha::Items->search({ biblionumber => $biblionumber });
91
        foreach my $itemnumber (@{ $itemnumbers->{$biblionumber} }) {
92
        while ( my $item = $items->next) {
92
        my $res = MoveItemFromBiblio($itemnumber, $biblionumber, $ref_biblionumber);
93
            my $res = MoveItemFromBiblio( $item->itemnumber, $biblionumber, $ref_biblionumber );
93
        if (not defined $res) {
94
            if ( not defined $res ) {
94
            push @notmoveditems, $itemnumber;
95
                push @notmoveditems, $item->itemnumber;
96
            }
95
        }
97
        }
96
    }
98
    }
97
    }
98
    # If some items could not be moved :
99
    # If some items could not be moved :
99
    if (scalar(@notmoveditems) > 0) {
100
    if (scalar(@notmoveditems) > 0) {
100
        my $itemlist = join(' ',@notmoveditems);
101
        my $itemlist = join(' ',@notmoveditems);
(-)a/labels/label-item-search.pl (-20 / +14 lines)
Lines 30-40 use C4::Output qw(output_html_with_http_headers); Link Here
30
use C4::Context;
30
use C4::Context;
31
use C4::Search qw(SimpleSearch);
31
use C4::Search qw(SimpleSearch);
32
use C4::Biblio qw(TransformMarcToKoha);
32
use C4::Biblio qw(TransformMarcToKoha);
33
use C4::Items qw(GetItemInfosOf get_itemnumbers_of);
33
use C4::Items qw(GetItemInfosOf);
34
use C4::Creators::Lib qw(html_table);
34
use C4::Creators::Lib qw(html_table);
35
use C4::Debug;
35
use C4::Debug;
36
use Koha::DateUtils;
37
36
37
use Koha::DateUtils;
38
use Koha::Items;
38
use Koha::ItemTypes;
39
use Koha::ItemTypes;
39
use Koha::SearchEngine::Search;
40
use Koha::SearchEngine::Search;
40
41
Lines 139-166 if ($show_results) { Link Here
139
        push (@results_set, $biblio);
140
        push (@results_set, $biblio);
140
        my $biblionumber = $biblio->{'biblionumber'};
141
        my $biblionumber = $biblio->{'biblionumber'};
141
        #DEBUG Notes: Grab the item numbers associated with this MARC record...
142
        #DEBUG Notes: Grab the item numbers associated with this MARC record...
142
        my $itemnums = get_itemnumbers_of($biblionumber);
143
        my $items = Koha::Items->search({ biblionumber => $biblionumber }, { order_by => { -desc => 'itemnumber' }});
143
        #DEBUG Notes: Retrieve the item data for each number...
144
        #DEBUG Notes: Retrieve the item data for each number...
144
        if (my $iii = $itemnums->{$biblionumber}) {
145
        while ( my $item = $items->next ) {
145
            my $item_results = GetItemInfosOf(@$iii);
146
            #DEBUG Notes: Build an array element 'item' of the correct bib (results) hash which contains item-specific data...
146
            foreach my $item ( keys %$item_results ) {
147
            if ( $item->biblionumber eq $results_set[$i]->{'biblionumber'} ) {
147
                #DEBUG Notes: Build an array element 'item' of the correct bib (results) hash which contains item-specific data...
148
                my $item_data;
148
                if ($item_results->{$item}->{'biblionumber'} eq $results_set[$i]->{'biblionumber'}) {
149
                $item_data->{'_item_number'}      = $item->itemnumber;
149
                    my $item_data;
150
                $item_data->{'_item_call_number'} = ( $item->itemcallnumber || 'NA' );
150
                    $item_data->{'_item_number'} = $item_results->{$item}->{'itemnumber'};
151
                $item_data->{'_date_accessioned'} = $item->dateaccessioned;
151
                    $item_data->{'_item_call_number'} = ($item_results->{$item}->{'itemcallnumber'} ? $item_results->{$item}->{'itemcallnumber'} : 'NA');
152
                $item_data->{'_barcode'}          = ( $item->barcode || 'NA' );
152
                    $item_data->{'_date_accessioned'} = $item_results->{$item}->{'dateaccessioned'};
153
                $item_data->{'_add'}              = $item->itemnumber;
153
                    $item_data->{'_barcode'} = ( $item_results->{$item}->{'barcode'} ? $item_results->{$item}->{'barcode'} : 'NA');
154
                push @row_data, $item_data;
154
                    $item_data->{'_add'} = $item_results->{$item}->{'itemnumber'};
155
                    unshift (@row_data, $item_data);    # item numbers are given to us in descending order by get_itemnumbers_of()...
156
                }
157
            }
155
            }
158
            $results_set[$i]->{'item_table'} = html_table($display_columns, \@row_data);
156
            $results_set[$i]->{'item_table'} = html_table($display_columns, \@row_data);
159
        }
157
        }
160
        else {
161
            # FIXME: Some error trapping code needed
162
            warn sprintf('No item numbers retrieved for biblio number: %s', $biblionumber);
163
        }
164
    }
158
    }
165
159
166
    ( $template, $loggedinuser, $cookie ) = get_template_and_user(
160
    ( $template, $loggedinuser, $cookie ) = get_template_and_user(
(-)a/reserve/request.pl (-5 / +2 lines)
Lines 293-304 foreach my $biblionumber (@biblionumbers) { Link Here
293
    my $fixedRank = $count+1;
293
    my $fixedRank = $count+1;
294
294
295
    my %itemnumbers_of_biblioitem;
295
    my %itemnumbers_of_biblioitem;
296
    my @itemnumbers;
297
296
298
    ## $items is array of 'item' table numbers
297
    ## $items is array of 'item' table numbers
299
    if (my $items = get_itemnumbers_of($biblionumber)->{$biblionumber}){
298
    my $items = Koha::Items->search({ biblionumber => $biblionumber });
300
        @itemnumbers  = @$items;
299
    my @itemnumbers = $items->get_column('itemnumber');
301
    }
302
    my @hostitems = get_hostitemnumbers_of($biblionumber);
300
    my @hostitems = get_hostitemnumbers_of($biblionumber);
303
    if (@hostitems){
301
    if (@hostitems){
304
        $template->param('hostitemsflag' => 1);
302
        $template->param('hostitemsflag' => 1);
305
- 

Return to bug 18295