Lines 459-532
sub CanBookBeReserved{
Link Here
|
459 |
|
459 |
|
460 |
=cut |
460 |
=cut |
461 |
|
461 |
|
462 |
sub CanItemBeReserved{ |
462 |
sub CanItemBeReserved { |
463 |
my ($borrowernumber, $itemnumber) = @_; |
463 |
my ( $borrowernumber, $itemnumber ) = @_; |
464 |
|
464 |
|
465 |
my $dbh = C4::Context->dbh; |
465 |
my $dbh = C4::Context->dbh; |
466 |
my $ruleitemtype; # itemtype of the matching issuing rule |
466 |
my $ruleitemtype; # itemtype of the matching issuing rule |
467 |
my $allowedreserves = 0; |
467 |
my $allowedreserves = 0; |
468 |
|
468 |
|
469 |
# we retrieve borrowers and items informations # |
469 |
# we retrieve borrowers and items informations # |
470 |
# item->{itype} will come for biblioitems if necessery |
470 |
# item->{itype} will come for biblioitems if necessery |
471 |
my $item = GetItem($itemnumber); |
471 |
my $item = GetItem($itemnumber); |
472 |
my $biblioData = C4::Biblio::GetBiblioData( $item->{biblionumber} ); |
472 |
my $biblioData = C4::Biblio::GetBiblioData( $item->{biblionumber} ); |
473 |
my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber); |
473 |
my $borrower = C4::Members::GetMember( 'borrowernumber' => $borrowernumber ); |
474 |
|
474 |
|
475 |
# If an item is damaged and we don't allow holds on damaged items, we can stop right here |
475 |
# If an item is damaged and we don't allow holds on damaged items, we can stop right here |
476 |
return 'damaged' if ( $item->{damaged} && !C4::Context->preference('AllowHoldsOnDamagedItems') ); |
476 |
return 'damaged' |
|
|
477 |
if ( $item->{damaged} |
478 |
&& !C4::Context->preference('AllowHoldsOnDamagedItems') ); |
477 |
|
479 |
|
478 |
#Check for the age restriction |
480 |
#Check for the age restriction |
479 |
my ($ageRestriction, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction( $biblioData->{agerestriction}, $borrower ); |
481 |
my ( $ageRestriction, $daysToAgeRestriction ) = |
|
|
482 |
C4::Circulation::GetAgeRestriction( $biblioData->{agerestriction}, $borrower ); |
480 |
return 'ageRestricted' if $daysToAgeRestriction && $daysToAgeRestriction > 0; |
483 |
return 'ageRestricted' if $daysToAgeRestriction && $daysToAgeRestriction > 0; |
481 |
|
484 |
|
482 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
485 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
483 |
|
486 |
|
484 |
# we retrieve user rights on this itemtype and branchcode |
487 |
# we retrieve user rights on this itemtype and branchcode |
485 |
my $sth = $dbh->prepare("SELECT categorycode, itemtype, branchcode, reservesallowed |
488 |
my $sth = $dbh->prepare( |
486 |
FROM issuingrules |
489 |
q{ |
487 |
WHERE (categorycode in (?,'*') ) |
490 |
SELECT categorycode, itemtype, branchcode, reservesallowed |
488 |
AND (itemtype IN (?,'*')) |
491 |
FROM issuingrules |
489 |
AND (branchcode IN (?,'*')) |
492 |
WHERE (categorycode in (?,'*') ) |
490 |
ORDER BY |
493 |
AND (itemtype IN (?,'*')) |
491 |
categorycode DESC, |
494 |
AND (branchcode IN (?,'*')) |
492 |
itemtype DESC, |
495 |
ORDER BY categorycode DESC, |
493 |
branchcode DESC;" |
496 |
itemtype DESC, |
494 |
); |
497 |
branchcode DESC |
495 |
|
498 |
} |
496 |
my $querycount ="SELECT |
499 |
); |
497 |
count(*) as count |
500 |
|
498 |
FROM reserves |
501 |
my $querycount = q{ |
499 |
LEFT JOIN items USING (itemnumber) |
502 |
SELECT count(*) AS count |
500 |
LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber) |
503 |
FROM reserves |
501 |
LEFT JOIN borrowers USING (borrowernumber) |
504 |
LEFT JOIN items USING (itemnumber) |
502 |
WHERE borrowernumber = ? |
505 |
LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber) |
503 |
"; |
506 |
LEFT JOIN borrowers USING (borrowernumber) |
504 |
|
507 |
WHERE borrowernumber = ? |
505 |
|
508 |
}; |
506 |
my $branchcode = ""; |
|
|
507 |
my $branchfield = "reserves.branchcode"; |
508 |
|
509 |
|
509 |
if( $controlbranch eq "ItemHomeLibrary" ){ |
510 |
my $branchcode = ""; |
|
|
511 |
my $branchfield = "reserves.branchcode"; |
512 |
|
513 |
if ( $controlbranch eq "ItemHomeLibrary" ) { |
510 |
$branchfield = "items.homebranch"; |
514 |
$branchfield = "items.homebranch"; |
511 |
$branchcode = $item->{homebranch}; |
515 |
$branchcode = $item->{homebranch}; |
512 |
}elsif( $controlbranch eq "PatronLibrary" ){ |
516 |
} |
|
|
517 |
elsif ( $controlbranch eq "PatronLibrary" ) { |
513 |
$branchfield = "borrowers.branchcode"; |
518 |
$branchfield = "borrowers.branchcode"; |
514 |
$branchcode = $borrower->{branchcode}; |
519 |
$branchcode = $borrower->{branchcode}; |
515 |
} |
520 |
} |
516 |
|
521 |
|
517 |
# we retrieve rights |
522 |
# we retrieve rights |
518 |
$sth->execute($borrower->{'categorycode'}, $item->{'itype'}, $branchcode); |
523 |
$sth->execute( $borrower->{'categorycode'}, $item->{'itype'}, $branchcode ); |
519 |
if(my $rights = $sth->fetchrow_hashref()){ |
524 |
if ( my $rights = $sth->fetchrow_hashref() ) { |
520 |
$ruleitemtype = $rights->{itemtype}; |
525 |
$ruleitemtype = $rights->{itemtype}; |
521 |
$allowedreserves = $rights->{reservesallowed}; |
526 |
$allowedreserves = $rights->{reservesallowed}; |
522 |
}else{ |
527 |
} |
|
|
528 |
else { |
523 |
$ruleitemtype = '*'; |
529 |
$ruleitemtype = '*'; |
524 |
} |
530 |
} |
525 |
|
531 |
|
526 |
# we retrieve count |
532 |
# we retrieve count |
527 |
|
533 |
|
528 |
$querycount .= "AND $branchfield = ?"; |
534 |
$querycount .= "AND $branchfield = ?"; |
529 |
|
535 |
|
530 |
# If using item-level itypes, fall back to the record |
536 |
# If using item-level itypes, fall back to the record |
531 |
# level itemtype if the hold has no associated item |
537 |
# level itemtype if the hold has no associated item |
532 |
$querycount .= |
538 |
$querycount .= |
Lines 536-561
sub CanItemBeReserved{
Link Here
|
536 |
if ( $ruleitemtype ne "*" ); |
542 |
if ( $ruleitemtype ne "*" ); |
537 |
|
543 |
|
538 |
my $sthcount = $dbh->prepare($querycount); |
544 |
my $sthcount = $dbh->prepare($querycount); |
539 |
|
545 |
|
540 |
if($ruleitemtype eq "*"){ |
546 |
if ( $ruleitemtype eq "*" ) { |
541 |
$sthcount->execute($borrowernumber, $branchcode); |
547 |
$sthcount->execute( $borrowernumber, $branchcode ); |
542 |
}else{ |
548 |
} |
543 |
$sthcount->execute($borrowernumber, $branchcode, $ruleitemtype); |
549 |
else { |
|
|
550 |
$sthcount->execute( $borrowernumber, $branchcode, $ruleitemtype ); |
544 |
} |
551 |
} |
545 |
|
552 |
|
546 |
my $reservecount = "0"; |
553 |
my $reservecount = "0"; |
547 |
if(my $rowcount = $sthcount->fetchrow_hashref()){ |
554 |
if ( my $rowcount = $sthcount->fetchrow_hashref() ) { |
548 |
$reservecount = $rowcount->{count}; |
555 |
$reservecount = $rowcount->{count}; |
549 |
} |
556 |
} |
|
|
557 |
|
550 |
# we check if it's ok or not |
558 |
# we check if it's ok or not |
551 |
if( $reservecount >= $allowedreserves ){ |
559 |
if ( $reservecount >= $allowedreserves ) { |
552 |
return 'tooManyReserves'; |
560 |
return 'tooManyReserves'; |
553 |
} |
561 |
} |
554 |
|
562 |
|
555 |
my $circ_control_branch = C4::Circulation::_GetCircControlBranch($item, |
563 |
my $circ_control_branch = |
556 |
$borrower); |
564 |
C4::Circulation::_GetCircControlBranch( $item, $borrower ); |
557 |
my $branchitemrule = C4::Circulation::GetBranchItemRule($circ_control_branch, |
565 |
my $branchitemrule = |
558 |
$item->{itype}); |
566 |
C4::Circulation::GetBranchItemRule( $circ_control_branch, $item->{itype} ); |
559 |
|
567 |
|
560 |
if ( $branchitemrule->{holdallowed} == 0 ) { |
568 |
if ( $branchitemrule->{holdallowed} == 0 ) { |
561 |
return 'notReservable'; |
569 |
return 'notReservable'; |
Lines 564-570
sub CanItemBeReserved{
Link Here
|
564 |
if ( $branchitemrule->{holdallowed} == 1 |
572 |
if ( $branchitemrule->{holdallowed} == 1 |
565 |
&& $borrower->{branchcode} ne $item->{homebranch} ) |
573 |
&& $borrower->{branchcode} ne $item->{homebranch} ) |
566 |
{ |
574 |
{ |
567 |
return 'cannotReserveFromOtherBranches'; |
575 |
return 'cannotReserveFromOtherBranches'; |
568 |
} |
576 |
} |
569 |
|
577 |
|
570 |
# If reservecount is ok, we check item branch if IndependentBranches is ON |
578 |
# If reservecount is ok, we check item branch if IndependentBranches is ON |
Lines 573-579
sub CanItemBeReserved{
Link Here
|
573 |
and !C4::Context->preference('canreservefromotherbranches') ) |
581 |
and !C4::Context->preference('canreservefromotherbranches') ) |
574 |
{ |
582 |
{ |
575 |
my $itembranch = $item->{homebranch}; |
583 |
my $itembranch = $item->{homebranch}; |
576 |
if ($itembranch ne $borrower->{branchcode}) { |
584 |
if ( $itembranch ne $borrower->{branchcode} ) { |
577 |
return 'cannotReserveFromOtherBranches'; |
585 |
return 'cannotReserveFromOtherBranches'; |
578 |
} |
586 |
} |
579 |
} |
587 |
} |
580 |
- |
|
|