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

(-)a/C4/Reserves.pm (-6 / +58 lines)
Lines 330-335 sub CanBookBeReserved{ Link Here
330
        return { status =>'alreadypossession' };
330
        return { status =>'alreadypossession' };
331
    }
331
    }
332
332
333
    if ( $params->{itemtype}
334
        and C4::Context->preference('BiblioHoldItemTypeUseForRules') )
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
333
    my $items;
365
    my $items;
334
    #get items linked via host records
366
    #get items linked via host records
335
    my @hostitemnumbers = get_hostitemnumbers_of($biblionumber);
367
    my @hostitemnumbers = get_hostitemnumbers_of($biblionumber);
Lines 510-524 sub CanItemBeReserved { Link Here
510
542
511
            # If using item-level itypes, fall back to the record
543
            # If using item-level itypes, fall back to the record
512
            # level itemtype if the hold has no associated item
544
            # level itemtype if the hold has no associated item
513
            $querycount .=
545
            if ( defined $ruleitemtype and C4::Context->preference('BiblioHoldItemTypeUseForRules') ) {
514
              C4::Context->preference('item-level_itypes')
546
                if ( C4::Context->preference('item-level_itypes') ) {
515
              ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?"
547
                    $querycount .= q{
516
              : " AND biblioitems.itemtype = ?"
548
                        AND ( COALESCE( items.itype, biblioitems.itemtype ) = ?
517
              if defined $ruleitemtype;
549
                           OR reserves.itemtype = ? )
550
                    };
551
                }
552
                else {
553
                    $querycount .= q{
554
                        AND ( biblioitems.itemtype = ?
555
                           OR reserves.itemtype = ? )
556
                    };
557
                }
558
            }
559
            elsif ( defined $ruleitemtype ) {
560
                # If using item-level itypes, fall back to the record
561
                # level itemtype if the hold has no associated item
562
                $querycount .=
563
                C4::Context->preference('item-level_itypes')
564
                ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?"
565
                : " AND biblioitems.itemtype = ?";
566
            }
518
567
519
            my $sthcount = $dbh->prepare($querycount);
568
            my $sthcount = $dbh->prepare($querycount);
520
569
521
            if ( defined $ruleitemtype ) {
570
            if ( defined $ruleitemtype and C4::Context->preference('BiblioHoldItemTypeUseForRules') ) {
571
                $sthcount->execute( $patron->borrowernumber, $reserves_control_branch, $ruleitemtype, $ruleitemtype );
572
            }
573
            elsif ( defined $ruleitemtype ) {
522
                $sthcount->execute( $patron->borrowernumber, $reserves_control_branch, $ruleitemtype );
574
                $sthcount->execute( $patron->borrowernumber, $reserves_control_branch, $ruleitemtype );
523
            }
575
            }
524
            else {
576
            else {
(-)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