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

(-)a/C4/Biblio.pm (-3 / +14 lines)
Lines 2523-2536 sub _adjust_pubyear { Link Here
2523
2523
2524
=head2 CountItemsIssued
2524
=head2 CountItemsIssued
2525
2525
2526
    my $count = CountItemsIssued( $biblionumber );
2526
    my $count = CountItemsIssued( { biblionumber => $biblionumber, count_on_order => 0 || 1 );
2527
2527
2528
=cut
2528
=cut
2529
2529
2530
sub CountItemsIssued {
2530
sub CountItemsIssued {
2531
    my ($biblionumber) = @_;
2531
    my ($params) = @_;
2532
    my $biblionumber = $params->{'biblionumber'};
2533
    my $count_on_order = $params->{'count_on_order'};
2534
2535
    my $sql = 'SELECT COUNT(*) AS issuedCount FROM items LEFT JOIN issues ON items.itemnumber = issues.itemnumber WHERE items.biblionumber = ?';
2536
2537
    if ( $count_on_order ) {
2538
        $sql .= ' AND ( issues.itemnumber IS NOT NULL OR items.notforloan < 0 )';
2539
    } else {
2540
        $sql .= ' AND issues.itemnumber IS NOT NULL';
2541
    }
2542
2532
    my $dbh            = C4::Context->dbh;
2543
    my $dbh            = C4::Context->dbh;
2533
    my $sth            = $dbh->prepare('SELECT COUNT(*) as issuedCount FROM items, issues WHERE items.itemnumber = issues.itemnumber AND items.biblionumber = ?');
2544
    my $sth            = $dbh->prepare( $sql );
2534
    $sth->execute($biblionumber);
2545
    $sth->execute($biblionumber);
2535
    my $row = $sth->fetchrow_hashref();
2546
    my $row = $sth->fetchrow_hashref();
2536
    return $row->{'issuedCount'};
2547
    return $row->{'issuedCount'};
(-)a/C4/Reserves.pm (-7 / +5 lines)
Lines 1279-1295 sub IsAvailableForItemLevelRequest { Link Here
1279
1279
1280
    if ( $on_shelf_holds == 1 ) {
1280
    if ( $on_shelf_holds == 1 ) {
1281
        return 1;
1281
        return 1;
1282
    } elsif ( $on_shelf_holds == 2 ) {
1282
    } elsif ( $on_shelf_holds == 2 ) { # On shelf holds == "If all unavailable"
1283
1283
1284
        # if we have this param predefined from outer caller sub, we just need
1284
        # if we have this param predefined from outer caller sub, we just need
1285
        # to return it, so we saving from having loop inside other loop:
1285
        # to return it, so we saving from having loop inside other loop:
1286
        return  $items_any_available ? 0 : 1
1286
        $items_any_available //= ItemsAnyAvailableForHold( { biblionumber => $item->biblionumber, patron => $patron });
1287
            if defined $items_any_available;
1288
1287
1289
        my $any_available = ItemsAnyAvailableForHold( { biblionumber => $item->biblionumber, patron => $patron });
1288
        return !$items_any_available;
1290
        return $any_available ? 0 : 1;
1291
    } else { # on_shelf_holds == 0 "If any unavailable" (the description is rather cryptic and could still be improved)
1289
    } else { # on_shelf_holds == 0 "If any unavailable" (the description is rather cryptic and could still be improved)
1292
        return $item->onloan || IsItemOnHoldAndFound( $item->itemnumber );
1290
        return $item->notforloan < 0 || $item->onloan || IsItemOnHoldAndFound( $item->itemnumber );
1293
    }
1291
    }
1294
}
1292
}
1295
1293
Lines 1319-1325 sub ItemsAnyAvailableForHold { Link Here
1319
1317
1320
        $any_available = 1
1318
        $any_available = 1
1321
            unless $i->itemlost
1319
            unless $i->itemlost
1322
            || $i->notforloan > 0
1320
            || $i->notforloan != 0
1323
            || $i->withdrawn
1321
            || $i->withdrawn
1324
            || $i->onloan
1322
            || $i->onloan
1325
            || IsItemOnHoldAndFound( $i->id )
1323
            || IsItemOnHoldAndFound( $i->id )
(-)a/opac/opac-ISBDdetail.pl (-1 / +1 lines)
Lines 182-188 while ( my $item = $items->next ) { Link Here
182
      unless $allow_onshelf_holds;
182
      unless $allow_onshelf_holds;
183
}
183
}
184
184
185
if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_items_waiting_or_intransit ) {
185
if( $allow_onshelf_holds || CountItemsIssued({ biblionumber => $biblionumber, count_on_order => 1 }) || $biblio->has_items_waiting_or_intransit ) {
186
    $template->param( ReservableItems => 1 );
186
    $template->param( ReservableItems => 1 );
187
}
187
}
188
188
(-)a/opac/opac-MARCdetail.pl (-1 / +1 lines)
Lines 143-149 for my $itm (@all_items) { Link Here
143
    last if $allow_onshelf_holds;
143
    last if $allow_onshelf_holds;
144
}
144
}
145
145
146
if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_items_waiting_or_intransit ) {
146
if ( $allow_onshelf_holds || CountItemsIssued({ biblionumber => $biblionumber, count_on_order => 1 }) || $biblio->has_items_waiting_or_intransit ) {
147
    $template->param( ReservableItems => 1 );
147
    $template->param( ReservableItems => 1 );
148
}
148
}
149
149
(-)a/opac/opac-detail.pl (-1 / +1 lines)
Lines 731-737 if ( not $viewallitems and @items > $max_items_to_display ) { Link Here
731
  }
