View | Details | Raw Unified | Return to bug 18295
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 1392-1432 sub GetItemnumbersForBiblio { Link Here
1392
    return \@items;
1391
    return \@items;
1393
}
1392
}
1394
1393
1395
=head2 get_itemnumbers_of
1396
1397
  my @itemnumbers_of = get_itemnumbers_of(@biblionumbers);
1398
1399
Given a list of biblionumbers, return the list of corresponding itemnumbers
1400
for each biblionumber.
1401
1402
Return a reference on a hash where keys are biblionumbers and values are
1403
references on array of itemnumbers.
1404
1405
=cut
1406
1407
sub get_itemnumbers_of {
1408
    my @biblionumbers = @_;
1409
1410
    my $dbh = C4::Context->dbh;
1411
1412
    my $query = '
1413
        SELECT itemnumber,
1414
            biblionumber
1415
        FROM items
1416
        WHERE biblionumber IN (?' . ( ',?' x scalar @biblionumbers - 1 ) . ')
1417
    ';
1418
    my $sth = $dbh->prepare($query);
1419
    $sth->execute(@biblionumbers);
1420
1421
    my %itemnumbers_of;
1422
1423
    while ( my ( $itemnumber, $biblionumber ) = $sth->fetchrow_array ) {
1424
        push @{ $itemnumbers_of{$biblionumber} }, $itemnumber;
1425
    }
1426
1427
    return \%itemnumbers_of;
1428
}
1429
1430
=head2 get_hostitemnumbers_of
1394
=head2 get_hostitemnumbers_of
1431
1395
1432
  my @itemnumbers_of = get_hostitemnumbers_of($biblionumber);
1396
  my @itemnumbers_of = get_hostitemnumbers_of($biblionumber);
Lines 1462-1479 sub get_hostitemnumbers_of { Link Here
1462
    foreach my $hostfield ( $marcrecord->field($tag) ) {
1426
    foreach my $hostfield ( $marcrecord->field($tag) ) {
1463
        my $hostbiblionumber = $hostfield->subfield($biblio_s);
1427
        my $hostbiblionumber = $hostfield->subfield($biblio_s);
1464
        my $linkeditemnumber = $hostfield->subfield($item_s);
1428
        my $linkeditemnumber = $hostfield->subfield($item_s);
1465
        my @itemnumbers;
1429
        my $is_from_biblio = Koha::Items->search({ itemnumber => $linkeditemnumber, biblionumber => $hostbiblionumber });
1466
        if ( my $itemnumbers =
1430
        push @returnhostitemnumbers, $linkeditemnumber
1467
            get_itemnumbers_of($hostbiblionumber)->{$hostbiblionumber} )
1431
          if $is_from_biblio;
1468
        {
1469
            @itemnumbers = @$itemnumbers;
1470
        }
1471
        foreach my $itemnumber (@itemnumbers) {
1472
            if ( $itemnumber eq $linkeditemnumber ) {
1473
                push( @returnhostitemnumbers, $itemnumber );
1474
                last;
1475
            }
1476
        }
1477
    }
1432
    }
1478
1433
1479
    return @returnhostitemnumbers;
1434
    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