| 
      
            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  |