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

(-)a/C4/Reserves.pm (-6 / +46 lines)
Lines 331-336 sub CanBookBeReserved{ Link Here
331
        return { status =>'alreadypossession' };
331
        return { status =>'alreadypossession' };
332
    }
332
    }
333
333
334
    if ( $params->{itemtype} ) {
335
336
        # biblio-level, item type-contrained
337
        my $patron          = Koha::Patrons->find($borrowernumber);
338
        my $reservesallowed = Koha::CirculationRules->get_effective_rule(
339
            {
340
                itemtype     => $params->{itemtype},
341
                categorycode => $patron->categorycode,
342
                branchcode   => $pickup_branchcode,
343
                rule_name    => 'reservesallowed',
344
            }
345
        )->rule_value;
346
347
        $reservesallowed = ( $reservesallowed eq '' ) ? undef : $reservesallowed;
348
349
        my $count = $patron->holds->search(
350
            {
351
                '-or' => [
352
                    { 'me.itemtype' => $params->{itemtype} },
353
                    { 'item.itype'  => $params->{itemtype} }
354
                ]
355
            },
356
            {
357
                join => ['item']
358
            }
359
        )->count;
360
361
        return { status => '' }
362
          if defined $reservesallowed and $reservesallowed < $count + 1;
363
    }
364
334
    my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber");
365
    my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber");
335
    #get items linked via host records
366
    #get items linked via host records
336
    my @hostitems = get_hostitemnumbers_of($biblionumber);
367
    my @hostitems = get_hostitemnumbers_of($biblionumber);