731
  }
732
}
732
}
733
733
734
if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_items_waiting_or_intransit ) {
734
if ( $allow_onshelf_holds || CountItemsIssued({ biblionumber => $biblionumber, count_on_order => 1 }) || $biblio->has_items_waiting_or_intransit ) {
735
    $template->param( ReservableItems => 1 );
735
    $template->param( ReservableItems => 1 );
736
}
736
}
737
737
(-)a/opac/opac-search.pl (-1 / +1 lines)
Lines 710-716 for (my $i=0;$i<@servers;$i++) { Link Here
710
            if (C4::Context->preference('TagsEnabled') and
710
            if (C4::Context->preference('TagsEnabled') and
711
                C4::Context->preference('TagsShowOnList')) {
711
                C4::Context->preference('TagsShowOnList')) {
712
                if ( my $bibnum = $res->{biblionumber} ) {
712
                if ( my $bibnum = $res->{biblionumber} ) {
713
                    $res->{itemsissued} = CountItemsIssued( $bibnum );
713
                    $res->{itemsissued} = CountItemsIssued( { biblionumber => $bibnum } );
714
                    $res->{'TagLoop'} = get_tags({
714
                    $res->{'TagLoop'} = get_tags({
715
                        biblionumber => $bibnum,
715
                        biblionumber => $bibnum,
716
                        approved => 1,
716
                        approved => 1,
(-)a/tools/batch_delete_records.pl (-3 / +2 lines)
Lines 96-102 if ( $op eq 'form' ) { Link Here
96
            my $record = &GetMarcBiblio({ biblionumber => $record_id });
96
            my $record = &GetMarcBiblio({ biblionumber => $record_id });
97
            $biblio->{itemnumbers} = [Koha::Items->search({ biblionumber => $record_id })->get_column('itemnumber')];
97
            $biblio->{itemnumbers} = [Koha::Items->search({ biblionumber => $record_id })->get_column('itemnumber')];
98
            $biblio->{holds_count} = $holds_count;
98
            $biblio->{holds_count} = $holds_count;
99
            $biblio->{issues_count} = C4::Biblio::CountItemsIssued( $record_id );
99
            $biblio->{issues_count} = C4::Biblio::CountItemsIssued({ biblionumber => $record_id, count_on_order => 1 });
100
            push @records, $biblio;
100
            push @records, $biblio;
101
        } else {
101
        } else {
102
            # Retrieve authority information
102
            # Retrieve authority information
Lines 145-151 if ( $op eq 'form' ) { Link Here
145
            my $biblio = Koha::Biblios->find( $biblionumber );
145
            my $biblio = Koha::Biblios->find( $biblionumber );
146
146
147
            # TODO Replace with $biblio->get_issues->count
147
            # TODO Replace with $biblio->get_issues->count
148
            if ( C4::Biblio::CountItemsIssued( $biblionumber ) ) {
148
            if ( C4::Biblio::CountItemsIssued({ biblionumber => $biblionumber, count_on_order => 1 }) ) {
149
                push @messages, {
149
                push @messages, {
150
                    type => 'warning',
150
                    type => 'warning',
151
                    code => 'item_issued',
151
                    code => 'item_issued',
152
- 

Return to bug 6918