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