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

(-)a/C4/Reserves.pm (-6 / +46 lines)
Lines 344-349 sub CanBookBeReserved{ Link Here
344
        return { status =>'alreadypossession' };
344
        return { status =>'alreadypossession' };
345
    }
345
    }
346
346
347
    if ( $params->{itemtype} ) {
348
349
        # biblio-level, item type-contrained
350
        my $patron          = Koha::Patrons->find($borrowernumber);
351
        my $reservesallowed = Koha::CirculationRules->get_effective_rule(
352
            {
353
                itemtype     => $params->{itemtype},
354
                categorycode => $patron->categorycode,
355
                branchcode   => $pickup_branchcode,
356
                rule_name    => 'reservesallowed',
357
            }
358
        )->rule_value;
359
360
        $reservesallowed = ( $reservesallowed eq '' ) ? undef : $reservesallowed;
361
362
        my $count = $patron->holds->search(
363
            {
364
                '-or' => [
365
                    { 'me.itemtype' => $params->{itemtype} },
366
                    { 'item.itype'  => $params->{itemtype} }
367
                ]
368
            },
369
            {
370
                join => ['item']
371
            }
372
        )->count;
373
374
        return { status => '' }
375
          if defined $reservesallowed and $reservesallowed < $count + 1;
376
    }
377
347
    my $items;
378
    my $items;
348
    #get items linked via host records
379
    #get items linked via host records
349
    my @hostitemnumbers = get_hostitemnumbers_of($biblionumber);
380
    my @hostitemnumbers = get_hostitemnumbers_of($biblionumber);