Lines 489-504 sub CanItemBeReserved { Link Here
489
520
490
    # If using item-level itypes, fall back to the record
521
    # If using item-level itypes, fall back to the record
491
    # level itemtype if the hold has no associated item
522
    # level itemtype if the hold has no associated item
492
    $querycount .=
523
    if ( defined $ruleitemtype ) {
493
      C4::Context->preference('item-level_itypes')
524
        if ( C4::Context->preference('item-level_itypes') ) {
494
      ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?"
525
            $querycount .= q{
495
      : " AND biblioitems.itemtype = ?"
526
                AND ( COALESCE( items.itype, biblioitems.itemtype ) = ?
496
      if defined $ruleitemtype;
527
                   OR reserves.itemtype = ? )
528
            };
529
        }
530
        else {
531
            $querycount .= q{
532
                AND ( biblioitems.itemtype = ?
533
                   OR reserves.itemtype = ? )
534
            };
535
        }
536
    }
497
537
498
    my $sthcount = $dbh->prepare($querycount);
538
    my $sthcount = $dbh->prepare($querycount);
499
539
500
    if ( defined $ruleitemtype ) {
540
    if ( defined $ruleitemtype ) {
501
        $sthcount->execute( $borrowernumber, $branchcode, $ruleitemtype );
541
        $sthcount->execute( $borrowernumber, $branchcode, $ruleitemtype, $ruleitemtype );
502
    }
542
    }
503
    else {
543
    else {
504
        $sthcount->execute( $borrowernumber, $branchcode );
544
        $sthcount->execute( $borrowernumber, $branchcode );
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt (-5 / +1 lines)
Lines 293-307 Link Here
293
                                                </li>
293
                                                </li>
294
294
295
                                                [% IF Koha.Preference('AllowHoldItemTypeSelection') %]
295
                                                [% IF Koha.Preference('AllowHoldItemTypeSelection') %]
296
                                                    [% itemtypes = [] %]
297
                                                    [% FOREACH item IN bibitemloo.itemLoop %]
298
                                                        [% itemtypes.push( item.itype ) %]
299
                                                    [%- END %]
300
                                                    <li>
296
                                                    <li>
301
                                                        <label for="itemtype">Request specific item type:</label>
297
                                                        <label for="itemtype">Request specific item type:</label>
302
                                                        <select name="itemtype" id="itemtype">
298
                                                        <select name="itemtype" id="itemtype">
303
                                                            <option value="">Any item type</option>
299
                                                            <option value="">Any item type</option>
304
                                                            [% FOREACH i IN itemtypes.unique.sort %]
300
                                                            [% FOREACH i IN bibitemloo.allowed_item_types %]
305
                                                                <option value="[% i | html %]">[% ItemTypes.GetDescription( i ) | html %]</option>
301
                                                                <option value="[% i | html %]">[% ItemTypes.GetDescription( i ) | html %]</option>
306
                                                            [%- END %]
302
                                                            [%- END %]
307
                                                        </select>
303
                                                        </select>
(-)a/opac/opac-reserve.pl (-5 / +21 lines)
Lines 277-288 if ( $query->param('place_reserve') ) { Link Here
277
277
278
        my $expiration_date = $query->param("expiration_date_$biblioNum");
278
        my $expiration_date = $query->param("expiration_date_$biblioNum");
279
279
280
        my $itemtype = $query->param('itemtype') || undef;
281
        $itemtype = undef if $itemNum;
282
280
        my $rank = $biblioData->{rank};
283
        my $rank = $biblioData->{rank};
281
        if ( $itemNum ne '' ) {
284
        if ( $itemNum ne '' ) {
282
            $canreserve = 1 if CanItemBeReserved( $borrowernumber, $itemNum, $branch )->{status} eq 'OK';
285
            $canreserve = 1 if CanItemBeReserved( $borrowernumber, $itemNum, $branch )->{status} eq 'OK';
283
        }
286
        }
284
        else {
287
        else {
285
            $canreserve = 1 if CanBookBeReserved( $borrowernumber, $biblioNum, $branch )->{status} eq 'OK';
288
            $canreserve = 1
289
              if CanBookBeReserved( $borrowernumber, $biblioNum, $branch, { itemtype => $itemtype } )->{status} eq 'OK';
286
290
287
            # Inserts a null into the 'itemnumber' field of 'reserves' table.
291
            # Inserts a null into the 'itemnumber' field of 'reserves' table.
288
            $itemNum = undef;
292
            $itemNum = undef;
Lines 304-312 if ( $query->param('place_reserve') ) { Link Here
304
            }
308
            }
305
        }
309
        }
306
310
307
        my $itemtype = $query->param('itemtype') || undef;
308
        $itemtype = undef if $itemNum;
309
310
        # Here we actually do the reserveration. Stage 3.
311
        # Here we actually do the reserveration. Stage 3.
311
        if ($canreserve) {
312
        if ($canreserve) {
312
            my $reserve_id = AddReserve(
313
            my $reserve_id = AddReserve(
Lines 635-640 foreach my $biblioNum (@biblionumbers) { Link Here
635
    $biblioLoopIter{holdable} &&= $status eq 'OK';
636
    $biblioLoopIter{holdable} &&= $status eq 'OK';
636
    $biblioLoopIter{already_patron_possession} = $status eq 'alreadypossession';
637
    $biblioLoopIter{already_patron_possession} = $status eq 'alreadypossession';
637
638
639
    if ( $biblioLoopIter{holdable} and C4::Context->preference('AllowHoldItemTypeSelection') ) {
640
        # build the allowed item types loop
641
        my $rs = $biblio->items->search(
642
            undef,
643
            {   select => [ { distinct => 'itype' } ],
644
                as     => 'item_type'
645
            }
646
        );
647
648
        my @item_types =
649
          grep { CanBookBeReserved( $borrowernumber, $biblioNum, $branch, { itemtype => $_ } )->{status} eq 'OK' }
650
          $rs->get_column('item_type');
651
652
        $biblioLoopIter{allowed_item_types} = \@item_types;
653
    }
654
638
    # For multiple holds per record, if a patron has previously placed a hold,
655
    # For multiple holds per record, if a patron has previously placed a hold,
639
    # the patron can only place more holds of the same type. That is, if the
656
    # the patron can only place more holds of the same type. That is, if the
640
    # patron placed a record level hold, all the holds the patron places must
657
    # patron placed a record level hold, all the holds the patron places must
641
- 

Return to bug 28529