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