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

(-)a/C4/Reserves.pm (-15 / +29 lines)
Lines 376-410 sub GetReservesFromBorrowernumber { Link Here
376
#-------------------------------------------------------------------------------------
376
#-------------------------------------------------------------------------------------
377
=head2 CanBookBeReserved
377
=head2 CanBookBeReserved
378
378
379
  $error = &CanBookBeReserved($borrowernumber, $biblionumber)
379
  my ($can, $reason) = CanBookBeReserved($borrowernumber, $biblionumber)
380
380
381
Calls CanItemBeReserved() for each item, stopping when first available item is found.
382
For return values see CanItemBeReserved(), with addition of reason constant
383
  NO_ITEMS
381
=cut
384
=cut
382
385
386
use constant NO_ITEMS             => "NO ITEMS";
387
use constant NO_RESERVES_ALLOWED  => "NO RESERVES ALLOWED";
388
use constant MAX_RESERVES_REACHED => "BORROWER MAX RESERVES REACHED";
383
sub CanBookBeReserved{
389
sub CanBookBeReserved{
384
    my ($borrowernumber, $biblionumber) = @_;
390
    my ($borrowernumber, $biblionumber) = @_;
385
391
386
    my @items = get_itemnumbers_of($biblionumber);
392
    my @items = get_itemnumbers_of($biblionumber);
387
    #get items linked via host records
393
    #get items linked via host records
388
    my @hostitems = get_hostitemnumbers_of($biblionumber);
394
    if ( my @hostitems = get_hostitemnumbers_of($biblionumber) ) {
389
    if (@hostitems){
395
	    push (@items,@hostitems);
390
	push (@items,@hostitems);
391
    }
396
    }
392
397
398
    my ($can, $reason) = (0, NO_ITEMS);
393
    foreach my $item (@items){
399
    foreach my $item (@items){
394
        return 1 if CanItemBeReserved($borrowernumber, $item);
400
        ($can, $reason) = _CanItemBeReserved($borrowernumber, $item);
401
        last if $can;
395
    }
402
    }
396
    return 0;
403
    return wantarray ? ($can, $reason) : $can;
397
}
404
}
398
405
399
=head2 CanItemBeReserved
406
=head2 CanItemBeReserved
400
407
401
  $error = &CanItemBeReserved($borrowernumber, $itemnumber)
408
  my ($can, $reason) = CanItemBeReserved($borrowernumber, $itemnumber)
402
409
403
This function return 1 if an item can be issued by this borrower.
410
This function returns (1) if an item can be issued by this borrower.
411
If not, it returns (0, $reason), reson being a constat:
412
  NO_RESERVES_ALLOWED
413
  MAX_RESERVES_REACHED
414
415
In scalar context it returns $can;  
404
416
405
=cut
417
=cut
406
418
407
sub CanItemBeReserved{
419
sub CanItemBeReserved{
420
    my ($can, $reason) = _CanItemBeReserved(@_);
421
    return wantarray ? ($can, $reason) : $can;
422
}
423
sub _CanItemBeReserved{
408
    my ($borrowernumber, $itemnumber) = @_;
424
    my ($borrowernumber, $itemnumber) = @_;
409
    
425
    
410
    my $dbh             = C4::Context->dbh;
426
    my $dbh             = C4::Context->dbh;
Lines 460-465 sub CanItemBeReserved{ Link Here
460
    }else{
476
    }else{
461
        $itemtype = '*';
477
        $itemtype = '*';
462
    }
478
    }
479
    return (0, NO_RESERVES_ALLOWED) unless $allowedreserves;
463
    
480
    
464
    # we retrieve count
481
    # we retrieve count
465
    
482
    
Lines 474-490 sub CanItemBeReserved{ Link Here
474
        $sthcount->execute($borrowernumber, $branchcode, $itemtype);
491
        $sthcount->execute($borrowernumber, $branchcode, $itemtype);
475
    }
492
    }
476
    
493
    
477
    my $reservecount = "0";
494
    my $reservecount = 0;
478
    if(my $rowcount = $sthcount->fetchrow_hashref()){
495
    if(my $rowcount = $sthcount->fetchrow_hashref()){
479
        $reservecount = $rowcount->{count};
496
        $reservecount = $rowcount->{count};
480
    }
497
    }
481
    
482
    # we check if it's ok or not
498
    # we check if it's ok or not
483
    if( $reservecount < $allowedreserves ){
499
    return (0, MAX_RESERVES_REACHED) unless $reservecount < $allowedreserves;
484
        return 1;
500
485
    }else{
501
    return (1);
486
        return 0;
487
    }
488
}
502
}
489
#--------------------------------------------------------------------------------
503
#--------------------------------------------------------------------------------
490
=head2 GetReserveCount
504
=head2 GetReserveCount
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt (+3 lines)
Lines 207-212 function checkMultiHold() { Link Here
207
        [% IF ( alreadyreserved ) %]
207
        [% IF ( alreadyreserved ) %]
208
          <li><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">[% borrowerfirstname %] [% borrowersurname %]</a> <strong>already has a hold</strong> on this item </li>
208
          <li><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">[% borrowerfirstname %] [% borrowersurname %]</a> <strong>already has a hold</strong> on this item </li>
209
        [% END %]
209
        [% END %]
210
        [% IF ( reservesnotallowed ) %]
211
          <li> <strong>Items can not be placed on hold</strong></li>
212
        [% END %]
210
        [% IF ( none_available ) %]
213
        [% IF ( none_available ) %]
211
          <li> <strong>No copies are available</strong> to be placed on hold</li>
214
          <li> <strong>No copies are available</strong> to be placed on hold</li>
212
        [% END %]
215
        [% END %]
(-)a/reserve/request.pl (-7 / +15 lines)
Lines 141-149 if ($borrowernumber_hold && !$action) { Link Here
141
    my $number_reserves =
141
    my $number_reserves =
142
      GetReserveCount( $borrowerinfo->{'borrowernumber'} );
142
      GetReserveCount( $borrowerinfo->{'borrowernumber'} );
143
143
144
    if ( C4::Context->preference('maxreserves') && ($number_reserves >= C4::Context->preference('maxreserves')) ) {
144
    if ( my $max = C4::Context->preference('maxreserves') ) {
145
		$warnings = 1;
145
        if ( $number_reserves >= $max ) {
146
        $maxreserves = 1;
146
		    $warnings = 1;
147
            $maxreserves = 1;
148
        }
147
    }
149
    }
148
150
149
    # we check the date expiry of the borrower (only if there is an expiry date, otherwise, set to 1 (warn)
151
    # we check the date expiry of the borrower (only if there is an expiry date, otherwise, set to 1 (warn)
Lines 234-245 foreach my $biblionumber (@biblionumbers) { Link Here
234
236
235
    my %biblioloopiter = ();
237
    my %biblioloopiter = ();
236
	my $maxreserves;
238
	my $maxreserves;
239
	my $reservesnotallowed;
237
240
238
    my $dat          = GetBiblioData($biblionumber);
241
    my $dat          = GetBiblioData($biblionumber);
239
242
240
    unless ( CanBookBeReserved($borrowerinfo->{borrowernumber}, $biblionumber) ) {
243
    my ($can_reserve, $reason) = CanBookBeReserved($borrowerinfo->{borrowernumber}, $biblionumber);
244
    unless ( $can_reserve ) {
241
 		$warnings = 1;
245
 		$warnings = 1;
242
        $maxreserves = 1;
246
        if ($reason eq C4::Reserves->MAX_RESERVES_REACHED) {
247
            $maxreserves = 1;
248
        } else {
249
            $reservesnotallowed = 1;
250
        }
243
    }
251
    }
244
    # get existing reserves .....
252
    # get existing reserves .....
245
    my ( $count, $reserves ) = GetReservesFromBiblionumber($biblionumber,1);
253
    my ( $count, $reserves ) = GetReservesFromBiblionumber($biblionumber,1);
Lines 262-268 foreach my $biblionumber (@biblionumbers) { Link Here
262
    $template->param( alreadyreserved => $alreadyreserved,
270
    $template->param( alreadyreserved => $alreadyreserved,
263
                      messages => $messages,
271
                      messages => $messages,
264
                      warnings => $warnings,
272
                      warnings => $warnings,
265
					  maxreserves=>$maxreserves
273
					  maxreserves=>$maxreserves,
274
                      reservesnotallowed=>$reservesnotallowed,
266
					  );
275
					  );
267
276
268
277
269
- 

Return to bug 6650