Lines 524-539 sub CanItemBeReserved { Link Here
524
555
525
            # If using item-level itypes, fall back to the record
556
            # If using item-level itypes, fall back to the record
526
            # level itemtype if the hold has no associated item
557
            # level itemtype if the hold has no associated item
527
            $querycount .=
558
            if ( defined $ruleitemtype ) {
528
              C4::Context->preference('item-level_itypes')
559
                if ( C4::Context->preference('item-level_itypes') ) {
529
              ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?"
560
                    $querycount .= q{
530
              : " AND biblioitems.itemtype = ?"
561
                        AND ( COALESCE( items.itype, biblioitems.itemtype ) = ?
531
              if defined $ruleitemtype;
562
                           OR reserves.itemtype = ? )
563
                    };
564
                }
565
                else {
566
                    $querycount .= q{
567
                        AND ( biblioitems.itemtype = ?
568
                           OR reserves.itemtype = ? )
569
                    };
570
                }
571
            }
532
572
533
            my $sthcount = $dbh->prepare($querycount);
573
            my $sthcount = $dbh->prepare($querycount);
534
574
535
            if ( defined $ruleitemtype ) {
575
            if ( defined $ruleitemtype ) {
536
                $sthcount->execute( $patron->borrowernumber, $reserves_control_branch, $ruleitemtype );
576
                $sthcount->execute( $patron->borrowernumber, $reserves_control_branch, $ruleitemtype, $ruleitemtype );
537
            }
577
            }
538
            else {
578
            else {
539
                $sthcount->execute( $patron->borrowernumber, $reserves_control_branch );
579
                $sthcount->execute( $patron->borrowernumber, $reserves_control_branch );
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt (-5 / +1 lines)
Lines 295-309 Link Here
295
                                                </li>
295
                                                </li>
296
296
297
                                                [% IF Koha.Preference('AllowHoldItemTypeSelection') %]
297
                                                [% IF Koha.Preference('AllowHoldItemTypeSelection') %]
298
                                                    [% itemtypes = [] %]
299
                                                    [% FOREACH item IN bibitemloo.itemLoop %]
300
                                                        [% itemtypes.push( item.itype ) %]
301
                                                    [%- END %]
302
                                                    <li>
298
                                                    <li>
303
                                                        <label for="itemtype">Request specific item type:</label>
299
                                                        <label for="itemtype">Request specific item type:</label>
304
                                                        <select name="itemtype" id="itemtype">
300
                                                        <select name="itemtype" id="itemtype">
305
                                                            <option value="">Any item type</option>
301
                                                            <option value="">Any item type</option>
306
                                                            [% FOREACH i IN itemtypes.unique.sort %]
302
                                                            [% FOREACH i IN bibitemloo.allowed_item_types %]
307
                                                                <option value="[% i | html %]">[% ItemTypes.GetDescription( i ) | html %]</option>
303
                                                                <option value="[% i | html %]">[% ItemTypes.GetDescription( i ) | html %]</option>
308
                                                            [%- END %]
304
                                                            [%- END %]
309
                                                        </select>
305
                                                        </select>
(-)a/opac/opac-reserve.pl (-5 / +21 lines)
Lines 274-286 if ( $query->param('place_reserve') ) { Link Here
274
274
275
        my $patron_expiration_date = $query->param("expiration_date_$biblioNum");
275
        my $patron_expiration_date = $query->param("expiration_date_$biblioNum");
276
276
277
        my $itemtype = $query->param('itemtype') || undef;
278
        $itemtype = undef if $itemNum;
279
277
        my $rank = $biblioData->{rank};
280
        my $rank = $biblioData->{rank};
278
        my $patron = Koha::Patrons->find( $borrowernumber );
281
        my $patron = Koha::Patrons->find( $borrowernumber );
279
        if ( $item ) {
282
        if ( $item ) {
280
            $canreserve = 1 if CanItemBeReserved( $patron, $item, $branch )->{status} eq 'OK';
283
            $canreserve = 1 if CanItemBeReserved( $patron, $item, $branch )->{status} eq 'OK';
281
        }
284
        }
282
        else {
285
        else {
283
            $canreserve = 1 if CanBookBeReserved( $borrowernumber, $biblioNum, $branch )->{status} eq 'OK';
286
            $canreserve = 1
287
              if CanBookBeReserved( $borrowernumber, $biblioNum, $branch, { itemtype => $itemtype } )->{status} eq 'OK';
284
288
285
            # Inserts a null into the 'itemnumber' field of 'reserves' table.
289
            # Inserts a null into the 'itemnumber' field of 'reserves' table.
286
            $itemNum = undef;
290
            $itemNum = undef;
Lines 302-310 if ( $query->param('place_reserve') ) { Link Here
302
            }
306
            }
303
        }
307
        }
304
308
305
        my $itemtype = $query->param('itemtype') || undef;
306
        $itemtype = undef if $itemNum;
307
308
        # Here we actually do the reserveration. Stage 3.
309
        # Here we actually do the reserveration. Stage 3.
309
        if ($canreserve) {
310
        if ($canreserve) {
310
            my $reserve_id = AddReserve(
311
            my $reserve_id = AddReserve(
Lines 633-638 foreach my $biblioNum (@biblionumbers) { Link Here
633
    $biblioLoopIter{holdable} &&= $status eq 'OK';
634
    $biblioLoopIter{holdable} &&= $status eq 'OK';
634
    $biblioLoopIter{already_patron_possession} = $status eq 'alreadypossession';
635
    $biblioLoopIter{already_patron_possession} = $status eq 'alreadypossession';
635
636
637
    if ( $biblioLoopIter{holdable} and C4::Context->preference('AllowHoldItemTypeSelection') ) {
638
        # build the allowed item types loop
639
        my $rs = $biblio->items->search(
640
            undef,
641
            {   select => [ { distinct => 'itype' } ],
642
                as     => 'item_type'
643
            }
644
        );
645
646
        my @item_types =
647
          grep { CanBookBeReserved( $borrowernumber, $biblioNum, $branch, { itemtype => $_ } )->{status} eq 'OK' }
648
          $rs->get_column('item_type');
649
650
        $biblioLoopIter{allowed_item_types} = \@item_types;
651
    }
652
636
    if ( $status eq 'recall' ) {
653
    if ( $status eq 'recall' ) {
637
        $biblioLoopIter{recall} = 1;
654
        $biblioLoopIter{recall} = 1;
638
    }
655
    }
639
- 

Return to bug 28529