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

(-)a/C4/Reserves.pm (-10 / +20 lines)
Lines 448-454 sub GetReservesFromBorrowernumber { Link Here
448
#-------------------------------------------------------------------------------------
448
#-------------------------------------------------------------------------------------
449
=head2 CanBookBeReserved
449
=head2 CanBookBeReserved
450
450
451
  $error = &CanBookBeReserved($borrowernumber, $biblionumber)
451
  $canReserve = &CanBookBeReserved($borrowernumber, $biblionumber)
452
  if ($canReserve eq 'OK') { #We can reserve this Item! }
453
454
See CanItemBeReserved() for possible return values.
452
455
453
=cut
456
=cut
454
457
Lines 462-478 sub CanBookBeReserved{ Link Here
462
    push (@$items,@hostitems);
465
    push (@$items,@hostitems);
463
    }
466
    }
464
467
468
	my $canReserve;
465
    foreach my $item (@$items){
469
    foreach my $item (@$items){
466
        return 1 if CanItemBeReserved($borrowernumber, $item);
470
		$canReserve = CanItemBeReserved($borrowernumber, $item);
471
        return 'OK' if $canReserve eq 'OK';
467
    }
472
    }
468
    return 0;
473
    return $canReserve;
469
}
474
}
470
475
471
=head2 CanItemBeReserved
476
=head2 CanItemBeReserved
472
477
473
  $error = &CanItemBeReserved($borrowernumber, $itemnumber)
478
  $canReserve = &CanItemBeReserved($borrowernumber, $itemnumber)
479
  if ($canReserve eq 'OK') { #We can reserve this Item! }
474
480
475
This function return 1 if an item can be issued by this borrower.
481
@RETURNS OK,              if the Item can be reserved.
482
         ageRestricted,   if the Item is age restricted for this borrower.
483
         damaged,         if the Item is damaged.
484
         cannotReserveFromOtherBranches, if syspref 'canreservefromotherbranches' is OK.
485
         tooManyReserves, if the borrower has exceeded his maximum reserve amount.
476
486
477
=cut
487
=cut
478
488
Lines 490-500 sub CanItemBeReserved{ Link Here
490
    my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber);     
500
    my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber);     
491
501
492
    # If an item is damaged and we don't allow holds on damaged items, we can stop right here
502
    # If an item is damaged and we don't allow holds on damaged items, we can stop right here
493
    return 0 if ( $item->{damaged} && !C4::Context->preference('AllowHoldsOnDamagedItems') );
503
    return 'damaged' if ( $item->{damaged} && !C4::Context->preference('AllowHoldsOnDamagedItems') );
494
504
495
    #Check for the age restriction
505
    #Check for the age restriction
