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