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

(-)a/C4/Reserves.pm (-6 / +58 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
        and C4::Context->preference('BiblioHoldItemTypeUseForRules') )
349
    {
350
        # biblio-level, item type-contrained
351
        my $patron          = Koha::Patrons->find($borrowernumber);
352
        my $reservesallowed = Koha::CirculationRules->get_effective_rule(
353
            {
354
                itemtype     => $params->{itemtype},
355
                categorycode => $patron->categorycode,
356
                branchcode   => $pickup_branchcode,
357
                rule_name    => 'reservesallowed',
358
            }
359
        )->rule_value;
360
361
        $reservesallowed = ($reservesallowed eq '') ? undef : $reservesallowed;
362
363
        my $count = $patron->holds->search(
364
            {
365
                '-or' => [
366
                    { 'me.itemtype' => $params->{itemtype} },
367
                    { 'item.itype'  => $params->{itemtype} }
368
                ]
369
            },
370
            {
371
                join => ['item']
372
            }
373
        )->count;
374
375
        return { status => '' }
376
          if defined $reservesallowed and $reservesallowed < $count + 1;
377
    }
378
347
    my $items;
379
    my $items;
348
    #get items linked via host records
380
    #get items linked via host records
349
    my @hostitemnumbers = get_hostitemnumbers_of($biblionumber);
381
    my @hostitemnumbers = get_hostitemnumbers_of($biblionumber);
Lines 524-538 sub CanItemBeReserved { Link Here
524
556
525
            # If using item-level itypes, fall back to the record
557
            # If using item-level itypes, fall back to the record
526
            # level itemtype if the hold has no associated item
558
            # level itemtype if the hold has no associated item
527
            $querycount .=
559
            if ( defined $ruleitemtype and C4::Context->preference('BiblioHoldItemTypeUseForRules') ) {
528
              C4::Context->preference('item-level_itypes')
560
                if ( C4::Context->preference('item-level_itypes') ) {
529
              ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?"
561
                    $querycount .= q{
530
              : " AND biblioitems.itemtype = ?"
562
                        AND ( COALESCE( items.itype, biblioitems.itemtype ) = ?
531
              if defined $ruleitemtype;
563
                           OR reserves.itemtype = ? )
564
                    };
565
                }
566
                else {
567
                    $querycount .= q{
568
                        AND ( biblioitems.itemtype = ?
569
                           OR reserves.itemtype = ? )
570
                    };
571
                }
572
            }
573
            elsif ( defined $ruleitemtype ) {
574
                # If using item-level itypes, fall back to the record
575
                # level itemtype if the hold has no associated item
576
                $querycount .=
577
                C4::Context->preference('item-level_itypes')
578
                ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?"
579
                : " AND biblioitems.itemtype = ?";
580
            }
532
581
533
            my $sthcount = $dbh->prepare($querycount);
582
            my $sthcount = $dbh->prepare($querycount);
534
583
535
            if ( defined $ruleitemtype ) {
584
            if ( defined $ruleitemtype and C4::Context->preference('BiblioHoldItemTypeUseForRules') ) {
585
                $sthcount->execute( $patron->borrowernumber, $reserves_control_branch, $ruleitemtype, $ruleitemtype );
586
            }
587
            elsif ( defined $ruleitemtype ) {
536
                $sthcount->execute( $patron->borrowernumber, $reserves_control_branch, $ruleitemtype );
588
                $sthcount->execute( $patron->borrowernumber, $reserves_control_branch, $ruleitemtype );
537
            }
589
            }
538
            else {
590
            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