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

(-)a/C4/Items.pm (-48 / +3 lines)
Lines 76-82 BEGIN { Link Here
76
	GetItemsLocationInfo
76
	GetItemsLocationInfo
77
	GetHostItemsInfo
77
	GetHostItemsInfo
78
        GetItemnumbersForBiblio
78
        GetItemnumbersForBiblio
79
        get_itemnumbers_of
80
	get_hostitemnumbers_of
79
	get_hostitemnumbers_of
81
        GetItemnumberFromBarcode
80
        GetItemnumberFromBarcode
82
        GetBarcodeFromItemnumber
81
        GetBarcodeFromItemnumber
Lines 1352-1392 sub GetItemnumbersForBiblio { Link Here
1352
    return \@items;
1351
    return \@items;
1353
}
1352
}
1354
1353
1355
=head2 get_itemnumbers_of
1356
1357
  my @itemnumbers_of = get_itemnumbers_of(@biblionumbers);
1358
1359
Given a list of biblionumbers, return the list of corresponding itemnumbers
1360
for each biblionumber.
1361
1362
Return a reference on a hash where keys are biblionumbers and values are
1363
references on array of itemnumbers.
1364
1365
=cut
1366
1367
sub get_itemnumbers_of {
1368
    my @biblionumbers = @_;
1369
1370
    my $dbh = C4::Context->dbh;
1371
1372
    my $query = '
1373
        SELECT itemnumber,
1374
            biblionumber
1375
        FROM items
1376
        WHERE biblionumber IN (?' . ( ',?' x scalar @biblionumbers - 1 ) . ')
1377
    ';
1378
    my $sth = $dbh->prepare($query);
1379
    $sth->execute(@biblionumbers);
1380
1381
    my %itemnumbers_of;
1382
1383
    while ( my ( $itemnumber, $biblionumber ) = $sth->fetchrow_array ) {
1384
        push @{ $itemnumbers_of{$biblionumber} }, $itemnumber;
1385
    }
1386
1387
    return \%itemnumbers_of;
1388
}
1389
1390
=head2 get_hostitemnumbers_of
1354
=head2 get_hostitemnumbers_of
1391
1355
1392
  my @itemnumbers_of = get_hostitemnumbers_of($biblionumber);
1356
  my @itemnumbers_of = get_hostitemnumbers_of($biblionumber);
Lines 1422-1439 sub get_hostitemnumbers_of { Link Here
1422
    foreach my $hostfield ( $marcrecord->field($tag) ) {
1386
    foreach my $hostfield ( $marcrecord->field($tag) ) {
1423
        my $hostbiblionumber = $hostfield->subfield($biblio_s);
1387
        my $hostbiblionumber = $hostfield->subfield($biblio_s);
1424
        my $linkeditemnumber = $hostfield->subfield($item_s);
1388
        my $linkeditemnumber = $hostfield->subfield($item_s);
1425
        my @itemnumbers;
1389
        my $is_from_biblio = Koha::Items->search({ itemnumber => $linkeditemnumber, biblionumber => $hostbiblionumber });
1426
        if ( my $itemnumbers =
1390
        push @returnhostitemnumbers, $linkeditemnumber
1427
            get_itemnumbers_of($hostbiblionumber)->{$hostbiblionumber} )
1391
          if $is_from_biblio;
1428
        {
1429
            @itemnumbers = @$itemnumbers;
1430
        }
1431
        foreach my $itemnumber (@itemnumbers) {
1432
            if ( $itemnumber eq $linkeditemnumber ) {
1433
                push( @returnhostitemnumbers, $itemnumber );
1434
                last;
1435
            }
1436
        }
1437
    }
1392
    }
1438
1393
1439
    return @returnhostitemnumbers;
1394
    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-41 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::Koha qw(GetItemTypes);
34
use C4::Koha qw(GetItemTypes);
35
use C4::Creators::Lib qw(html_table);
35
use C4::Creators::Lib qw(html_table);
36
use C4::Debug;
36
use C4::Debug;
37
use Koha::DateUtils;
38
37
38
use Koha::DateUtils;
39
use Koha::Items;
39
use Koha::SearchEngine::Search;
40
use Koha::SearchEngine::Search;
40
41
41
BEGIN {
42
BEGIN {
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 291-302 foreach my $biblionumber (@biblionumbers) { Link Here
291
    my $fixedRank = $count+1;
291
    my $fixedRank = $count+1;
292
292
293
    my %itemnumbers_of_biblioitem;
293
    my %itemnumbers_of_biblioitem;
294
    my @itemnumbers;
295
294
296
    ## $items is array of 'item' table numbers
295
    ## $items is array of 'item' table numbers
297
    if (my $items = get_itemnumbers_of($biblionumber)->{$biblionumber}){
296
    my $items = Koha::Items->search({ biblionumber => $biblionumber });
298
        @itemnumbers  = @$items;
297
    my @itemnumbers = $items->get_column('itemnumber');
299
    }
300
    my @hostitems = get_hostitemnumbers_of($biblionumber);
298
    my @hostitems = get_hostitemnumbers_of($biblionumber);
301
    if (@hostitems){
299
    if (@hostitems){
302
        $template->param('hostitemsflag' => 1);
300
        $template->param('hostitemsflag' => 1);
303
- 

Return to bug 18296