496
    my ($ageRestriction, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction( $biblioData->{agerestriction}, $borrower );
506
    my ($ageRestriction, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction( $biblioData->{agerestriction}, $borrower );
497
    return 0 if $daysToAgeRestriction && $daysToAgeRestriction > 0;
507
    return 'ageRestricted' if $daysToAgeRestriction && $daysToAgeRestriction > 0;
498
508
499
    my $controlbranch = C4::Context->preference('ReservesControlBranch');
509
    my $controlbranch = C4::Context->preference('ReservesControlBranch');
500
    my $itemtypefield = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype";
510
    my $itemtypefield = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype";
Lines 561-567 sub CanItemBeReserved{ Link Here
561
    
571
    
562
    # we check if it's ok or not
572
    # we check if it's ok or not
563
    if( $reservecount >= $allowedreserves ){
573
    if( $reservecount >= $allowedreserves ){
564
        return 0;
574
        return 'tooManyReserves';
565
    }
575
    }
566
576
567
    # If reservecount is ok, we check item branch if IndependentBranches is ON
577
    # If reservecount is ok, we check item branch if IndependentBranches is ON
Lines 571-581 sub CanItemBeReserved{ Link Here
571
    {
581
    {
572
        my $itembranch = $item->{homebranch};
582
        my $itembranch = $item->{homebranch};
573
        if ($itembranch ne $borrower->{branchcode}) {
583
        if ($itembranch ne $borrower->{branchcode}) {
574
            return 0;
584
            return 'cannotReserveFromOtherBranches';
575
        }
585
        }
576
    }
586
    }
577
587
578
    return 1;
588
    return 'OK';
579
}
589
}
580
590
581
=head2 CanReserveBeCanceledFromOpac
591
=head2 CanReserveBeCanceledFromOpac
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt (-1 / +4 lines)
Lines 241-247 function checkMultiHold() { Link Here
241
    </form>
241
    </form>
242
  [% ELSE %]
242
  [% ELSE %]
243
243
244
[% IF ( maxreserves || alreadyreserved || none_available || alreadypossession ) %]
244
[% IF ( maxreserves || alreadyreserved || none_available || alreadypossession || ageRestricted ) %]
245
    <div class="dialog alert">
245
    <div class="dialog alert">
246
246
247
    [% UNLESS ( multi_hold ) %]
247
    [% UNLESS ( multi_hold ) %]
Lines 250-255 function checkMultiHold() { Link Here
250
        [% IF ( maxreserves ) %]
250
        [% IF ( maxreserves ) %]
251
          <li><strong>Too many holds: </strong> <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">[% borrowerfirstname %] [% borrowersurname %] </a> has too many holds.</li>
251
          <li><strong>Too many holds: </strong> <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">[% borrowerfirstname %] [% borrowersurname %] </a> has too many holds.</li>
252
        [% END %]
252
        [% END %]
253
        [% IF ( ageRestricted ) %]
254
          <li><strong>Age restricted</strong></li>
255
        [% END %]
253
        [% IF ( alreadyreserved ) %]
256
        [% IF ( alreadyreserved ) %]
254
          <li><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">[% borrowerfirstname %] [% borrowersurname %]</a> <strong>already has a hold</strong> on this item </li>
257
          <li><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">[% borrowerfirstname %] [% borrowersurname %]</a> <strong>already has a hold</strong> on this item </li>
255
        [% END %]
258
        [% END %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt (+6 lines)
Lines 52-57 Link Here
52
                            </div>
52
                            </div>
53
                        [% END %]
53
                        [% END %]
54
54
55
                        [% IF ( ageRestricted ) %]
56
                            <div id="ageRestricted" class="alert">
57
                                Sorry, you are too young to reserve this material.
58
                            </div>
59
                        [% END %]
60
55
                        [% IF ( bad_biblionumber ) %]
61
                        [% IF ( bad_biblionumber ) %]
56
                            <div id="bad_biblionumber" class="alert">
62
                            <div id="bad_biblionumber" class="alert">
57
                                ERROR: No biblio record found for biblionumber [% bad_biblionumber %].</div>
63
                                ERROR: No biblio record found for biblionumber [% bad_biblionumber %].</div>
(-)a/opac/opac-detail.pl (-2 / +2 lines)
Lines 522-529 my $dat = &GetBiblioData($biblionumber); Link Here
522
522
523
#Check if we can place a hold on this biblio.
523
#Check if we can place a hold on this biblio.
524
my $canReserve = C4::Reserves::CanBookBeReserved( $biblionumber, $biblionumber );
524
my $canReserve = C4::Reserves::CanBookBeReserved( $biblionumber, $biblionumber );
525
unless ($canReserve ) {
525
unless ($canReserve eq 'OK' ) {
526
	$template->param( cannotReserve => 1 ) ;
526
	$template->param( cannotReserve => $canReserve ) ;
527
}
527
}
528
528
529
529
(-)a/opac/opac-reserve.pl (-1 / +9 lines)
Lines 548-556 foreach my $biblioNum (@biblionumbers) { Link Here
548
    if ($biblioLoopIter{already_reserved}) {
548
    if ($biblioLoopIter{already_reserved}) {
549
        $biblioLoopIter{holdable} = undef;
549
        $biblioLoopIter{holdable} = undef;
550
    }
550
    }
551
    if(not CanBookBeReserved($borrowernumber,$biblioNum)){
551
	my $canReserve = CanBookBeReserved($borrowernumber,$biblioNum);
552
	if ($canReserve eq 'OK') {
553
		#All is OK!
554
	}
555
    elsif ($canReserve eq 'ageRestricted') {
552
        $biblioLoopIter{holdable} = undef;
556
        $biblioLoopIter{holdable} = undef;
557
		$template->param( message => 1, $canReserve => 1 );
553
    }
558
    }
559
	else {
560
		$biblioLoopIter{holdable} = undef;
561
	}
554
    if(not C4::Context->preference('AllowHoldsOnPatronsPossessions') and CheckIfIssuedToPatron($borrowernumber,$biblioNum)) {
562
    if(not C4::Context->preference('AllowHoldsOnPatronsPossessions') and CheckIfIssuedToPatron($borrowernumber,$biblioNum)) {
555
        $biblioLoopIter{holdable} = undef;
563
        $biblioLoopIter{holdable} = undef;
556
        $biblioLoopIter{already_patron_possession} = 1;
564
        $biblioLoopIter{already_patron_possession} = 1;
(-)a/reserve/request.pl (-4 / +15 lines)
Lines 1-4 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl -d
2
2
3
3
4
#writen 2/1/00 by chris@katipo.oc.nz
4
#writen 2/1/00 by chris@katipo.oc.nz
Lines 191-199 foreach my $biblionumber (@biblionumbers) { Link Here
191
191
192
    my $dat = GetBiblioData($biblionumber);
192
    my $dat = GetBiblioData($biblionumber);
193
193
194
    unless ( CanBookBeReserved($borrowerinfo->{borrowernumber}, $biblionumber) ) {
194
	my $canReserve = CanBookBeReserved($borrowerinfo->{borrowernumber}, $biblionumber);
195
        $maxreserves = 1;
195
	if ($canReserve eq 'OK') {
196
		#All is OK and we can continue
197
	}
198
	elsif ( $canReserve eq 'tooManyReserves' ) {
199
		$maxreserves = 1;
196
    }
200
    }
201
	elsif ( $canReserve eq 'ageRestricted' ) {
202
		$template->param( $canReserve => 1 );
203
		$biblioloopiter{ $canReserve } = 1;
204
	}
205
	else {
206
		$biblioloopiter{ $canReserve } = 1;
207
	}
197
208
198
    my $alreadypossession;
209
    my $alreadypossession;
199
    if (not C4::Context->preference('AllowHoldsOnPatronsPossessions') and CheckIfIssuedToPatron($borrowerinfo->{borrowernumber},$biblionumber)) {
210
    if (not C4::Context->preference('AllowHoldsOnPatronsPossessions') and CheckIfIssuedToPatron($borrowerinfo->{borrowernumber},$biblionumber)) {
Lines 415-421 foreach my $biblionumber (@biblionumbers) { Link Here
415
                && IsAvailableForItemLevelRequest($itemnumber)
426
                && IsAvailableForItemLevelRequest($itemnumber)
416
                && CanItemBeReserved(
427
                && CanItemBeReserved(
417
                    $borrowerinfo->{borrowernumber}, $itemnumber
428
                    $borrowerinfo->{borrowernumber}, $itemnumber
418
                )
429
                ) eq 'OK'
419
              )
430
              )
420
            {
431
            {
421
                $item->{available} = 1;
432
                $item->{available} = 1;
(-)a/t/db_dependent/Reserves.t (-4 / +3 lines)
Lines 486-492 my ( $ageres_tagid, $ageres_subfieldid ) = GetMarcFromKohaField( "biblioitems.ag Link Here
486
$record->append_fields(  MARC::Field->new($ageres_tagid, '', '', $ageres_subfieldid => 'PEGI 16')  );
486
$record->append_fields(  MARC::Field->new($ageres_tagid, '', '', $ageres_subfieldid => 'PEGI 16')  );
487
C4::Biblio::ModBiblio( $record, $bibnum, '' );
487
C4::Biblio::ModBiblio( $record, $bibnum, '' );
488
488
489
is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 1, "Reserving an ageRestricted Biblio without a borrower dateofbirth succeeds" );
489
is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'OK', "Reserving an ageRestricted Biblio without a borrower dateofbirth succeeds" );
490
490
491
#Set the dateofbirth for the Borrower making him "too young".
491
#Set the dateofbirth for the Borrower making him "too young".
492
my $now = DateTime->now();
492
my $now = DateTime->now();
Lines 494-507 my $duration_15years = DateTime::Duration->new(years => 15); Link Here
494
my $past15yearsAgo = DateTime->now()->subtract_duration($duration_15years);
494
my $past15yearsAgo = DateTime->now()->subtract_duration($duration_15years);
495
C4::Members::ModMember( borrowernumber => $borrowernumber, dateofbirth => $past15yearsAgo->ymd() );
495
C4::Members::ModMember( borrowernumber => $borrowernumber, dateofbirth => $past15yearsAgo->ymd() );
496
496
497
is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 0, "Reserving a 'PEGI 16' Biblio by a 15 year old borrower fails");
497
is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'ageRestricted', "Reserving a 'PEGI 16' Biblio by a 15 year old borrower fails");
498
498
499
#Set the dateofbirth for the Borrower making him "too old".
499
#Set the dateofbirth for the Borrower making him "too old".
500
my $duration_30years = DateTime::Duration->new(years => 30);
500
my $duration_30years = DateTime::Duration->new(years => 30);
501
my $past30yearsAgo = DateTime->now()->subtract_duration($duration_30years);
501
my $past30yearsAgo = DateTime->now()->subtract_duration($duration_30years);
502
C4::Members::ModMember( borrowernumber => $borrowernumber, dateofbirth => $past30yearsAgo->ymd() );
502
C4::Members::ModMember( borrowernumber => $borrowernumber, dateofbirth => $past30yearsAgo->ymd() );
503
503
504
is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 1, "Reserving a 'PEGI 16' Biblio by a 30 year old borrower succeeds");
504
is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber) , 'OK', "Reserving a 'PEGI 16' Biblio by a 30 year old borrower succeeds");
505
       ####
505
       ####
506
####### EO Bug 13113 <<<
506
####### EO Bug 13113 <<<
507
       ####
507
       ####
508
- 

Return to bug 13116